spade 0.0.8.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/.gitmodules +4 -4
- data/README.md +4 -0
- data/bin/spade +1 -1
- data/lib/spade.rb +0 -51
- data/lib/spade/cli.rb +10 -4
- data/lib/spade/version.rb +1 -1
- data/spade.gemspec +4 -21
- metadata +13 -482
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -40
- data/lib/index.js +0 -14
- data/lib/node/loader.js +0 -146
- data/lib/node/sandbox.js +0 -44
- data/lib/spade.js +0 -1130
- data/lib/spade/bundle.rb +0 -171
- data/lib/spade/cli/base.rb +0 -354
- data/lib/spade/cli/owner.rb +0 -45
- data/lib/spade/cli/project_generator.rb +0 -58
- data/lib/spade/compiler.rb +0 -34
- data/lib/spade/console.rb +0 -39
- data/lib/spade/context.rb +0 -116
- data/lib/spade/credentials.rb +0 -36
- data/lib/spade/dependency_installer.rb +0 -103
- data/lib/spade/environment.rb +0 -35
- data/lib/spade/exports.rb +0 -71
- data/lib/spade/installer.rb +0 -40
- data/lib/spade/loader.rb +0 -238
- data/lib/spade/local.rb +0 -46
- data/lib/spade/package.rb +0 -157
- data/lib/spade/reactor.rb +0 -159
- data/lib/spade/remote.rb +0 -99
- data/lib/spade/repository.rb +0 -18
- data/lib/spade/server.rb +0 -66
- data/lib/spade/shell.rb +0 -36
- data/lib/spade/templates/project/LICENSE +0 -19
- data/lib/spade/templates/project/README.md +0 -21
- data/lib/spade/templates/project/lib/main.js +0 -9
- data/lib/spade/templates/project/project.json +0 -31
- data/lib/spade/templates/project/tests/main-test.js +0 -8
- data/package.json +0 -27
- data/packages/coffee-script/.gitignore +0 -8
- data/packages/coffee-script/.npmignore +0 -11
- data/packages/coffee-script/Cakefile +0 -229
- data/packages/coffee-script/LICENSE +0 -22
- data/packages/coffee-script/README +0 -47
- data/packages/coffee-script/Rakefile +0 -78
- data/packages/coffee-script/bin/cake +0 -7
- data/packages/coffee-script/bin/coffee +0 -7
- data/packages/coffee-script/documentation/coffee/aliases.coffee +0 -11
- data/packages/coffee-script/documentation/coffee/array_comprehensions.coffee +0 -2
- data/packages/coffee-script/documentation/coffee/block_comment.coffee +0 -6
- data/packages/coffee-script/documentation/coffee/cake_tasks.coffee +0 -9
- data/packages/coffee-script/documentation/coffee/classes.coffee +0 -25
- data/packages/coffee-script/documentation/coffee/comparisons.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/conditionals.coffee +0 -13
- data/packages/coffee-script/documentation/coffee/default_args.coffee +0 -8
- data/packages/coffee-script/documentation/coffee/do.coffee +0 -4
- data/packages/coffee-script/documentation/coffee/embedded.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/existence.coffee +0 -10
- data/packages/coffee-script/documentation/coffee/expressions.coffee +0 -9
- data/packages/coffee-script/documentation/coffee/expressions_assignment.coffee +0 -3
- data/packages/coffee-script/documentation/coffee/expressions_comprehension.coffee +0 -3
- data/packages/coffee-script/documentation/coffee/expressions_try.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/fat_arrow.coffee +0 -6
- data/packages/coffee-script/documentation/coffee/functions.coffee +0 -2
- data/packages/coffee-script/documentation/coffee/heredocs.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/heregexes.coffee +0 -11
- data/packages/coffee-script/documentation/coffee/interpolation.coffee +0 -6
- data/packages/coffee-script/documentation/coffee/multiple_return_values.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/object_comprehensions.coffee +0 -4
- data/packages/coffee-script/documentation/coffee/object_extraction.coffee +0 -13
- data/packages/coffee-script/documentation/coffee/objects_and_arrays.coffee +0 -19
- data/packages/coffee-script/documentation/coffee/objects_reserved.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/overview.coffee +0 -28
- data/packages/coffee-script/documentation/coffee/parallel_assignment.coffee +0 -6
- data/packages/coffee-script/documentation/coffee/patterns_and_splats.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/prototypes.coffee +0 -3
- data/packages/coffee-script/documentation/coffee/range_comprehensions.coffee +0 -2
- data/packages/coffee-script/documentation/coffee/scope.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/slices.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/soaks.coffee +0 -1
- data/packages/coffee-script/documentation/coffee/splats.coffee +0 -27
- data/packages/coffee-script/documentation/coffee/splices.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/strings.coffee +0 -8
- data/packages/coffee-script/documentation/coffee/switch.coffee +0 -10
- data/packages/coffee-script/documentation/coffee/try.coffee +0 -8
- data/packages/coffee-script/documentation/coffee/while.coffee +0 -10
- data/packages/coffee-script/documentation/css/docs.css +0 -374
- data/packages/coffee-script/documentation/css/idle.css +0 -64
- data/packages/coffee-script/documentation/docs/browser.html +0 -25
- data/packages/coffee-script/documentation/docs/cake.html +0 -43
- data/packages/coffee-script/documentation/docs/coffee-script.html +0 -51
- data/packages/coffee-script/documentation/docs/command.html +0 -161
- data/packages/coffee-script/documentation/docs/docco.css +0 -186
- data/packages/coffee-script/documentation/docs/grammar.html +0 -399
- data/packages/coffee-script/documentation/docs/helpers.html +0 -31
- data/packages/coffee-script/documentation/docs/index.html +0 -3
- data/packages/coffee-script/documentation/docs/lexer.html +0 -490
- data/packages/coffee-script/documentation/docs/nodes.html +0 -1338
- data/packages/coffee-script/documentation/docs/optparse.html +0 -78
- data/packages/coffee-script/documentation/docs/repl.html +0 -24
- data/packages/coffee-script/documentation/docs/rewriter.html +0 -251
- data/packages/coffee-script/documentation/docs/scope.html +0 -54
- data/packages/coffee-script/documentation/docs/underscore.html +0 -295
- data/packages/coffee-script/documentation/images/background.png +0 -0
- data/packages/coffee-script/documentation/images/banding.png +0 -0
- data/packages/coffee-script/documentation/images/button_bg.png +0 -0
- data/packages/coffee-script/documentation/images/button_bg_dark.gif +0 -0
- data/packages/coffee-script/documentation/images/button_bg_green.gif +0 -0
- data/packages/coffee-script/documentation/images/favicon.ico +0 -0
- data/packages/coffee-script/documentation/images/logo.png +0 -0
- data/packages/coffee-script/documentation/images/screenshadow.png +0 -0
- data/packages/coffee-script/documentation/index.html.erb +0 -1607
- data/packages/coffee-script/documentation/js/aliases.js +0 -17
- data/packages/coffee-script/documentation/js/array_comprehensions.js +0 -6
- data/packages/coffee-script/documentation/js/block_comment.js +0 -4
- data/packages/coffee-script/documentation/js/cake_tasks.js +0 -10
- data/packages/coffee-script/documentation/js/classes.js +0 -44
- data/packages/coffee-script/documentation/js/comparisons.js +0 -3
- data/packages/coffee-script/documentation/js/conditionals.js +0 -12
- data/packages/coffee-script/documentation/js/default_args.js +0 -7
- data/packages/coffee-script/documentation/js/do.js +0 -10
- data/packages/coffee-script/documentation/js/embedded.js +0 -4
- data/packages/coffee-script/documentation/js/existence.js +0 -6
- data/packages/coffee-script/documentation/js/expressions.js +0 -15
- data/packages/coffee-script/documentation/js/expressions_assignment.js +0 -2
- data/packages/coffee-script/documentation/js/expressions_comprehension.js +0 -9
- data/packages/coffee-script/documentation/js/expressions_try.js +0 -7
- data/packages/coffee-script/documentation/js/fat_arrow.js +0 -9
- data/packages/coffee-script/documentation/js/functions.js +0 -7
- data/packages/coffee-script/documentation/js/heredocs.js +0 -2
- data/packages/coffee-script/documentation/js/heregexes.js +0 -2
- data/packages/coffee-script/documentation/js/interpolation.js +0 -4
- data/packages/coffee-script/documentation/js/multiple_return_values.js +0 -5
- data/packages/coffee-script/documentation/js/object_comprehensions.js +0 -15
- data/packages/coffee-script/documentation/js/object_extraction.js +0 -10
- data/packages/coffee-script/documentation/js/objects_and_arrays.js +0 -17
- data/packages/coffee-script/documentation/js/objects_reserved.js +0 -4
- data/packages/coffee-script/documentation/js/overview.js +0 -35
- data/packages/coffee-script/documentation/js/parallel_assignment.js +0 -4
- data/packages/coffee-script/documentation/js/patterns_and_splats.js +0 -4
- data/packages/coffee-script/documentation/js/prototypes.js +0 -3
- data/packages/coffee-script/documentation/js/range_comprehensions.js +0 -9
- data/packages/coffee-script/documentation/js/scope.js +0 -8
- data/packages/coffee-script/documentation/js/slices.js +0 -4
- data/packages/coffee-script/documentation/js/soaks.js +0 -2
- data/packages/coffee-script/documentation/js/splats.js +0 -15
- data/packages/coffee-script/documentation/js/splices.js +0 -3
- data/packages/coffee-script/documentation/js/strings.js +0 -2
- data/packages/coffee-script/documentation/js/switch.js +0 -23
- data/packages/coffee-script/documentation/js/try.js +0 -8
- data/packages/coffee-script/documentation/js/while.js +0 -18
- data/packages/coffee-script/documentation/vendor/jquery-1.4.2.js +0 -6240
- data/packages/coffee-script/examples/beautiful_code/binary_search.coffee +0 -16
- data/packages/coffee-script/examples/beautiful_code/quicksort_runtime.coffee +0 -13
- data/packages/coffee-script/examples/beautiful_code/regular_expression_matcher.coffee +0 -34
- data/packages/coffee-script/examples/blocks.coffee +0 -54
- data/packages/coffee-script/examples/code.coffee +0 -167
- data/packages/coffee-script/examples/computer_science/README +0 -4
- data/packages/coffee-script/examples/computer_science/binary_search.coffee +0 -25
- data/packages/coffee-script/examples/computer_science/bubble_sort.coffee +0 -11
- data/packages/coffee-script/examples/computer_science/linked_list.coffee +0 -108
- data/packages/coffee-script/examples/computer_science/luhn_algorithm.coffee +0 -36
- data/packages/coffee-script/examples/computer_science/merge_sort.coffee +0 -19
- data/packages/coffee-script/examples/computer_science/selection_sort.coffee +0 -23
- data/packages/coffee-script/examples/poignant.coffee +0 -181
- data/packages/coffee-script/examples/potion.coffee +0 -206
- data/packages/coffee-script/examples/underscore.coffee +0 -682
- data/packages/coffee-script/examples/web_server.coffee +0 -12
- data/packages/coffee-script/extras/EXTRAS +0 -7
- data/packages/coffee-script/extras/coffee-script.js +0 -8
- data/packages/coffee-script/extras/jsl.conf +0 -44
- data/packages/coffee-script/index.html +0 -2515
- data/packages/coffee-script/lib/browser.js +0 -52
- data/packages/coffee-script/lib/cake.js +0 -76
- data/packages/coffee-script/lib/coffee-script.js +0 -82
- data/packages/coffee-script/lib/command.js +0 -263
- data/packages/coffee-script/lib/grammar.js +0 -581
- data/packages/coffee-script/lib/helpers.js +0 -66
- data/packages/coffee-script/lib/index.js +0 -8
- data/packages/coffee-script/lib/lexer.js +0 -633
- data/packages/coffee-script/lib/nodes.js +0 -2165
- data/packages/coffee-script/lib/optparse.js +0 -111
- data/packages/coffee-script/lib/parser.js +0 -649
- data/packages/coffee-script/lib/repl.js +0 -42
- data/packages/coffee-script/lib/rewriter.js +0 -353
- data/packages/coffee-script/lib/scope.js +0 -120
- data/packages/coffee-script/lib/spade-format.js +0 -45
- data/packages/coffee-script/package.json +0 -26
- data/packages/coffee-script/src/browser.coffee +0 -43
- data/packages/coffee-script/src/cake.coffee +0 -69
- data/packages/coffee-script/src/coffee-script.coffee +0 -92
- data/packages/coffee-script/src/command.coffee +0 -214
- data/packages/coffee-script/src/grammar.coffee +0 -590
- data/packages/coffee-script/src/helpers.coffee +0 -56
- data/packages/coffee-script/src/index.coffee +0 -2
- data/packages/coffee-script/src/lexer.coffee +0 -653
- data/packages/coffee-script/src/nodes.coffee +0 -1754
- data/packages/coffee-script/src/optparse.coffee +0 -99
- data/packages/coffee-script/src/repl.coffee +0 -42
- data/packages/coffee-script/src/rewriter.coffee +0 -326
- data/packages/coffee-script/src/scope.coffee +0 -94
- data/packages/coffee-script/test/arguments.coffee +0 -127
- data/packages/coffee-script/test/assignment.coffee +0 -98
- data/packages/coffee-script/test/break.coffee +0 -18
- data/packages/coffee-script/test/comments.coffee +0 -201
- data/packages/coffee-script/test/conditionals.coffee +0 -181
- data/packages/coffee-script/test/exception_handling.coffee +0 -90
- data/packages/coffee-script/test/helpers.coffee +0 -96
- data/packages/coffee-script/test/importing.coffee +0 -18
- data/packages/coffee-script/test/operators.coffee +0 -225
- data/packages/coffee-script/test/ranges_slices_and_splices.coffee +0 -186
- data/packages/coffee-script/test/regular_expressions.coffee +0 -56
- data/packages/coffee-script/test/test.html +0 -123
- data/packages/coffee-script/test/test_chaining.coffee +0 -77
- data/packages/coffee-script/test/test_classes.coffee +0 -372
- data/packages/coffee-script/test/test_compilation.coffee +0 -26
- data/packages/coffee-script/test/test_comprehensions.coffee +0 -318
- data/packages/coffee-script/test/test_existence.coffee +0 -165
- data/packages/coffee-script/test/test_functions.coffee +0 -379
- data/packages/coffee-script/test/test_heredocs.coffee +0 -111
- data/packages/coffee-script/test/test_literals.coffee +0 -270
- data/packages/coffee-script/test/test_option_parser.coffee +0 -27
- data/packages/coffee-script/test/test_pattern_matching.coffee +0 -162
- data/packages/coffee-script/test/test_returns.coffee +0 -63
- data/packages/coffee-script/test/test_splats.coffee +0 -102
- data/packages/coffee-script/test/test_strings.coffee +0 -118
- data/packages/coffee-script/test/test_switch.coffee +0 -103
- data/packages/coffee-script/test/test_while.coffee +0 -71
- data/packages/ivory/LICENSE.txt +0 -1
- data/packages/ivory/README.md +0 -19
- data/packages/ivory/lib/buffer.js +0 -111
- data/packages/ivory/lib/events.js +0 -137
- data/packages/ivory/lib/fs.js +0 -266
- data/packages/ivory/lib/main.js +0 -13
- data/packages/ivory/lib/path.js +0 -158
- data/packages/ivory/lib/ruby/buffer.rb +0 -145
- data/packages/ivory/lib/ruby/constants.rb +0 -585
- data/packages/ivory/lib/ruby/events.rb +0 -32
- data/packages/ivory/lib/ruby/fs.rb +0 -245
- data/packages/ivory/lib/ruby/process.rb +0 -28
- data/packages/ivory/lib/stream.js +0 -115
- data/packages/ivory/lib/util.js +0 -414
- data/packages/ivory/package.json +0 -11
- data/packages/jquery/main.js +0 -7179
- data/packages/jquery/package.json +0 -10
- data/packages/json/lib/main.js +0 -14
- data/packages/json/package.json +0 -8
- data/packages/lproj/README.md +0 -77
- data/packages/lproj/examples/demo-app/en.lproj/localized.strings +0 -2
- data/packages/lproj/examples/demo-app/fr.lproj/localized.strings +0 -3
- data/packages/lproj/examples/demo-app/index.html +0 -8
- data/packages/lproj/examples/demo-app/lib/main.js +0 -7
- data/packages/lproj/examples/demo-app/package.json +0 -9
- data/packages/lproj/lib/main.js +0 -78
- data/packages/lproj/lib/strings-format.js +0 -6
- data/packages/lproj/package.json +0 -9
- data/packages/optparse/README.md +0 -161
- data/packages/optparse/TODO +0 -1
- data/packages/optparse/examples/browser-test.html +0 -75
- data/packages/optparse/examples/nodejs-test.js +0 -90
- data/packages/optparse/lib/optparse.js +0 -309
- data/packages/optparse/package.json +0 -13
- data/packages/optparse/seed.yml +0 -5
- data/packages/text/lib/main.js +0 -8
- data/packages/text/package.json +0 -9
- data/packages/web-file/README.md +0 -7
- data/packages/web-file/lib/errors.js +0 -32
- data/packages/web-file/lib/file-reader.js +0 -10
- data/packages/web-file/lib/file-system.js +0 -234
- data/packages/web-file/lib/file-writer.js +0 -10
- data/packages/web-file/lib/file.js +0 -9
- data/packages/web-file/lib/main.js +0 -34
- data/packages/web-file/lib/platform.js +0 -25
- data/packages/web-file/lib/ruby/file.rb +0 -252
- data/packages/web-file/lib/ruby/file_reader.rb +0 -69
- data/packages/web-file/lib/ruby/file_system.rb +0 -134
- data/packages/web-file/lib/ruby/file_writer.rb +0 -78
- data/packages/web-file/package.json +0 -12
- data/packages/web-typed-array/README.md +0 -7
- data/packages/web-typed-array/lib/array-buffer-view.js +0 -9
- data/packages/web-typed-array/lib/array-buffer.js +0 -7
- data/packages/web-typed-array/lib/main.js +0 -33
- data/packages/web-typed-array/lib/platform.js +0 -20
- data/packages/web-typed-array/lib/ruby/array_buffer.rb +0 -31
- data/packages/web-typed-array/lib/ruby/array_buffer_view.rb +0 -130
- data/packages/web-typed-array/lib/ruby/typed_array.rb +0 -133
- data/packages/web-typed-array/lib/typed-array.js +0 -26
- data/packages/web-typed-array/package.json +0 -9
- data/spec/cli/build_spec.rb +0 -59
- data/spec/cli/install_spec.rb +0 -120
- data/spec/cli/installed_spec.rb +0 -55
- data/spec/cli/list_spec.rb +0 -75
- data/spec/cli/login_spec.rb +0 -76
- data/spec/cli/new_spec.rb +0 -5
- data/spec/cli/owner_spec.rb +0 -115
- data/spec/cli/push_spec.rb +0 -74
- data/spec/cli/uninstall_spec.rb +0 -58
- data/spec/cli/unpack_spec.rb +0 -73
- data/spec/cli/unyank_spec.rb +0 -74
- data/spec/cli/update_spec.rb +0 -8
- data/spec/cli/yank_spec.rb +0 -74
- data/spec/credentials_spec.rb +0 -24
- data/spec/fixtures/coffee-1.0.1.pre.spd +0 -0
- data/spec/fixtures/core-test-0.4.3.spd +0 -0
- data/spec/fixtures/core-test/bin/cot +0 -3
- data/spec/fixtures/core-test/lib/main.js +0 -1
- data/spec/fixtures/core-test/resources/runner.css +0 -0
- data/spec/fixtures/core-test/tests/test.js +0 -1
- data/spec/fixtures/ivory-0.0.1.spd +0 -0
- data/spec/fixtures/jquery-1.4.3.spd +0 -0
- data/spec/fixtures/optparse-1.0.1.spd +0 -0
- data/spec/fixtures/package.json +0 -30
- data/spec/gauntlet_spec.rb +0 -27
- data/spec/javascript/async-test.js +0 -123
- data/spec/javascript/compiler/javascript.js +0 -13
- data/spec/javascript/compiler/ruby.js +0 -14
- data/spec/javascript/loader-test.js +0 -64
- data/spec/javascript/normalize-test.js +0 -73
- data/spec/javascript/packages-test.js +0 -44
- data/spec/javascript/relative-require-test.js +0 -72
- data/spec/javascript/require-test.js +0 -117
- data/spec/javascript/sandbox/compile.js +0 -37
- data/spec/javascript/sandbox/creation.js +0 -44
- data/spec/javascript/sandbox/format.js +0 -79
- data/spec/javascript/sandbox/misc.js +0 -57
- data/spec/javascript/sandbox/preprocessor.js +0 -81
- data/spec/javascript/sandbox/require.js +0 -48
- data/spec/javascript/sandbox/run-command.js +0 -21
- data/spec/javascript/spade/externs.js +0 -14
- data/spec/javascript/spade/load-factory.js +0 -15
- data/spec/javascript/spade/misc.js +0 -23
- data/spec/javascript/spade/ready.js +0 -12
- data/spec/javascript/spade/register.js +0 -13
- data/spec/javascript_spec.rb +0 -7
- data/spec/package_spec.rb +0 -267
- data/spec/spec_helper.rb +0 -30
- data/spec/support/cli.rb +0 -94
- data/spec/support/core_test.rb +0 -59
- data/spec/support/fake.rb +0 -44
- data/spec/support/fake_gem_server.rb +0 -66
- data/spec/support/fake_gemcutter.rb +0 -49
- data/spec/support/matchers.rb +0 -31
- data/spec/support/path.rb +0 -54
- data/test-spade.html +0 -8
@@ -1,2165 +0,0 @@
|
|
1
|
-
(function() {
|
2
|
-
var Access, Arr, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, NEGATE, NO, Obj, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref;
|
3
|
-
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
|
4
|
-
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
|
5
|
-
function ctor() { this.constructor = child; }
|
6
|
-
ctor.prototype = parent.prototype;
|
7
|
-
child.prototype = new ctor;
|
8
|
-
child.__super__ = parent.prototype;
|
9
|
-
return child;
|
10
|
-
}, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
11
|
-
Scope = require('./scope').Scope;
|
12
|
-
_ref = require('./helpers'), compact = _ref.compact, flatten = _ref.flatten, extend = _ref.extend, merge = _ref.merge, del = _ref.del, starts = _ref.starts, ends = _ref.ends, last = _ref.last;
|
13
|
-
exports.extend = extend;
|
14
|
-
YES = function() {
|
15
|
-
return true;
|
16
|
-
};
|
17
|
-
NO = function() {
|
18
|
-
return false;
|
19
|
-
};
|
20
|
-
THIS = function() {
|
21
|
-
return this;
|
22
|
-
};
|
23
|
-
NEGATE = function() {
|
24
|
-
this.negated = !this.negated;
|
25
|
-
return this;
|
26
|
-
};
|
27
|
-
exports.Base = Base = (function() {
|
28
|
-
function Base() {}
|
29
|
-
Base.prototype.compile = function(o, lvl) {
|
30
|
-
var node;
|
31
|
-
o = extend({}, o);
|
32
|
-
if (lvl) {
|
33
|
-
o.level = lvl;
|
34
|
-
}
|
35
|
-
node = this.unfoldSoak(o) || this;
|
36
|
-
node.tab = o.indent;
|
37
|
-
if (o.level === LEVEL_TOP || !node.isStatement(o)) {
|
38
|
-
return node.compileNode(o);
|
39
|
-
} else {
|
40
|
-
return node.compileClosure(o);
|
41
|
-
}
|
42
|
-
};
|
43
|
-
Base.prototype.compileClosure = function(o) {
|
44
|
-
if (this.jumps()) {
|
45
|
-
throw SyntaxError('cannot use a pure statement in an expression.');
|
46
|
-
}
|
47
|
-
o.sharedScope = true;
|
48
|
-
return Closure.wrap(this).compileNode(o);
|
49
|
-
};
|
50
|
-
Base.prototype.cache = function(o, level, reused) {
|
51
|
-
var ref, sub;
|
52
|
-
if (!this.isComplex()) {
|
53
|
-
ref = level ? this.compile(o, level) : this;
|
54
|
-
return [ref, ref];
|
55
|
-
} else {
|
56
|
-
ref = new Literal(reused || o.scope.freeVariable('ref'));
|
57
|
-
sub = new Assign(ref, this);
|
58
|
-
if (level) {
|
59
|
-
return [sub.compile(o, level), ref.value];
|
60
|
-
} else {
|
61
|
-
return [sub, ref];
|
62
|
-
}
|
63
|
-
}
|
64
|
-
};
|
65
|
-
Base.prototype.compileLoopReference = function(o, name) {
|
66
|
-
var src, tmp, _ref;
|
67
|
-
src = tmp = this.compile(o, LEVEL_LIST);
|
68
|
-
if (!((-Infinity < (_ref = +src) && _ref < Infinity) || IDENTIFIER.test(src) && o.scope.check(src, true))) {
|
69
|
-
src = "" + (tmp = o.scope.freeVariable(name)) + " = " + src;
|
70
|
-
}
|
71
|
-
return [src, tmp];
|
72
|
-
};
|
73
|
-
Base.prototype.makeReturn = function() {
|
74
|
-
return new Return(this);
|
75
|
-
};
|
76
|
-
Base.prototype.contains = function(pred) {
|
77
|
-
var contains;
|
78
|
-
contains = false;
|
79
|
-
this.traverseChildren(false, function(node) {
|
80
|
-
if (pred(node)) {
|
81
|
-
contains = true;
|
82
|
-
return false;
|
83
|
-
}
|
84
|
-
});
|
85
|
-
return contains;
|
86
|
-
};
|
87
|
-
Base.prototype.containsType = function(type) {
|
88
|
-
return this instanceof type || this.contains(function(node) {
|
89
|
-
return node instanceof type;
|
90
|
-
});
|
91
|
-
};
|
92
|
-
Base.prototype.lastNonComment = function(list) {
|
93
|
-
var i;
|
94
|
-
i = list.length;
|
95
|
-
while (i--) {
|
96
|
-
if (!(list[i] instanceof Comment)) {
|
97
|
-
return list[i];
|
98
|
-
}
|
99
|
-
}
|
100
|
-
return null;
|
101
|
-
};
|
102
|
-
Base.prototype.toString = function(idt, name) {
|
103
|
-
var tree;
|
104
|
-
if (idt == null) {
|
105
|
-
idt = '';
|
106
|
-
}
|
107
|
-
if (name == null) {
|
108
|
-
name = this.constructor.name;
|
109
|
-
}
|
110
|
-
tree = '\n' + idt + name;
|
111
|
-
if (this.soak) {
|
112
|
-
tree += '?';
|
113
|
-
}
|
114
|
-
this.eachChild(function(node) {
|
115
|
-
return tree += node.toString(idt + TAB);
|
116
|
-
});
|
117
|
-
return tree;
|
118
|
-
};
|
119
|
-
Base.prototype.eachChild = function(func) {
|
120
|
-
var attr, child, _i, _j, _len, _len2, _ref, _ref2;
|
121
|
-
if (!this.children) {
|
122
|
-
return this;
|
123
|
-
}
|
124
|
-
_ref = this.children;
|
125
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
126
|
-
attr = _ref[_i];
|
127
|
-
if (this[attr]) {
|
128
|
-
_ref2 = flatten([this[attr]]);
|
129
|
-
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
130
|
-
child = _ref2[_j];
|
131
|
-
if (func(child) === false) {
|
132
|
-
return this;
|
133
|
-
}
|
134
|
-
}
|
135
|
-
}
|
136
|
-
}
|
137
|
-
return this;
|
138
|
-
};
|
139
|
-
Base.prototype.traverseChildren = function(crossScope, func) {
|
140
|
-
return this.eachChild(function(child) {
|
141
|
-
if (func(child) === false) {
|
142
|
-
return false;
|
143
|
-
}
|
144
|
-
return child.traverseChildren(crossScope, func);
|
145
|
-
});
|
146
|
-
};
|
147
|
-
Base.prototype.invert = function() {
|
148
|
-
return new Op('!', this);
|
149
|
-
};
|
150
|
-
Base.prototype.unwrapAll = function() {
|
151
|
-
var node;
|
152
|
-
node = this;
|
153
|
-
while (node !== (node = node.unwrap())) {
|
154
|
-
continue;
|
155
|
-
}
|
156
|
-
return node;
|
157
|
-
};
|
158
|
-
Base.prototype.children = [];
|
159
|
-
Base.prototype.isStatement = NO;
|
160
|
-
Base.prototype.jumps = NO;
|
161
|
-
Base.prototype.isComplex = YES;
|
162
|
-
Base.prototype.isChainable = NO;
|
163
|
-
Base.prototype.isAssignable = NO;
|
164
|
-
Base.prototype.unwrap = THIS;
|
165
|
-
Base.prototype.unfoldSoak = NO;
|
166
|
-
Base.prototype.assigns = NO;
|
167
|
-
return Base;
|
168
|
-
})();
|
169
|
-
exports.Expressions = Expressions = (function() {
|
170
|
-
__extends(Expressions, Base);
|
171
|
-
function Expressions(nodes) {
|
172
|
-
this.expressions = compact(flatten(nodes || []));
|
173
|
-
}
|
174
|
-
Expressions.prototype.children = ['expressions'];
|
175
|
-
Expressions.prototype.push = function(node) {
|
176
|
-
this.expressions.push(node);
|
177
|
-
return this;
|
178
|
-
};
|
179
|
-
Expressions.prototype.pop = function() {
|
180
|
-
return this.expressions.pop();
|
181
|
-
};
|
182
|
-
Expressions.prototype.unshift = function(node) {
|
183
|
-
this.expressions.unshift(node);
|
184
|
-
return this;
|
185
|
-
};
|
186
|
-
Expressions.prototype.unwrap = function() {
|
187
|
-
if (this.expressions.length === 1) {
|
188
|
-
return this.expressions[0];
|
189
|
-
} else {
|
190
|
-
return this;
|
191
|
-
}
|
192
|
-
};
|
193
|
-
Expressions.prototype.isEmpty = function() {
|
194
|
-
return !this.expressions.length;
|
195
|
-
};
|
196
|
-
Expressions.prototype.isStatement = function(o) {
|
197
|
-
var exp, _i, _len, _ref;
|
198
|
-
_ref = this.expressions;
|
199
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
200
|
-
exp = _ref[_i];
|
201
|
-
if (exp.isStatement(o)) {
|
202
|
-
return true;
|
203
|
-
}
|
204
|
-
}
|
205
|
-
return false;
|
206
|
-
};
|
207
|
-
Expressions.prototype.jumps = function(o) {
|
208
|
-
var exp, _i, _len, _ref;
|
209
|
-
_ref = this.expressions;
|
210
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
211
|
-
exp = _ref[_i];
|
212
|
-
if (exp.jumps(o)) {
|
213
|
-
return exp;
|
214
|
-
}
|
215
|
-
}
|
216
|
-
};
|
217
|
-
Expressions.prototype.makeReturn = function() {
|
218
|
-
var expr, len;
|
219
|
-
len = this.expressions.length;
|
220
|
-
while (len--) {
|
221
|
-
expr = this.expressions[len];
|
222
|
-
if (!(expr instanceof Comment)) {
|
223
|
-
this.expressions[len] = expr.makeReturn();
|
224
|
-
break;
|
225
|
-
}
|
226
|
-
}
|
227
|
-
return this;
|
228
|
-
};
|
229
|
-
Expressions.prototype.compile = function(o, level) {
|
230
|
-
if (o == null) {
|
231
|
-
o = {};
|
232
|
-
}
|
233
|
-
if (o.scope) {
|
234
|
-
return Expressions.__super__.compile.call(this, o, level);
|
235
|
-
} else {
|
236
|
-
return this.compileRoot(o);
|
237
|
-
}
|
238
|
-
};
|
239
|
-
Expressions.prototype.compileNode = function(o) {
|
240
|
-
var code, codes, node, top, _i, _len, _ref;
|
241
|
-
this.tab = o.indent;
|
242
|
-
top = o.level === LEVEL_TOP;
|
243
|
-
codes = [];
|
244
|
-
_ref = this.expressions;
|
245
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
246
|
-
node = _ref[_i];
|
247
|
-
node = node.unwrapAll();
|
248
|
-
node = node.unfoldSoak(o) || node;
|
249
|
-
if (top) {
|
250
|
-
node.front = true;
|
251
|
-
code = node.compile(o);
|
252
|
-
codes.push(node.isStatement(o) ? code : this.tab + code + ';');
|
253
|
-
} else {
|
254
|
-
codes.push(node.compile(o, LEVEL_LIST));
|
255
|
-
}
|
256
|
-
}
|
257
|
-
if (top) {
|
258
|
-
return codes.join('\n');
|
259
|
-
}
|
260
|
-
code = codes.join(', ') || 'void 0';
|
261
|
-
if (codes.length > 1 && o.level >= LEVEL_LIST) {
|
262
|
-
return "(" + code + ")";
|
263
|
-
} else {
|
264
|
-
return code;
|
265
|
-
}
|
266
|
-
};
|
267
|
-
Expressions.prototype.compileRoot = function(o) {
|
268
|
-
var code;
|
269
|
-
o.indent = this.tab = o.bare ? '' : TAB;
|
270
|
-
o.scope = new Scope(null, this, null);
|
271
|
-
o.level = LEVEL_TOP;
|
272
|
-
code = this.compileWithDeclarations(o);
|
273
|
-
code = code.replace(TRAILING_WHITESPACE, '');
|
274
|
-
if (o.bare) {
|
275
|
-
return code;
|
276
|
-
} else {
|
277
|
-
return "(function() {\n" + code + "\n}).call(this);\n";
|
278
|
-
}
|
279
|
-
};
|
280
|
-
Expressions.prototype.compileWithDeclarations = function(o) {
|
281
|
-
var code, exp, i, post, rest, scope, _len, _ref;
|
282
|
-
code = post = '';
|
283
|
-
_ref = this.expressions;
|
284
|
-
for (i = 0, _len = _ref.length; i < _len; i++) {
|
285
|
-
exp = _ref[i];
|
286
|
-
exp = exp.unwrap();
|
287
|
-
if (!(exp instanceof Comment || exp instanceof Literal)) {
|
288
|
-
break;
|
289
|
-
}
|
290
|
-
}
|
291
|
-
o = merge(o, {
|
292
|
-
level: LEVEL_TOP
|
293
|
-
});
|
294
|
-
if (i) {
|
295
|
-
rest = this.expressions.splice(i, this.expressions.length);
|
296
|
-
code = this.compileNode(o);
|
297
|
-
this.expressions = rest;
|
298
|
-
}
|
299
|
-
post = this.compileNode(o);
|
300
|
-
scope = o.scope;
|
301
|
-
if (scope.expressions === this) {
|
302
|
-
if (!o.globals && o.scope.hasDeclarations()) {
|
303
|
-
code += "" + this.tab + "var " + (scope.declaredVariables().join(', ')) + ";\n";
|
304
|
-
}
|
305
|
-
if (scope.hasAssignments) {
|
306
|
-
code += "" + this.tab + "var " + (multident(scope.assignedVariables().join(', '), this.tab)) + ";\n";
|
307
|
-
}
|
308
|
-
}
|
309
|
-
return code + post;
|
310
|
-
};
|
311
|
-
Expressions.wrap = function(nodes) {
|
312
|
-
if (nodes.length === 1 && nodes[0] instanceof Expressions) {
|
313
|
-
return nodes[0];
|
314
|
-
}
|
315
|
-
return new Expressions(nodes);
|
316
|
-
};
|
317
|
-
return Expressions;
|
318
|
-
})();
|
319
|
-
exports.Literal = Literal = (function() {
|
320
|
-
__extends(Literal, Base);
|
321
|
-
function Literal(value) {
|
322
|
-
this.value = value;
|
323
|
-
}
|
324
|
-
Literal.prototype.makeReturn = function() {
|
325
|
-
if (this.isStatement()) {
|
326
|
-
return this;
|
327
|
-
} else {
|
328
|
-
return new Return(this);
|
329
|
-
}
|
330
|
-
};
|
331
|
-
Literal.prototype.isAssignable = function() {
|
332
|
-
return IDENTIFIER.test(this.value);
|
333
|
-
};
|
334
|
-
Literal.prototype.isStatement = function() {
|
335
|
-
var _ref;
|
336
|
-
return (_ref = this.value) === 'break' || _ref === 'continue' || _ref === 'debugger';
|
337
|
-
};
|
338
|
-
Literal.prototype.isComplex = NO;
|
339
|
-
Literal.prototype.assigns = function(name) {
|
340
|
-
return name === this.value;
|
341
|
-
};
|
342
|
-
Literal.prototype.jumps = function(o) {
|
343
|
-
if (!this.isStatement()) {
|
344
|
-
return false;
|
345
|
-
}
|
346
|
-
if (!(o && (o.loop || o.block && (this.value !== 'continue')))) {
|
347
|
-
return this;
|
348
|
-
} else {
|
349
|
-
return false;
|
350
|
-
}
|
351
|
-
};
|
352
|
-
Literal.prototype.compileNode = function(o) {
|
353
|
-
var code;
|
354
|
-
code = this.value.reserved ? "\"" + this.value + "\"" : this.value;
|
355
|
-
if (this.isStatement()) {
|
356
|
-
return "" + this.tab + code + ";";
|
357
|
-
} else {
|
358
|
-
return code;
|
359
|
-
}
|
360
|
-
};
|
361
|
-
Literal.prototype.toString = function() {
|
362
|
-
return ' "' + this.value + '"';
|
363
|
-
};
|
364
|
-
return Literal;
|
365
|
-
})();
|
366
|
-
exports.Return = Return = (function() {
|
367
|
-
__extends(Return, Base);
|
368
|
-
function Return(expression) {
|
369
|
-
this.expression = expression;
|
370
|
-
}
|
371
|
-
Return.prototype.children = ['expression'];
|
372
|
-
Return.prototype.isStatement = YES;
|
373
|
-
Return.prototype.makeReturn = THIS;
|
374
|
-
Return.prototype.jumps = THIS;
|
375
|
-
Return.prototype.compile = function(o, level) {
|
376
|
-
var expr, _ref;
|
377
|
-
expr = (_ref = this.expression) != null ? _ref.makeReturn() : void 0;
|
378
|
-
if (expr && !(expr instanceof Return)) {
|
379
|
-
return expr.compile(o, level);
|
380
|
-
} else {
|
381
|
-
return Return.__super__.compile.call(this, o, level);
|
382
|
-
}
|
383
|
-
};
|
384
|
-
Return.prototype.compileNode = function(o) {
|
385
|
-
return this.tab + ("return" + (this.expression ? ' ' + this.expression.compile(o, LEVEL_PAREN) : '') + ";");
|
386
|
-
};
|
387
|
-
return Return;
|
388
|
-
})();
|
389
|
-
exports.Value = Value = (function() {
|
390
|
-
__extends(Value, Base);
|
391
|
-
function Value(base, props, tag) {
|
392
|
-
if (!props && base instanceof Value) {
|
393
|
-
return base;
|
394
|
-
}
|
395
|
-
this.base = base;
|
396
|
-
this.properties = props || [];
|
397
|
-
if (tag) {
|
398
|
-
this[tag] = true;
|
399
|
-
}
|
400
|
-
return this;
|
401
|
-
}
|
402
|
-
Value.prototype.children = ['base', 'properties'];
|
403
|
-
Value.prototype.push = function(prop) {
|
404
|
-
this.properties.push(prop);
|
405
|
-
return this;
|
406
|
-
};
|
407
|
-
Value.prototype.hasProperties = function() {
|
408
|
-
return !!this.properties.length;
|
409
|
-
};
|
410
|
-
Value.prototype.isArray = function() {
|
411
|
-
return !this.properties.length && this.base instanceof Arr;
|
412
|
-
};
|
413
|
-
Value.prototype.isComplex = function() {
|
414
|
-
return this.hasProperties() || this.base.isComplex();
|
415
|
-
};
|
416
|
-
Value.prototype.isAssignable = function() {
|
417
|
-
return this.hasProperties() || this.base.isAssignable();
|
418
|
-
};
|
419
|
-
Value.prototype.isSimpleNumber = function() {
|
420
|
-
return this.base instanceof Literal && SIMPLENUM.test(this.base.value);
|
421
|
-
};
|
422
|
-
Value.prototype.isAtomic = function() {
|
423
|
-
var node, _i, _len, _ref;
|
424
|
-
_ref = this.properties.concat(this.base);
|
425
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
426
|
-
node = _ref[_i];
|
427
|
-
if (node.soak || node instanceof Call) {
|
428
|
-
return false;
|
429
|
-
}
|
430
|
-
}
|
431
|
-
return true;
|
432
|
-
};
|
433
|
-
Value.prototype.isStatement = function(o) {
|
434
|
-
return !this.properties.length && this.base.isStatement(o);
|
435
|
-
};
|
436
|
-
Value.prototype.assigns = function(name) {
|
437
|
-
return !this.properties.length && this.base.assigns(name);
|
438
|
-
};
|
439
|
-
Value.prototype.jumps = function(o) {
|
440
|
-
return !this.properties.length && this.base.jumps(o);
|
441
|
-
};
|
442
|
-
Value.prototype.isObject = function(onlyGenerated) {
|
443
|
-
if (this.properties.length) {
|
444
|
-
return false;
|
445
|
-
}
|
446
|
-
return (this.base instanceof Obj) && (!onlyGenerated || this.base.generated);
|
447
|
-
};
|
448
|
-
Value.prototype.isSplice = function() {
|
449
|
-
return last(this.properties) instanceof Slice;
|
450
|
-
};
|
451
|
-
Value.prototype.makeReturn = function() {
|
452
|
-
if (this.properties.length) {
|
453
|
-
return Value.__super__.makeReturn.call(this);
|
454
|
-
} else {
|
455
|
-
return this.base.makeReturn();
|
456
|
-
}
|
457
|
-
};
|
458
|
-
Value.prototype.unwrap = function() {
|
459
|
-
if (this.properties.length) {
|
460
|
-
return this;
|
461
|
-
} else {
|
462
|
-
return this.base;
|
463
|
-
}
|
464
|
-
};
|
465
|
-
Value.prototype.cacheReference = function(o) {
|
466
|
-
var base, bref, name, nref;
|
467
|
-
name = last(this.properties);
|
468
|
-
if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) {
|
469
|
-
return [this, this];
|
470
|
-
}
|
471
|
-
base = new Value(this.base, this.properties.slice(0, -1));
|
472
|
-
if (base.isComplex()) {
|
473
|
-
bref = new Literal(o.scope.freeVariable('base'));
|
474
|
-
base = new Value(new Parens(new Assign(bref, base)));
|
475
|
-
}
|
476
|
-
if (!name) {
|
477
|
-
return [base, bref];
|
478
|
-
}
|
479
|
-
if (name.isComplex()) {
|
480
|
-
nref = new Literal(o.scope.freeVariable('name'));
|
481
|
-
name = new Index(new Assign(nref, name.index));
|
482
|
-
nref = new Index(nref);
|
483
|
-
}
|
484
|
-
return [base.push(name), new Value(bref || base.base, [nref || name])];
|
485
|
-
};
|
486
|
-
Value.prototype.compileNode = function(o) {
|
487
|
-
var code, prop, props, _i, _len;
|
488
|
-
this.base.front = this.front;
|
489
|
-
props = this.properties;
|
490
|
-
code = this.base.compile(o, props.length ? LEVEL_ACCESS : null);
|
491
|
-
if (props[0] instanceof Access && this.isSimpleNumber()) {
|
492
|
-
code = "(" + code + ")";
|
493
|
-
}
|
494
|
-
for (_i = 0, _len = props.length; _i < _len; _i++) {
|
495
|
-
prop = props[_i];
|
496
|
-
code += prop.compile(o);
|
497
|
-
}
|
498
|
-
return code;
|
499
|
-
};
|
500
|
-
Value.prototype.unfoldSoak = function(o) {
|
501
|
-
var fst, i, ifn, prop, ref, snd, _len, _ref;
|
502
|
-
if (ifn = this.base.unfoldSoak(o)) {
|
503
|
-
Array.prototype.push.apply(ifn.body.properties, this.properties);
|
504
|
-
return ifn;
|
505
|
-
}
|
506
|
-
_ref = this.properties;
|
507
|
-
for (i = 0, _len = _ref.length; i < _len; i++) {
|
508
|
-
prop = _ref[i];
|
509
|
-
if (prop.soak) {
|
510
|
-
prop.soak = false;
|
511
|
-
fst = new Value(this.base, this.properties.slice(0, i));
|
512
|
-
snd = new Value(this.base, this.properties.slice(i));
|
513
|
-
if (fst.isComplex()) {
|
514
|
-
ref = new Literal(o.scope.freeVariable('ref'));
|
515
|
-
fst = new Parens(new Assign(ref, fst));
|
516
|
-
snd.base = ref;
|
517
|
-
}
|
518
|
-
return new If(new Existence(fst), snd, {
|
519
|
-
soak: true
|
520
|
-
});
|
521
|
-
}
|
522
|
-
}
|
523
|
-
return null;
|
524
|
-
};
|
525
|
-
return Value;
|
526
|
-
})();
|
527
|
-
exports.Comment = Comment = (function() {
|
528
|
-
__extends(Comment, Base);
|
529
|
-
function Comment(comment) {
|
530
|
-
this.comment = comment;
|
531
|
-
}
|
532
|
-
Comment.prototype.isStatement = YES;
|
533
|
-
Comment.prototype.makeReturn = THIS;
|
534
|
-
Comment.prototype.compileNode = function(o, level) {
|
535
|
-
var code;
|
536
|
-
code = '/*' + multident(this.comment, this.tab) + '*/';
|
537
|
-
if ((level || o.level) === LEVEL_TOP) {
|
538
|
-
code = o.indent + code;
|
539
|
-
}
|
540
|
-
return code;
|
541
|
-
};
|
542
|
-
return Comment;
|
543
|
-
})();
|
544
|
-
exports.Call = Call = (function() {
|
545
|
-
__extends(Call, Base);
|
546
|
-
function Call(variable, args, soak) {
|
547
|
-
this.args = args != null ? args : [];
|
548
|
-
this.soak = soak;
|
549
|
-
this.isNew = false;
|
550
|
-
this.isSuper = variable === 'super';
|
551
|
-
this.variable = this.isSuper ? null : variable;
|
552
|
-
}
|
553
|
-
Call.prototype.children = ['variable', 'args'];
|
554
|
-
Call.prototype.newInstance = function() {
|
555
|
-
var base;
|
556
|
-
base = this.variable.base || this.variable;
|
557
|
-
if (base instanceof Call) {
|
558
|
-
base.newInstance();
|
559
|
-
} else {
|
560
|
-
this.isNew = true;
|
561
|
-
}
|
562
|
-
return this;
|
563
|
-
};
|
564
|
-
Call.prototype.superReference = function(o) {
|
565
|
-
var method, name;
|
566
|
-
method = o.scope.method;
|
567
|
-
if (!method) {
|
568
|
-
throw SyntaxError('cannot call super outside of a function.');
|
569
|
-
}
|
570
|
-
name = method.name;
|
571
|
-
if (!name) {
|
572
|
-
throw SyntaxError('cannot call super on an anonymous function.');
|
573
|
-
}
|
574
|
-
if (method.klass) {
|
575
|
-
return "" + method.klass + ".__super__." + name;
|
576
|
-
} else {
|
577
|
-
return "" + name + ".__super__.constructor";
|
578
|
-
}
|
579
|
-
};
|
580
|
-
Call.prototype.unfoldSoak = function(o) {
|
581
|
-
var call, ifn, left, list, rite, _i, _len, _ref, _ref2;
|
582
|
-
if (this.soak) {
|
583
|
-
if (this.variable) {
|
584
|
-
if (ifn = unfoldSoak(o, this, 'variable')) {
|
585
|
-
return ifn;
|
586
|
-
}
|
587
|
-
_ref = new Value(this.variable).cacheReference(o), left = _ref[0], rite = _ref[1];
|
588
|
-
} else {
|
589
|
-
left = new Literal(this.superReference(o));
|
590
|
-
rite = new Value(left);
|
591
|
-
}
|
592
|
-
rite = new Call(rite, this.args);
|
593
|
-
rite.isNew = this.isNew;
|
594
|
-
left = new Literal("typeof " + (left.compile(o)) + " === \"function\"");
|
595
|
-
return new If(left, new Value(rite), {
|
596
|
-
soak: true
|
597
|
-
});
|
598
|
-
}
|
599
|
-
call = this;
|
600
|
-
list = [];
|
601
|
-
while (true) {
|
602
|
-
if (call.variable instanceof Call) {
|
603
|
-
list.push(call);
|
604
|
-
call = call.variable;
|
605
|
-
continue;
|
606
|
-
}
|
607
|
-
if (!(call.variable instanceof Value)) {
|
608
|
-
break;
|
609
|
-
}
|
610
|
-
list.push(call);
|
611
|
-
if (!((call = call.variable.base) instanceof Call)) {
|
612
|
-
break;
|
613
|
-
}
|
614
|
-
}
|
615
|
-
_ref2 = list.reverse();
|
616
|
-
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
617
|
-
call = _ref2[_i];
|
618
|
-
if (ifn) {
|
619
|
-
if (call.variable instanceof Call) {
|
620
|
-
call.variable = ifn;
|
621
|
-
} else {
|
622
|
-
call.variable.base = ifn;
|
623
|
-
}
|
624
|
-
}
|
625
|
-
ifn = unfoldSoak(o, call, 'variable');
|
626
|
-
}
|
627
|
-
return ifn;
|
628
|
-
};
|
629
|
-
Call.prototype.compileNode = function(o) {
|
630
|
-
var arg, args, code, _ref;
|
631
|
-
if ((_ref = this.variable) != null) {
|
632
|
-
_ref.front = this.front;
|
633
|
-
}
|
634
|
-
if (code = Splat.compileSplattedArray(o, this.args, true)) {
|
635
|
-
return this.compileSplat(o, code);
|
636
|
-
}
|
637
|
-
args = ((function() {
|
638
|
-
var _i, _len, _ref, _results;
|
639
|
-
_ref = this.args;
|
640
|
-
_results = [];
|
641
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
642
|
-
arg = _ref[_i];
|
643
|
-
_results.push(arg.compile(o, LEVEL_LIST));
|
644
|
-
}
|
645
|
-
return _results;
|
646
|
-
}).call(this)).join(', ');
|
647
|
-
if (this.isSuper) {
|
648
|
-
return this.superReference(o) + (".call(this" + (args && ', ' + args) + ")");
|
649
|
-
} else {
|
650
|
-
return (this.isNew ? 'new ' : '') + this.variable.compile(o, LEVEL_ACCESS) + ("(" + args + ")");
|
651
|
-
}
|
652
|
-
};
|
653
|
-
Call.prototype.compileSuper = function(args, o) {
|
654
|
-
return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + args + ")";
|
655
|
-
};
|
656
|
-
Call.prototype.compileSplat = function(o, splatArgs) {
|
657
|
-
var base, fun, idt, name, ref;
|
658
|
-
if (this.isSuper) {
|
659
|
-
return "" + (this.superReference(o)) + ".apply(this, " + splatArgs + ")";
|
660
|
-
}
|
661
|
-
if (this.isNew) {
|
662
|
-
idt = this.tab + TAB;
|
663
|
-
return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" ? result : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function() {})";
|
664
|
-
}
|
665
|
-
base = new Value(this.variable);
|
666
|
-
if ((name = base.properties.pop()) && base.isComplex()) {
|
667
|
-
ref = o.scope.freeVariable('ref');
|
668
|
-
fun = "(" + ref + " = " + (base.compile(o, LEVEL_LIST)) + ")" + (name.compile(o));
|
669
|
-
} else {
|
670
|
-
fun = base.compile(o, LEVEL_ACCESS);
|
671
|
-
if (name) {
|
672
|
-
ref = fun;
|
673
|
-
fun += name.compile(o);
|
674
|
-
} else {
|
675
|
-
ref = 'null';
|
676
|
-
}
|
677
|
-
}
|
678
|
-
return "" + fun + ".apply(" + ref + ", " + splatArgs + ")";
|
679
|
-
};
|
680
|
-
return Call;
|
681
|
-
})();
|
682
|
-
exports.Extends = Extends = (function() {
|
683
|
-
__extends(Extends, Base);
|
684
|
-
function Extends(child, parent) {
|
685
|
-
this.child = child;
|
686
|
-
this.parent = parent;
|
687
|
-
}
|
688
|
-
Extends.prototype.children = ['child', 'parent'];
|
689
|
-
Extends.prototype.compile = function(o) {
|
690
|
-
utility('hasProp');
|
691
|
-
return new Call(new Value(new Literal(utility('extends'))), [this.child, this.parent]).compile(o);
|
692
|
-
};
|
693
|
-
return Extends;
|
694
|
-
})();
|
695
|
-
exports.Access = Access = (function() {
|
696
|
-
__extends(Access, Base);
|
697
|
-
function Access(name, tag) {
|
698
|
-
this.name = name;
|
699
|
-
this.name.asKey = true;
|
700
|
-
this.proto = tag === 'proto' ? '.prototype' : '';
|
701
|
-
this.soak = tag === 'soak';
|
702
|
-
}
|
703
|
-
Access.prototype.children = ['name'];
|
704
|
-
Access.prototype.compile = function(o) {
|
705
|
-
var name;
|
706
|
-
name = this.name.compile(o);
|
707
|
-
return this.proto + (IS_STRING.test(name) ? "[" + name + "]" : "." + name);
|
708
|
-
};
|
709
|
-
Access.prototype.isComplex = NO;
|
710
|
-
return Access;
|
711
|
-
})();
|
712
|
-
exports.Index = Index = (function() {
|
713
|
-
__extends(Index, Base);
|
714
|
-
function Index(index) {
|
715
|
-
this.index = index;
|
716
|
-
}
|
717
|
-
Index.prototype.children = ['index'];
|
718
|
-
Index.prototype.compile = function(o) {
|
719
|
-
return (this.proto ? '.prototype' : '') + ("[" + (this.index.compile(o, LEVEL_PAREN)) + "]");
|
720
|
-
};
|
721
|
-
Index.prototype.isComplex = function() {
|
722
|
-
return this.index.isComplex();
|
723
|
-
};
|
724
|
-
return Index;
|
725
|
-
})();
|
726
|
-
exports.Range = Range = (function() {
|
727
|
-
__extends(Range, Base);
|
728
|
-
Range.prototype.children = ['from', 'to'];
|
729
|
-
function Range(from, to, tag) {
|
730
|
-
this.from = from;
|
731
|
-
this.to = to;
|
732
|
-
this.exclusive = tag === 'exclusive';
|
733
|
-
this.equals = this.exclusive ? '' : '=';
|
734
|
-
}
|
735
|
-
Range.prototype.compileVariables = function(o) {
|
736
|
-
var parts, _ref, _ref2, _ref3;
|
737
|
-
o = merge(o, {
|
738
|
-
top: true
|
739
|
-
});
|
740
|
-
_ref = this.from.cache(o, LEVEL_LIST), this.from = _ref[0], this.fromVar = _ref[1];
|
741
|
-
_ref2 = this.to.cache(o, LEVEL_LIST), this.to = _ref2[0], this.toVar = _ref2[1];
|
742
|
-
_ref3 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref3[0], this.toNum = _ref3[1];
|
743
|
-
parts = [];
|
744
|
-
if (this.from !== this.fromVar) {
|
745
|
-
parts.push(this.from);
|
746
|
-
}
|
747
|
-
if (this.to !== this.toVar) {
|
748
|
-
return parts.push(this.to);
|
749
|
-
}
|
750
|
-
};
|
751
|
-
Range.prototype.compileNode = function(o) {
|
752
|
-
var compare, idx, incr, intro, step, stepPart, vars;
|
753
|
-
this.compileVariables(o);
|
754
|
-
if (!o.index) {
|
755
|
-
return this.compileArray(o);
|
756
|
-
}
|
757
|
-
if (this.fromNum && this.toNum) {
|
758
|
-
return this.compileSimple(o);
|
759
|
-
}
|
760
|
-
idx = del(o, 'index');
|
761
|
-
step = del(o, 'step');
|
762
|
-
vars = ("" + idx + " = " + this.from) + (this.to !== this.toVar ? ", " + this.to : '');
|
763
|
-
intro = "(" + this.fromVar + " <= " + this.toVar + " ? " + idx;
|
764
|
-
compare = "" + intro + " <" + this.equals + " " + this.toVar + " : " + idx + " >" + this.equals + " " + this.toVar + ")";
|
765
|
-
stepPart = step ? step.compile(o) : '1';
|
766
|
-
incr = step ? "" + idx + " += " + stepPart : "" + intro + " += " + stepPart + " : " + idx + " -= " + stepPart + ")";
|
767
|
-
return "" + vars + "; " + compare + "; " + incr;
|
768
|
-
};
|
769
|
-
Range.prototype.compileSimple = function(o) {
|
770
|
-
var from, idx, step, to, _ref;
|
771
|
-
_ref = [+this.fromNum, +this.toNum], from = _ref[0], to = _ref[1];
|
772
|
-
idx = del(o, 'index');
|
773
|
-
step = del(o, 'step');
|
774
|
-
step && (step = "" + idx + " += " + (step.compile(o)));
|
775
|
-
if (from <= to) {
|
776
|
-
return "" + idx + " = " + from + "; " + idx + " <" + this.equals + " " + to + "; " + (step || ("" + idx + "++"));
|
777
|
-
} else {
|
778
|
-
return "" + idx + " = " + from + "; " + idx + " >" + this.equals + " " + to + "; " + (step || ("" + idx + "--"));
|
779
|
-
}
|
780
|
-
};
|
781
|
-
Range.prototype.compileArray = function(o) {
|
782
|
-
var body, clause, i, idt, post, pre, range, result, vars, _i, _ref, _ref2, _results;
|
783
|
-
if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {
|
784
|
-
range = (function() {
|
785
|
-
_results = [];
|
786
|
-
for (var _i = _ref = +this.fromNum, _ref2 = +this.toNum; _ref <= _ref2 ? _i <= _ref2 : _i >= _ref2; _ref <= _ref2 ? _i += 1 : _i -= 1){ _results.push(_i); }
|
787
|
-
return _results;
|
788
|
-
}).call(this);
|
789
|
-
if (this.exclusive) {
|
790
|
-
range.pop();
|
791
|
-
}
|
792
|
-
return "[" + (range.join(', ')) + "]";
|
793
|
-
}
|
794
|
-
idt = this.tab + TAB;
|
795
|
-
i = o.scope.freeVariable('i');
|
796
|
-
result = o.scope.freeVariable('results');
|
797
|
-
pre = "\n" + idt + result + " = [];";
|
798
|
-
if (this.fromNum && this.toNum) {
|
799
|
-
o.index = i;
|
800
|
-
body = this.compileSimple(o);
|
801
|
-
} else {
|
802
|
-
vars = ("" + i + " = " + this.from) + (this.to !== this.toVar ? ", " + this.to : '');
|
803
|
-
clause = "" + this.fromVar + " <= " + this.toVar + " ?";
|
804
|
-
body = "var " + vars + "; " + clause + " " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + clause + " " + i + " += 1 : " + i + " -= 1";
|
805
|
-
}
|
806
|
-
post = "{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + o.indent;
|
807
|
-
return "(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).call(this)";
|
808
|
-
};
|
809
|
-
return Range;
|
810
|
-
})();
|
811
|
-
exports.Slice = Slice = (function() {
|
812
|
-
__extends(Slice, Base);
|
813
|
-
Slice.prototype.children = ['range'];
|
814
|
-
function Slice(range) {
|
815
|
-
this.range = range;
|
816
|
-
Slice.__super__.constructor.call(this);
|
817
|
-
}
|
818
|
-
Slice.prototype.compileNode = function(o) {
|
819
|
-
var compiled, from, fromStr, to, toStr, _ref;
|
820
|
-
_ref = this.range, to = _ref.to, from = _ref.from;
|
821
|
-
fromStr = from && from.compile(o, LEVEL_PAREN) || '0';
|
822
|
-
compiled = to && to.compile(o, LEVEL_PAREN);
|
823
|
-
if (to && !(!this.range.exclusive && +compiled === -1)) {
|
824
|
-
toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? (+compiled + 1).toString() : "(" + compiled + " + 1) || 9e9");
|
825
|
-
}
|
826
|
-
return ".slice(" + fromStr + (toStr || '') + ")";
|
827
|
-
};
|
828
|
-
return Slice;
|
829
|
-
})();
|
830
|
-
exports.Obj = Obj = (function() {
|
831
|
-
__extends(Obj, Base);
|
832
|
-
function Obj(props, generated) {
|
833
|
-
this.generated = generated != null ? generated : false;
|
834
|
-
this.objects = this.properties = props || [];
|
835
|
-
}
|
836
|
-
Obj.prototype.children = ['properties'];
|
837
|
-
Obj.prototype.compileNode = function(o) {
|
838
|
-
var i, idt, indent, join, lastNoncom, obj, prop, props;
|
839
|
-
props = this.properties;
|
840
|
-
if (!props.length) {
|
841
|
-
if (this.front) {
|
842
|
-
return '({})';
|
843
|
-
} else {
|
844
|
-
return '{}';
|
845
|
-
}
|
846
|
-
}
|
847
|
-
idt = o.indent += TAB;
|
848
|
-
lastNoncom = this.lastNonComment(this.properties);
|
849
|
-
props = (function() {
|
850
|
-
var _len, _results;
|
851
|
-
_results = [];
|
852
|
-
for (i = 0, _len = props.length; i < _len; i++) {
|
853
|
-
prop = props[i];
|
854
|
-
join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
|
855
|
-
indent = prop instanceof Comment ? '' : idt;
|
856
|
-
if (prop instanceof Value && prop["this"]) {
|
857
|
-
prop = new Assign(prop.properties[0].name, prop, 'object');
|
858
|
-
}
|
859
|
-
if (!(prop instanceof Comment)) {
|
860
|
-
if (!(prop instanceof Assign)) {
|
861
|
-
prop = new Assign(prop, prop, 'object');
|
862
|
-
}
|
863
|
-
(prop.variable.base || prop.variable).asKey = true;
|
864
|
-
}
|
865
|
-
_results.push(indent + prop.compile(o, LEVEL_TOP) + join);
|
866
|
-
}
|
867
|
-
return _results;
|
868
|
-
})();
|
869
|
-
props = props.join('');
|
870
|
-
obj = "{" + (props && '\n' + props + '\n' + this.tab) + "}";
|
871
|
-
if (this.front) {
|
872
|
-
return "(" + obj + ")";
|
873
|
-
} else {
|
874
|
-
return obj;
|
875
|
-
}
|
876
|
-
};
|
877
|
-
Obj.prototype.assigns = function(name) {
|
878
|
-
var prop, _i, _len, _ref;
|
879
|
-
_ref = this.properties;
|
880
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
881
|
-
prop = _ref[_i];
|
882
|
-
if (prop.assigns(name)) {
|
883
|
-
return true;
|
884
|
-
}
|
885
|
-
}
|
886
|
-
return false;
|
887
|
-
};
|
888
|
-
return Obj;
|
889
|
-
})();
|
890
|
-
exports.Arr = Arr = (function() {
|
891
|
-
__extends(Arr, Base);
|
892
|
-
function Arr(objs) {
|
893
|
-
this.objects = objs || [];
|
894
|
-
}
|
895
|
-
Arr.prototype.children = ['objects'];
|
896
|
-
Arr.prototype.compileNode = function(o) {
|
897
|
-
var code, obj;
|
898
|
-
if (!this.objects.length) {
|
899
|
-
return '[]';
|
900
|
-
}
|
901
|
-
o.indent += TAB;
|
902
|
-
if (code = Splat.compileSplattedArray(o, this.objects)) {
|
903
|
-
return code;
|
904
|
-
}
|
905
|
-
code = ((function() {
|
906
|
-
var _i, _len, _ref, _results;
|
907
|
-
_ref = this.objects;
|
908
|
-
_results = [];
|
909
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
910
|
-
obj = _ref[_i];
|
911
|
-
_results.push(obj.compile(o, LEVEL_LIST));
|
912
|
-
}
|
913
|
-
return _results;
|
914
|
-
}).call(this)).join(', ');
|
915
|
-
if (code.indexOf('\n') >= 0) {
|
916
|
-
return "[\n" + o.indent + code + "\n" + this.tab + "]";
|
917
|
-
} else {
|
918
|
-
return "[" + code + "]";
|
919
|
-
}
|
920
|
-
};
|
921
|
-
Arr.prototype.assigns = function(name) {
|
922
|
-
var obj, _i, _len, _ref;
|
923
|
-
_ref = this.objects;
|
924
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
925
|
-
obj = _ref[_i];
|
926
|
-
if (obj.assigns(name)) {
|
927
|
-
return true;
|
928
|
-
}
|
929
|
-
}
|
930
|
-
return false;
|
931
|
-
};
|
932
|
-
return Arr;
|
933
|
-
})();
|
934
|
-
exports.Class = Class = (function() {
|
935
|
-
__extends(Class, Base);
|
936
|
-
function Class(variable, parent, body) {
|
937
|
-
this.variable = variable;
|
938
|
-
this.parent = parent;
|
939
|
-
this.body = body != null ? body : new Expressions;
|
940
|
-
this.boundFuncs = [];
|
941
|
-
this.body.classBody = true;
|
942
|
-
}
|
943
|
-
Class.prototype.children = ['variable', 'parent', 'body'];
|
944
|
-
Class.prototype.determineName = function() {
|
945
|
-
var decl, tail;
|
946
|
-
if (!this.variable) {
|
947
|
-
return null;
|
948
|
-
}
|
949
|
-
decl = (tail = last(this.variable.properties)) ? tail instanceof Access && tail.name.value : this.variable.base.value;
|
950
|
-
return decl && (decl = IDENTIFIER.test(decl) && decl);
|
951
|
-
};
|
952
|
-
Class.prototype.setContext = function(name) {
|
953
|
-
return this.body.traverseChildren(false, function(node) {
|
954
|
-
if (node.classBody) {
|
955
|
-
return false;
|
956
|
-
}
|
957
|
-
if (node instanceof Literal && node.value === 'this') {
|
958
|
-
return node.value = name;
|
959
|
-
} else if (node instanceof Code) {
|
960
|
-
node.klass = name;
|
961
|
-
if (node.bound) {
|
962
|
-
return node.context = name;
|
963
|
-
}
|
964
|
-
}
|
965
|
-
});
|
966
|
-
};
|
967
|
-
Class.prototype.addBoundFunctions = function(o) {
|
968
|
-
var bname, bvar, _i, _len, _ref, _results;
|
969
|
-
if (this.boundFuncs.length) {
|
970
|
-
_ref = this.boundFuncs;
|
971
|
-
_results = [];
|
972
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
973
|
-
bvar = _ref[_i];
|
974
|
-
bname = bvar.compile(o);
|
975
|
-
_results.push(this.ctor.body.unshift(new Literal("this." + bname + " = " + (utility('bind')) + "(this." + bname + ", this);")));
|
976
|
-
}
|
977
|
-
return _results;
|
978
|
-
}
|
979
|
-
};
|
980
|
-
Class.prototype.addProperties = function(node, name) {
|
981
|
-
var assign, base, func, props, _results;
|
982
|
-
props = node.base.properties.slice(0);
|
983
|
-
_results = [];
|
984
|
-
while (assign = props.shift()) {
|
985
|
-
if (assign instanceof Assign) {
|
986
|
-
base = assign.variable.base;
|
987
|
-
delete assign.context;
|
988
|
-
func = assign.value;
|
989
|
-
if (base.value === 'constructor') {
|
990
|
-
if (this.ctor) {
|
991
|
-
throw new Error('cannot define more than one constructor in a class');
|
992
|
-
}
|
993
|
-
if (func.bound) {
|
994
|
-
throw new Error('cannot define a constructor as a bound function');
|
995
|
-
}
|
996
|
-
if (func instanceof Code) {
|
997
|
-
assign = this.ctor = func;
|
998
|
-
} else {
|
999
|
-
assign = this.ctor = new Assign(new Value(new Literal(name)), func);
|
1000
|
-
}
|
1001
|
-
} else {
|
1002
|
-
if (!assign.variable["this"]) {
|
1003
|
-
assign.variable = new Value(new Literal(name), [new Access(base, 'proto')]);
|
1004
|
-
}
|
1005
|
-
if (func instanceof Code && func.bound) {
|
1006
|
-
this.boundFuncs.push(base);
|
1007
|
-
func.bound = false;
|
1008
|
-
}
|
1009
|
-
}
|
1010
|
-
}
|
1011
|
-
_results.push(assign);
|
1012
|
-
}
|
1013
|
-
return _results;
|
1014
|
-
};
|
1015
|
-
Class.prototype.walkBody = function(name) {
|
1016
|
-
return this.traverseChildren(false, __bind(function(child) {
|
1017
|
-
var exps, i, node, _len, _ref;
|
1018
|
-
if (child instanceof Class) {
|
1019
|
-
return false;
|
1020
|
-
}
|
1021
|
-
if (child instanceof Expressions) {
|
1022
|
-
_ref = exps = child.expressions;
|
1023
|
-
for (i = 0, _len = _ref.length; i < _len; i++) {
|
1024
|
-
node = _ref[i];
|
1025
|
-
if (node instanceof Value && node.isObject(true)) {
|
1026
|
-
exps[i] = this.addProperties(node, name);
|
1027
|
-
}
|
1028
|
-
}
|
1029
|
-
return child.expressions = exps = flatten(exps);
|
1030
|
-
}
|
1031
|
-
}, this));
|
1032
|
-
};
|
1033
|
-
Class.prototype.ensureConstructor = function(name) {
|
1034
|
-
if (!this.ctor) {
|
1035
|
-
this.ctor = new Code;
|
1036
|
-
if (this.parent) {
|
1037
|
-
this.ctor.body.push(new Call('super', [new Splat(new Literal('arguments'))]));
|
1038
|
-
}
|
1039
|
-
this.body.expressions.unshift(this.ctor);
|
1040
|
-
}
|
1041
|
-
this.ctor.ctor = this.ctor.name = name;
|
1042
|
-
this.ctor.klass = null;
|
1043
|
-
return this.ctor.noReturn = true;
|
1044
|
-
};
|
1045
|
-
Class.prototype.compileNode = function(o) {
|
1046
|
-
var decl, klass, lname, name;
|
1047
|
-
decl = this.determineName();
|
1048
|
-
name = decl || this.name || '_Class';
|
1049
|
-
lname = new Literal(name);
|
1050
|
-
this.setContext(name);
|
1051
|
-
this.walkBody(name);
|
1052
|
-
if (this.parent) {
|
1053
|
-
this.body.expressions.unshift(new Extends(lname, this.parent));
|
1054
|
-
}
|
1055
|
-
this.ensureConstructor(name);
|
1056
|
-
this.body.expressions.push(lname);
|
1057
|
-
this.addBoundFunctions(o);
|
1058
|
-
klass = new Parens(Closure.wrap(this.body), true);
|
1059
|
-
if (this.variable) {
|
1060
|
-
klass = new Assign(this.variable, klass);
|
1061
|
-
}
|
1062
|
-
return klass.compile(o);
|
1063
|
-
};
|
1064
|
-
return Class;
|
1065
|
-
})();
|
1066
|
-
exports.Assign = Assign = (function() {
|
1067
|
-
__extends(Assign, Base);
|
1068
|
-
function Assign(variable, value, context, options) {
|
1069
|
-
this.variable = variable;
|
1070
|
-
this.value = value;
|
1071
|
-
this.context = context;
|
1072
|
-
this.param = options && options.param;
|
1073
|
-
}
|
1074
|
-
Assign.prototype.METHOD_DEF = /^(?:(\S+)\.prototype\.|\S+?)?\b([$A-Za-z_][$\w]*)$/;
|
1075
|
-
Assign.prototype.children = ['variable', 'value'];
|
1076
|
-
Assign.prototype.assigns = function(name) {
|
1077
|
-
return this[this.context === 'object' ? 'value' : 'variable'].assigns(name);
|
1078
|
-
};
|
1079
|
-
Assign.prototype.unfoldSoak = function(o) {
|
1080
|
-
return unfoldSoak(o, this, 'variable');
|
1081
|
-
};
|
1082
|
-
Assign.prototype.compileNode = function(o) {
|
1083
|
-
var isValue, match, name, val, _ref;
|
1084
|
-
if (isValue = this.variable instanceof Value) {
|
1085
|
-
if (this.variable.isArray() || this.variable.isObject()) {
|
1086
|
-
return this.compilePatternMatch(o);
|
1087
|
-
}
|
1088
|
-
if (this.variable.isSplice()) {
|
1089
|
-
return this.compileSplice(o);
|
1090
|
-
}
|
1091
|
-
if ((_ref = this.context) === '||=' || _ref === '&&=' || _ref === '?=') {
|
1092
|
-
return this.compileConditional(o);
|
1093
|
-
}
|
1094
|
-
}
|
1095
|
-
name = this.variable.compile(o, LEVEL_LIST);
|
1096
|
-
if (this.value instanceof Code && (match = this.METHOD_DEF.exec(name))) {
|
1097
|
-
this.value.name = match[2];
|
1098
|
-
if (match[1]) {
|
1099
|
-
this.value.klass = match[1];
|
1100
|
-
}
|
1101
|
-
}
|
1102
|
-
val = this.value.compile(o, LEVEL_LIST);
|
1103
|
-
if (this.context === 'object') {
|
1104
|
-
return "" + name + ": " + val;
|
1105
|
-
}
|
1106
|
-
if (!this.variable.isAssignable()) {
|
1107
|
-
throw SyntaxError("\"" + (this.variable.compile(o)) + "\" cannot be assigned.");
|
1108
|
-
}
|
1109
|
-
if (!(this.context || isValue && (this.variable.namespaced || this.variable.hasProperties()))) {
|
1110
|
-
if (this.param) {
|
1111
|
-
o.scope.add(name, 'var');
|
1112
|
-
} else {
|
1113
|
-
o.scope.find(name);
|
1114
|
-
}
|
1115
|
-
}
|
1116
|
-
val = name + (" " + (this.context || '=') + " ") + val;
|
1117
|
-
if (o.level <= LEVEL_LIST) {
|
1118
|
-
return val;
|
1119
|
-
} else {
|
1120
|
-
return "(" + val + ")";
|
1121
|
-
}
|
1122
|
-
};
|
1123
|
-
Assign.prototype.compilePatternMatch = function(o) {
|
1124
|
-
var acc, assigns, code, i, idx, isObject, ivar, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _len, _ref, _ref2, _ref3, _ref4;
|
1125
|
-
top = o.level === LEVEL_TOP;
|
1126
|
-
value = this.value;
|
1127
|
-
objects = this.variable.base.objects;
|
1128
|
-
if (!(olen = objects.length)) {
|
1129
|
-
return value.compile(o);
|
1130
|
-
}
|
1131
|
-
isObject = this.variable.isObject();
|
1132
|
-
if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) {
|
1133
|
-
if (obj instanceof Assign) {
|
1134
|
-
_ref = obj, idx = _ref.variable.base, obj = _ref.value;
|
1135
|
-
} else {
|
1136
|
-
if (obj.base instanceof Parens) {
|
1137
|
-
_ref2 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref2[0], idx = _ref2[1];
|
1138
|
-
} else {
|
1139
|
-
idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0);
|
1140
|
-
}
|
1141
|
-
}
|
1142
|
-
acc = IDENTIFIER.test(idx.unwrap().value || 0);
|
1143
|
-
value = new Value(value);
|
1144
|
-
value.properties.push(new (acc ? Access : Index)(idx));
|
1145
|
-
return new Assign(obj, value).compile(o);
|
1146
|
-
}
|
1147
|
-
vvar = value.compile(o, LEVEL_LIST);
|
1148
|
-
assigns = [];
|
1149
|
-
splat = false;
|
1150
|
-
if (!IDENTIFIER.test(vvar) || this.variable.assigns(vvar)) {
|
1151
|
-
assigns.push("" + (ref = o.scope.freeVariable('ref')) + " = " + vvar);
|
1152
|
-
vvar = ref;
|
1153
|
-
}
|
1154
|
-
for (i = 0, _len = objects.length; i < _len; i++) {
|
1155
|
-
obj = objects[i];
|
1156
|
-
idx = i;
|
1157
|
-
if (isObject) {
|
1158
|
-
if (obj instanceof Assign) {
|
1159
|
-
_ref3 = obj, idx = _ref3.variable.base, obj = _ref3.value;
|
1160
|
-
} else {
|
1161
|
-
if (obj.base instanceof Parens) {
|
1162
|
-
_ref4 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref4[0], idx = _ref4[1];
|
1163
|
-
} else {
|
1164
|
-
idx = obj["this"] ? obj.properties[0].name : obj;
|
1165
|
-
}
|
1166
|
-
}
|
1167
|
-
}
|
1168
|
-
if (!splat && obj instanceof Splat) {
|
1169
|
-
val = "" + olen + " <= " + vvar + ".length ? " + (utility('slice')) + ".call(" + vvar + ", " + i;
|
1170
|
-
if (rest = olen - i - 1) {
|
1171
|
-
ivar = o.scope.freeVariable('i');
|
1172
|
-
val += ", " + ivar + " = " + vvar + ".length - " + rest + ") : (" + ivar + " = " + i + ", [])";
|
1173
|
-
} else {
|
1174
|
-
val += ") : []";
|
1175
|
-
}
|
1176
|
-
val = new Literal(val);
|
1177
|
-
splat = "" + ivar + "++";
|
1178
|
-
} else {
|
1179
|
-
if (obj instanceof Splat) {
|
1180
|
-
obj = obj.name.compile(o);
|
1181
|
-
throw SyntaxError("multiple splats are disallowed in an assignment: " + obj + " ...");
|
1182
|
-
}
|
1183
|
-
if (typeof idx === 'number') {
|
1184
|
-
idx = new Literal(splat || idx);
|
1185
|
-
acc = false;
|
1186
|
-
} else {
|
1187
|
-
acc = isObject && IDENTIFIER.test(idx.unwrap().value || 0);
|
1188
|
-
}
|
1189
|
-
val = new Value(new Literal(vvar), [new (acc ? Access : Index)(idx)]);
|
1190
|
-
}
|
1191
|
-
assigns.push(new Assign(obj, val, null, {
|
1192
|
-
param: this.param
|
1193
|
-
}).compile(o, LEVEL_TOP));
|
1194
|
-
}
|
1195
|
-
if (!top) {
|
1196
|
-
assigns.push(vvar);
|
1197
|
-
}
|
1198
|
-
code = assigns.join(', ');
|
1199
|
-
if (o.level < LEVEL_LIST) {
|
1200
|
-
return code;
|
1201
|
-
} else {
|
1202
|
-
return "(" + code + ")";
|
1203
|
-
}
|
1204
|
-
};
|
1205
|
-
Assign.prototype.compileConditional = function(o) {
|
1206
|
-
var left, rite, _ref;
|
1207
|
-
_ref = this.variable.cacheReference(o), left = _ref[0], rite = _ref[1];
|
1208
|
-
return new Op(this.context.slice(0, -1), left, new Assign(rite, this.value, '=')).compile(o);
|
1209
|
-
};
|
1210
|
-
Assign.prototype.compileSplice = function(o) {
|
1211
|
-
var code, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref, _ref2, _ref3;
|
1212
|
-
_ref = this.variable.properties.pop().range, from = _ref.from, to = _ref.to, exclusive = _ref.exclusive;
|
1213
|
-
name = this.variable.compile(o);
|
1214
|
-
_ref2 = (from != null ? from.cache(o, LEVEL_OP) : void 0) || ['0', '0'], fromDecl = _ref2[0], fromRef = _ref2[1];
|
1215
|
-
if (to) {
|
1216
|
-
if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) {
|
1217
|
-
to = +to.compile(o) - +fromRef;
|
1218
|
-
if (!exclusive) {
|
1219
|
-
to += 1;
|
1220
|
-
}
|
1221
|
-
} else {
|
1222
|
-
to = to.compile(o) + ' - ' + fromRef;
|
1223
|
-
if (!exclusive) {
|
1224
|
-
to += ' + 1';
|
1225
|
-
}
|
1226
|
-
}
|
1227
|
-
} else {
|
1228
|
-
to = "9e9";
|
1229
|
-
}
|
1230
|
-
_ref3 = this.value.cache(o, LEVEL_LIST), valDef = _ref3[0], valRef = _ref3[1];
|
1231
|
-
code = "[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat(" + valDef + ")), " + valRef;
|
1232
|
-
if (o.level > LEVEL_TOP) {
|
1233
|
-
return "(" + code + ")";
|
1234
|
-
} else {
|
1235
|
-
return code;
|
1236
|
-
}
|
1237
|
-
};
|
1238
|
-
return Assign;
|
1239
|
-
})();
|
1240
|
-
exports.Code = Code = (function() {
|
1241
|
-
__extends(Code, Base);
|
1242
|
-
function Code(params, body, tag) {
|
1243
|
-
this.params = params || [];
|
1244
|
-
this.body = body || new Expressions;
|
1245
|
-
this.bound = tag === 'boundfunc';
|
1246
|
-
if (this.bound) {
|
1247
|
-
this.context = 'this';
|
1248
|
-
}
|
1249
|
-
}
|
1250
|
-
Code.prototype.children = ['params', 'body'];
|
1251
|
-
Code.prototype.isStatement = function() {
|
1252
|
-
return !!this.ctor;
|
1253
|
-
};
|
1254
|
-
Code.prototype.jumps = NO;
|
1255
|
-
Code.prototype.compileNode = function(o) {
|
1256
|
-
var code, exprs, i, idt, lit, p, param, ref, splats, v, val, vars, wasEmpty, _i, _j, _len, _len2, _len3, _ref, _ref2, _ref3;
|
1257
|
-
o.scope = new Scope(o.scope, this.body, this);
|
1258
|
-
o.scope.shared = del(o, 'sharedScope');
|
1259
|
-
o.indent += TAB;
|
1260
|
-
delete o.bare;
|
1261
|
-
delete o.globals;
|
1262
|
-
vars = [];
|
1263
|
-
exprs = [];
|
1264
|
-
_ref = this.params;
|
1265
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1266
|
-
param = _ref[_i];
|
1267
|
-
if (param.splat) {
|
1268
|
-
splats = new Assign(new Value(new Arr((function() {
|
1269
|
-
var _i, _len, _ref, _results;
|
1270
|
-
_ref = this.params;
|
1271
|
-
_results = [];
|
1272
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1273
|
-
p = _ref[_i];
|
1274
|
-
_results.push(p.asReference(o));
|
1275
|
-
}
|
1276
|
-
return _results;
|
1277
|
-
}).call(this))), new Value(new Literal('arguments')));
|
1278
|
-
break;
|
1279
|
-
}
|
1280
|
-
}
|
1281
|
-
_ref2 = this.params;
|
1282
|
-
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
|
1283
|
-
param = _ref2[_j];
|
1284
|
-
if (param.isComplex()) {
|
1285
|
-
val = ref = param.asReference(o);
|
1286
|
-
if (param.value) {
|
1287
|
-
val = new Op('?', ref, param.value);
|
1288
|
-
}
|
1289
|
-
exprs.push(new Assign(new Value(param.name), val, '=', {
|
1290
|
-
param: true
|
1291
|
-
}));
|
1292
|
-
} else {
|
1293
|
-
ref = param;
|
1294
|
-
if (param.value) {
|
1295
|
-
lit = new Literal(ref.name.value + ' == null');
|
1296
|
-
val = new Assign(new Value(param.name), param.value, '=');
|
1297
|
-
exprs.push(new If(lit, val));
|
1298
|
-
}
|
1299
|
-
}
|
1300
|
-
if (!splats) {
|
1301
|
-
vars.push(ref);
|
1302
|
-
}
|
1303
|
-
}
|
1304
|
-
wasEmpty = this.body.isEmpty();
|
1305
|
-
if (splats) {
|
1306
|
-
exprs.unshift(splats);
|
1307
|
-
}
|
1308
|
-
if (exprs.length) {
|
1309
|
-
(_ref3 = this.body.expressions).unshift.apply(_ref3, exprs);
|
1310
|
-
}
|
1311
|
-
if (!splats) {
|
1312
|
-
for (i = 0, _len3 = vars.length; i < _len3; i++) {
|
1313
|
-
v = vars[i];
|
1314
|
-
o.scope.parameter(vars[i] = v.compile(o));
|
1315
|
-
}
|
1316
|
-
}
|
1317
|
-
if (!(wasEmpty || this.noReturn)) {
|
1318
|
-
this.body.makeReturn();
|
1319
|
-
}
|
1320
|
-
idt = o.indent;
|
1321
|
-
code = 'function';
|
1322
|
-
if (this.ctor) {
|
1323
|
-
code += ' ' + this.name;
|
1324
|
-
}
|
1325
|
-
code += '(' + vars.join(', ') + ') {';
|
1326
|
-
if (!this.body.isEmpty()) {
|
1327
|
-
code += "\n" + (this.body.compileWithDeclarations(o)) + "\n" + this.tab;
|
1328
|
-
}
|
1329
|
-
code += '}';
|
1330
|
-
if (this.ctor) {
|
1331
|
-
return this.tab + code;
|
1332
|
-
}
|
1333
|
-
if (this.bound) {
|
1334
|
-
return utility('bind') + ("(" + code + ", " + this.context + ")");
|
1335
|
-
}
|
1336
|
-
if (this.front || (o.level >= LEVEL_ACCESS)) {
|
1337
|
-
return "(" + code + ")";
|
1338
|
-
} else {
|
1339
|
-
return code;
|
1340
|
-
}
|
1341
|
-
};
|
1342
|
-
Code.prototype.traverseChildren = function(crossScope, func) {
|
1343
|
-
if (crossScope) {
|
1344
|
-
return Code.__super__.traverseChildren.call(this, crossScope, func);
|
1345
|
-
}
|
1346
|
-
};
|
1347
|
-
return Code;
|
1348
|
-
})();
|
1349
|
-
exports.Param = Param = (function() {
|
1350
|
-
__extends(Param, Base);
|
1351
|
-
function Param(name, value, splat) {
|
1352
|
-
this.name = name;
|
1353
|
-
this.value = value;
|
1354
|
-
this.splat = splat;
|
1355
|
-
}
|
1356
|
-
Param.prototype.children = ['name', 'value'];
|
1357
|
-
Param.prototype.compile = function(o) {
|
1358
|
-
return this.name.compile(o, LEVEL_LIST);
|
1359
|
-
};
|
1360
|
-
Param.prototype.asReference = function(o) {
|
1361
|
-
var node;
|
1362
|
-
if (this.reference) {
|
1363
|
-
return this.reference;
|
1364
|
-
}
|
1365
|
-
node = this.name;
|
1366
|
-
if (node["this"]) {
|
1367
|
-
node = node.properties[0].name;
|
1368
|
-
if (node.value.reserved) {
|
1369
|
-
node = new Literal('_' + node.value);
|
1370
|
-
}
|
1371
|
-
} else if (node.isComplex()) {
|
1372
|
-
node = new Literal(o.scope.freeVariable('arg'));
|
1373
|
-
}
|
1374
|
-
node = new Value(node);
|
1375
|
-
if (this.splat) {
|
1376
|
-
node = new Splat(node);
|
1377
|
-
}
|
1378
|
-
return this.reference = node;
|
1379
|
-
};
|
1380
|
-
Param.prototype.isComplex = function() {
|
1381
|
-
return this.name.isComplex();
|
1382
|
-
};
|
1383
|
-
return Param;
|
1384
|
-
})();
|
1385
|
-
exports.Splat = Splat = (function() {
|
1386
|
-
__extends(Splat, Base);
|
1387
|
-
Splat.prototype.children = ['name'];
|
1388
|
-
Splat.prototype.isAssignable = YES;
|
1389
|
-
function Splat(name) {
|
1390
|
-
this.name = name.compile ? name : new Literal(name);
|
1391
|
-
}
|
1392
|
-
Splat.prototype.assigns = function(name) {
|
1393
|
-
return this.name.assigns(name);
|
1394
|
-
};
|
1395
|
-
Splat.prototype.compile = function(o) {
|
1396
|
-
if (this.index != null) {
|
1397
|
-
return this.compileParam(o);
|
1398
|
-
} else {
|
1399
|
-
return this.name.compile(o);
|
1400
|
-
}
|
1401
|
-
};
|
1402
|
-
Splat.compileSplattedArray = function(o, list, apply) {
|
1403
|
-
var args, base, code, i, index, node, _len;
|
1404
|
-
index = -1;
|
1405
|
-
while ((node = list[++index]) && !(node instanceof Splat)) {
|
1406
|
-
continue;
|
1407
|
-
}
|
1408
|
-
if (index >= list.length) {
|
1409
|
-
return '';
|
1410
|
-
}
|
1411
|
-
if (list.length === 1) {
|
1412
|
-
code = list[0].compile(o, LEVEL_LIST);
|
1413
|
-
if (apply) {
|
1414
|
-
return code;
|
1415
|
-
}
|
1416
|
-
return "" + (utility('slice')) + ".call(" + code + ")";
|
1417
|
-
}
|
1418
|
-
args = list.slice(index);
|
1419
|
-
for (i = 0, _len = args.length; i < _len; i++) {
|
1420
|
-
node = args[i];
|
1421
|
-
code = node.compile(o, LEVEL_LIST);
|
1422
|
-
args[i] = node instanceof Splat ? "" + (utility('slice')) + ".call(" + code + ")" : "[" + code + "]";
|
1423
|
-
}
|
1424
|
-
if (index === 0) {
|
1425
|
-
return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")");
|
1426
|
-
}
|
1427
|
-
base = (function() {
|
1428
|
-
var _i, _len, _ref, _results;
|
1429
|
-
_ref = list.slice(0, index);
|
1430
|
-
_results = [];
|
1431
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1432
|
-
node = _ref[_i];
|
1433
|
-
_results.push(node.compile(o, LEVEL_LIST));
|
1434
|
-
}
|
1435
|
-
return _results;
|
1436
|
-
})();
|
1437
|
-
return "[" + (base.join(', ')) + "].concat(" + (args.join(', ')) + ")";
|
1438
|
-
};
|
1439
|
-
return Splat;
|
1440
|
-
})();
|
1441
|
-
exports.While = While = (function() {
|
1442
|
-
__extends(While, Base);
|
1443
|
-
function While(condition, options) {
|
1444
|
-
this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition;
|
1445
|
-
this.guard = options != null ? options.guard : void 0;
|
1446
|
-
}
|
1447
|
-
While.prototype.children = ['condition', 'guard', 'body'];
|
1448
|
-
While.prototype.isStatement = YES;
|
1449
|
-
While.prototype.makeReturn = function() {
|
1450
|
-
this.returns = true;
|
1451
|
-
return this;
|
1452
|
-
};
|
1453
|
-
While.prototype.addBody = function(body) {
|
1454
|
-
this.body = body;
|
1455
|
-
return this;
|
1456
|
-
};
|
1457
|
-
While.prototype.jumps = function() {
|
1458
|
-
var expressions, node, _i, _len;
|
1459
|
-
expressions = this.body.expressions;
|
1460
|
-
if (!expressions.length) {
|
1461
|
-
return false;
|
1462
|
-
}
|
1463
|
-
for (_i = 0, _len = expressions.length; _i < _len; _i++) {
|
1464
|
-
node = expressions[_i];
|
1465
|
-
if (node.jumps({
|
1466
|
-
loop: true
|
1467
|
-
})) {
|
1468
|
-
return node;
|
1469
|
-
}
|
1470
|
-
}
|
1471
|
-
return false;
|
1472
|
-
};
|
1473
|
-
While.prototype.compileNode = function(o) {
|
1474
|
-
var body, code, rvar, set;
|
1475
|
-
o.indent += TAB;
|
1476
|
-
set = '';
|
1477
|
-
body = this.body;
|
1478
|
-
if (body.isEmpty()) {
|
1479
|
-
body = '';
|
1480
|
-
} else {
|
1481
|
-
if (o.level > LEVEL_TOP || this.returns) {
|
1482
|
-
rvar = o.scope.freeVariable('results');
|
1483
|
-
set = "" + this.tab + rvar + " = [];\n";
|
1484
|
-
if (body) {
|
1485
|
-
body = Push.wrap(rvar, body);
|
1486
|
-
}
|
1487
|
-
}
|
1488
|
-
if (this.guard) {
|
1489
|
-
body = Expressions.wrap([new If(this.guard, body)]);
|
1490
|
-
}
|
1491
|
-
body = "\n" + (body.compile(o, LEVEL_TOP)) + "\n" + this.tab;
|
1492
|
-
}
|
1493
|
-
code = set + this.tab + ("while (" + (this.condition.compile(o, LEVEL_PAREN)) + ") {" + body + "}");
|
1494
|
-
if (this.returns) {
|
1495
|
-
code += "\n" + this.tab + "return " + rvar + ";";
|
1496
|
-
}
|
1497
|
-
return code;
|
1498
|
-
};
|
1499
|
-
return While;
|
1500
|
-
})();
|
1501
|
-
exports.Op = Op = (function() {
|
1502
|
-
var CONVERSIONS, INVERSIONS;
|
1503
|
-
__extends(Op, Base);
|
1504
|
-
function Op(op, first, second, flip) {
|
1505
|
-
if (op === 'in') {
|
1506
|
-
return new In(first, second);
|
1507
|
-
}
|
1508
|
-
if (op === 'do') {
|
1509
|
-
return new Call(first, first.params || []);
|
1510
|
-
}
|
1511
|
-
if (op === 'new') {
|
1512
|
-
if (first instanceof Call) {
|
1513
|
-
return first.newInstance();
|
1514
|
-
}
|
1515
|
-
if (first instanceof Code && first.bound) {
|
1516
|
-
first = new Parens(first);
|
1517
|
-
}
|
1518
|
-
}
|
1519
|
-
this.operator = CONVERSIONS[op] || op;
|
1520
|
-
this.first = first;
|
1521
|
-
this.second = second;
|
1522
|
-
this.flip = !!flip;
|
1523
|
-
return this;
|
1524
|
-
}
|
1525
|
-
CONVERSIONS = {
|
1526
|
-
'==': '===',
|
1527
|
-
'!=': '!==',
|
1528
|
-
'of': 'in'
|
1529
|
-
};
|
1530
|
-
INVERSIONS = {
|
1531
|
-
'!==': '===',
|
1532
|
-
'===': '!=='
|
1533
|
-
};
|
1534
|
-
Op.prototype.children = ['first', 'second'];
|
1535
|
-
Op.prototype.isSimpleNumber = NO;
|
1536
|
-
Op.prototype.isUnary = function() {
|
1537
|
-
return !this.second;
|
1538
|
-
};
|
1539
|
-
Op.prototype.isChainable = function() {
|
1540
|
-
var _ref;
|
1541
|
-
return (_ref = this.operator) === '<' || _ref === '>' || _ref === '>=' || _ref === '<=' || _ref === '===' || _ref === '!==';
|
1542
|
-
};
|
1543
|
-
Op.prototype.invert = function() {
|
1544
|
-
var allInvertable, curr, fst, op, _ref;
|
1545
|
-
if (this.isChainable() && this.first.isChainable()) {
|
1546
|
-
allInvertable = true;
|
1547
|
-
curr = this;
|
1548
|
-
while (curr && curr.operator) {
|
1549
|
-
allInvertable && (allInvertable = curr.operator in INVERSIONS);
|
1550
|
-
curr = curr.first;
|
1551
|
-
}
|
1552
|
-
if (!allInvertable) {
|
1553
|
-
return new Parens(this).invert();
|
1554
|
-
}
|
1555
|
-
curr = this;
|
1556
|
-
while (curr && curr.operator) {
|
1557
|
-
curr.invert = !curr.invert;
|
1558
|
-
curr.operator = INVERSIONS[curr.operator];
|
1559
|
-
curr = curr.first;
|
1560
|
-
}
|
1561
|
-
return this;
|
1562
|
-
} else if (op = INVERSIONS[this.operator]) {
|
1563
|
-
this.operator = op;
|
1564
|
-
if (this.first.unwrap() instanceof Op) {
|
1565
|
-
this.first.invert();
|
1566
|
-
}
|
1567
|
-
return this;
|
1568
|
-
} else if (this.second) {
|
1569
|
-
return new Parens(this).invert();
|
1570
|
-
} else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref = fst.operator) === '!' || _ref === 'in' || _ref === 'instanceof')) {
|
1571
|
-
return fst;
|
1572
|
-
} else {
|
1573
|
-
return new Op('!', this);
|
1574
|
-
}
|
1575
|
-
};
|
1576
|
-
Op.prototype.unfoldSoak = function(o) {
|
1577
|
-
var _ref;
|
1578
|
-
return ((_ref = this.operator) === '++' || _ref === '--' || _ref === 'delete') && unfoldSoak(o, this, 'first');
|
1579
|
-
};
|
1580
|
-
Op.prototype.compileNode = function(o) {
|
1581
|
-
var code;
|
1582
|
-
if (this.isUnary()) {
|
1583
|
-
return this.compileUnary(o);
|
1584
|
-
}
|
1585
|
-
if (this.isChainable() && this.first.isChainable()) {
|
1586
|
-
return this.compileChain(o);
|
1587
|
-
}
|
1588
|
-
if (this.operator === '?') {
|
1589
|
-
return this.compileExistence(o);
|
1590
|
-
}
|
1591
|
-
this.first.front = this.front;
|
1592
|
-
code = this.first.compile(o, LEVEL_OP) + ' ' + this.operator + ' ' + this.second.compile(o, LEVEL_OP);
|
1593
|
-
if (o.level <= LEVEL_OP) {
|
1594
|
-
return code;
|
1595
|
-
} else {
|
1596
|
-
return "(" + code + ")";
|
1597
|
-
}
|
1598
|
-
};
|
1599
|
-
Op.prototype.compileChain = function(o) {
|
1600
|
-
var code, fst, shared, _ref;
|
1601
|
-
_ref = this.first.second.cache(o), this.first.second = _ref[0], shared = _ref[1];
|
1602
|
-
fst = this.first.compile(o, LEVEL_OP);
|
1603
|
-
code = "" + fst + " " + (this.invert ? '&&' : '||') + " " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP));
|
1604
|
-
return "(" + code + ")";
|
1605
|
-
};
|
1606
|
-
Op.prototype.compileExistence = function(o) {
|
1607
|
-
var fst, ref;
|
1608
|
-
if (this.first.isComplex()) {
|
1609
|
-
ref = o.scope.freeVariable('ref');
|
1610
|
-
fst = new Parens(new Assign(new Literal(ref), this.first));
|
1611
|
-
} else {
|
1612
|
-
fst = this.first;
|
1613
|
-
ref = fst.compile(o);
|
1614
|
-
}
|
1615
|
-
return new Existence(fst).compile(o) + (" ? " + ref + " : " + (this.second.compile(o, LEVEL_LIST)));
|
1616
|
-
};
|
1617
|
-
Op.prototype.compileUnary = function(o) {
|
1618
|
-
var op, parts;
|
1619
|
-
parts = [op = this.operator];
|
1620
|
-
if ((op === 'new' || op === 'typeof' || op === 'delete') || (op === '+' || op === '-') && this.first instanceof Op && this.first.operator === op) {
|
1621
|
-
parts.push(' ');
|
1622
|
-
}
|
1623
|
-
parts.push(this.first.compile(o, LEVEL_OP));
|
1624
|
-
if (this.flip) {
|
1625
|
-
parts.reverse();
|
1626
|
-
}
|
1627
|
-
return parts.join('');
|
1628
|
-
};
|
1629
|
-
Op.prototype.toString = function(idt) {
|
1630
|
-
return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
|
1631
|
-
};
|
1632
|
-
return Op;
|
1633
|
-
})();
|
1634
|
-
exports.In = In = (function() {
|
1635
|
-
__extends(In, Base);
|
1636
|
-
function In(object, array) {
|
1637
|
-
this.object = object;
|
1638
|
-
this.array = array;
|
1639
|
-
}
|
1640
|
-
In.prototype.children = ['object', 'array'];
|
1641
|
-
In.prototype.invert = NEGATE;
|
1642
|
-
In.prototype.compileNode = function(o) {
|
1643
|
-
if (this.array instanceof Value && this.array.isArray()) {
|
1644
|
-
return this.compileOrTest(o);
|
1645
|
-
} else {
|
1646
|
-
return this.compileLoopTest(o);
|
1647
|
-
}
|
1648
|
-
};
|
1649
|
-
In.prototype.compileOrTest = function(o) {
|
1650
|
-
var cmp, cnj, i, item, ref, sub, tests, _ref, _ref2;
|
1651
|
-
_ref = this.object.cache(o, LEVEL_OP), sub = _ref[0], ref = _ref[1];
|
1652
|
-
_ref2 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref2[0], cnj = _ref2[1];
|
1653
|
-
tests = (function() {
|
1654
|
-
var _len, _ref, _results;
|
1655
|
-
_ref = this.array.base.objects;
|
1656
|
-
_results = [];
|
1657
|
-
for (i = 0, _len = _ref.length; i < _len; i++) {
|
1658
|
-
item = _ref[i];
|
1659
|
-
_results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_OP));
|
1660
|
-
}
|
1661
|
-
return _results;
|
1662
|
-
}).call(this);
|
1663
|
-
tests = tests.join(cnj);
|
1664
|
-
if (o.level < LEVEL_OP) {
|
1665
|
-
return tests;
|
1666
|
-
} else {
|
1667
|
-
return "(" + tests + ")";
|
1668
|
-
}
|
1669
|
-
};
|
1670
|
-
In.prototype.compileLoopTest = function(o) {
|
1671
|
-
var code, ref, sub, _ref;
|
1672
|
-
_ref = this.object.cache(o, LEVEL_LIST), sub = _ref[0], ref = _ref[1];
|
1673
|
-
code = utility('indexOf') + (".call(" + (this.array.compile(o, LEVEL_LIST)) + ", " + ref + ") ") + (this.negated ? '< 0' : '>= 0');
|
1674
|
-
if (sub === ref) {
|
1675
|
-
return code;
|
1676
|
-
}
|
1677
|
-
code = sub + ', ' + code;
|
1678
|
-
if (o.level < LEVEL_LIST) {
|
1679
|
-
return code;
|
1680
|
-
} else {
|
1681
|
-
return "(" + code + ")";
|
1682
|
-
}
|
1683
|
-
};
|
1684
|
-
In.prototype.toString = function(idt) {
|
1685
|
-
return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : ''));
|
1686
|
-
};
|
1687
|
-
return In;
|
1688
|
-
})();
|
1689
|
-
exports.Try = Try = (function() {
|
1690
|
-
__extends(Try, Base);
|
1691
|
-
function Try(attempt, error, recovery, ensure) {
|
1692
|
-
this.attempt = attempt;
|
1693
|
-
this.error = error;
|
1694
|
-
this.recovery = recovery;
|
1695
|
-
this.ensure = ensure;
|
1696
|
-
}
|
1697
|
-
Try.prototype.children = ['attempt', 'recovery', 'ensure'];
|
1698
|
-
Try.prototype.isStatement = YES;
|
1699
|
-
Try.prototype.jumps = function(o) {
|
1700
|
-
var _ref;
|
1701
|
-
return this.attempt.jumps(o) || ((_ref = this.recovery) != null ? _ref.jumps(o) : void 0);
|
1702
|
-
};
|
1703
|
-
Try.prototype.makeReturn = function() {
|
1704
|
-
if (this.attempt) {
|
1705
|
-
this.attempt = this.attempt.makeReturn();
|
1706
|
-
}
|
1707
|
-
if (this.recovery) {
|
1708
|
-
this.recovery = this.recovery.makeReturn();
|
1709
|
-
}
|
1710
|
-
return this;
|
1711
|
-
};
|
1712
|
-
Try.prototype.compileNode = function(o) {
|
1713
|
-
var catchPart, errorPart;
|
1714
|
-
o.indent += TAB;
|
1715
|
-
errorPart = this.error ? " (" + (this.error.compile(o)) + ") " : ' ';
|
1716
|
-
catchPart = this.recovery ? " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : !(this.ensure || this.recovery) ? ' catch (_e) {}' : void 0;
|
1717
|
-
return ("" + this.tab + "try {\n" + (this.attempt.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" + (catchPart || '')) + (this.ensure ? " finally {\n" + (this.ensure.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : '');
|
1718
|
-
};
|
1719
|
-
return Try;
|
1720
|
-
})();
|
1721
|
-
exports.Throw = Throw = (function() {
|
1722
|
-
__extends(Throw, Base);
|
1723
|
-
function Throw(expression) {
|
1724
|
-
this.expression = expression;
|
1725
|
-
}
|
1726
|
-
Throw.prototype.children = ['expression'];
|
1727
|
-
Throw.prototype.isStatement = YES;
|
1728
|
-
Throw.prototype.jumps = NO;
|
1729
|
-
Throw.prototype.makeReturn = THIS;
|
1730
|
-
Throw.prototype.compileNode = function(o) {
|
1731
|
-
return this.tab + ("throw " + (this.expression.compile(o)) + ";");
|
1732
|
-
};
|
1733
|
-
return Throw;
|
1734
|
-
})();
|
1735
|
-
exports.Existence = Existence = (function() {
|
1736
|
-
__extends(Existence, Base);
|
1737
|
-
function Existence(expression) {
|
1738
|
-
this.expression = expression;
|
1739
|
-
}
|
1740
|
-
Existence.prototype.children = ['expression'];
|
1741
|
-
Existence.prototype.invert = NEGATE;
|
1742
|
-
Existence.prototype.compileNode = function(o) {
|
1743
|
-
var code, sym;
|
1744
|
-
code = this.expression.compile(o, LEVEL_OP);
|
1745
|
-
code = IDENTIFIER.test(code) && !o.scope.check(code) ? this.negated ? "typeof " + code + " == \"undefined\" || " + code + " === null" : "typeof " + code + " != \"undefined\" && " + code + " !== null" : (sym = this.negated ? '==' : '!=', "" + code + " " + sym + " null");
|
1746
|
-
if (o.level <= LEVEL_COND) {
|
1747
|
-
return code;
|
1748
|
-
} else {
|
1749
|
-
return "(" + code + ")";
|
1750
|
-
}
|
1751
|
-
};
|
1752
|
-
return Existence;
|
1753
|
-
})();
|
1754
|
-
exports.Parens = Parens = (function() {
|
1755
|
-
__extends(Parens, Base);
|
1756
|
-
function Parens(body) {
|
1757
|
-
this.body = body;
|
1758
|
-
}
|
1759
|
-
Parens.prototype.children = ['body'];
|
1760
|
-
Parens.prototype.unwrap = function() {
|
1761
|
-
return this.body;
|
1762
|
-
};
|
1763
|
-
Parens.prototype.isComplex = function() {
|
1764
|
-
return this.body.isComplex();
|
1765
|
-
};
|
1766
|
-
Parens.prototype.makeReturn = function() {
|
1767
|
-
return this.body.makeReturn();
|
1768
|
-
};
|
1769
|
-
Parens.prototype.compileNode = function(o) {
|
1770
|
-
var bare, code, expr;
|
1771
|
-
expr = this.body.unwrap();
|
1772
|
-
if (expr instanceof Value && expr.isAtomic()) {
|
1773
|
-
expr.front = this.front;
|
1774
|
-
return expr.compile(o);
|
1775
|
-
}
|
1776
|
-
code = expr.compile(o, LEVEL_PAREN);
|
1777
|
-
bare = o.level < LEVEL_OP && (expr instanceof Op || expr instanceof Call || (expr instanceof For && expr.returns));
|
1778
|
-
if (bare) {
|
1779
|
-
return code;
|
1780
|
-
} else {
|
1781
|
-
return "(" + code + ")";
|
1782
|
-
}
|
1783
|
-
};
|
1784
|
-
return Parens;
|
1785
|
-
})();
|
1786
|
-
exports.For = For = (function() {
|
1787
|
-
__extends(For, Base);
|
1788
|
-
function For(body, source) {
|
1789
|
-
var _ref;
|
1790
|
-
this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;
|
1791
|
-
this.body = Expressions.wrap([body]);
|
1792
|
-
this.own = !!source.own;
|
1793
|
-
this.object = !!source.object;
|
1794
|
-
if (this.object) {
|
1795
|
-
_ref = [this.index, this.name], this.name = _ref[0], this.index = _ref[1];
|
1796
|
-
}
|
1797
|
-
if (this.index instanceof Value) {
|
1798
|
-
throw SyntaxError('index cannot be a pattern matching expression');
|
1799
|
-
}
|
1800
|
-
this.range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
|
1801
|
-
this.pattern = this.name instanceof Value;
|
1802
|
-
if (this.range && this.index) {
|
1803
|
-
throw SyntaxError('indexes do not apply to range loops');
|
1804
|
-
}
|
1805
|
-
if (this.range && this.pattern) {
|
1806
|
-
throw SyntaxError('cannot pattern match over range loops');
|
1807
|
-
}
|
1808
|
-
this.returns = false;
|
1809
|
-
}
|
1810
|
-
For.prototype.children = ['body', 'source', 'guard', 'step'];
|
1811
|
-
For.prototype.isStatement = YES;
|
1812
|
-
For.prototype.jumps = While.prototype.jumps;
|
1813
|
-
For.prototype.makeReturn = function() {
|
1814
|
-
this.returns = true;
|
1815
|
-
return this;
|
1816
|
-
};
|
1817
|
-
For.prototype.compileNode = function(o) {
|
1818
|
-
var body, defPart, forPart, guardPart, idt1, index, ivar, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, svar, varPart, _ref;
|
1819
|
-
body = Expressions.wrap([this.body]);
|
1820
|
-
lastJumps = (_ref = last(body.expressions)) != null ? _ref.jumps() : void 0;
|
1821
|
-
if (lastJumps && lastJumps instanceof Return) {
|
1822
|
-
this.returns = false;
|
1823
|
-
}
|
1824
|
-
source = this.range ? this.source.base : this.source;
|
1825
|
-
scope = o.scope;
|
1826
|
-
name = this.name && this.name.compile(o, LEVEL_LIST);
|
1827
|
-
index = this.index && this.index.compile(o, LEVEL_LIST);
|
1828
|
-
if (name && !this.pattern) {
|
1829
|
-
scope.find(name, {
|
1830
|
-
immediate: true
|
1831
|
-
});
|
1832
|
-
}
|
1833
|
-
if (index) {
|
1834
|
-
scope.find(index, {
|
1835
|
-
immediate: true
|
1836
|
-
});
|
1837
|
-
}
|
1838
|
-
if (this.returns) {
|
1839
|
-
rvar = scope.freeVariable('results');
|
1840
|
-
}
|
1841
|
-
ivar = (this.range ? name : index) || scope.freeVariable('i');
|
1842
|
-
if (this.pattern) {
|
1843
|
-
name = ivar;
|
1844
|
-
}
|
1845
|
-
varPart = '';
|
1846
|
-
guardPart = '';
|
1847
|
-
defPart = '';
|
1848
|
-
idt1 = this.tab + TAB;
|
1849
|
-
if (this.range) {
|
1850
|
-
forPart = source.compile(merge(o, {
|
1851
|
-
index: ivar,
|
1852
|
-
step: this.step
|
1853
|
-
}));
|
1854
|
-
} else {
|
1855
|
-
svar = this.source.compile(o, LEVEL_LIST);
|
1856
|
-
if ((name || this.own) && !IDENTIFIER.test(svar)) {
|
1857
|
-
defPart = "" + this.tab + (ref = scope.freeVariable('ref')) + " = " + svar + ";\n";
|
1858
|
-
svar = ref;
|
1859
|
-
}
|
1860
|
-
if (name && !this.pattern) {
|
1861
|
-
namePart = "" + name + " = " + svar + "[" + ivar + "]";
|
1862
|
-
}
|
1863
|
-
if (!this.object) {
|
1864
|
-
lvar = scope.freeVariable('len');
|
1865
|
-
stepPart = this.step ? "" + ivar + " += " + (this.step.compile(o, LEVEL_OP)) : "" + ivar + "++";
|
1866
|
-
forPart = "" + ivar + " = 0, " + lvar + " = " + svar + ".length; " + ivar + " < " + lvar + "; " + stepPart;
|
1867
|
-
}
|
1868
|
-
}
|
1869
|
-
if (this.returns) {
|
1870
|
-
resultPart = "" + this.tab + rvar + " = [];\n";
|
1871
|
-
returnResult = "\n" + this.tab + "return " + rvar + ";";
|
1872
|
-
body = Push.wrap(rvar, body);
|
1873
|
-
}
|
1874
|
-
if (this.guard) {
|
1875
|
-
body = Expressions.wrap([new If(this.guard, body)]);
|
1876
|
-
}
|
1877
|
-
if (this.pattern) {
|
1878
|
-
body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + ivar + "]")));
|
1879
|
-
}
|
1880
|
-
defPart += this.pluckDirectCall(o, body);
|
1881
|
-
if (namePart) {
|
1882
|
-
varPart = "\n" + idt1 + namePart + ";";
|
1883
|
-
}
|
1884
|
-
if (this.object) {
|
1885
|
-
forPart = "" + ivar + " in " + svar;
|
1886
|
-
if (this.own) {
|
1887
|
-
guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;";
|
1888
|
-
}
|
1889
|
-
}
|
1890
|
-
body = body.compile(merge(o, {
|
1891
|
-
indent: idt1
|
1892
|
-
}), LEVEL_TOP);
|
1893
|
-
if (body) {
|
1894
|
-
body = '\n' + body + '\n';
|
1895
|
-
}
|
1896
|
-
return "" + defPart + (resultPart || '') + this.tab + "for (" + forPart + ") {" + guardPart + varPart + body + this.tab + "}" + (returnResult || '');
|
1897
|
-
};
|
1898
|
-
For.prototype.pluckDirectCall = function(o, body) {
|
1899
|
-
var base, defs, expr, fn, idx, ref, val, _len, _ref, _ref2, _ref3, _ref4, _ref5, _ref6;
|
1900
|
-
defs = '';
|
1901
|
-
_ref = body.expressions;
|
1902
|
-
for (idx = 0, _len = _ref.length; idx < _len; idx++) {
|
1903
|
-
expr = _ref[idx];
|
1904
|
-
expr = expr.unwrapAll();
|
1905
|
-
if (!(expr instanceof Call)) {
|
1906
|
-
continue;
|
1907
|
-
}
|
1908
|
-
val = expr.variable.unwrapAll();
|
1909
|
-
if (!((val instanceof Code) || (val instanceof Value && ((_ref2 = val.base) != null ? _ref2.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref3 = (_ref4 = val.properties[0].name) != null ? _ref4.value : void 0) === 'call' || _ref3 === 'apply')))) {
|
1910
|
-
continue;
|
1911
|
-
}
|
1912
|
-
fn = ((_ref5 = val.base) != null ? _ref5.unwrapAll() : void 0) || val;
|
1913
|
-
ref = new Literal(o.scope.freeVariable('fn'));
|
1914
|
-
base = new Value(ref);
|
1915
|
-
if (val.base) {
|
1916
|
-
_ref6 = [base, val], val.base = _ref6[0], base = _ref6[1];
|
1917
|
-
args.unshift(new Literal('this'));
|
1918
|
-
}
|
1919
|
-
body.expressions[idx] = new Call(base, expr.args);
|
1920
|
-
defs += this.tab + new Assign(ref, fn).compile(o, LEVEL_TOP) + ';\n';
|
1921
|
-
}
|
1922
|
-
return defs;
|
1923
|
-
};
|
1924
|
-
return For;
|
1925
|
-
})();
|
1926
|
-
exports.Switch = Switch = (function() {
|
1927
|
-
__extends(Switch, Base);
|
1928
|
-
function Switch(subject, cases, otherwise) {
|
1929
|
-
this.subject = subject;
|
1930
|
-
this.cases = cases;
|
1931
|
-
this.otherwise = otherwise;
|
1932
|
-
}
|
1933
|
-
Switch.prototype.children = ['subject', 'cases', 'otherwise'];
|
1934
|
-
Switch.prototype.isStatement = YES;
|
1935
|
-
Switch.prototype.jumps = function(o) {
|
1936
|
-
var block, conds, _i, _len, _ref, _ref2, _ref3;
|
1937
|
-
if (o == null) {
|
1938
|
-
o = {
|
1939
|
-
block: true
|
1940
|
-
};
|
1941
|
-
}
|
1942
|
-
_ref = this.cases;
|
1943
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1944
|
-
_ref2 = _ref[_i], conds = _ref2[0], block = _ref2[1];
|
1945
|
-
if (block.jumps(o)) {
|
1946
|
-
return block;
|
1947
|
-
}
|
1948
|
-
}
|
1949
|
-
return (_ref3 = this.otherwise) != null ? _ref3.jumps(o) : void 0;
|
1950
|
-
};
|
1951
|
-
Switch.prototype.makeReturn = function() {
|
1952
|
-
var pair, _i, _len, _ref, _ref2;
|
1953
|
-
_ref = this.cases;
|
1954
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1955
|
-
pair = _ref[_i];
|
1956
|
-
pair[1].makeReturn();
|
1957
|
-
}
|
1958
|
-
if ((_ref2 = this.otherwise) != null) {
|
1959
|
-
_ref2.makeReturn();
|
1960
|
-
}
|
1961
|
-
return this;
|
1962
|
-
};
|
1963
|
-
Switch.prototype.compileNode = function(o) {
|
1964
|
-
var block, body, code, cond, conditions, expr, i, idt1, idt2, jumper, _i, _len, _len2, _ref, _ref2, _ref3, _ref4;
|
1965
|
-
idt1 = o.indent + TAB;
|
1966
|
-
idt2 = o.indent = idt1 + TAB;
|
1967
|
-
code = this.tab + ("switch (" + (((_ref = this.subject) != null ? _ref.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n");
|
1968
|
-
_ref2 = this.cases;
|
1969
|
-
for (i = 0, _len = _ref2.length; i < _len; i++) {
|
1970
|
-
_ref3 = _ref2[i], conditions = _ref3[0], block = _ref3[1];
|
1971
|
-
_ref4 = flatten([conditions]);
|
1972
|
-
for (_i = 0, _len2 = _ref4.length; _i < _len2; _i++) {
|
1973
|
-
cond = _ref4[_i];
|
1974
|
-
if (!this.subject) {
|
1975
|
-
cond = cond.invert();
|
1976
|
-
}
|
1977
|
-
code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n");
|
1978
|
-
}
|
1979
|
-
if (body = block.compile(o, LEVEL_TOP)) {
|
1980
|
-
code += body + '\n';
|
1981
|
-
}
|
1982
|
-
if (i === this.cases.length - 1 && !this.otherwise) {
|
1983
|
-
break;
|
1984
|
-
}
|
1985
|
-
expr = this.lastNonComment(block.expressions);
|
1986
|
-
jumper = expr.jumps();
|
1987
|
-
if (!expr || !jumper || (jumper instanceof Literal && jumper.value === 'debugger')) {
|
1988
|
-
code += idt2 + 'break;\n';
|
1989
|
-
}
|
1990
|
-
}
|
1991
|
-
if (this.otherwise && this.otherwise.expressions.length) {
|
1992
|
-
code += idt1 + ("default:\n" + (this.otherwise.compile(o, LEVEL_TOP)) + "\n");
|
1993
|
-
}
|
1994
|
-
return code + this.tab + '}';
|
1995
|
-
};
|
1996
|
-
return Switch;
|
1997
|
-
})();
|
1998
|
-
exports.If = If = (function() {
|
1999
|
-
__extends(If, Base);
|
2000
|
-
function If(condition, body, options) {
|
2001
|
-
this.body = body;
|
2002
|
-
if (options == null) {
|
2003
|
-
options = {};
|
2004
|
-
}
|
2005
|
-
this.condition = options.type === 'unless' ? condition.invert() : condition;
|
2006
|
-
this.elseBody = null;
|
2007
|
-
this.isChain = false;
|
2008
|
-
this.soak = options.soak;
|
2009
|
-
}
|
2010
|
-
If.prototype.children = ['condition', 'body', 'elseBody'];
|
2011
|
-
If.prototype.bodyNode = function() {
|
2012
|
-
var _ref;
|
2013
|
-
return (_ref = this.body) != null ? _ref.unwrap() : void 0;
|
2014
|
-
};
|
2015
|
-
If.prototype.elseBodyNode = function() {
|
2016
|
-
var _ref;
|
2017
|
-
return (_ref = this.elseBody) != null ? _ref.unwrap() : void 0;
|
2018
|
-
};
|
2019
|
-
If.prototype.addElse = function(elseBody) {
|
2020
|
-
if (this.isChain) {
|
2021
|
-
this.elseBodyNode().addElse(elseBody);
|
2022
|
-
} else {
|
2023
|
-
this.isChain = elseBody instanceof If;
|
2024
|
-
this.elseBody = this.ensureExpressions(elseBody);
|
2025
|
-
}
|
2026
|
-
return this;
|
2027
|
-
};
|
2028
|
-
If.prototype.isStatement = function(o) {
|
2029
|
-
var _ref;
|
2030
|
-
return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref = this.elseBodyNode()) != null ? _ref.isStatement(o) : void 0);
|
2031
|
-
};
|
2032
|
-
If.prototype.jumps = function(o) {
|
2033
|
-
var _ref;
|
2034
|
-
return this.body.jumps(o) || ((_ref = this.elseBody) != null ? _ref.jumps(o) : void 0);
|
2035
|
-
};
|
2036
|
-
If.prototype.compileNode = function(o) {
|
2037
|
-
if (this.isStatement(o)) {
|
2038
|
-
return this.compileStatement(o);
|
2039
|
-
} else {
|
2040
|
-
return this.compileExpression(o);
|
2041
|
-
}
|
2042
|
-
};
|
2043
|
-
If.prototype.makeReturn = function() {
|
2044
|
-
this.body && (this.body = new Expressions([this.body.makeReturn()]));
|
2045
|
-
this.elseBody && (this.elseBody = new Expressions([this.elseBody.makeReturn()]));
|
2046
|
-
return this;
|
2047
|
-
};
|
2048
|
-
If.prototype.ensureExpressions = function(node) {
|
2049
|
-
if (node instanceof Expressions) {
|
2050
|
-
return node;
|
2051
|
-
} else {
|
2052
|
-
return new Expressions([node]);
|
2053
|
-
}
|
2054
|
-
};
|
2055
|
-
If.prototype.compileStatement = function(o) {
|
2056
|
-
var body, child, cond, ifPart;
|
2057
|
-
child = del(o, 'chainChild');
|
2058
|
-
cond = this.condition.compile(o, LEVEL_PAREN);
|
2059
|
-
o.indent += TAB;
|
2060
|
-
body = this.ensureExpressions(this.body).compile(o);
|
2061
|
-
if (body) {
|
2062
|
-
body = "\n" + body + "\n" + this.tab;
|
2063
|
-
}
|
2064
|
-
ifPart = "if (" + cond + ") {" + body + "}";
|
2065
|
-
if (!child) {
|
2066
|
-
ifPart = this.tab + ifPart;
|
2067
|
-
}
|
2068
|
-
if (!this.elseBody) {
|
2069
|
-
return ifPart;
|
2070
|
-
}
|
2071
|
-
return ifPart + ' else ' + (this.isChain ? (o.indent = this.tab, o.chainChild = true, this.elseBody.unwrap().compile(o, LEVEL_TOP)) : "{\n" + (this.elseBody.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}");
|
2072
|
-
};
|
2073
|
-
If.prototype.compileExpression = function(o) {
|
2074
|
-
var alt, body, code, cond;
|
2075
|
-
cond = this.condition.compile(o, LEVEL_COND);
|
2076
|
-
body = this.bodyNode().compile(o, LEVEL_LIST);
|
2077
|
-
alt = this.elseBodyNode() ? this.elseBodyNode().compile(o, LEVEL_LIST) : 'void 0';
|
2078
|
-
code = "" + cond + " ? " + body + " : " + alt;
|
2079
|
-
if (o.level >= LEVEL_COND) {
|
2080
|
-
return "(" + code + ")";
|
2081
|
-
} else {
|
2082
|
-
return code;
|
2083
|
-
}
|
2084
|
-
};
|
2085
|
-
If.prototype.unfoldSoak = function() {
|
2086
|
-
return this.soak && this;
|
2087
|
-
};
|
2088
|
-
return If;
|
2089
|
-
})();
|
2090
|
-
Push = {
|
2091
|
-
wrap: function(name, exps) {
|
2092
|
-
if (exps.isEmpty() || last(exps.expressions).jumps()) {
|
2093
|
-
return exps;
|
2094
|
-
}
|
2095
|
-
return exps.push(new Call(new Value(new Literal(name), [new Access(new Literal('push'))]), [exps.pop()]));
|
2096
|
-
}
|
2097
|
-
};
|
2098
|
-
Closure = {
|
2099
|
-
wrap: function(expressions, statement, noReturn) {
|
2100
|
-
var args, call, func, mentionsArgs, meth;
|
2101
|
-
if (expressions.jumps()) {
|
2102
|
-
return expressions;
|
2103
|
-
}
|
2104
|
-
func = new Code([], Expressions.wrap([expressions]));
|
2105
|
-
args = [];
|
2106
|
-
if ((mentionsArgs = expressions.contains(this.literalArgs)) || (expressions.contains(this.literalThis))) {
|
2107
|
-
meth = new Literal(mentionsArgs ? 'apply' : 'call');
|
2108
|
-
args = [new Literal('this')];
|
2109
|
-
if (mentionsArgs) {
|
2110
|
-
args.push(new Literal('arguments'));
|
2111
|
-
}
|
2112
|
-
func = new Value(func, [new Access(meth)]);
|
2113
|
-
}
|
2114
|
-
func.noReturn = noReturn;
|
2115
|
-
call = new Call(func, args);
|
2116
|
-
if (statement) {
|
2117
|
-
return Expressions.wrap([call]);
|
2118
|
-
} else {
|
2119
|
-
return call;
|
2120
|
-
}
|
2121
|
-
},
|
2122
|
-
literalArgs: function(node) {
|
2123
|
-
return node instanceof Literal && node.value === 'arguments' && !node.asKey;
|
2124
|
-
},
|
2125
|
-
literalThis: function(node) {
|
2126
|
-
return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound);
|
2127
|
-
}
|
2128
|
-
};
|
2129
|
-
unfoldSoak = function(o, parent, name) {
|
2130
|
-
var ifn;
|
2131
|
-
if (!(ifn = parent[name].unfoldSoak(o))) {
|
2132
|
-
return;
|
2133
|
-
}
|
2134
|
-
parent[name] = ifn.body;
|
2135
|
-
ifn.body = new Value(parent);
|
2136
|
-
return ifn;
|
2137
|
-
};
|
2138
|
-
UTILITIES = {
|
2139
|
-
"extends": 'function(child, parent) {\n for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n child.__super__ = parent.prototype;\n return child;\n}',
|
2140
|
-
bind: 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }',
|
2141
|
-
indexOf: 'Array.prototype.indexOf || function(item) {\n for (var i = 0, l = this.length; i < l; i++) {\n if (this[i] === item) return i;\n }\n return -1;\n}',
|
2142
|
-
hasProp: 'Object.prototype.hasOwnProperty',
|
2143
|
-
slice: 'Array.prototype.slice'
|
2144
|
-
};
|
2145
|
-
LEVEL_TOP = 1;
|
2146
|
-
LEVEL_PAREN = 2;
|
2147
|
-
LEVEL_LIST = 3;
|
2148
|
-
LEVEL_COND = 4;
|
2149
|
-
LEVEL_OP = 5;
|
2150
|
-
LEVEL_ACCESS = 6;
|
2151
|
-
TAB = ' ';
|
2152
|
-
TRAILING_WHITESPACE = /[ \t]+$/gm;
|
2153
|
-
IDENTIFIER = /^[$A-Za-z_][$\w]*$/;
|
2154
|
-
SIMPLENUM = /^[+-]?\d+$/;
|
2155
|
-
IS_STRING = /^['"]/;
|
2156
|
-
utility = function(name) {
|
2157
|
-
var ref;
|
2158
|
-
ref = "__" + name;
|
2159
|
-
Scope.root.assign(ref, UTILITIES[name]);
|
2160
|
-
return ref;
|
2161
|
-
};
|
2162
|
-
multident = function(code, tab) {
|
2163
|
-
return code.replace(/\n/g, '$&' + tab);
|
2164
|
-
};
|
2165
|
-
}).call(this);
|