holmes 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/README.md +10 -0
  4. data/Rakefile +1 -0
  5. data/holmes.gemspec +24 -0
  6. data/lib/holmes.rb +38 -0
  7. data/lib/holmes/node_modules/detective/README.markdown +64 -0
  8. data/lib/holmes/node_modules/detective/example/strings.js +6 -0
  9. data/lib/holmes/node_modules/detective/example/strings_src.js +3 -0
  10. data/lib/holmes/node_modules/detective/index.js +65 -0
  11. data/lib/holmes/node_modules/detective/node_modules/burrito/.npmignore +1 -0
  12. data/lib/holmes/node_modules/detective/node_modules/burrito/README.markdown +185 -0
  13. data/lib/holmes/node_modules/detective/node_modules/burrito/browserify.js +4296 -0
  14. data/lib/holmes/node_modules/detective/node_modules/burrito/example/microwave.js +7 -0
  15. data/lib/holmes/node_modules/detective/node_modules/burrito/example/web/bs.js +4832 -0
  16. data/lib/holmes/node_modules/detective/node_modules/burrito/example/web/index.html +14 -0
  17. data/lib/holmes/node_modules/detective/node_modules/burrito/example/web/main.js +17 -0
  18. data/lib/holmes/node_modules/detective/node_modules/burrito/example/web/server.js +12 -0
  19. data/lib/holmes/node_modules/detective/node_modules/burrito/example/wrap.js +7 -0
  20. data/lib/holmes/node_modules/detective/node_modules/burrito/index.html +8 -0
  21. data/lib/holmes/node_modules/detective/node_modules/burrito/index.js +208 -0
  22. data/lib/holmes/node_modules/detective/node_modules/burrito/main.js +11 -0
  23. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/.bin/uglifyjs +317 -0
  24. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/.npmignore +1 -0
  25. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/LICENSE +24 -0
  26. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/README.markdown +237 -0
  27. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/json.js +16 -0
  28. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/leaves.js +15 -0
  29. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/negative.js +8 -0
  30. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/scrub.js +10 -0
  31. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/examples/stringify.js +38 -0
  32. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/index.js +267 -0
  33. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/main.js +10 -0
  34. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/package.json +18 -0
  35. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/circular.js +115 -0
  36. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/date.js +35 -0
  37. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/equal.js +220 -0
  38. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/instance.js +17 -0
  39. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/interface.js +42 -0
  40. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/json.js +47 -0
  41. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/keys.js +29 -0
  42. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/leaves.js +21 -0
  43. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/lib/deep_equal.js +92 -0
  44. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/mutability.js +252 -0
  45. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/negative.js +20 -0
  46. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/obj.js +15 -0
  47. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/siblings.js +35 -0
  48. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/stop.js +41 -0
  49. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/stringify.js +36 -0
  50. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/subexpr.js +34 -0
  51. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/super_deep.js +55 -0
  52. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/.npmignore +4 -0
  53. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/README.html +888 -0
  54. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/README.org +463 -0
  55. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/bin/uglifyjs +317 -0
  56. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/docstyle.css +75 -0
  57. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/object-ast.js +75 -0
  58. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/parse-js.js +1341 -0
  59. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/process.js +1949 -0
  60. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/lib/squeeze-more.js +51 -0
  61. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/package.json +22 -0
  62. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/beautify.js +28 -0
  63. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/testparser.js +402 -0
  64. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/array1.js +1 -0
  65. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/array2.js +1 -0
  66. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/array3.js +1 -0
  67. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/array4.js +1 -0
  68. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/assignment.js +1 -0
  69. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/concatstring.js +1 -0
  70. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/const.js +1 -0
  71. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/empty-blocks.js +1 -0
  72. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/forstatement.js +1 -0
  73. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/if.js +1 -0
  74. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/ifreturn.js +1 -0
  75. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/ifreturn2.js +1 -0
  76. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue10.js +1 -0
  77. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue11.js +1 -0
  78. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue13.js +1 -0
  79. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue14.js +1 -0
  80. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue16.js +1 -0
  81. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue17.js +1 -0
  82. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue20.js +1 -0
  83. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue21.js +1 -0
  84. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue25.js +1 -0
  85. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue27.js +1 -0
  86. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue28.js +1 -0
  87. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue29.js +1 -0
  88. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue30.js +1 -0
  89. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue34.js +1 -0
  90. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue4.js +1 -0
  91. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue48.js +1 -0
  92. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue50.js +1 -0
  93. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue53.js +1 -0
  94. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue54.1.js +1 -0
  95. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue68.js +1 -0
  96. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue69.js +1 -0
  97. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/issue9.js +1 -0
  98. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/mangle.js +1 -0
  99. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/strict-equals.js +1 -0
  100. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/var.js +1 -0
  101. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/expected/with.js +1 -0
  102. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/array1.js +3 -0
  103. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/array2.js +4 -0
  104. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/array3.js +4 -0
  105. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/array4.js +6 -0
  106. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/assignment.js +20 -0
  107. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/concatstring.js +3 -0
  108. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/const.js +5 -0
  109. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/empty-blocks.js +4 -0
  110. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/forstatement.js +10 -0
  111. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/if.js +6 -0
  112. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/ifreturn.js +9 -0
  113. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/ifreturn2.js +16 -0
  114. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue10.js +1 -0
  115. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue11.js +3 -0
  116. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue13.js +1 -0
  117. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue14.js +1 -0
  118. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue16.js +1 -0
  119. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue17.js +4 -0
  120. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue20.js +1 -0
  121. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue21.js +6 -0
  122. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue25.js +7 -0
  123. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue27.js +1 -0
  124. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue28.js +3 -0
  125. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue29.js +1 -0
  126. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue30.js +3 -0
  127. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue34.js +3 -0
  128. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue4.js +3 -0
  129. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue48.js +1 -0
  130. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue50.js +9 -0
  131. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue53.js +1 -0
  132. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue54.1.js +3 -0
  133. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue68.js +5 -0
  134. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue69.js +1 -0
  135. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/issue9.js +4 -0
  136. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/mangle.js +5 -0
  137. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/strict-equals.js +3 -0
  138. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/var.js +3 -0
  139. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/compress/test/with.js +2 -0
  140. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/test/unit/scripts.js +55 -0
  141. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/tmp/hoist.js +33 -0
  142. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/tmp/instrument.js +97 -0
  143. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/tmp/instrument2.js +138 -0
  144. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/tmp/test.js +16 -0
  145. data/lib/holmes/node_modules/detective/node_modules/burrito/node_modules/uglify-js/uglify-js.js +17 -0
  146. data/lib/holmes/node_modules/detective/node_modules/burrito/package.json +43 -0
  147. data/lib/holmes/node_modules/detective/node_modules/burrito/server.js +4 -0
  148. data/lib/holmes/node_modules/detective/node_modules/burrito/test/ast.js +29 -0
  149. data/lib/holmes/node_modules/detective/node_modules/burrito/test/err.js +47 -0
  150. data/lib/holmes/node_modules/detective/node_modules/burrito/test/fail.js +8 -0
  151. data/lib/holmes/node_modules/detective/node_modules/burrito/test/fail/src.js +60 -0
  152. data/lib/holmes/node_modules/detective/node_modules/burrito/test/label.js +110 -0
  153. data/lib/holmes/node_modules/detective/node_modules/burrito/test/microwave.js +33 -0
  154. data/lib/holmes/node_modules/detective/node_modules/burrito/test/parent.js +26 -0
  155. data/lib/holmes/node_modules/detective/node_modules/burrito/test/wrap.js +157 -0
  156. data/lib/holmes/node_modules/detective/package.json +39 -0
  157. data/lib/holmes/node_modules/detective/test/both.js +10 -0
  158. data/lib/holmes/node_modules/detective/test/files/both.js +4 -0
  159. data/lib/holmes/node_modules/detective/test/files/nested.js +22 -0
  160. data/lib/holmes/node_modules/detective/test/files/strings.js +13 -0
  161. data/lib/holmes/node_modules/detective/test/files/word.js +13 -0
  162. data/lib/holmes/node_modules/detective/test/nested.js +8 -0
  163. data/lib/holmes/node_modules/detective/test/strings.js +8 -0
  164. data/lib/holmes/node_modules/detective/test/word.js +11 -0
  165. data/lib/holmes/require.js +5 -0
  166. data/lib/holmes/runner.js +20 -0
  167. data/lib/holmes/version.rb +3 -0
  168. metadata +223 -0
