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,14 @@
1
+ <html>
2
+ <head>
3
+ <script type="text/javascript" src="/browserify.js"></script>
4
+ <style type="text/css">
5
+ pre {
6
+ white-space: pre;
7
+ word-wrap: break-word;
8
+ }
9
+ </style>
10
+ </head>
11
+ <body>
12
+ <pre id="output"></pre>
13
+ </body>
14
+ </html>
@@ -0,0 +1,17 @@
1
+ var burrito = require('burrito');
2
+ var json = require('jsonify');
3
+
4
+ var src = [
5
+ 'function f () { g() }',
6
+ 'function g () { h() }',
7
+ 'function h () { throw "moo" + Array(x).join("!") }',
8
+ 'var x = 4',
9
+ 'f()'
10
+ ].join('\r\n');
11
+
12
+ window.onload = function () {
13
+ burrito(src, function (node) {
14
+ document.body.innerHTML += node.name + '<br>\n';
15
+ });
16
+ };
17
+ if (document.readyState === 'complete') window.onload();
@@ -0,0 +1,12 @@
1
+ var express = require('express');
2
+ var browserify = require('browserify');
3
+
4
+ var app = express.createServer();
5
+ app.use(express.static(__dirname));
6
+ app.use(browserify({
7
+ entry : __dirname + '/main.js',
8
+ watch : true,
9
+ }));
10
+
11
+ app.listen(8081);
12
+ console.log('Listening on :8081');
@@ -0,0 +1,7 @@
1
+ var burrito = require('burrito');
2
+
3
+ var src = burrito('f() && g(h())\nfoo()', function (node) {
4
+ if (node.name === 'call') node.wrap('qqq(%s)');
5
+ });
6
+
7
+ console.log(src);
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <script type="text/javascript" src="/browserify.js"></script>
4
+ </head>
5
+ <body>
6
+ <h2>results</h2>
7
+ </body>
8
+ </html>
@@ -0,0 +1,208 @@
1
+ var uglify = require('uglify-js');
2
+ var parser = uglify.parser;
3
+ var parse = function (expr) {
4
+ if (typeof expr !== 'string') throw 'expression should be a string';
5
+
6
+ try {
7
+ var ast = parser.parse.apply(null, arguments);
8
+ }
9
+ catch (err) {
10
+ if (err.message === undefined
11
+ || err.line === undefined
12
+ || err.col === undefined
13
+ || err.pos === undefined
14
+ ) { throw err }
15
+
16
+ var e = new SyntaxError(
17
+ err.message
18
+ + '\n at line ' + err.line + ':' + err.col + ' in expression:\n\n'
19
+ + ' ' + expr.split(/\r?\n/)[err.line]
20
+ );
21
+
22
+ e.original = err;
23
+ e.line = err.line;
24
+ e.col = err.col;
25
+ e.pos = err.pos;
26
+ throw e;
27
+ }
28
+ return ast;
29
+ };
30
+
31
+ var deparse = function (ast, b) {
32
+ return uglify.uglify.gen_code(ast, { beautify : b });
33
+ };
34
+
35
+ var traverse = require('traverse');
36
+ var vm = require('vm');
37
+
38
+ var burrito = module.exports = function (code, cb) {
39
+ var ast = Array_isArray(code)
40
+ ? code // already an ast
41
+ : parse(code.toString(), false, true)
42
+ ;
43
+
44
+ var ast_ = traverse(ast).map(function mapper () {
45
+ wrapNode(this, cb);
46
+ });
47
+
48
+ return deparse(parse(deparse(ast_)), true);
49
+ };
50
+
51
+ var wrapNode = burrito.wrapNode = function (state, cb) {
52
+ var node = state.node;
53
+
54
+ var ann = Array_isArray(node) && node[0]
55
+ && typeof node[0] === 'object' && node[0].name
56
+ ? node[0]
57
+ : null
58
+ ;
59
+
60
+ if (!ann) return undefined;
61
+
62
+ var self = {
63
+ name : ann.name,
64
+ node : node,
65
+ start : node[0].start,
66
+ end : node[0].end,
67
+ value : node.slice(1),
68
+ state : state
69
+ };
70
+
71
+ self.wrap = function (s) {
72
+ var subsrc = deparse(
73
+ traverse(node).map(function (x) {
74
+ if (!this.isRoot) wrapNode(this, cb)
75
+ })
76
+ );
77
+
78
+ if (self.name === 'binary') {
79
+ var a = deparse(traverse(node[2]).map(function (x) {
80
+ if (!this.isRoot) wrapNode(this, cb)
81
+ }));
82
+ var b = deparse(traverse(node[3]).map(function (x) {
83
+ if (!this.isRoot) wrapNode(this, cb)
84
+ }));
85
+ }
86
+
87
+ var src = '';
88
+
89
+ if (typeof s === 'function') {
90
+ if (self.name === 'binary') {
91
+ src = s(subsrc, a, b);
92
+ }
93
+ else {
94
+ src = s(subsrc);
95
+ }
96
+ }
97
+ else {
98
+ src = s.toString()
99
+ .replace(/%s/g, function () {
100
+ return subsrc
101
+ })
102
+ ;
103
+
104
+ if (self.name === 'binary') {
105
+ src = src
106
+ .replace(/%a/g, function () { return a })
107
+ .replace(/%b/g, function () { return b })
108
+ ;
109
+ }
110
+ }
111
+
112
+ var expr = parse(src);
113
+ state.update(expr, true);
114
+ };
115
+
116
+ var cache = {};
117
+
118
+ self.parent = state.isRoot ? null : function () {
119
+ if (!cache.parent) {
120
+ var s = state;
121
+ var x;
122
+ do {
123
+ s = s.parent;
124
+ if (s) x = wrapNode(s);
125
+ } while (s && !x);
126
+
127
+ cache.parent = x;
128
+ }
129
+
130
+ return cache.parent;
131
+ };
132
+
133
+ self.source = function () {
134
+ if (!cache.source) cache.source = deparse(node);
135
+ return cache.source;
136
+ };
137
+
138
+ self.label = function () {
139
+ return burrito.label(self);
140
+ };
141
+
142
+ if (cb) cb.call(state, self);
143
+
144
+ if (self.node[0].name === 'conditional') {
145
+ self.wrap('[%s][0]');
146
+ }
147
+
148
+ return self;
149
+ }
150
+
151
+ burrito.microwave = function (code, context, cb) {
152
+ if (!cb) { cb = context; context = {} };
153
+ if (!context) context = {};
154
+
155
+ var src = burrito(code, cb);
156
+ return vm.runInNewContext(src, context);
157
+ };
158
+
159
+ burrito.generateName = function (len) {
160
+ var name = '';
161
+ var lower = '$'.charCodeAt(0);
162
+ var upper = 'z'.charCodeAt(0);
163
+
164
+ while (name.length < len) {
165
+ var c = String.fromCharCode(Math.floor(
166
+ Math.random() * (upper - lower + 1) + lower
167
+ ));
168
+ if ((name + c).match(/^[A-Za-z_$][A-Za-z0-9_$]*$/)) name += c;
169
+ }
170
+
171
+ return name;
172
+ };
173
+
174
+ burrito.parse = parse;
175
+ burrito.deparse = deparse;
176
+
177
+ burrito.label = function (node) {
178
+ if (node.name === 'call') {
179
+ if (typeof node.value[0] === 'string') {
180
+ return node.value[0];
181
+ }
182
+ else if (node.value[0] && typeof node.value[0][1] === 'string') {
183
+ return node.value[0][1];
184
+ }
185
+ else if (node.value[0][0] === 'dot') {
186
+ return node.value[0][node.value[0].length - 1];
187
+ }
188
+ else {
189
+ return null;
190
+ }
191
+ }
192
+ else if (node.name === 'var') {
193
+ return node.value[0].map(function (x) { return x[0] });
194
+ }
195
+ else if (node.name === 'defun') {
196
+ return node.value[0];
197
+ }
198
+ else if (node.name === 'function') {
199
+ return node.value[0];
200
+ }
201
+ else {
202
+ return null;
203
+ }
204
+ };
205
+
206
+ var Array_isArray = Array.isArray || function isArray (xs) {
207
+ return Object.prototype.toString.call(xs) === '[object Array]';
208
+ };
@@ -0,0 +1,11 @@
1
+ var burrito = require('./');
2
+
3
+ window.onload = function () {
4
+ var res = burrito.microwave('Math.sin(2)', function (node) {
5
+ if (node.name === 'num') node.wrap('Math.PI / %s');
6
+ });
7
+
8
+ document.body.innerHTML += res;
9
+ };
10
+
11
+ if (document.readyState === 'complete') window.onload();
@@ -0,0 +1,317 @@
1
+ #! /usr/bin/env node
2
+ // -*- js -*-
3
+
4
+ global.sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util");
5
+ var fs = require("fs");
6
+ var uglify = require("uglify-js"), // symlink ~/.node_libraries/uglify-js.js to ../uglify-js.js
7
+ jsp = uglify.parser,
8
+ pro = uglify.uglify;
9
+
10
+ var options = {
11
+ ast: false,
12
+ mangle: true,
13
+ mangle_toplevel: false,
14
+ squeeze: true,
15
+ make_seqs: true,
16
+ dead_code: true,
17
+ verbose: false,
18
+ show_copyright: true,
19
+ out_same_file: false,
20
+ max_line_length: 32 * 1024,
21
+ unsafe: false,
22
+ reserved_names: null,
23
+ defines: { },
24
+ lift_vars: false,
25
+ codegen_options: {
26
+ ascii_only: false,
27
+ beautify: false,
28
+ indent_level: 4,
29
+ indent_start: 0,
30
+ quote_keys: false,
31
+ space_colon: false,
32
+ inline_script: false
33
+ },
34
+ make: false,
35
+ output: true // stdout
36
+ };
37
+
38
+ var args = jsp.slice(process.argv, 2);
39
+ var filename;
40
+
41
+ out: while (args.length > 0) {
42
+ var v = args.shift();
43
+ switch (v) {
44
+ case "-b":
45
+ case "--beautify":
46
+ options.codegen_options.beautify = true;
47
+ break;
48
+ case "-i":
49
+ case "--indent":
50
+ options.codegen_options.indent_level = args.shift();
51
+ break;
52
+ case "-q":
53
+ case "--quote-keys":
54
+ options.codegen_options.quote_keys = true;
55
+ break;
56
+ case "-mt":
57
+ case "--mangle-toplevel":
58
+ options.mangle_toplevel = true;
59
+ break;
60
+ case "--no-mangle":
61
+ case "-nm":
62
+ options.mangle = false;
63
+ break;
64
+ case "--no-squeeze":
65
+ case "-ns":
66
+ options.squeeze = false;
67
+ break;
68
+ case "--no-seqs":
69
+ options.make_seqs = false;
70
+ break;
71
+ case "--no-dead-code":
72
+ options.dead_code = false;
73
+ break;
74
+ case "--no-copyright":
75
+ case "-nc":
76
+ options.show_copyright = false;
77
+ break;
78
+ case "-o":
79
+ case "--output":
80
+ options.output = args.shift();
81
+ break;
82
+ case "--overwrite":
83
+ options.out_same_file = true;
84
+ break;
85
+ case "-v":
86
+ case "--verbose":
87
+ options.verbose = true;
88
+ break;
89
+ case "--ast":
90
+ options.ast = true;
91
+ break;
92
+ case "--unsafe":
93
+ options.unsafe = true;
94
+ break;
95
+ case "--max-line-len":
96
+ options.max_line_length = parseInt(args.shift(), 10);
97
+ break;
98
+ case "--reserved-names":
99
+ options.reserved_names = args.shift().split(",");
100
+ break;
101
+ case "--lift-vars":
102
+ options.lift_vars = true;
103
+ break;
104
+ case "-d":
105
+ case "--define":
106
+ var defarg = args.shift();
107
+ try {
108
+ var defsym = function(sym) {
109
+ // KEYWORDS_ATOM doesn't include NaN or Infinity - should we check
110
+ // for them too ?? We don't check reserved words and the like as the
111
+ // define values are only substituted AFTER parsing
112
+ if (jsp.KEYWORDS_ATOM.hasOwnProperty(sym)) {
113
+ throw "Don't define values for inbuilt constant '"+sym+"'";
114
+ }
115
+ return sym;
116
+ },
117
+ defval = function(v) {
118
+ if (v.match(/^"(.*)"$/) || v.match(/^'(.*)'$/)) {
119
+ return [ "string", RegExp.$1 ];
120
+ }
121
+ else if (!isNaN(parseFloat(v))) {
122
+ return [ "num", parseFloat(v) ];
123
+ }
124
+ else if (v.match(/^[a-z\$_][a-z\$_0-9]*$/i)) {
125
+ return [ "name", v ];
126
+ }
127
+ else if (!v.match(/"/)) {
128
+ return [ "string", v ];
129
+ }
130
+ else if (!v.match(/'/)) {
131
+ return [ "string", v ];
132
+ }
133
+ throw "Can't understand the specified value: "+v;
134
+ };
135
+ if (defarg.match(/^([a-z_\$][a-z_\$0-9]*)(=(.*))?$/i)) {
136
+ var sym = defsym(RegExp.$1),
137
+ val = RegExp.$2 ? defval(RegExp.$2.substr(1)) : [ 'name', 'true' ];
138
+ options.defines[sym] = val;
139
+ }
140
+ else {
141
+ throw "The --define option expects SYMBOL[=value]";
142
+ }
143
+ } catch(ex) {
144
+ sys.print("ERROR: In option --define "+defarg+"\n"+ex+"\n");
145
+ process.exit(1);
146
+ }
147
+ break;
148
+ case "--define-from-module":
149
+ var defmodarg = args.shift(),
150
+ defmodule = require(defmodarg),
151
+ sym,
152
+ val;
153
+ for (sym in defmodule) {
154
+ if (defmodule.hasOwnProperty(sym)) {
155
+ options.defines[sym] = function(val) {
156
+ if (typeof val == "string")
157
+ return [ "string", val ];
158
+ if (typeof val == "number")
159
+ return [ "num", val ];
160
+ if (val === true)
161
+ return [ 'name', 'true' ];
162
+ if (val === false)
163
+ return [ 'name', 'false' ];
164
+ if (val === null)
165
+ return [ 'name', 'null' ];
166
+ if (val === undefined)
167
+ return [ 'name', 'undefined' ];
168
+ sys.print("ERROR: In option --define-from-module "+defmodarg+"\n");
169
+ sys.print("ERROR: Unknown object type for: "+sym+"="+val+"\n");
170
+ process.exit(1);
171
+ return null;
172
+ }(defmodule[sym]);
173
+ }
174
+ }
175
+ break;
176
+ case "--ascii":
177
+ options.codegen_options.ascii_only = true;
178
+ break;
179
+ case "--make":
180
+ options.make = true;
181
+ break;
182
+ case "--inline-script":
183
+ options.codegen_options.inline_script = true;
184
+ break;
185
+ default:
186
+ filename = v;
187
+ break out;
188
+ }
189
+ }
190
+
191
+ if (options.verbose) {
192
+ pro.set_logger(function(msg){
193
+ sys.debug(msg);
194
+ });
195
+ }
196
+
197
+ jsp.set_logger(function(msg){
198
+ sys.debug(msg);
199
+ });
200
+
201
+ if (options.make) {
202
+ options.out_same_file = false; // doesn't make sense in this case
203
+ var makefile = JSON.parse(fs.readFileSync(filename || "Makefile.uglify.js").toString());
204
+ output(makefile.files.map(function(file){
205
+ var code = fs.readFileSync(file.name);
206
+ if (file.module) {
207
+ code = "!function(exports, global){global = this;\n" + code + "\n;this." + file.module + " = exports;}({})";
208
+ }
209
+ else if (file.hide) {
210
+ code = "(function(){" + code + "}());";
211
+ }
212
+ return squeeze_it(code);
213
+ }).join("\n"));
214
+ }
215
+ else if (filename) {
216
+ fs.readFile(filename, "utf8", function(err, text){
217
+ if (err) throw err;
218
+ output(squeeze_it(text));
219
+ });
220
+ }
221
+ else {
222
+ var stdin = process.openStdin();
223
+ stdin.setEncoding("utf8");
224
+ var text = "";
225
+ stdin.on("data", function(chunk){
226
+ text += chunk;
227
+ });
228
+ stdin.on("end", function() {
229
+ output(squeeze_it(text));
230
+ });
231
+ }
232
+
233
+ function output(text) {
234
+ var out;
235
+ if (options.out_same_file && filename)
236
+ options.output = filename;
237
+ if (options.output === true) {
238
+ out = process.stdout;
239
+ } else {
240
+ out = fs.createWriteStream(options.output, {
241
+ flags: "w",
242
+ encoding: "utf8",
243
+ mode: 0644
244
+ });
245
+ }
246
+ out.write(text);
247
+ if (options.output !== true) {
248
+ out.end();
249
+ }
250
+ };
251
+
252
+ // --------- main ends here.
253
+
254
+ function show_copyright(comments) {
255
+ var ret = "";
256
+ for (var i = 0; i < comments.length; ++i) {
257
+ var c = comments[i];
258
+ if (c.type == "comment1") {
259
+ ret += "//" + c.value + "\n";
260
+ } else {
261
+ ret += "/*" + c.value + "*/";
262
+ }
263
+ }
264
+ return ret;
265
+ };
266
+
267
+ function squeeze_it(code) {
268
+ var result = "";
269
+ if (options.show_copyright) {
270
+ var tok = jsp.tokenizer(code), c;
271
+ c = tok();
272
+ result += show_copyright(c.comments_before);
273
+ }
274
+ try {
275
+ var ast = time_it("parse", function(){ return jsp.parse(code); });
276
+ if (options.lift_vars) {
277
+ ast = time_it("lift", function(){ return pro.ast_lift_variables(ast); });
278
+ }
279
+ if (options.mangle) ast = time_it("mangle", function(){
280
+ return pro.ast_mangle(ast, {
281
+ toplevel: options.mangle_toplevel,
282
+ defines: options.defines,
283
+ except: options.reserved_names
284
+ });
285
+ });
286
+ if (options.squeeze) ast = time_it("squeeze", function(){
287
+ ast = pro.ast_squeeze(ast, {
288
+ make_seqs : options.make_seqs,
289
+ dead_code : options.dead_code,
290
+ keep_comps : !options.unsafe
291
+ });
292
+ if (options.unsafe)
293
+ ast = pro.ast_squeeze_more(ast);
294
+ return ast;
295
+ });
296
+ if (options.ast)
297
+ return sys.inspect(ast, null, null);
298
+ result += time_it("generate", function(){ return pro.gen_code(ast, options.codegen_options) });
299
+ if (!options.codegen_options.beautify && options.max_line_length) {
300
+ result = time_it("split", function(){ return pro.split_lines(result, options.max_line_length) });
301
+ }
302
+ return result;
303
+ } catch(ex) {
304
+ sys.debug(ex.stack);
305
+ sys.debug(sys.inspect(ex));
306
+ sys.debug(JSON.stringify(ex));
307
+ process.exit(1);
308
+ }
309
+ };
310
+
311
+ function time_it(name, cont) {
312
+ if (!options.verbose)
313
+ return cont();
314
+ var t1 = new Date().getTime();
315
+ try { return cont(); }
316
+ finally { sys.debug("// " + name + ": " + ((new Date().getTime() - t1) / 1000).toFixed(3) + " sec."); }
317
+ };