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
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in holmes.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # Holmes
2
+
3
+ Find JavaScript `require()` calls using [detective](https://github.com/substack/node-detective).
4
+
5
+ Requires Node to be available.
6
+
7
+ # Usage
8
+
9
+ require_calls = Holmes.find('/path/to/file.js')
10
+ require_calls #=> ['burrito', 'another']
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/holmes.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "holmes/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "holmes"
7
+ s.version = Holmes::VERSION
8
+ s.authors = ["Alex MacCaw"]
9
+ s.email = ["maccman@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Parse require calls out of JavaScript}
12
+ s.description = s.summary
13
+
14
+ s.rubyforge_project = "holmes"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "execjs", "~>1.3.0"
24
+ end
data/lib/holmes.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'holmes/version'
2
+ require 'execjs'
3
+
4
+ module Holmes extend self
5
+ def parse(data, options = {})
6
+ context.call('find', data, options)
7
+ end
8
+
9
+ def find(src, options = {})
10
+ data = File.read(src)
11
+ result = parse(data, options)
12
+ raise 'Dynamic require calls' if result['expressions'].any?
13
+ result['strings']
14
+ end
15
+
16
+ protected
17
+ def context
18
+ @context ||= backend.compile(script)
19
+ end
20
+
21
+ def script
22
+ File.read(File.expand_path('../holmes/require.js', __FILE__))
23
+ end
24
+
25
+ def backend
26
+ @backend ||= ExecJS::ExternalRuntime.new(
27
+ :name => 'Node.js (V8)',
28
+ :command => ['nodejs', 'node'],
29
+ :runner_path => File.expand_path('../holmes/runner.js', __FILE__)
30
+ )
31
+ end
32
+
33
+ def bundled_path
34
+ File.expand_path('../holmes/node_modules', __FILE__)
35
+ end
36
+
37
+ ENV['NODE_PATH'] = "#{File.expand_path('node_modules')}:#{bundled_path}:#{ENV['NODE_PATH']}"
38
+ end
@@ -0,0 +1,64 @@
1
+ detective
2
+ =========
3
+
4
+ Find all calls to require() no matter how crazily nested using a proper walk of
5
+ the AST.
6
+
7
+ example
8
+ =======
9
+
10
+ strings
11
+ -------
12
+
13
+ strings_src.js:
14
+
15
+ ````javascript
16
+ var a = require('a');
17
+ var b = require('b');
18
+ var c = require('c');
19
+ ````
20
+
21
+ strings.js:
22
+
23
+ ````javascript
24
+ var detective = require('detective');
25
+ var fs = require('fs');
26
+
27
+ var src = fs.readFileSync(__dirname + '/strings_src.js');
28
+ var requires = detective(src);
29
+ console.dir(requires);
30
+ ````
31
+
32
+ output:
33
+
34
+ $ node examples/strings.js
35
+ [ 'a', 'b', 'c' ]
36
+
37
+ methods
38
+ =======
39
+
40
+ var detective = require('detective');
41
+
42
+ detective(src, opts)
43
+ --------------------
44
+
45
+ Give some source body `src`, return an array of all the require()s with string
46
+ arguments.
47
+
48
+ The options parameter `opts` is passed along to `detective.find()`.
49
+
50
+ detective.find(src, opts)
51
+ -------------------------
52
+
53
+ Give some source body `src`, return an object with "strings" and "expressions"
54
+ arrays for each of the require() calls.
55
+
56
+ The "expressions" array will contain the stringified expressions.
57
+
58
+ Optionally you can specify a different function besides `"require"` to analyze
59
+ with `opts.word`.
60
+
61
+ installation
62
+ ============
63
+
64
+ npm install detective
@@ -0,0 +1,6 @@
1
+ var detective = require('detective');
2
+ var fs = require('fs');
3
+
4
+ var src = fs.readFileSync(__dirname + '/strings_src.js');
5
+ var requires = detective(src);
6
+ console.dir(requires);
@@ -0,0 +1,3 @@
1
+ var a = require('a');
2
+ var b = require('b');
3
+ var c = require('c');
@@ -0,0 +1,65 @@
1
+ var burrito = require('burrito');
2
+
3
+ var exports = module.exports = function (src, opts) {
4
+ return exports.find(src, opts).strings;
5
+ };
6
+
7
+ exports.find = function (src, opts) {
8
+ if (!opts) opts = {};
9
+ var word = opts.word === undefined ? 'require' : opts.word;
10
+
11
+ var modules = { strings : [], expressions : [] };
12
+
13
+ if (src.toString().indexOf(word) == -1) return modules;
14
+
15
+ burrito(src, function (node) {
16
+ var isRequire = node.name === 'call'
17
+ && node.value[0][0] === 'name'
18
+ && node.value[0][1] === word
19
+ ;
20
+ if (isRequire) {
21
+ var expr = node.value[1][0];
22
+
23
+ if (expr[0].name === 'string') {
24
+ modules.strings.push(expr[1]);
25
+ }
26
+ else {
27
+ modules.expressions.push(burrito.deparse(expr));
28
+ }
29
+ }
30
+
31
+ var isDotRequire = (node.name === 'dot' || node.name === 'call')
32
+ && node.value[0][0] === 'call'
33
+ && node.value[0][1][0] === 'name'
34
+ && node.value[0][1][1] === word
35
+ ;
36
+
37
+ if (isDotRequire) {
38
+ var expr = node.value[0][2][0];
39
+ if (expr[0].name === 'string') {
40
+ modules.strings.push(expr[1]);
41
+ }
42
+ else {
43
+ modules.expressions.push(burrito.deparse(expr));
44
+ }
45
+ }
46
+
47
+ var isDotCallRequire = node.name === 'call'
48
+ && node.value[0][0] === 'dot'
49
+ && node.value[0][1][0] === 'call'
50
+ && node.value[0][1][1][0] === 'name'
51
+ && node.value[0][1][1][1] === word
52
+ ;
53
+ if (isDotCallRequire) {
54
+ var expr = node.value[0][1][2][0];
55
+ if (expr[0].name === 'string') {
56
+ modules.strings.push(expr[1]);
57
+ }
58
+ else {
59
+ modules.expressions.push(burrito.deparse(expr));
60
+ }
61
+ }
62
+ });
63
+
64
+ return modules;
65
+ };
@@ -0,0 +1,185 @@
1
+ burrito
2
+ =======
3
+
4
+ Burrito makes it easy to do crazy stuff with the javascript AST.
5
+
6
+ This is super useful if you want to roll your own stack traces or build a code
7
+ coverage tool.
8
+
9
+ ![node.wrap("burrito")](http://substack.net/images/burrito.png)
10
+
11
+ examples
12
+ ========
13
+
14
+ microwave
15
+ ---------
16
+
17
+ examples/microwave.js
18
+
19
+ ````javascript
20
+ var burrito = require('burrito');
21
+
22
+ var res = burrito.microwave('Math.sin(2)', function (node) {
23
+ if (node.name === 'num') node.wrap('Math.PI / %s');
24
+ });
25
+
26
+ console.log(res); // sin(pi / 2) == 1
27
+ ````
28
+
29
+ output:
30
+
31
+ 1
32
+
33
+ wrap
34
+ ----
35
+
36
+ examples/wrap.js
37
+
38
+ ````javascript
39
+ var burrito = require('burrito');
40
+
41
+ var src = burrito('f() && g(h())\nfoo()', function (node) {
42
+ if (node.name === 'call') node.wrap('qqq(%s)');
43
+ });
44
+
45
+ console.log(src);
46
+ ````
47
+
48
+ output:
49
+
50
+ qqq(f()) && qqq(g(qqq(h())));
51
+
52
+ qqq(foo());
53
+
54
+ methods
55
+ =======
56
+
57
+ var burrito = require('burrito');
58
+
59
+ burrito(code, cb)
60
+ -----------------
61
+
62
+ Given some source `code` and a function `trace`, walk the ast by expression.
63
+
64
+ The `cb` gets called with a node object described below.
65
+
66
+ If `code` is an Array then it is assumbed to be an AST which you can generate
67
+ yourself with `burrito.parse()`. The AST must be annotated, so make sure to
68
+ `burrito.parse(src, false, true)`.
69
+
70
+ burrito.microwave(code, context={}, cb)
71
+ ---------------------------------------
72
+
73
+ Like `burrito()` except the result is run using
74
+ `vm.runInNewContext(res, context)`.
75
+
76
+ node object
77
+ ===========
78
+
79
+ node.name
80
+ ---------
81
+
82
+ Name is a string that contains the type of the expression as named by uglify.
83
+
84
+ node.wrap(s)
85
+ ------------
86
+
87
+ Wrap the current expression in `s`.
88
+
89
+ If `s` is a string, `"%s"` will be replaced with the stringified current
90
+ expression.
91
+
92
+ If `s` is a function, it is called with the stringified current expression and
93
+ should return a new stringified expression.
94
+
95
+ If the `node.name === "binary"`, you get the subterms "%a" and "%b" to play with
96
+ too. These subterms are applied if `s` is a function too: `s(expr, a, b)`.
97
+
98
+ Protip: to insert multiple statements you can use javascript's lesser-known block
99
+ syntax that it gets from C:
100
+
101
+ ````javascript
102
+ if (node.name === 'stat') node.wrap('{ foo(); %s }')
103
+ ````
104
+
105
+ node.node
106
+ ---------
107
+
108
+ raw ast data generated by uglify
109
+
110
+ node.value
111
+ ----------
112
+
113
+ `node.node.slice(1)` to skip the annotations
114
+
115
+ node.start
116
+ ----------
117
+
118
+ The start location of the expression, like this:
119
+
120
+ ````javascript
121
+ { type: 'name',
122
+ value: 'b',
123
+ line: 0,
124
+ col: 3,
125
+ pos: 3,
126
+ nlb: false,
127
+ comments_before: [] }
128
+ ````
129
+
130
+ node.end
131
+ --------
132
+
133
+ The end location of the expression, formatted the same as `node.start`.
134
+
135
+ node.state
136
+ ----------
137
+
138
+ The state of the traversal using traverse.
139
+
140
+ node.source()
141
+ -------------
142
+
143
+ Returns a stringified version of the expression.
144
+
145
+ node.parent()
146
+ -------------
147
+
148
+ Returns the parent `node` or `null` if the node is the root element.
149
+
150
+ node.label()
151
+ ------------
152
+
153
+ Return the label of the present node or `null` if there is no label.
154
+
155
+ Labels are returned for "call", "var", "defun", and "function" nodes.
156
+
157
+ Returns an array for "var" nodes since `var` statements can
158
+ contain multiple labels in assignment.
159
+
160
+ install
161
+ =======
162
+
163
+ With [npm](http://npmjs.org) you can just:
164
+
165
+ npm install burrito
166
+
167
+ in the browser
168
+ ==============
169
+
170
+ Burrito works in browser with
171
+ [browserify](https://github.com/substack/node-browserify).
172
+
173
+ It has been tested against:
174
+
175
+ * Internet Explorer 5.5, 6.0, 7.0, 8.0, 9.0
176
+ * Firefox 3.5
177
+ * Chrome 6.0
178
+ * Opera 10.6
179
+ * Safari 5.0
180
+
181
+ kudos
182
+ =====
183
+
184
+ Heavily inspired by (and previously mostly lifted outright from) isaacs's nifty
185
+ tmp/instrument.js thingy from uglify-js.
@@ -0,0 +1,4296 @@
1
+ var require = function (file, cwd) {
2
+ var resolved = require.resolve(file, cwd || '/');
3
+ var mod = require.modules[resolved];
4
+ if (!mod) throw new Error(
5
+ 'Failed to resolve module ' + file + ', tried ' + resolved
6
+ );
7
+ var res = mod._cached ? mod._cached : mod();
8
+ return res;
9
+ }
10
+ var __require = require;
11
+
12
+ require.paths = [];
13
+ require.modules = {};
14
+ require.extensions = [".js",".coffee"];
15
+
16
+ require.resolve = (function () {
17
+ var core = {
18
+ 'assert': true,
19
+ 'events': true,
20
+ 'fs': true,
21
+ 'path': true,
22
+ 'vm': true
23
+ };
24
+
25
+ return function (x, cwd) {
26
+ if (!cwd) cwd = '/';
27
+
28
+ if (core[x]) return x;
29
+ var path = require.modules.path();
30
+ var y = cwd || '.';
31
+
32
+ if (x.match(/^(?:\.\.?\/|\/)/)) {
33
+ var m = loadAsFileSync(path.resolve(y, x))
34
+ || loadAsDirectorySync(path.resolve(y, x));
35
+ if (m) return m;
36
+ }
37
+
38
+ var n = loadNodeModulesSync(x, y);
39
+ if (n) return n;
40
+
41
+ throw new Error("Cannot find module '" + x + "'");
42
+
43
+ function loadAsFileSync (x) {
44
+ if (require.modules[x]) {
45
+ return x;
46
+ }
47
+
48
+ for (var i = 0; i < require.extensions.length; i++) {
49
+ var ext = require.extensions[i];
50
+ if (require.modules[x + ext]) return x + ext;
51
+ }
52
+ }
53
+
54
+ function loadAsDirectorySync (x) {
55
+ x = x.replace(/\/+$/, '');
56
+ var pkgfile = x + '/package.json';
57
+ if (require.modules[pkgfile]) {
58
+ var pkg = require.modules[pkgfile]();
59
+ var b = pkg.browserify;
60
+ if (typeof b === 'object' && b.main) {
61
+ var m = loadAsFileSync(path.resolve(x, b.main));
62
+ if (m) return m;
63
+ }
64
+ else if (typeof b === 'string') {
65
+ var m = loadAsFileSync(path.resolve(x, b));
66
+ if (m) return m;
67
+ }
68
+ else if (pkg.main) {
69
+ var m = loadAsFileSync(path.resolve(x, pkg.main));
70
+ if (m) return m;
71
+ }
72
+ }
73
+
74
+ return loadAsFileSync(x + '/index');
75
+ }
76
+
77
+ function loadNodeModulesSync (x, start) {
78
+ var dirs = nodeModulesPathsSync(start);
79
+ for (var i = 0; i < dirs.length; i++) {
80
+ var dir = dirs[i];
81
+ var m = loadAsFileSync(dir + '/' + x);
82
+ if (m) return m;
83
+ var n = loadAsDirectorySync(dir + '/' + x);
84
+ if (n) return n;
85
+ }
86
+
87
+ var m = loadAsFileSync(x);
88
+ if (m) return m;
89
+ }
90
+
91
+ function nodeModulesPathsSync (start) {
92
+ var parts;
93
+ if (start === '/') parts = [ '' ];
94
+ else parts = path.normalize(start).split('/');
95
+
96
+ var dirs = [];
97
+ for (var i = parts.length - 1; i >= 0; i--) {
98
+ if (parts[i] === 'node_modules') continue;
99
+ var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
100
+ dirs.push(dir);
101
+ }
102
+
103
+ return dirs;
104
+ }
105
+ };
106
+ })();
107
+
108
+ require.alias = function (from, to) {
109
+ var path = require.modules.path();
110
+ var res = null;
111
+ try {
112
+ res = require.resolve(from + '/package.json', '/');
113
+ }
114
+ catch (err) {
115
+ res = require.resolve(from, '/');
116
+ }
117
+ var basedir = path.dirname(res);
118
+
119
+ var keys = Object_keys(require.modules);
120
+
121
+ for (var i = 0; i < keys.length; i++) {
122
+ var key = keys[i];
123
+ if (key.slice(0, basedir.length + 1) === basedir + '/') {
124
+ var f = key.slice(basedir.length);
125
+ require.modules[to + f] = require.modules[basedir + f];
126
+ }
127
+ else if (key === basedir) {
128
+ require.modules[to] = require.modules[basedir];
129
+ }
130
+ }
131
+ };
132
+
133
+ var Object_keys = Object.keys || function (obj) {
134
+ var res = [];
135
+ for (var key in obj) res.push(key)
136
+ return res;
137
+ };
138
+
139
+ if (typeof process === 'undefined') process = {};
140
+
141
+ if (!process.nextTick) process.nextTick = function (fn) {
142
+ setTimeout(fn, 0);
143
+ };
144
+
145
+ if (!process.title) process.title = 'browser';
146
+
147
+ if (!process.binding) process.binding = function (name) {
148
+ if (name === 'evals') return require('vm')
149
+ else throw new Error('No such module')
150
+ };
151
+
152
+ if (!process.cwd) process.cwd = function () { return '.' };
153
+
154
+ require.modules["path"] = function () {
155
+ var module = { exports : {} };
156
+ var exports = module.exports;
157
+ var __dirname = ".";
158
+ var __filename = "path";
159
+
160
+ var require = function (file) {
161
+ return __require(file, ".");
162
+ };
163
+
164
+ require.resolve = function (file) {
165
+ return __require.resolve(name, ".");
166
+ };
167
+
168
+ require.modules = __require.modules;
169
+ __require.modules["path"]._cached = module.exports;
170
+
171
+ (function () {
172
+ function filter (xs, fn) {
173
+ var res = [];
174
+ for (var i = 0; i < xs.length; i++) {
175
+ if (fn(xs[i], i, xs)) res.push(xs[i]);
176
+ }
177
+ return res;
178
+ }
179
+
180
+ // resolves . and .. elements in a path array with directory names there
181
+ // must be no slashes, empty elements, or device names (c:\) in the array
182
+ // (so also no leading and trailing slashes - it does not distinguish
183
+ // relative and absolute paths)
184
+ function normalizeArray(parts, allowAboveRoot) {
185
+ // if the path tries to go above the root, `up` ends up > 0
186
+ var up = 0;
187
+ for (var i = parts.length; i >= 0; i--) {
188
+ var last = parts[i];
189
+ if (last == '.') {
190
+ parts.splice(i, 1);
191
+ } else if (last === '..') {
192
+ parts.splice(i, 1);
193
+ up++;
194
+ } else if (up) {
195
+ parts.splice(i, 1);
196
+ up--;
197
+ }
198
+ }
199
+
200
+ // if the path is allowed to go above the root, restore leading ..s
201
+ if (allowAboveRoot) {
202
+ for (; up--; up) {
203
+ parts.unshift('..');
204
+ }
205
+ }
206
+
207
+ return parts;
208
+ }
209
+
210
+ // Regex to split a filename into [*, dir, basename, ext]
211
+ // posix version
212
+ var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
213
+
214
+ // path.resolve([from ...], to)
215
+ // posix version
216
+ exports.resolve = function() {
217
+ var resolvedPath = '',
218
+ resolvedAbsolute = false;
219
+
220
+ for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
221
+ var path = (i >= 0)
222
+ ? arguments[i]
223
+ : process.cwd();
224
+
225
+ // Skip empty and invalid entries
226
+ if (typeof path !== 'string' || !path) {
227
+ continue;
228
+ }
229
+
230
+ resolvedPath = path + '/' + resolvedPath;
231
+ resolvedAbsolute = path.charAt(0) === '/';
232
+ }
233
+
234
+ // At this point the path should be resolved to a full absolute path, but
235
+ // handle relative paths to be safe (might happen when process.cwd() fails)
236
+
237
+ // Normalize the path
238
+ resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
239
+ return !!p;
240
+ }), !resolvedAbsolute).join('/');
241
+
242
+ return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
243
+ };
244
+
245
+ // path.normalize(path)
246
+ // posix version
247
+ exports.normalize = function(path) {
248
+ var isAbsolute = path.charAt(0) === '/',
249
+ trailingSlash = path.slice(-1) === '/';
250
+
251
+ // Normalize the path
252
+ path = normalizeArray(filter(path.split('/'), function(p) {
253
+ return !!p;
254
+ }), !isAbsolute).join('/');
255
+
256
+ if (!path && !isAbsolute) {
257
+ path = '.';
258
+ }
259
+ if (path && trailingSlash) {
260
+ path += '/';
261
+ }
262
+
263
+ return (isAbsolute ? '/' : '') + path;
264
+ };
265
+
266
+
267
+ // posix version
268
+ exports.join = function() {
269
+ var paths = Array.prototype.slice.call(arguments, 0);
270
+ return exports.normalize(filter(paths, function(p, index) {
271
+ return p && typeof p === 'string';
272
+ }).join('/'));
273
+ };
274
+
275
+
276
+ exports.dirname = function(path) {
277
+ var dir = splitPathRe.exec(path)[1] || '';
278
+ var isWindows = false;
279
+ if (!dir) {
280
+ // No dirname
281
+ return '.';
282
+ } else if (dir.length === 1 ||
283
+ (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {
284
+ // It is just a slash or a drive letter with a slash
285
+ return dir;
286
+ } else {
287
+ // It is a full dirname, strip trailing slash
288
+ return dir.substring(0, dir.length - 1);
289
+ }
290
+ };
291
+
292
+
293
+ exports.basename = function(path, ext) {
294
+ var f = splitPathRe.exec(path)[2] || '';
295
+ // TODO: make this comparison case-insensitive on windows?
296
+ if (ext && f.substr(-1 * ext.length) === ext) {
297
+ f = f.substr(0, f.length - ext.length);
298
+ }
299
+ return f;
300
+ };
301
+
302
+
303
+ exports.extname = function(path) {
304
+ return splitPathRe.exec(path)[3] || '';
305
+ };
306
+ ;
307
+ }).call(module.exports);
308
+
309
+ __require.modules["path"]._cached = module.exports;
310
+ return module.exports;
311
+ };
312
+
313
+ require.modules["/package.json"] = function () {
314
+ var module = { exports : {} };
315
+ var exports = module.exports;
316
+ var __dirname = "/";
317
+ var __filename = "/package.json";
318
+
319
+ var require = function (file) {
320
+ return __require(file, "/");
321
+ };
322
+
323
+ require.resolve = function (file) {
324
+ return __require.resolve(name, "/");
325
+ };
326
+
327
+ require.modules = __require.modules;
328
+ __require.modules["/package.json"]._cached = module.exports;
329
+
330
+ (function () {
331
+ module.exports = {"name":"burrito","description":"Wrap up expressions with a trace function while walking the AST with rice and beans on the side","version":"0.2.7","repository":{"type":"git","url":"git://github.com/substack/node-burrito.git"},"main":"./index.js","keywords":["trace","ast","walk","syntax","source","tree","uglify"],"directories":{"lib":".","example":"example","test":"test"},"scripts":{"test":"expresso"},"dependencies":{"traverse":"0.5.x","uglify-js":"1.0.4"},"devDependencies":{"expresso":"=0.7.x"},"engines":{"node":">=0.4.0"},"license":"BSD","author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"}};
332
+ }).call(module.exports);
333
+
334
+ __require.modules["/package.json"]._cached = module.exports;
335
+ return module.exports;
336
+ };
337
+
338
+ require.modules["/index.js"] = function () {
339
+ var module = { exports : {} };
340
+ var exports = module.exports;
341
+ var __dirname = "/";
342
+ var __filename = "/index.js";
343
+
344
+ var require = function (file) {
345
+ return __require(file, "/");
346
+ };
347
+
348
+ require.resolve = function (file) {
349
+ return __require.resolve(name, "/");
350
+ };
351
+
352
+ require.modules = __require.modules;
353
+ __require.modules["/index.js"]._cached = module.exports;
354
+
355
+ (function () {
356
+ var uglify = require('uglify-js');
357
+ var parser = uglify.parser;
358
+ var parse = function (expr) {
359
+ if (typeof expr !== 'string') throw 'expression should be a string';
360
+
361
+ try {
362
+ var ast = parser.parse.apply(null, arguments);
363
+ }
364
+ catch (err) {
365
+ if (err.message === undefined
366
+ || err.line === undefined
367
+ || err.col === undefined
368
+ || err.pos === undefined
369
+ ) { throw err }
370
+
371
+ var e = new SyntaxError(
372
+ err.message
373
+ + '\n at line ' + err.line + ':' + err.col + ' in expression:\n\n'
374
+ + ' ' + expr.split(/\r?\n/)[err.line]
375
+ );
376
+
377
+ e.original = err;
378
+ e.line = err.line;
379
+ e.col = err.col;
380
+ e.pos = err.pos;
381
+ throw e;
382
+ }
383
+ return ast;
384
+ };
385
+
386
+ var deparse = function (ast, b) {
387
+ return uglify.uglify.gen_code(ast, { beautify : b });
388
+ };
389
+
390
+ var traverse = require('traverse');
391
+ var vm = require('vm');
392
+
393
+ var burrito = module.exports = function (code, cb) {
394
+ var ast = Array_isArray(code)
395
+ ? code // already an ast
396
+ : parse(code.toString(), false, true)
397
+ ;
398
+
399
+ var ast_ = traverse(ast).map(function mapper () {
400
+ wrapNode(this, cb);
401
+ });
402
+
403
+ return deparse(parse(deparse(ast_)), true);
404
+ };
405
+
406
+ var wrapNode = burrito.wrapNode = function (state, cb) {
407
+ var node = state.node;
408
+
409
+ var ann = Array_isArray(node) && node[0]
410
+ && typeof node[0] === 'object' && node[0].name
411
+ ? node[0]
412
+ : null
413
+ ;
414
+
415
+ if (!ann) return undefined;
416
+
417
+ var self = {
418
+ name : ann.name,
419
+ node : node,
420
+ start : node[0].start,
421
+ end : node[0].end,
422
+ value : node.slice(1),
423
+ state : state
424
+ };
425
+
426
+ self.wrap = function (s) {
427
+ var subsrc = deparse(
428
+ traverse(node).map(function (x) {
429
+ if (!this.isRoot) wrapNode(this, cb)
430
+ })
431
+ );
432
+
433
+ if (self.name === 'binary') {
434
+ var a = deparse(traverse(node[2]).map(function (x) {
435
+ if (!this.isRoot) wrapNode(this, cb)
436
+ }));
437
+ var b = deparse(traverse(node[3]).map(function (x) {
438
+ if (!this.isRoot) wrapNode(this, cb)
439
+ }));
440
+ }
441
+
442
+ var src = '';
443
+
444
+ if (typeof s === 'function') {
445
+ if (self.name === 'binary') {
446
+ src = s(subsrc, a, b);
447
+ }
448
+ else {
449
+ src = s(subsrc);
450
+ }
451
+ }
452
+ else {
453
+ src = s.toString()
454
+ .replace(/undefined/g, function () {
455
+ return subsrc
456
+ })
457
+ ;
458
+
459
+ if (self.name === 'binary') {
460
+ src = src
461
+ .replace(/%a/g, function () { return a })
462
+ .replace(/%b/g, function () { return b })
463
+ ;
464
+ }
465
+ }
466
+
467
+ var expr = parse(src);
468
+ state.update(expr, true);
469
+ };
470
+
471
+ var cache = {};
472
+
473
+ self.parent = state.isRoot ? null : function () {
474
+ if (!cache.parent) {
475
+ var s = state;
476
+ var x;
477
+ do {
478
+ s = s.parent;
479
+ if (s) x = wrapNode(s);
480
+ } while (s && !x);
481
+
482
+ cache.parent = x;
483
+ }
484
+
485
+ return cache.parent;
486
+ };
487
+
488
+ self.source = function () {
489
+ if (!cache.source) cache.source = deparse(node);
490
+ return cache.source;
491
+ };
492
+
493
+ self.label = function () {
494
+ return burrito.label(self);
495
+ };
496
+
497
+ if (cb) cb.call(state, self);
498
+
499
+ if (self.node[0].name === 'conditional') {
500
+ self.wrap('[undefined][0]');
501
+ }
502
+
503
+ return self;
504
+ }
505
+
506
+ burrito.microwave = function (code, context, cb) {
507
+ if (!cb) { cb = context; context = {} };
508
+ if (!context) context = {};
509
+
510
+ var src = burrito(code, cb);
511
+ return vm.runInNewContext(src, context);
512
+ };
513
+
514
+ burrito.generateName = function (len) {
515
+ var name = '';
516
+ var lower = '$'.charCodeAt(0);
517
+ var upper = 'z'.charCodeAt(0);
518
+
519
+ while (name.length < len) {
520
+ var c = String.fromCharCode(Math.floor(
521
+ Math.random() * (upper - lower + 1) + lower
522
+ ));
523
+ if ((name + c).match(/^[A-Za-z_$][A-Za-z0-9_$]*$/)) name += c;
524
+ }
525
+
526
+ return name;
527
+ };
528
+
529
+ burrito.parse = parse;
530
+ burrito.deparse = deparse;
531
+
532
+ burrito.label = function (node) {
533
+ if (node.name === 'call') {
534
+ if (typeof node.value[0] === 'string') {
535
+ return node.value[0];
536
+ }
537
+ else if (node.value[0] && typeof node.value[0][1] === 'string') {
538
+ return node.value[0][1];
539
+ }
540
+ else {
541
+ return null;
542
+ }
543
+ }
544
+ else if (node.name === 'var') {
545
+ return node.value[0].map(function (x) { return x[0] });
546
+ }
547
+ else if (node.name === 'defun') {
548
+ return node.value[0];
549
+ }
550
+ else if (node.name === 'function') {
551
+ return node.value[0];
552
+ }
553
+ else {
554
+ return null;
555
+ }
556
+ };
557
+
558
+ var Array_isArray = Array.isArray || function isArray (xs) {
559
+ return Object.prototype.toString.call(xs) === '[object Array]';
560
+ };
561
+ ;
562
+ }).call(module.exports);
563
+
564
+ __require.modules["/index.js"]._cached = module.exports;
565
+ return module.exports;
566
+ };
567
+
568
+ require.modules["/node_modules/uglify-js/package.json"] = function () {
569
+ var module = { exports : {} };
570
+ var exports = module.exports;
571
+ var __dirname = "/node_modules/uglify-js";
572
+ var __filename = "/node_modules/uglify-js/package.json";
573
+
574
+ var require = function (file) {
575
+ return __require(file, "/node_modules/uglify-js");
576
+ };
577
+
578
+ require.resolve = function (file) {
579
+ return __require.resolve(name, "/node_modules/uglify-js");
580
+ };
581
+
582
+ require.modules = __require.modules;
583
+ __require.modules["/node_modules/uglify-js/package.json"]._cached = module.exports;
584
+
585
+ (function () {
586
+ module.exports = {"name":"uglify-js","author":{"name":"Mihai Bazon","email":"mihai.bazon@gmail.com","url":"http://mihai.bazon.net/blog"},"version":"1.0.4","main":"./uglify-js.js","bin":{"uglifyjs":"./bin/uglifyjs"},"repository":{"type":"git","url":"git@github.com:mishoo/UglifyJS.git"}};
587
+ }).call(module.exports);
588
+
589
+ __require.modules["/node_modules/uglify-js/package.json"]._cached = module.exports;
590
+ return module.exports;
591
+ };
592
+
593
+ require.modules["/node_modules/uglify-js/uglify-js.js"] = function () {
594
+ var module = { exports : {} };
595
+ var exports = module.exports;
596
+ var __dirname = "/node_modules/uglify-js";
597
+ var __filename = "/node_modules/uglify-js/uglify-js.js";
598
+
599
+ var require = function (file) {
600
+ return __require(file, "/node_modules/uglify-js");
601
+ };
602
+
603
+ require.resolve = function (file) {
604
+ return __require.resolve(name, "/node_modules/uglify-js");
605
+ };
606
+
607
+ require.modules = __require.modules;
608
+ __require.modules["/node_modules/uglify-js/uglify-js.js"]._cached = module.exports;
609
+
610
+ (function () {
611
+ //convienence function(src, [options]);
612
+ function uglify(orig_code, options){
613
+ options || (options = {});
614
+ var jsp = uglify.parser;
615
+ var pro = uglify.uglify;
616
+
617
+ var ast = jsp.parse(orig_code, options.strict_semicolons); // parse code and get the initial AST
618
+ ast = pro.ast_mangle(ast, options.mangle_options); // get a new AST with mangled names
619
+ ast = pro.ast_squeeze(ast, options.squeeze_options); // get an AST with compression optimizations
620
+ var final_code = pro.gen_code(ast, options.gen_options); // compressed code here
621
+ return final_code;
622
+ };
623
+
624
+ uglify.parser = require("./lib/parse-js");
625
+ uglify.uglify = require("./lib/process");
626
+
627
+ module.exports = uglify;
628
+ }).call(module.exports);
629
+
630
+ __require.modules["/node_modules/uglify-js/uglify-js.js"]._cached = module.exports;
631
+ return module.exports;
632
+ };
633
+
634
+ require.modules["/node_modules/uglify-js/lib/parse-js.js"] = function () {
635
+ var module = { exports : {} };
636
+ var exports = module.exports;
637
+ var __dirname = "/node_modules/uglify-js/lib";
638
+ var __filename = "/node_modules/uglify-js/lib/parse-js.js";
639
+
640
+ var require = function (file) {
641
+ return __require(file, "/node_modules/uglify-js/lib");
642
+ };
643
+
644
+ require.resolve = function (file) {
645
+ return __require.resolve(name, "/node_modules/uglify-js/lib");
646
+ };
647
+
648
+ require.modules = __require.modules;
649
+ __require.modules["/node_modules/uglify-js/lib/parse-js.js"]._cached = module.exports;
650
+
651
+ (function () {
652
+ /***********************************************************************
653
+
654
+ A JavaScript tokenizer / parser / beautifier / compressor.
655
+
656
+ This version is suitable for Node.js. With minimal changes (the
657
+ exports stuff) it should work on any JS platform.
658
+
659
+ This file contains the tokenizer/parser. It is a port to JavaScript
660
+ of parse-js [1], a JavaScript parser library written in Common Lisp
661
+ by Marijn Haverbeke. Thank you Marijn!
662
+
663
+ [1] http://marijn.haverbeke.nl/parse-js/
664
+
665
+ Exported functions:
666
+
667
+ - tokenizer(code) -- returns a function. Call the returned
668
+ function to fetch the next token.
669
+
670
+ - parse(code) -- returns an AST of the given JavaScript code.
671
+
672
+ -------------------------------- (C) ---------------------------------
673
+
674
+ Author: Mihai Bazon
675
+ <mihai.bazon@gmail.com>
676
+ http://mihai.bazon.net/blog
677
+
678
+ Distributed under the BSD license:
679
+
680
+ Copyright 2010 (c) Mihai Bazon <mihai.bazon@gmail.com>
681
+ Based on parse-js (http://marijn.haverbeke.nl/parse-js/).
682
+
683
+ Redistribution and use in source and binary forms, with or without
684
+ modification, are permitted provided that the following conditions
685
+ are met:
686
+
687
+ * Redistributions of source code must retain the above
688
+ copyright notice, this list of conditions and the following
689
+ disclaimer.
690
+
691
+ * Redistributions in binary form must reproduce the above
692
+ copyright notice, this list of conditions and the following
693
+ disclaimer in the documentation and/or other materials
694
+ provided with the distribution.
695
+
696
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
697
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
698
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
699
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
700
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
701
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
702
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
703
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
704
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
705
+ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
706
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
707
+ SUCH DAMAGE.
708
+
709
+ ***********************************************************************/
710
+
711
+ /* -----[ Tokenizer (constants) ]----- */
712
+
713
+ var KEYWORDS = array_to_hash([
714
+ "break",
715
+ "case",
716
+ "catch",
717
+ "const",
718
+ "continue",
719
+ "default",
720
+ "delete",
721
+ "do",
722
+ "else",
723
+ "finally",
724
+ "for",
725
+ "function",
726
+ "if",
727
+ "in",
728
+ "instanceof",
729
+ "new",
730
+ "return",
731
+ "switch",
732
+ "throw",
733
+ "try",
734
+ "typeof",
735
+ "var",
736
+ "void",
737
+ "while",
738
+ "with"
739
+ ]);
740
+
741
+ var RESERVED_WORDS = array_to_hash([
742
+ "abstract",
743
+ "boolean",
744
+ "byte",
745
+ "char",
746
+ "class",
747
+ "debugger",
748
+ "double",
749
+ "enum",
750
+ "export",
751
+ "extends",
752
+ "final",
753
+ "float",
754
+ "goto",
755
+ "implements",
756
+ "import",
757
+ "int",
758
+ "interface",
759
+ "long",
760
+ "native",
761
+ "package",
762
+ "private",
763
+ "protected",
764
+ "public",
765
+ "short",
766
+ "static",
767
+ "super",
768
+ "synchronized",
769
+ "throws",
770
+ "transient",
771
+ "volatile"
772
+ ]);
773
+
774
+ var KEYWORDS_BEFORE_EXPRESSION = array_to_hash([
775
+ "return",
776
+ "new",
777
+ "delete",
778
+ "throw",
779
+ "else",
780
+ "case"
781
+ ]);
782
+
783
+ var KEYWORDS_ATOM = array_to_hash([
784
+ "false",
785
+ "null",
786
+ "true",
787
+ "undefined"
788
+ ]);
789
+
790
+ var OPERATOR_CHARS = array_to_hash(characters("+-*&%=<>!?|~^"));
791
+
792
+ var RE_HEX_NUMBER = /^0x[0-9a-f]+$/i;
793
+ var RE_OCT_NUMBER = /^0[0-7]+$/;
794
+ var RE_DEC_NUMBER = /^\d*\.?\d*(?:e[+-]?\d*(?:\d\.?|\.?\d)\d*)?$/i;
795
+
796
+ var OPERATORS = array_to_hash([
797
+ "in",
798
+ "instanceof",
799
+ "typeof",
800
+ "new",
801
+ "void",
802
+ "delete",
803
+ "++",
804
+ "--",
805
+ "+",
806
+ "-",
807
+ "!",
808
+ "~",
809
+ "&",
810
+ "|",
811
+ "^",
812
+ "*",
813
+ "/",
814
+ "%",
815
+ ">>",
816
+ "<<",
817
+ ">>>",
818
+ "<",
819
+ ">",
820
+ "<=",
821
+ ">=",
822
+ "==",
823
+ "===",
824
+ "!=",
825
+ "!==",
826
+ "?",
827
+ "=",
828
+ "+=",
829
+ "-=",
830
+ "/=",
831
+ "*=",
832
+ "%=",
833
+ ">>=",
834
+ "<<=",
835
+ ">>>=",
836
+ "|=",
837
+ "^=",
838
+ "&=",
839
+ "&&",
840
+ "||"
841
+ ]);
842
+
843
+ var WHITESPACE_CHARS = array_to_hash(characters(" \u00a0\n\r\t\f\v\u200b"));
844
+
845
+ var PUNC_BEFORE_EXPRESSION = array_to_hash(characters("[{}(,.;:"));
846
+
847
+ var PUNC_CHARS = array_to_hash(characters("[]{}(),;:"));
848
+
849
+ var REGEXP_MODIFIERS = array_to_hash(characters("gmsiy"));
850
+
851
+ /* -----[ Tokenizer ]----- */
852
+
853
+ // regexps adapted from http://xregexp.com/plugins/#unicode
854
+ var UNICODE = {
855
+ letter: new RegExp("[\\u0041-\\u005A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u0523\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0621-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971\\u0972\\u097B-\\u097F\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D28\\u0D2A-\\u0D39\\u0D3D\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E46\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC\\u0EDD\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8B\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10D0-\\u10FA\\u10FC\\u1100-\\u1159\\u115F-\\u11A2\\u11A8-\\u11F9\\u1200-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u1676\\u1681-\\u169A\\u16A0-\\u16EA\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1877\\u1880-\\u18A8\\u18AA\\u1900-\\u191C\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19A9\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u2094\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2183\\u2184\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2C6F\\u2C71-\\u2C7D\\u2C80-\\u2CE4\\u2D00-\\u2D25\\u2D30-\\u2D65\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005\\u3006\\u3031-\\u3035\\u303B\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31B7\\u31F0-\\u31FF\\u3400\\u4DB5\\u4E00\\u9FC3\\uA000-\\uA48C\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA65F\\uA662-\\uA66E\\uA67F-\\uA697\\uA717-\\uA71F\\uA722-\\uA788\\uA78B\\uA78C\\uA7FB-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA90A-\\uA925\\uA930-\\uA946\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAC00\\uD7A3\\uF900-\\uFA2D\\uFA30-\\uFA6A\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]"),
856
+ non_spacing_mark: new RegExp("[\\u0300-\\u036F\\u0483-\\u0487\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u0610-\\u061A\\u064B-\\u065E\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED\\u0711\\u0730-\\u074A\\u07A6-\\u07B0\\u07EB-\\u07F3\\u0816-\\u0819\\u081B-\\u0823\\u0825-\\u0827\\u0829-\\u082D\\u0900-\\u0902\\u093C\\u0941-\\u0948\\u094D\\u0951-\\u0955\\u0962\\u0963\\u0981\\u09BC\\u09C1-\\u09C4\\u09CD\\u09E2\\u09E3\\u0A01\\u0A02\\u0A3C\\u0A41\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A70\\u0A71\\u0A75\\u0A81\\u0A82\\u0ABC\\u0AC1-\\u0AC5\\u0AC7\\u0AC8\\u0ACD\\u0AE2\\u0AE3\\u0B01\\u0B3C\\u0B3F\\u0B41-\\u0B44\\u0B4D\\u0B56\\u0B62\\u0B63\\u0B82\\u0BC0\\u0BCD\\u0C3E-\\u0C40\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C62\\u0C63\\u0CBC\\u0CBF\\u0CC6\\u0CCC\\u0CCD\\u0CE2\\u0CE3\\u0D41-\\u0D44\\u0D4D\\u0D62\\u0D63\\u0DCA\\u0DD2-\\u0DD4\\u0DD6\\u0E31\\u0E34-\\u0E3A\\u0E47-\\u0E4E\\u0EB1\\u0EB4-\\u0EB9\\u0EBB\\u0EBC\\u0EC8-\\u0ECD\\u0F18\\u0F19\\u0F35\\u0F37\\u0F39\\u0F71-\\u0F7E\\u0F80-\\u0F84\\u0F86\\u0F87\\u0F90-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u102D-\\u1030\\u1032-\\u1037\\u1039\\u103A\\u103D\\u103E\\u1058\\u1059\\u105E-\\u1060\\u1071-\\u1074\\u1082\\u1085\\u1086\\u108D\\u109D\\u135F\\u1712-\\u1714\\u1732-\\u1734\\u1752\\u1753\\u1772\\u1773\\u17B7-\\u17BD\\u17C6\\u17C9-\\u17D3\\u17DD\\u180B-\\u180D\\u18A9\\u1920-\\u1922\\u1927\\u1928\\u1932\\u1939-\\u193B\\u1A17\\u1A18\\u1A56\\u1A58-\\u1A5E\\u1A60\\u1A62\\u1A65-\\u1A6C\\u1A73-\\u1A7C\\u1A7F\\u1B00-\\u1B03\\u1B34\\u1B36-\\u1B3A\\u1B3C\\u1B42\\u1B6B-\\u1B73\\u1B80\\u1B81\\u1BA2-\\u1BA5\\u1BA8\\u1BA9\\u1C2C-\\u1C33\\u1C36\\u1C37\\u1CD0-\\u1CD2\\u1CD4-\\u1CE0\\u1CE2-\\u1CE8\\u1CED\\u1DC0-\\u1DE6\\u1DFD-\\u1DFF\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2CEF-\\u2CF1\\u2DE0-\\u2DFF\\u302A-\\u302F\\u3099\\u309A\\uA66F\\uA67C\\uA67D\\uA6F0\\uA6F1\\uA802\\uA806\\uA80B\\uA825\\uA826\\uA8C4\\uA8E0-\\uA8F1\\uA926-\\uA92D\\uA947-\\uA951\\uA980-\\uA982\\uA9B3\\uA9B6-\\uA9B9\\uA9BC\\uAA29-\\uAA2E\\uAA31\\uAA32\\uAA35\\uAA36\\uAA43\\uAA4C\\uAAB0\\uAAB2-\\uAAB4\\uAAB7\\uAAB8\\uAABE\\uAABF\\uAAC1\\uABE5\\uABE8\\uABED\\uFB1E\\uFE00-\\uFE0F\\uFE20-\\uFE26]"),
857
+ space_combining_mark: new RegExp("[\\u0903\\u093E-\\u0940\\u0949-\\u094C\\u094E\\u0982\\u0983\\u09BE-\\u09C0\\u09C7\\u09C8\\u09CB\\u09CC\\u09D7\\u0A03\\u0A3E-\\u0A40\\u0A83\\u0ABE-\\u0AC0\\u0AC9\\u0ACB\\u0ACC\\u0B02\\u0B03\\u0B3E\\u0B40\\u0B47\\u0B48\\u0B4B\\u0B4C\\u0B57\\u0BBE\\u0BBF\\u0BC1\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCC\\u0BD7\\u0C01-\\u0C03\\u0C41-\\u0C44\\u0C82\\u0C83\\u0CBE\\u0CC0-\\u0CC4\\u0CC7\\u0CC8\\u0CCA\\u0CCB\\u0CD5\\u0CD6\\u0D02\\u0D03\\u0D3E-\\u0D40\\u0D46-\\u0D48\\u0D4A-\\u0D4C\\u0D57\\u0D82\\u0D83\\u0DCF-\\u0DD1\\u0DD8-\\u0DDF\\u0DF2\\u0DF3\\u0F3E\\u0F3F\\u0F7F\\u102B\\u102C\\u1031\\u1038\\u103B\\u103C\\u1056\\u1057\\u1062-\\u1064\\u1067-\\u106D\\u1083\\u1084\\u1087-\\u108C\\u108F\\u109A-\\u109C\\u17B6\\u17BE-\\u17C5\\u17C7\\u17C8\\u1923-\\u1926\\u1929-\\u192B\\u1930\\u1931\\u1933-\\u1938\\u19B0-\\u19C0\\u19C8\\u19C9\\u1A19-\\u1A1B\\u1A55\\u1A57\\u1A61\\u1A63\\u1A64\\u1A6D-\\u1A72\\u1B04\\u1B35\\u1B3B\\u1B3D-\\u1B41\\u1B43\\u1B44\\u1B82\\u1BA1\\u1BA6\\u1BA7\\u1BAA\\u1C24-\\u1C2B\\u1C34\\u1C35\\u1CE1\\u1CF2\\uA823\\uA824\\uA827\\uA880\\uA881\\uA8B4-\\uA8C3\\uA952\\uA953\\uA983\\uA9B4\\uA9B5\\uA9BA\\uA9BB\\uA9BD-\\uA9C0\\uAA2F\\uAA30\\uAA33\\uAA34\\uAA4D\\uAA7B\\uABE3\\uABE4\\uABE6\\uABE7\\uABE9\\uABEA\\uABEC]"),
858
+ connector_punctuation: new RegExp("[\\u005F\\u203F\\u2040\\u2054\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF3F]")
859
+ };
860
+
861
+ function is_letter(ch) {
862
+ return UNICODE.letter.test(ch);
863
+ };
864
+
865
+ function is_digit(ch) {
866
+ ch = ch.charCodeAt(0);
867
+ return ch >= 48 && ch <= 57; //XXX: find out if "UnicodeDigit" means something else than 0..9
868
+ };
869
+
870
+ function is_alphanumeric_char(ch) {
871
+ return is_digit(ch) || is_letter(ch);
872
+ };
873
+
874
+ function is_unicode_combining_mark(ch) {
875
+ return UNICODE.non_spacing_mark.test(ch) || UNICODE.space_combining_mark.test(ch);
876
+ };
877
+
878
+ function is_unicode_connector_punctuation(ch) {
879
+ return UNICODE.connector_punctuation.test(ch);
880
+ };
881
+
882
+ function is_identifier_start(ch) {
883
+ return ch == "$" || ch == "_" || is_letter(ch);
884
+ };
885
+
886
+ function is_identifier_char(ch) {
887
+ return is_identifier_start(ch)
888
+ || is_unicode_combining_mark(ch)
889
+ || is_digit(ch)
890
+ || is_unicode_connector_punctuation(ch)
891
+ || ch == "\u200c" // zero-width non-joiner <ZWNJ>
892
+ || ch == "\u200d" // zero-width joiner <ZWJ> (in my ECMA-262 PDF, this is also 200c)
893
+ ;
894
+ };
895
+
896
+ function parse_js_number(num) {
897
+ if (RE_HEX_NUMBER.test(num)) {
898
+ return parseInt(num.substr(2), 16);
899
+ } else if (RE_OCT_NUMBER.test(num)) {
900
+ return parseInt(num.substr(1), 8);
901
+ } else if (RE_DEC_NUMBER.test(num)) {
902
+ return parseFloat(num);
903
+ }
904
+ };
905
+
906
+ function JS_Parse_Error(message, line, col, pos) {
907
+ this.message = message;
908
+ this.line = line;
909
+ this.col = col;
910
+ this.pos = pos;
911
+ try {
912
+ ({})();
913
+ } catch(ex) {
914
+ this.stack = ex.stack;
915
+ };
916
+ };
917
+
918
+ JS_Parse_Error.prototype.toString = function() {
919
+ return this.message + " (line: " + this.line + ", col: " + this.col + ", pos: " + this.pos + ")" + "\n\n" + this.stack;
920
+ };
921
+
922
+ function js_error(message, line, col, pos) {
923
+ throw new JS_Parse_Error(message, line, col, pos);
924
+ };
925
+
926
+ function is_token(token, type, val) {
927
+ return token.type == type && (val == null || token.value == val);
928
+ };
929
+
930
+ var EX_EOF = {};
931
+
932
+ function tokenizer($TEXT) {
933
+
934
+ var S = {
935
+ text : $TEXT.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, ''),
936
+ pos : 0,
937
+ tokpos : 0,
938
+ line : 0,
939
+ tokline : 0,
940
+ col : 0,
941
+ tokcol : 0,
942
+ newline_before : false,
943
+ regex_allowed : false,
944
+ comments_before : []
945
+ };
946
+
947
+ function peek() { return S.text.charAt(S.pos); };
948
+
949
+ function next(signal_eof) {
950
+ var ch = S.text.charAt(S.pos++);
951
+ if (signal_eof && !ch)
952
+ throw EX_EOF;
953
+ if (ch == "\n") {
954
+ S.newline_before = true;
955
+ ++S.line;
956
+ S.col = 0;
957
+ } else {
958
+ ++S.col;
959
+ }
960
+ return ch;
961
+ };
962
+
963
+ function eof() {
964
+ return !S.peek();
965
+ };
966
+
967
+ function find(what, signal_eof) {
968
+ var pos = S.text.indexOf(what, S.pos);
969
+ if (signal_eof && pos == -1) throw EX_EOF;
970
+ return pos;
971
+ };
972
+
973
+ function start_token() {
974
+ S.tokline = S.line;
975
+ S.tokcol = S.col;
976
+ S.tokpos = S.pos;
977
+ };
978
+
979
+ function token(type, value, is_comment) {
980
+ S.regex_allowed = ((type == "operator" && !HOP(UNARY_POSTFIX, value)) ||
981
+ (type == "keyword" && HOP(KEYWORDS_BEFORE_EXPRESSION, value)) ||
982
+ (type == "punc" && HOP(PUNC_BEFORE_EXPRESSION, value)));
983
+ var ret = {
984
+ type : type,
985
+ value : value,
986
+ line : S.tokline,
987
+ col : S.tokcol,
988
+ pos : S.tokpos,
989
+ nlb : S.newline_before
990
+ };
991
+ if (!is_comment) {
992
+ ret.comments_before = S.comments_before;
993
+ S.comments_before = [];
994
+ }
995
+ S.newline_before = false;
996
+ return ret;
997
+ };
998
+
999
+ function skip_whitespace() {
1000
+ while (HOP(WHITESPACE_CHARS, peek()))
1001
+ next();
1002
+ };
1003
+
1004
+ function read_while(pred) {
1005
+ var ret = "", ch = peek(), i = 0;
1006
+ while (ch && pred(ch, i++)) {
1007
+ ret += next();
1008
+ ch = peek();
1009
+ }
1010
+ return ret;
1011
+ };
1012
+
1013
+ function parse_error(err) {
1014
+ js_error(err, S.tokline, S.tokcol, S.tokpos);
1015
+ };
1016
+
1017
+ function read_num(prefix) {
1018
+ var has_e = false, after_e = false, has_x = false, has_dot = prefix == ".";
1019
+ var num = read_while(function(ch, i){
1020
+ if (ch == "x" || ch == "X") {
1021
+ if (has_x) return false;
1022
+ return has_x = true;
1023
+ }
1024
+ if (!has_x && (ch == "E" || ch == "e")) {
1025
+ if (has_e) return false;
1026
+ return has_e = after_e = true;
1027
+ }
1028
+ if (ch == "-") {
1029
+ if (after_e || (i == 0 && !prefix)) return true;
1030
+ return false;
1031
+ }
1032
+ if (ch == "+") return after_e;
1033
+ after_e = false;
1034
+ if (ch == ".") {
1035
+ if (!has_dot && !has_x)
1036
+ return has_dot = true;
1037
+ return false;
1038
+ }
1039
+ return is_alphanumeric_char(ch);
1040
+ });
1041
+ if (prefix)
1042
+ num = prefix + num;
1043
+ var valid = parse_js_number(num);
1044
+ if (!isNaN(valid)) {
1045
+ return token("num", valid);
1046
+ } else {
1047
+ parse_error("Invalid syntax: " + num);
1048
+ }
1049
+ };
1050
+
1051
+ function read_escaped_char() {
1052
+ var ch = next(true);
1053
+ switch (ch) {
1054
+ case "n" : return "\n";
1055
+ case "r" : return "\r";
1056
+ case "t" : return "\t";
1057
+ case "b" : return "\b";
1058
+ case "v" : return "\v";
1059
+ case "f" : return "\f";
1060
+ case "0" : return "\0";
1061
+ case "x" : return String.fromCharCode(hex_bytes(2));
1062
+ case "u" : return String.fromCharCode(hex_bytes(4));
1063
+ default : return ch;
1064
+ }
1065
+ };
1066
+
1067
+ function hex_bytes(n) {
1068
+ var num = 0;
1069
+ for (; n > 0; --n) {
1070
+ var digit = parseInt(next(true), 16);
1071
+ if (isNaN(digit))
1072
+ parse_error("Invalid hex-character pattern in string");
1073
+ num = (num << 4) | digit;
1074
+ }
1075
+ return num;
1076
+ };
1077
+
1078
+ function read_string() {
1079
+ return with_eof_error("Unterminated string constant", function(){
1080
+ var quote = next(), ret = "";
1081
+ for (;;) {
1082
+ var ch = next(true);
1083
+ if (ch == "\\") ch = read_escaped_char();
1084
+ else if (ch == quote) break;
1085
+ ret += ch;
1086
+ }
1087
+ return token("string", ret);
1088
+ });
1089
+ };
1090
+
1091
+ function read_line_comment() {
1092
+ next();
1093
+ var i = find("\n"), ret;
1094
+ if (i == -1) {
1095
+ ret = S.text.substr(S.pos);
1096
+ S.pos = S.text.length;
1097
+ } else {
1098
+ ret = S.text.substring(S.pos, i);
1099
+ S.pos = i;
1100
+ }
1101
+ return token("comment1", ret, true);
1102
+ };
1103
+
1104
+ function read_multiline_comment() {
1105
+ next();
1106
+ return with_eof_error("Unterminated multiline comment", function(){
1107
+ var i = find("*/", true),
1108
+ text = S.text.substring(S.pos, i),
1109
+ tok = token("comment2", text, true);
1110
+ S.pos = i + 2;
1111
+ S.line += text.split("\n").length - 1;
1112
+ S.newline_before = text.indexOf("\n") >= 0;
1113
+
1114
+ // https://github.com/mishoo/UglifyJS/issues/#issue/100
1115
+ if (/^@cc_on/i.test(text)) {
1116
+ warn("WARNING: at line " + S.line);
1117
+ warn("*** Found \"conditional comment\": " + text);
1118
+ warn("*** UglifyJS DISCARDS ALL COMMENTS. This means your code might no longer work properly in Internet Explorer.");
1119
+ }
1120
+
1121
+ return tok;
1122
+ });
1123
+ };
1124
+
1125
+ function read_name() {
1126
+ var backslash = false, name = "", ch;
1127
+ while ((ch = peek()) != null) {
1128
+ if (!backslash) {
1129
+ if (ch == "\\") backslash = true, next();
1130
+ else if (is_identifier_char(ch)) name += next();
1131
+ else break;
1132
+ }
1133
+ else {
1134
+ if (ch != "u") parse_error("Expecting UnicodeEscapeSequence -- uXXXX");
1135
+ ch = read_escaped_char();
1136
+ if (!is_identifier_char(ch)) parse_error("Unicode char: " + ch.charCodeAt(0) + " is not valid in identifier");
1137
+ name += ch;
1138
+ backslash = false;
1139
+ }
1140
+ }
1141
+ return name;
1142
+ };
1143
+
1144
+ function read_regexp() {
1145
+ return with_eof_error("Unterminated regular expression", function(){
1146
+ var prev_backslash = false, regexp = "", ch, in_class = false;
1147
+ while ((ch = next(true))) if (prev_backslash) {
1148
+ regexp += "\\" + ch;
1149
+ prev_backslash = false;
1150
+ } else if (ch == "[") {
1151
+ in_class = true;
1152
+ regexp += ch;
1153
+ } else if (ch == "]" && in_class) {
1154
+ in_class = false;
1155
+ regexp += ch;
1156
+ } else if (ch == "/" && !in_class) {
1157
+ break;
1158
+ } else if (ch == "\\") {
1159
+ prev_backslash = true;
1160
+ } else {
1161
+ regexp += ch;
1162
+ }
1163
+ var mods = read_name();
1164
+ return token("regexp", [ regexp, mods ]);
1165
+ });
1166
+ };
1167
+
1168
+ function read_operator(prefix) {
1169
+ function grow(op) {
1170
+ if (!peek()) return op;
1171
+ var bigger = op + peek();
1172
+ if (HOP(OPERATORS, bigger)) {
1173
+ next();
1174
+ return grow(bigger);
1175
+ } else {
1176
+ return op;
1177
+ }
1178
+ };
1179
+ return token("operator", grow(prefix || next()));
1180
+ };
1181
+
1182
+ function handle_slash() {
1183
+ next();
1184
+ var regex_allowed = S.regex_allowed;
1185
+ switch (peek()) {
1186
+ case "/":
1187
+ S.comments_before.push(read_line_comment());
1188
+ S.regex_allowed = regex_allowed;
1189
+ return next_token();
1190
+ case "*":
1191
+ S.comments_before.push(read_multiline_comment());
1192
+ S.regex_allowed = regex_allowed;
1193
+ return next_token();
1194
+ }
1195
+ return S.regex_allowed ? read_regexp() : read_operator("/");
1196
+ };
1197
+
1198
+ function handle_dot() {
1199
+ next();
1200
+ return is_digit(peek())
1201
+ ? read_num(".")
1202
+ : token("punc", ".");
1203
+ };
1204
+
1205
+ function read_word() {
1206
+ var word = read_name();
1207
+ return !HOP(KEYWORDS, word)
1208
+ ? token("name", word)
1209
+ : HOP(OPERATORS, word)
1210
+ ? token("operator", word)
1211
+ : HOP(KEYWORDS_ATOM, word)
1212
+ ? token("atom", word)
1213
+ : token("keyword", word);
1214
+ };
1215
+
1216
+ function with_eof_error(eof_error, cont) {
1217
+ try {
1218
+ return cont();
1219
+ } catch(ex) {
1220
+ if (ex === EX_EOF) parse_error(eof_error);
1221
+ else throw ex;
1222
+ }
1223
+ };
1224
+
1225
+ function next_token(force_regexp) {
1226
+ if (force_regexp)
1227
+ return read_regexp();
1228
+ skip_whitespace();
1229
+ start_token();
1230
+ var ch = peek();
1231
+ if (!ch) return token("eof");
1232
+ if (is_digit(ch)) return read_num();
1233
+ if (ch == '"' || ch == "'") return read_string();
1234
+ if (HOP(PUNC_CHARS, ch)) return token("punc", next());
1235
+ if (ch == ".") return handle_dot();
1236
+ if (ch == "/") return handle_slash();
1237
+ if (HOP(OPERATOR_CHARS, ch)) return read_operator();
1238
+ if (ch == "\\" || is_identifier_start(ch)) return read_word();
1239
+ parse_error("Unexpected character '" + ch + "'");
1240
+ };
1241
+
1242
+ next_token.context = function(nc) {
1243
+ if (nc) S = nc;
1244
+ return S;
1245
+ };
1246
+
1247
+ return next_token;
1248
+
1249
+ };
1250
+
1251
+ /* -----[ Parser (constants) ]----- */
1252
+
1253
+ var UNARY_PREFIX = array_to_hash([
1254
+ "typeof",
1255
+ "void",
1256
+ "delete",
1257
+ "--",
1258
+ "++",
1259
+ "!",
1260
+ "~",
1261
+ "-",
1262
+ "+"
1263
+ ]);
1264
+
1265
+ var UNARY_POSTFIX = array_to_hash([ "--", "++" ]);
1266
+
1267
+ var ASSIGNMENT = (function(a, ret, i){
1268
+ while (i < a.length) {
1269
+ ret[a[i]] = a[i].substr(0, a[i].length - 1);
1270
+ i++;
1271
+ }
1272
+ return ret;
1273
+ })(
1274
+ ["+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&="],
1275
+ { "=": true },
1276
+ 0
1277
+ );
1278
+
1279
+ var PRECEDENCE = (function(a, ret){
1280
+ for (var i = 0, n = 1; i < a.length; ++i, ++n) {
1281
+ var b = a[i];
1282
+ for (var j = 0; j < b.length; ++j) {
1283
+ ret[b[j]] = n;
1284
+ }
1285
+ }
1286
+ return ret;
1287
+ })(
1288
+ [
1289
+ ["||"],
1290
+ ["&&"],
1291
+ ["|"],
1292
+ ["^"],
1293
+ ["&"],
1294
+ ["==", "===", "!=", "!=="],
1295
+ ["<", ">", "<=", ">=", "in", "instanceof"],
1296
+ [">>", "<<", ">>>"],
1297
+ ["+", "-"],
1298
+ ["*", "/", "%"]
1299
+ ],
1300
+ {}
1301
+ );
1302
+
1303
+ var STATEMENTS_WITH_LABELS = array_to_hash([ "for", "do", "while", "switch" ]);
1304
+
1305
+ var ATOMIC_START_TOKEN = array_to_hash([ "atom", "num", "string", "regexp", "name" ]);
1306
+
1307
+ /* -----[ Parser ]----- */
1308
+
1309
+ function NodeWithToken(str, start, end) {
1310
+ this.name = str;
1311
+ this.start = start;
1312
+ this.end = end;
1313
+ };
1314
+
1315
+ NodeWithToken.prototype.toString = function() { return this.name; };
1316
+
1317
+ function parse($TEXT, exigent_mode, embed_tokens) {
1318
+
1319
+ var S = {
1320
+ input : typeof $TEXT == "string" ? tokenizer($TEXT, true) : $TEXT,
1321
+ token : null,
1322
+ prev : null,
1323
+ peeked : null,
1324
+ in_function : 0,
1325
+ in_loop : 0,
1326
+ labels : []
1327
+ };
1328
+
1329
+ S.token = next();
1330
+
1331
+ function is(type, value) {
1332
+ return is_token(S.token, type, value);
1333
+ };
1334
+
1335
+ function peek() { return S.peeked || (S.peeked = S.input()); };
1336
+
1337
+ function next() {
1338
+ S.prev = S.token;
1339
+ if (S.peeked) {
1340
+ S.token = S.peeked;
1341
+ S.peeked = null;
1342
+ } else {
1343
+ S.token = S.input();
1344
+ }
1345
+ return S.token;
1346
+ };
1347
+
1348
+ function prev() {
1349
+ return S.prev;
1350
+ };
1351
+
1352
+ function croak(msg, line, col, pos) {
1353
+ var ctx = S.input.context();
1354
+ js_error(msg,
1355
+ line != null ? line : ctx.tokline,
1356
+ col != null ? col : ctx.tokcol,
1357
+ pos != null ? pos : ctx.tokpos);
1358
+ };
1359
+
1360
+ function token_error(token, msg) {
1361
+ croak(msg, token.line, token.col);
1362
+ };
1363
+
1364
+ function unexpected(token) {
1365
+ if (token == null)
1366
+ token = S.token;
1367
+ token_error(token, "Unexpected token: " + token.type + " (" + token.value + ")");
1368
+ };
1369
+
1370
+ function expect_token(type, val) {
1371
+ if (is(type, val)) {
1372
+ return next();
1373
+ }
1374
+ token_error(S.token, "Unexpected token " + S.token.type + ", expected " + type);
1375
+ };
1376
+
1377
+ function expect(punc) { return expect_token("punc", punc); };
1378
+
1379
+ function can_insert_semicolon() {
1380
+ return !exigent_mode && (
1381
+ S.token.nlb || is("eof") || is("punc", "}")
1382
+ );
1383
+ };
1384
+
1385
+ function semicolon() {
1386
+ if (is("punc", ";")) next();
1387
+ else if (!can_insert_semicolon()) unexpected();
1388
+ };
1389
+
1390
+ function as() {
1391
+ return slice(arguments);
1392
+ };
1393
+
1394
+ function parenthesised() {
1395
+ expect("(");
1396
+ var ex = expression();
1397
+ expect(")");
1398
+ return ex;
1399
+ };
1400
+
1401
+ function add_tokens(str, start, end) {
1402
+ return str instanceof NodeWithToken ? str : new NodeWithToken(str, start, end);
1403
+ };
1404
+
1405
+ function maybe_embed_tokens(parser) {
1406
+ if (embed_tokens) return function() {
1407
+ var start = S.token;
1408
+ var ast = parser.apply(this, arguments);
1409
+ ast[0] = add_tokens(ast[0], start, prev());
1410
+ return ast;
1411
+ };
1412
+ else return parser;
1413
+ };
1414
+
1415
+ var statement = maybe_embed_tokens(function() {
1416
+ if (is("operator", "/")) {
1417
+ S.peeked = null;
1418
+ S.token = S.input(true); // force regexp
1419
+ }
1420
+ switch (S.token.type) {
1421
+ case "num":
1422
+ case "string":
1423
+ case "regexp":
1424
+ case "operator":
1425
+ case "atom":
1426
+ return simple_statement();
1427
+
1428
+ case "name":
1429
+ return is_token(peek(), "punc", ":")
1430
+ ? labeled_statement(prog1(S.token.value, next, next))
1431
+ : simple_statement();
1432
+
1433
+ case "punc":
1434
+ switch (S.token.value) {
1435
+ case "{":
1436
+ return as("block", block_());
1437
+ case "[":
1438
+ case "(":
1439
+ return simple_statement();
1440
+ case ";":
1441
+ next();
1442
+ return as("block");
1443
+ default:
1444
+ unexpected();
1445
+ }
1446
+
1447
+ case "keyword":
1448
+ switch (prog1(S.token.value, next)) {
1449
+ case "break":
1450
+ return break_cont("break");
1451
+
1452
+ case "continue":
1453
+ return break_cont("continue");
1454
+
1455
+ case "debugger":
1456
+ semicolon();
1457
+ return as("debugger");
1458
+
1459
+ case "do":
1460
+ return (function(body){
1461
+ expect_token("keyword", "while");
1462
+ return as("do", prog1(parenthesised, semicolon), body);
1463
+ })(in_loop(statement));
1464
+
1465
+ case "for":
1466
+ return for_();
1467
+
1468
+ case "function":
1469
+ return function_(true);
1470
+
1471
+ case "if":
1472
+ return if_();
1473
+
1474
+ case "return":
1475
+ if (S.in_function == 0)
1476
+ croak("'return' outside of function");
1477
+ return as("return",
1478
+ is("punc", ";")
1479
+ ? (next(), null)
1480
+ : can_insert_semicolon()
1481
+ ? null
1482
+ : prog1(expression, semicolon));
1483
+
1484
+ case "switch":
1485
+ return as("switch", parenthesised(), switch_block_());
1486
+
1487
+ case "throw":
1488
+ return as("throw", prog1(expression, semicolon));
1489
+
1490
+ case "try":
1491
+ return try_();
1492
+
1493
+ case "var":
1494
+ return prog1(var_, semicolon);
1495
+
1496
+ case "const":
1497
+ return prog1(const_, semicolon);
1498
+
1499
+ case "while":
1500
+ return as("while", parenthesised(), in_loop(statement));
1501
+
1502
+ case "with":
1503
+ return as("with", parenthesised(), statement());
1504
+
1505
+ default:
1506
+ unexpected();
1507
+ }
1508
+ }
1509
+ });
1510
+
1511
+ function labeled_statement(label) {
1512
+ S.labels.push(label);
1513
+ var start = S.token, stat = statement();
1514
+ if (exigent_mode && !HOP(STATEMENTS_WITH_LABELS, stat[0]))
1515
+ unexpected(start);
1516
+ S.labels.pop();
1517
+ return as("label", label, stat);
1518
+ };
1519
+
1520
+ function simple_statement() {
1521
+ return as("stat", prog1(expression, semicolon));
1522
+ };
1523
+
1524
+ function break_cont(type) {
1525
+ var name;
1526
+ if (!can_insert_semicolon()) {
1527
+ name = is("name") ? S.token.value : null;
1528
+ }
1529
+ if (name != null) {
1530
+ next();
1531
+ if (!member(name, S.labels))
1532
+ croak("Label " + name + " without matching loop or statement");
1533
+ }
1534
+ else if (S.in_loop == 0)
1535
+ croak(type + " not inside a loop or switch");
1536
+ semicolon();
1537
+ return as(type, name);
1538
+ };
1539
+
1540
+ function for_() {
1541
+ expect("(");
1542
+ var init = null;
1543
+ if (!is("punc", ";")) {
1544
+ init = is("keyword", "var")
1545
+ ? (next(), var_(true))
1546
+ : expression(true, true);
1547
+ if (is("operator", "in"))
1548
+ return for_in(init);
1549
+ }
1550
+ return regular_for(init);
1551
+ };
1552
+
1553
+ function regular_for(init) {
1554
+ expect(";");
1555
+ var test = is("punc", ";") ? null : expression();
1556
+ expect(";");
1557
+ var step = is("punc", ")") ? null : expression();
1558
+ expect(")");
1559
+ return as("for", init, test, step, in_loop(statement));
1560
+ };
1561
+
1562
+ function for_in(init) {
1563
+ var lhs = init[0] == "var" ? as("name", init[1][0]) : init;
1564
+ next();
1565
+ var obj = expression();
1566
+ expect(")");
1567
+ return as("for-in", init, lhs, obj, in_loop(statement));
1568
+ };
1569
+
1570
+ var function_ = maybe_embed_tokens(function(in_statement) {
1571
+ var name = is("name") ? prog1(S.token.value, next) : null;
1572
+ if (in_statement && !name)
1573
+ unexpected();
1574
+ expect("(");
1575
+ return as(in_statement ? "defun" : "function",
1576
+ name,
1577
+ // arguments
1578
+ (function(first, a){
1579
+ while (!is("punc", ")")) {
1580
+ if (first) first = false; else expect(",");
1581
+ if (!is("name")) unexpected();
1582
+ a.push(S.token.value);
1583
+ next();
1584
+ }
1585
+ next();
1586
+ return a;
1587
+ })(true, []),
1588
+ // body
1589
+ (function(){
1590
+ ++S.in_function;
1591
+ var loop = S.in_loop;
1592
+ S.in_loop = 0;
1593
+ var a = block_();
1594
+ --S.in_function;
1595
+ S.in_loop = loop;
1596
+ return a;
1597
+ })());
1598
+ });
1599
+
1600
+ function if_() {
1601
+ var cond = parenthesised(), body = statement(), belse;
1602
+ if (is("keyword", "else")) {
1603
+ next();
1604
+ belse = statement();
1605
+ }
1606
+ return as("if", cond, body, belse);
1607
+ };
1608
+
1609
+ function block_() {
1610
+ expect("{");
1611
+ var a = [];
1612
+ while (!is("punc", "}")) {
1613
+ if (is("eof")) unexpected();
1614
+ a.push(statement());
1615
+ }
1616
+ next();
1617
+ return a;
1618
+ };
1619
+
1620
+ var switch_block_ = curry(in_loop, function(){
1621
+ expect("{");
1622
+ var a = [], cur = null;
1623
+ while (!is("punc", "}")) {
1624
+ if (is("eof")) unexpected();
1625
+ if (is("keyword", "case")) {
1626
+ next();
1627
+ cur = [];
1628
+ a.push([ expression(), cur ]);
1629
+ expect(":");
1630
+ }
1631
+ else if (is("keyword", "default")) {
1632
+ next();
1633
+ expect(":");
1634
+ cur = [];
1635
+ a.push([ null, cur ]);
1636
+ }
1637
+ else {
1638
+ if (!cur) unexpected();
1639
+ cur.push(statement());
1640
+ }
1641
+ }
1642
+ next();
1643
+ return a;
1644
+ });
1645
+
1646
+ function try_() {
1647
+ var body = block_(), bcatch, bfinally;
1648
+ if (is("keyword", "catch")) {
1649
+ next();
1650
+ expect("(");
1651
+ if (!is("name"))
1652
+ croak("Name expected");
1653
+ var name = S.token.value;
1654
+ next();
1655
+ expect(")");
1656
+ bcatch = [ name, block_() ];
1657
+ }
1658
+ if (is("keyword", "finally")) {
1659
+ next();
1660
+ bfinally = block_();
1661
+ }
1662
+ if (!bcatch && !bfinally)
1663
+ croak("Missing catch/finally blocks");
1664
+ return as("try", body, bcatch, bfinally);
1665
+ };
1666
+
1667
+ function vardefs(no_in) {
1668
+ var a = [];
1669
+ for (;;) {
1670
+ if (!is("name"))
1671
+ unexpected();
1672
+ var name = S.token.value;
1673
+ next();
1674
+ if (is("operator", "=")) {
1675
+ next();
1676
+ a.push([ name, expression(false, no_in) ]);
1677
+ } else {
1678
+ a.push([ name ]);
1679
+ }
1680
+ if (!is("punc", ","))
1681
+ break;
1682
+ next();
1683
+ }
1684
+ return a;
1685
+ };
1686
+
1687
+ function var_(no_in) {
1688
+ return as("var", vardefs(no_in));
1689
+ };
1690
+
1691
+ function const_() {
1692
+ return as("const", vardefs());
1693
+ };
1694
+
1695
+ function new_() {
1696
+ var newexp = expr_atom(false), args;
1697
+ if (is("punc", "(")) {
1698
+ next();
1699
+ args = expr_list(")");
1700
+ } else {
1701
+ args = [];
1702
+ }
1703
+ return subscripts(as("new", newexp, args), true);
1704
+ };
1705
+
1706
+ var expr_atom = maybe_embed_tokens(function(allow_calls) {
1707
+ if (is("operator", "new")) {
1708
+ next();
1709
+ return new_();
1710
+ }
1711
+ if (is("operator") && HOP(UNARY_PREFIX, S.token.value)) {
1712
+ return make_unary("unary-prefix",
1713
+ prog1(S.token.value, next),
1714
+ expr_atom(allow_calls));
1715
+ }
1716
+ if (is("punc")) {
1717
+ switch (S.token.value) {
1718
+ case "(":
1719
+ next();
1720
+ return subscripts(prog1(expression, curry(expect, ")")), allow_calls);
1721
+ case "[":
1722
+ next();
1723
+ return subscripts(array_(), allow_calls);
1724
+ case "{":
1725
+ next();
1726
+ return subscripts(object_(), allow_calls);
1727
+ }
1728
+ unexpected();
1729
+ }
1730
+ if (is("keyword", "function")) {
1731
+ next();
1732
+ return subscripts(function_(false), allow_calls);
1733
+ }
1734
+ if (HOP(ATOMIC_START_TOKEN, S.token.type)) {
1735
+ var atom = S.token.type == "regexp"
1736
+ ? as("regexp", S.token.value[0], S.token.value[1])
1737
+ : as(S.token.type, S.token.value);
1738
+ return subscripts(prog1(atom, next), allow_calls);
1739
+ }
1740
+ unexpected();
1741
+ });
1742
+
1743
+ function expr_list(closing, allow_trailing_comma, allow_empty) {
1744
+ var first = true, a = [];
1745
+ while (!is("punc", closing)) {
1746
+ if (first) first = false; else expect(",");
1747
+ if (allow_trailing_comma && is("punc", closing)) break;
1748
+ if (is("punc", ",") && allow_empty) {
1749
+ a.push([ "atom", "undefined" ]);
1750
+ } else {
1751
+ a.push(expression(false));
1752
+ }
1753
+ }
1754
+ next();
1755
+ return a;
1756
+ };
1757
+
1758
+ function array_() {
1759
+ return as("array", expr_list("]", !exigent_mode, true));
1760
+ };
1761
+
1762
+ function object_() {
1763
+ var first = true, a = [];
1764
+ while (!is("punc", "}")) {
1765
+ if (first) first = false; else expect(",");
1766
+ if (!exigent_mode && is("punc", "}"))
1767
+ // allow trailing comma
1768
+ break;
1769
+ var type = S.token.type;
1770
+ var name = as_property_name();
1771
+ if (type == "name" && (name == "get" || name == "set") && !is("punc", ":")) {
1772
+ a.push([ as_name(), function_(false), name ]);
1773
+ } else {
1774
+ expect(":");
1775
+ a.push([ name, expression(false) ]);
1776
+ }
1777
+ }
1778
+ next();
1779
+ return as("object", a);
1780
+ };
1781
+
1782
+ function as_property_name() {
1783
+ switch (S.token.type) {
1784
+ case "num":
1785
+ case "string":
1786
+ return prog1(S.token.value, next);
1787
+ }
1788
+ return as_name();
1789
+ };
1790
+
1791
+ function as_name() {
1792
+ switch (S.token.type) {
1793
+ case "name":
1794
+ case "operator":
1795
+ case "keyword":
1796
+ case "atom":
1797
+ return prog1(S.token.value, next);
1798
+ default:
1799
+ unexpected();
1800
+ }
1801
+ };
1802
+
1803
+ function subscripts(expr, allow_calls) {
1804
+ if (is("punc", ".")) {
1805
+ next();
1806
+ return subscripts(as("dot", expr, as_name()), allow_calls);
1807
+ }
1808
+ if (is("punc", "[")) {
1809
+ next();
1810
+ return subscripts(as("sub", expr, prog1(expression, curry(expect, "]"))), allow_calls);
1811
+ }
1812
+ if (allow_calls && is("punc", "(")) {
1813
+ next();
1814
+ return subscripts(as("call", expr, expr_list(")")), true);
1815
+ }
1816
+ if (allow_calls && is("operator") && HOP(UNARY_POSTFIX, S.token.value)) {
1817
+ return prog1(curry(make_unary, "unary-postfix", S.token.value, expr),
1818
+ next);
1819
+ }
1820
+ return expr;
1821
+ };
1822
+
1823
+ function make_unary(tag, op, expr) {
1824
+ if ((op == "++" || op == "--") && !is_assignable(expr))
1825
+ croak("Invalid use of " + op + " operator");
1826
+ return as(tag, op, expr);
1827
+ };
1828
+
1829
+ function expr_op(left, min_prec, no_in) {
1830
+ var op = is("operator") ? S.token.value : null;
1831
+ if (op && op == "in" && no_in) op = null;
1832
+ var prec = op != null ? PRECEDENCE[op] : null;
1833
+ if (prec != null && prec > min_prec) {
1834
+ next();
1835
+ var right = expr_op(expr_atom(true), prec, no_in);
1836
+ return expr_op(as("binary", op, left, right), min_prec, no_in);
1837
+ }
1838
+ return left;
1839
+ };
1840
+
1841
+ function expr_ops(no_in) {
1842
+ return expr_op(expr_atom(true), 0, no_in);
1843
+ };
1844
+
1845
+ function maybe_conditional(no_in) {
1846
+ var expr = expr_ops(no_in);
1847
+ if (is("operator", "?")) {
1848
+ next();
1849
+ var yes = expression(false);
1850
+ expect(":");
1851
+ return as("conditional", expr, yes, expression(false, no_in));
1852
+ }
1853
+ return expr;
1854
+ };
1855
+
1856
+ function is_assignable(expr) {
1857
+ if (!exigent_mode) return true;
1858
+ switch (expr[0]) {
1859
+ case "dot":
1860
+ case "sub":
1861
+ case "new":
1862
+ case "call":
1863
+ return true;
1864
+ case "name":
1865
+ return expr[1] != "this";
1866
+ }
1867
+ };
1868
+
1869
+ function maybe_assign(no_in) {
1870
+ var left = maybe_conditional(no_in), val = S.token.value;
1871
+ if (is("operator") && HOP(ASSIGNMENT, val)) {
1872
+ if (is_assignable(left)) {
1873
+ next();
1874
+ return as("assign", ASSIGNMENT[val], left, maybe_assign(no_in));
1875
+ }
1876
+ croak("Invalid assignment");
1877
+ }
1878
+ return left;
1879
+ };
1880
+
1881
+ var expression = maybe_embed_tokens(function(commas, no_in) {
1882
+ if (arguments.length == 0)
1883
+ commas = true;
1884
+ var expr = maybe_assign(no_in);
1885
+ if (commas && is("punc", ",")) {
1886
+ next();
1887
+ return as("seq", expr, expression(true, no_in));
1888
+ }
1889
+ return expr;
1890
+ });
1891
+
1892
+ function in_loop(cont) {
1893
+ try {
1894
+ ++S.in_loop;
1895
+ return cont();
1896
+ } finally {
1897
+ --S.in_loop;
1898
+ }
1899
+ };
1900
+
1901
+ return as("toplevel", (function(a){
1902
+ while (!is("eof"))
1903
+ a.push(statement());
1904
+ return a;
1905
+ })([]));
1906
+
1907
+ };
1908
+
1909
+ /* -----[ Utilities ]----- */
1910
+
1911
+ function curry(f) {
1912
+ var args = slice(arguments, 1);
1913
+ return function() { return f.apply(this, args.concat(slice(arguments))); };
1914
+ };
1915
+
1916
+ function prog1(ret) {
1917
+ if (ret instanceof Function)
1918
+ ret = ret();
1919
+ for (var i = 1, n = arguments.length; --n > 0; ++i)
1920
+ arguments[i]();
1921
+ return ret;
1922
+ };
1923
+
1924
+ function array_to_hash(a) {
1925
+ var ret = {};
1926
+ for (var i = 0; i < a.length; ++i)
1927
+ ret[a[i]] = true;
1928
+ return ret;
1929
+ };
1930
+
1931
+ function slice(a, start) {
1932
+ return Array.prototype.slice.call(a, start == null ? 0 : start);
1933
+ };
1934
+
1935
+ function characters(str) {
1936
+ return str.split("");
1937
+ };
1938
+
1939
+ function member(name, array) {
1940
+ for (var i = array.length; --i >= 0;)
1941
+ if (array[i] === name)
1942
+ return true;
1943
+ return false;
1944
+ };
1945
+
1946
+ function HOP(obj, prop) {
1947
+ return Object.prototype.hasOwnProperty.call(obj, prop);
1948
+ };
1949
+
1950
+ var warn = function() {};
1951
+
1952
+ /* -----[ Exports ]----- */
1953
+
1954
+ exports.tokenizer = tokenizer;
1955
+ exports.parse = parse;
1956
+ exports.slice = slice;
1957
+ exports.curry = curry;
1958
+ exports.member = member;
1959
+ exports.array_to_hash = array_to_hash;
1960
+ exports.PRECEDENCE = PRECEDENCE;
1961
+ exports.KEYWORDS_ATOM = KEYWORDS_ATOM;
1962
+ exports.RESERVED_WORDS = RESERVED_WORDS;
1963
+ exports.KEYWORDS = KEYWORDS;
1964
+ exports.ATOMIC_START_TOKEN = ATOMIC_START_TOKEN;
1965
+ exports.OPERATORS = OPERATORS;
1966
+ exports.is_alphanumeric_char = is_alphanumeric_char;
1967
+ exports.set_logger = function(logger) {
1968
+ warn = logger;
1969
+ };
1970
+ ;
1971
+ }).call(module.exports);
1972
+
1973
+ __require.modules["/node_modules/uglify-js/lib/parse-js.js"]._cached = module.exports;
1974
+ return module.exports;
1975
+ };
1976
+
1977
+ require.modules["/node_modules/uglify-js/lib/process.js"] = function () {
1978
+ var module = { exports : {} };
1979
+ var exports = module.exports;
1980
+ var __dirname = "/node_modules/uglify-js/lib";
1981
+ var __filename = "/node_modules/uglify-js/lib/process.js";
1982
+
1983
+ var require = function (file) {
1984
+ return __require(file, "/node_modules/uglify-js/lib");
1985
+ };
1986
+
1987
+ require.resolve = function (file) {
1988
+ return __require.resolve(name, "/node_modules/uglify-js/lib");
1989
+ };
1990
+
1991
+ require.modules = __require.modules;
1992
+ __require.modules["/node_modules/uglify-js/lib/process.js"]._cached = module.exports;
1993
+
1994
+ (function () {
1995
+ /***********************************************************************
1996
+
1997
+ A JavaScript tokenizer / parser / beautifier / compressor.
1998
+
1999
+ This version is suitable for Node.js. With minimal changes (the
2000
+ exports stuff) it should work on any JS platform.
2001
+
2002
+ This file implements some AST processors. They work on data built
2003
+ by parse-js.
2004
+
2005
+ Exported functions:
2006
+
2007
+ - ast_mangle(ast, options) -- mangles the variable/function names
2008
+ in the AST. Returns an AST.
2009
+
2010
+ - ast_squeeze(ast) -- employs various optimizations to make the
2011
+ final generated code even smaller. Returns an AST.
2012
+
2013
+ - gen_code(ast, options) -- generates JS code from the AST. Pass
2014
+ true (or an object, see the code for some options) as second
2015
+ argument to get "pretty" (indented) code.
2016
+
2017
+ -------------------------------- (C) ---------------------------------
2018
+
2019
+ Author: Mihai Bazon
2020
+ <mihai.bazon@gmail.com>
2021
+ http://mihai.bazon.net/blog
2022
+
2023
+ Distributed under the BSD license:
2024
+
2025
+ Copyright 2010 (c) Mihai Bazon <mihai.bazon@gmail.com>
2026
+
2027
+ Redistribution and use in source and binary forms, with or without
2028
+ modification, are permitted provided that the following conditions
2029
+ are met:
2030
+
2031
+ * Redistributions of source code must retain the above
2032
+ copyright notice, this list of conditions and the following
2033
+ disclaimer.
2034
+
2035
+ * Redistributions in binary form must reproduce the above
2036
+ copyright notice, this list of conditions and the following
2037
+ disclaimer in the documentation and/or other materials
2038
+ provided with the distribution.
2039
+
2040
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
2041
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2042
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2043
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
2044
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
2045
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2046
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2047
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2048
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
2049
+ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
2050
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2051
+ SUCH DAMAGE.
2052
+
2053
+ ***********************************************************************/
2054
+
2055
+ var jsp = require("./parse-js"),
2056
+ slice = jsp.slice,
2057
+ member = jsp.member,
2058
+ PRECEDENCE = jsp.PRECEDENCE,
2059
+ OPERATORS = jsp.OPERATORS;
2060
+
2061
+ /* -----[ helper for AST traversal ]----- */
2062
+
2063
+ function ast_walker(ast) {
2064
+ function _vardefs(defs) {
2065
+ return [ this[0], MAP(defs, function(def){
2066
+ var a = [ def[0] ];
2067
+ if (def.length > 1)
2068
+ a[1] = walk(def[1]);
2069
+ return a;
2070
+ }) ];
2071
+ };
2072
+ function _block(statements) {
2073
+ var out = [ this[0] ];
2074
+ if (statements != null)
2075
+ out.push(MAP(statements, walk));
2076
+ return out;
2077
+ };
2078
+ var walkers = {
2079
+ "string": function(str) {
2080
+ return [ this[0], str ];
2081
+ },
2082
+ "num": function(num) {
2083
+ return [ this[0], num ];
2084
+ },
2085
+ "name": function(name) {
2086
+ return [ this[0], name ];
2087
+ },
2088
+ "toplevel": function(statements) {
2089
+ return [ this[0], MAP(statements, walk) ];
2090
+ },
2091
+ "block": _block,
2092
+ "splice": _block,
2093
+ "var": _vardefs,
2094
+ "const": _vardefs,
2095
+ "try": function(t, c, f) {
2096
+ return [
2097
+ this[0],
2098
+ MAP(t, walk),
2099
+ c != null ? [ c[0], MAP(c[1], walk) ] : null,
2100
+ f != null ? MAP(f, walk) : null
2101
+ ];
2102
+ },
2103
+ "throw": function(expr) {
2104
+ return [ this[0], walk(expr) ];
2105
+ },
2106
+ "new": function(ctor, args) {
2107
+ return [ this[0], walk(ctor), MAP(args, walk) ];
2108
+ },
2109
+ "switch": function(expr, body) {
2110
+ return [ this[0], walk(expr), MAP(body, function(branch){
2111
+ return [ branch[0] ? walk(branch[0]) : null,
2112
+ MAP(branch[1], walk) ];
2113
+ }) ];
2114
+ },
2115
+ "break": function(label) {
2116
+ return [ this[0], label ];
2117
+ },
2118
+ "continue": function(label) {
2119
+ return [ this[0], label ];
2120
+ },
2121
+ "conditional": function(cond, t, e) {
2122
+ return [ this[0], walk(cond), walk(t), walk(e) ];
2123
+ },
2124
+ "assign": function(op, lvalue, rvalue) {
2125
+ return [ this[0], op, walk(lvalue), walk(rvalue) ];
2126
+ },
2127
+ "dot": function(expr) {
2128
+ return [ this[0], walk(expr) ].concat(slice(arguments, 1));
2129
+ },
2130
+ "call": function(expr, args) {
2131
+ return [ this[0], walk(expr), MAP(args, walk) ];
2132
+ },
2133
+ "function": function(name, args, body) {
2134
+ return [ this[0], name, args.slice(), MAP(body, walk) ];
2135
+ },
2136
+ "defun": function(name, args, body) {
2137
+ return [ this[0], name, args.slice(), MAP(body, walk) ];
2138
+ },
2139
+ "if": function(conditional, t, e) {
2140
+ return [ this[0], walk(conditional), walk(t), walk(e) ];
2141
+ },
2142
+ "for": function(init, cond, step, block) {
2143
+ return [ this[0], walk(init), walk(cond), walk(step), walk(block) ];
2144
+ },
2145
+ "for-in": function(vvar, key, hash, block) {
2146
+ return [ this[0], walk(vvar), walk(key), walk(hash), walk(block) ];
2147
+ },
2148
+ "while": function(cond, block) {
2149
+ return [ this[0], walk(cond), walk(block) ];
2150
+ },
2151
+ "do": function(cond, block) {
2152
+ return [ this[0], walk(cond), walk(block) ];
2153
+ },
2154
+ "return": function(expr) {
2155
+ return [ this[0], walk(expr) ];
2156
+ },
2157
+ "binary": function(op, left, right) {
2158
+ return [ this[0], op, walk(left), walk(right) ];
2159
+ },
2160
+ "unary-prefix": function(op, expr) {
2161
+ return [ this[0], op, walk(expr) ];
2162
+ },
2163
+ "unary-postfix": function(op, expr) {
2164
+ return [ this[0], op, walk(expr) ];
2165
+ },
2166
+ "sub": function(expr, subscript) {
2167
+ return [ this[0], walk(expr), walk(subscript) ];
2168
+ },
2169
+ "object": function(props) {
2170
+ return [ this[0], MAP(props, function(p){
2171
+ return p.length == 2
2172
+ ? [ p[0], walk(p[1]) ]
2173
+ : [ p[0], walk(p[1]), p[2] ]; // get/set-ter
2174
+ }) ];
2175
+ },
2176
+ "regexp": function(rx, mods) {
2177
+ return [ this[0], rx, mods ];
2178
+ },
2179
+ "array": function(elements) {
2180
+ return [ this[0], MAP(elements, walk) ];
2181
+ },
2182
+ "stat": function(stat) {
2183
+ return [ this[0], walk(stat) ];
2184
+ },
2185
+ "seq": function() {
2186
+ return [ this[0] ].concat(MAP(slice(arguments), walk));
2187
+ },
2188
+ "label": function(name, block) {
2189
+ return [ this[0], name, walk(block) ];
2190
+ },
2191
+ "with": function(expr, block) {
2192
+ return [ this[0], walk(expr), walk(block) ];
2193
+ },
2194
+ "atom": function(name) {
2195
+ return [ this[0], name ];
2196
+ }
2197
+ };
2198
+
2199
+ var user = {};
2200
+ var stack = [];
2201
+ function walk(ast) {
2202
+ if (ast == null)
2203
+ return null;
2204
+ try {
2205
+ stack.push(ast);
2206
+ var type = ast[0];
2207
+ var gen = user[type];
2208
+ if (gen) {
2209
+ var ret = gen.apply(ast, ast.slice(1));
2210
+ if (ret != null)
2211
+ return ret;
2212
+ }
2213
+ gen = walkers[type];
2214
+ return gen.apply(ast, ast.slice(1));
2215
+ } finally {
2216
+ stack.pop();
2217
+ }
2218
+ };
2219
+
2220
+ function with_walkers(walkers, cont){
2221
+ var save = {}, i;
2222
+ for (i in walkers) if (HOP(walkers, i)) {
2223
+ save[i] = user[i];
2224
+ user[i] = walkers[i];
2225
+ }
2226
+ var ret = cont();
2227
+ for (i in save) if (HOP(save, i)) {
2228
+ if (!save[i]) delete user[i];
2229
+ else user[i] = save[i];
2230
+ }
2231
+ return ret;
2232
+ };
2233
+
2234
+ return {
2235
+ walk: walk,
2236
+ with_walkers: with_walkers,
2237
+ parent: function() {
2238
+ return stack[stack.length - 2]; // last one is current node
2239
+ },
2240
+ stack: function() {
2241
+ return stack;
2242
+ }
2243
+ };
2244
+ };
2245
+
2246
+ /* -----[ Scope and mangling ]----- */
2247
+
2248
+ function Scope(parent) {
2249
+ this.names = {}; // names defined in this scope
2250
+ this.mangled = {}; // mangled names (orig.name => mangled)
2251
+ this.rev_mangled = {}; // reverse lookup (mangled => orig.name)
2252
+ this.cname = -1; // current mangled name
2253
+ this.refs = {}; // names referenced from this scope
2254
+ this.uses_with = false; // will become TRUE if with() is detected in this or any subscopes
2255
+ this.uses_eval = false; // will become TRUE if eval() is detected in this or any subscopes
2256
+ this.parent = parent; // parent scope
2257
+ this.children = []; // sub-scopes
2258
+ if (parent) {
2259
+ this.level = parent.level + 1;
2260
+ parent.children.push(this);
2261
+ } else {
2262
+ this.level = 0;
2263
+ }
2264
+ };
2265
+
2266
+ var base54 = (function(){
2267
+ var DIGITS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_";
2268
+ return function(num) {
2269
+ var ret = "";
2270
+ do {
2271
+ ret = DIGITS.charAt(num % 54) + ret;
2272
+ num = Math.floor(num / 54);
2273
+ } while (num > 0);
2274
+ return ret;
2275
+ };
2276
+ })();
2277
+
2278
+ Scope.prototype = {
2279
+ has: function(name) {
2280
+ for (var s = this; s; s = s.parent)
2281
+ if (HOP(s.names, name))
2282
+ return s;
2283
+ },
2284
+ has_mangled: function(mname) {
2285
+ for (var s = this; s; s = s.parent)
2286
+ if (HOP(s.rev_mangled, mname))
2287
+ return s;
2288
+ },
2289
+ toJSON: function() {
2290
+ return {
2291
+ names: this.names,
2292
+ uses_eval: this.uses_eval,
2293
+ uses_with: this.uses_with
2294
+ };
2295
+ },
2296
+
2297
+ next_mangled: function() {
2298
+ // we must be careful that the new mangled name:
2299
+ //
2300
+ // 1. doesn't shadow a mangled name from a parent
2301
+ // scope, unless we don't reference the original
2302
+ // name from this scope OR from any sub-scopes!
2303
+ // This will get slow.
2304
+ //
2305
+ // 2. doesn't shadow an original name from a parent
2306
+ // scope, in the event that the name is not mangled
2307
+ // in the parent scope and we reference that name
2308
+ // here OR IN ANY SUBSCOPES!
2309
+ //
2310
+ // 3. doesn't shadow a name that is referenced but not
2311
+ // defined (possibly global defined elsewhere).
2312
+ for (;;) {
2313
+ var m = base54(++this.cname), prior;
2314
+
2315
+ // case 1.
2316
+ prior = this.has_mangled(m);
2317
+ if (prior && this.refs[prior.rev_mangled[m]] === prior)
2318
+ continue;
2319
+
2320
+ // case 2.
2321
+ prior = this.has(m);
2322
+ if (prior && prior !== this && this.refs[m] === prior && !prior.has_mangled(m))
2323
+ continue;
2324
+
2325
+ // case 3.
2326
+ if (HOP(this.refs, m) && this.refs[m] == null)
2327
+ continue;
2328
+
2329
+ // I got "do" once. :-/
2330
+ if (!is_identifier(m))
2331
+ continue;
2332
+
2333
+ return m;
2334
+ }
2335
+ },
2336
+ set_mangle: function(name, m) {
2337
+ this.rev_mangled[m] = name;
2338
+ return this.mangled[name] = m;
2339
+ },
2340
+ get_mangled: function(name, newMangle) {
2341
+ if (this.uses_eval || this.uses_with) return name; // no mangle if eval or with is in use
2342
+ var s = this.has(name);
2343
+ if (!s) return name; // not in visible scope, no mangle
2344
+ if (HOP(s.mangled, name)) return s.mangled[name]; // already mangled in this scope
2345
+ if (!newMangle) return name; // not found and no mangling requested
2346
+ return s.set_mangle(name, s.next_mangled());
2347
+ },
2348
+ define: function(name) {
2349
+ if (name != null)
2350
+ return this.names[name] = name;
2351
+ }
2352
+ };
2353
+
2354
+ function ast_add_scope(ast) {
2355
+
2356
+ var current_scope = null;
2357
+ var w = ast_walker(), walk = w.walk;
2358
+ var having_eval = [];
2359
+
2360
+ function with_new_scope(cont) {
2361
+ current_scope = new Scope(current_scope);
2362
+ var ret = current_scope.body = cont();
2363
+ ret.scope = current_scope;
2364
+ current_scope = current_scope.parent;
2365
+ return ret;
2366
+ };
2367
+
2368
+ function define(name) {
2369
+ return current_scope.define(name);
2370
+ };
2371
+
2372
+ function reference(name) {
2373
+ current_scope.refs[name] = true;
2374
+ };
2375
+
2376
+ function _lambda(name, args, body) {
2377
+ var is_defun = this[0] == "defun";
2378
+ return [ this[0], is_defun ? define(name) : name, args, with_new_scope(function(){
2379
+ if (!is_defun) define(name);
2380
+ MAP(args, define);
2381
+ return MAP(body, walk);
2382
+ })];
2383
+ };
2384
+
2385
+ return with_new_scope(function(){
2386
+ // process AST
2387
+ var ret = w.with_walkers({
2388
+ "function": _lambda,
2389
+ "defun": _lambda,
2390
+ "with": function(expr, block) {
2391
+ for (var s = current_scope; s; s = s.parent)
2392
+ s.uses_with = true;
2393
+ },
2394
+ "var": function(defs) {
2395
+ MAP(defs, function(d){ define(d[0]) });
2396
+ },
2397
+ "const": function(defs) {
2398
+ MAP(defs, function(d){ define(d[0]) });
2399
+ },
2400
+ "try": function(t, c, f) {
2401
+ if (c != null) return [
2402
+ this[0],
2403
+ MAP(t, walk),
2404
+ [ define(c[0]), MAP(c[1], walk) ],
2405
+ f != null ? MAP(f, walk) : null
2406
+ ];
2407
+ },
2408
+ "name": function(name) {
2409
+ if (name == "eval")
2410
+ having_eval.push(current_scope);
2411
+ reference(name);
2412
+ }
2413
+ }, function(){
2414
+ return walk(ast);
2415
+ });
2416
+
2417
+ // the reason why we need an additional pass here is
2418
+ // that names can be used prior to their definition.
2419
+
2420
+ // scopes where eval was detected and their parents
2421
+ // are marked with uses_eval, unless they define the
2422
+ // "eval" name.
2423
+ MAP(having_eval, function(scope){
2424
+ if (!scope.has("eval")) while (scope) {
2425
+ scope.uses_eval = true;
2426
+ scope = scope.parent;
2427
+ }
2428
+ });
2429
+
2430
+ // for referenced names it might be useful to know
2431
+ // their origin scope. current_scope here is the
2432
+ // toplevel one.
2433
+ function fixrefs(scope, i) {
2434
+ // do children first; order shouldn't matter
2435
+ for (i = scope.children.length; --i >= 0;)
2436
+ fixrefs(scope.children[i]);
2437
+ for (i in scope.refs) if (HOP(scope.refs, i)) {
2438
+ // find origin scope and propagate the reference to origin
2439
+ for (var origin = scope.has(i), s = scope; s; s = s.parent) {
2440
+ s.refs[i] = origin;
2441
+ if (s === origin) break;
2442
+ }
2443
+ }
2444
+ };
2445
+ fixrefs(current_scope);
2446
+
2447
+ return ret;
2448
+ });
2449
+
2450
+ };
2451
+
2452
+ /* -----[ mangle names ]----- */
2453
+
2454
+ function ast_mangle(ast, options) {
2455
+ var w = ast_walker(), walk = w.walk, scope;
2456
+ options = options || {};
2457
+
2458
+ function get_mangled(name, newMangle) {
2459
+ if (!options.toplevel && !scope.parent) return name; // don't mangle toplevel
2460
+ if (options.except && member(name, options.except))
2461
+ return name;
2462
+ return scope.get_mangled(name, newMangle);
2463
+ };
2464
+
2465
+ function get_define(name) {
2466
+ if (options.defines) {
2467
+ // we always lookup a defined symbol for the current scope FIRST, so declared
2468
+ // vars trump a DEFINE symbol, but if no such var is found, then match a DEFINE value
2469
+ if (!scope.has(name)) {
2470
+ if (HOP(options.defines, name)) {
2471
+ return options.defines[name];
2472
+ }
2473
+ }
2474
+ return null;
2475
+ }
2476
+ };
2477
+
2478
+ function _lambda(name, args, body) {
2479
+ var is_defun = this[0] == "defun", extra;
2480
+ if (name) {
2481
+ if (is_defun) name = get_mangled(name);
2482
+ else {
2483
+ extra = {};
2484
+ name = extra[name] = scope.next_mangled();
2485
+ }
2486
+ }
2487
+ body = with_scope(body.scope, function(){
2488
+ args = MAP(args, function(name){ return get_mangled(name) });
2489
+ return MAP(body, walk);
2490
+ }, extra);
2491
+ return [ this[0], name, args, body ];
2492
+ };
2493
+
2494
+ function with_scope(s, cont, extra) {
2495
+ var _scope = scope;
2496
+ scope = s;
2497
+ if (extra) for (var i in extra) if (HOP(extra, i)) {
2498
+ s.set_mangle(i, extra[i]);
2499
+ }
2500
+ for (var i in s.names) if (HOP(s.names, i)) {
2501
+ get_mangled(i, true);
2502
+ }
2503
+ var ret = cont();
2504
+ ret.scope = s;
2505
+ scope = _scope;
2506
+ return ret;
2507
+ };
2508
+
2509
+ function _vardefs(defs) {
2510
+ return [ this[0], MAP(defs, function(d){
2511
+ return [ get_mangled(d[0]), walk(d[1]) ];
2512
+ }) ];
2513
+ };
2514
+
2515
+ return w.with_walkers({
2516
+ "function": _lambda,
2517
+ "defun": function() {
2518
+ // move function declarations to the top when
2519
+ // they are not in some block.
2520
+ var ast = _lambda.apply(this, arguments);
2521
+ switch (w.parent()[0]) {
2522
+ case "toplevel":
2523
+ case "function":
2524
+ case "defun":
2525
+ return MAP.at_top(ast);
2526
+ }
2527
+ return ast;
2528
+ },
2529
+ "var": _vardefs,
2530
+ "const": _vardefs,
2531
+ "name": function(name) {
2532
+ return get_define(name) || [ this[0], get_mangled(name) ];
2533
+ },
2534
+ "try": function(t, c, f) {
2535
+ return [ this[0],
2536
+ MAP(t, walk),
2537
+ c != null ? [ get_mangled(c[0]), MAP(c[1], walk) ] : null,
2538
+ f != null ? MAP(f, walk) : null ];
2539
+ },
2540
+ "toplevel": function(body) {
2541
+ var self = this;
2542
+ return with_scope(self.scope, function(){
2543
+ return [ self[0], MAP(body, walk) ];
2544
+ });
2545
+ }
2546
+ }, function() {
2547
+ return walk(ast_add_scope(ast));
2548
+ });
2549
+ };
2550
+
2551
+ /* -----[
2552
+ - compress foo["bar"] into foo.bar,
2553
+ - remove block brackets {} where possible
2554
+ - join consecutive var declarations
2555
+ - various optimizations for IFs:
2556
+ - if (cond) foo(); else bar(); ==> cond?foo():bar();
2557
+ - if (cond) foo(); ==> cond&&foo();
2558
+ - if (foo) return bar(); else return baz(); ==> return foo?bar():baz(); // also for throw
2559
+ - if (foo) return bar(); else something(); ==> {if(foo)return bar();something()}
2560
+ ]----- */
2561
+
2562
+ var warn = function(){};
2563
+
2564
+ function best_of(ast1, ast2) {
2565
+ return gen_code(ast1).length > gen_code(ast2[0] == "stat" ? ast2[1] : ast2).length ? ast2 : ast1;
2566
+ };
2567
+
2568
+ function last_stat(b) {
2569
+ if (b[0] == "block" && b[1] && b[1].length > 0)
2570
+ return b[1][b[1].length - 1];
2571
+ return b;
2572
+ }
2573
+
2574
+ function aborts(t) {
2575
+ if (t) {
2576
+ t = last_stat(t);
2577
+ if (t[0] == "return" || t[0] == "break" || t[0] == "continue" || t[0] == "throw")
2578
+ return true;
2579
+ }
2580
+ };
2581
+
2582
+ function boolean_expr(expr) {
2583
+ return ( (expr[0] == "unary-prefix"
2584
+ && member(expr[1], [ "!", "delete" ])) ||
2585
+
2586
+ (expr[0] == "binary"
2587
+ && member(expr[1], [ "in", "instanceof", "==", "!=", "===", "!==", "<", "<=", ">=", ">" ])) ||
2588
+
2589
+ (expr[0] == "binary"
2590
+ && member(expr[1], [ "&&", "||" ])
2591
+ && boolean_expr(expr[2])
2592
+ && boolean_expr(expr[3])) ||
2593
+
2594
+ (expr[0] == "conditional"
2595
+ && boolean_expr(expr[2])
2596
+ && boolean_expr(expr[3])) ||
2597
+
2598
+ (expr[0] == "assign"
2599
+ && expr[1] === true
2600
+ && boolean_expr(expr[3])) ||
2601
+
2602
+ (expr[0] == "seq"
2603
+ && boolean_expr(expr[expr.length - 1]))
2604
+ );
2605
+ };
2606
+
2607
+ function make_conditional(c, t, e) {
2608
+ var make_real_conditional = function() {
2609
+ if (c[0] == "unary-prefix" && c[1] == "!") {
2610
+ return e ? [ "conditional", c[2], e, t ] : [ "binary", "||", c[2], t ];
2611
+ } else {
2612
+ return e ? [ "conditional", c, t, e ] : [ "binary", "&&", c, t ];
2613
+ }
2614
+ };
2615
+ // shortcut the conditional if the expression has a constant value
2616
+ return when_constant(c, function(ast, val){
2617
+ warn_unreachable(val ? e : t);
2618
+ return (val ? t : e);
2619
+ }, make_real_conditional);
2620
+ };
2621
+
2622
+ function empty(b) {
2623
+ return !b || (b[0] == "block" && (!b[1] || b[1].length == 0));
2624
+ };
2625
+
2626
+ function is_string(node) {
2627
+ return (node[0] == "string" ||
2628
+ node[0] == "unary-prefix" && node[1] == "typeof" ||
2629
+ node[0] == "binary" && node[1] == "+" &&
2630
+ (is_string(node[2]) || is_string(node[3])));
2631
+ };
2632
+
2633
+ var when_constant = (function(){
2634
+
2635
+ var $NOT_CONSTANT = {};
2636
+
2637
+ // this can only evaluate constant expressions. If it finds anything
2638
+ // not constant, it throws $NOT_CONSTANT.
2639
+ function evaluate(expr) {
2640
+ switch (expr[0]) {
2641
+ case "string":
2642
+ case "num":
2643
+ return expr[1];
2644
+ case "name":
2645
+ case "atom":
2646
+ switch (expr[1]) {
2647
+ case "true": return true;
2648
+ case "false": return false;
2649
+ }
2650
+ break;
2651
+ case "unary-prefix":
2652
+ switch (expr[1]) {
2653
+ case "!": return !evaluate(expr[2]);
2654
+ case "typeof": return typeof evaluate(expr[2]);
2655
+ case "~": return ~evaluate(expr[2]);
2656
+ case "-": return -evaluate(expr[2]);
2657
+ case "+": return +evaluate(expr[2]);
2658
+ }
2659
+ break;
2660
+ case "binary":
2661
+ var left = expr[2], right = expr[3];
2662
+ switch (expr[1]) {
2663
+ case "&&" : return evaluate(left) && evaluate(right);
2664
+ case "||" : return evaluate(left) || evaluate(right);
2665
+ case "|" : return evaluate(left) | evaluate(right);
2666
+ case "&" : return evaluate(left) & evaluate(right);
2667
+ case "^" : return evaluate(left) ^ evaluate(right);
2668
+ case "+" : return evaluate(left) + evaluate(right);
2669
+ case "*" : return evaluate(left) * evaluate(right);
2670
+ case "/" : return evaluate(left) / evaluate(right);
2671
+ case "-" : return evaluate(left) - evaluate(right);
2672
+ case "<<" : return evaluate(left) << evaluate(right);
2673
+ case ">>" : return evaluate(left) >> evaluate(right);
2674
+ case ">>>" : return evaluate(left) >>> evaluate(right);
2675
+ case "==" : return evaluate(left) == evaluate(right);
2676
+ case "===" : return evaluate(left) === evaluate(right);
2677
+ case "!=" : return evaluate(left) != evaluate(right);
2678
+ case "!==" : return evaluate(left) !== evaluate(right);
2679
+ case "<" : return evaluate(left) < evaluate(right);
2680
+ case "<=" : return evaluate(left) <= evaluate(right);
2681
+ case ">" : return evaluate(left) > evaluate(right);
2682
+ case ">=" : return evaluate(left) >= evaluate(right);
2683
+ case "in" : return evaluate(left) in evaluate(right);
2684
+ case "instanceof" : return evaluate(left) instanceof evaluate(right);
2685
+ }
2686
+ }
2687
+ throw $NOT_CONSTANT;
2688
+ };
2689
+
2690
+ return function(expr, yes, no) {
2691
+ try {
2692
+ var val = evaluate(expr), ast;
2693
+ switch (typeof val) {
2694
+ case "string": ast = [ "string", val ]; break;
2695
+ case "number": ast = [ "num", val ]; break;
2696
+ case "boolean": ast = [ "name", String(val) ]; break;
2697
+ default: throw new Error("Can't handle constant of type: " + (typeof val));
2698
+ }
2699
+ return yes.call(expr, ast, val);
2700
+ } catch(ex) {
2701
+ if (ex === $NOT_CONSTANT) {
2702
+ if (expr[0] == "binary"
2703
+ && (expr[1] == "===" || expr[1] == "!==")
2704
+ && ((is_string(expr[2]) && is_string(expr[3]))
2705
+ || (boolean_expr(expr[2]) && boolean_expr(expr[3])))) {
2706
+ expr[1] = expr[1].substr(0, 2);
2707
+ }
2708
+ else if (no && expr[0] == "binary"
2709
+ && (expr[1] == "||" || expr[1] == "&&")) {
2710
+ // the whole expression is not constant but the lval may be...
2711
+ try {
2712
+ var lval = evaluate(expr[2]);
2713
+ expr = ((expr[1] == "&&" && (lval ? expr[3] : lval)) ||
2714
+ (expr[1] == "||" && (lval ? lval : expr[3])) ||
2715
+ expr);
2716
+ } catch(ex2) {
2717
+ // IGNORE... lval is not constant
2718
+ }
2719
+ }
2720
+ return no ? no.call(expr, expr) : null;
2721
+ }
2722
+ else throw ex;
2723
+ }
2724
+ };
2725
+
2726
+ })();
2727
+
2728
+ function warn_unreachable(ast) {
2729
+ if (!empty(ast))
2730
+ warn("Dropping unreachable code: " + gen_code(ast, true));
2731
+ };
2732
+
2733
+ function prepare_ifs(ast) {
2734
+ var w = ast_walker(), walk = w.walk;
2735
+ // In this first pass, we rewrite ifs which abort with no else with an
2736
+ // if-else. For example:
2737
+ //
2738
+ // if (x) {
2739
+ // blah();
2740
+ // return y;
2741
+ // }
2742
+ // foobar();
2743
+ //
2744
+ // is rewritten into:
2745
+ //
2746
+ // if (x) {
2747
+ // blah();
2748
+ // return y;
2749
+ // } else {
2750
+ // foobar();
2751
+ // }
2752
+ function redo_if(statements) {
2753
+ statements = MAP(statements, walk);
2754
+
2755
+ for (var i = 0; i < statements.length; ++i) {
2756
+ var fi = statements[i];
2757
+ if (fi[0] != "if") continue;
2758
+
2759
+ if (fi[3] && walk(fi[3])) continue;
2760
+
2761
+ var t = walk(fi[2]);
2762
+ if (!aborts(t)) continue;
2763
+
2764
+ var conditional = walk(fi[1]);
2765
+
2766
+ var e_body = statements.slice(i + 1);
2767
+ var e;
2768
+ if (e_body.length == 1) e = e_body[0];
2769
+ else e = [ "block", e_body ];
2770
+
2771
+ var ret = statements.slice(0, i).concat([ [
2772
+ fi[0], // "if"
2773
+ conditional, // conditional
2774
+ t, // then
2775
+ e // else
2776
+ ] ]);
2777
+
2778
+ return redo_if(ret);
2779
+ }
2780
+
2781
+ return statements;
2782
+ };
2783
+
2784
+ function redo_if_lambda(name, args, body) {
2785
+ body = redo_if(body);
2786
+ return [ this[0], name, args.slice(), body ];
2787
+ };
2788
+
2789
+ function redo_if_block(statements) {
2790
+ var out = [ this[0] ];
2791
+ if (statements != null)
2792
+ out.push(redo_if(statements));
2793
+ return out;
2794
+ };
2795
+
2796
+ return w.with_walkers({
2797
+ "defun": redo_if_lambda,
2798
+ "function": redo_if_lambda,
2799
+ "block": redo_if_block,
2800
+ "splice": redo_if_block,
2801
+ "toplevel": function(statements) {
2802
+ return [ this[0], redo_if(statements) ];
2803
+ },
2804
+ "try": function(t, c, f) {
2805
+ return [
2806
+ this[0],
2807
+ redo_if(t),
2808
+ c != null ? [ c[0], redo_if(c[1]) ] : null,
2809
+ f != null ? redo_if(f) : null
2810
+ ];
2811
+ },
2812
+ "with": function(expr, block) {
2813
+ return [ this[0], walk(expr), redo_if(block) ];
2814
+ }
2815
+ }, function() {
2816
+ return walk(ast);
2817
+ });
2818
+ };
2819
+
2820
+ function ast_squeeze(ast, options) {
2821
+ options = defaults(options, {
2822
+ make_seqs : true,
2823
+ dead_code : true,
2824
+ keep_comps : true,
2825
+ no_warnings : false
2826
+ });
2827
+
2828
+ var w = ast_walker(), walk = w.walk, scope;
2829
+
2830
+ function negate(c) {
2831
+ var not_c = [ "unary-prefix", "!", c ];
2832
+ switch (c[0]) {
2833
+ case "unary-prefix":
2834
+ return c[1] == "!" && boolean_expr(c[2]) ? c[2] : not_c;
2835
+ case "seq":
2836
+ c = slice(c);
2837
+ c[c.length - 1] = negate(c[c.length - 1]);
2838
+ return c;
2839
+ case "conditional":
2840
+ return best_of(not_c, [ "conditional", c[1], negate(c[2]), negate(c[3]) ]);
2841
+ case "binary":
2842
+ var op = c[1], left = c[2], right = c[3];
2843
+ if (!options.keep_comps) switch (op) {
2844
+ case "<=" : return [ "binary", ">", left, right ];
2845
+ case "<" : return [ "binary", ">=", left, right ];
2846
+ case ">=" : return [ "binary", "<", left, right ];
2847
+ case ">" : return [ "binary", "<=", left, right ];
2848
+ }
2849
+ switch (op) {
2850
+ case "==" : return [ "binary", "!=", left, right ];
2851
+ case "!=" : return [ "binary", "==", left, right ];
2852
+ case "===" : return [ "binary", "!==", left, right ];
2853
+ case "!==" : return [ "binary", "===", left, right ];
2854
+ case "&&" : return best_of(not_c, [ "binary", "||", negate(left), negate(right) ]);
2855
+ case "||" : return best_of(not_c, [ "binary", "&&", negate(left), negate(right) ]);
2856
+ }
2857
+ break;
2858
+ }
2859
+ return not_c;
2860
+ };
2861
+
2862
+ function with_scope(s, cont) {
2863
+ var _scope = scope;
2864
+ scope = s;
2865
+ var ret = cont();
2866
+ ret.scope = s;
2867
+ scope = _scope;
2868
+ return ret;
2869
+ };
2870
+
2871
+ function rmblock(block) {
2872
+ if (block != null && block[0] == "block" && block[1]) {
2873
+ if (block[1].length == 1)
2874
+ block = block[1][0];
2875
+ else if (block[1].length == 0)
2876
+ block = [ "block" ];
2877
+ }
2878
+ return block;
2879
+ };
2880
+
2881
+ function _lambda(name, args, body) {
2882
+ var is_defun = this[0] == "defun";
2883
+ body = with_scope(body.scope, function(){
2884
+ var ret = tighten(MAP(body, walk), "lambda");
2885
+ if (!is_defun && name && !HOP(scope.refs, name))
2886
+ name = null;
2887
+ return ret;
2888
+ });
2889
+ return [ this[0], name, args, body ];
2890
+ };
2891
+
2892
+ // we get here for blocks that have been already transformed.
2893
+ // this function does a few things:
2894
+ // 1. discard useless blocks
2895
+ // 2. join consecutive var declarations
2896
+ // 3. remove obviously dead code
2897
+ // 4. transform consecutive statements using the comma operator
2898
+ // 5. if block_type == "lambda" and it detects constructs like if(foo) return ... - rewrite like if (!foo) { ... }
2899
+ function tighten(statements, block_type) {
2900
+ statements = statements.reduce(function(a, stat){
2901
+ if (stat[0] == "block") {
2902
+ if (stat[1]) {
2903
+ a.push.apply(a, stat[1]);
2904
+ }
2905
+ } else {
2906
+ a.push(stat);
2907
+ }
2908
+ return a;
2909
+ }, []);
2910
+
2911
+ statements = (function(a, prev){
2912
+ statements.forEach(function(cur){
2913
+ if (prev && ((cur[0] == "var" && prev[0] == "var") ||
2914
+ (cur[0] == "const" && prev[0] == "const"))) {
2915
+ prev[1] = prev[1].concat(cur[1]);
2916
+ } else {
2917
+ a.push(cur);
2918
+ prev = cur;
2919
+ }
2920
+ });
2921
+ return a;
2922
+ })([]);
2923
+
2924
+ if (options.dead_code) statements = (function(a, has_quit){
2925
+ statements.forEach(function(st){
2926
+ if (has_quit) {
2927
+ if (member(st[0], [ "function", "defun" , "var", "const" ])) {
2928
+ a.push(st);
2929
+ }
2930
+ else if (!options.no_warnings)
2931
+ warn_unreachable(st);
2932
+ }
2933
+ else {
2934
+ a.push(st);
2935
+ if (member(st[0], [ "return", "throw", "break", "continue" ]))
2936
+ has_quit = true;
2937
+ }
2938
+ });
2939
+ return a;
2940
+ })([]);
2941
+
2942
+ if (options.make_seqs) statements = (function(a, prev) {
2943
+ statements.forEach(function(cur){
2944
+ if (prev && prev[0] == "stat" && cur[0] == "stat") {
2945
+ prev[1] = [ "seq", prev[1], cur[1] ];
2946
+ } else {
2947
+ a.push(cur);
2948
+ prev = cur;
2949
+ }
2950
+ });
2951
+ return a;
2952
+ })([]);
2953
+
2954
+ if (block_type == "lambda") statements = (function(i, a, stat){
2955
+ while (i < statements.length) {
2956
+ stat = statements[i++];
2957
+ if (stat[0] == "if" && !stat[3]) {
2958
+ if (stat[2][0] == "return" && stat[2][1] == null) {
2959
+ a.push(make_if(negate(stat[1]), [ "block", statements.slice(i) ]));
2960
+ break;
2961
+ }
2962
+ var last = last_stat(stat[2]);
2963
+ if (last[0] == "return" && last[1] == null) {
2964
+ a.push(make_if(stat[1], [ "block", stat[2][1].slice(0, -1) ], [ "block", statements.slice(i) ]));
2965
+ break;
2966
+ }
2967
+ }
2968
+ a.push(stat);
2969
+ }
2970
+ return a;
2971
+ })(0, []);
2972
+
2973
+ return statements;
2974
+ };
2975
+
2976
+ function make_if(c, t, e) {
2977
+ return when_constant(c, function(ast, val){
2978
+ if (val) {
2979
+ warn_unreachable(e);
2980
+ return t;
2981
+ } else {
2982
+ warn_unreachable(t);
2983
+ return e;
2984
+ }
2985
+ }, function() {
2986
+ return make_real_if(c, t, e);
2987
+ });
2988
+ };
2989
+
2990
+ function make_real_if(c, t, e) {
2991
+ c = walk(c);
2992
+ t = walk(t);
2993
+ e = walk(e);
2994
+
2995
+ if (empty(t)) {
2996
+ c = negate(c);
2997
+ t = e;
2998
+ e = null;
2999
+ } else if (empty(e)) {
3000
+ e = null;
3001
+ } else {
3002
+ // if we have both else and then, maybe it makes sense to switch them?
3003
+ (function(){
3004
+ var a = gen_code(c);
3005
+ var n = negate(c);
3006
+ var b = gen_code(n);
3007
+ if (b.length < a.length) {
3008
+ var tmp = t;
3009
+ t = e;
3010
+ e = tmp;
3011
+ c = n;
3012
+ }
3013
+ })();
3014
+ }
3015
+ if (empty(e) && empty(t))
3016
+ return [ "stat", c ];
3017
+ var ret = [ "if", c, t, e ];
3018
+ if (t[0] == "if" && empty(t[3]) && empty(e)) {
3019
+ ret = best_of(ret, walk([ "if", [ "binary", "&&", c, t[1] ], t[2] ]));
3020
+ }
3021
+ else if (t[0] == "stat") {
3022
+ if (e) {
3023
+ if (e[0] == "stat") {
3024
+ ret = best_of(ret, [ "stat", make_conditional(c, t[1], e[1]) ]);
3025
+ }
3026
+ }
3027
+ else {
3028
+ ret = best_of(ret, [ "stat", make_conditional(c, t[1]) ]);
3029
+ }
3030
+ }
3031
+ else if (e && t[0] == e[0] && (t[0] == "return" || t[0] == "throw") && t[1] && e[1]) {
3032
+ ret = best_of(ret, [ t[0], make_conditional(c, t[1], e[1] ) ]);
3033
+ }
3034
+ else if (e && aborts(t)) {
3035
+ ret = [ [ "if", c, t ] ];
3036
+ if (e[0] == "block") {
3037
+ if (e[1]) ret = ret.concat(e[1]);
3038
+ }
3039
+ else {
3040
+ ret.push(e);
3041
+ }
3042
+ ret = walk([ "block", ret ]);
3043
+ }
3044
+ else if (t && aborts(e)) {
3045
+ ret = [ [ "if", negate(c), e ] ];
3046
+ if (t[0] == "block") {
3047
+ if (t[1]) ret = ret.concat(t[1]);
3048
+ } else {
3049
+ ret.push(t);
3050
+ }
3051
+ ret = walk([ "block", ret ]);
3052
+ }
3053
+ return ret;
3054
+ };
3055
+
3056
+ function _do_while(cond, body) {
3057
+ return when_constant(cond, function(cond, val){
3058
+ if (!val) {
3059
+ warn_unreachable(body);
3060
+ return [ "block" ];
3061
+ } else {
3062
+ return [ "for", null, null, null, walk(body) ];
3063
+ }
3064
+ });
3065
+ };
3066
+
3067
+ ast = prepare_ifs(ast);
3068
+ ast = ast_add_scope(ast);
3069
+
3070
+ return w.with_walkers({
3071
+ "sub": function(expr, subscript) {
3072
+ if (subscript[0] == "string") {
3073
+ var name = subscript[1];
3074
+ if (is_identifier(name))
3075
+ return [ "dot", walk(expr), name ];
3076
+ else if (/^[1-9][0-9]*$/.test(name) || name === "0")
3077
+ return [ "sub", walk(expr), [ "num", parseInt(name, 10) ] ];
3078
+ }
3079
+ },
3080
+ "if": make_if,
3081
+ "toplevel": function(body) {
3082
+ return [ "toplevel", with_scope(this.scope, function(){
3083
+ return tighten(MAP(body, walk));
3084
+ }) ];
3085
+ },
3086
+ "switch": function(expr, body) {
3087
+ var last = body.length - 1;
3088
+ return [ "switch", walk(expr), MAP(body, function(branch, i){
3089
+ var block = tighten(MAP(branch[1], walk));
3090
+ if (i == last && block.length > 0) {
3091
+ var node = block[block.length - 1];
3092
+ if (node[0] == "break" && !node[1])
3093
+ block.pop();
3094
+ }
3095
+ return [ branch[0] ? walk(branch[0]) : null, block ];
3096
+ }) ];
3097
+ },
3098
+ "function": _lambda,
3099
+ "defun": _lambda,
3100
+ "block": function(body) {
3101
+ if (body) return rmblock([ "block", tighten(MAP(body, walk)) ]);
3102
+ },
3103
+ "binary": function(op, left, right) {
3104
+ return when_constant([ "binary", op, walk(left), walk(right) ], function yes(c){
3105
+ return best_of(walk(c), this);
3106
+ }, function no() {
3107
+ return this;
3108
+ });
3109
+ },
3110
+ "conditional": function(c, t, e) {
3111
+ return make_conditional(walk(c), walk(t), walk(e));
3112
+ },
3113
+ "try": function(t, c, f) {
3114
+ return [
3115
+ "try",
3116
+ tighten(MAP(t, walk)),
3117
+ c != null ? [ c[0], tighten(MAP(c[1], walk)) ] : null,
3118
+ f != null ? tighten(MAP(f, walk)) : null
3119
+ ];
3120
+ },
3121
+ "unary-prefix": function(op, expr) {
3122
+ expr = walk(expr);
3123
+ var ret = [ "unary-prefix", op, expr ];
3124
+ if (op == "!")
3125
+ ret = best_of(ret, negate(expr));
3126
+ return when_constant(ret, function(ast, val){
3127
+ return walk(ast); // it's either true or false, so minifies to !0 or !1
3128
+ }, function() { return ret });
3129
+ },
3130
+ "name": function(name) {
3131
+ switch (name) {
3132
+ case "true": return [ "unary-prefix", "!", [ "num", 0 ]];
3133
+ case "false": return [ "unary-prefix", "!", [ "num", 1 ]];
3134
+ }
3135
+ },
3136
+ "new": function(ctor, args) {
3137
+ if (ctor[0] == "name" && ctor[1] == "Array" && !scope.has("Array")) {
3138
+ if (args.length != 1) {
3139
+ return [ "array", args ];
3140
+ } else {
3141
+ return [ "call", [ "name", "Array" ], args ];
3142
+ }
3143
+ }
3144
+ },
3145
+ "call": function(expr, args) {
3146
+ if (expr[0] == "name" && expr[1] == "Array" && args.length != 1 && !scope.has("Array")) {
3147
+ return [ "array", args ];
3148
+ }
3149
+ },
3150
+ "while": _do_while
3151
+ }, function() {
3152
+ return walk(ast);
3153
+ });
3154
+ };
3155
+
3156
+ /* -----[ re-generate code from the AST ]----- */
3157
+
3158
+ var DOT_CALL_NO_PARENS = jsp.array_to_hash([
3159
+ "name",
3160
+ "array",
3161
+ "object",
3162
+ "string",
3163
+ "dot",
3164
+ "sub",
3165
+ "call",
3166
+ "regexp"
3167
+ ]);
3168
+
3169
+ function make_string(str, ascii_only) {
3170
+ var dq = 0, sq = 0;
3171
+ str = str.replace(/[\\\b\f\n\r\t\x22\x27\u2028\u2029]/g, function(s){
3172
+ switch (s) {
3173
+ case "\\": return "\\\\";
3174
+ case "\b": return "\\b";
3175
+ case "\f": return "\\f";
3176
+ case "\n": return "\\n";
3177
+ case "\r": return "\\r";
3178
+ case "\t": return "\\t";
3179
+ case "\u2028": return "\\u2028";
3180
+ case "\u2029": return "\\u2029";
3181
+ case '"': ++dq; return '"';
3182
+ case "'": ++sq; return "'";
3183
+ }
3184
+ return s;
3185
+ });
3186
+ if (ascii_only) str = to_ascii(str);
3187
+ if (dq > sq) return "'" + str.replace(/\x27/g, "\\'") + "'";
3188
+ else return '"' + str.replace(/\x22/g, '\\"') + '"';
3189
+ };
3190
+
3191
+ function to_ascii(str) {
3192
+ return str.replace(/[\u0080-\uffff]/g, function(ch) {
3193
+ var code = ch.charCodeAt(0).toString(16);
3194
+ while (code.length < 4) code = "0" + code;
3195
+ return "\\u" + code;
3196
+ });
3197
+ };
3198
+
3199
+ var SPLICE_NEEDS_BRACKETS = jsp.array_to_hash([ "if", "while", "do", "for", "for-in", "with" ]);
3200
+
3201
+ function gen_code(ast, options) {
3202
+ options = defaults(options, {
3203
+ indent_start : 0,
3204
+ indent_level : 4,
3205
+ quote_keys : false,
3206
+ space_colon : false,
3207
+ beautify : false,
3208
+ ascii_only : false
3209
+ });
3210
+ var beautify = !!options.beautify;
3211
+ var indentation = 0,
3212
+ newline = beautify ? "\n" : "",
3213
+ space = beautify ? " " : "";
3214
+
3215
+ function encode_string(str) {
3216
+ return make_string(str, options.ascii_only);
3217
+ };
3218
+
3219
+ function make_name(name) {
3220
+ name = name.toString();
3221
+ if (options.ascii_only)
3222
+ name = to_ascii(name);
3223
+ return name;
3224
+ };
3225
+
3226
+ function indent(line) {
3227
+ if (line == null)
3228
+ line = "";
3229
+ if (beautify)
3230
+ line = repeat_string(" ", options.indent_start + indentation * options.indent_level) + line;
3231
+ return line;
3232
+ };
3233
+
3234
+ function with_indent(cont, incr) {
3235
+ if (incr == null) incr = 1;
3236
+ indentation += incr;
3237
+ try { return cont.apply(null, slice(arguments, 1)); }
3238
+ finally { indentation -= incr; }
3239
+ };
3240
+
3241
+ function add_spaces(a) {
3242
+ if (beautify)
3243
+ return a.join(" ");
3244
+ var b = [];
3245
+ for (var i = 0; i < a.length; ++i) {
3246
+ var next = a[i + 1];
3247
+ b.push(a[i]);
3248
+ if (next &&
3249
+ ((/[a-z0-9_\x24]$/i.test(a[i].toString()) && /^[a-z0-9_\x24]/i.test(next.toString())) ||
3250
+ (/[\+\-]$/.test(a[i].toString()) && /^[\+\-]/.test(next.toString())))) {
3251
+ b.push(" ");
3252
+ }
3253
+ }
3254
+ return b.join("");
3255
+ };
3256
+
3257
+ function add_commas(a) {
3258
+ return a.join("," + space);
3259
+ };
3260
+
3261
+ function parenthesize(expr) {
3262
+ var gen = make(expr);
3263
+ for (var i = 1; i < arguments.length; ++i) {
3264
+ var el = arguments[i];
3265
+ if ((el instanceof Function && el(expr)) || expr[0] == el)
3266
+ return "(" + gen + ")";
3267
+ }
3268
+ return gen;
3269
+ };
3270
+
3271
+ function best_of(a) {
3272
+ if (a.length == 1) {
3273
+ return a[0];
3274
+ }
3275
+ if (a.length == 2) {
3276
+ var b = a[1];
3277
+ a = a[0];
3278
+ return a.length <= b.length ? a : b;
3279
+ }
3280
+ return best_of([ a[0], best_of(a.slice(1)) ]);
3281
+ };
3282
+
3283
+ function needs_parens(expr) {
3284
+ if (expr[0] == "function" || expr[0] == "object") {
3285
+ // dot/call on a literal function requires the
3286
+ // function literal itself to be parenthesized
3287
+ // only if it's the first "thing" in a
3288
+ // statement. This means that the parent is
3289
+ // "stat", but it could also be a "seq" and
3290
+ // we're the first in this "seq" and the
3291
+ // parent is "stat", and so on. Messy stuff,
3292
+ // but it worths the trouble.
3293
+ var a = slice($stack), self = a.pop(), p = a.pop();
3294
+ while (p) {
3295
+ if (p[0] == "stat") return true;
3296
+ if (((p[0] == "seq" || p[0] == "call" || p[0] == "dot" || p[0] == "sub" || p[0] == "conditional") && p[1] === self) ||
3297
+ ((p[0] == "binary" || p[0] == "assign" || p[0] == "unary-postfix") && p[2] === self)) {
3298
+ self = p;
3299
+ p = a.pop();
3300
+ } else {
3301
+ return false;
3302
+ }
3303
+ }
3304
+ }
3305
+ return !HOP(DOT_CALL_NO_PARENS, expr[0]);
3306
+ };
3307
+
3308
+ function make_num(num) {
3309
+ var str = num.toString(10), a = [ str.replace(/^0\./, ".") ], m;
3310
+ if (Math.floor(num) === num) {
3311
+ a.push("0x" + num.toString(16).toLowerCase(), // probably pointless
3312
+ "0" + num.toString(8)); // same.
3313
+ if ((m = /^(.*?)(0+)$/.exec(num))) {
3314
+ a.push(m[1] + "e" + m[2].length);
3315
+ }
3316
+ } else if ((m = /^0?\.(0+)(.*)$/.exec(num))) {
3317
+ a.push(m[2] + "e-" + (m[1].length + m[2].length),
3318
+ str.substr(str.indexOf(".")));
3319
+ }
3320
+ return best_of(a);
3321
+ };
3322
+
3323
+ var generators = {
3324
+ "string": encode_string,
3325
+ "num": make_num,
3326
+ "name": make_name,
3327
+ "toplevel": function(statements) {
3328
+ return make_block_statements(statements)
3329
+ .join(newline + newline);
3330
+ },
3331
+ "splice": function(statements) {
3332
+ var parent = $stack[$stack.length - 2][0];
3333
+ if (HOP(SPLICE_NEEDS_BRACKETS, parent)) {
3334
+ // we need block brackets in this case
3335
+ return make_block.apply(this, arguments);
3336
+ } else {
3337
+ return MAP(make_block_statements(statements, true),
3338
+ function(line, i) {
3339
+ // the first line is already indented
3340
+ return i > 0 ? indent(line) : line;
3341
+ }).join(newline);
3342
+ }
3343
+ },
3344
+ "block": make_block,
3345
+ "var": function(defs) {
3346
+ return "var " + add_commas(MAP(defs, make_1vardef)) + ";";
3347
+ },
3348
+ "const": function(defs) {
3349
+ return "const " + add_commas(MAP(defs, make_1vardef)) + ";";
3350
+ },
3351
+ "try": function(tr, ca, fi) {
3352
+ var out = [ "try", make_block(tr) ];
3353
+ if (ca) out.push("catch", "(" + ca[0] + ")", make_block(ca[1]));
3354
+ if (fi) out.push("finally", make_block(fi));
3355
+ return add_spaces(out);
3356
+ },
3357
+ "throw": function(expr) {
3358
+ return add_spaces([ "throw", make(expr) ]) + ";";
3359
+ },
3360
+ "new": function(ctor, args) {
3361
+ args = args.length > 0 ? "(" + add_commas(MAP(args, make)) + ")" : "";
3362
+ return add_spaces([ "new", parenthesize(ctor, "seq", "binary", "conditional", "assign", function(expr){
3363
+ var w = ast_walker(), has_call = {};
3364
+ try {
3365
+ w.with_walkers({
3366
+ "call": function() { throw has_call },
3367
+ "function": function() { return this }
3368
+ }, function(){
3369
+ w.walk(expr);
3370
+ });
3371
+ } catch(ex) {
3372
+ if (ex === has_call)
3373
+ return true;
3374
+ throw ex;
3375
+ }
3376
+ }) + args ]);
3377
+ },
3378
+ "switch": function(expr, body) {
3379
+ return add_spaces([ "switch", "(" + make(expr) + ")", make_switch_block(body) ]);
3380
+ },
3381
+ "break": function(label) {
3382
+ var out = "break";
3383
+ if (label != null)
3384
+ out += " " + make_name(label);
3385
+ return out + ";";
3386
+ },
3387
+ "continue": function(label) {
3388
+ var out = "continue";
3389
+ if (label != null)
3390
+ out += " " + make_name(label);
3391
+ return out + ";";
3392
+ },
3393
+ "conditional": function(co, th, el) {
3394
+ return add_spaces([ parenthesize(co, "assign", "seq", "conditional"), "?",
3395
+ parenthesize(th, "seq"), ":",
3396
+ parenthesize(el, "seq") ]);
3397
+ },
3398
+ "assign": function(op, lvalue, rvalue) {
3399
+ if (op && op !== true) op += "=";
3400
+ else op = "=";
3401
+ return add_spaces([ make(lvalue), op, parenthesize(rvalue, "seq") ]);
3402
+ },
3403
+ "dot": function(expr) {
3404
+ var out = make(expr), i = 1;
3405
+ if (expr[0] == "num") {
3406
+ if (!/\./.test(expr[1]))
3407
+ out += ".";
3408
+ } else if (needs_parens(expr))
3409
+ out = "(" + out + ")";
3410
+ while (i < arguments.length)
3411
+ out += "." + make_name(arguments[i++]);
3412
+ return out;
3413
+ },
3414
+ "call": function(func, args) {
3415
+ var f = make(func);
3416
+ if (needs_parens(func))
3417
+ f = "(" + f + ")";
3418
+ return f + "(" + add_commas(MAP(args, function(expr){
3419
+ return parenthesize(expr, "seq");
3420
+ })) + ")";
3421
+ },
3422
+ "function": make_function,
3423
+ "defun": make_function,
3424
+ "if": function(co, th, el) {
3425
+ var out = [ "if", "(" + make(co) + ")", el ? make_then(th) : make(th) ];
3426
+ if (el) {
3427
+ out.push("else", make(el));
3428
+ }
3429
+ return add_spaces(out);
3430
+ },
3431
+ "for": function(init, cond, step, block) {
3432
+ var out = [ "for" ];
3433
+ init = (init != null ? make(init) : "").replace(/;*\s*$/, ";" + space);
3434
+ cond = (cond != null ? make(cond) : "").replace(/;*\s*$/, ";" + space);
3435
+ step = (step != null ? make(step) : "").replace(/;*\s*$/, "");
3436
+ var args = init + cond + step;
3437
+ if (args == "; ; ") args = ";;";
3438
+ out.push("(" + args + ")", make(block));
3439
+ return add_spaces(out);
3440
+ },
3441
+ "for-in": function(vvar, key, hash, block) {
3442
+ return add_spaces([ "for", "(" +
3443
+ (vvar ? make(vvar).replace(/;+$/, "") : make(key)),
3444
+ "in",
3445
+ make(hash) + ")", make(block) ]);
3446
+ },
3447
+ "while": function(condition, block) {
3448
+ return add_spaces([ "while", "(" + make(condition) + ")", make(block) ]);
3449
+ },
3450
+ "do": function(condition, block) {
3451
+ return add_spaces([ "do", make(block), "while", "(" + make(condition) + ")" ]) + ";";
3452
+ },
3453
+ "return": function(expr) {
3454
+ var out = [ "return" ];
3455
+ if (expr != null) out.push(make(expr));
3456
+ return add_spaces(out) + ";";
3457
+ },
3458
+ "binary": function(operator, lvalue, rvalue) {
3459
+ var left = make(lvalue), right = make(rvalue);
3460
+ // XXX: I'm pretty sure other cases will bite here.
3461
+ // we need to be smarter.
3462
+ // adding parens all the time is the safest bet.
3463
+ if (member(lvalue[0], [ "assign", "conditional", "seq" ]) ||
3464
+ lvalue[0] == "binary" && PRECEDENCE[operator] > PRECEDENCE[lvalue[1]]) {
3465
+ left = "(" + left + ")";
3466
+ }
3467
+ if (member(rvalue[0], [ "assign", "conditional", "seq" ]) ||
3468
+ rvalue[0] == "binary" && PRECEDENCE[operator] >= PRECEDENCE[rvalue[1]] &&
3469
+ !(rvalue[1] == operator && member(operator, [ "&&", "||", "*" ]))) {
3470
+ right = "(" + right + ")";
3471
+ }
3472
+ return add_spaces([ left, operator, right ]);
3473
+ },
3474
+ "unary-prefix": function(operator, expr) {
3475
+ var val = make(expr);
3476
+ if (!(expr[0] == "num" || (expr[0] == "unary-prefix" && !HOP(OPERATORS, operator + expr[1])) || !needs_parens(expr)))
3477
+ val = "(" + val + ")";
3478
+ return operator + (jsp.is_alphanumeric_char(operator.charAt(0)) ? " " : "") + val;
3479
+ },
3480
+ "unary-postfix": function(operator, expr) {
3481
+ var val = make(expr);
3482
+ if (!(expr[0] == "num" || (expr[0] == "unary-postfix" && !HOP(OPERATORS, operator + expr[1])) || !needs_parens(expr)))
3483
+ val = "(" + val + ")";
3484
+ return val + operator;
3485
+ },
3486
+ "sub": function(expr, subscript) {
3487
+ var hash = make(expr);
3488
+ if (needs_parens(expr))
3489
+ hash = "(" + hash + ")";
3490
+ return hash + "[" + make(subscript) + "]";
3491
+ },
3492
+ "object": function(props) {
3493
+ if (props.length == 0)
3494
+ return "{}";
3495
+ return "{" + newline + with_indent(function(){
3496
+ return MAP(props, function(p){
3497
+ if (p.length == 3) {
3498
+ // getter/setter. The name is in p[0], the arg.list in p[1][2], the
3499
+ // body in p[1][3] and type ("get" / "set") in p[2].
3500
+ return indent(make_function(p[0], p[1][2], p[1][3], p[2]));
3501
+ }
3502
+ var key = p[0], val = make(p[1]);
3503
+ if (options.quote_keys) {
3504
+ key = encode_string(key);
3505
+ } else if ((typeof key == "number" || !beautify && +key + "" == key)
3506
+ && parseFloat(key) >= 0) {
3507
+ key = make_num(+key);
3508
+ } else if (!is_identifier(key)) {
3509
+ key = encode_string(key);
3510
+ }
3511
+ return indent(add_spaces(beautify && options.space_colon
3512
+ ? [ key, ":", val ]
3513
+ : [ key + ":", val ]));
3514
+ }).join("," + newline);
3515
+ }) + newline + indent("}");
3516
+ },
3517
+ "regexp": function(rx, mods) {
3518
+ return "/" + rx + "/" + mods;
3519
+ },
3520
+ "array": function(elements) {
3521
+ if (elements.length == 0) return "[]";
3522
+ return add_spaces([ "[", add_commas(MAP(elements, function(el){
3523
+ if (!beautify && el[0] == "atom" && el[1] == "undefined") return "";
3524
+ return parenthesize(el, "seq");
3525
+ })), "]" ]);
3526
+ },
3527
+ "stat": function(stmt) {
3528
+ return make(stmt).replace(/;*\s*$/, ";");
3529
+ },
3530
+ "seq": function() {
3531
+ return add_commas(MAP(slice(arguments), make));
3532
+ },
3533
+ "label": function(name, block) {
3534
+ return add_spaces([ make_name(name), ":", make(block) ]);
3535
+ },
3536
+ "with": function(expr, block) {
3537
+ return add_spaces([ "with", "(" + make(expr) + ")", make(block) ]);
3538
+ },
3539
+ "atom": function(name) {
3540
+ return make_name(name);
3541
+ }
3542
+ };
3543
+
3544
+ // The squeezer replaces "block"-s that contain only a single
3545
+ // statement with the statement itself; technically, the AST
3546
+ // is correct, but this can create problems when we output an
3547
+ // IF having an ELSE clause where the THEN clause ends in an
3548
+ // IF *without* an ELSE block (then the outer ELSE would refer
3549
+ // to the inner IF). This function checks for this case and
3550
+ // adds the block brackets if needed.
3551
+ function make_then(th) {
3552
+ if (th[0] == "do") {
3553
+ // https://github.com/mishoo/UglifyJS/issues/#issue/57
3554
+ // IE croaks with "syntax error" on code like this:
3555
+ // if (foo) do ... while(cond); else ...
3556
+ // we need block brackets around do/while
3557
+ return make([ "block", [ th ]]);
3558
+ }
3559
+ var b = th;
3560
+ while (true) {
3561
+ var type = b[0];
3562
+ if (type == "if") {
3563
+ if (!b[3])
3564
+ // no else, we must add the block
3565
+ return make([ "block", [ th ]]);
3566
+ b = b[3];
3567
+ }
3568
+ else if (type == "while" || type == "do") b = b[2];
3569
+ else if (type == "for" || type == "for-in") b = b[4];
3570
+ else break;
3571
+ }
3572
+ return make(th);
3573
+ };
3574
+
3575
+ function make_function(name, args, body, keyword) {
3576
+ var out = keyword || "function";
3577
+ if (name) {
3578
+ out += " " + make_name(name);
3579
+ }
3580
+ out += "(" + add_commas(MAP(args, make_name)) + ")";
3581
+ return add_spaces([ out, make_block(body) ]);
3582
+ };
3583
+
3584
+ function make_block_statements(statements, noindent) {
3585
+ for (var a = [], last = statements.length - 1, i = 0; i <= last; ++i) {
3586
+ var stat = statements[i];
3587
+ var code = make(stat);
3588
+ if (code != ";") {
3589
+ if (!beautify && i == last) {
3590
+ if ((stat[0] == "while" && empty(stat[2])) ||
3591
+ (member(stat[0], [ "for", "for-in"] ) && empty(stat[4])) ||
3592
+ (stat[0] == "if" && empty(stat[2]) && !stat[3]) ||
3593
+ (stat[0] == "if" && stat[3] && empty(stat[3]))) {
3594
+ code = code.replace(/;*\s*$/, ";");
3595
+ } else {
3596
+ code = code.replace(/;+\s*$/, "");
3597
+ }
3598
+ }
3599
+ a.push(code);
3600
+ }
3601
+ }
3602
+ return noindent ? a : MAP(a, indent);
3603
+ };
3604
+
3605
+ function make_switch_block(body) {
3606
+ var n = body.length;
3607
+ if (n == 0) return "{}";
3608
+ return "{" + newline + MAP(body, function(branch, i){
3609
+ var has_body = branch[1].length > 0, code = with_indent(function(){
3610
+ return indent(branch[0]
3611
+ ? add_spaces([ "case", make(branch[0]) + ":" ])
3612
+ : "default:");
3613
+ }, 0.5) + (has_body ? newline + with_indent(function(){
3614
+ return make_block_statements(branch[1]).join(newline);
3615
+ }) : "");
3616
+ if (!beautify && has_body && i < n - 1)
3617
+ code += ";";
3618
+ return code;
3619
+ }).join(newline) + newline + indent("}");
3620
+ };
3621
+
3622
+ function make_block(statements) {
3623
+ if (!statements) return ";";
3624
+ if (statements.length == 0) return "{}";
3625
+ return "{" + newline + with_indent(function(){
3626
+ return make_block_statements(statements).join(newline);
3627
+ }) + newline + indent("}");
3628
+ };
3629
+
3630
+ function make_1vardef(def) {
3631
+ var name = def[0], val = def[1];
3632
+ if (val != null)
3633
+ name = add_spaces([ make_name(name), "=", parenthesize(val, "seq") ]);
3634
+ return name;
3635
+ };
3636
+
3637
+ var $stack = [];
3638
+
3639
+ function make(node) {
3640
+ var type = node[0];
3641
+ var gen = generators[type];
3642
+ if (!gen)
3643
+ throw new Error("Can't find generator for \"" + type + "\"");
3644
+ $stack.push(node);
3645
+ var ret = gen.apply(type, node.slice(1));
3646
+ $stack.pop();
3647
+ return ret;
3648
+ };
3649
+
3650
+ return make(ast);
3651
+ };
3652
+
3653
+ function split_lines(code, max_line_length) {
3654
+ var splits = [ 0 ];
3655
+ jsp.parse(function(){
3656
+ var next_token = jsp.tokenizer(code);
3657
+ var last_split = 0;
3658
+ var prev_token;
3659
+ function current_length(tok) {
3660
+ return tok.pos - last_split;
3661
+ };
3662
+ function split_here(tok) {
3663
+ last_split = tok.pos;
3664
+ splits.push(last_split);
3665
+ };
3666
+ function custom(){
3667
+ var tok = next_token.apply(this, arguments);
3668
+ out: {
3669
+ if (prev_token) {
3670
+ if (prev_token.type == "keyword") break out;
3671
+ }
3672
+ if (current_length(tok) > max_line_length) {
3673
+ switch (tok.type) {
3674
+ case "keyword":
3675
+ case "atom":
3676
+ case "name":
3677
+ case "punc":
3678
+ split_here(tok);
3679
+ break out;
3680
+ }
3681
+ }
3682
+ }
3683
+ prev_token = tok;
3684
+ return tok;
3685
+ };
3686
+ custom.context = function() {
3687
+ return next_token.context.apply(this, arguments);
3688
+ };
3689
+ return custom;
3690
+ }());
3691
+ return splits.map(function(pos, i){
3692
+ return code.substring(pos, splits[i + 1] || code.length);
3693
+ }).join("\n");
3694
+ };
3695
+
3696
+ /* -----[ Utilities ]----- */
3697
+
3698
+ function repeat_string(str, i) {
3699
+ if (i <= 0) return "";
3700
+ if (i == 1) return str;
3701
+ var d = repeat_string(str, i >> 1);
3702
+ d += d;
3703
+ if (i & 1) d += str;
3704
+ return d;
3705
+ };
3706
+
3707
+ function defaults(args, defs) {
3708
+ var ret = {};
3709
+ if (args === true)
3710
+ args = {};
3711
+ for (var i in defs) if (HOP(defs, i)) {
3712
+ ret[i] = (args && HOP(args, i)) ? args[i] : defs[i];
3713
+ }
3714
+ return ret;
3715
+ };
3716
+
3717
+ function is_identifier(name) {
3718
+ return /^[a-z_$][a-z0-9_$]*$/i.test(name)
3719
+ && name != "this"
3720
+ && !HOP(jsp.KEYWORDS_ATOM, name)
3721
+ && !HOP(jsp.RESERVED_WORDS, name)
3722
+ && !HOP(jsp.KEYWORDS, name);
3723
+ };
3724
+
3725
+ function HOP(obj, prop) {
3726
+ return Object.prototype.hasOwnProperty.call(obj, prop);
3727
+ };
3728
+
3729
+ // some utilities
3730
+
3731
+ var MAP;
3732
+
3733
+ (function(){
3734
+ MAP = function(a, f, o) {
3735
+ var ret = [];
3736
+ for (var i = 0; i < a.length; ++i) {
3737
+ var val = f.call(o, a[i], i);
3738
+ if (val instanceof AtTop) ret.unshift(val.v);
3739
+ else ret.push(val);
3740
+ }
3741
+ return ret;
3742
+ };
3743
+ MAP.at_top = function(val) { return new AtTop(val) };
3744
+ function AtTop(val) { this.v = val };
3745
+ })();
3746
+
3747
+ /* -----[ Exports ]----- */
3748
+
3749
+ exports.ast_walker = ast_walker;
3750
+ exports.ast_mangle = ast_mangle;
3751
+ exports.ast_squeeze = ast_squeeze;
3752
+ exports.gen_code = gen_code;
3753
+ exports.ast_add_scope = ast_add_scope;
3754
+ exports.set_logger = function(logger) { warn = logger };
3755
+ exports.make_string = make_string;
3756
+ exports.split_lines = split_lines;
3757
+ exports.MAP = MAP;
3758
+
3759
+ // keep this last!
3760
+ exports.ast_squeeze_more = require("./squeeze-more").ast_squeeze_more;
3761
+ ;
3762
+ }).call(module.exports);
3763
+
3764
+ __require.modules["/node_modules/uglify-js/lib/process.js"]._cached = module.exports;
3765
+ return module.exports;
3766
+ };
3767
+
3768
+ require.modules["/node_modules/uglify-js/lib/squeeze-more.js"] = function () {
3769
+ var module = { exports : {} };
3770
+ var exports = module.exports;
3771
+ var __dirname = "/node_modules/uglify-js/lib";
3772
+ var __filename = "/node_modules/uglify-js/lib/squeeze-more.js";
3773
+
3774
+ var require = function (file) {
3775
+ return __require(file, "/node_modules/uglify-js/lib");
3776
+ };
3777
+
3778
+ require.resolve = function (file) {
3779
+ return __require.resolve(name, "/node_modules/uglify-js/lib");
3780
+ };
3781
+
3782
+ require.modules = __require.modules;
3783
+ __require.modules["/node_modules/uglify-js/lib/squeeze-more.js"]._cached = module.exports;
3784
+
3785
+ (function () {
3786
+ var jsp = require("./parse-js"),
3787
+ pro = require("./process"),
3788
+ slice = jsp.slice,
3789
+ member = jsp.member,
3790
+ PRECEDENCE = jsp.PRECEDENCE,
3791
+ OPERATORS = jsp.OPERATORS;
3792
+
3793
+ function ast_squeeze_more(ast) {
3794
+ var w = pro.ast_walker(), walk = w.walk;
3795
+ return w.with_walkers({
3796
+ "call": function(expr, args) {
3797
+ if (expr[0] == "dot" && expr[2] == "toString" && args.length == 0) {
3798
+ // foo.toString() ==> foo+""
3799
+ return [ "binary", "+", expr[1], [ "string", "" ]];
3800
+ }
3801
+ }
3802
+ }, function() {
3803
+ return walk(ast);
3804
+ });
3805
+ };
3806
+
3807
+ exports.ast_squeeze_more = ast_squeeze_more;
3808
+ ;
3809
+ }).call(module.exports);
3810
+
3811
+ __require.modules["/node_modules/uglify-js/lib/squeeze-more.js"]._cached = module.exports;
3812
+ return module.exports;
3813
+ };
3814
+
3815
+ require.modules["/node_modules/traverse/package.json"] = function () {
3816
+ var module = { exports : {} };
3817
+ var exports = module.exports;
3818
+ var __dirname = "/node_modules/traverse";
3819
+ var __filename = "/node_modules/traverse/package.json";
3820
+
3821
+ var require = function (file) {
3822
+ return __require(file, "/node_modules/traverse");
3823
+ };
3824
+
3825
+ require.resolve = function (file) {
3826
+ return __require.resolve(name, "/node_modules/traverse");
3827
+ };
3828
+
3829
+ require.modules = __require.modules;
3830
+ __require.modules["/node_modules/traverse/package.json"]._cached = module.exports;
3831
+
3832
+ (function () {
3833
+ module.exports = {"name":"traverse","version":"0.5.0","description":"Traverse and transform objects by visiting every node on a recursive walk","author":"James Halliday","license":"MIT/X11","main":"./index","repository":{"type":"git","url":"http://github.com/substack/js-traverse.git"},"devDependencies":{"expresso":"0.7.x"},"scripts":{"test":"expresso"}};
3834
+ }).call(module.exports);
3835
+
3836
+ __require.modules["/node_modules/traverse/package.json"]._cached = module.exports;
3837
+ return module.exports;
3838
+ };
3839
+
3840
+ require.modules["/node_modules/traverse/index.js"] = function () {
3841
+ var module = { exports : {} };
3842
+ var exports = module.exports;
3843
+ var __dirname = "/node_modules/traverse";
3844
+ var __filename = "/node_modules/traverse/index.js";
3845
+
3846
+ var require = function (file) {
3847
+ return __require(file, "/node_modules/traverse");
3848
+ };
3849
+
3850
+ require.resolve = function (file) {
3851
+ return __require.resolve(name, "/node_modules/traverse");
3852
+ };
3853
+
3854
+ require.modules = __require.modules;
3855
+ __require.modules["/node_modules/traverse/index.js"]._cached = module.exports;
3856
+
3857
+ (function () {
3858
+ module.exports = Traverse;
3859
+ function Traverse (obj) {
3860
+ if (!(this instanceof Traverse)) return new Traverse(obj);
3861
+ this.value = obj;
3862
+ }
3863
+
3864
+ Traverse.prototype.get = function (ps) {
3865
+ var node = this.value;
3866
+ for (var i = 0; i < ps.length; i ++) {
3867
+ var key = ps[i];
3868
+ if (!Object.hasOwnProperty.call(node, key)) {
3869
+ node = undefined;
3870
+ break;
3871
+ }
3872
+ node = node[key];
3873
+ }
3874
+ return node;
3875
+ };
3876
+
3877
+ Traverse.prototype.set = function (ps, value) {
3878
+ var node = this.value;
3879
+ for (var i = 0; i < ps.length - 1; i ++) {
3880
+ var key = ps[i];
3881
+ if (!Object.hasOwnProperty.call(node, key)) node[key] = {};
3882
+ node = node[key];
3883
+ }
3884
+ node[ps[i]] = value;
3885
+ return value;
3886
+ };
3887
+
3888
+ Traverse.prototype.map = function (cb) {
3889
+ return walk(this.value, cb, true);
3890
+ };
3891
+
3892
+ Traverse.prototype.forEach = function (cb) {
3893
+ this.value = walk(this.value, cb, false);
3894
+ return this.value;
3895
+ };
3896
+
3897
+ Traverse.prototype.reduce = function (cb, init) {
3898
+ var skip = arguments.length === 1;
3899
+ var acc = skip ? this.value : init;
3900
+ this.forEach(function (x) {
3901
+ if (!this.isRoot || !skip) {
3902
+ acc = cb.call(this, acc, x);
3903
+ }
3904
+ });
3905
+ return acc;
3906
+ };
3907
+
3908
+ Traverse.prototype.paths = function () {
3909
+ var acc = [];
3910
+ this.forEach(function (x) {
3911
+ acc.push(this.path);
3912
+ });
3913
+ return acc;
3914
+ };
3915
+
3916
+ Traverse.prototype.nodes = function () {
3917
+ var acc = [];
3918
+ this.forEach(function (x) {
3919
+ acc.push(this.node);
3920
+ });
3921
+ return acc;
3922
+ };
3923
+
3924
+ Traverse.prototype.clone = function () {
3925
+ var parents = [], nodes = [];
3926
+
3927
+ return (function clone (src) {
3928
+ for (var i = 0; i < parents.length; i++) {
3929
+ if (parents[i] === src) {
3930
+ return nodes[i];
3931
+ }
3932
+ }
3933
+
3934
+ if (typeof src === 'object' && src !== null) {
3935
+ var dst = copy(src);
3936
+
3937
+ parents.push(src);
3938
+ nodes.push(dst);
3939
+
3940
+ forEach(Object_keys(src), function (key) {
3941
+ dst[key] = clone(src[key]);
3942
+ });
3943
+
3944
+ parents.pop();
3945
+ nodes.pop();
3946
+ return dst;
3947
+ }
3948
+ else {
3949
+ return src;
3950
+ }
3951
+ })(this.value);
3952
+ };
3953
+
3954
+ function walk (root, cb, immutable) {
3955
+ var path = [];
3956
+ var parents = [];
3957
+ var alive = true;
3958
+
3959
+ return (function walker (node_) {
3960
+ var node = immutable ? copy(node_) : node_;
3961
+ var modifiers = {};
3962
+
3963
+ var keepGoing = true;
3964
+
3965
+ var state = {
3966
+ node : node,
3967
+ node_ : node_,
3968
+ path : [].concat(path),
3969
+ parent : parents[parents.length - 1],
3970
+ parents : parents,
3971
+ key : path.slice(-1)[0],
3972
+ isRoot : path.length === 0,
3973
+ level : path.length,
3974
+ circular : null,
3975
+ update : function (x, stopHere) {
3976
+ if (!state.isRoot) {
3977
+ state.parent.node[state.key] = x;
3978
+ }
3979
+ state.node = x;
3980
+ if (stopHere) keepGoing = false;
3981
+ },
3982
+ 'delete' : function () {
3983
+ delete state.parent.node[state.key];
3984
+ },
3985
+ remove : function () {
3986
+ if (Array_isArray(state.parent.node)) {
3987
+ state.parent.node.splice(state.key, 1);
3988
+ }
3989
+ else {
3990
+ delete state.parent.node[state.key];
3991
+ }
3992
+ },
3993
+ keys : null,
3994
+ before : function (f) { modifiers.before = f },
3995
+ after : function (f) { modifiers.after = f },
3996
+ pre : function (f) { modifiers.pre = f },
3997
+ post : function (f) { modifiers.post = f },
3998
+ stop : function () { alive = false },
3999
+ block : function () { keepGoing = false }
4000
+ };
4001
+
4002
+ if (!alive) return state;
4003
+
4004
+ if (typeof node === 'object' && node !== null) {
4005
+ state.keys = Object_keys(node);
4006
+
4007
+ state.isLeaf = state.keys.length == 0;
4008
+
4009
+ for (var i = 0; i < parents.length; i++) {
4010
+ if (parents[i].node_ === node_) {
4011
+ state.circular = parents[i];
4012
+ break;
4013
+ }
4014
+ }
4015
+ }
4016
+ else {
4017
+ state.isLeaf = true;
4018
+ }
4019
+
4020
+ state.notLeaf = !state.isLeaf;
4021
+ state.notRoot = !state.isRoot;
4022
+
4023
+ // use return values to update if defined
4024
+ var ret = cb.call(state, state.node);
4025
+ if (ret !== undefined && state.update) state.update(ret);
4026
+
4027
+ if (modifiers.before) modifiers.before.call(state, state.node);
4028
+
4029
+ if (!keepGoing) return state;
4030
+
4031
+ if (typeof state.node == 'object'
4032
+ && state.node !== null && !state.circular) {
4033
+ parents.push(state);
4034
+
4035
+ forEach(state.keys, function (key, i) {
4036
+ path.push(key);
4037
+
4038
+ if (modifiers.pre) modifiers.pre.call(state, state.node[key], key);
4039
+
4040
+ var child = walker(state.node[key]);
4041
+ if (immutable && Object.hasOwnProperty.call(state.node, key)) {
4042
+ state.node[key] = child.node;
4043
+ }
4044
+
4045
+ child.isLast = i == state.keys.length - 1;
4046
+ child.isFirst = i == 0;
4047
+
4048
+ if (modifiers.post) modifiers.post.call(state, child);
4049
+
4050
+ path.pop();
4051
+ });
4052
+ parents.pop();
4053
+ }
4054
+
4055
+ if (modifiers.after) modifiers.after.call(state, state.node);
4056
+
4057
+ return state;
4058
+ })(root).node;
4059
+ }
4060
+
4061
+ function copy (src) {
4062
+ if (typeof src === 'object' && src !== null) {
4063
+ var dst;
4064
+
4065
+ if (Array_isArray(src)) {
4066
+ dst = [];
4067
+ }
4068
+ else if (src instanceof Date) {
4069
+ dst = new Date(src);
4070
+ }
4071
+ else if (src instanceof Boolean) {
4072
+ dst = new Boolean(src);
4073
+ }
4074
+ else if (src instanceof Number) {
4075
+ dst = new Number(src);
4076
+ }
4077
+ else if (src instanceof String) {
4078
+ dst = new String(src);
4079
+ }
4080
+ else if (Object.create && Object.getPrototypeOf) {
4081
+ dst = Object.create(Object.getPrototypeOf(src));
4082
+ }
4083
+ else if (src.__proto__ || src.constructor.prototype) {
4084
+ var proto = src.__proto__ || src.constructor.prototype || {};
4085
+ var T = function () {};
4086
+ T.prototype = proto;
4087
+ dst = new T;
4088
+ if (!dst.__proto__) dst.__proto__ = proto;
4089
+ }
4090
+
4091
+ forEach(Object_keys(src), function (key) {
4092
+ dst[key] = src[key];
4093
+ });
4094
+ return dst;
4095
+ }
4096
+ else return src;
4097
+ }
4098
+
4099
+ var Object_keys = Object.keys || function keys (obj) {
4100
+ var res = [];
4101
+ for (var key in obj) res.push(key)
4102
+ return res;
4103
+ };
4104
+
4105
+ var Array_isArray = Array.isArray || function isArray (xs) {
4106
+ return Object.prototype.toString.call(xs) === '[object Array]';
4107
+ };
4108
+
4109
+ var forEach = function (xs, fn) {
4110
+ if (xs.forEach) return xs.forEach(fn)
4111
+ else for (var i = 0; i < xs.length; i++) {
4112
+ fn(xs[i], i, xs);
4113
+ }
4114
+ };
4115
+
4116
+ forEach(Object_keys(Traverse.prototype), function (key) {
4117
+ Traverse[key] = function (obj) {
4118
+ var args = [].slice.call(arguments, 1);
4119
+ var t = Traverse(obj);
4120
+ return t[key].apply(t, args);
4121
+ };
4122
+ });
4123
+ ;
4124
+ }).call(module.exports);
4125
+
4126
+ __require.modules["/node_modules/traverse/index.js"]._cached = module.exports;
4127
+ return module.exports;
4128
+ };
4129
+
4130
+ require.modules["vm"] = function () {
4131
+ var module = { exports : {} };
4132
+ var exports = module.exports;
4133
+ var __dirname = ".";
4134
+ var __filename = "vm";
4135
+
4136
+ var require = function (file) {
4137
+ return __require(file, ".");
4138
+ };
4139
+
4140
+ require.resolve = function (file) {
4141
+ return __require.resolve(name, ".");
4142
+ };
4143
+
4144
+ require.modules = __require.modules;
4145
+ __require.modules["vm"]._cached = module.exports;
4146
+
4147
+ (function () {
4148
+ var Object_keys = function (obj) {
4149
+ if (Object.keys) return Object.keys(obj)
4150
+ else {
4151
+ var res = [];
4152
+ for (var key in obj) res.push(key)
4153
+ return res;
4154
+ }
4155
+ };
4156
+
4157
+ var forEach = function (xs, fn) {
4158
+ if (xs.forEach) return xs.forEach(fn)
4159
+ else for (var i = 0; i < xs.length; i++) {
4160
+ fn(xs[i], i, xs);
4161
+ }
4162
+ };
4163
+
4164
+ var Script = exports.Script = function NodeScript (code) {
4165
+ if (!(this instanceof Script)) return new Script(code);
4166
+ this.code = code;
4167
+ };
4168
+
4169
+ var iframe = document.createElement('iframe');
4170
+ if (!iframe.style) iframe.style = {};
4171
+ iframe.style.display = 'none';
4172
+
4173
+ var iframeCapable = true; // until proven otherwise
4174
+ if (navigator.appName === 'Microsoft Internet Explorer') {
4175
+ var m = navigator.appVersion.match(/\bMSIE (\d+\.\d+);/);
4176
+ if (m && parseFloat(m[1]) < 9.0) {
4177
+ iframeCapable = false;
4178
+ }
4179
+ }
4180
+
4181
+ Script.prototype.runInNewContext = function (context) {
4182
+ if (!context) context = {};
4183
+
4184
+ if (!iframeCapable) {
4185
+ var keys = Object_keys(context);
4186
+ var args = [];
4187
+ for (var i = 0; i < keys.length; i++) {
4188
+ args.push(context[keys[i]]);
4189
+ }
4190
+
4191
+ var fn = new Function(keys, 'return ' + this.code);
4192
+ return fn.apply(null, args);
4193
+ }
4194
+
4195
+ document.body.appendChild(iframe);
4196
+
4197
+ var win = iframe.contentWindow
4198
+ || (window.frames && window.frames[window.frames.length - 1])
4199
+ || window[window.length - 1]
4200
+ ;
4201
+
4202
+ forEach(Object_keys(context), function (key) {
4203
+ win[key] = context[key];
4204
+ iframe[key] = context[key];
4205
+ });
4206
+
4207
+ if (win.eval) {
4208
+ // chrome and ff can just .eval()
4209
+ var res = win.eval(this.code);
4210
+ }
4211
+ else {
4212
+ // this works in IE9 but not anything newer
4213
+ iframe.setAttribute('src',
4214
+ 'javascript:__browserifyVmResult=(' + this.code + ')'
4215
+ );
4216
+ if ('__browserifyVmResult' in win) {
4217
+ var res = win.__browserifyVmResult;
4218
+ }
4219
+ else {
4220
+ iframeCapable = false;
4221
+ res = this.runInThisContext(context);
4222
+ }
4223
+ }
4224
+
4225
+ forEach(Object_keys(win), function (key) {
4226
+ context[key] = win[key];
4227
+ });
4228
+
4229
+ document.body.removeChild(iframe);
4230
+
4231
+ return res;
4232
+ };
4233
+
4234
+ Script.prototype.runInThisContext = function () {
4235
+ return eval(this.code); // maybe...
4236
+ };
4237
+
4238
+ Script.prototype.runInContext = function (context) {
4239
+ // seems to be just runInNewContext on magical context objects which are
4240
+ // otherwise indistinguishable from objects except plain old objects
4241
+ // for the parameter segfaults node
4242
+ return this.runInNewContext(context);
4243
+ };
4244
+
4245
+ forEach(Object_keys(Script.prototype), function (name) {
4246
+ exports[name] = Script[name] = function (code) {
4247
+ var s = Script(code);
4248
+ return s[name].apply(s, [].slice.call(arguments, 1));
4249
+ };
4250
+ });
4251
+
4252
+ exports.createScript = function (code) {
4253
+ return exports.Script(code);
4254
+ };
4255
+
4256
+ exports.createContext = Script.createContext = function (context) {
4257
+ // not really sure what this one does
4258
+ // seems to just make a shallow copy
4259
+ var copy = {};
4260
+ forEach(Object_keys(context), function (key) {
4261
+ copy[key] = context[key];
4262
+ });
4263
+ return copy;
4264
+ };
4265
+ ;
4266
+ }).call(module.exports);
4267
+
4268
+ __require.modules["vm"]._cached = module.exports;
4269
+ return module.exports;
4270
+ };
4271
+
4272
+ process.nextTick(function () {
4273
+ var module = { exports : {} };
4274
+ var exports = module.exports;
4275
+ var __dirname = "/";
4276
+ var __filename = "//home/substack/projects/node-burrito";
4277
+
4278
+ var require = function (file) {
4279
+ return __require(file, "/");
4280
+ };
4281
+ require.modules = __require.modules;
4282
+
4283
+ var burrito = require('./');
4284
+
4285
+ window.onload = function () {
4286
+ var res = burrito.microwave('Math.sin(2)', function (node) {
4287
+ if (node.name === 'num') node.wrap('Math.PI / undefined');
4288
+ });
4289
+
4290
+ document.body.innerHTML += res;
4291
+ };
4292
+
4293
+ if (document.readyState === 'complete') window.onload();
4294
+ ;
4295
+ });
4296
+