@@ -0,0 +1,51 @@
1
+ var jsp = require("./parse-js"),
2
+ pro = require("./process"),
3
+ slice = jsp.slice,
4
+ member = jsp.member,
5
+ curry = jsp.curry,
6
+ MAP = pro.MAP,
7
+ PRECEDENCE = jsp.PRECEDENCE,
8
+ OPERATORS = jsp.OPERATORS;
9
+
10
+ function ast_squeeze_more(ast) {
11
+ var w = pro.ast_walker(), walk = w.walk, scope;
12
+ function with_scope(s, cont) {
13
+ var save = scope, ret;
14
+ scope = s;
15
+ ret = cont();
16
+ scope = save;
17
+ return ret;
18
+ };
19
+ function _lambda(name, args, body) {
20
+ return [ this[0], name, args, with_scope(body.scope, curry(MAP, body, walk)) ];
21
+ };
22
+ return w.with_walkers({
23
+ "toplevel": function(body) {
24
+ return [ this[0], with_scope(this.scope, curry(MAP, body, walk)) ];
25
+ },
26
+ "function": _lambda,
27
+ "defun": _lambda,
28
+ "new": function(ctor, args) {
29
+ if (ctor[0] == "name" && ctor[1] == "Array" && !scope.has("Array")) {
30
+ if (args.length != 1) {
31
+ return [ "array", args ];
32
+ } else {
33
+ return walk([ "call", [ "name", "Array" ], args ]);
34
+ }
35
+ }
36
+ },
37
+ "call": function(expr, args) {
38
+ if (expr[0] == "dot" && expr[2] == "toString" && args.length == 0) {
39
+ // foo.toString() ==> foo+""
40
+ return [ "binary", "+", expr[1], [ "string", "" ]];
41
+ }
42
+ if (expr[0] == "name" && expr[1] == "Array" && args.length != 1 && !scope.has("Array")) {
43
+ return [ "array", args ];
44
+ }
45
+ }
46
+ }, function() {
47
+ return walk(pro.ast_add_scope(ast));
48
+ });
49
+ };
50
+
51
+ exports.ast_squeeze_more = ast_squeeze_more;
@@ -0,0 +1,22 @@
1
+ {
2
+ "name" : "uglify-js",
3
+
4
+ "author" : {
5
+ "name" : "Mihai Bazon",
6
+ "email" : "mihai.bazon@gmail.com",
7
+ "url" : "http://mihai.bazon.net/blog"
8
+ },
9
+
10
+ "version" : "1.0.7",
11
+
12
+ "main" : "./uglify-js.js",
13
+
14
+ "bin" : {
15
+ "uglifyjs" : "./bin/uglifyjs"
16
+ },
17
+
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git@github.com:mishoo/UglifyJS.git"
21
+ }
22
+ }
@@ -0,0 +1,28 @@
1
+ #! /usr/bin/env node
2
+
3
+ global.sys = require("sys");
4
+ var fs = require("fs");
5
+
6
+ var jsp = require("../lib/parse-js");
7
+ var pro = require("../lib/process");
8
+
9
+ var filename = process.argv[2];
10
+ fs.readFile(filename, "utf8", function(err, text){
11
+ try {
12
+ var ast = time_it("parse", function(){ return jsp.parse(text); });
13
+ ast = time_it("mangle", function(){ return pro.ast_mangle(ast); });
14
+ ast = time_it("squeeze", function(){ return pro.ast_squeeze(ast); });
15
+ var gen = time_it("generate", function(){ return pro.gen_code(ast, false); });
16
+ sys.puts(gen);
17
+ } catch(ex) {
18
+ sys.debug(ex.stack);
19
+ sys.debug(sys.inspect(ex));
20
+ sys.debug(JSON.stringify(ex));
21
+ }
22
+ });
23
+
24
+ function time_it(name, cont) {
25
+ var t1 = new Date().getTime();
26
+ try { return cont(); }
27
+ finally { sys.debug("// " + name + ": " + ((new Date().getTime() - t1) / 1000).toFixed(3) + " sec."); }
28
+ };
@@ -0,0 +1,402 @@
1
+ #! /usr/bin/env node
2
+
3
+ var parseJS = require("../lib/parse-js");
4
+ var sys = require("sys");
5
+
6
+ // write debug in a very straightforward manner
7
+ var debug = function(){
8
+ sys.log(Array.prototype.slice.call(arguments).join(', '));
9
+ };
10
+
11
+ ParserTestSuite(function(i, input, desc){
12
+ try {
13
+ parseJS.parse(input);
14
+ debug("ok " + i + ": " + desc);
15
+ } catch(e){
16
+ debug("FAIL " + i + " " + desc + " (" + e + ")");
17
+ }
18
+ });
19
+
20
+ function ParserTestSuite(callback){
21
+ var inps = [
22
+ ["var abc;", "Regular variable statement w/o assignment"],
23
+ ["var abc = 5;", "Regular variable statement with assignment"],
24
+ ["/* */;", "Multiline comment"],
25
+ ['/** **/;', 'Double star multiline comment'],
26
+ ["var f = function(){;};", "Function expression in var assignment"],
27
+ ['hi; // moo\n;', 'single line comment'],
28
+ ['var varwithfunction;', 'Dont match keywords as substrings'], // difference between `var withsomevar` and `"str"` (local search and lits)
29
+ ['a + b;', 'addition'],
30
+ ["'a';", 'single string literal'],
31
+ ["'a\\n';", 'single string literal with escaped return'],
32
+ ['"a";', 'double string literal'],
33
+ ['"a\\n";', 'double string literal with escaped return'],
34
+ ['"var";', 'string is a keyword'],
35
+ ['"variable";', 'string starts with a keyword'],
36
+ ['"somevariable";', 'string contains a keyword'],
37
+ ['"somevar";', 'string ends with a keyword'],
38
+ ['500;', 'int literal'],
39
+ ['500.;', 'float literal w/o decimals'],
40
+ ['500.432;', 'float literal with decimals'],
41
+ ['.432432;', 'float literal w/o int'],
42
+ ['(a,b,c);', 'parens and comma'],
43
+ ['[1,2,abc];', 'array literal'],
44
+ ['var o = {a:1};', 'object literal unquoted key'],
45
+ ['var o = {"b":2};', 'object literal quoted key'], // opening curly may not be at the start of a statement...
46
+ ['var o = {c:c};', 'object literal keyname is identifier'],
47
+ ['var o = {a:1,"b":2,c:c};', 'object literal combinations'],
48
+ ['var x;\nvar y;', 'two lines'],
49
+ ['var x;\nfunction n(){; }', 'function def'],
50
+ ['var x;\nfunction n(abc){; }', 'function def with arg'],
51
+ ['var x;\nfunction n(abc, def){ ;}', 'function def with args'],
52
+ ['function n(){ "hello"; }', 'function def with body'],
53
+ ['/a/;', 'regex literal'],
54
+ ['/a/b;', 'regex literal with flag'],
55
+ ['/a/ / /b/;', 'regex div regex'],
56
+ ['a/b/c;', 'triple division looks like regex'],
57
+ ['+function(){/regex/;};', 'regex at start of function body'],
58
+ // http://code.google.com/p/es-lab/source/browse/trunk/tests/parser/parsertests.js?r=86
59
+ // http://code.google.com/p/es-lab/source/browse/trunk/tests/parser/parsertests.js?r=430
60
+
61
+ // first tests for the lexer, should also parse as program (when you append a semi)
62
+
63
+ // comments
64
+ ['//foo!@#^&$1234\nbar;', 'single line comment'],
65
+ ['/* abcd!@#@$* { } && null*/;', 'single line multi line comment'],
66
+ ['/*foo\nbar*/;','multi line comment'],
67
+ ['/*x*x*/;','multi line comment with *'],
68
+ ['/**/;','empty comment'],
69
+ // identifiers
70
+ ["x;",'1 identifier'],
71
+ ["_x;",'2 identifier'],
72
+ ["xyz;",'3 identifier'],
73
+ ["$x;",'4 identifier'],
74
+ ["x$;",'5 identifier'],
75
+ ["_;",'6 identifier'],
76
+ ["x5;",'7 identifier'],
77
+ ["x_y;",'8 identifier'],
78
+ ["x+5;",'9 identifier'],
79
+ ["xyz123;",'10 identifier'],
80
+ ["x1y1z1;",'11 identifier'],
81
+ ["foo\\u00D8bar;",'12 identifier unicode escape'],
82
+ //["foo�bar;",'13 identifier unicode embedded (might fail)'],
83
+ // numbers
84
+ ["5;", '1 number'],
85
+ ["5.5;", '2 number'],
86
+ ["0;", '3 number'],
87
+ ["0.0;", '4 number'],
88
+ ["0.001;", '5 number'],
89
+ ["1.e2;", '6 number'],
90
+ ["1.e-2;", '7 number'],
91
+ ["1.E2;", '8 number'],
92
+ ["1.E-2;", '9 number'],
93
+ [".5;", '10 number'],
94
+ [".5e3;", '11 number'],
95
+ [".5e-3;", '12 number'],
96
+ ["0.5e3;", '13 number'],
97
+ ["55;", '14 number'],
98
+ ["123;", '15 number'],
99
+ ["55.55;", '16 number'],
100
+ ["55.55e10;", '17 number'],
101
+ ["123.456;", '18 number'],
102
+ ["1+e;", '20 number'],
103
+ ["0x01;", '22 number'],
104
+ ["0XCAFE;", '23 number'],
105
+ ["0x12345678;", '24 number'],
106
+ ["0x1234ABCD;", '25 number'],
107
+ ["0x0001;", '26 number'],
108
+ // strings
109
+ ["\"foo\";", '1 string'],
110
+ ["\'foo\';", '2 string'],
111
+ ["\"x\";", '3 string'],
112
+ ["\'\';", '4 string'],
113
+ ["\"foo\\tbar\";", '5 string'],
114
+ ["\"!@#$%^&*()_+{}[]\";", '6 string'],
115
+ ["\"/*test*/\";", '7 string'],
116
+ ["\"//test\";", '8 string'],
117
+ ["\"\\\\\";", '9 string'],
118
+ ["\"\\u0001\";", '10 string'],
119
+ ["\"\\uFEFF\";", '11 string'],
120
+ ["\"\\u10002\";", '12 string'],
121
+ ["\"\\x55\";", '13 string'],
122
+ ["\"\\x55a\";", '14 string'],
123
+ ["\"a\\\\nb\";", '15 string'],
124
+ ['";"', '16 string: semi in a string'],
125
+ ['"a\\\nb";', '17 string: line terminator escape'],
126
+ // literals
127
+ ["null;", "null"],
128
+ ["true;", "true"],
129
+ ["false;", "false"],
130
+ // regex
131
+ ["/a/;", "1 regex"],
132
+ ["/abc/;", "2 regex"],
133
+ ["/abc[a-z]*def/g;", "3 regex"],
134
+ ["/\\b/;", "4 regex"],
135
+ ["/[a-zA-Z]/;", "5 regex"],
136
+
137
+ // program tests (for as far as they havent been covered above)
138
+
139
+ // regexp
140
+ ["/foo(.*)/g;", "another regexp"],
141
+ // arrays
142
+ ["[];", "1 array"],
143
+ ["[ ];", "2 array"],
144
+ ["[1];", "3 array"],
145
+ ["[1,2];", "4 array"],
146
+ ["[1,2,,];", "5 array"],
147
+ ["[1,2,3];", "6 array"],
148
+ ["[1,2,3,,,];", "7 array"],
149
+ // objects
150
+ ["{};", "1 object"],
151
+ ["({x:5});", "2 object"],
152
+ ["({x:5,y:6});", "3 object"],
153
+ ["({x:5,});", "4 object"],
154
+ ["({if:5});", "5 object"],
155
+ ["({ get x() {42;} });", "6 object"],
156
+ ["({ set y(a) {1;} });", "7 object"],
157
+ // member expression
158
+ ["o.m;", "1 member expression"],
159
+ ["o['m'];", "2 member expression"],
160
+ ["o['n']['m'];", "3 member expression"],
161
+ ["o.n.m;", "4 member expression"],
162
+ ["o.if;", "5 member expression"],
163
+ // call and invoke expressions
164
+ ["f();", "1 call/invoke expression"],
165
+ ["f(x);", "2 call/invoke expression"],
166
+ ["f(x,y);", "3 call/invoke expression"],
167
+ ["o.m();", "4 call/invoke expression"],
168
+ ["o['m'];", "5 call/invoke expression"],
169
+ ["o.m(x);", "6 call/invoke expression"],
170
+ ["o['m'](x);", "7 call/invoke expression"],
171
+ ["o.m(x,y);", "8 call/invoke expression"],
172
+ ["o['m'](x,y);", "9 call/invoke expression"],
173
+ ["f(x)(y);", "10 call/invoke expression"],
174
+ ["f().x;", "11 call/invoke expression"],
175
+
176
+ // eval
177
+ ["eval('x');", "1 eval"],
178
+ ["(eval)('x');", "2 eval"],
179
+ ["(1,eval)('x');", "3 eval"],
180
+ ["eval(x,y);", "4 eval"],
181
+ // new expression
182
+ ["new f();", "1 new expression"],
183
+ ["new o;", "2 new expression"],
184
+ ["new o.m;", "3 new expression"],
185
+ ["new o.m(x);", "4 new expression"],
186
+ ["new o.m(x,y);", "5 new expression"],
187
+ // prefix/postfix
188
+ ["++x;", "1 pre/postfix"],
189
+ ["x++;", "2 pre/postfix"],
190
+ ["--x;", "3 pre/postfix"],
191
+ ["x--;", "4 pre/postfix"],
192
+ ["x ++;", "5 pre/postfix"],
193
+ ["x /* comment */ ++;", "6 pre/postfix"],
194
+ ["++ /* comment */ x;", "7 pre/postfix"],
195
+ // unary operators
196
+ ["delete x;", "1 unary operator"],
197
+ ["void x;", "2 unary operator"],
198
+ ["+ x;", "3 unary operator"],
199
+ ["-x;", "4 unary operator"],
200
+ ["~x;", "5 unary operator"],
201
+ ["!x;", "6 unary operator"],
202
+ // meh
203
+ ["new Date++;", "new date ++"],
204
+ ["+x++;", " + x ++"],
205
+ // expression expressions
206
+ ["1 * 2;", "1 expression expressions"],
207
+ ["1 / 2;", "2 expression expressions"],
208
+ ["1 % 2;", "3 expression expressions"],
209
+ ["1 + 2;", "4 expression expressions"],
210
+ ["1 - 2;", "5 expression expressions"],
211
+ ["1 << 2;", "6 expression expressions"],
212
+ ["1 >>> 2;", "7 expression expressions"],
213
+ ["1 >> 2;", "8 expression expressions"],
214
+ ["1 * 2 + 3;", "9 expression expressions"],
215
+ ["(1+2)*3;", "10 expression expressions"],
216
+ ["1*(2+3);", "11 expression expressions"],
217
+ ["x<y;", "12 expression expressions"],
218
+ ["x>y;", "13 expression expressions"],
219
+ ["x<=y;", "14 expression expressions"],
220
+ ["x>=y;", "15 expression expressions"],
221
+ ["x instanceof y;", "16 expression expressions"],
222
+ ["x in y;", "17 expression expressions"],
223
+ ["x&y;", "18 expression expressions"],
224
+ ["x^y;", "19 expression expressions"],
225
+ ["x|y;", "20 expression expressions"],
226
+ ["x+y<z;", "21 expression expressions"],
227
+ ["x<y+z;", "22 expression expressions"],
228
+ ["x+y+z;", "23 expression expressions"],
229
+ ["x+y<z;", "24 expression expressions"],
230
+ ["x<y+z;", "25 expression expressions"],
231
+ ["x&y|z;", "26 expression expressions"],
232
+ ["x&&y;", "27 expression expressions"],
233
+ ["x||y;", "28 expression expressions"],
234
+ ["x&&y||z;", "29 expression expressions"],
235
+ ["x||y&&z;", "30 expression expressions"],
236
+ ["x<y?z:w;", "31 expression expressions"],
237
+ // assignment
238
+ ["x >>>= y;", "1 assignment"],
239
+ ["x <<= y;", "2 assignment"],
240
+ ["x = y;", "3 assignment"],
241
+ ["x += y;", "4 assignment"],
242
+ ["x /= y;", "5 assignment"],
243
+ // comma
244
+ ["x, y;", "comma"],
245
+ // block
246
+ ["{};", "1 block"],
247
+ ["{x;};", "2 block"],
248
+ ["{x;y;};", "3 block"],
249
+ // vars
250
+ ["var x;", "1 var"],
251
+ ["var x,y;", "2 var"],
252
+ ["var x=1,y=2;", "3 var"],
253
+ ["var x,y=2;", "4 var"],
254
+ // empty
255
+ [";", "1 empty"],
256
+ ["\n;", "2 empty"],
257
+ // expression statement
258
+ ["x;", "1 expression statement"],
259
+ ["5;", "2 expression statement"],
260
+ ["1+2;", "3 expression statement"],
261
+ // if
262
+ ["if (c) x; else y;", "1 if statement"],
263
+ ["if (c) x;", "2 if statement"],
264
+ ["if (c) {} else {};", "3 if statement"],
265
+ ["if (c1) if (c2) s1; else s2;", "4 if statement"],
266
+ // while
267
+ ["do s; while (e);", "1 while statement"],
268
+ ["do { s; } while (e);", "2 while statement"],
269
+ ["while (e) s;", "3 while statement"],
270
+ ["while (e) { s; };", "4 while statement"],
271
+ // for
272
+ ["for (;;) ;", "1 for statement"],
273
+ ["for (;c;x++) x;", "2 for statement"],
274
+ ["for (i;i<len;++i){};", "3 for statement"],
275
+ ["for (var i=0;i<len;++i) {};", "4 for statement"],
276
+ ["for (var i=0,j=0;;){};", "5 for statement"],
277
+ //["for (x in b; c; u) {};", "6 for statement"],
278
+ ["for ((x in b); c; u) {};", "7 for statement"],
279
+ ["for (x in a);", "8 for statement"],
280
+ ["for (var x in a){};", "9 for statement"],
281
+ ["for (var x=5 in a) {};", "10 for statement"],
282
+ ["for (var x = a in b in c) {};", "11 for statement"],
283
+ ["for (var x=function(){a+b;}; a<b; ++i) some;", "11 for statement, testing for parsingForHeader reset with the function"],
284
+ ["for (var x=function(){for (x=0; x<15; ++x) alert(foo); }; a<b; ++i) some;", "11 for statement, testing for parsingForHeader reset with the function"],
285
+ // flow statements
286
+ ["while(1){ continue; }", "1 flow statement"],
287
+ ["label: while(1){ continue label; }", "2 flow statement"],
288
+ ["while(1){ break; }", "3 flow statement"],
289
+ ["somewhere: while(1){ break somewhere; }", "4 flow statement"],
290
+ ["while(1){ continue /* comment */ ; }", "5 flow statement"],
291
+ ["while(1){ continue \n; }", "6 flow statement"],
292
+ ["(function(){ return; })()", "7 flow statement"],
293
+ ["(function(){ return 0; })()", "8 flow statement"],
294
+ ["(function(){ return 0 + \n 1; })()", "9 flow statement"],
295
+ // with
296
+ ["with (e) s;", "with statement"],
297
+ // switch
298
+ ["switch (e) { case x: s; };", "1 switch statement"],
299
+ ["switch (e) { case x: s1;s2; default: s3; case y: s4; };", "2 switch statement"],
300
+ ["switch (e) { default: s1; case x: s2; case y: s3; };", "3 switch statement"],
301
+ ["switch (e) { default: s; };", "4 switch statement"],
302
+ ["switch (e) { case x: s1; case y: s2; };", "5 switch statement"],
303
+ // labels
304
+ ["foo : x;", " flow statement"],
305
+ // throw
306
+ ["throw x;", "1 throw statement"],
307
+ ["throw x\n;", "2 throw statement"],
308
+ // try catch finally
309
+ ["try { s1; } catch (e) { s2; };", "1 trycatchfinally statement"],
310
+ ["try { s1; } finally { s2; };", "2 trycatchfinally statement"],
311
+ ["try { s1; } catch (e) { s2; } finally { s3; };", "3 trycatchfinally statement"],
312
+ // debugger
313
+ ["debugger;", "debuger statement"],
314
+ // function decl
315
+ ["function f(x) { e; return x; };", "1 function declaration"],
316
+ ["function f() { x; y; };", "2 function declaration"],
317
+ ["function f(x,y) { var z; return x; };", "3 function declaration"],
318
+ // function exp
319
+ ["(function f(x) { return x; });", "1 function expression"],
320
+ ["(function empty() {;});", "2 function expression"],
321
+ ["(function empty() {;});", "3 function expression"],
322
+ ["(function (x) {; });", "4 function expression"],
323
+ // program
324
+ ["var x; function f(){;}; null;", "1 program"],
325
+ [";;", "2 program"],
326
+ ["{ x; y; z; }", "3 program"],
327
+ ["function f(){ function g(){;}};", "4 program"],
328
+ ["x;\n/*foo*/\n ;", "5 program"],
329
+
330
+ // asi
331
+ ["foo: while(1){ continue \n foo; }", "1 asi"],
332
+ ["foo: while(1){ break \n foo; }", "2 asi"],
333
+ ["(function(){ return\nfoo; })()", "3 asi"],
334
+ ["var x; { 1 \n 2 } 3", "4 asi"],
335
+ ["ab /* hi */\ncd", "5 asi"],
336
+ ["ab/*\n*/cd", "6 asi (multi line multilinecomment counts as eol)"],
337
+ ["foo: while(1){ continue /* wtf \n busta */ foo; }", "7 asi illegal with multi line comment"],
338
+ ["function f() { s }", "8 asi"],
339
+ ["function f() { return }", "9 asi"],
340
+
341
+ // use strict
342
+ // XXX: some of these should actually fail?
343
+ // no support for "use strict" yet...
344
+ ['"use strict"; \'bla\'\n; foo;', "1 directive"],
345
+ ['(function() { "use strict"; \'bla\';\n foo; });', "2 directive"],
346
+ ['"use\\n strict";', "3 directive"],
347
+ ['foo; "use strict";', "4 directive"],
348
+
349
+ // tests from http://es5conform.codeplex.com/
350
+
351
+ ['"use strict"; var o = { eval: 42};', "8.7.2-3-1-s: the use of eval as property name is allowed"],
352
+ ['({foo:0,foo:1});', 'Duplicate property name allowed in not strict mode'],
353
+ ['function foo(a,a){}', 'Duplicate parameter name allowed in not strict mode'],
354
+ ['(function foo(eval){})', 'Eval allowed as parameter name in non strict mode'],
355
+ ['(function foo(arguments){})', 'Arguments allowed as parameter name in non strict mode'],
356
+
357
+ // empty programs
358
+
359
+ ['', '1 Empty program'],
360
+ ['// test', '2 Empty program'],
361
+ ['//test\n', '3 Empty program'],
362
+ ['\n// test', '4 Empty program'],
363
+ ['\n// test\n', '5 Empty program'],
364
+ ['/* */', '6 Empty program'],
365
+ ['/*\ns,fd\n*/', '7 Empty program'],
366
+ ['/*\ns,fd\n*/\n', '8 Empty program'],
367
+ [' ', '9 Empty program'],
368
+ [' /*\nsmeh*/ \n ', '10 Empty program'],
369
+
370
+ // trailing whitespace
371
+
372
+ ['a ', '1 Trailing whitespace'],
373
+ ['a /* something */', '2 Trailing whitespace'],
374
+ ['a\n // hah', '3 Trailing whitespace'],
375
+ ['/abc/de//f', '4 Trailing whitespace'],
376
+ ['/abc/de/*f*/\n ', '5 Trailing whitespace'],
377
+
378
+ // things the parser tripped over at one point or the other (prevents regression bugs)
379
+ ['for (x;function(){ a\nb };z) x;', 'for header with function body forcing ASI'],
380
+ ['c=function(){return;return};', 'resetting noAsi after literal'],
381
+ ['d\nd()', 'asi exception causing token overflow'],
382
+ ['for(;;){x=function(){}}', 'function expression in a for header'],
383
+ ['for(var k;;){}', 'parser failing due to ASI accepting the incorrect "for" rule'],
384
+ ['({get foo(){ }})', 'getter with empty function body'],
385
+ ['\nreturnr', 'eol causes return statement to ignore local search requirement'],
386
+ [' / /', '1 whitespace before regex causes regex to fail?'],
387
+ ['/ // / /', '2 whitespace before regex causes regex to fail?'],
388
+ ['/ / / / /', '3 whitespace before regex causes regex to fail?'],
389
+
390
+ ['\n\t// Used for trimming whitespace\n\ttrimLeft = /^\\s+/;\n\ttrimRight = /\\s+$/;\t\n','turned out this didnt crash (the test below did), but whatever.'],
391
+ ['/[\\/]/;', 'escaped forward slash inside class group (would choke on fwd slash)'],
392
+ ['/[/]/;', 'also broke but is valid in es5 (not es3)'],
393
+ ['({get:5});','get property name thats not a getter'],
394
+ ['({set:5});','set property name thats not a setter'],
395
+ ['l !== "px" && (d.style(h, c, (k || 1) + l), j = (k || 1) / f.cur() * j, d.style(h, c, j + l)), i[1] && (k = (i[1] === "-=" ? -1 : 1) * k + j), f.custom(j, k, l)', 'this choked regex/div at some point'],
396
+ ['(/\'/g, \'\\\\\\\'\') + "\'";', 'the sequence of escaped characters confused the tokenizer']
397
+ ];
398
+
399
+ for (var i=0; i<inps.length; ++i) {
400
+ callback(i, inps[i][0], inps[i][1]);
401
+ };
402
+ };