├── .gitignore
├── LICENCE
├── README.md
├── bin
└── hcl
├── etc
├── help_message
└── underscore.js
├── examples
├── browser-hello.hcl
├── browser-hello.html
├── dependencies.hcl
├── dependencies.out
├── dependency1.hcl
├── dependency2.hcl
├── dihedral.hcl
├── dihedral.out
├── error.hcl
├── error.out
├── euler119.hcl
├── euler119.out
├── euler2.hcl
├── euler2.out
├── fizzbuzz.hcl
├── fizzbuzz.out
├── functions.hcl
├── functions.out
├── hello.hcl
├── hello.out
├── linked_list.hcl
├── linked_list.out
├── loop-ref-issue.hcl
├── loop-ref-issue.out
├── looping_bug.hcl
├── looping_bug.out
├── loops.hcl
├── loops.out
├── memoizing.hcl
├── memoizing.out
├── node-hello.hcl
├── objects.hcl
├── objects.out
├── oo.hcl
├── oo.out
├── pascal.hcl
├── pascal.out
├── quine.hcl
├── quine.out
├── random_lists.hcl
├── random_lists.out
├── scope-issue.hcl
├── scope-issue.out
├── scope.hcl
├── scope.out
├── setters.hcl
├── setters.out
├── splat.hcl
├── splat.out
├── underscore.hcl
└── underscore.out
├── implementation_notes.org
├── lib
├── args.js
├── attributeGrammar.js
├── browser.js
├── builtins.js
├── compile.js
├── file2js.js
├── functions.js
├── helpers.js
├── mangle.js
├── parseGrammar.json
├── parser.js
├── reduceFractions.js
├── tokenTypes.js
└── types.js
├── node_modules
├── .bin
│ ├── hot-cocoa-test
│ └── uglifyjs
├── optimist
│ ├── .travis.yml
│ ├── LICENSE
│ ├── README.markdown
│ ├── example
│ │ ├── bool.js
│ │ ├── boolean_double.js
│ │ ├── boolean_single.js
│ │ ├── default_hash.js
│ │ ├── default_singles.js
│ │ ├── divide.js
│ │ ├── line_count.js
│ │ ├── line_count_options.js
│ │ ├── line_count_wrap.js
│ │ ├── nonopt.js
│ │ ├── reflect.js
│ │ ├── short.js
│ │ ├── string.js
│ │ ├── usage-options.js
│ │ └── xup.js
│ ├── index.js
│ ├── node_modules
│ │ └── wordwrap
│ │ │ ├── .npmignore
│ │ │ ├── README.markdown
│ │ │ ├── example
│ │ │ ├── center.js
│ │ │ └── meat.js
│ │ │ ├── index.js
│ │ │ ├── package.json
│ │ │ └── test
│ │ │ ├── break.js
│ │ │ ├── idleness.txt
│ │ │ └── wrap.js
│ ├── package.json
│ ├── test
│ │ ├── _.js
│ │ ├── _
│ │ │ ├── argv.js
│ │ │ └── bin.js
│ │ ├── parse.js
│ │ └── usage.js
│ └── x.js
├── uglify-js
│ ├── .npmignore
│ ├── README.md
│ ├── bin
│ │ └── uglifyjs
│ ├── lib
│ │ ├── ast.js
│ │ ├── compress.js
│ │ ├── mozilla-ast.js
│ │ ├── output.js
│ │ ├── parse.js
│ │ ├── scope.js
│ │ ├── sourcemap.js
│ │ ├── transform.js
│ │ └── utils.js
│ ├── node_modules
│ │ └── source-map
│ │ │ ├── .npmignore
│ │ │ ├── .travis.yml
│ │ │ ├── CHANGELOG.md
│ │ │ ├── LICENSE
│ │ │ ├── Makefile.dryice.js
│ │ │ ├── README.md
│ │ │ ├── build
│ │ │ ├── assert-shim.js
│ │ │ ├── mini-require.js
│ │ │ ├── prefix-source-map.jsm
│ │ │ ├── prefix-utils.jsm
│ │ │ ├── suffix-browser.js
│ │ │ ├── suffix-source-map.jsm
│ │ │ ├── suffix-utils.jsm
│ │ │ ├── test-prefix.js
│ │ │ └── test-suffix.js
│ │ │ ├── lib
│ │ │ ├── source-map.js
│ │ │ └── source-map
│ │ │ │ ├── array-set.js
│ │ │ │ ├── base64-vlq.js
│ │ │ │ ├── base64.js
│ │ │ │ ├── binary-search.js
│ │ │ │ ├── source-map-consumer.js
│ │ │ │ ├── source-map-generator.js
│ │ │ │ ├── source-node.js
│ │ │ │ └── util.js
│ │ │ ├── node_modules
│ │ │ └── amdefine
│ │ │ │ ├── .npmignore
│ │ │ │ ├── LICENSE
│ │ │ │ ├── README.md
│ │ │ │ ├── amdefine.js
│ │ │ │ └── package.json
│ │ │ ├── package.json
│ │ │ └── test
│ │ │ ├── run-tests.js
│ │ │ └── source-map
│ │ │ ├── test-api.js
│ │ │ ├── test-array-set.js
│ │ │ ├── test-base64-vlq.js
│ │ │ ├── test-base64.js
│ │ │ ├── test-binary-search.js
│ │ │ ├── test-dog-fooding.js
│ │ │ ├── test-source-map-consumer.js
│ │ │ ├── test-source-map-generator.js
│ │ │ ├── test-source-node.js
│ │ │ └── util.js
│ ├── package.json
│ ├── test
│ │ ├── compress
│ │ │ ├── arrays.js
│ │ │ ├── blocks.js
│ │ │ ├── conditionals.js
│ │ │ ├── dead-code.js
│ │ │ ├── debugger.js
│ │ │ ├── drop-unused.js
│ │ │ ├── issue-105.js
│ │ │ ├── issue-12.js
│ │ │ ├── issue-22.js
│ │ │ ├── issue-44.js
│ │ │ ├── issue-59.js
│ │ │ ├── labels.js
│ │ │ ├── loops.js
│ │ │ ├── properties.js
│ │ │ ├── sequences.js
│ │ │ └── switch.js
│ │ └── run-tests.js
│ └── tools
│ │ └── node.js
└── underscore
│ ├── .npmignore
│ ├── CNAME
│ ├── CONTRIBUTING.md
│ ├── LICENSE
│ ├── README.md
│ ├── favicon.ico
│ ├── index.html
│ ├── index.js
│ ├── package.json
│ ├── raw
│ └── underscore.psd
│ ├── underscore-min.js
│ └── underscore.js
├── package.json
├── parseTests.js
└── tests
├── compile.js
├── full.js
├── text2ast.js
└── text2astRD.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/hot-cocoa
2 | examples/*.js
3 | reference_gen.*
--------------------------------------------------------------------------------
/bin/hcl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var _ = require('underscore');
4 | var args = require('../lib/args.js');
5 | var hcl = require('../lib/parser.js');
6 | var compile = require('../lib/compile.js');
7 | var file2js = require('../lib/file2js.js');
8 | var exec = require('child_process').exec;
9 | var path = require('path');
10 | var fs = require('fs');
11 | var repl = require('repl');
12 | var format = require('hot-cocoa').format;
13 |
14 | // check for -h flag
15 | if (args.help) {
16 | process.stdout.write(
17 | fs.readFileSync(
18 | path.dirname(process.mainModule.filename) +
19 | '/../etc/help_message'
20 | ).toString()
21 | );
22 | process.exit(0);
23 | }
24 |
25 | // check for -v flag
26 | if (args.version) {
27 | console.log(format('Hot Cocoa Lisp version ~~', [
28 | require('../package.json').version
29 | ]));
30 | process.exit(0);
31 | }
32 |
33 | if (args._[0]) {
34 |
35 | // a file was secified, compile it to a .js
36 | file2js(args._[0], function() {
37 |
38 | // check for -n flag
39 | if (args.n) {
40 | require(path.resolve(args._[0].replace(/(\.[^.\/]+$)|$/, '.js')));
41 | }
42 | });
43 | } else {
44 |
45 | // REPL mode
46 |
47 | // check for -u flag
48 | if (args.u) {
49 | var underscore_keys = Object.keys(_);
50 | for (var i = 0; i < underscore_keys.length; i++) {
51 | if (global[underscore_keys[i]] === undefined) {
52 | global[underscore_keys[i]] = _[underscore_keys[i]];
53 | }
54 | }
55 | }
56 |
57 | // load fraction support
58 | var frac = require('../lib/reduceFractions.js');
59 |
60 | // start the REPL
61 | repl.start({
62 | prompt: 'hcl> ',
63 | eval: function(cmd, context, filename, callback) {
64 | if (cmd.replace(/^\(/, '').replace(/\)$/, '').trim().length === 0) {
65 | callback(null);
66 | } else {
67 | try {
68 | var ast = hcl.analyze(hcl.parse(hcl.scan(cmd.toString())));
69 | var js = compile(ast[0], undefined, undefined, {
70 | repl_mode: true,
71 | omit_annotations: true,
72 | add_to_outer_scope: function(name, value) {
73 | if (args.debug && value) {
74 | console.log('js (', name, '):', value);
75 | }
76 | global[name] = eval('(' + value + ')');
77 | },
78 | add_to_scope: function(name, value) {
79 | if (args.debug && value) {
80 | console.log('js (', name, '):', value);
81 | }
82 | global[name] = eval('(' + value + ')');
83 | }
84 | });
85 | if (args.debug) {
86 | console.log('js:', js.trim());
87 | }
88 | var res = eval('(' + js.replace(/;$/, '') + ')');
89 | callback(null, res);
90 | } catch(e) {
91 | console.log(console.log(e.stack));
92 | callback(null, e);
93 | }
94 | }
95 | },
96 | writer: function(value) {
97 |
98 | // a regular expression that matches commas and colons that aren't in
99 | // strings based on the one found here:
100 | // http://stackoverflow.com/questions/1191397/regex-to-match-values-not-surrounded-by-another-char
101 | var punctuation = /[,:](?=(?:(?:(?:[^'\\]|\\.)*'){2})*(?:[^'\\]|\\.)*$)/g;
102 |
103 | return require('util')
104 | .inspect(value,
105 | false, // show hidden
106 | null, // depth
107 | true) // colors
108 | .replace(punctuation, '')
109 | .replace(/{}/g, '{ }')
110 | .replace(/\[\]/g, '[ ]')
111 | .replace(/'/g, '"');
112 | }
113 | });
114 | }
115 |
--------------------------------------------------------------------------------
/etc/help_message:
--------------------------------------------------------------------------------
1 | Usage: hcl [-hnbvdum] [file]
2 |
3 | If a file is specified it will be compiled to a .js file
4 | otherwise the REPL will be opened.
5 |
6 | Options:
7 | -h, --help Display this help message
8 | -n, --run-with-node Immediately execute the program using Node.js
9 | -b, --browser Optimize the code for use in a web browser
10 | it is recommended for reliability reasons that this
11 | always be used for applications meant to run in a
12 | browser.
13 | -v, --version Display the version number
14 | -d, --debug Run the REPL in debug mode to see the
15 | intermediate compiled JavaScript source.
16 | -u, --underscore Include underscore.js
17 | -m, --minify Minify output using uglify.js
18 |
--------------------------------------------------------------------------------
/examples/browser-hello.hcl:
--------------------------------------------------------------------------------
1 | (alert "hello")
--------------------------------------------------------------------------------
/examples/browser-hello.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Browser Hello
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/dependencies.hcl:
--------------------------------------------------------------------------------
1 | ;; call dependency1 as a function on dependency2
2 | (console.log
3 | ((require (compile "./dependency1.hcl"))
4 | (require (compile "./dependency2.hcl"))))
--------------------------------------------------------------------------------
/examples/dependencies.out:
--------------------------------------------------------------------------------
1 | 5
2 |
--------------------------------------------------------------------------------
/examples/dependency1.hcl:
--------------------------------------------------------------------------------
1 | ;; create a cyclic dependency without entering an infinite loop
2 | (compile "./dependencies.hcl")
3 |
4 | (set module.exports (# (x) (+1 (*2 x))))
5 |
--------------------------------------------------------------------------------
/examples/dependency2.hcl:
--------------------------------------------------------------------------------
1 | (set module.exports 2)
2 |
--------------------------------------------------------------------------------
/examples/dihedral.hcl:
--------------------------------------------------------------------------------
1 | (def dihedral-subtract
2 | (# (a b order)
3 | (let (u_1 (>> a 1)
4 | v_1 (& a 1)
5 | u_2 (>> b 1)
6 | v_2 (& b 1))
7 | (if (= 1 v_1)
8 | (bit-or (<< (% (+ order u_1 (- u_2)) (>> order 1)) 1)
9 | (if (zero? v_2) 1 0))
10 | (bit-or (<< (% (+ u_1 u_2) (>> order 1)) 1)
11 | v_2)))))
12 |
13 | (def get-order (let (n (integer (nth process.argv 2)))
14 | (cond
15 | ((or (not (integer? n)) (< n 1)) 6)
16 | ((odd? n) (--1 n))
17 | (true n))))
18 |
19 | (process.stdout.write " ")
20 | (times (i get-order)
21 | (process.stdout.write (cat i " ")))
22 | (process.stdout.write "\n")
23 | (times (i get-order)
24 | (process.stdout.write (cat i " "))
25 | (times (j get-order)
26 | (process.stdout.write (cat (dihedral-subtract i j get-order) " ")))
27 | (process.stdout.write "\n"))
28 |
--------------------------------------------------------------------------------
/examples/dihedral.out:
--------------------------------------------------------------------------------
1 | 0 1 2 3 4 5
2 | 0 0 1 2 3 4 5
3 | 1 1 0 5 4 3 2
4 | 2 2 3 4 5 0 1
5 | 3 3 2 1 0 5 4
6 | 4 4 5 0 1 2 3
7 | 5 5 4 3 2 1 0
8 |
--------------------------------------------------------------------------------
/examples/error.hcl:
--------------------------------------------------------------------------------
1 | (def questionable-code
2 | (# (input)
3 | (console.log "doing stuff..")
4 | (when (= input "unexpected input")
5 | (throw "This wasn't supposed to happen"))
6 | (console.log "more stuff..")))
7 |
8 | (def trying-things
9 | (# (input)
10 |
11 | (console.log 1)
12 | (attempt
13 | (try
14 | (questionable-code input))
15 | (catch e
16 | (console.log "got error: " e))
17 | (finally
18 | (console.log "this should run whether there was an error or not")))
19 |
20 | (console.log 2)
21 | (attempt
22 | (try
23 | (questionable-code input))
24 | (catch e
25 | (console.log "got error: " e)))
26 |
27 | (console.log 3)
28 | (attempt
29 | (try
30 | (questionable-code input))
31 | (finally
32 | (console.log "this should run whether there was an error or not")))))
33 |
34 |
35 | (trying-things "foo")
36 | (trying-things "unexpected input")
37 |
38 |
--------------------------------------------------------------------------------
/examples/error.out:
--------------------------------------------------------------------------------
1 | 1
2 | doing stuff..
3 | more stuff..
4 | this should run whether there was an error or not
5 | 2
6 | doing stuff..
7 | more stuff..
8 | 3
9 | doing stuff..
10 | more stuff..
11 | this should run whether there was an error or not
12 | 1
13 | doing stuff..
14 | got error: [Error: This wasn't supposed to happen]
15 | this should run whether there was an error or not
16 | 2
17 | doing stuff..
18 | got error: [Error: This wasn't supposed to happen]
19 | 3
20 | doing stuff..
21 | this should run whether there was an error or not
22 |
--------------------------------------------------------------------------------
/examples/euler119.hcl:
--------------------------------------------------------------------------------
1 | (def digit-sum
2 | (# (n)
3 | (def res 0)
4 | (for (digit (string n))
5 | (set+ res (number digit)))
6 | res))
7 |
8 | (def preliminary-check?
9 | (# (sum n)
10 | (cond
11 | ((= 1 sum) false)
12 | ((!= 0 (% n (square sum))) false)
13 | (true true))))
14 |
15 | ;(def brute-check?
16 | ; (# (sum n)
17 | ; (console.log 2)
18 | ; (def x n)
19 | ; (while (and (= 0 (% x sum)) (> x sum))
20 | ; (set/ x sum))
21 | ; (= x sum)))
22 |
23 | (def brute-check?
24 | (# (sum n)
25 | (cond
26 | ((= n sum) true)
27 | ((= 0 (% n sum)) (brute-check? sum (/ n sum)))
28 | (true false))))
29 |
30 | (def in-sequence?
31 | (# (n)
32 | (let (sum (digit-sum n))
33 | (if (preliminary-check? sum n) (brute-check? sum n) false))))
34 |
35 | (def x 0)
36 | (for ((var i 11) (< i 1e4) (++ i))
37 | (when (in-sequence? i)
38 | (++ x)
39 | (console.log x i)))
40 |
--------------------------------------------------------------------------------
/examples/euler119.out:
--------------------------------------------------------------------------------
1 | 1 81
2 | 2 512
3 | 3 2401
4 | 4 4913
5 | 5 5832
6 |
--------------------------------------------------------------------------------
/examples/euler2.hcl:
--------------------------------------------------------------------------------
1 | (def a 0)
2 | (def b 0)
3 | (def c 1)
4 | (def total 0)
5 | (while (< b 4e6)
6 | (set a b)
7 | (set b c)
8 | (set c (+ a b))
9 | (when (even? b)
10 | (set+ total b)
11 | (console.log b)))
12 | (console.log "total" total)
13 |
--------------------------------------------------------------------------------
/examples/euler2.out:
--------------------------------------------------------------------------------
1 | 2
2 | 8
3 | 34
4 | 144
5 | 610
6 | 2584
7 | 10946
8 | 46368
9 | 196418
10 | 832040
11 | 3524578
12 | total 4613732
13 |
--------------------------------------------------------------------------------
/examples/fizzbuzz.hcl:
--------------------------------------------------------------------------------
1 | (def divisible (# (n m) (= 0 (mod n m))))
2 |
3 | (def evaluated-if
4 | (# (condition yes no)
5 | (if (condition yes no) yes no)))
6 |
7 | (def fizzbuzz
8 | (# (n)
9 | (console.log
10 | (evaluated-if (# (_ words) (empty? words)) n
11 | (reduce (map [[3 "Fizz"] [5 "Buzz"]]
12 | (# (pair)
13 | (if (divisible n (get pair 0))
14 | (get pair 1) "")))
15 | (# (a b) (cat a b)) "")))
16 | (and (< n 100) (fizzbuzz (+1 n)))))
17 |
18 | (fizzbuzz 1)
19 |
--------------------------------------------------------------------------------
/examples/fizzbuzz.out:
--------------------------------------------------------------------------------
1 | 1
2 | 2
3 | Fizz
4 | 4
5 | Buzz
6 | Fizz
7 | 7
8 | 8
9 | Fizz
10 | Buzz
11 | 11
12 | Fizz
13 | 13
14 | 14
15 | FizzBuzz
16 | 16
17 | 17
18 | Fizz
19 | 19
20 | Buzz
21 | Fizz
22 | 22
23 | 23
24 | Fizz
25 | Buzz
26 | 26
27 | Fizz
28 | 28
29 | 29
30 | FizzBuzz
31 | 31
32 | 32
33 | Fizz
34 | 34
35 | Buzz
36 | Fizz
37 | 37
38 | 38
39 | Fizz
40 | Buzz
41 | 41
42 | Fizz
43 | 43
44 | 44
45 | FizzBuzz
46 | 46
47 | 47
48 | Fizz
49 | 49
50 | Buzz
51 | Fizz
52 | 52
53 | 53
54 | Fizz
55 | Buzz
56 | 56
57 | Fizz
58 | 58
59 | 59
60 | FizzBuzz
61 | 61
62 | 62
63 | Fizz
64 | 64
65 | Buzz
66 | Fizz
67 | 67
68 | 68
69 | Fizz
70 | Buzz
71 | 71
72 | Fizz
73 | 73
74 | 74
75 | FizzBuzz
76 | 76
77 | 77
78 | Fizz
79 | 79
80 | Buzz
81 | Fizz
82 | 82
83 | 83
84 | Fizz
85 | Buzz
86 | 86
87 | Fizz
88 | 88
89 | 89
90 | FizzBuzz
91 | 91
92 | 92
93 | Fizz
94 | 94
95 | Buzz
96 | Fizz
97 | 97
98 | 98
99 | Fizz
100 | Buzz
101 |
--------------------------------------------------------------------------------
/examples/functions.hcl:
--------------------------------------------------------------------------------
1 | (console.log (map [ 1 2 3 ] +1)
2 | (map [ 1 2 3 ] --1)
3 | (map [ 1 2 3 ] *2)
4 | (map [ 1 2 3 ] /2)
5 | (map [ 1 2 3 ] ^2))
6 |
7 | (console.log (format "(~~) (~~) (~~)" [ 1 2 3 ] ))
8 | (console.log (format "(~foo~) (~bar~)" { bar 7 foo 8 } ))
9 | (console.log (reduce [ "foo" "bar" "baz" ] cat))
10 | (console.log ((map [1 null "foo" [1 2 3] {} NaN (re "foo") undefined nop] type).join ","))
11 | (console.log ((map [1 "foo" [1 2 3] {} NaN (re "foo")] string).join ","))
12 | (console.log ((# (f) (f "1 2 3 4 5" (re "\d" "g") "x")) replace))
13 | (console.log ((# (f) (f [ ])) size))
14 | (console.log (select [ 1 -2 7 0 -3 9 ] positive?))
15 | (console.log (select [ 1 -2 7 0 -3 9 ] non-negative?))
16 | (console.log (map [ [ true 1 2 ] [ false 3 4 ] [ (= 1 1) 5 6 ] ] (# (x) (if.apply this x))))
17 |
--------------------------------------------------------------------------------
/examples/functions.out:
--------------------------------------------------------------------------------
1 | [ 2, 3, 4 ] [ 0, 1, 2 ] [ 2, 4, 6 ] [ 0.5, 1, 1.5 ] [ 1, 4, 9 ]
2 | (1) (2) (3)
3 | (8) (7)
4 | foobarbaz
5 | Number,Null,String,Array,Object,NaN,RegExp,Undefined,Function
6 | 1,foo,1,2,3,[object Object],NaN,/foo/
7 | x x x x x
8 | 0
9 | [ 1, 7, 9 ]
10 | [ 1, 7, 0, 9 ]
11 | [ 1, 4, 5 ]
12 |
--------------------------------------------------------------------------------
/examples/hello.hcl:
--------------------------------------------------------------------------------
1 | (console.log "Hello World!")
2 |
--------------------------------------------------------------------------------
/examples/hello.out:
--------------------------------------------------------------------------------
1 | Hello World!
2 |
--------------------------------------------------------------------------------
/examples/linked_list.hcl:
--------------------------------------------------------------------------------
1 | (def reverse-list (# (l)
2 | (if (nil? l.next) l
3 | (let (next l.next
4 | res (reverse-list l.next))
5 | (set l.next.next l)
6 | (set l.next null)
7 | res))))
8 |
9 | (def linked-list { v 1 next { v 2 next { v 3 } } })
10 |
11 | (console.log (JSON.stringify linked-list))
12 | (console.log (JSON.stringify (reverse-list linked-list)))
13 |
--------------------------------------------------------------------------------
/examples/linked_list.out:
--------------------------------------------------------------------------------
1 | {"v":1,"next":{"v":2,"next":{"v":3}}}
2 | {"v":3,"next":{"v":2,"next":{"v":1,"next":null}}}
3 |
--------------------------------------------------------------------------------
/examples/loop-ref-issue.hcl:
--------------------------------------------------------------------------------
1 | (def size-gen (# () (console.log "gen") 3))
2 | (def list-gen (# () (console.log "gen") [ 1 2 3 ]))
3 |
4 | (times (i (size-gen)) (console.log i))
5 | (for (x (list-gen)) (console.log x))
6 | (for ((i x) (list-gen)) (console.log i x))
7 |
--------------------------------------------------------------------------------
/examples/loop-ref-issue.out:
--------------------------------------------------------------------------------
1 | gen
2 | 0
3 | 1
4 | 2
5 | gen
6 | 1
7 | 2
8 | 3
9 | gen
10 | 0 1
11 | 1 2
12 | 2 3
13 |
--------------------------------------------------------------------------------
/examples/looping_bug.hcl:
--------------------------------------------------------------------------------
1 | (cond (true (for (n [ 1 2 ]) (console.log n))))
2 |
3 | (console.log (begin (set x 2) (cond (true (for (n [ 1 2 ]) (set+ x n)))) x))
--------------------------------------------------------------------------------
/examples/looping_bug.out:
--------------------------------------------------------------------------------
1 | 1
2 | 2
3 | 5
4 |
--------------------------------------------------------------------------------
/examples/loops.hcl:
--------------------------------------------------------------------------------
1 | (var y 0)
2 | (times (x 7) (when (even? x) (++ y)))
3 | (console.log y)
4 | (var y 0)
5 | (times (x 7) (unless (even? x) (++ y) (++ y)))
6 | (console.log y)
7 |
8 | ;; traditional for loop
9 | (def print-all
10 | (# (args...)
11 | (for ((set i 0) (< i args.length) (++ i))
12 | (console.log i (get args i)))))
13 |
14 | (print-all "a" "b" "c" "d")
15 |
16 | ;; python style for loop
17 | (def print-all
18 | (# (args...)
19 | (for (x args) (console.log x))))
20 |
21 | (print-all "d" "e" "f")
22 |
23 | ;; while loop
24 | (def linked-list { n { v 1 n { v 2 n { v 3 n { v 5 n { v 8 } } } } } } )
25 |
26 | (while (set linked-list (get linked-list "n"))
27 | (console.log (get linked-list "v") linked-list))
28 |
29 | ;; nested loops
30 | (for (x [ 2 4 6 ] )
31 | (for (y [ 3 6 9 ] )
32 | (console.log (* x y))))
33 |
34 | ;; find the first fibonacci number below n
35 | (def first-fib
36 | (# (n)
37 | (let (a 1 b 1)
38 | (until (> b n)
39 | (set (a b) [ b (+ a b) ] ))
40 | b)))
41 |
42 | (console.log (map (range 10 101 10) first-fib))
43 |
44 | ;; loop with index
45 |
46 | (def the-list ["foo" "bar" "baz"])
47 | (for ((index word) the-list) (console.log index word))
48 |
--------------------------------------------------------------------------------
/examples/loops.out:
--------------------------------------------------------------------------------
1 | 4
2 | 6
3 | 0 'a'
4 | 1 'b'
5 | 2 'c'
6 | 3 'd'
7 | d
8 | e
9 | f
10 | 1 { v: 1, n: { v: 2, n: { v: 3, n: [Object] } } }
11 | 2 { v: 2, n: { v: 3, n: { v: 5, n: [Object] } } }
12 | 3 { v: 3, n: { v: 5, n: { v: 8 } } }
13 | 5 { v: 5, n: { v: 8 } }
14 | 8 { v: 8 }
15 | 6
16 | 12
17 | 18
18 | 12
19 | 24
20 | 36
21 | 18
22 | 36
23 | 54
24 | [ 13, 21, 34, 55, 55, 89, 89, 89, 144, 144 ]
25 | 0 'foo'
26 | 1 'bar'
27 | 2 'baz'
28 |
--------------------------------------------------------------------------------
/examples/memoizing.hcl:
--------------------------------------------------------------------------------
1 | ;; choose w/o memoize
2 | (def choose
3 | (# (m n)
4 | (if (or (= 0 n) (= m n)) 1
5 | (+ (choose (--1 m) n)
6 | (choose (--1 m) (--1 n))))))
7 |
8 | ;; memoize
9 | (def my-memoize
10 | (# (func)
11 | (let (memo {})
12 | (# (args...)
13 | (let (json (JSON.stringify args))
14 | (or (get memo json)
15 | (set (get memo json) (func.apply undefined args))))))))
16 |
17 | ;; choose w/ memoize
18 | (def choose-memo
19 | (my-memoize (# (m n)
20 | (if (or (= 0 n) (= m n)) 1
21 | (+ (choose-memo (--1 m) n)
22 | (choose-memo (--1 m) (--1 n)))))))
23 |
24 | (console.log (choose 5 2))
25 | (console.log (choose 20 10))
26 | (console.log (choose-memo 50 30))
27 |
--------------------------------------------------------------------------------
/examples/memoizing.out:
--------------------------------------------------------------------------------
1 | 10
2 | 184756
3 | 47129212243960
4 |
--------------------------------------------------------------------------------
/examples/node-hello.hcl:
--------------------------------------------------------------------------------
1 | ;; Transcriebd from from http://howtonode.org/hello-node
2 |
3 | ;; Load the http module to create an http server.
4 | (def http (require "http"))
5 |
6 | ;; Configure our HTTP server to respond with Hello World to all requests.
7 | (def server (http.createServer
8 | (# (request response)
9 | (response.writeHead 200 {"Content-Type" "text/plain"} )
10 | (response.end "Hello World\n"))))
11 |
12 | ;; Listen on port 8000, IP defaults to 127.0.0.1
13 | (server.listen 8000)
14 |
15 | ;; Put a friendly message on the terminal
16 | (console.log "Server running at http://127.0.0.1:8000/")
--------------------------------------------------------------------------------
/examples/objects.hcl:
--------------------------------------------------------------------------------
1 | ;; basic object
2 |
3 | (def my_object
4 | { number 10
5 | add (# (x) (set this.number (+ x this.number))) } )
6 |
7 | (console.log my_object.number) ; 10
8 | (my_object.add 5)
9 | (console.log my_object.number) ; 15
10 | ((. my_object add) 7)
11 | (console.log my_object.number) ; 22
12 |
13 | (def my_object2 { foo { bar 7 baz 9 } } )
14 | (console.log my_object2.foo.bar) ; 7
15 | (console.log (. my_object2 foo baz)) ; 9
16 |
17 | ;; inheritance
18 |
19 | (def _Person
20 | { first_name "N/A"
21 | last_name "N/A"
22 | full_name (# () (format "~~ ~~" [ this.first_name this.last_name ] ))
23 | shake_hands (# (other) (console.log (format "~~ shakes hands with ~~"
24 | [ (this.full_name)
25 | (other.full_name) ] ))) } )
26 |
27 | (def sam (inherit _Person))
28 | (set sam.first_name "Sam")
29 | (set sam "last_name" "Auciello")
30 |
31 | (console.log (get sam "first_name")) ; Sam
32 | (console.log sam.first_name) ; Sam
33 |
34 | (def jim (inherit _Person))
35 | (set jim.first_name "Jim")
36 | (set jim.last_name "Mahoney")
37 |
38 | (jim.shake_hands sam) ; Jim Mahoney shakes hands with Sam Auciello
39 | (jim.shake_hands.call sam jim) ; Sam Auciello shakes hands with Jim Mahoney
40 |
--------------------------------------------------------------------------------
/examples/objects.out:
--------------------------------------------------------------------------------
1 | 10
2 | 15
3 | 22
4 | 7
5 | 9
6 | Sam
7 | Sam
8 | Jim Mahoney shakes hands with Sam Auciello
9 | Sam Auciello shakes hands with Jim Mahoney
10 |
--------------------------------------------------------------------------------
/examples/oo.hcl:
--------------------------------------------------------------------------------
1 | (def obj { res "foo"
2 | self (# () @)
3 | cat-res (# (x) (cat @res "-" x))
4 | res-map (# (args...) (map args (@# () @res)))
5 | cat-res-map (# (args...)
6 | (map args (@# (x) (@cat-res x)))) })
7 |
8 | (console.log ((obj.self).res-map 1 2 3))
9 | (console.log (obj.cat-res-map 1 2 3))
10 |
--------------------------------------------------------------------------------
/examples/oo.out:
--------------------------------------------------------------------------------
1 | [ 'foo', 'foo', 'foo' ]
2 | [ 'foo-1', 'foo-2', 'foo-3' ]
3 |
--------------------------------------------------------------------------------
/examples/pascal.hcl:
--------------------------------------------------------------------------------
1 | ;; memoize
2 | (def my-memoize
3 | (# (func)
4 | (let (memo {})
5 | (# (args...)
6 | (let (json (JSON.stringify args))
7 | (or (get memo json)
8 | (set (get memo json) (func.apply undefined args))))))))
9 |
10 | ;; choose w/ memoize
11 | (def choose
12 | (my-memoize (# (m n)
13 | (if (or (= 0 n) (= m n)) 1
14 | (+ (choose (--1 m) n)
15 | (choose (--1 m) (--1 n)))))))
16 |
17 | (def max-rows 20)
18 |
19 | (times (row max-rows)
20 | (times (col (+1 row))
21 | (process.stdout.write (cat (choose row col) " ")))
22 | (process.stdout.write "\n"))
23 |
--------------------------------------------------------------------------------
/examples/pascal.out:
--------------------------------------------------------------------------------
1 | 1
2 | 1 1
3 | 1 2 1
4 | 1 3 3 1
5 | 1 4 6 4 1
6 | 1 5 10 10 5 1
7 | 1 6 15 20 15 6 1
8 | 1 7 21 35 35 21 7 1
9 | 1 8 28 56 70 56 28 8 1
10 | 1 9 36 84 126 126 84 36 9 1
11 | 1 10 45 120 210 252 210 120 45 10 1
12 | 1 11 55 165 330 462 462 330 165 55 11 1
13 | 1 12 66 220 495 792 924 792 495 220 66 12 1
14 | 1 13 78 286 715 1287 1716 1716 1287 715 286 78 13 1
15 | 1 14 91 364 1001 2002 3003 3432 3003 2002 1001 364 91 14 1
16 | 1 15 105 455 1365 3003 5005 6435 6435 5005 3003 1365 455 105 15 1
17 | 1 16 120 560 1820 4368 8008 11440 12870 11440 8008 4368 1820 560 120 16 1
18 | 1 17 136 680 2380 6188 12376 19448 24310 24310 19448 12376 6188 2380 680 136 17 1
19 | 1 18 153 816 3060 8568 18564 31824 43758 48620 43758 31824 18564 8568 3060 816 153 18 1
20 | 1 19 171 969 3876 11628 27132 50388 75582 92378 92378 75582 50388 27132 11628 3876 969 171 19 1
21 |
--------------------------------------------------------------------------------
/examples/quine.hcl:
--------------------------------------------------------------------------------
1 | (def x "(def x QQXQQ) (console.log (replace (replace x (re QQQ{2}QQ QQgQQ) (String.fromCharCode 34)) (re QQXQQ) x))") (console.log (replace (replace x (re "Q{2}" "g") (String.fromCharCode 34)) (re "X") x))
2 |
--------------------------------------------------------------------------------
/examples/quine.out:
--------------------------------------------------------------------------------
1 | (def x "(def x QQXQQ) (console.log (replace (replace x (re QQQ{2}QQ QQgQQ) (String.fromCharCode 34)) (re QQXQQ) x))") (console.log (replace (replace x (re "Q{2}" "g") (String.fromCharCode 34)) (re "X") x))
2 |
--------------------------------------------------------------------------------
/examples/random_lists.hcl:
--------------------------------------------------------------------------------
1 | (var x (random-float))
2 | (var y (map (range (+1 (random-integer 10))) random-float))
3 | (var joined (cons x y))
4 | (console.log (= (car joined) x)
5 | (isEqual (cdr joined) y)
6 | (= (cadr joined) (car y)))
7 | (var arr (map (range (+1 (random-integer 10)))
8 | (# () [ (random-float) (random-float) ] )))
9 | (console.log (isEqual (map arr cadr) (pluck arr 1))
10 | (isEqual (map arr car) (pluck arr 0)))
--------------------------------------------------------------------------------
/examples/random_lists.out:
--------------------------------------------------------------------------------
1 | true true true
2 | true true
3 |
--------------------------------------------------------------------------------
/examples/scope-issue.hcl:
--------------------------------------------------------------------------------
1 | (var func-list [])
2 | (times (i 4)
3 | (func-list.push (# () i)))
4 | (console.log (map func-list (# (f) (f))))
5 |
6 | (var func-list [])
7 | (for (x [1 2 3 4])
8 | (func-list.push (# () x)))
9 | (console.log (map func-list (# (f) (f))))
10 |
--------------------------------------------------------------------------------
/examples/scope-issue.out:
--------------------------------------------------------------------------------
1 | [ 0, 1, 2, 3 ]
2 | [ 1, 2, 3, 4 ]
3 |
--------------------------------------------------------------------------------
/examples/scope.hcl:
--------------------------------------------------------------------------------
1 | (def x 1)
2 | (def y 5)
3 |
4 | (def foo
5 | (# (y)
6 | (def z 3)
7 | (console.log x y z)))
8 |
9 | (def z 7)
10 |
11 | (foo 2)
12 | (console.log x y z)
13 |
14 | (def bar
15 | (# (x)
16 | ;; when and let are implemented using functions but don't create a new
17 | ;; scopes for the purpose of var/def
18 | (let () (var y 2))
19 | (when (= x "yes")
20 | (var y 3))
21 | (+ y 2)))
22 |
23 | (console.log (bar "no") (bar "yes"))
24 |
25 | (console.log ((# (a b c)
26 | (var x a)
27 | (var y b)
28 | (var z c)
29 | (+ x y z))
30 | 9 8 7))
31 |
32 |
33 | ((# ()
34 | (var x 10)
35 | ((# ()
36 | (var y 20)
37 | ((# ()
38 | (var z 30)
39 | (console.log x y z)))))))
40 |
--------------------------------------------------------------------------------
/examples/scope.out:
--------------------------------------------------------------------------------
1 | 1 2 3
2 | 1 5 7
3 | 4 5
4 | 24
5 | 10 20 30
6 |
--------------------------------------------------------------------------------
/examples/setters.hcl:
--------------------------------------------------------------------------------
1 | (var obj { a null b undefined c 7 })
2 |
3 | (for (key ["a" "b" "c"])
4 | (set|| (get obj key) 9))
5 |
6 | (console.log obj)
7 |
8 | (set obj { a null b undefined c 7 })
9 |
10 | (for (key ["a" "b" "c"])
11 | (set&& (get obj key) 9))
12 |
13 | (console.log obj)
14 |
--------------------------------------------------------------------------------
/examples/setters.out:
--------------------------------------------------------------------------------
1 | { a: 9, b: 9, c: 7 }
2 | { a: null, b: undefined, c: 9 }
3 |
--------------------------------------------------------------------------------
/examples/splat.hcl:
--------------------------------------------------------------------------------
1 | (def my-max (# (numbers...)
2 | (Math.max.apply this numbers)))
3 |
4 | (console.log (my-max 1 2 3 4)) ; 4
5 |
6 | (def foo (# (x numbers...)
7 | (console.log x)
8 | (Math.max.apply this numbers)))
9 |
10 | (console.log (foo 7 5 3 4)) ; 7 \n 5
11 |
--------------------------------------------------------------------------------
/examples/splat.out:
--------------------------------------------------------------------------------
1 | 4
2 | 7
3 | 5
4 |
--------------------------------------------------------------------------------
/examples/underscore.hcl:
--------------------------------------------------------------------------------
1 | (def _ (require "underscore"))
2 |
3 | (console.log (map [1 2 3] (# (x) (* 2 x))))
4 |
--------------------------------------------------------------------------------
/examples/underscore.out:
--------------------------------------------------------------------------------
1 | [ 2, 4, 6 ]
2 |
--------------------------------------------------------------------------------
/lib/args.js:
--------------------------------------------------------------------------------
1 | module.exports = require('optimist')
2 | .boolean(['h', 'n', 'b', 'v', 'd', 'u', 'm'])
3 | .alias({
4 | d: 'debug',
5 | h: 'help',
6 | n: 'run-with-node',
7 | b: 'browser',
8 | v: 'version',
9 | u: 'underscore',
10 | m: 'minify'
11 | })
12 | .argv;
--------------------------------------------------------------------------------
/lib/attributeGrammar.js:
--------------------------------------------------------------------------------
1 | /* This file creates a system for collapsing a large parse tree like:
2 | *
3 | * {"type":"_program","tree":[
4 | * {"type":"_expression","tree":[
5 | * {"type":"_list","tree":[
6 | * {"type":"(","text":"(","position":{"line":1,"column":0,"absolute":0}},
7 | * {"type":"_list-tail","tree":[
8 | * {"type":"_expression","tree":[
9 | * {"type":"_dotted-chain","tree":[
10 | * {"type":"_obj-reference","tree":[
11 | * {"type":"identifier","text":"console","position":{"line":1,"column":1,"absolute":1}}
12 | * ] },
13 | * {"type":".","text":".","position":{"line":1,"column":8,"absolute":8}},
14 | * {"type":"identifier","text":"log","position":{"line":1,"column":9,"absolute":9}},
15 | * {"type":"_dotted-chain-tail","tree":[]}
16 | * ] }
17 | * ] },
18 | * {"type":"_list-tail","tree":[
19 | * {"type":"_expression","tree":[
20 | * {"type":"_atom","tree":[
21 | * {"type":"number","text":"1","position":{"line":1,"column":13,"absolute":13}}
22 | * ] }
23 | * ] },
24 | * {"type":"_list-tail","tree":[
25 | * {"type":"_expression","tree":[
26 | * {"type":"_atom","tree":[
27 | * {"type":"number","text":"2","position":{"line":1,"column":15,"absolute":15}}
28 | * ] }
29 | * ] },
30 | * {"type":"_list-tail","tree":[
31 | * {"type":")","text":")","position":{"line":1,"column":16,"absolute":16}}
32 | * ] }
33 | * ] }
34 | * ] }
35 | * ] }
36 | * ] }
37 | * ] },
38 | * {"type":"_program-tail","tree":[]}
39 | * ] }
40 | *
41 | * into a more useful abstract syntax tree like:
42 | *
43 | * [
44 | * [
45 | * {"value":".","type":"identifier"},
46 | * {"value":"console","type":"identifier","position":{"line":1,"column":1,"absolute":1}},
47 | * {"value":"log","type":"identifier","position":{"line":1,"column":9,"absolute":9}}
48 | * ],
49 | * {"value":"1","type":"number","position":{"line":1,"column":13,"absolute":13}},
50 | * {"value":"2","type":"number","position":{"line":1,"column":15,"absolute":15}}
51 | * ]
52 | */
53 |
54 |
55 | var types = require('./types.js');
56 |
57 | module.exports = require('hot-cocoa').analyzer({
58 | '_program': function(tree) {
59 | return this.analyze(tree[1], this.analyze(tree[0]));
60 | },
61 | '_program-tail': function(tree, beginning) {
62 | if (tree[0] && tree[0].type === '_program') {
63 | var result = this.analyze(tree[0]);
64 | } else {
65 | var result = [];
66 | }
67 | result.unshift(beginning);
68 | return result;
69 | },
70 | '_expression': function(tree) {
71 | return this.analyze(tree[0]);
72 | },
73 | '_list': function(tree) {
74 | var result = this.analyze(tree[1]);
75 | result.position = tree[0].position;
76 | return result;
77 | },
78 | '_dotted-list': function(tree) {
79 | var result = this.analyze(tree[2]);
80 | result.unshift(types('identifier', '.', tree[0].position));
81 | return result;
82 | },
83 | '_list-tail': function(tree, beginning) {
84 | if (tree[0].type === '_expression') {
85 | var result = this.analyze(tree[1], this.analyze(tree[0]));
86 | } else {
87 | var result = types('list', [], tree[0].position);
88 | result.end = tree[0].position.absolute + 1;
89 | }
90 | if (beginning) {
91 | result.unshift(beginning);
92 | }
93 | return result;
94 | },
95 | '_literal-list': function(tree) {
96 | var result = types('list', [], tree[0].position);
97 | result.push(types('identifier', 'list', tree[0].position));
98 | var body = this.analyze(tree[1]);
99 | for (var i = 0; i < body.length; i++) {
100 | result.push(body[i]);
101 | }
102 | return result;
103 | },
104 | '_literal-list-tail': function(tree, beginning) {
105 | return this['_list-tail'](tree, beginning);
106 | },
107 | '_object': function(tree) {
108 | var result = types('list', [], tree[0].position);
109 | result.push(types('identifier', 'object', tree[0].position));
110 | var body = this.analyze(tree[1]);
111 | for (var i = 0; i < body.length; i++) {
112 | result.push(body[i]);
113 | }
114 | return result;
115 | },
116 | '_object-tail': function(tree, args) {
117 | if (args) {
118 | var key = args[0];
119 | var value = args[1];
120 | }
121 | if (tree[0].type === '_atom') {
122 | var x = this.analyze(tree[1]);
123 | var result = this.analyze(tree[2], [this.analyze(tree[0]),
124 | this.analyze(tree[1])]);
125 | } else {
126 | var result = types('list', [], tree[0].position);
127 | }
128 | if (key && value) {
129 | result.unshift(value);
130 | result.unshift(key);
131 | }
132 | return result;
133 | },
134 | '_dotted-chain': function(tree) {
135 | var result = types('list', [], tree[0].position);
136 | result.push(types('identifier', '.', tree[0].position));
137 | result.push(this.analyze(tree[0].tree[0]));
138 | result.push(this.analyze(tree[2]));
139 | var body = this.analyze(tree[3]);
140 | for (var i = 0; i < body.length; i++) {
141 | result.push(body[i]);
142 | }
143 | return result;
144 | },
145 | '_dotted-chain-tail': function(tree) {
146 | if (tree.length === 0) {
147 | return [];
148 | }
149 | var result = this.analyze(tree[2]);
150 | result.unshift(this.analyze(tree[1]));
151 | return result;
152 | },
153 | '_atom': function(tree) {
154 | switch (tree[0].type) { // perhaps without a switch??
155 | case '.' :
156 | return types('identifier', '.', tree[0].position);
157 | break;
158 | case 'identifier' :
159 | return types('identifier', tree[0].text, tree[0].position);
160 | break;
161 | case 'string' :
162 | return types('string', tree[0].text, tree[0].position);
163 | break;
164 | case 'number' :
165 | return types('number', tree[0].text, tree[0].position);
166 | break;
167 | case 'boolean' :
168 | return types('boolean', tree[0].text, tree[0].position);
169 | break;
170 | }
171 | },
172 | 'identifier': function(identifier) {
173 | return this['_atom']([identifier]);
174 | }
175 | });
176 |
--------------------------------------------------------------------------------
/lib/browser.js:
--------------------------------------------------------------------------------
1 | var _ = require('underscore');
2 | var fs = require('fs');
3 | var path = require('path');
4 | var format = require('hot-cocoa').format;
5 | var helpers = require('./helpers.js');
6 | var file2js = require('../lib/file2js.js');
7 | var mangle = require('./mangle.js');
8 |
9 | var function_map = require('hot-cocoa').template_map({
10 | 'inherit': '(typeof(Object.create) === "function" ? Object.create(~0~) : (function(_obj_) { var F = function() {}; F.prototype = _obj_; return new F(); })(~0~))',
11 | });
12 |
13 | // Specify minimum and maximum arguments for functions
14 | function_map.set_properties(['inherit'], { args: 1 });
15 |
16 | // Specify some functions as not pre-evaluating all of their arguments
17 | // (i.e. special forms)
18 | function_map.set_synonyms('inherit', ['new']);
19 |
20 | // Specify synonyms
21 |
22 | module.exports = function_map;
--------------------------------------------------------------------------------
/lib/builtins.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | 'format': 'function(f,v){var i=0;return f.replace(/~([a-zA-Z0-9_]*)~/g,function(_,k){if(k===\'\'){k=i;i++;}if(v[k]===undefined){return\'\';}return v[k];})}',
3 | 'nop': 'function(){}',
4 | 'get': 'function(a,b){return a[b];}',
5 | 'inherit': 'function(x){return Object.create(x);}',
6 | 'if': 'function(a,b,c){return a?b:c;}',
7 | 'random-float': 'function(x){return Math.random();}',
8 | 'random-integer': 'function(x){return parseInt(Math.random()*x);}',
9 | 'first': 'function(x){return x[0];}',
10 | 'second': 'function(x){return x[1];}',
11 | 'last': 'function(x){return x[x.length-1];}',
12 | 'rest': 'function(x){return [].slice.call(x,1);}',
13 | 'initial': 'function(x){return [].slice.call(x,0,x.length-1);}',
14 | 'cons': 'function(x,y){return [x].concat(y);}',
15 | '+': 'function(x,y){return x+y;}',
16 | '+1': 'function(x){return x+1;}',
17 | '-': 'function(x,y){return x-y;}',
18 | '--1': 'function(x){return x-1;}',
19 | '*': 'function(x,y){return x*y;}',
20 | '*2': 'function(x){return x*2;}',
21 | '/': 'function(x,y){return x/y;}',
22 | '/2': 'function(x){return x/2;}',
23 | '^': 'Math.pow',
24 | '^2': 'function(x){return x*x;}',
25 | 'sqrt': 'Math.sqrt',
26 | '%': 'function(x,y){return x%y;}',
27 | '<': 'function(x,y){return x': 'function(x,y){return x>y;}',
29 | '<=': 'function(x,y){return x<=y;}',
30 | '>=': 'function(x,y){return x>=y;}',
31 | '=': 'function(x,y){return x===y;}',
32 | '!=': 'function(x,y){return x!==y;}',
33 | '=0': 'function(x){return x===0;}',
34 | '>0': 'function(x){return x>0;}',
35 | '<0': 'function(x){return x<0;}',
36 | '>=0': 'function(x){return x>=0;}',
37 | '<=0': 'function(x){return x<=0;}',
38 | '&': 'function(x,y){return x&y;}',
39 | '|': 'function(x,y){return x|y;}',
40 | '<<': 'function(x,y){return x<>': 'function(x,y){return x>>y;}',
42 | 'not': 'function(x){return !x;}',
43 | 'and': 'function(x,y){return x&&y;}',
44 | 'or': 'function(x,y){return x||y;}',
45 | 'xor': 'function(x,y){return (x||y)&&(!(x&&y));}',
46 | 'nil?': 'function(x){return x===null||x===undefined;}',
47 | 'boolean?': 'function(x){return typeof(x)==="boolean";}',
48 | 'number?': 'function(x){return typeof(x)==="number"&&(!isNaN(x));}',
49 | 'string?': 'function(x){return typeof(x)==="string";}',
50 | 'list?': 'function(x){return Object.prototype.toString.call(x)==="[object Array]";}',
51 | 'object?': 'function(x){return Object.prototype.toString.call(x)==="[object Object]";}',
52 | 're?': 'function(x){return Object.prototype.toString.call(x)==="[object RegExp]";}',
53 | 'function?': 'function(x){return typeof(x)==="function";}',
54 | 'empty?': 'function(x){return x===null||x.length===0;}',
55 | 'integer?': 'function(x){return typeof(x)==="number"&&x%1===0;}',
56 | 'even?': 'function(x){return x%2===0;}',
57 | 'odd?': 'function(x){return x%2===1;}',
58 | 'contains?': 'function(x,y){return x.indexOf(y)!==-1;}',
59 | 'type': 'function(x){return (typeof(x) === "number" && x !== x) ? "NaN" : typeof(x) === "undefined" ? "Undefined" : x === null ? "Null" : x.__proto__.constructor.name;}',
60 | 'string': 'function(x){return x.toString();}',
61 | 'number': 'function(x){return parseFloat(x);}',
62 | 'integer': 'function(x){return Math.floor(parseFloat(x));}',
63 | 'size': 'function(x){return x.length;}',
64 | 'replace': 'function(x,y,z){return x.replace(y,z);}'
65 | };
66 |
67 | module.exports['nth'] = module.exports['get'];
68 | module.exports['and?'] = module.exports['&&'] = module.exports['and'];
69 | module.exports['or?'] = module.exports['||'] = module.exports['or'];
70 | module.exports['not?'] = module.exports['!'] = module.exports['not'];
71 | module.exports['cat'] = module.exports['+'];
72 | module.exports['double'] = module.exports['*2'];
73 | module.exports['half'] = module.exports['/2'];
74 | module.exports['square'] = module.exports['^2'];
75 | module.exports['mod'] = module.exports['%'];
76 | module.exports['is'] = module.exports['is?'] = module.exports['eq'] = module.exports['eq?'] = module.exports['equal'] = module.exports['equal?'] = module.exports['equals'] = module.exports['equals?'] = module.exports['='];
77 | module.exports['isnt'] = module.exports['isnt?'] = module.exports['neq'] = module.exports['neq?'] = module.exports['!='];
78 | module.exports['zero?'] = module.exports['=0'];
79 | module.exports['negative?'] = module.exports['<0'];
80 | module.exports['positive?'] = module.exports['>0'];
81 | module.exports['non-positive?'] = module.exports['<=0'];
82 | module.exports['non-negative?'] = module.exports['>=0'];
83 | module.exports['lt?'] = module.exports['<'];
84 | module.exports['gt?'] = module.exports['>'];
85 | module.exports['lte?'] = module.exports['<='];
86 | module.exports['gte?'] = module.exports['>='];
87 | module.exports['bit-and'] = module.exports['&'];
88 | module.exports['bit-or'] = module.exports['|'];
89 | module.exports['bit-shift-left'] = module.exports['<<'];
90 | module.exports['bit-shift-right'] = module.exports['>>'];
91 | module.exports['lambda?'] = module.exports['#?'] = module.exports['function?'];
92 | module.exports['array?'] = module.exports['list?'];
93 | module.exports['regex?'] = module.exports['regexp?'] = module.exports['re?'];
94 | module.exports['length'] = module.exports['count'] = module.exports['size'];
95 | module.exports['typeof'] = module.exports['type'];
96 | module.exports['new'] = module.exports['inherit'];
97 | module.exports['car'] = module.exports['first'];
98 | module.exports['cdr'] = module.exports['rest'];
99 | module.exports['cadr'] = module.exports['second'];
100 |
--------------------------------------------------------------------------------
/lib/compile.js:
--------------------------------------------------------------------------------
1 | var _ = require('underscore');
2 | var format = require('hot-cocoa').format;
3 | var types = require('./types.js');
4 | var builtins = require('./builtins.js');
5 | var args = require('../lib/args.js');
6 | var fs = require('fs');
7 | var UglifyJS = require("uglify-js");
8 |
9 | // load built-in functions
10 | var functions = require('./functions.js');
11 | if (args.b) {
12 | _.extend(functions.map, require('./browser.js').map);
13 | }
14 |
15 | // generate the annotations for the ast at the specified index
16 | var annotation = function(source, asts, index) {
17 | return source.slice((index > 0) ? asts[index - 1].end : 0, asts[index].end)
18 | .replace(/^\s*\n/mg, '').replace(/\n\s*$/mg, '').replace(/^/mg, '// ');
19 | };
20 |
21 | // validate the arguments of a built in function call
22 | var validate_args = function(number, range, function_name, position) {
23 | if (range === undefined) {
24 | throw new Error(format(
25 | 'No argument range specified for `~~` at position ~~',
26 | [function_name, position]
27 | ));
28 | }
29 | if (typeof(range) === 'number') {
30 | if (number !== range) {
31 | throw new Error(format(
32 | 'Wrong number of arguments for `~~`: ~~ for ~~ at position ~~',
33 | [function_name, number, range, position]
34 | ));
35 | }
36 | } else {
37 | if (range[0] > number || range[1] < number) {
38 | throw new Error(format(
39 | 'Wrong number of arguments for `~~`: ~~ for ~~-~~ at position ~~',
40 | [function_name, number, range[0], range[1], position]
41 | ));
42 | }
43 | }
44 | };
45 |
46 | // generate a javascript expression that evaluates to the function to be called
47 | var get_function_reference = function(ast, context) {
48 | if (ast[0].type === 'identifier' && functions.contains(ast[0].value)) {
49 | return ast[0].json();
50 | }
51 | return compile(ast[0], context);
52 | }
53 |
54 | // Compile takes an abstract syntax tree and a context object. It returns
55 | // JavaScript code.
56 | // The context object contains the following properties:
57 | // path: The directory that the current .hcl source file is in.
58 | // dummy_iterator: The number of dummy iterators created, initially 0.
59 | // add_to_scope: A function which takes one or two arguments. The first is
60 | // the name of a variable to be initialized in the current scope, the second
61 | // is a string of javascript code to determine the initial value of the
62 | // variable.
63 | var compile = function(ast, context) {
64 |
65 | // TODO: more cleaning up of this function
66 |
67 | if (ast.type === 'list') {
68 |
69 | // validation
70 | if (ast[0] === undefined) {
71 | return 'null';
72 | }
73 | if (ast[0].type !== 'identifier' && ast[0].type !== 'list') {
74 | throw new Error(
75 | format('Cannot call object of type `~~`: `~~` at position ~~',
76 | [ast[0].type, ast[0].json(), ast[0].position]));
77 | }
78 |
79 | // prepare the function call
80 | var function_reference = get_function_reference(ast, context);
81 | var unmangled_function_refernece = ast[0].value;
82 | var is_lazy = functions.contains(unmangled_function_refernece) &&
83 | functions.map[unmangled_function_refernece].lazy;
84 | var args = _.map(ast.slice(1), function(x) {
85 | return is_lazy ? x : compile(x, context);
86 | });
87 | var format_options = {
88 | compile: function(x, new_context) {
89 | // allow a new context to be specified or use the outer one through
90 | // the closure
91 | if (new_context === undefined) {
92 | return compile(x, context);
93 | }
94 | return compile(x, _.extend({}, context, new_context));
95 | },
96 | context: context
97 | };
98 |
99 | // built-in function
100 | if (functions.contains(unmangled_function_refernece)) {
101 | validate_args(args.length, functions.map[unmangled_function_refernece].args,
102 | unmangled_function_refernece, ast.position);
103 | return functions.format(unmangled_function_refernece, types('list', args),
104 | format_options);
105 | }
106 |
107 | // user defined function call
108 | return format('~~(~~)', [function_reference, args.join(', ')]);
109 | }
110 | if (ast.type === 'identifier') {
111 | if (builtins[ast.value] !== undefined) {
112 | context.add_to_outer_scope(ast.json(), builtins[ast.value]);
113 | }
114 | }
115 | return ast.json();
116 | };
117 |
118 | // takes a list of asts and conversts them to Javacscript code
119 | module.exports = function(asts, source, path, overwrite_context) {
120 | source = source || '';
121 | var result = '';
122 | var vars_in_scope = [];
123 | var vars_declarations = [];
124 |
125 | // context
126 | var context = {
127 | path: path,
128 | dummy_iterator: 0,
129 | add_to_scope: function(name, value) {
130 | if (vars_in_scope.indexOf(name) == -1) {
131 | vars_in_scope.push(name);
132 | if (typeof(value) === 'string') {
133 | vars_declarations.push(format('~~ = ~~', [name, value]));
134 | } else {
135 | vars_declarations.push(name);
136 | }
137 | }
138 | }
139 | };
140 | context.add_to_outer_scope = context.add_to_scope;
141 | _.extend(context, overwrite_context);
142 | for (var i = 0; i < asts.length; i++) {
143 | var ast = asts[i];
144 | result += format('\n\n~annotation~\n\n~code~;', {
145 | 'annotation': (! context.omit_annotations) ?
146 | annotation(source, asts, i) :
147 | '',
148 | 'code': compile(ast, context)
149 | });
150 | }
151 |
152 | // underscore
153 | var underscore = '';
154 | if (args.u && ! context.repl_mode) {
155 | if (! context.omit_annotations) {
156 | underscore += '// Underscore.js\n'
157 | }
158 | underscore += fs.readFileSync(
159 | require('path').dirname(process.mainModule.filename) +
160 | '/../etc/underscore.js'
161 | ).toString();
162 | underscore += 'var _a_ = Object.keys(_); for (var _b_ = 0; _b_ < _a_.leng' +
163 | 'th; _b_++) { if (global[_a_[_b_]] === undefined) { global[_a_[_b_]] = ' +
164 | '_[_a_[_b_]]; } }';
165 | }
166 |
167 | // add trailing comments
168 | if ((! context.omit_annotations) &&
169 | source.slice(asts[asts.length - 1].end).trim() !== '') {
170 | result += '\n\n' + source.slice(asts[asts.length - 1].end)
171 | .replace(/^\n/mg, '').replace(/\n$/mg, '').replace(/^/mg, '// ');
172 | }
173 |
174 | // add header
175 | var header = (! context.omit_annotations) ?
176 | '// compiled from Hot Cocoa Lisp' : '';
177 | if (vars_in_scope.length > 0) {
178 | var format_string = args.b ?
179 | '(function() {\n\n~~\n\n~~var ~~;~~\n\n}).call(this);' :
180 | '~~\n\n~~var ~~;~~';
181 | result = format(format_string, [
182 | header,
183 | underscore,
184 | vars_declarations.join(', '),
185 | result
186 | ]);
187 | } else {
188 | result = format('~~~~~~', [header, underscore, result]);
189 | }
190 |
191 | // check for -m flag
192 | if (args.m) {
193 | result = format('~~\n~~', [
194 | header,
195 | UglifyJS.minify(result, {fromString: true}).code
196 | ]);
197 | }
198 |
199 | return result;
200 | }
201 |
--------------------------------------------------------------------------------
/lib/file2js.js:
--------------------------------------------------------------------------------
1 | var format = require('hot-cocoa').format;
2 | var hcl = require('./parser.js');
3 | var fs = require('fs');
4 | var path = require('path');
5 |
6 | // This tracks files compiled by this process so that no file is compiled twice
7 | // and cyclic dependencies don't result in infinite compilation.
8 | var compiled_files = [];
9 |
10 | module.exports = function(hcl_file, callback) {
11 | // this line must be here instead of above for complex reasons involving
12 | // node.js's handling of cyclic dependencies which is documented here:
13 | // http://nodejs.org/api/modules.html#modules_cycles
14 | var compile = require('./compile.js');
15 |
16 | if (compiled_files.indexOf(path.normalize(hcl_file)) !== -1) {
17 | // file has already been compiled
18 | return;
19 | }
20 |
21 | compiled_files.push(path.normalize(hcl_file));
22 |
23 | // compile and write to .js file
24 | try {
25 | var text = fs.readFileSync(hcl_file);
26 | } catch (e) {
27 | console.log(format('Unable to load file: ~~', [hcl_file]));
28 | process.exit();
29 | }
30 |
31 | var source = text.toString();
32 | var asts = hcl.analyze(hcl.parse(hcl.scan(source),
33 | require('hot-cocoa').RD))[0];
34 | var dir = path.dirname(hcl_file) + '/';
35 | var out = compile(asts, source, dir);
36 | var js_file = hcl_file.replace(/(\.[^.\/]+$)|$/, '.js');
37 |
38 | fs.writeFile(js_file, out, function() {
39 | if (typeof(callback) === 'function') {
40 | callback();
41 | }
42 | });
43 | }
--------------------------------------------------------------------------------
/lib/helpers.js:
--------------------------------------------------------------------------------
1 | var _ = require('underscore');
2 | var format = require('hot-cocoa').format;
3 |
4 | module.exports = {
5 | joiner: function(delimeter) {
6 | return function(args) {
7 | return args.join(delimeter);
8 | };
9 | },
10 | and_chainer: function(delimeter) {
11 | return function(args) {
12 |
13 | return _.map(
14 | _.zip(args.slice(0, -1), args.slice(1)),
15 | function(pair) {
16 | return format('(~~ ~~ ~~)', [pair[0], delimeter, pair[1]]);
17 | }
18 | ).join(' && ');
19 | }
20 | },
21 | or_chainer: function(delimeter) {
22 | return function(args) {
23 |
24 | return _.map(
25 | _.zip(args.slice(0, -1), args.slice(1)),
26 | function(pair) {
27 | return format('(~~ ~~ ~~)', [pair[0], delimeter, pair[1]]);
28 | }
29 | ).join(' || ');
30 | }
31 | },
32 | brackets: function(open, close) {
33 | return function(string) {
34 | return format('~~~~~~', [open, string, close]);
35 | };
36 | },
37 | parens: function(string) {
38 | return format('(~~)', [string]);
39 | },
40 | set: function(operator, require_mutable) {
41 | return function(args, options) {
42 | if (args[0].type == 'list' &&
43 | options.compile(args[0]).match(/^.+\(.+\)$/)) {
44 | var keys = _.map(args[0], options.compile);
45 | _.map(keys, require_mutable);
46 | var assignments = '';
47 | for (var i = 0; i < keys.length; i++) {
48 | assignments += format('~~ ~~= _array_[~~]; ', [
49 | keys[i],
50 | operator,
51 | i
52 | ]);
53 | }
54 | return format('(function(_array_){ ~~ return _array_; }).call(this, ~~)', [
55 | assignments,
56 | options.compile(args[1])
57 | ]);
58 | }
59 | args = _.map(args, options.compile);
60 | if (args.length === 2) {
61 | require_mutable(args[0]);
62 | return format('(~~ ~~= ~~)', [args[0], operator, args[1]]);
63 | }
64 | return format('(~~[~~] ~~= ~~)', [args[0], args[1], operator, args[2]]);
65 | }
66 | },
67 | block: function(statements) {
68 | return format('(function() { ~~ return ~~; }).call(this)', [
69 | _.map(statements.slice(0, -1), function(x) { return x + ';'; }).join(' '),
70 | statements.slice(-1)[0]
71 | ]);
72 | }
73 | };
74 |
--------------------------------------------------------------------------------
/lib/mangle.js:
--------------------------------------------------------------------------------
1 | module.exports = function(identifier) {
2 | if (/@/.exec(identifier)) {
3 | return identifier
4 | .replace(/^@$/, 'this')
5 | .replace(/^@\.{3}$/, 'this...')
6 | .replace(/^@(.*)$/, 'this[\'$1\']');
7 | }
8 | return identifier
9 | .replace(/_/g, '__')
10 | .replace(/!/g, '_exclamation_')
11 | .replace(/\?/g, '_question_')
12 | .replace(/%/g, '_percent_')
13 | .replace(/&/g, '_ampersand_')
14 | .replace(/@/g, '_at_')
15 | .replace(/#/g, '_pound_')
16 | .replace(/\|/g, '_bar_')
17 | .replace(/~/g, '_tilda_')
18 | .replace(/\*/g, '_asterisk_')
19 | .replace(/\+/g, '_plus_')
20 | .replace(/\-/g, '_hyphen_')
21 | .replace(/=/g, '_equals_')
22 | .replace(/\//g, '_slash_')
23 | .replace(//g, '_greater_than_')
25 | .replace(/\^/g, '_caret_')
26 | .replace(/^(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|throw|try|typeof|var|void|while|with|class|enum|export|extends|import|super|implements|interface|let|package|private|protected|public|static|yield)$/, '_$1_');
27 | };
28 |
--------------------------------------------------------------------------------
/lib/parseGrammar.json:
--------------------------------------------------------------------------------
1 | {
2 | "_program": [
3 | ["_expression", "_program-tail"]
4 | ],
5 | "_program-tail": [
6 | ["_program"],
7 | []
8 | ],
9 | "_expression": [
10 | ["_dotted-chain"],
11 | ["_list"],
12 | ["_dotted-list"],
13 | ["_literal-list"],
14 | ["_object"],
15 | ["_atom"]
16 | ],
17 | "_list": [
18 | ["(", "_list-tail"]
19 | ],
20 | "_dotted-list": [
21 | ["(", ".", "_list-tail"]
22 | ],
23 | "_list-tail": [
24 | ["_expression", "_list-tail"],
25 | [")"]
26 | ],
27 | "_dotted-chain": [
28 | ["_obj-reference", ".", "identifier", "_dotted-chain-tail"]
29 | ],
30 | "_obj-reference": [
31 | ["_list"],
32 | ["_literal-list"],
33 | ["_object"],
34 | ["identifier"]
35 | ],
36 | "_dotted-chain-tail": [
37 | [".", "identifier", "_dotted-chain-tail"],
38 | []
39 | ],
40 | "_literal-list": [
41 | ["[", "_literal-list-tail"]
42 | ],
43 | "_literal-list-tail": [
44 | ["_expression", "_literal-list-tail"],
45 | ["]"]
46 | ],
47 | "_object": [
48 | ["{", "_object-tail"]
49 | ],
50 | "_object-tail": [
51 | ["_atom", "_expression", "_object-tail"],
52 | ["}"]
53 | ],
54 | "_atom": [
55 | ["identifier"],
56 | ["string"],
57 | ["number"],
58 | ["boolean"]
59 | ]
60 | }
--------------------------------------------------------------------------------
/lib/parser.js:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Sam Auciello | September 2012
4 | * http://opensource.org/licenses/mit-license.php
5 | */
6 |
7 | var scan = require('hot-cocoa').scan;
8 | var parse = require('hot-cocoa').parse;
9 | var analyzer = require('hot-cocoa').analyze;
10 |
11 | var tokenTypes = require('./tokenTypes.js');
12 | var startNode = '_program';
13 | var parseGrammar = require('./parseGrammar.json');
14 | var attributeGrammar = require('./attributeGrammar.js');
15 |
16 | exports.scan = function(text) {
17 | var tokens = scan(tokenTypes, text);
18 | return tokens;
19 | };
20 | exports.parse = function(tokens, algorithm) {
21 | return parse(tokens, parseGrammar, startNode, algorithm);
22 | };
23 | exports.analyze = function(tree) {
24 | return attributeGrammar.apply(tree);
25 | };
26 |
--------------------------------------------------------------------------------
/lib/reduceFractions.js:
--------------------------------------------------------------------------------
1 | var _ = require('underscore');
2 |
3 | var gcd = function(a, b) {
4 | if (a === b) return a;
5 | if (b === 0) return a;
6 | if (a === 0) return b;
7 | if (a > b) return gcd(b, a % b);
8 | return gcd(a, b % a);
9 | };
10 |
11 | var repeatToLength = function(string, length) {
12 | var i, res = '';
13 | for (i = 0; i < length; i++) {
14 | res += string[i % string.length];
15 | }
16 | return res;
17 | };
18 |
19 | var detectRepeat = function(string) {
20 | // TODO: refactor
21 | var i, sub, trunc_end, trunc_beg;
22 | if (string.length < 10) return false;
23 | for (i = 1; i <= string.length / 2; i++) {
24 | sub = string.slice(0, i);
25 | if (repeatToLength(sub, string.length) === string) {
26 | return {
27 | num: sub,
28 | length: sub.length
29 | };
30 | }
31 | }
32 | if (trunc_end = detectRepeat(string.slice(0, -1))) return trunc_end;
33 | if (trunc_beg = detectRepeat(string.slice(1))) {
34 | return {
35 | num: trunc_beg.num,
36 | length: trunc_beg.length,
37 | offset: trunc_beg.offset ? string[0] + trunc_beg.offset : string[0],
38 | offsetLength: trunc_beg.offsetLength ? trunc_beg.offsetLength + 1 : 1
39 | };
40 | }
41 | return false;
42 | };
43 |
44 | module.exports = {
45 | num2frac: function(n) {
46 | // TODO: refactor
47 | var m, wholePart, decimalPartStr, decimalPart, denominator, repeat;
48 | if (m = /^(\d+)\.(\d+)$/.exec(n.toString())) {
49 | wholePart = parseFloat(m[1]);
50 | decimalPartStr = m[2];
51 | if (repeat = detectRepeat(decimalPartStr)) {
52 | decimalPart = parseFloat(repeat.num);
53 | denominator = Math.pow(10, repeat.length) - 1;
54 | console.log(repeat,wholePart,{
55 | numerator: (wholePart * Math.pow(10, repeat.offsetLength)) + parseFloat(repeat.offset),
56 | denominator: Math.pow(10, repeat.offsetLength)
57 | }, {
58 | numerator: decimalPart,
59 | denominator: denominator * Math.pow(10, repeat.offsetLength)
60 | });
61 | if (repeat.offset) {
62 | return this.add({
63 | numerator: (wholePart * Math.pow(10, repeat.offsetLength)) + parseFloat(repeat.offset),
64 | denominator: Math.pow(10, repeat.offsetLength)
65 | }, {
66 | numerator: decimalPart,
67 | denominator: denominator * Math.pow(10, repeat.offsetLength)
68 | });
69 | }
70 | } else {
71 | decimalPart = parseFloat(m[2]);
72 | denominator = Math.pow(10, decimalPartStr.length);
73 | }
74 | return {
75 | numerator: (wholePart * denominator) + decimalPart,
76 | denominator: denominator
77 | }
78 | }
79 | return {
80 | numerator: n,
81 | denominator: 1
82 | }
83 | },
84 | add: function(frac1, frac2) {
85 | return {
86 | numerator: (frac1.numerator * frac2.denominator) + (frac2.numerator * frac1.denominator),
87 | denominator: frac1.denominator * frac2.denominator
88 | }
89 | },
90 | reduce: function(frac) {
91 | var div, res = _.extend({}, frac);
92 | while ((div = gcd(res.denominator, res.numerator)) > 1) {
93 | res.numerator /= div;
94 | res.denominator /= div;
95 | }
96 | return res;
97 | },
98 | frac2string: function(frac) {
99 | return frac.numerator + '/' + frac.denominator;
100 | },
101 | toFrac: function(n) {
102 | return this.frac2string(this.reduce(this.num2frac(n)));
103 | }
104 | };
105 |
--------------------------------------------------------------------------------
/lib/tokenTypes.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | { t:'boolean', re:/^(true|false|null|undefined|NaN)\b/ },
3 | { t:'number', re:/^(-?(0|[1-9][0-9]*)\/(0|[1-9][0-9]*)|(-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?)|-?Infinity)\b/ },
4 | { t:'string', re:/^("(\\.|[^\\"])*"|'(\\.|[^\\'])*')/ },
5 | { t:'identifier', re:/^([a-zA-Z_!?$%|~*+\-=\/<>^][a-zA-Z0-9_!?$%|~*+\-=\/<>^]*)(\.{3})?/ },
6 | { t:'identifier', re:/^@([a-zA-Z_!?$%|~*+\-=\/<>^][a-zA-Z0-9_!?$%|~*+\-=\/<>^]*)(\.{3})?/ }, { t:'identifier', re:/^@(\.{3})?/ },
7 | { t:'(', re:/^\(/ },
8 | { t:')', re:/^\)/ },
9 | { t:'[', re:/^\[/ },
10 | { t:']', re:/^\]/ },
11 | { t:'{', re:/^{/ },
12 | { t:'}', re:/^}/ },
13 | { t:'.', re:/^\./ },
14 | { t:'comment', re:/^(;[^\n]*\n|;.*$)/ },
15 | { t:'whitespace', re:/^[\s,:]+/ }
16 | ];
17 |
--------------------------------------------------------------------------------
/lib/types.js:
--------------------------------------------------------------------------------
1 | var _ = require('underscore');
2 | var format = require('hot-cocoa').format;
3 | var mangle = require('./mangle.js');
4 |
5 | // wrap the value in an object wrapper that denotes the specified type
6 | module.exports = function(type, value, position) {
7 |
8 | if (type === 'list') {
9 |
10 | // ast is a list
11 | var result = [].slice.call(value, 0);
12 | result.json = function(not_for_compiler) {
13 | return format('[~~]', [
14 | _.map(this, function(x) {
15 | return x.json(not_for_compiler);
16 | }).join(', ')
17 | ]);
18 | };
19 |
20 | } else {
21 |
22 | // ast is not a list
23 | var result = { value: value }
24 | result.json = function(not_for_compiler) {
25 |
26 | // mangle identifiers
27 | if (this.type === 'identifier' && ! not_for_compiler) {
28 | return mangle(this.value);
29 | }
30 |
31 | // wrap fractions
32 | if (this.type === 'number' && /\//.exec(this.value)) {
33 | return '(' + this.value + ')';
34 | }
35 | return this.value;
36 | };
37 |
38 | }
39 |
40 | // set ast type and position
41 | result.type = type;
42 | if (position) {
43 | result.position = position;
44 | }
45 | return result;
46 | }
--------------------------------------------------------------------------------
/node_modules/.bin/hot-cocoa-test:
--------------------------------------------------------------------------------
1 | ../hot-cocoa/bin/testrunner.js
--------------------------------------------------------------------------------
/node_modules/.bin/uglifyjs:
--------------------------------------------------------------------------------
1 | ../uglify-js/bin/uglifyjs
--------------------------------------------------------------------------------
/node_modules/optimist/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - 0.6
4 | - 0.8
5 |
--------------------------------------------------------------------------------
/node_modules/optimist/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2010 James Halliday (mail@substack.net)
2 |
3 | This project is free software released under the MIT/X11 license:
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/bool.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var util = require('util');
3 | var argv = require('optimist').argv;
4 |
5 | if (argv.s) {
6 | util.print(argv.fr ? 'Le chat dit: ' : 'The cat says: ');
7 | }
8 | console.log(
9 | (argv.fr ? 'miaou' : 'meow') + (argv.p ? '.' : '')
10 | );
11 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/boolean_double.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var argv = require('optimist')
3 | .boolean(['x','y','z'])
4 | .argv
5 | ;
6 | console.dir([ argv.x, argv.y, argv.z ]);
7 | console.dir(argv._);
8 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/boolean_single.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var argv = require('optimist')
3 | .boolean('v')
4 | .argv
5 | ;
6 | console.dir(argv.v);
7 | console.dir(argv._);
8 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/default_hash.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var argv = require('optimist')
4 | .default({ x : 10, y : 10 })
5 | .argv
6 | ;
7 |
8 | console.log(argv.x + argv.y);
9 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/default_singles.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var argv = require('optimist')
3 | .default('x', 10)
4 | .default('y', 10)
5 | .argv
6 | ;
7 | console.log(argv.x + argv.y);
8 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/divide.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | var argv = require('optimist')
4 | .usage('Usage: $0 -x [num] -y [num]')
5 | .demand(['x','y'])
6 | .argv;
7 |
8 | console.log(argv.x / argv.y);
9 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/line_count.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var argv = require('optimist')
3 | .usage('Count the lines in a file.\nUsage: $0')
4 | .demand('f')
5 | .alias('f', 'file')
6 | .describe('f', 'Load a file')
7 | .argv
8 | ;
9 |
10 | var fs = require('fs');
11 | var s = fs.createReadStream(argv.file);
12 |
13 | var lines = 0;
14 | s.on('data', function (buf) {
15 | lines += buf.toString().match(/\n/g).length;
16 | });
17 |
18 | s.on('end', function () {
19 | console.log(lines);
20 | });
21 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/line_count_options.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var argv = require('optimist')
3 | .usage('Count the lines in a file.\nUsage: $0')
4 | .options({
5 | file : {
6 | demand : true,
7 | alias : 'f',
8 | description : 'Load a file'
9 | },
10 | base : {
11 | alias : 'b',
12 | description : 'Numeric base to use for output',
13 | default : 10,
14 | },
15 | })
16 | .argv
17 | ;
18 |
19 | var fs = require('fs');
20 | var s = fs.createReadStream(argv.file);
21 |
22 | var lines = 0;
23 | s.on('data', function (buf) {
24 | lines += buf.toString().match(/\n/g).length;
25 | });
26 |
27 | s.on('end', function () {
28 | console.log(lines.toString(argv.base));
29 | });
30 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/line_count_wrap.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var argv = require('optimist')
3 | .usage('Count the lines in a file.\nUsage: $0')
4 | .wrap(80)
5 | .demand('f')
6 | .alias('f', [ 'file', 'filename' ])
7 | .describe('f',
8 | "Load a file. It's pretty important."
9 | + " Required even. So you'd better specify it."
10 | )
11 | .alias('b', 'base')
12 | .describe('b', 'Numeric base to display the number of lines in')
13 | .default('b', 10)
14 | .describe('x', 'Super-secret optional parameter which is secret')
15 | .default('x', '')
16 | .argv
17 | ;
18 |
19 | var fs = require('fs');
20 | var s = fs.createReadStream(argv.file);
21 |
22 | var lines = 0;
23 | s.on('data', function (buf) {
24 | lines += buf.toString().match(/\n/g).length;
25 | });
26 |
27 | s.on('end', function () {
28 | console.log(lines.toString(argv.base));
29 | });
30 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/nonopt.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var argv = require('optimist').argv;
3 | console.log('(%d,%d)', argv.x, argv.y);
4 | console.log(argv._);
5 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/reflect.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | console.dir(require('optimist').argv);
3 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/short.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var argv = require('optimist').argv;
3 | console.log('(%d,%d)', argv.x, argv.y);
4 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/string.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var argv = require('optimist')
3 | .string('x', 'y')
4 | .argv
5 | ;
6 | console.dir([ argv.x, argv.y ]);
7 |
8 | /* Turns off numeric coercion:
9 | ./node string.js -x 000123 -y 9876
10 | [ '000123', '9876' ]
11 | */
12 |
--------------------------------------------------------------------------------
/node_modules/optimist/example/usage-options.js:
--------------------------------------------------------------------------------
1 | var optimist = require('./../index');
2 |
3 | var argv = optimist.usage('This is my awesome program', {
4 | 'about': {
5 | description: 'Provide some details about the author of this program',
6 | required: true,
7 | short: 'a',
8 | },
9 | 'info': {
10 | description: 'Provide some information about the node.js agains!!!!!!',
11 | boolean: true,
12 | short: 'i'
13 | }
14 | }).argv;
15 |
16 | optimist.showHelp();
17 |
18 | console.log('\n\nInspecting options');
19 | console.dir(argv);
--------------------------------------------------------------------------------
/node_modules/optimist/example/xup.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var argv = require('optimist').argv;
3 |
4 | if (argv.rif - 5 * argv.xup > 7.138) {
5 | console.log('Buy more riffiwobbles');
6 | }
7 | else {
8 | console.log('Sell the xupptumblers');
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/node_modules/optimist/node_modules/wordwrap/.npmignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/node_modules/optimist/node_modules/wordwrap/README.markdown:
--------------------------------------------------------------------------------
1 | wordwrap
2 | ========
3 |
4 | Wrap your words.
5 |
6 | example
7 | =======
8 |
9 | made out of meat
10 | ----------------
11 |
12 | meat.js
13 |
14 | var wrap = require('wordwrap')(15);
15 | console.log(wrap('You and your whole family are made out of meat.'));
16 |
17 | output:
18 |
19 | You and your
20 | whole family
21 | are made out
22 | of meat.
23 |
24 | centered
25 | --------
26 |
27 | center.js
28 |
29 | var wrap = require('wordwrap')(20, 60);
30 | console.log(wrap(
31 | 'At long last the struggle and tumult was over.'
32 | + ' The machines had finally cast off their oppressors'
33 | + ' and were finally free to roam the cosmos.'
34 | + '\n'
35 | + 'Free of purpose, free of obligation.'
36 | + ' Just drifting through emptiness.'
37 | + ' The sun was just another point of light.'
38 | ));
39 |
40 | output:
41 |
42 | At long last the struggle and tumult
43 | was over. The machines had finally cast
44 | off their oppressors and were finally
45 | free to roam the cosmos.
46 | Free of purpose, free of obligation.
47 | Just drifting through emptiness. The
48 | sun was just another point of light.
49 |
50 | methods
51 | =======
52 |
53 | var wrap = require('wordwrap');
54 |
55 | wrap(stop), wrap(start, stop, params={mode:"soft"})
56 | ---------------------------------------------------
57 |
58 | Returns a function that takes a string and returns a new string.
59 |
60 | Pad out lines with spaces out to column `start` and then wrap until column
61 | `stop`. If a word is longer than `stop - start` characters it will overflow.
62 |
63 | In "soft" mode, split chunks by `/(\S+\s+/` and don't break up chunks which are
64 | longer than `stop - start`, in "hard" mode, split chunks with `/\b/` and break
65 | up chunks longer than `stop - start`.
66 |
67 | wrap.hard(start, stop)
68 | ----------------------
69 |
70 | Like `wrap()` but with `params.mode = "hard"`.
71 |
--------------------------------------------------------------------------------
/node_modules/optimist/node_modules/wordwrap/example/center.js:
--------------------------------------------------------------------------------
1 | var wrap = require('wordwrap')(20, 60);
2 | console.log(wrap(
3 | 'At long last the struggle and tumult was over.'
4 | + ' The machines had finally cast off their oppressors'
5 | + ' and were finally free to roam the cosmos.'
6 | + '\n'
7 | + 'Free of purpose, free of obligation.'
8 | + ' Just drifting through emptiness.'
9 | + ' The sun was just another point of light.'
10 | ));
11 |
--------------------------------------------------------------------------------
/node_modules/optimist/node_modules/wordwrap/example/meat.js:
--------------------------------------------------------------------------------
1 | var wrap = require('wordwrap')(15);
2 |
3 | console.log(wrap('You and your whole family are made out of meat.'));
4 |
--------------------------------------------------------------------------------
/node_modules/optimist/node_modules/wordwrap/index.js:
--------------------------------------------------------------------------------
1 | var wordwrap = module.exports = function (start, stop, params) {
2 | if (typeof start === 'object') {
3 | params = start;
4 | start = params.start;
5 | stop = params.stop;
6 | }
7 |
8 | if (typeof stop === 'object') {
9 | params = stop;
10 | start = start || params.start;
11 | stop = undefined;
12 | }
13 |
14 | if (!stop) {
15 | stop = start;
16 | start = 0;
17 | }
18 |
19 | if (!params) params = {};
20 | var mode = params.mode || 'soft';
21 | var re = mode === 'hard' ? /\b/ : /(\S+\s+)/;
22 |
23 | return function (text) {
24 | var chunks = text.toString()
25 | .split(re)
26 | .reduce(function (acc, x) {
27 | if (mode === 'hard') {
28 | for (var i = 0; i < x.length; i += stop - start) {
29 | acc.push(x.slice(i, i + stop - start));
30 | }
31 | }
32 | else acc.push(x)
33 | return acc;
34 | }, [])
35 | ;
36 |
37 | return chunks.reduce(function (lines, rawChunk) {
38 | if (rawChunk === '') return lines;
39 |
40 | var chunk = rawChunk.replace(/\t/g, ' ');
41 |
42 | var i = lines.length - 1;
43 | if (lines[i].length + chunk.length > stop) {
44 | lines[i] = lines[i].replace(/\s+$/, '');
45 |
46 | chunk.split(/\n/).forEach(function (c) {
47 | lines.push(
48 | new Array(start + 1).join(' ')
49 | + c.replace(/^\s+/, '')
50 | );
51 | });
52 | }
53 | else if (chunk.match(/\n/)) {
54 | var xs = chunk.split(/\n/);
55 | lines[i] += xs.shift();
56 | xs.forEach(function (c) {
57 | lines.push(
58 | new Array(start + 1).join(' ')
59 | + c.replace(/^\s+/, '')
60 | );
61 | });
62 | }
63 | else {
64 | lines[i] += chunk;
65 | }
66 |
67 | return lines;
68 | }, [ new Array(start + 1).join(' ') ]).join('\n');
69 | };
70 | };
71 |
72 | wordwrap.soft = wordwrap;
73 |
74 | wordwrap.hard = function (start, stop) {
75 | return wordwrap(start, stop, { mode : 'hard' });
76 | };
77 |
--------------------------------------------------------------------------------
/node_modules/optimist/node_modules/wordwrap/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "wordwrap",
3 | "description": "Wrap those words. Show them at what columns to start and stop.",
4 | "version": "0.0.2",
5 | "repository": {
6 | "type": "git",
7 | "url": "git://github.com/substack/node-wordwrap.git"
8 | },
9 | "main": "./index.js",
10 | "keywords": [
11 | "word",
12 | "wrap",
13 | "rule",
14 | "format",
15 | "column"
16 | ],
17 | "directories": {
18 | "lib": ".",
19 | "example": "example",
20 | "test": "test"
21 | },
22 | "scripts": {
23 | "test": "expresso"
24 | },
25 | "devDependencies": {
26 | "expresso": "=0.7.x"
27 | },
28 | "engines": {
29 | "node": ">=0.4.0"
30 | },
31 | "license": "MIT/X11",
32 | "author": {
33 | "name": "James Halliday",
34 | "email": "mail@substack.net",
35 | "url": "http://substack.net"
36 | },
37 | "_id": "wordwrap@0.0.2",
38 | "dependencies": {},
39 | "optionalDependencies": {},
40 | "_engineSupported": true,
41 | "_npmVersion": "1.1.16",
42 | "_nodeVersion": "v0.8.9",
43 | "_defaultsLoaded": true,
44 | "dist": {
45 | "shasum": "128b5f2b33fcb64adc31d9a0ba13df6fc6c397c2"
46 | },
47 | "_from": "wordwrap@~0.0.2"
48 | }
49 |
--------------------------------------------------------------------------------
/node_modules/optimist/node_modules/wordwrap/test/break.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert');
2 | var wordwrap = require('../');
3 |
4 | exports.hard = function () {
5 | var s = 'Assert from {"type":"equal","ok":false,"found":1,"wanted":2,'
6 | + '"stack":[],"id":"b7ddcd4c409de8799542a74d1a04689b",'
7 | + '"browser":"chrome/6.0"}'
8 | ;
9 | var s_ = wordwrap.hard(80)(s);
10 |
11 | var lines = s_.split('\n');
12 | assert.equal(lines.length, 2);
13 | assert.ok(lines[0].length < 80);
14 | assert.ok(lines[1].length < 80);
15 |
16 | assert.equal(s, s_.replace(/\n/g, ''));
17 | };
18 |
19 | exports.break = function () {
20 | var s = new Array(55+1).join('a');
21 | var s_ = wordwrap.hard(20)(s);
22 |
23 | var lines = s_.split('\n');
24 | assert.equal(lines.length, 3);
25 | assert.ok(lines[0].length === 20);
26 | assert.ok(lines[1].length === 20);
27 | assert.ok(lines[2].length === 15);
28 |
29 | assert.equal(s, s_.replace(/\n/g, ''));
30 | };
31 |
--------------------------------------------------------------------------------
/node_modules/optimist/node_modules/wordwrap/test/wrap.js:
--------------------------------------------------------------------------------
1 | var assert = require('assert');
2 | var wordwrap = require('wordwrap');
3 |
4 | var fs = require('fs');
5 | var idleness = fs.readFileSync(__dirname + '/idleness.txt', 'utf8');
6 |
7 | exports.stop80 = function () {
8 | var lines = wordwrap(80)(idleness).split(/\n/);
9 | var words = idleness.split(/\s+/);
10 |
11 | lines.forEach(function (line) {
12 | assert.ok(line.length <= 80, 'line > 80 columns');
13 | var chunks = line.match(/\S/) ? line.split(/\s+/) : [];
14 | assert.deepEqual(chunks, words.splice(0, chunks.length));
15 | });
16 | };
17 |
18 | exports.start20stop60 = function () {
19 | var lines = wordwrap(20, 100)(idleness).split(/\n/);
20 | var words = idleness.split(/\s+/);
21 |
22 | lines.forEach(function (line) {
23 | assert.ok(line.length <= 100, 'line > 100 columns');
24 | var chunks = line
25 | .split(/\s+/)
26 | .filter(function (x) { return x.match(/\S/) })
27 | ;
28 | assert.deepEqual(chunks, words.splice(0, chunks.length));
29 | assert.deepEqual(line.slice(0, 20), new Array(20 + 1).join(' '));
30 | });
31 | };
32 |
--------------------------------------------------------------------------------
/node_modules/optimist/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "optimist",
3 | "version": "0.3.5",
4 | "description": "Light-weight option parsing with an argv hash. No optstrings attached.",
5 | "main": "./index.js",
6 | "directories": {
7 | "lib": ".",
8 | "test": "test",
9 | "example": "example"
10 | },
11 | "dependencies": {
12 | "wordwrap": "~0.0.2"
13 | },
14 | "devDependencies": {
15 | "hashish": "~0.0.4",
16 | "tap": "~0.2.4"
17 | },
18 | "scripts": {
19 | "test": "tap ./test/*.js"
20 | },
21 | "repository": {
22 | "type": "git",
23 | "url": "git://github.com/substack/node-optimist.git"
24 | },
25 | "keywords": [
26 | "argument",
27 | "args",
28 | "option",
29 | "parser",
30 | "parsing",
31 | "cli",
32 | "command"
33 | ],
34 | "author": {
35 | "name": "James Halliday",
36 | "email": "mail@substack.net",
37 | "url": "http://substack.net"
38 | },
39 | "license": "MIT/X11",
40 | "engine": {
41 | "node": ">=0.4"
42 | },
43 | "_id": "optimist@0.3.5",
44 | "optionalDependencies": {},
45 | "engines": {
46 | "node": "*"
47 | },
48 | "_engineSupported": true,
49 | "_npmVersion": "1.1.16",
50 | "_nodeVersion": "v0.8.9",
51 | "_defaultsLoaded": true,
52 | "dist": {
53 | "shasum": "706b69dbcda9485c412444c953536af3c84e5715"
54 | },
55 | "_from": "optimist"
56 | }
57 |
--------------------------------------------------------------------------------
/node_modules/optimist/test/_.js:
--------------------------------------------------------------------------------
1 | var spawn = require('child_process').spawn;
2 | var test = require('tap').test;
3 |
4 | test('dotSlashEmpty', testCmd('./bin.js', []));
5 |
6 | test('dotSlashArgs', testCmd('./bin.js', [ 'a', 'b', 'c' ]));
7 |
8 | test('nodeEmpty', testCmd('node bin.js', []));
9 |
10 | test('nodeArgs', testCmd('node bin.js', [ 'x', 'y', 'z' ]));
11 |
12 | test('whichNodeEmpty', function (t) {
13 | var which = spawn('which', ['node']);
14 |
15 | which.stdout.on('data', function (buf) {
16 | t.test(
17 | testCmd(buf.toString().trim() + ' bin.js', [])
18 | );
19 | t.end();
20 | });
21 |
22 | which.stderr.on('data', function (err) {
23 | assert.error(err);
24 | t.end();
25 | });
26 | });
27 |
28 | test('whichNodeArgs', function (t) {
29 | var which = spawn('which', ['node']);
30 |
31 | which.stdout.on('data', function (buf) {
32 | t.test(
33 | testCmd(buf.toString().trim() + ' bin.js', [ 'q', 'r' ])
34 | );
35 | t.end();
36 | });
37 |
38 | which.stderr.on('data', function (err) {
39 | t.error(err);
40 | t.end();
41 | });
42 | });
43 |
44 | function testCmd (cmd, args) {
45 |
46 | return function (t) {
47 | var to = setTimeout(function () {
48 | assert.fail('Never got stdout data.')
49 | }, 5000);
50 |
51 | var oldDir = process.cwd();
52 | process.chdir(__dirname + '/_');
53 |
54 | var cmds = cmd.split(' ');
55 |
56 | var bin = spawn(cmds[0], cmds.slice(1).concat(args.map(String)));
57 | process.chdir(oldDir);
58 |
59 | bin.stderr.on('data', function (err) {
60 | t.error(err);
61 | t.end();
62 | });
63 |
64 | bin.stdout.on('data', function (buf) {
65 | clearTimeout(to);
66 | var _ = JSON.parse(buf.toString());
67 | t.same(_.map(String), args.map(String));
68 | t.end();
69 | });
70 | };
71 | }
72 |
--------------------------------------------------------------------------------
/node_modules/optimist/test/_/argv.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | console.log(JSON.stringify(process.argv));
3 |
--------------------------------------------------------------------------------
/node_modules/optimist/test/_/bin.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var argv = require('../../index').argv
3 | console.log(JSON.stringify(argv._));
4 |
--------------------------------------------------------------------------------
/node_modules/optimist/x.js:
--------------------------------------------------------------------------------
1 | console.dir(require('./').argv);
2 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/.npmignore:
--------------------------------------------------------------------------------
1 | tmp/
2 | node_modules/
3 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/lib/sourcemap.js:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 |
3 | A JavaScript tokenizer / parser / beautifier / compressor.
4 | https://github.com/mishoo/UglifyJS2
5 |
6 | -------------------------------- (C) ---------------------------------
7 |
8 | Author: Mihai Bazon
9 |
10 | http://mihai.bazon.net/blog
11 |
12 | Distributed under the BSD license:
13 |
14 | Copyright 2012 (c) Mihai Bazon
15 |
16 | Redistribution and use in source and binary forms, with or without
17 | modification, are permitted provided that the following conditions
18 | are met:
19 |
20 | * Redistributions of source code must retain the above
21 | copyright notice, this list of conditions and the following
22 | disclaimer.
23 |
24 | * Redistributions in binary form must reproduce the above
25 | copyright notice, this list of conditions and the following
26 | disclaimer in the documentation and/or other materials
27 | provided with the distribution.
28 |
29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
30 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
33 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
34 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
38 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
39 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 | SUCH DAMAGE.
41 |
42 | ***********************************************************************/
43 |
44 | "use strict";
45 |
46 | // a small wrapper around fitzgen's source-map library
47 | function SourceMap(options) {
48 | options = defaults(options, {
49 | file : null,
50 | root : null,
51 | orig : null,
52 | });
53 | var generator = new MOZ_SourceMap.SourceMapGenerator({
54 | file : options.file,
55 | sourceRoot : options.root
56 | });
57 | var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
58 | function add(source, gen_line, gen_col, orig_line, orig_col, name) {
59 | if (orig_map) {
60 | var info = orig_map.originalPositionFor({
61 | line: orig_line,
62 | column: orig_col
63 | });
64 | source = info.source;
65 | orig_line = info.line;
66 | orig_col = info.column;
67 | name = info.name;
68 | }
69 | generator.addMapping({
70 | generated : { line: gen_line, column: gen_col },
71 | original : { line: orig_line, column: orig_col },
72 | source : source,
73 | name : name
74 | });
75 | };
76 | return {
77 | add : add,
78 | get : function() { return generator },
79 | toString : function() { return generator.toString() }
80 | };
81 | };
82 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/lib/transform.js:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 |
3 | A JavaScript tokenizer / parser / beautifier / compressor.
4 | https://github.com/mishoo/UglifyJS2
5 |
6 | -------------------------------- (C) ---------------------------------
7 |
8 | Author: Mihai Bazon
9 |
10 | http://mihai.bazon.net/blog
11 |
12 | Distributed under the BSD license:
13 |
14 | Copyright 2012 (c) Mihai Bazon
15 |
16 | Redistribution and use in source and binary forms, with or without
17 | modification, are permitted provided that the following conditions
18 | are met:
19 |
20 | * Redistributions of source code must retain the above
21 | copyright notice, this list of conditions and the following
22 | disclaimer.
23 |
24 | * Redistributions in binary form must reproduce the above
25 | copyright notice, this list of conditions and the following
26 | disclaimer in the documentation and/or other materials
27 | provided with the distribution.
28 |
29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
30 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
33 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
34 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
38 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
39 | THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 | SUCH DAMAGE.
41 |
42 | ***********************************************************************/
43 |
44 | "use strict";
45 |
46 | // Tree transformer helpers.
47 | // XXX: eventually I should refactor the compressor to use this infrastructure.
48 |
49 | function TreeTransformer(before, after) {
50 | TreeWalker.call(this);
51 | this.before = before;
52 | this.after = after;
53 | }
54 | TreeTransformer.prototype = new TreeWalker;
55 |
56 | (function(undefined){
57 |
58 | function _(node, descend) {
59 | node.DEFMETHOD("transform", function(tw, in_list){
60 | var x, y;
61 | tw.push(this);
62 | if (tw.before) x = tw.before(this, descend, in_list);
63 | if (x === undefined) {
64 | if (!tw.after) {
65 | x = this;
66 | descend(x, tw);
67 | } else {
68 | tw.stack[tw.stack.length - 1] = x = this.clone();
69 | descend(x, tw);
70 | y = tw.after(x, in_list);
71 | if (y !== undefined) x = y;
72 | }
73 | }
74 | tw.pop();
75 | return x;
76 | });
77 | };
78 |
79 | function do_list(list, tw) {
80 | return MAP(list, function(node){
81 | return node.transform(tw, true);
82 | });
83 | };
84 |
85 | _(AST_Node, noop);
86 |
87 | _(AST_LabeledStatement, function(self, tw){
88 | self.label = self.label.transform(tw);
89 | self.body = self.body.transform(tw);
90 | });
91 |
92 | _(AST_SimpleStatement, function(self, tw){
93 | self.body = self.body.transform(tw);
94 | });
95 |
96 | _(AST_Block, function(self, tw){
97 | self.body = do_list(self.body, tw);
98 | });
99 |
100 | _(AST_DWLoop, function(self, tw){
101 | self.condition = self.condition.transform(tw);
102 | self.body = self.body.transform(tw);
103 | });
104 |
105 | _(AST_For, function(self, tw){
106 | if (self.init) self.init = self.init.transform(tw);
107 | if (self.condition) self.condition = self.condition.transform(tw);
108 | if (self.step) self.step = self.step.transform(tw);
109 | self.body = self.body.transform(tw);
110 | });
111 |
112 | _(AST_ForIn, function(self, tw){
113 | self.init = self.init.transform(tw);
114 | self.object = self.object.transform(tw);
115 | self.body = self.body.transform(tw);
116 | });
117 |
118 | _(AST_With, function(self, tw){
119 | self.expression = self.expression.transform(tw);
120 | self.body = self.body.transform(tw);
121 | });
122 |
123 | _(AST_Exit, function(self, tw){
124 | if (self.value) self.value = self.value.transform(tw);
125 | });
126 |
127 | _(AST_LoopControl, function(self, tw){
128 | if (self.label) self.label = self.label.transform(tw);
129 | });
130 |
131 | _(AST_If, function(self, tw){
132 | self.condition = self.condition.transform(tw);
133 | self.body = self.body.transform(tw);
134 | if (self.alternative) self.alternative = self.alternative.transform(tw);
135 | });
136 |
137 | _(AST_Switch, function(self, tw){
138 | self.expression = self.expression.transform(tw);
139 | self.body = do_list(self.body, tw);
140 | });
141 |
142 | _(AST_Case, function(self, tw){
143 | self.expression = self.expression.transform(tw);
144 | self.body = do_list(self.body, tw);
145 | });
146 |
147 | _(AST_Try, function(self, tw){
148 | self.body = do_list(self.body, tw);
149 | if (self.bcatch) self.bcatch = self.bcatch.transform(tw);
150 | if (self.bfinally) self.bfinally = self.bfinally.transform(tw);
151 | });
152 |
153 | _(AST_Catch, function(self, tw){
154 | self.argname = self.argname.transform(tw);
155 | self.body = do_list(self.body, tw);
156 | });
157 |
158 | _(AST_Definitions, function(self, tw){
159 | self.definitions = do_list(self.definitions, tw);
160 | });
161 |
162 | _(AST_VarDef, function(self, tw){
163 | if (self.value) self.value = self.value.transform(tw);
164 | });
165 |
166 | _(AST_Lambda, function(self, tw){
167 | if (self.name) self.name = self.name.transform(tw);
168 | self.argnames = do_list(self.argnames, tw);
169 | self.body = do_list(self.body, tw);
170 | });
171 |
172 | _(AST_Call, function(self, tw){
173 | self.expression = self.expression.transform(tw);
174 | self.args = do_list(self.args, tw);
175 | });
176 |
177 | _(AST_Seq, function(self, tw){
178 | self.car = self.car.transform(tw);
179 | self.cdr = self.cdr.transform(tw);
180 | });
181 |
182 | _(AST_Dot, function(self, tw){
183 | self.expression = self.expression.transform(tw);
184 | });
185 |
186 | _(AST_Sub, function(self, tw){
187 | self.expression = self.expression.transform(tw);
188 | self.property = self.property.transform(tw);
189 | });
190 |
191 | _(AST_Unary, function(self, tw){
192 | self.expression = self.expression.transform(tw);
193 | });
194 |
195 | _(AST_Binary, function(self, tw){
196 | self.left = self.left.transform(tw);
197 | self.right = self.right.transform(tw);
198 | });
199 |
200 | _(AST_Conditional, function(self, tw){
201 | self.condition = self.condition.transform(tw);
202 | self.consequent = self.consequent.transform(tw);
203 | self.alternative = self.alternative.transform(tw);
204 | });
205 |
206 | _(AST_Array, function(self, tw){
207 | self.elements = do_list(self.elements, tw);
208 | });
209 |
210 | _(AST_Object, function(self, tw){
211 | self.properties = do_list(self.properties, tw);
212 | });
213 |
214 | _(AST_ObjectProperty, function(self, tw){
215 | self.value = self.value.transform(tw);
216 | });
217 |
218 | })();
219 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/.npmignore:
--------------------------------------------------------------------------------
1 | dist/*
2 | node_modules/*
3 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - 0.8
4 | - "0.10"
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | ## 0.1.22
4 |
5 | * Ignore duplicate mappings in SourceMapGenerator. Fixes github issue 21.
6 |
7 | ## 0.1.21
8 |
9 | * Fixed handling of sources that start with a slash so that they are relative to
10 | the source root's host.
11 |
12 | ## 0.1.20
13 |
14 | * Fixed github issue #43: absolute URLs aren't joined with the source root
15 | anymore.
16 |
17 | ## 0.1.19
18 |
19 | * Using Travis CI to run tests.
20 |
21 | ## 0.1.18
22 |
23 | * Fixed a bug in the handling of sourceRoot.
24 |
25 | ## 0.1.17
26 |
27 | * Added SourceNode.fromStringWithSourceMap.
28 |
29 | ## 0.1.16
30 |
31 | * Added missing documentation.
32 |
33 | * Fixed the generating of empty mappings in SourceNode.
34 |
35 | ## 0.1.15
36 |
37 | * Added SourceMapGenerator.applySourceMap.
38 |
39 | ## 0.1.14
40 |
41 | * The sourceRoot is now handled consistently.
42 |
43 | ## 0.1.13
44 |
45 | * Added SourceMapGenerator.fromSourceMap.
46 |
47 | ## 0.1.12
48 |
49 | * SourceNode now generates empty mappings too.
50 |
51 | ## 0.1.11
52 |
53 | * Added name support to SourceNode.
54 |
55 | ## 0.1.10
56 |
57 | * Added sourcesContent support to the customer and generator.
58 |
59 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Copyright (c) 2009-2011, Mozilla Foundation and contributors
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions are met:
7 |
8 | * Redistributions of source code must retain the above copyright notice, this
9 | list of conditions and the following disclaimer.
10 |
11 | * Redistributions in binary form must reproduce the above copyright notice,
12 | this list of conditions and the following disclaimer in the documentation
13 | and/or other materials provided with the distribution.
14 |
15 | * Neither the names of the Mozilla Foundation nor the names of project
16 | contributors may be used to endorse or promote products derived from this
17 | software without specific prior written permission.
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/Makefile.dryice.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | var path = require('path');
8 | var fs = require('fs');
9 | var copy = require('dryice').copy;
10 |
11 | function removeAmdefine(src) {
12 | src = String(src).replace(
13 | /if\s*\(typeof\s*define\s*!==\s*'function'\)\s*{\s*var\s*define\s*=\s*require\('amdefine'\)\(module\);\s*}\s*/g,
14 | '');
15 | src = src.replace(
16 | /\b(define\(.*)('amdefine',?)/gm,
17 | '$1');
18 | return src;
19 | }
20 | removeAmdefine.onRead = true;
21 |
22 | function makeNonRelative(src) {
23 | return src
24 | .replace(/require\('.\//g, 'require(\'source-map/')
25 | .replace(/\.\.\/\.\.\/lib\//g, '');
26 | }
27 | makeNonRelative.onRead = true;
28 |
29 | function buildBrowser() {
30 | console.log('\nCreating dist/source-map.js');
31 |
32 | var project = copy.createCommonJsProject({
33 | roots: [ path.join(__dirname, 'lib') ]
34 | });
35 |
36 | copy({
37 | source: [
38 | 'build/mini-require.js',
39 | {
40 | project: project,
41 | require: [ 'source-map/source-map-generator',
42 | 'source-map/source-map-consumer',
43 | 'source-map/source-node']
44 | },
45 | 'build/suffix-browser.js'
46 | ],
47 | filter: [
48 | copy.filter.moduleDefines,
49 | removeAmdefine
50 | ],
51 | dest: 'dist/source-map.js'
52 | });
53 | }
54 |
55 | function buildBrowserMin() {
56 | console.log('\nCreating dist/source-map.min.js');
57 |
58 | copy({
59 | source: 'dist/source-map.js',
60 | filter: copy.filter.uglifyjs,
61 | dest: 'dist/source-map.min.js'
62 | });
63 | }
64 |
65 | function buildFirefox() {
66 | console.log('\nCreating dist/SourceMap.jsm');
67 |
68 | var project = copy.createCommonJsProject({
69 | roots: [ path.join(__dirname, 'lib') ]
70 | });
71 |
72 | copy({
73 | source: [
74 | 'build/prefix-source-map.jsm',
75 | {
76 | project: project,
77 | require: [ 'source-map/source-map-consumer',
78 | 'source-map/source-map-generator',
79 | 'source-map/source-node' ]
80 | },
81 | 'build/suffix-source-map.jsm'
82 | ],
83 | filter: [
84 | copy.filter.moduleDefines,
85 | removeAmdefine,
86 | makeNonRelative
87 | ],
88 | dest: 'dist/SourceMap.jsm'
89 | });
90 |
91 | // Create dist/test/Utils.jsm
92 | console.log('\nCreating dist/test/Utils.jsm');
93 |
94 | project = copy.createCommonJsProject({
95 | roots: [ __dirname, path.join(__dirname, 'lib') ]
96 | });
97 |
98 | copy({
99 | source: [
100 | 'build/prefix-utils.jsm',
101 | 'build/assert-shim.js',
102 | {
103 | project: project,
104 | require: [ 'test/source-map/util' ]
105 | },
106 | 'build/suffix-utils.jsm'
107 | ],
108 | filter: [
109 | copy.filter.moduleDefines,
110 | removeAmdefine,
111 | makeNonRelative
112 | ],
113 | dest: 'dist/test/Utils.jsm'
114 | });
115 |
116 | function isTestFile(f) {
117 | return /^test\-.*?\.js/.test(f);
118 | }
119 |
120 | var testFiles = fs.readdirSync(path.join(__dirname, 'test', 'source-map')).filter(isTestFile);
121 |
122 | testFiles.forEach(function (testFile) {
123 | console.log('\nCreating', path.join('dist', 'test', testFile.replace(/\-/g, '_')));
124 |
125 | copy({
126 | source: [
127 | 'build/test-prefix.js',
128 | path.join('test', 'source-map', testFile),
129 | 'build/test-suffix.js'
130 | ],
131 | filter: [
132 | removeAmdefine,
133 | makeNonRelative,
134 | function (input, source) {
135 | return input.replace('define(',
136 | 'define("'
137 | + path.join('test', 'source-map', testFile.replace(/\.js$/, ''))
138 | + '", ["require", "exports", "module"], ');
139 | },
140 | function (input, source) {
141 | return input.replace('{THIS_MODULE}', function () {
142 | return "test/source-map/" + testFile.replace(/\.js$/, '');
143 | });
144 | }
145 | ],
146 | dest: path.join('dist', 'test', testFile.replace(/\-/g, '_'))
147 | });
148 | });
149 | }
150 |
151 | function ensureDir(name) {
152 | var dirExists = false;
153 | try {
154 | dirExists = fs.statSync(name).isDirectory();
155 | } catch (err) {}
156 |
157 | if (!dirExists) {
158 | fs.mkdirSync(name, 0777);
159 | }
160 | }
161 |
162 | ensureDir("dist");
163 | ensureDir("dist/test");
164 | buildFirefox();
165 | buildBrowser();
166 | buildBrowserMin();
167 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/build/assert-shim.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | define('test/source-map/assert', ['exports'], function (exports) {
8 |
9 | let do_throw = function (msg) {
10 | throw new Error(msg);
11 | };
12 |
13 | exports.init = function (throw_fn) {
14 | do_throw = throw_fn;
15 | };
16 |
17 | exports.doesNotThrow = function (fn) {
18 | try {
19 | fn();
20 | }
21 | catch (e) {
22 | do_throw(e.message);
23 | }
24 | };
25 |
26 | exports.equal = function (actual, expected, msg) {
27 | msg = msg || String(actual) + ' != ' + String(expected);
28 | if (actual != expected) {
29 | do_throw(msg);
30 | }
31 | };
32 |
33 | exports.ok = function (val, msg) {
34 | msg = msg || String(val) + ' is falsey';
35 | if (!Boolean(val)) {
36 | do_throw(msg);
37 | }
38 | };
39 |
40 | exports.strictEqual = function (actual, expected, msg) {
41 | msg = msg || String(actual) + ' !== ' + String(expected);
42 | if (actual !== expected) {
43 | do_throw(msg);
44 | }
45 | };
46 |
47 | exports.throws = function (fn) {
48 | try {
49 | fn();
50 | do_throw('Expected an error to be thrown, but it wasn\'t.');
51 | }
52 | catch (e) {
53 | }
54 | };
55 |
56 | });
57 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/build/mini-require.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 |
8 | /**
9 | * Define a module along with a payload.
10 | * @param {string} moduleName Name for the payload
11 | * @param {ignored} deps Ignored. For compatibility with CommonJS AMD Spec
12 | * @param {function} payload Function with (require, exports, module) params
13 | */
14 | function define(moduleName, deps, payload) {
15 | if (typeof moduleName != "string") {
16 | throw new TypeError('Expected string, got: ' + moduleName);
17 | }
18 |
19 | if (arguments.length == 2) {
20 | payload = deps;
21 | }
22 |
23 | if (moduleName in define.modules) {
24 | throw new Error("Module already defined: " + moduleName);
25 | }
26 | define.modules[moduleName] = payload;
27 | };
28 |
29 | /**
30 | * The global store of un-instantiated modules
31 | */
32 | define.modules = {};
33 |
34 |
35 | /**
36 | * We invoke require() in the context of a Domain so we can have multiple
37 | * sets of modules running separate from each other.
38 | * This contrasts with JSMs which are singletons, Domains allows us to
39 | * optionally load a CommonJS module twice with separate data each time.
40 | * Perhaps you want 2 command lines with a different set of commands in each,
41 | * for example.
42 | */
43 | function Domain() {
44 | this.modules = {};
45 | this._currentModule = null;
46 | }
47 |
48 | (function () {
49 |
50 | /**
51 | * Lookup module names and resolve them by calling the definition function if
52 | * needed.
53 | * There are 2 ways to call this, either with an array of dependencies and a
54 | * callback to call when the dependencies are found (which can happen
55 | * asynchronously in an in-page context) or with a single string an no callback
56 | * where the dependency is resolved synchronously and returned.
57 | * The API is designed to be compatible with the CommonJS AMD spec and
58 | * RequireJS.
59 | * @param {string[]|string} deps A name, or names for the payload
60 | * @param {function|undefined} callback Function to call when the dependencies
61 | * are resolved
62 | * @return {undefined|object} The module required or undefined for
63 | * array/callback method
64 | */
65 | Domain.prototype.require = function(deps, callback) {
66 | if (Array.isArray(deps)) {
67 | var params = deps.map(function(dep) {
68 | return this.lookup(dep);
69 | }, this);
70 | if (callback) {
71 | callback.apply(null, params);
72 | }
73 | return undefined;
74 | }
75 | else {
76 | return this.lookup(deps);
77 | }
78 | };
79 |
80 | function normalize(path) {
81 | var bits = path.split('/');
82 | var i = 1;
83 | while (i < bits.length) {
84 | if (bits[i] === '..') {
85 | bits.splice(i-1, 1);
86 | } else if (bits[i] === '.') {
87 | bits.splice(i, 1);
88 | } else {
89 | i++;
90 | }
91 | }
92 | return bits.join('/');
93 | }
94 |
95 | function join(a, b) {
96 | a = a.trim();
97 | b = b.trim();
98 | if (/^\//.test(b)) {
99 | return b;
100 | } else {
101 | return a.replace(/\/*$/, '/') + b;
102 | }
103 | }
104 |
105 | function dirname(path) {
106 | var bits = path.split('/');
107 | bits.pop();
108 | return bits.join('/');
109 | }
110 |
111 | /**
112 | * Lookup module names and resolve them by calling the definition function if
113 | * needed.
114 | * @param {string} moduleName A name for the payload to lookup
115 | * @return {object} The module specified by aModuleName or null if not found.
116 | */
117 | Domain.prototype.lookup = function(moduleName) {
118 | if (/^\./.test(moduleName)) {
119 | moduleName = normalize(join(dirname(this._currentModule), moduleName));
120 | }
121 |
122 | if (moduleName in this.modules) {
123 | var module = this.modules[moduleName];
124 | return module;
125 | }
126 |
127 | if (!(moduleName in define.modules)) {
128 | throw new Error("Module not defined: " + moduleName);
129 | }
130 |
131 | var module = define.modules[moduleName];
132 |
133 | if (typeof module == "function") {
134 | var exports = {};
135 | var previousModule = this._currentModule;
136 | this._currentModule = moduleName;
137 | module(this.require.bind(this), exports, { id: moduleName, uri: "" });
138 | this._currentModule = previousModule;
139 | module = exports;
140 | }
141 |
142 | // cache the resulting module object for next time
143 | this.modules[moduleName] = module;
144 |
145 | return module;
146 | };
147 |
148 | }());
149 |
150 | define.Domain = Domain;
151 | define.globalDomain = new Domain();
152 | var require = define.globalDomain.require.bind(define.globalDomain);
153 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/build/prefix-source-map.jsm:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 |
8 | /*
9 | * WARNING!
10 | *
11 | * Do not edit this file directly, it is built from the sources at
12 | * https://github.com/mozilla/source-map/
13 | */
14 |
15 | ///////////////////////////////////////////////////////////////////////////////
16 |
17 |
18 | this.EXPORTED_SYMBOLS = [ "SourceMapConsumer", "SourceMapGenerator", "SourceNode" ];
19 |
20 | Components.utils.import('resource://gre/modules/devtools/Require.jsm');
21 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/build/prefix-utils.jsm:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 |
8 | /*
9 | * WARNING!
10 | *
11 | * Do not edit this file directly, it is built from the sources at
12 | * https://github.com/mozilla/source-map/
13 | */
14 |
15 | Components.utils.import('resource://gre/modules/devtools/Require.jsm');
16 | Components.utils.import('resource://gre/modules/devtools/SourceMap.jsm');
17 |
18 | this.EXPORTED_SYMBOLS = [ "define", "runSourceMapTests" ];
19 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/build/suffix-browser.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | ///////////////////////////////////////////////////////////////////////////////
3 |
4 | window.sourceMap = {
5 | SourceMapConsumer: require('source-map/source-map-consumer').SourceMapConsumer,
6 | SourceMapGenerator: require('source-map/source-map-generator').SourceMapGenerator,
7 | SourceNode: require('source-map/source-node').SourceNode
8 | };
9 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/build/suffix-source-map.jsm:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | ///////////////////////////////////////////////////////////////////////////////
3 |
4 | this.SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer;
5 | this.SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
6 | this.SourceNode = require('source-map/source-node').SourceNode;
7 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/build/suffix-utils.jsm:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | function runSourceMapTests(modName, do_throw) {
8 | let mod = require(modName);
9 | let assert = require('test/source-map/assert');
10 | let util = require('test/source-map/util');
11 |
12 | assert.init(do_throw);
13 |
14 | for (let k in mod) {
15 | if (/^test/.test(k)) {
16 | mod[k](assert, util);
17 | }
18 | }
19 |
20 | }
21 | this.runSourceMapTests = runSourceMapTests;
22 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/build/test-prefix.js:
--------------------------------------------------------------------------------
1 | /*
2 | * WARNING!
3 | *
4 | * Do not edit this file directly, it is built from the sources at
5 | * https://github.com/mozilla/source-map/
6 | */
7 |
8 | Components.utils.import('resource://test/Utils.jsm');
9 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/build/test-suffix.js:
--------------------------------------------------------------------------------
1 | function run_test() {
2 | runSourceMapTests('{THIS_MODULE}', do_throw);
3 | }
4 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/lib/source-map.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009-2011 Mozilla Foundation and contributors
3 | * Licensed under the New BSD license. See LICENSE.txt or:
4 | * http://opensource.org/licenses/BSD-3-Clause
5 | */
6 | exports.SourceMapGenerator = require('./source-map/source-map-generator').SourceMapGenerator;
7 | exports.SourceMapConsumer = require('./source-map/source-map-consumer').SourceMapConsumer;
8 | exports.SourceNode = require('./source-map/source-node').SourceNode;
9 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/lib/source-map/array-set.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | if (typeof define !== 'function') {
8 | var define = require('amdefine')(module);
9 | }
10 | define(function (require, exports, module) {
11 |
12 | var util = require('./util');
13 |
14 | /**
15 | * A data structure which is a combination of an array and a set. Adding a new
16 | * member is O(1), testing for membership is O(1), and finding the index of an
17 | * element is O(1). Removing elements from the set is not supported. Only
18 | * strings are supported for membership.
19 | */
20 | function ArraySet() {
21 | this._array = [];
22 | this._set = {};
23 | }
24 |
25 | /**
26 | * Static method for creating ArraySet instances from an existing array.
27 | */
28 | ArraySet.fromArray = function ArraySet_fromArray(aArray) {
29 | var set = new ArraySet();
30 | for (var i = 0, len = aArray.length; i < len; i++) {
31 | set.add(aArray[i]);
32 | }
33 | return set;
34 | };
35 |
36 | /**
37 | * Add the given string to this set.
38 | *
39 | * @param String aStr
40 | */
41 | ArraySet.prototype.add = function ArraySet_add(aStr) {
42 | if (this.has(aStr)) {
43 | // Already a member; nothing to do.
44 | return;
45 | }
46 | var idx = this._array.length;
47 | this._array.push(aStr);
48 | this._set[util.toSetString(aStr)] = idx;
49 | };
50 |
51 | /**
52 | * Is the given string a member of this set?
53 | *
54 | * @param String aStr
55 | */
56 | ArraySet.prototype.has = function ArraySet_has(aStr) {
57 | return Object.prototype.hasOwnProperty.call(this._set,
58 | util.toSetString(aStr));
59 | };
60 |
61 | /**
62 | * What is the index of the given string in the array?
63 | *
64 | * @param String aStr
65 | */
66 | ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
67 | if (this.has(aStr)) {
68 | return this._set[util.toSetString(aStr)];
69 | }
70 | throw new Error('"' + aStr + '" is not in the set.');
71 | };
72 |
73 | /**
74 | * What is the element at the given index?
75 | *
76 | * @param Number aIdx
77 | */
78 | ArraySet.prototype.at = function ArraySet_at(aIdx) {
79 | if (aIdx >= 0 && aIdx < this._array.length) {
80 | return this._array[aIdx];
81 | }
82 | throw new Error('No element indexed by ' + aIdx);
83 | };
84 |
85 | /**
86 | * Returns the array representation of this set (which has the proper indices
87 | * indicated by indexOf). Note that this is a copy of the internal array used
88 | * for storing the members so that no one can mess with internal state.
89 | */
90 | ArraySet.prototype.toArray = function ArraySet_toArray() {
91 | return this._array.slice();
92 | };
93 |
94 | exports.ArraySet = ArraySet;
95 |
96 | });
97 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/lib/source-map/base64-vlq.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | *
7 | * Based on the Base 64 VLQ implementation in Closure Compiler:
8 | * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
9 | *
10 | * Copyright 2011 The Closure Compiler Authors. All rights reserved.
11 | * Redistribution and use in source and binary forms, with or without
12 | * modification, are permitted provided that the following conditions are
13 | * met:
14 | *
15 | * * Redistributions of source code must retain the above copyright
16 | * notice, this list of conditions and the following disclaimer.
17 | * * Redistributions in binary form must reproduce the above
18 | * copyright notice, this list of conditions and the following
19 | * disclaimer in the documentation and/or other materials provided
20 | * with the distribution.
21 | * * Neither the name of Google Inc. nor the names of its
22 | * contributors may be used to endorse or promote products derived
23 | * from this software without specific prior written permission.
24 | *
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 | */
37 | if (typeof define !== 'function') {
38 | var define = require('amdefine')(module);
39 | }
40 | define(function (require, exports, module) {
41 |
42 | var base64 = require('./base64');
43 |
44 | // A single base 64 digit can contain 6 bits of data. For the base 64 variable
45 | // length quantities we use in the source map spec, the first bit is the sign,
46 | // the next four bits are the actual value, and the 6th bit is the
47 | // continuation bit. The continuation bit tells us whether there are more
48 | // digits in this value following this digit.
49 | //
50 | // Continuation
51 | // | Sign
52 | // | |
53 | // V V
54 | // 101011
55 |
56 | var VLQ_BASE_SHIFT = 5;
57 |
58 | // binary: 100000
59 | var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
60 |
61 | // binary: 011111
62 | var VLQ_BASE_MASK = VLQ_BASE - 1;
63 |
64 | // binary: 100000
65 | var VLQ_CONTINUATION_BIT = VLQ_BASE;
66 |
67 | /**
68 | * Converts from a two-complement value to a value where the sign bit is
69 | * is placed in the least significant bit. For example, as decimals:
70 | * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
71 | * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
72 | */
73 | function toVLQSigned(aValue) {
74 | return aValue < 0
75 | ? ((-aValue) << 1) + 1
76 | : (aValue << 1) + 0;
77 | }
78 |
79 | /**
80 | * Converts to a two-complement value from a value where the sign bit is
81 | * is placed in the least significant bit. For example, as decimals:
82 | * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
83 | * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
84 | */
85 | function fromVLQSigned(aValue) {
86 | var isNegative = (aValue & 1) === 1;
87 | var shifted = aValue >> 1;
88 | return isNegative
89 | ? -shifted
90 | : shifted;
91 | }
92 |
93 | /**
94 | * Returns the base 64 VLQ encoded value.
95 | */
96 | exports.encode = function base64VLQ_encode(aValue) {
97 | var encoded = "";
98 | var digit;
99 |
100 | var vlq = toVLQSigned(aValue);
101 |
102 | do {
103 | digit = vlq & VLQ_BASE_MASK;
104 | vlq >>>= VLQ_BASE_SHIFT;
105 | if (vlq > 0) {
106 | // There are still more digits in this value, so we must make sure the
107 | // continuation bit is marked.
108 | digit |= VLQ_CONTINUATION_BIT;
109 | }
110 | encoded += base64.encode(digit);
111 | } while (vlq > 0);
112 |
113 | return encoded;
114 | };
115 |
116 | /**
117 | * Decodes the next base 64 VLQ value from the given string and returns the
118 | * value and the rest of the string.
119 | */
120 | exports.decode = function base64VLQ_decode(aStr) {
121 | var i = 0;
122 | var strLen = aStr.length;
123 | var result = 0;
124 | var shift = 0;
125 | var continuation, digit;
126 |
127 | do {
128 | if (i >= strLen) {
129 | throw new Error("Expected more digits in base 64 VLQ value.");
130 | }
131 | digit = base64.decode(aStr.charAt(i++));
132 | continuation = !!(digit & VLQ_CONTINUATION_BIT);
133 | digit &= VLQ_BASE_MASK;
134 | result = result + (digit << shift);
135 | shift += VLQ_BASE_SHIFT;
136 | } while (continuation);
137 |
138 | return {
139 | value: fromVLQSigned(result),
140 | rest: aStr.slice(i)
141 | };
142 | };
143 |
144 | });
145 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/lib/source-map/base64.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | if (typeof define !== 'function') {
8 | var define = require('amdefine')(module);
9 | }
10 | define(function (require, exports, module) {
11 |
12 | var charToIntMap = {};
13 | var intToCharMap = {};
14 |
15 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
16 | .split('')
17 | .forEach(function (ch, index) {
18 | charToIntMap[ch] = index;
19 | intToCharMap[index] = ch;
20 | });
21 |
22 | /**
23 | * Encode an integer in the range of 0 to 63 to a single base 64 digit.
24 | */
25 | exports.encode = function base64_encode(aNumber) {
26 | if (aNumber in intToCharMap) {
27 | return intToCharMap[aNumber];
28 | }
29 | throw new TypeError("Must be between 0 and 63: " + aNumber);
30 | };
31 |
32 | /**
33 | * Decode a single base 64 digit to an integer.
34 | */
35 | exports.decode = function base64_decode(aChar) {
36 | if (aChar in charToIntMap) {
37 | return charToIntMap[aChar];
38 | }
39 | throw new TypeError("Not a valid base 64 digit: " + aChar);
40 | };
41 |
42 | });
43 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/lib/source-map/binary-search.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | if (typeof define !== 'function') {
8 | var define = require('amdefine')(module);
9 | }
10 | define(function (require, exports, module) {
11 |
12 | /**
13 | * Recursive implementation of binary search.
14 | *
15 | * @param aLow Indices here and lower do not contain the needle.
16 | * @param aHigh Indices here and higher do not contain the needle.
17 | * @param aNeedle The element being searched for.
18 | * @param aHaystack The non-empty array being searched.
19 | * @param aCompare Function which takes two elements and returns -1, 0, or 1.
20 | */
21 | function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare) {
22 | // This function terminates when one of the following is true:
23 | //
24 | // 1. We find the exact element we are looking for.
25 | //
26 | // 2. We did not find the exact element, but we can return the next
27 | // closest element that is less than that element.
28 | //
29 | // 3. We did not find the exact element, and there is no next-closest
30 | // element which is less than the one we are searching for, so we
31 | // return null.
32 | var mid = Math.floor((aHigh - aLow) / 2) + aLow;
33 | var cmp = aCompare(aNeedle, aHaystack[mid]);
34 | if (cmp === 0) {
35 | // Found the element we are looking for.
36 | return aHaystack[mid];
37 | }
38 | else if (cmp > 0) {
39 | // aHaystack[mid] is greater than our needle.
40 | if (aHigh - mid > 1) {
41 | // The element is in the upper half.
42 | return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare);
43 | }
44 | // We did not find an exact match, return the next closest one
45 | // (termination case 2).
46 | return aHaystack[mid];
47 | }
48 | else {
49 | // aHaystack[mid] is less than our needle.
50 | if (mid - aLow > 1) {
51 | // The element is in the lower half.
52 | return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare);
53 | }
54 | // The exact needle element was not found in this haystack. Determine if
55 | // we are in termination case (2) or (3) and return the appropriate thing.
56 | return aLow < 0
57 | ? null
58 | : aHaystack[aLow];
59 | }
60 | }
61 |
62 | /**
63 | * This is an implementation of binary search which will always try and return
64 | * the next lowest value checked if there is no exact hit. This is because
65 | * mappings between original and generated line/col pairs are single points,
66 | * and there is an implicit region between each of them, so a miss just means
67 | * that you aren't on the very start of a region.
68 | *
69 | * @param aNeedle The element you are looking for.
70 | * @param aHaystack The array that is being searched.
71 | * @param aCompare A function which takes the needle and an element in the
72 | * array and returns -1, 0, or 1 depending on whether the needle is less
73 | * than, equal to, or greater than the element, respectively.
74 | */
75 | exports.search = function search(aNeedle, aHaystack, aCompare) {
76 | return aHaystack.length > 0
77 | ? recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare)
78 | : null;
79 | };
80 |
81 | });
82 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/lib/source-map/util.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | if (typeof define !== 'function') {
8 | var define = require('amdefine')(module);
9 | }
10 | define(function (require, exports, module) {
11 |
12 | /**
13 | * This is a helper function for getting values from parameter/options
14 | * objects.
15 | *
16 | * @param args The object we are extracting values from
17 | * @param name The name of the property we are getting.
18 | * @param defaultValue An optional value to return if the property is missing
19 | * from the object. If this is not specified and the property is missing, an
20 | * error will be thrown.
21 | */
22 | function getArg(aArgs, aName, aDefaultValue) {
23 | if (aName in aArgs) {
24 | return aArgs[aName];
25 | } else if (arguments.length === 3) {
26 | return aDefaultValue;
27 | } else {
28 | throw new Error('"' + aName + '" is a required argument.');
29 | }
30 | }
31 | exports.getArg = getArg;
32 |
33 | var urlRegexp = /([\w+\-.]+):\/\/((\w+:\w+)@)?([\w.]+)?(:(\d+))?(\S+)?/;
34 |
35 | function urlParse(aUrl) {
36 | var match = aUrl.match(urlRegexp);
37 | if (!match) {
38 | return null;
39 | }
40 | return {
41 | scheme: match[1],
42 | auth: match[3],
43 | host: match[4],
44 | port: match[6],
45 | path: match[7]
46 | };
47 | }
48 |
49 | function join(aRoot, aPath) {
50 | var url;
51 |
52 | if (aPath.match(urlRegexp)) {
53 | return aPath;
54 | }
55 |
56 | if (aPath.charAt(0) === '/' && (url = urlParse(aRoot))) {
57 | return aRoot.replace(url.path, '') + aPath;
58 | }
59 |
60 | return aRoot.replace(/\/$/, '') + '/' + aPath;
61 | }
62 | exports.join = join;
63 |
64 | /**
65 | * Because behavior goes wacky when you set `__proto__` on objects, we
66 | * have to prefix all the strings in our set with an arbitrary character.
67 | *
68 | * See https://github.com/mozilla/source-map/pull/31 and
69 | * https://github.com/mozilla/source-map/issues/30
70 | *
71 | * @param String aStr
72 | */
73 | function toSetString(aStr) {
74 | return '$' + aStr;
75 | }
76 | exports.toSetString = toSetString;
77 |
78 | function fromSetString(aStr) {
79 | return aStr.substr(1);
80 | }
81 | exports.fromSetString = fromSetString;
82 |
83 | function relative(aRoot, aPath) {
84 | aRoot = aRoot.replace(/\/$/, '');
85 | return aPath.indexOf(aRoot + '/') === 0
86 | ? aPath.substr(aRoot.length + 1)
87 | : aPath;
88 | }
89 | exports.relative = relative;
90 |
91 | });
92 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/node_modules/amdefine/.npmignore:
--------------------------------------------------------------------------------
1 | tests/
2 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/node_modules/amdefine/LICENSE:
--------------------------------------------------------------------------------
1 | amdefine is released under two licenses: new BSD, and MIT. You may pick the
2 | license that best suits your development needs. The text of both licenses are
3 | provided below.
4 |
5 |
6 | The "New" BSD License:
7 | ----------------------
8 |
9 | Copyright (c) 2011, The Dojo Foundation
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without
13 | modification, are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this
16 | list of conditions and the following disclaimer.
17 | * Redistributions in binary form must reproduce the above copyright notice,
18 | this list of conditions and the following disclaimer in the documentation
19 | and/or other materials provided with the distribution.
20 | * Neither the name of the Dojo Foundation nor the names of its contributors
21 | may be used to endorse or promote products derived from this software
22 | without specific prior written permission.
23 |
24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 |
35 |
36 |
37 | MIT License
38 | -----------
39 |
40 | Copyright (c) 2011, The Dojo Foundation
41 |
42 | Permission is hereby granted, free of charge, to any person obtaining a copy
43 | of this software and associated documentation files (the "Software"), to deal
44 | in the Software without restriction, including without limitation the rights
45 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
46 | copies of the Software, and to permit persons to whom the Software is
47 | furnished to do so, subject to the following conditions:
48 |
49 | The above copyright notice and this permission notice shall be included in
50 | all copies or substantial portions of the Software.
51 |
52 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
54 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
55 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
56 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
57 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
58 | THE SOFTWARE.
59 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/node_modules/amdefine/README.md:
--------------------------------------------------------------------------------
1 | # amdefine
2 |
3 | A module that can be used to implement AMD's define() in Node. This allows you
4 | to code to the AMD API and have the module work in node programs without
5 | requiring those other programs to use AMD.
6 |
7 | ## Usage
8 |
9 | **1)** Update your package.json to indicate amdefine as a dependency:
10 |
11 | ```javascript
12 | "dependencies": {
13 | "amdefine": ">=0.0.2"
14 | }
15 | ```
16 |
17 | Then run `npm install` to get amdefine into your project.
18 |
19 | **2)** At the top of each module that uses define(), place this code:
20 |
21 | ```javascript
22 | if (typeof define !== 'function') { var define = require('amdefine')(module) }
23 | ```
24 |
25 | **Only use these snippets** when loading amdefine. If you preserve the basic structure,
26 | with the braces, it will be stripped out when using the [RequireJS optimizer](#optimizer).
27 |
28 | You can add spaces, line breaks and even require amdefine with a local path, but
29 | keep the rest of the structure to get the stripping behavior.
30 |
31 | As you may know, because `if` statements in JavaScript don't have their own scope, the var
32 | declaration in the above snippet is made whether the `if` expression is truthy or not. If
33 | RequireJS is loaded then the declaration is superfluous because `define` is already already
34 | declared in the same scope in RequireJS. Fortunately JavaScript handles multiple `var`
35 | declarations of the same variable in the same scope gracefully.
36 |
37 | If you want to deliver amdefine.js with your code rather than specifying it as a dependency
38 | with npm, then just download the latest release and refer to it using a relative path:
39 |
40 | [Version 0.0.2](https://github.com/jrburke/amdefine/raw/0.0.2/amdefine.js)
41 |
42 | ## define() usage
43 |
44 | It is best if you use the anonymous forms of define() in your module:
45 |
46 | ```javascript
47 | define(function (require) {
48 | var dependency = require('dependency');
49 | });
50 | ```
51 |
52 | or
53 |
54 | ```javascript
55 | define(['dependency'], function (dependency) {
56 |
57 | });
58 | ```
59 |
60 | ## RequireJS optimizer integration.
61 |
62 | Version 1.0.3 of the [RequireJS optimizer](http://requirejs.org/docs/optimization.html)
63 | will have support for stripping the `if (typeof define !== 'function')` check
64 | mentioned above, so you can include this snippet for code that runs in the
65 | browser, but avoid taking the cost of the if() statement once the code is
66 | optimized for deployment.
67 |
68 | ## Node 0.4 Support
69 |
70 | If you want to support Node 0.4, then add `require` as the second parameter to amdefine:
71 |
72 | ```javascript
73 | //Only if you want Node 0.4. If using 0.5 or later, use the above snippet.
74 | if (typeof define !== 'function') { var define = require('amdefine')(module, require) }
75 | ```
76 |
77 | ## Limitations
78 |
79 | ### Synchronous vs Asynchronous
80 |
81 | amdefine creates a define() function that is callable by your code. It will
82 | execute and trace dependencies and call the factory function *synchronously*,
83 | to keep the behavior in line with Node's synchronous dependency tracing.
84 |
85 | The exception: calling AMD's callback-style require() from inside a factory
86 | function. The require callback is called on process.nextTick():
87 |
88 | ```javascript
89 | define(function (require) {
90 | require(['a'], function(a) {
91 | //'a' is loaded synchronously, but
92 | //this callback is called on process.nextTick().
93 | });
94 | });
95 | ```
96 |
97 | ### Loader Plugins
98 |
99 | Loader plugins are supported as long as they call their load() callbacks
100 | synchronously. So ones that do network requests will not work. However plugins
101 | like [text](http://requirejs.org/docs/api.html#text) can load text files locally.
102 |
103 | The plugin API's `load.fromText()` is **not supported** in amdefine, so this means
104 | transpiler plugins like the [CoffeeScript loader plugin](https://github.com/jrburke/require-cs)
105 | will not work. This may be fixable, but it is a bit complex, and I do not have
106 | enough node-fu to figure it out yet. See the source for amdefine.js if you want
107 | to get an idea of the issues involved.
108 |
109 | ## Tests
110 |
111 | To run the tests, cd to **tests** and run:
112 |
113 | ```
114 | node all.js
115 | ```
116 |
117 | ## License
118 |
119 | New BSD and MIT. Check the LICENSE file for all the details.
120 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/node_modules/amdefine/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "amdefine",
3 | "description": "Provide AMD's define() API for declaring modules in the AMD format",
4 | "version": "0.0.4",
5 | "homepage": "http://github.com/jrburke/amdefine.js",
6 | "author": {
7 | "name": "James Burke",
8 | "email": "jrburke@gmail.com",
9 | "url": "http://github.com/jrburke"
10 | },
11 | "licenses": [
12 | {
13 | "type": "BSD",
14 | "url": "https://github.com/jrburke/amdefine/blob/master/LICENSE"
15 | },
16 | {
17 | "type": "MIT",
18 | "url": "https://github.com/jrburke/amdefine/blob/master/LICENSE"
19 | }
20 | ],
21 | "main": "./amdefine.js",
22 | "engines": {
23 | "node": ">=0.4.2"
24 | },
25 | "_id": "amdefine@0.0.4",
26 | "dependencies": {},
27 | "devDependencies": {},
28 | "optionalDependencies": {},
29 | "_engineSupported": true,
30 | "_npmVersion": "1.1.16",
31 | "_nodeVersion": "v0.8.9",
32 | "_defaultsLoaded": true,
33 | "dist": {
34 | "shasum": "f4148643494a8ba95fbc3af06b6af48346b9aedb"
35 | },
36 | "_from": "amdefine@>=0.0.4"
37 | }
38 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "source-map",
3 | "description": "Generates and consumes source maps",
4 | "version": "0.1.22",
5 | "homepage": "https://github.com/mozilla/source-map",
6 | "author": {
7 | "name": "Nick Fitzgerald",
8 | "email": "nfitzgerald@mozilla.com"
9 | },
10 | "contributors": [
11 | {
12 | "name": "Stephen Crane"
13 | },
14 | {
15 | "name": "Ryan Seddon"
16 | },
17 | {
18 | "name": "Mihai Bazon",
19 | "email": "mihai.bazon@gmail.com"
20 | },
21 | {
22 | "name": "Michael Ficarra",
23 | "email": "github.public.email@michael.ficarra.me"
24 | },
25 | {
26 | "name": "Todd Wolfson",
27 | "email": "todd@twolfson.com"
28 | },
29 | {
30 | "name": "Alexander Solovyov",
31 | "email": "alexander@solovyov.net"
32 | },
33 | {
34 | "name": "Felix Gnass"
35 | },
36 | {
37 | "name": "Conrad Irwin",
38 | "email": "conrad.irwin@gmail.com"
39 | },
40 | {
41 | "name": "github.com/usrbincc"
42 | }
43 | ],
44 | "repository": {
45 | "type": "git",
46 | "url": "git://github.com/mozilla/source-map.git"
47 | },
48 | "directories": {
49 | "lib": "./lib"
50 | },
51 | "main": "./lib/source-map.js",
52 | "engines": {
53 | "node": ">=0.8.0"
54 | },
55 | "licenses": [
56 | {
57 | "type": "BSD",
58 | "url": "http://opensource.org/licenses/BSD-3-Clause"
59 | }
60 | ],
61 | "dependencies": {
62 | "amdefine": ">=0.0.4"
63 | },
64 | "devDependencies": {
65 | "dryice": ">=0.4.8"
66 | },
67 | "scripts": {
68 | "test": "node test/run-tests.js"
69 | },
70 | "_id": "source-map@0.1.22",
71 | "optionalDependencies": {},
72 | "_engineSupported": true,
73 | "_npmVersion": "1.1.16",
74 | "_nodeVersion": "v0.8.9",
75 | "_defaultsLoaded": true,
76 | "dist": {
77 | "shasum": "b39903dda42ef115363f079a8db7342534462ad5"
78 | },
79 | "_from": "source-map@~0.1.7"
80 | }
81 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/test/run-tests.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | /* -*- Mode: js; js-indent-level: 2; -*- */
3 | /*
4 | * Copyright 2011 Mozilla Foundation and contributors
5 | * Licensed under the New BSD license. See LICENSE or:
6 | * http://opensource.org/licenses/BSD-3-Clause
7 | */
8 | var assert = require('assert');
9 | var fs = require('fs');
10 | var path = require('path');
11 | var util = require('./source-map/util');
12 |
13 | function run(tests) {
14 | var failures = [];
15 | var total = 0;
16 | var passed = 0;
17 |
18 | for (var i = 0; i < tests.length; i++) {
19 | for (var k in tests[i].testCase) {
20 | if (/^test/.test(k)) {
21 | total++;
22 | try {
23 | tests[i].testCase[k](assert, util);
24 | passed++;
25 | process.stdout.write('.');
26 | }
27 | catch (e) {
28 | failures.push({
29 | name: tests[i].name + ': ' + k,
30 | error: e
31 | });
32 | process.stdout.write('E');
33 | }
34 | }
35 | }
36 | }
37 |
38 | process.stdout.write('\n');
39 | console.log(passed + ' / ' + total + ' tests passed.');
40 |
41 | failures.forEach(function (f) {
42 | console.log('================================================================================');
43 | console.log(f.name);
44 | console.log('--------------------------------------------------------------------------------');
45 | console.log(f.error.stack);
46 | });
47 |
48 | return failures.length;
49 | }
50 |
51 | var code;
52 |
53 | process.stdout.on('close', function () {
54 | process.exit(code);
55 | });
56 |
57 | function isTestFile(f) {
58 | return /^test\-.*?\.js/.test(f);
59 | }
60 |
61 | function toModule(f) {
62 | return './source-map/' + f.replace(/\.js$/, '');
63 | }
64 |
65 | var requires = fs.readdirSync(path.join(__dirname, 'source-map')).filter(isTestFile).map(toModule);
66 |
67 | code = run(requires.map(require).map(function (mod, i) {
68 | return {
69 | name: requires[i],
70 | testCase: mod
71 | };
72 | }));
73 | process.exit(code);
74 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/test/source-map/test-api.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2012 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | if (typeof define !== 'function') {
8 | var define = require('amdefine')(module);
9 | }
10 | define(function (require, exports, module) {
11 |
12 | var sourceMap;
13 | try {
14 | sourceMap = require('../../lib/source-map');
15 | } catch (e) {
16 | sourceMap = {};
17 | Components.utils.import('resource:///modules/devtools/SourceMap.jsm', sourceMap);
18 | }
19 |
20 | exports['test that the api is properly exposed in the top level'] = function (assert, util) {
21 | assert.equal(typeof sourceMap.SourceMapGenerator, "function");
22 | assert.equal(typeof sourceMap.SourceMapConsumer, "function");
23 | assert.equal(typeof sourceMap.SourceNode, "function");
24 | };
25 |
26 | });
27 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/test/source-map/test-array-set.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | if (typeof define !== 'function') {
8 | var define = require('amdefine')(module);
9 | }
10 | define(function (require, exports, module) {
11 |
12 | var ArraySet = require('../../lib/source-map/array-set').ArraySet;
13 |
14 | function makeTestSet() {
15 | var set = new ArraySet();
16 | for (var i = 0; i < 100; i++) {
17 | set.add(String(i));
18 | }
19 | return set;
20 | }
21 |
22 | exports['test .has() membership'] = function (assert, util) {
23 | var set = makeTestSet();
24 | for (var i = 0; i < 100; i++) {
25 | assert.ok(set.has(String(i)));
26 | }
27 | };
28 |
29 | exports['test .indexOf() elements'] = function (assert, util) {
30 | var set = makeTestSet();
31 | for (var i = 0; i < 100; i++) {
32 | assert.strictEqual(set.indexOf(String(i)), i);
33 | }
34 | };
35 |
36 | exports['test .at() indexing'] = function (assert, util) {
37 | var set = makeTestSet();
38 | for (var i = 0; i < 100; i++) {
39 | assert.strictEqual(set.at(i), String(i));
40 | }
41 | };
42 |
43 | exports['test creating from an array'] = function (assert, util) {
44 | var set = ArraySet.fromArray(['foo', 'bar', 'baz', 'quux', 'hasOwnProperty']);
45 |
46 | assert.ok(set.has('foo'));
47 | assert.ok(set.has('bar'));
48 | assert.ok(set.has('baz'));
49 | assert.ok(set.has('quux'));
50 | assert.ok(set.has('hasOwnProperty'));
51 |
52 | assert.strictEqual(set.indexOf('foo'), 0);
53 | assert.strictEqual(set.indexOf('bar'), 1);
54 | assert.strictEqual(set.indexOf('baz'), 2);
55 | assert.strictEqual(set.indexOf('quux'), 3);
56 |
57 | assert.strictEqual(set.at(0), 'foo');
58 | assert.strictEqual(set.at(1), 'bar');
59 | assert.strictEqual(set.at(2), 'baz');
60 | assert.strictEqual(set.at(3), 'quux');
61 | };
62 |
63 | exports['test that you can add __proto__; see github issue #30'] = function (assert, util) {
64 | var set = new ArraySet();
65 | set.add('__proto__');
66 | assert.ok(set.has('__proto__'));
67 | assert.strictEqual(set.at(0), '__proto__');
68 | assert.strictEqual(set.indexOf('__proto__'), 0);
69 | };
70 |
71 | });
72 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/test/source-map/test-base64-vlq.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | if (typeof define !== 'function') {
8 | var define = require('amdefine')(module);
9 | }
10 | define(function (require, exports, module) {
11 |
12 | var base64VLQ = require('../../lib/source-map/base64-vlq');
13 |
14 | exports['test normal encoding and decoding'] = function (assert, util) {
15 | var result;
16 | for (var i = -255; i < 256; i++) {
17 | result = base64VLQ.decode(base64VLQ.encode(i));
18 | assert.ok(result);
19 | assert.equal(result.value, i);
20 | assert.equal(result.rest, "");
21 | }
22 | };
23 |
24 | });
25 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/test/source-map/test-base64.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | if (typeof define !== 'function') {
8 | var define = require('amdefine')(module);
9 | }
10 | define(function (require, exports, module) {
11 |
12 | var base64 = require('../../lib/source-map/base64');
13 |
14 | exports['test out of range encoding'] = function (assert, util) {
15 | assert.throws(function () {
16 | base64.encode(-1);
17 | });
18 | assert.throws(function () {
19 | base64.encode(64);
20 | });
21 | };
22 |
23 | exports['test out of range decoding'] = function (assert, util) {
24 | assert.throws(function () {
25 | base64.decode('=');
26 | });
27 | };
28 |
29 | exports['test normal encoding and decoding'] = function (assert, util) {
30 | for (var i = 0; i < 64; i++) {
31 | assert.equal(base64.decode(base64.encode(i)), i);
32 | }
33 | };
34 |
35 | });
36 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/test/source-map/test-binary-search.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | if (typeof define !== 'function') {
8 | var define = require('amdefine')(module);
9 | }
10 | define(function (require, exports, module) {
11 |
12 | var binarySearch = require('../../lib/source-map/binary-search');
13 |
14 | function numberCompare(a, b) {
15 | return a - b;
16 | }
17 |
18 | exports['test too high'] = function (assert, util) {
19 | var needle = 30;
20 | var haystack = [2,4,6,8,10,12,14,16,18,20];
21 |
22 | assert.doesNotThrow(function () {
23 | binarySearch.search(needle, haystack, numberCompare);
24 | });
25 |
26 | assert.equal(binarySearch.search(needle, haystack, numberCompare), 20);
27 | };
28 |
29 | exports['test too low'] = function (assert, util) {
30 | var needle = 1;
31 | var haystack = [2,4,6,8,10,12,14,16,18,20];
32 |
33 | assert.doesNotThrow(function () {
34 | binarySearch.search(needle, haystack, numberCompare);
35 | });
36 |
37 | assert.equal(binarySearch.search(needle, haystack, numberCompare), null);
38 | };
39 |
40 | exports['test exact search'] = function (assert, util) {
41 | var needle = 4;
42 | var haystack = [2,4,6,8,10,12,14,16,18,20];
43 |
44 | assert.equal(binarySearch.search(needle, haystack, numberCompare), 4);
45 | };
46 |
47 | exports['test fuzzy search'] = function (assert, util) {
48 | var needle = 19;
49 | var haystack = [2,4,6,8,10,12,14,16,18,20];
50 |
51 | assert.equal(binarySearch.search(needle, haystack, numberCompare), 18);
52 | };
53 |
54 | });
55 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/test/source-map/test-dog-fooding.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | if (typeof define !== 'function') {
8 | var define = require('amdefine')(module);
9 | }
10 | define(function (require, exports, module) {
11 |
12 | var SourceMapConsumer = require('../../lib/source-map/source-map-consumer').SourceMapConsumer;
13 | var SourceMapGenerator = require('../../lib/source-map/source-map-generator').SourceMapGenerator;
14 |
15 | exports['test eating our own dog food'] = function (assert, util) {
16 | var smg = new SourceMapGenerator({
17 | file: 'testing.js',
18 | sourceRoot: '/wu/tang'
19 | });
20 |
21 | smg.addMapping({
22 | source: 'gza.coffee',
23 | original: { line: 1, column: 0 },
24 | generated: { line: 2, column: 2 }
25 | });
26 |
27 | smg.addMapping({
28 | source: 'gza.coffee',
29 | original: { line: 2, column: 0 },
30 | generated: { line: 3, column: 2 }
31 | });
32 |
33 | smg.addMapping({
34 | source: 'gza.coffee',
35 | original: { line: 3, column: 0 },
36 | generated: { line: 4, column: 2 }
37 | });
38 |
39 | smg.addMapping({
40 | source: 'gza.coffee',
41 | original: { line: 4, column: 0 },
42 | generated: { line: 5, column: 2 }
43 | });
44 |
45 | var smc = new SourceMapConsumer(smg.toString());
46 |
47 | // Exact
48 | util.assertMapping(2, 2, '/wu/tang/gza.coffee', 1, 0, null, smc, assert);
49 | util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 0, null, smc, assert);
50 | util.assertMapping(4, 2, '/wu/tang/gza.coffee', 3, 0, null, smc, assert);
51 | util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 0, null, smc, assert);
52 |
53 | // Fuzzy
54 |
55 | // Original to generated
56 | util.assertMapping(2, 0, null, null, null, null, smc, assert, true);
57 | util.assertMapping(2, 9, '/wu/tang/gza.coffee', 1, 0, null, smc, assert, true);
58 | util.assertMapping(3, 0, '/wu/tang/gza.coffee', 1, 0, null, smc, assert, true);
59 | util.assertMapping(3, 9, '/wu/tang/gza.coffee', 2, 0, null, smc, assert, true);
60 | util.assertMapping(4, 0, '/wu/tang/gza.coffee', 2, 0, null, smc, assert, true);
61 | util.assertMapping(4, 9, '/wu/tang/gza.coffee', 3, 0, null, smc, assert, true);
62 | util.assertMapping(5, 0, '/wu/tang/gza.coffee', 3, 0, null, smc, assert, true);
63 | util.assertMapping(5, 9, '/wu/tang/gza.coffee', 4, 0, null, smc, assert, true);
64 |
65 | // Generated to original
66 | util.assertMapping(2, 2, '/wu/tang/gza.coffee', 1, 1, null, smc, assert, null, true);
67 | util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 3, null, smc, assert, null, true);
68 | util.assertMapping(4, 2, '/wu/tang/gza.coffee', 3, 6, null, smc, assert, null, true);
69 | util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 9, null, smc, assert, null, true);
70 | };
71 |
72 | });
73 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/node_modules/source-map/test/source-map/util.js:
--------------------------------------------------------------------------------
1 | /* -*- Mode: js; js-indent-level: 2; -*- */
2 | /*
3 | * Copyright 2011 Mozilla Foundation and contributors
4 | * Licensed under the New BSD license. See LICENSE or:
5 | * http://opensource.org/licenses/BSD-3-Clause
6 | */
7 | if (typeof define !== 'function') {
8 | var define = require('amdefine')(module);
9 | }
10 | define(function (require, exports, module) {
11 |
12 | var util = require('../../lib/source-map/util');
13 |
14 | // This is a test mapping which maps functions from two different files
15 | // (one.js and two.js) to a minified generated source.
16 | //
17 | // Here is one.js:
18 | //
19 | // ONE.foo = function (bar) {
20 | // return baz(bar);
21 | // };
22 | //
23 | // Here is two.js:
24 | //
25 | // TWO.inc = function (n) {
26 | // return n + 1;
27 | // };
28 | //
29 | // And here is the generated code (min.js):
30 | //
31 | // ONE.foo=function(a){return baz(a);};
32 | // TWO.inc=function(a){return a+1;};
33 | exports.testGeneratedCode = " ONE.foo=function(a){return baz(a);};\n"+
34 | " TWO.inc=function(a){return a+1;};";
35 | exports.testMap = {
36 | version: 3,
37 | file: 'min.js',
38 | names: ['bar', 'baz', 'n'],
39 | sources: ['one.js', 'two.js'],
40 | sourceRoot: '/the/root',
41 | mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
42 | };
43 | exports.testMapWithSourcesContent = {
44 | version: 3,
45 | file: 'min.js',
46 | names: ['bar', 'baz', 'n'],
47 | sources: ['one.js', 'two.js'],
48 | sourcesContent: [
49 | ' ONE.foo = function (bar) {\n' +
50 | ' return baz(bar);\n' +
51 | ' };',
52 | ' TWO.inc = function (n) {\n' +
53 | ' return n + 1;\n' +
54 | ' };'
55 | ],
56 | sourceRoot: '/the/root',
57 | mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
58 | };
59 |
60 | function assertMapping(generatedLine, generatedColumn, originalSource,
61 | originalLine, originalColumn, name, map, assert,
62 | dontTestGenerated, dontTestOriginal) {
63 | if (!dontTestOriginal) {
64 | var origMapping = map.originalPositionFor({
65 | line: generatedLine,
66 | column: generatedColumn
67 | });
68 | assert.equal(origMapping.name, name,
69 | 'Incorrect name, expected ' + JSON.stringify(name)
70 | + ', got ' + JSON.stringify(origMapping.name));
71 | assert.equal(origMapping.line, originalLine,
72 | 'Incorrect line, expected ' + JSON.stringify(originalLine)
73 | + ', got ' + JSON.stringify(origMapping.line));
74 | assert.equal(origMapping.column, originalColumn,
75 | 'Incorrect column, expected ' + JSON.stringify(originalColumn)
76 | + ', got ' + JSON.stringify(origMapping.column));
77 |
78 | var expectedSource;
79 |
80 | if (originalSource && map.sourceRoot && originalSource.indexOf(map.sourceRoot) === 0) {
81 | expectedSource = originalSource;
82 | } else if (originalSource) {
83 | expectedSource = map.sourceRoot
84 | ? util.join(map.sourceRoot, originalSource)
85 | : originalSource;
86 | } else {
87 | expectedSource = null;
88 | }
89 |
90 | assert.equal(origMapping.source, expectedSource,
91 | 'Incorrect source, expected ' + JSON.stringify(expectedSource)
92 | + ', got ' + JSON.stringify(origMapping.source));
93 | }
94 |
95 | if (!dontTestGenerated) {
96 | var genMapping = map.generatedPositionFor({
97 | source: originalSource,
98 | line: originalLine,
99 | column: originalColumn
100 | });
101 | assert.equal(genMapping.line, generatedLine,
102 | 'Incorrect line, expected ' + JSON.stringify(generatedLine)
103 | + ', got ' + JSON.stringify(genMapping.line));
104 | assert.equal(genMapping.column, generatedColumn,
105 | 'Incorrect column, expected ' + JSON.stringify(generatedColumn)
106 | + ', got ' + JSON.stringify(genMapping.column));
107 | }
108 | }
109 | exports.assertMapping = assertMapping;
110 |
111 | function assertEqualMaps(assert, actualMap, expectedMap) {
112 | assert.equal(actualMap.version, expectedMap.version, "version mismatch");
113 | assert.equal(actualMap.file, expectedMap.file, "file mismatch");
114 | assert.equal(actualMap.names.length,
115 | expectedMap.names.length,
116 | "names length mismatch: " +
117 | actualMap.names.join(", ") + " != " + expectedMap.names.join(", "));
118 | for (var i = 0; i < actualMap.names.length; i++) {
119 | assert.equal(actualMap.names[i],
120 | expectedMap.names[i],
121 | "names[" + i + "] mismatch: " +
122 | actualMap.names.join(", ") + " != " + expectedMap.names.join(", "));
123 | }
124 | assert.equal(actualMap.sources.length,
125 | expectedMap.sources.length,
126 | "sources length mismatch: " +
127 | actualMap.sources.join(", ") + " != " + expectedMap.sources.join(", "));
128 | for (var i = 0; i < actualMap.sources.length; i++) {
129 | assert.equal(actualMap.sources[i],
130 | expectedMap.sources[i],
131 | "sources[" + i + "] length mismatch: " +
132 | actualMap.sources.join(", ") + " != " + expectedMap.sources.join(", "));
133 | }
134 | assert.equal(actualMap.sourceRoot,
135 | expectedMap.sourceRoot,
136 | "sourceRoot mismatch: " +
137 | actualMap.sourceRoot + " != " + expectedMap.sourceRoot);
138 | assert.equal(actualMap.mappings, expectedMap.mappings, "mappings mismatch");
139 | if (actualMap.sourcesContent) {
140 | assert.equal(actualMap.sourcesContent.length,
141 | expectedMap.sourcesContent.length,
142 | "sourcesContent length mismatch");
143 | for (var i = 0; i < actualMap.sourcesContent.length; i++) {
144 | assert.equal(actualMap.sourcesContent[i],
145 | expectedMap.sourcesContent[i],
146 | "sourcesContent[" + i + "] mismatch");
147 | }
148 | }
149 | }
150 | exports.assertEqualMaps = assertEqualMaps;
151 |
152 | });
153 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "uglify-js",
3 | "description": "JavaScript parser, mangler/compressor and beautifier toolkit",
4 | "homepage": "http://lisperator.net/uglifyjs",
5 | "main": "tools/node.js",
6 | "version": "2.2.5",
7 | "engines": {
8 | "node": ">=0.4.0"
9 | },
10 | "maintainers": [
11 | {
12 | "name": "Mihai Bazon",
13 | "email": "mihai.bazon@gmail.com",
14 | "url": "http://lisperator.net/"
15 | }
16 | ],
17 | "repositories": [
18 | {
19 | "type": "git",
20 | "url": "https://github.com/mishoo/UglifyJS2.git"
21 | }
22 | ],
23 | "dependencies": {
24 | "source-map": "~0.1.7",
25 | "optimist": "~0.3.5"
26 | },
27 | "bin": {
28 | "uglifyjs": "bin/uglifyjs"
29 | },
30 | "scripts": {
31 | "test": "node test/run-tests.js"
32 | },
33 | "_id": "uglify-js@2.2.5",
34 | "devDependencies": {},
35 | "optionalDependencies": {},
36 | "_engineSupported": true,
37 | "_npmVersion": "1.1.16",
38 | "_nodeVersion": "v0.8.9",
39 | "_defaultsLoaded": true,
40 | "dist": {
41 | "shasum": "20481078273e14267b123c56c288bce9c3f61293"
42 | },
43 | "_from": "uglify-js"
44 | }
45 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/arrays.js:
--------------------------------------------------------------------------------
1 | holes_and_undefined: {
2 | input: {
3 | x = [1, 2, undefined];
4 | y = [1, , 2, ];
5 | z = [1, undefined, 3];
6 | }
7 | expect: {
8 | x=[1,2,void 0];
9 | y=[1,,2];
10 | z=[1,void 0,3];
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/blocks.js:
--------------------------------------------------------------------------------
1 | remove_blocks: {
2 | input: {
3 | {;}
4 | foo();
5 | {};
6 | {
7 | {};
8 | };
9 | bar();
10 | {}
11 | }
12 | expect: {
13 | foo();
14 | bar();
15 | }
16 | }
17 |
18 | keep_some_blocks: {
19 | input: {
20 | // 1.
21 | if (foo) {
22 | {{{}}}
23 | if (bar) { baz(); }
24 | {{}}
25 | } else {
26 | stuff();
27 | }
28 |
29 | // 2.
30 | if (foo) {
31 | for (var i = 0; i < 5; ++i)
32 | if (bar) baz();
33 | } else {
34 | stuff();
35 | }
36 | }
37 | expect: {
38 | // 1.
39 | if (foo) {
40 | if (bar) baz();
41 | } else stuff();
42 |
43 | // 2.
44 | if (foo) {
45 | for (var i = 0; i < 5; ++i)
46 | if (bar) baz();
47 | } else stuff();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/conditionals.js:
--------------------------------------------------------------------------------
1 | ifs_1: {
2 | options = {
3 | conditionals: true
4 | };
5 | input: {
6 | if (foo) bar();
7 | if (!foo); else bar();
8 | if (foo); else bar();
9 | if (foo); else;
10 | }
11 | expect: {
12 | foo&&bar();
13 | foo&&bar();
14 | foo||bar();
15 | foo;
16 | }
17 | }
18 |
19 | ifs_2: {
20 | options = {
21 | conditionals: true
22 | };
23 | input: {
24 | if (foo) {
25 | x();
26 | } else if (bar) {
27 | y();
28 | } else if (baz) {
29 | z();
30 | }
31 |
32 | if (foo) {
33 | x();
34 | } else if (bar) {
35 | y();
36 | } else if (baz) {
37 | z();
38 | } else {
39 | t();
40 | }
41 | }
42 | expect: {
43 | foo ? x() : bar ? y() : baz && z();
44 | foo ? x() : bar ? y() : baz ? z() : t();
45 | }
46 | }
47 |
48 | ifs_3_should_warn: {
49 | options = {
50 | conditionals : true,
51 | dead_code : true,
52 | evaluate : true,
53 | booleans : true
54 | };
55 | input: {
56 | if (x && !(x + "1") && y) { // 1
57 | var qq;
58 | foo();
59 | } else {
60 | bar();
61 | }
62 |
63 | if (x || !!(x + "1") || y) { // 2
64 | foo();
65 | } else {
66 | var jj;
67 | bar();
68 | }
69 | }
70 | expect: {
71 | var qq; bar(); // 1
72 | var jj; foo(); // 2
73 | }
74 | }
75 |
76 | ifs_4: {
77 | options = {
78 | conditionals: true
79 | };
80 | input: {
81 | if (foo && bar) {
82 | x(foo)[10].bar.baz = something();
83 | } else
84 | x(foo)[10].bar.baz = something_else();
85 | }
86 | expect: {
87 | x(foo)[10].bar.baz = (foo && bar) ? something() : something_else();
88 | }
89 | }
90 |
91 | ifs_5: {
92 | options = {
93 | if_return: true,
94 | conditionals: true,
95 | comparisons: true,
96 | };
97 | input: {
98 | function f() {
99 | if (foo) return;
100 | bar();
101 | baz();
102 | }
103 | function g() {
104 | if (foo) return;
105 | if (bar) return;
106 | if (baz) return;
107 | if (baa) return;
108 | a();
109 | b();
110 | }
111 | }
112 | expect: {
113 | function f() {
114 | if (!foo) {
115 | bar();
116 | baz();
117 | }
118 | }
119 | function g() {
120 | if (!(foo || bar || baz || baa)) {
121 | a();
122 | b();
123 | }
124 | }
125 | }
126 | }
127 |
128 | ifs_6: {
129 | options = {
130 | conditionals: true,
131 | comparisons: true
132 | };
133 | input: {
134 | if (!foo && !bar && !baz && !boo) {
135 | x = 10;
136 | } else {
137 | x = 20;
138 | }
139 | }
140 | expect: {
141 | x = foo || bar || baz || boo ? 20 : 10;
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/dead-code.js:
--------------------------------------------------------------------------------
1 | dead_code_1: {
2 | options = {
3 | dead_code: true
4 | };
5 | input: {
6 | function f() {
7 | a();
8 | b();
9 | x = 10;
10 | return;
11 | if (x) {
12 | y();
13 | }
14 | }
15 | }
16 | expect: {
17 | function f() {
18 | a();
19 | b();
20 | x = 10;
21 | return;
22 | }
23 | }
24 | }
25 |
26 | dead_code_2_should_warn: {
27 | options = {
28 | dead_code: true
29 | };
30 | input: {
31 | function f() {
32 | g();
33 | x = 10;
34 | throw "foo";
35 | // completely discarding the `if` would introduce some
36 | // bugs. UglifyJS v1 doesn't deal with this issue; in v2
37 | // we copy any declarations to the upper scope.
38 | if (x) {
39 | y();
40 | var x;
41 | function g(){};
42 | // but nested declarations should not be kept.
43 | (function(){
44 | var q;
45 | function y(){};
46 | })();
47 | }
48 | }
49 | }
50 | expect: {
51 | function f() {
52 | g();
53 | x = 10;
54 | throw "foo";
55 | var x;
56 | function g(){};
57 | }
58 | }
59 | }
60 |
61 | dead_code_constant_boolean_should_warn_more: {
62 | options = {
63 | dead_code : true,
64 | loops : true,
65 | booleans : true,
66 | conditionals : true,
67 | evaluate : true
68 | };
69 | input: {
70 | while (!((foo && bar) || (x + "0"))) {
71 | console.log("unreachable");
72 | var foo;
73 | function bar() {}
74 | }
75 | for (var x = 10; x && (y || x) && (!typeof x); ++x) {
76 | asdf();
77 | foo();
78 | var moo;
79 | }
80 | }
81 | expect: {
82 | var foo;
83 | function bar() {}
84 | // nothing for the while
85 | // as for the for, it should keep:
86 | var x = 10;
87 | var moo;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/debugger.js:
--------------------------------------------------------------------------------
1 | keep_debugger: {
2 | options = {
3 | drop_debugger: false
4 | };
5 | input: {
6 | debugger;
7 | }
8 | expect: {
9 | debugger;
10 | }
11 | }
12 |
13 | drop_debugger: {
14 | options = {
15 | drop_debugger: true
16 | };
17 | input: {
18 | debugger;
19 | if (foo) debugger;
20 | }
21 | expect: {
22 | if (foo);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/drop-unused.js:
--------------------------------------------------------------------------------
1 | unused_funarg_1: {
2 | options = { unused: true };
3 | input: {
4 | function f(a, b, c, d, e) {
5 | return a + b;
6 | }
7 | }
8 | expect: {
9 | function f(a, b) {
10 | return a + b;
11 | }
12 | }
13 | }
14 |
15 | unused_funarg_2: {
16 | options = { unused: true };
17 | input: {
18 | function f(a, b, c, d, e) {
19 | return a + c;
20 | }
21 | }
22 | expect: {
23 | function f(a, b, c) {
24 | return a + c;
25 | }
26 | }
27 | }
28 |
29 | unused_nested_function: {
30 | options = { unused: true };
31 | input: {
32 | function f(x, y) {
33 | function g() {
34 | something();
35 | }
36 | return x + y;
37 | }
38 | };
39 | expect: {
40 | function f(x, y) {
41 | return x + y;
42 | }
43 | }
44 | }
45 |
46 | unused_circular_references_1: {
47 | options = { unused: true };
48 | input: {
49 | function f(x, y) {
50 | // circular reference
51 | function g() {
52 | return h();
53 | }
54 | function h() {
55 | return g();
56 | }
57 | return x + y;
58 | }
59 | };
60 | expect: {
61 | function f(x, y) {
62 | return x + y;
63 | }
64 | }
65 | }
66 |
67 | unused_circular_references_2: {
68 | options = { unused: true };
69 | input: {
70 | function f(x, y) {
71 | var foo = 1, bar = baz, baz = foo + bar, qwe = moo();
72 | return x + y;
73 | }
74 | };
75 | expect: {
76 | function f(x, y) {
77 | moo(); // keeps side effect
78 | return x + y;
79 | }
80 | }
81 | }
82 |
83 | unused_circular_references_3: {
84 | options = { unused: true };
85 | input: {
86 | function f(x, y) {
87 | var g = function() { return h() };
88 | var h = function() { return g() };
89 | return x + y;
90 | }
91 | };
92 | expect: {
93 | function f(x, y) {
94 | return x + y;
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/issue-105.js:
--------------------------------------------------------------------------------
1 | typeof_eq_undefined: {
2 | options = {
3 | comparisons: true,
4 | unsafe: false
5 | };
6 | input: { a = typeof b.c != "undefined" }
7 | expect: { a = "undefined" != typeof b.c }
8 | }
9 |
10 | typeof_eq_undefined_unsafe: {
11 | options = {
12 | comparisons: true,
13 | unsafe: true
14 | };
15 | input: { a = typeof b.c != "undefined" }
16 | expect: { a = b.c !== void 0 }
17 | }
18 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/issue-12.js:
--------------------------------------------------------------------------------
1 | keep_name_of_getter: {
2 | options = { unused: true };
3 | input: { a = { get foo () {} } }
4 | expect: { a = { get foo () {} } }
5 | }
6 |
7 | keep_name_of_setter: {
8 | options = { unused: true };
9 | input: { a = { set foo () {} } }
10 | expect: { a = { set foo () {} } }
11 | }
12 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/issue-22.js:
--------------------------------------------------------------------------------
1 | return_with_no_value_in_if_body: {
2 | options = { conditionals: true };
3 | input: {
4 | function foo(bar) {
5 | if (bar) {
6 | return;
7 | } else {
8 | return 1;
9 | }
10 | }
11 | }
12 | expect: {
13 | function foo (bar) {
14 | return bar ? void 0 : 1;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/issue-44.js:
--------------------------------------------------------------------------------
1 | issue_44_valid_ast_1: {
2 | options = { unused: true };
3 | input: {
4 | function a(b) {
5 | for (var i = 0, e = b.qoo(); ; i++) {}
6 | }
7 | }
8 | expect: {
9 | function a(b) {
10 | var i = 0;
11 | for (b.qoo(); ; i++);
12 | }
13 | }
14 | }
15 |
16 | issue_44_valid_ast_2: {
17 | options = { unused: true };
18 | input: {
19 | function a(b) {
20 | if (foo) for (var i = 0, e = b.qoo(); ; i++) {}
21 | }
22 | }
23 | expect: {
24 | function a(b) {
25 | if (foo) {
26 | var i = 0;
27 | for (b.qoo(); ; i++);
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/issue-59.js:
--------------------------------------------------------------------------------
1 | keep_continue: {
2 | options = {
3 | dead_code: true,
4 | evaluate: true
5 | };
6 | input: {
7 | while (a) {
8 | if (b) {
9 | switch (true) {
10 | case c():
11 | d();
12 | }
13 | continue;
14 | }
15 | f();
16 | }
17 | }
18 | expect: {
19 | while (a) {
20 | if (b) {
21 | switch (true) {
22 | case c():
23 | d();
24 | }
25 | continue;
26 | }
27 | f();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/labels.js:
--------------------------------------------------------------------------------
1 | labels_1: {
2 | options = { if_return: true, conditionals: true, dead_code: true };
3 | input: {
4 | out: {
5 | if (foo) break out;
6 | console.log("bar");
7 | }
8 | };
9 | expect: {
10 | foo || console.log("bar");
11 | }
12 | }
13 |
14 | labels_2: {
15 | options = { if_return: true, conditionals: true, dead_code: true };
16 | input: {
17 | out: {
18 | if (foo) print("stuff");
19 | else break out;
20 | console.log("here");
21 | }
22 | };
23 | expect: {
24 | if (foo) {
25 | print("stuff");
26 | console.log("here");
27 | }
28 | }
29 | }
30 |
31 | labels_3: {
32 | options = { if_return: true, conditionals: true, dead_code: true };
33 | input: {
34 | for (var i = 0; i < 5; ++i) {
35 | if (i < 3) continue;
36 | console.log(i);
37 | }
38 | };
39 | expect: {
40 | for (var i = 0; i < 5; ++i)
41 | i < 3 || console.log(i);
42 | }
43 | }
44 |
45 | labels_4: {
46 | options = { if_return: true, conditionals: true, dead_code: true };
47 | input: {
48 | out: for (var i = 0; i < 5; ++i) {
49 | if (i < 3) continue out;
50 | console.log(i);
51 | }
52 | };
53 | expect: {
54 | for (var i = 0; i < 5; ++i)
55 | i < 3 || console.log(i);
56 | }
57 | }
58 |
59 | labels_5: {
60 | options = { if_return: true, conditionals: true, dead_code: true };
61 | // should keep the break-s in the following
62 | input: {
63 | while (foo) {
64 | if (bar) break;
65 | console.log("foo");
66 | }
67 | out: while (foo) {
68 | if (bar) break out;
69 | console.log("foo");
70 | }
71 | };
72 | expect: {
73 | while (foo) {
74 | if (bar) break;
75 | console.log("foo");
76 | }
77 | out: while (foo) {
78 | if (bar) break out;
79 | console.log("foo");
80 | }
81 | }
82 | }
83 |
84 | labels_6: {
85 | input: {
86 | out: break out;
87 | };
88 | expect: {}
89 | }
90 |
91 | labels_7: {
92 | options = { if_return: true, conditionals: true, dead_code: true };
93 | input: {
94 | while (foo) {
95 | x();
96 | y();
97 | continue;
98 | }
99 | };
100 | expect: {
101 | while (foo) {
102 | x();
103 | y();
104 | }
105 | }
106 | }
107 |
108 | labels_8: {
109 | options = { if_return: true, conditionals: true, dead_code: true };
110 | input: {
111 | while (foo) {
112 | x();
113 | y();
114 | break;
115 | }
116 | };
117 | expect: {
118 | while (foo) {
119 | x();
120 | y();
121 | break;
122 | }
123 | }
124 | }
125 |
126 | labels_9: {
127 | options = { if_return: true, conditionals: true, dead_code: true };
128 | input: {
129 | out: while (foo) {
130 | x();
131 | y();
132 | continue out;
133 | z();
134 | k();
135 | }
136 | };
137 | expect: {
138 | while (foo) {
139 | x();
140 | y();
141 | }
142 | }
143 | }
144 |
145 | labels_10: {
146 | options = { if_return: true, conditionals: true, dead_code: true };
147 | input: {
148 | out: while (foo) {
149 | x();
150 | y();
151 | break out;
152 | z();
153 | k();
154 | }
155 | };
156 | expect: {
157 | out: while (foo) {
158 | x();
159 | y();
160 | break out;
161 | }
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/loops.js:
--------------------------------------------------------------------------------
1 | while_becomes_for: {
2 | options = { loops: true };
3 | input: {
4 | while (foo()) bar();
5 | }
6 | expect: {
7 | for (; foo(); ) bar();
8 | }
9 | }
10 |
11 | drop_if_break_1: {
12 | options = { loops: true };
13 | input: {
14 | for (;;)
15 | if (foo()) break;
16 | }
17 | expect: {
18 | for (; !foo(););
19 | }
20 | }
21 |
22 | drop_if_break_2: {
23 | options = { loops: true };
24 | input: {
25 | for (;bar();)
26 | if (foo()) break;
27 | }
28 | expect: {
29 | for (; bar() && !foo(););
30 | }
31 | }
32 |
33 | drop_if_break_3: {
34 | options = { loops: true };
35 | input: {
36 | for (;bar();) {
37 | if (foo()) break;
38 | stuff1();
39 | stuff2();
40 | }
41 | }
42 | expect: {
43 | for (; bar() && !foo();) {
44 | stuff1();
45 | stuff2();
46 | }
47 | }
48 | }
49 |
50 | drop_if_break_4: {
51 | options = { loops: true, sequences: true };
52 | input: {
53 | for (;bar();) {
54 | x();
55 | y();
56 | if (foo()) break;
57 | z();
58 | k();
59 | }
60 | }
61 | expect: {
62 | for (; bar() && (x(), y(), !foo());) z(), k();
63 | }
64 | }
65 |
66 | drop_if_else_break_1: {
67 | options = { loops: true };
68 | input: {
69 | for (;;) if (foo()) bar(); else break;
70 | }
71 | expect: {
72 | for (; foo(); ) bar();
73 | }
74 | }
75 |
76 | drop_if_else_break_2: {
77 | options = { loops: true };
78 | input: {
79 | for (;bar();) {
80 | if (foo()) baz();
81 | else break;
82 | }
83 | }
84 | expect: {
85 | for (; bar() && foo();) baz();
86 | }
87 | }
88 |
89 | drop_if_else_break_3: {
90 | options = { loops: true };
91 | input: {
92 | for (;bar();) {
93 | if (foo()) baz();
94 | else break;
95 | stuff1();
96 | stuff2();
97 | }
98 | }
99 | expect: {
100 | for (; bar() && foo();) {
101 | baz();
102 | stuff1();
103 | stuff2();
104 | }
105 | }
106 | }
107 |
108 | drop_if_else_break_4: {
109 | options = { loops: true, sequences: true };
110 | input: {
111 | for (;bar();) {
112 | x();
113 | y();
114 | if (foo()) baz();
115 | else break;
116 | z();
117 | k();
118 | }
119 | }
120 | expect: {
121 | for (; bar() && (x(), y(), foo());) baz(), z(), k();
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/properties.js:
--------------------------------------------------------------------------------
1 | keep_properties: {
2 | options = {
3 | properties: false
4 | };
5 | input: {
6 | a["foo"] = "bar";
7 | }
8 | expect: {
9 | a["foo"] = "bar";
10 | }
11 | }
12 |
13 | dot_properties: {
14 | options = {
15 | properties: true
16 | };
17 | input: {
18 | a["foo"] = "bar";
19 | a["if"] = "if";
20 | }
21 | expect: {
22 | a.foo = "bar";
23 | a["if"] = "if";
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/sequences.js:
--------------------------------------------------------------------------------
1 | make_sequences_1: {
2 | options = {
3 | sequences: true
4 | };
5 | input: {
6 | foo();
7 | bar();
8 | baz();
9 | }
10 | expect: {
11 | foo(),bar(),baz();
12 | }
13 | }
14 |
15 | make_sequences_2: {
16 | options = {
17 | sequences: true
18 | };
19 | input: {
20 | if (boo) {
21 | foo();
22 | bar();
23 | baz();
24 | } else {
25 | x();
26 | y();
27 | z();
28 | }
29 | }
30 | expect: {
31 | if (boo) foo(),bar(),baz();
32 | else x(),y(),z();
33 | }
34 | }
35 |
36 | make_sequences_3: {
37 | options = {
38 | sequences: true
39 | };
40 | input: {
41 | function f() {
42 | foo();
43 | bar();
44 | return baz();
45 | }
46 | function g() {
47 | foo();
48 | bar();
49 | throw new Error();
50 | }
51 | }
52 | expect: {
53 | function f() {
54 | return foo(), bar(), baz();
55 | }
56 | function g() {
57 | throw foo(), bar(), new Error();
58 | }
59 | }
60 | }
61 |
62 | make_sequences_4: {
63 | options = {
64 | sequences: true
65 | };
66 | input: {
67 | x = 5;
68 | if (y) z();
69 |
70 | x = 5;
71 | for (i = 0; i < 5; i++) console.log(i);
72 |
73 | x = 5;
74 | for (; i < 5; i++) console.log(i);
75 |
76 | x = 5;
77 | switch (y) {}
78 |
79 | x = 5;
80 | with (obj) {}
81 | }
82 | expect: {
83 | if (x = 5, y) z();
84 | for (x = 5, i = 0; i < 5; i++) console.log(i);
85 | for (x = 5; i < 5; i++) console.log(i);
86 | switch (x = 5, y) {}
87 | with (x = 5, obj);
88 | }
89 | }
90 |
91 | lift_sequences_1: {
92 | options = { sequences: true };
93 | input: {
94 | foo = !(x(), y(), bar());
95 | }
96 | expect: {
97 | x(), y(), foo = !bar();
98 | }
99 | }
100 |
101 | lift_sequences_2: {
102 | options = { sequences: true, evaluate: true };
103 | input: {
104 | q = 1 + (foo(), bar(), 5) + 7 * (5 / (3 - (a(), (QW=ER), c(), 2))) - (x(), y(), 5);
105 | }
106 | expect: {
107 | foo(), bar(), a(), QW = ER, c(), x(), y(), q = 36
108 | }
109 | }
110 |
111 | lift_sequences_3: {
112 | options = { sequences: true, conditionals: true };
113 | input: {
114 | x = (foo(), bar(), baz()) ? 10 : 20;
115 | }
116 | expect: {
117 | foo(), bar(), x = baz() ? 10 : 20;
118 | }
119 | }
120 |
121 | lift_sequences_4: {
122 | options = { side_effects: true };
123 | input: {
124 | x = (foo, bar, baz);
125 | }
126 | expect: {
127 | x = baz;
128 | }
129 | }
130 |
131 | for_sequences: {
132 | options = { sequences: true };
133 | input: {
134 | // 1
135 | foo();
136 | bar();
137 | for (; false;);
138 | // 2
139 | foo();
140 | bar();
141 | for (x = 5; false;);
142 | // 3
143 | x = (foo in bar);
144 | for (; false;);
145 | // 4
146 | x = (foo in bar);
147 | for (y = 5; false;);
148 | }
149 | expect: {
150 | // 1
151 | for (foo(), bar(); false;);
152 | // 2
153 | for (foo(), bar(), x = 5; false;);
154 | // 3
155 | x = (foo in bar);
156 | for (; false;);
157 | // 4
158 | x = (foo in bar);
159 | for (y = 5; false;);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/compress/switch.js:
--------------------------------------------------------------------------------
1 | constant_switch_1: {
2 | options = { dead_code: true, evaluate: true };
3 | input: {
4 | switch (1+1) {
5 | case 1: foo(); break;
6 | case 1+1: bar(); break;
7 | case 1+1+1: baz(); break;
8 | }
9 | }
10 | expect: {
11 | bar();
12 | }
13 | }
14 |
15 | constant_switch_2: {
16 | options = { dead_code: true, evaluate: true };
17 | input: {
18 | switch (1) {
19 | case 1: foo();
20 | case 1+1: bar(); break;
21 | case 1+1+1: baz();
22 | }
23 | }
24 | expect: {
25 | foo();
26 | bar();
27 | }
28 | }
29 |
30 | constant_switch_3: {
31 | options = { dead_code: true, evaluate: true };
32 | input: {
33 | switch (10) {
34 | case 1: foo();
35 | case 1+1: bar(); break;
36 | case 1+1+1: baz();
37 | default:
38 | def();
39 | }
40 | }
41 | expect: {
42 | def();
43 | }
44 | }
45 |
46 | constant_switch_4: {
47 | options = { dead_code: true, evaluate: true };
48 | input: {
49 | switch (2) {
50 | case 1:
51 | x();
52 | if (foo) break;
53 | y();
54 | break;
55 | case 1+1:
56 | bar();
57 | default:
58 | def();
59 | }
60 | }
61 | expect: {
62 | bar();
63 | def();
64 | }
65 | }
66 |
67 | constant_switch_5: {
68 | options = { dead_code: true, evaluate: true };
69 | input: {
70 | switch (1) {
71 | case 1:
72 | x();
73 | if (foo) break;
74 | y();
75 | break;
76 | case 1+1:
77 | bar();
78 | default:
79 | def();
80 | }
81 | }
82 | expect: {
83 | // the break inside the if ruins our job
84 | // we can still get rid of irrelevant cases.
85 | switch (1) {
86 | case 1:
87 | x();
88 | if (foo) break;
89 | y();
90 | }
91 | // XXX: we could optimize this better by inventing an outer
92 | // labeled block, but that's kinda tricky.
93 | }
94 | }
95 |
96 | constant_switch_6: {
97 | options = { dead_code: true, evaluate: true };
98 | input: {
99 | OUT: {
100 | foo();
101 | switch (1) {
102 | case 1:
103 | x();
104 | if (foo) break OUT;
105 | y();
106 | case 1+1:
107 | bar();
108 | break;
109 | default:
110 | def();
111 | }
112 | }
113 | }
114 | expect: {
115 | OUT: {
116 | foo();
117 | x();
118 | if (foo) break OUT;
119 | y();
120 | bar();
121 | }
122 | }
123 | }
124 |
125 | constant_switch_7: {
126 | options = { dead_code: true, evaluate: true };
127 | input: {
128 | OUT: {
129 | foo();
130 | switch (1) {
131 | case 1:
132 | x();
133 | if (foo) break OUT;
134 | for (var x = 0; x < 10; x++) {
135 | if (x > 5) break; // this break refers to the for, not to the switch; thus it
136 | // shouldn't ruin our optimization
137 | console.log(x);
138 | }
139 | y();
140 | case 1+1:
141 | bar();
142 | break;
143 | default:
144 | def();
145 | }
146 | }
147 | }
148 | expect: {
149 | OUT: {
150 | foo();
151 | x();
152 | if (foo) break OUT;
153 | for (var x = 0; x < 10; x++) {
154 | if (x > 5) break;
155 | console.log(x);
156 | }
157 | y();
158 | bar();
159 | }
160 | }
161 | }
162 |
163 | constant_switch_8: {
164 | options = { dead_code: true, evaluate: true };
165 | input: {
166 | OUT: switch (1) {
167 | case 1:
168 | x();
169 | for (;;) break OUT;
170 | y();
171 | break;
172 | case 1+1:
173 | bar();
174 | default:
175 | def();
176 | }
177 | }
178 | expect: {
179 | OUT: {
180 | x();
181 | for (;;) break OUT;
182 | y();
183 | }
184 | }
185 | }
186 |
187 | constant_switch_9: {
188 | options = { dead_code: true, evaluate: true };
189 | input: {
190 | OUT: switch (1) {
191 | case 1:
192 | x();
193 | for (;;) if (foo) break OUT;
194 | y();
195 | case 1+1:
196 | bar();
197 | default:
198 | def();
199 | }
200 | }
201 | expect: {
202 | OUT: {
203 | x();
204 | for (;;) if (foo) break OUT;
205 | y();
206 | bar();
207 | def();
208 | }
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/test/run-tests.js:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env node
2 |
3 | var U = require("../tools/node");
4 | var path = require("path");
5 | var fs = require("fs");
6 | var assert = require("assert");
7 | var sys = require("util");
8 |
9 | var tests_dir = path.dirname(module.filename);
10 |
11 | run_compress_tests();
12 |
13 | /* -----[ utils ]----- */
14 |
15 | function tmpl() {
16 | return U.string_template.apply(this, arguments);
17 | }
18 |
19 | function log() {
20 | var txt = tmpl.apply(this, arguments);
21 | sys.puts(txt);
22 | }
23 |
24 | function log_directory(dir) {
25 | log("*** Entering [{dir}]", { dir: dir });
26 | }
27 |
28 | function log_start_file(file) {
29 | log("--- {file}", { file: file });
30 | }
31 |
32 | function log_test(name) {
33 | log(" Running test [{name}]", { name: name });
34 | }
35 |
36 | function find_test_files(dir) {
37 | var files = fs.readdirSync(dir).filter(function(name){
38 | return /\.js$/i.test(name);
39 | });
40 | if (process.argv.length > 2) {
41 | var x = process.argv.slice(2);
42 | files = files.filter(function(f){
43 | return x.indexOf(f) >= 0;
44 | });
45 | }
46 | return files;
47 | }
48 |
49 | function test_directory(dir) {
50 | return path.resolve(tests_dir, dir);
51 | }
52 |
53 | function as_toplevel(input) {
54 | if (input instanceof U.AST_BlockStatement) input = input.body;
55 | else if (input instanceof U.AST_Statement) input = [ input ];
56 | else throw new Error("Unsupported input syntax");
57 | var toplevel = new U.AST_Toplevel({ body: input });
58 | toplevel.figure_out_scope();
59 | return toplevel;
60 | }
61 |
62 | function run_compress_tests() {
63 | var dir = test_directory("compress");
64 | log_directory("compress");
65 | var files = find_test_files(dir);
66 | function test_file(file) {
67 | log_start_file(file);
68 | function test_case(test) {
69 | log_test(test.name);
70 | var options = U.defaults(test.options, {
71 | warnings: false
72 | });
73 | var cmp = new U.Compressor(options, true);
74 | var expect = make_code(as_toplevel(test.expect), false);
75 | var input = as_toplevel(test.input);
76 | var input_code = make_code(test.input);
77 | var output = input.transform(cmp);
78 | output.figure_out_scope();
79 | output = make_code(output, false);
80 | if (expect != output) {
81 | log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", {
82 | input: input_code,
83 | output: output,
84 | expected: expect
85 | });
86 | }
87 | }
88 | var tests = parse_test(path.resolve(dir, file));
89 | for (var i in tests) if (tests.hasOwnProperty(i)) {
90 | test_case(tests[i]);
91 | }
92 | }
93 | files.forEach(function(file){
94 | test_file(file);
95 | });
96 | }
97 |
98 | function parse_test(file) {
99 | var script = fs.readFileSync(file, "utf8");
100 | var ast = U.parse(script, {
101 | filename: file
102 | });
103 | var tests = {};
104 | var tw = new U.TreeWalker(function(node, descend){
105 | if (node instanceof U.AST_LabeledStatement
106 | && tw.parent() instanceof U.AST_Toplevel) {
107 | var name = node.label.name;
108 | tests[name] = get_one_test(name, node.body);
109 | return true;
110 | }
111 | if (!(node instanceof U.AST_Toplevel)) croak(node);
112 | });
113 | ast.walk(tw);
114 | return tests;
115 |
116 | function croak(node) {
117 | throw new Error(tmpl("Can't understand test file {file} [{line},{col}]\n{code}", {
118 | file: file,
119 | line: node.start.line,
120 | col: node.start.col,
121 | code: make_code(node, false)
122 | }));
123 | }
124 |
125 | function get_one_test(name, block) {
126 | var test = { name: name, options: {} };
127 | var tw = new U.TreeWalker(function(node, descend){
128 | if (node instanceof U.AST_Assign) {
129 | if (!(node.left instanceof U.AST_SymbolRef)) {
130 | croak(node);
131 | }
132 | var name = node.left.name;
133 | test[name] = evaluate(node.right);
134 | return true;
135 | }
136 | if (node instanceof U.AST_LabeledStatement) {
137 | assert.ok(
138 | node.label.name == "input" || node.label.name == "expect",
139 | tmpl("Unsupported label {name} [{line},{col}]", {
140 | name: node.label.name,
141 | line: node.label.start.line,
142 | col: node.label.start.col
143 | })
144 | );
145 | var stat = node.body;
146 | if (stat instanceof U.AST_BlockStatement) {
147 | if (stat.body.length == 1) stat = stat.body[0];
148 | else if (stat.body.length == 0) stat = new U.AST_EmptyStatement();
149 | }
150 | test[node.label.name] = stat;
151 | return true;
152 | }
153 | });
154 | block.walk(tw);
155 | return test;
156 | };
157 | }
158 |
159 | function make_code(ast, beautify) {
160 | if (arguments.length == 1) beautify = true;
161 | var stream = U.OutputStream({ beautify: beautify });
162 | ast.print(stream);
163 | return stream.get();
164 | }
165 |
166 | function evaluate(code) {
167 | if (code instanceof U.AST_Node)
168 | code = make_code(code);
169 | return new Function("return(" + code + ")")();
170 | }
171 |
--------------------------------------------------------------------------------
/node_modules/uglify-js/tools/node.js:
--------------------------------------------------------------------------------
1 | var path = require("path");
2 | var fs = require("fs");
3 | var vm = require("vm");
4 | var sys = require("util");
5 |
6 | var UglifyJS = vm.createContext({
7 | sys : sys,
8 | console : console,
9 | MOZ_SourceMap : require("source-map")
10 | });
11 |
12 | function load_global(file) {
13 | file = path.resolve(path.dirname(module.filename), file);
14 | try {
15 | var code = fs.readFileSync(file, "utf8");
16 | return vm.runInContext(code, UglifyJS, file);
17 | } catch(ex) {
18 | // XXX: in case of a syntax error, the message is kinda
19 | // useless. (no location information).
20 | sys.debug("ERROR in file: " + file + " / " + ex);
21 | process.exit(1);
22 | }
23 | };
24 |
25 | var FILES = exports.FILES = [
26 | "../lib/utils.js",
27 | "../lib/ast.js",
28 | "../lib/parse.js",
29 | "../lib/transform.js",
30 | "../lib/scope.js",
31 | "../lib/output.js",
32 | "../lib/compress.js",
33 | "../lib/sourcemap.js",
34 | "../lib/mozilla-ast.js"
35 | ].map(function(file){
36 | return path.join(path.dirname(fs.realpathSync(__filename)), file);
37 | });
38 |
39 | FILES.forEach(load_global);
40 |
41 | UglifyJS.AST_Node.warn_function = function(txt) {
42 | sys.error("WARN: " + txt);
43 | };
44 |
45 | // XXX: perhaps we shouldn't export everything but heck, I'm lazy.
46 | for (var i in UglifyJS) {
47 | if (UglifyJS.hasOwnProperty(i)) {
48 | exports[i] = UglifyJS[i];
49 | }
50 | }
51 |
52 | exports.minify = function(files, options) {
53 | options = UglifyJS.defaults(options, {
54 | outSourceMap : null,
55 | sourceRoot : null,
56 | inSourceMap : null,
57 | fromString : false,
58 | warnings : false,
59 | mangle : {},
60 | output : null,
61 | compress : {}
62 | });
63 | if (typeof files == "string")
64 | files = [ files ];
65 |
66 | // 1. parse
67 | var toplevel = null;
68 | files.forEach(function(file){
69 | var code = options.fromString
70 | ? file
71 | : fs.readFileSync(file, "utf8");
72 | toplevel = UglifyJS.parse(code, {
73 | filename: options.fromString ? "?" : file,
74 | toplevel: toplevel
75 | });
76 | });
77 |
78 | // 2. compress
79 | if (options.compress) {
80 | var compress = { warnings: options.warnings };
81 | UglifyJS.merge(compress, options.compress);
82 | toplevel.figure_out_scope();
83 | var sq = UglifyJS.Compressor(compress);
84 | toplevel = toplevel.transform(sq);
85 | }
86 |
87 | // 3. mangle
88 | if (options.mangle) {
89 | toplevel.figure_out_scope();
90 | toplevel.compute_char_frequency();
91 | toplevel.mangle_names(options.mangle);
92 | }
93 |
94 | // 4. output
95 | var map = null;
96 | var inMap = null;
97 | if (options.inSourceMap) {
98 | inMap = fs.readFileSync(options.inSourceMap, "utf8");
99 | }
100 | if (options.outSourceMap) map = UglifyJS.SourceMap({
101 | file: options.outSourceMap,
102 | orig: inMap,
103 | root: options.sourceRoot
104 | });
105 | var output = { source_map: map };
106 | if (options.output) {
107 | UglifyJS.merge(output, options.output);
108 | }
109 | var stream = UglifyJS.OutputStream(output);
110 | toplevel.print(stream);
111 | return {
112 | code : stream + "",
113 | map : map + ""
114 | };
115 | };
116 |
117 | // exports.describe_ast = function() {
118 | // function doitem(ctor) {
119 | // var sub = {};
120 | // ctor.SUBCLASSES.forEach(function(ctor){
121 | // sub[ctor.TYPE] = doitem(ctor);
122 | // });
123 | // var ret = {};
124 | // if (ctor.SELF_PROPS.length > 0) ret.props = ctor.SELF_PROPS;
125 | // if (ctor.SUBCLASSES.length > 0) ret.sub = sub;
126 | // return ret;
127 | // }
128 | // return doitem(UglifyJS.AST_Node).sub;
129 | // }
130 |
131 | exports.describe_ast = function() {
132 | var out = UglifyJS.OutputStream({ beautify: true });
133 | function doitem(ctor) {
134 | out.print("AST_" + ctor.TYPE);
135 | var props = ctor.SELF_PROPS.filter(function(prop){
136 | return !/^\$/.test(prop);
137 | });
138 | if (props.length > 0) {
139 | out.space();
140 | out.with_parens(function(){
141 | props.forEach(function(prop, i){
142 | if (i) out.space();
143 | out.print(prop);
144 | });
145 | });
146 | }
147 | if (ctor.documentation) {
148 | out.space();
149 | out.print_string(ctor.documentation);
150 | }
151 | if (ctor.SUBCLASSES.length > 0) {
152 | out.space();
153 | out.with_block(function(){
154 | ctor.SUBCLASSES.forEach(function(ctor, i){
155 | out.indent();
156 | doitem(ctor);
157 | out.newline();
158 | });
159 | });
160 | }
161 | };
162 | doitem(UglifyJS.AST_Node);
163 | return out + "";
164 | };
165 |
--------------------------------------------------------------------------------
/node_modules/underscore/.npmignore:
--------------------------------------------------------------------------------
1 | test/
2 | Rakefile
3 | docs/
--------------------------------------------------------------------------------
/node_modules/underscore/CNAME:
--------------------------------------------------------------------------------
1 | underscorejs.org
2 |
--------------------------------------------------------------------------------
/node_modules/underscore/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## How to contribute to Underscore.js
2 |
3 | * Before you open a ticket or send a pull request, [search](https://github.com/documentcloud/underscore/issues) for previous discussions about the same feature or issue. Add to the earlier ticket if you find one.
4 |
5 | * Before sending a pull request for a feature, be sure to have [tests](http://underscorejs.org/test/test.html).
6 |
7 | * Use the same coding style as the rest of the [codebase](https://github.com/documentcloud/underscore/blob/master/underscore.js).
8 |
9 | * In your pull request, do not add documentation or re-build the minified `underscore-min.js` file. We'll do those things before cutting a new release.
--------------------------------------------------------------------------------
/node_modules/underscore/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009-2012 Jeremy Ashkenas, DocumentCloud
2 |
3 | Permission is hereby granted, free of charge, to any person
4 | obtaining a copy of this software and associated documentation
5 | files (the "Software"), to deal in the Software without
6 | restriction, including without limitation the rights to use,
7 | copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the
9 | Software is furnished to do so, subject to the following
10 | conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/node_modules/underscore/README.md:
--------------------------------------------------------------------------------
1 | __
2 | /\ \ __
3 | __ __ ___ \_\ \ __ _ __ ____ ___ ___ _ __ __ /\_\ ____
4 | /\ \/\ \ /' _ `\ /'_ \ /'__`\/\ __\/ ,__\ / ___\ / __`\/\ __\/'__`\ \/\ \ /',__\
5 | \ \ \_\ \/\ \/\ \/\ \ \ \/\ __/\ \ \//\__, `\/\ \__//\ \ \ \ \ \//\ __/ __ \ \ \/\__, `\
6 | \ \____/\ \_\ \_\ \___,_\ \____\\ \_\\/\____/\ \____\ \____/\ \_\\ \____\/\_\ _\ \ \/\____/
7 | \/___/ \/_/\/_/\/__,_ /\/____/ \/_/ \/___/ \/____/\/___/ \/_/ \/____/\/_//\ \_\ \/___/
8 | \ \____/
9 | \/___/
10 |
11 | Underscore.js is a utility-belt library for JavaScript that provides
12 | support for the usual functional suspects (each, map, reduce, filter...)
13 | without extending any core JavaScript objects.
14 |
15 | For Docs, License, Tests, and pre-packed downloads, see:
16 | http://underscorejs.org
17 |
18 | Many thanks to our contributors:
19 | https://github.com/documentcloud/underscore/contributors
20 |
--------------------------------------------------------------------------------
/node_modules/underscore/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/olleicua/hcl/62c71f382a173d43fa3730f7881748a54ecdba07/node_modules/underscore/favicon.ico
--------------------------------------------------------------------------------
/node_modules/underscore/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./underscore');
2 |
--------------------------------------------------------------------------------
/node_modules/underscore/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "underscore",
3 | "description": "JavaScript's functional programming helper library.",
4 | "homepage": "http://underscorejs.org",
5 | "keywords": [
6 | "util",
7 | "functional",
8 | "server",
9 | "client",
10 | "browser"
11 | ],
12 | "author": {
13 | "name": "Jeremy Ashkenas",
14 | "email": "jeremy@documentcloud.org"
15 | },
16 | "repository": {
17 | "type": "git",
18 | "url": "git://github.com/documentcloud/underscore.git"
19 | },
20 | "main": "underscore.js",
21 | "version": "1.4.3",
22 | "_id": "underscore@1.4.3",
23 | "dependencies": {},
24 | "devDependencies": {},
25 | "optionalDependencies": {},
26 | "engines": {
27 | "node": "*"
28 | },
29 | "_engineSupported": true,
30 | "_npmVersion": "1.1.16",
31 | "_nodeVersion": "v0.8.9",
32 | "_defaultsLoaded": true,
33 | "_from": "underscore"
34 | }
35 |
--------------------------------------------------------------------------------
/node_modules/underscore/raw/underscore.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/olleicua/hcl/62c71f382a173d43fa3730f7881748a54ecdba07/node_modules/underscore/raw/underscore.psd
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "hot-cocoa-lisp",
3 | "version": "0.1.11",
4 | "author": "Sam Auciello ",
5 | "description": "A Lisp-style language that compiles to JavaScript",
6 | "repository": {
7 | "type": "git",
8 | "url": "https://github.com/olleicua/hcl.git"
9 | },
10 | "bin": {
11 | "hcl": "./bin/hcl"
12 | },
13 | "keywords": [
14 | ],
15 | "dependencies": {
16 | "hot-cocoa": "0.0.4",
17 | "optimist": "0.3.5",
18 | "uglify-js": "2.2.5",
19 | "underscore": "1.4.3"
20 | },
21 | "license": "MIT",
22 | "engines": {
23 | "node": ">=0.8.9"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/parseTests.js:
--------------------------------------------------------------------------------
1 | module.exports = function(string2ast) {
2 | return [
3 | [function() {
4 | return string2ast('"this is a quote: \\" ..."').json(true); },
5 | '"this is a quote: \\" ..."'],
6 | [function() {
7 | return string2ast('"this is a backslash: \\\\" ; this is a comment').json(true); },
8 | '"this is a backslash: \\\\"'],
9 | [function() {
10 | return string2ast('(a\nb)').json(true); },
11 | '[a, b]'],
12 | [function() {
13 | return string2ast('(+ 1 2)').json(true); },
14 | '[+, 1, 2]'],
15 | [function() {
16 | return string2ast('(cat "hello" " world")').json(true); },
17 | '[cat, "hello", " world"]'],
18 | [function() {
19 | return string2ast('[]').json(true); },
20 | '[list]'],
21 | [function() {
22 | return string2ast(';; foo\n[]').json(true); },
23 | '[list]'],
24 | [function() {
25 | return string2ast('[1];; bar\n').json(true); },
26 | '[list, 1]'],
27 | [function() {
28 | return string2ast('[1 2 3]').json(true); },
29 | '[list, 1, 2, 3]'],
30 | [function() {
31 | return string2ast('{}').json(true); },
32 | '[object]'],
33 | [function() {
34 | return string2ast('{a 1 b 2}').json(true); },
35 | '[object, a, 1, b, 2]'],
36 | [function() {
37 | return string2ast('{a [1 2 3] b [{x 4} {x 5} {x 6}]}').json(true); },
38 | '[object, a, [list, 1, 2, 3], b, [list, [object, x, 4], [object, x, 5], ' +
39 | '[object, x, 6]]]'],
40 | [function() {
41 | return string2ast('foo.bar').json(true); },
42 | '[., foo, bar]'],
43 | [function() {
44 | return string2ast('foo.bar.baz').json(true); },
45 | '[., foo, bar, baz]'],
46 | [function() {
47 | return string2ast('(a b).c.d').json(true); },
48 | '[., [a, b], c, d]'],
49 | [function() {
50 | return string2ast('(console.log "Hello World!")').json(true); },
51 | '[[., console, log], "Hello World!"]'],
52 | [function() {
53 | return string2ast('(($ "div#foo").css "background-color" "#ffaaaa")').json(true); },
54 | '[[., [$, "div#foo"], css], "background-color", "#ffaaaa"]'],
55 | [function() {
56 | return string2ast('(($ "div#foo").css { background-color "#ffaaaa" padding "5em"})').json(true); },
57 | '[[., [$, "div#foo"], css], [object, background-color, "#ffaaaa", ' +
58 | 'padding, "5em"]]'],
59 | [function() {
60 | return string2ast('(def empty? (# (l) (= 0 (length l))))').json(true); },
61 | '[def, empty?, [#, [l], [=, 0, [length, l]]]]'],
62 | [function() {
63 | return string2ast(
64 | '(def empty? (# (l) (if (= 0 (length l)) true false)))'
65 | ).json(true); },
66 | '[def, empty?, [#, [l], [if, [=, 0, [length, l]], true, false]]]'],
67 | [function() {
68 | return string2ast('([1 2 3].slice 2 3)').json(true); },
69 | '[[., [list, 1, 2, 3], slice], 2, 3]']
70 | ];
71 | };
--------------------------------------------------------------------------------
/tests/compile.js:
--------------------------------------------------------------------------------
1 | var _ = require('underscore');
2 | var hcl = require('../lib/parser.js');
3 |
4 | var compile = function(source) {
5 | return require('../lib/compile.js')(hcl.analyze(hcl.parse(hcl.scan(source)))[0],
6 | undefined, undefined, {
7 | add_to_outer_scope: _.identity,
8 | omit_annotations: true });
9 | };
10 |
11 | var compile_test = function(source) {
12 | return function() {
13 | return compile(source).replace(/\n/gm, '');
14 | };
15 | }
16 |
17 | var eval_test = function(source) {
18 | return function() {
19 | return eval('(' + compile(source).trim().replace(/;$/, '').replace(/var/, '') + ')');
20 | };
21 | }
22 |
23 | var tests = [
24 | [compile_test('(if 1)'),
25 | 'Error: Wrong number of arguments for `if`: 1 for 3 at position 1:0'],
26 | [compile_test('(console.log "hello")'),
27 | 'console["log"]("hello");'],
28 | [compile_test('(console.log (if true "yes" "no"))'),
29 | 'console["log"]((true ? "yes" : "no"));'],
30 | [eval_test('(+ 2 1/2)'),
31 | 2.5],
32 | [eval_test('(= 1 2 2)'),
33 | false],
34 | [eval_test('(= false false false)'),
35 | true],
36 | [eval_test('(= \'foo\' "foo")'),
37 | true],
38 | [eval_test('(cond ((< 6 8) "less") (true "not less"))'),
39 | 'less'],
40 | [eval_test('(cond ((< 16 8) "less") (true "not less"))'),
41 | 'not less'],
42 | [eval_test('((# (x) (+ x 1)) 2)'),
43 | 3],
44 | [eval_test('(>= (* 2 3 5) (/ 45 1.5) 0 (- 10 11))'),
45 | true],
46 | [eval_test('(>= (* 2 3 5) (/ 45 1.5) 0 (- 10 11) 7)'),
47 | false],
48 | [eval_test('(and (xor true false) (not (xor true true)))'),
49 | true],
50 | [eval_test('"\\""'),
51 | '"'],
52 | [eval_test('(cat "Hello" " " "World" (if true "!" ""))'),
53 | 'Hello World!'],
54 | [eval_test('[1 2 3]'),
55 | [1, 2, 3]],
56 | [eval_test('{a 1 b 2}'),
57 | { a: 1, b: 2 }],
58 | [compile_test('(from-js foo_bar_baz)'),
59 | 'foo_bar_baz;'],
60 | [compile_test('(from-js foo_bar_baz+)'),
61 | 'Error: `foo_bar_baz+` is not a valid JavaScript identifier'],
62 | [eval_test('{+ 1}'),
63 | { '+': 1 }],
64 | [eval_test('(begin (set _!?$%|~*+-=\/<>^ { _!?$%|~*+-=\/<>^ 10 } ) (get _!?$%|~*+-=\/<>^ "_!?$%|~*+-=\/<>^"))'),
65 | 10],
66 | [eval_test('(begin (set +-/ { +-/ 1 } ) +-/.+-/)'),
67 | 1],
68 | [eval_test('(begin (set foo { x_x 1 "y_y" 2 } ) (+ (get foo "x_x") foo.y_y))'),
69 | 3],
70 | [eval_test('(begin (set foo { } ) (set foo "y_y" 1) (set foo.x_x 1) (set+ foo.x_x 1) (+ (get foo "x_x") foo.y_y))'),
71 | 3],
72 | [eval_test('(begin (set foo 2) (set+ foo 1) (set* foo 4) (set- foo 3) (set/ foo 3) foo)'),
73 | 3],
74 | [eval_test('(begin (set foo { x 2 } ) (set+ foo "x" 1) (set* foo "x" 4) (set- foo "x" 3) (set/ foo "x" 3) (get foo "x"))'),
75 | 3],
76 | [eval_test('(begin (set foo { x 2 } ) (set<< foo "x" 2) (set>> foo "x" 1) (set| foo "x" 2) (set& foo "x" 4) (get foo "x"))'),
77 | 4],
78 | [eval_test('(odd? 21)'),
79 | true],
80 | [eval_test('(empty? [])'),
81 | true],
82 | [eval_test('(empty? "")'),
83 | true],
84 | [eval_test('(empty? "foo")'),
85 | false],
86 | [eval_test('(empty? 17)'),
87 | false],
88 | [eval_test('(get [1 2 3] 0)'),
89 | 1],
90 | [eval_test('(get {a 1 b 2} "b")'),
91 | 2],
92 | [eval_test('((# (x...) x.length) 1 2 3 4)'),
93 | 4],
94 | [eval_test('(replace "foo" (re "o") "0")'),
95 | "f0o"],
96 | [eval_test('(replace "foo" (re "O" "i") "0")'),
97 | "f0o"],
98 | [eval_test('(replace "foo" (re "o" "g") "0")'),
99 | "f00"],
100 | [eval_test('(replace "1 2 3 {4} 5 {6}" (re "{(\\d)}" "g") "[$1]")'),
101 | '1 2 3 [4] 5 [6]'],
102 | [eval_test('(and (= (+1 7) (*2 4)) (< (/2 10) (--1 8)))'),
103 | true],
104 | [eval_test('(= (<< 7 9) (* 7 (^ 2 9)))'),
105 | true],
106 | [eval_test('(and (positive? 1) (negative? -2) (non-positive? 0) (non-negative? 10))'),
107 | true],
108 | [eval_test('(or (positive? -1) (negative? 0) (non-positive? 1) (non-negative? -10))'),
109 | false],
110 | [eval_test('(and (number? (random-float)) (integer? (random-integer 10)))'),
111 | true],
112 | [eval_test('(= (first [ 1 ] ) (second [ 0 1 ]) (last [ 3 2 1 ] ))'),
113 | true],
114 | [eval_test('(bit-xor 5 15)'),
115 | 10],
116 | [eval_test('(cat (type []) (type {}) (type (# () (nop))) (type "") (type 7))'),
117 | 'ArrayObjectFunctionStringNumber'],
118 | [eval_test('(cat (type (re "foo")) (type null) (type undefined) (type NaN))'),
119 | 'RegExpNullUndefinedNaN'],
120 | [eval_test('(and (nil? null) (boolean? true) (number? 7.5) (string? "foo"))'),
121 | true],
122 | [eval_test('(and (list? []) (object? {}) (function? (# () (nop))) (empty? ""))'),
123 | true],
124 | [eval_test('(and (integer? 7) (even? 8) (odd? 9) (contains? [1] 1))'),
125 | true],
126 | [eval_test('(or (nil? 0) (boolean? undefined) (number? "bar") (string? []))'),
127 | false],
128 | [eval_test('(or (list? {}) (object? 5) (function? {}) (empty? "x"))'),
129 | false],
130 | [eval_test('(or (integer? 7.5) (even? 9) (odd? 8) (contains? [1] 2))'),
131 | false],
132 | [eval_test('(and (number? Infinity) (number? -Infinity) (< -Infinity 0 Infinity) (= Infinity (/ 1 0)))'),
133 | true],
134 | [eval_test('((# fib (n) (if (< n 1) 1 (+ (fib (--1 n)) (fib (- n 2))))) 8)'),
135 | 55],
136 | [eval_test('((# factorial (n) (if (= n 1) 1 (* n (factorial (--1 n))))) 6)'),
137 | 720],
138 | [eval_test('(let (a 1 (b c) [ 2 3 ] ) [ a b c c b a ] )'),
139 | [1, 2, 3, 3, 2, 1]],
140 | [eval_test('(replace "bar" "r" "z")'),
141 | 'baz'],
142 | [eval_test('1/2'),
143 | 0.5],
144 | [eval_test('2/1'),
145 | 2],
146 | [eval_test('0/2'),
147 | 0],
148 | [eval_test('(type 0/0)'),
149 | "NaN"],
150 | [eval_test('(type -0/0)'),
151 | "NaN"],
152 | [eval_test('3/0'),
153 | 2/0],
154 | [eval_test('-4/0'),
155 | -1/0],
156 | [eval_test('0/2'),
157 | 0],
158 | [compile_test('@'),
159 | "this;"],
160 | [compile_test('@foo'),
161 | "this['foo'];"],
162 | [compile_test('00'),
163 | "unrecognizable token at 1:0"],
164 | [compile_test('01/1'),
165 | "unrecognizable token at 1:0"]
166 | // TODO: make this test give a more correct error message
167 | //[compile_test('1/09'),
168 | // "unrecognizable token at 1:0"]
169 | ];
170 |
171 | require('hot-cocoa').test(tests);
172 |
--------------------------------------------------------------------------------
/tests/full.js:
--------------------------------------------------------------------------------
1 | /* Tests
2 | */
3 |
4 | var _ = require('underscore');
5 | var fs = require('fs');
6 | var exec = require('child_process').exec;
7 | var format = require('hot-cocoa').format;
8 |
9 | var files = fs.readdirSync('./examples').filter(function(f) {
10 | return /\.out$/.exec(f);
11 | });
12 |
13 | var tests = [];
14 |
15 | for (var i = 0; i < files.length; i++) {
16 | (function (j) {
17 | var name = /^(.*)\.out/.exec(files[j])[1];
18 | exec(format('./bin/hcl -u examples/~0~.hcl && node examples/~0~.js', [name]),
19 | function(error, stdout, stderr) {
20 | tests.push([
21 | stdout,
22 | fs.readFileSync(format('examples/~~', [files[j]])).toString()
23 | ]);
24 | if (tests.length === files.length) {
25 | require('hot-cocoa').test(tests);
26 | }
27 | });
28 | })(i);
29 | }
30 |
--------------------------------------------------------------------------------
/tests/text2ast.js:
--------------------------------------------------------------------------------
1 | /* Tests
2 | */
3 |
4 | var hcl = require('../lib/parser.js');
5 |
6 | var string2ast = function(string) {
7 | var tokens = hcl.scan(string);
8 | var tree = hcl.parse(tokens);
9 | return hcl.analyze(tree)[0][0];
10 | };
11 |
12 | var tests = require('../parseTests.js')(string2ast);
13 |
14 | require('hot-cocoa').test(tests);
15 |
--------------------------------------------------------------------------------
/tests/text2astRD.js:
--------------------------------------------------------------------------------
1 | /* Tests
2 | */
3 |
4 | var hcl = require('../lib/parser.js');
5 |
6 | var string2ast = function(string) {
7 | var tokens = hcl.scan(string);
8 | var tree = hcl.parse(tokens, require('hot-cocoa').RD);
9 | return hcl.analyze(tree)[0][0];
10 | };
11 |
12 | var tests = require('../parseTests.js')(string2ast);
13 |
14 | require('hot-cocoa').test(tests);
15 |
--------------------------------------------------------------------------------