vulcan 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vulcan/cli.rb +20 -10
- data/lib/vulcan/version.rb +1 -1
- data/server/Procfile +1 -1
- data/server/bin/web +10 -0
- data/server/lib/cloudant.coffee +20 -0
- data/server/lib/logger.coffee +17 -0
- data/server/lib/on.coffee +10 -0
- data/server/lib/spawner.coffee +65 -0
- data/server/node_modules/coffee-script/CNAME +1 -0
- data/server/node_modules/coffee-script/LICENSE +22 -0
- data/server/node_modules/coffee-script/README +51 -0
- data/server/node_modules/coffee-script/Rakefile +78 -0
- data/server/node_modules/coffee-script/bin/cake +7 -0
- data/server/node_modules/coffee-script/bin/coffee +7 -0
- data/server/node_modules/coffee-script/extras/jsl.conf +44 -0
- data/server/node_modules/coffee-script/lib/coffee-script/browser.js +92 -0
- data/server/node_modules/coffee-script/lib/coffee-script/cake.js +111 -0
- data/server/node_modules/coffee-script/lib/coffee-script/coffee-script.js +167 -0
- data/server/node_modules/coffee-script/lib/coffee-script/command.js +500 -0
- data/server/node_modules/coffee-script/lib/coffee-script/grammar.js +606 -0
- data/server/node_modules/coffee-script/lib/coffee-script/helpers.js +77 -0
- data/server/node_modules/coffee-script/lib/coffee-script/index.js +11 -0
- data/server/node_modules/coffee-script/lib/coffee-script/lexer.js +788 -0
- data/server/node_modules/coffee-script/lib/coffee-script/nodes.js +2986 -0
- data/server/node_modules/coffee-script/lib/coffee-script/optparse.js +138 -0
- data/server/node_modules/coffee-script/lib/coffee-script/parser.js +683 -0
- data/server/node_modules/coffee-script/lib/coffee-script/repl.js +261 -0
- data/server/node_modules/coffee-script/lib/coffee-script/rewriter.js +349 -0
- data/server/node_modules/coffee-script/lib/coffee-script/scope.js +146 -0
- data/server/node_modules/coffee-script/package.json +55 -0
- data/server/node_modules/connect-form/History.md +0 -6
- data/server/node_modules/connect-form/lib/connect-form.js +2 -4
- data/server/node_modules/connect-form/node_modules/formidable/Readme.md +64 -36
- data/server/node_modules/connect-form/node_modules/formidable/lib/incoming_form.js +5 -1
- data/server/node_modules/connect-form/node_modules/formidable/package.json +20 -6
- data/server/node_modules/connect-form/node_modules/formidable/test/common.js +5 -6
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/file/funkyfilename.txt +1 -0
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/js/special-chars-in-filename.js +1 -1
- data/server/node_modules/connect-form/node_modules/formidable/test/{slow → integration}/test-fixtures.js +38 -33
- data/server/node_modules/connect-form/node_modules/formidable/test/legacy/simple/test-incoming-form.js +11 -0
- data/server/node_modules/connect-form/node_modules/formidable/test/run.js +1 -6
- data/server/node_modules/connect-form/node_modules/formidable/test/unit/test-incoming-form.js +63 -0
- data/server/node_modules/connect-form/package.json +27 -5
- data/server/node_modules/cradle/README.md +10 -10
- data/server/node_modules/cradle/lib/cradle.js +117 -523
- data/server/node_modules/cradle/lib/cradle/database/attachments.js +120 -0
- data/server/node_modules/cradle/lib/cradle/database/changes.js +56 -0
- data/server/node_modules/cradle/lib/cradle/database/documents.js +215 -0
- data/server/node_modules/cradle/lib/cradle/database/index.js +65 -0
- data/server/node_modules/cradle/lib/cradle/database/views.js +125 -0
- data/server/node_modules/cradle/node_modules/follow/LICENSE +202 -0
- data/server/node_modules/cradle/node_modules/follow/README.md +164 -0
- data/server/node_modules/cradle/node_modules/follow/Rakefile +54 -0
- data/server/node_modules/cradle/node_modules/follow/api.js +35 -0
- data/server/node_modules/cradle/node_modules/follow/browser/eventemitter2.js +453 -0
- data/server/node_modules/cradle/node_modules/follow/browser/export.js +78 -0
- data/server/node_modules/cradle/node_modules/follow/browser/index.html +14 -0
- data/server/node_modules/cradle/node_modules/follow/browser/jquery-1.6.1.min.js +18 -0
- data/server/node_modules/cradle/node_modules/follow/browser/log4js.js +46 -0
- data/server/node_modules/cradle/node_modules/follow/browser/main.js +92 -0
- data/server/node_modules/cradle/node_modules/follow/browser/querystring.js +28 -0
- data/server/node_modules/cradle/node_modules/follow/browser/request.jquery.js +237 -0
- data/server/node_modules/cradle/node_modules/follow/browser/require.js +33 -0
- data/server/node_modules/cradle/node_modules/follow/browser/util.js +28 -0
- data/server/node_modules/cradle/node_modules/follow/cli.js +101 -0
- data/server/node_modules/cradle/node_modules/follow/lib/feed.js +556 -0
- data/server/node_modules/cradle/node_modules/follow/lib/index.js +66 -0
- data/server/node_modules/cradle/node_modules/follow/lib/stream.js +305 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/LICENSE +55 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/README.md +285 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/main.js +618 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/mimetypes.js +146 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/oauth.js +34 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/package.json +42 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/googledoodle.png +0 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/run.sh +6 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/server.js +57 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-body.js +90 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-cookie.js +29 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-cookiejar.js +90 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-errors.js +30 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-oauth.js +109 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-pipes.js +167 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-proxy.js +39 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/tests/test-timeout.js +87 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/uuid.js +19 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/vendor/cookie/index.js +55 -0
- data/server/node_modules/cradle/node_modules/follow/node_modules/request/vendor/cookie/jar.js +72 -0
- data/server/node_modules/cradle/node_modules/follow/package.json +45 -0
- data/server/node_modules/cradle/node_modules/follow/test/couch.js +153 -0
- data/server/node_modules/cradle/node_modules/follow/test/follow.js +136 -0
- data/server/node_modules/cradle/node_modules/follow/test/issues.js +178 -0
- data/server/node_modules/cradle/node_modules/follow/test/issues/10.js +24 -0
- data/server/node_modules/cradle/node_modules/follow/test/stream.js +493 -0
- data/server/node_modules/cradle/node_modules/request/LICENSE +55 -0
- data/server/node_modules/cradle/node_modules/request/README.md +287 -0
- data/server/node_modules/cradle/node_modules/request/forever.js +103 -0
- data/server/node_modules/cradle/node_modules/request/main.js +913 -0
- data/server/node_modules/cradle/node_modules/request/mimetypes.js +152 -0
- data/server/node_modules/cradle/node_modules/request/oauth.js +34 -0
- data/server/node_modules/cradle/node_modules/request/package.json +42 -0
- data/server/node_modules/cradle/node_modules/request/tests/googledoodle.png +0 -0
- data/server/node_modules/cradle/node_modules/request/tests/run.js +38 -0
- data/server/node_modules/cradle/node_modules/request/tests/server.js +82 -0
- data/server/node_modules/cradle/node_modules/request/tests/squid.conf +77 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.cnf +20 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.crl +0 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.crt +17 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.csr +13 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.key +18 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/ca.srl +1 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.cnf +19 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.crt +16 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.csr +11 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.js +28 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/ca/server.key +9 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/npm-ca.crt +16 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/test.crt +15 -0
- data/server/node_modules/cradle/node_modules/request/tests/ssl/test.key +15 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-body.js +95 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-cookie.js +29 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-cookiejar.js +90 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-defaults.js +68 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-errors.js +37 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-headers.js +52 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-httpModule.js +94 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-https-strict.js +97 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-https.js +86 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-oauth.js +117 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-params.js +92 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-pipes.js +202 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-proxy.js +39 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-qs.js +28 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-redirect.js +154 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-timeout.js +87 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-toJSON.js +14 -0
- data/server/node_modules/cradle/node_modules/request/tests/test-tunnel.js +61 -0
- data/server/node_modules/cradle/node_modules/request/tunnel.js +229 -0
- data/server/node_modules/cradle/node_modules/request/uuid.js +19 -0
- data/server/node_modules/cradle/node_modules/request/vendor/cookie/index.js +65 -0
- data/server/node_modules/cradle/node_modules/request/vendor/cookie/jar.js +72 -0
- data/server/node_modules/cradle/node_modules/vargs/package.json +33 -10
- data/server/node_modules/cradle/package.json +50 -12
- data/server/node_modules/cradle/test/cache-test.js +1 -4
- data/server/node_modules/cradle/test/connection-test.js +179 -0
- data/server/node_modules/cradle/test/database-attachment-test.js +344 -0
- data/server/node_modules/cradle/test/database-cache-test.js +132 -0
- data/server/node_modules/cradle/test/database-test.js +219 -0
- data/server/node_modules/cradle/test/database-view-test.js +141 -0
- data/server/node_modules/cradle/test/fixtures/databases.json +28 -1
- data/server/node_modules/cradle/test/helpers/seed.js +14 -5
- data/server/node_modules/cradle/test/response-test.js +1 -1
- data/server/node_modules/express/History.md +16 -0
- data/server/node_modules/express/bin/express +7 -6
- data/server/node_modules/express/lib-cov/application.js +510 -0
- data/server/node_modules/express/lib-cov/express.js +65 -0
- data/server/node_modules/express/lib-cov/middleware.js +54 -0
- data/server/node_modules/express/lib-cov/request.js +225 -0
- data/server/node_modules/express/lib-cov/response.js +611 -0
- data/server/node_modules/express/lib-cov/router/collection.js +40 -0
- data/server/node_modules/express/lib-cov/router/index.js +515 -0
- data/server/node_modules/express/lib-cov/router/methods.js +9 -0
- data/server/node_modules/express/lib-cov/router/route.js +68 -0
- data/server/node_modules/express/lib-cov/utils.js +151 -0
- data/server/node_modules/express/lib-cov/view.js +81 -0
- data/server/node_modules/express/lib/express.js +1 -1
- data/server/node_modules/express/lib/http.js +1 -2
- data/server/node_modules/express/lib/request.js +2 -2
- data/server/node_modules/express/lib/router/methods.js +10 -1
- data/server/node_modules/express/node_modules/connect/lib/connect.js +1 -1
- data/server/node_modules/express/node_modules/connect/lib/http.js +3 -2
- data/server/node_modules/express/node_modules/connect/lib/middleware/limit.js +0 -2
- data/server/node_modules/express/node_modules/connect/lib/middleware/session.js +1 -2
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/Readme.md +42 -25
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js +1 -0
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/package.json +14 -3
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/legacy/simple/test-incoming-form.js +11 -0
- data/server/node_modules/express/node_modules/connect/package.json +35 -7
- data/server/node_modules/express/node_modules/mime/package.json +30 -8
- data/server/node_modules/express/node_modules/mkdirp/README.markdown +35 -2
- data/server/node_modules/express/node_modules/mkdirp/examples/pow.js +1 -1
- data/server/node_modules/express/node_modules/mkdirp/index.js +72 -13
- data/server/node_modules/express/node_modules/mkdirp/package.json +39 -21
- data/server/node_modules/express/node_modules/mkdirp/test/chmod.js +38 -0
- data/server/node_modules/express/node_modules/mkdirp/test/clobber.js +37 -0
- data/server/node_modules/express/node_modules/mkdirp/test/perm.js +32 -0
- data/server/node_modules/express/node_modules/mkdirp/test/perm_sync.js +39 -0
- data/server/node_modules/express/node_modules/mkdirp/test/sync.js +27 -0
- data/server/node_modules/express/node_modules/mkdirp/test/umask.js +28 -0
- data/server/node_modules/express/node_modules/mkdirp/test/umask_sync.js +27 -0
- data/server/node_modules/express/node_modules/qs/History.md +10 -0
- data/server/node_modules/express/node_modules/qs/Readme.md +9 -2
- data/server/node_modules/express/node_modules/qs/examples.js +3 -0
- data/server/node_modules/express/node_modules/qs/lib/querystring.js +8 -6
- data/server/node_modules/express/node_modules/qs/package.json +26 -8
- data/server/node_modules/express/node_modules/qs/test/parse.js +13 -1
- data/server/node_modules/express/node_modules/qs/test/stringify.js +45 -37
- data/server/node_modules/express/package.json +55 -16
- data/server/node_modules/express/test.js +41 -0
- data/server/node_modules/knox/package.json +26 -4
- data/server/node_modules/node-uuid/package.json +40 -11
- data/server/node_modules/node-uuid/test/test.js +1 -1
- data/server/node_modules/nodemon/README.md +120 -0
- data/server/node_modules/nodemon/nodemon.js +518 -0
- data/server/node_modules/nodemon/nodemonignore.example +11 -0
- data/server/node_modules/nodemon/package.json +49 -0
- data/server/node_modules/restler/README.md +144 -94
- data/server/node_modules/restler/lib/multipartform.js +2 -0
- data/server/node_modules/restler/lib/restler.js +218 -61
- data/server/node_modules/restler/package.json +35 -8
- data/server/node_modules/restler/test/all.js +6 -1
- data/server/node_modules/restler/test/restler.js +624 -118
- data/server/package.json +14 -10
- data/server/web.coffee +64 -0
- data/server/web.js +15 -3
- metadata +170 -57
- data/server/index.js +0 -14
- data/server/node_modules/connect-form/LICENSE +0 -22
- data/server/node_modules/connect-form/index.js +0 -100
- data/server/node_modules/connect-form/node_modules/formidable/test/fast/test-incoming-form.js +0 -45
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/no-filename/generic.http +0 -13
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-chrome-13.http +0 -26
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-firefox-3.6.http +0 -24
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-safari-5.http +0 -23
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-chrome-12.http +0 -24
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-7.http +0 -22
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-8.http +0 -22
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-safari-5.http +0 -22
- data/server/node_modules/connect-form/node_modules/formidable/test/fixture/multi_video.upload +0 -0
- data/server/node_modules/cradle/Makefile +0 -10
- data/server/node_modules/cradle/test/cradle-test.js +0 -650
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/no-filename/generic.http +0 -13
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-chrome-13.http +0 -26
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-firefox-3.6.http +0 -24
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/osx-safari-5.http +0 -23
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-chrome-12.http +0 -24
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-7.http +0 -22
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-ie-8.http +0 -22
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/http/special-chars-in-filename/xp-safari-5.http +0 -22
- data/server/node_modules/express/node_modules/connect/node_modules/formidable/test/fixture/multi_video.upload +0 -0
- data/server/node_modules/express/node_modules/connect/test.js +0 -52
- data/server/node_modules/express/testing/foo/app.js +0 -35
- data/server/node_modules/express/testing/foo/package.json +0 -9
- data/server/node_modules/express/testing/foo/public/stylesheets/style.css +0 -8
- data/server/node_modules/express/testing/foo/routes/index.js +0 -10
- data/server/node_modules/express/testing/foo/views/index.jade +0 -2
- data/server/node_modules/express/testing/foo/views/layout.jade +0 -6
- data/server/node_modules/express/testing/index.js +0 -43
- data/server/node_modules/express/testing/public/test.txt +0 -2971
- data/server/node_modules/express/testing/views/page.html +0 -1
- data/server/node_modules/express/testing/views/page.jade +0 -3
- data/server/node_modules/express/testing/views/test.md +0 -1
- data/server/node_modules/express/testing/views/user/index.jade +0 -1
- data/server/node_modules/express/testing/views/user/list.jade +0 -1
- data/server/node_modules/knox/lib/knox/mime/index.js +0 -308
- data/server/node_modules/knox/lib/knox/mime/test.js +0 -59
- data/server/node_modules/node-uuid/test/benchmark-native +0 -0
- data/server/node_modules/on/index.js +0 -13
- data/server/node_modules/restler/test/test_helper.js +0 -163
- data/server/node_modules/spawner/index.js +0 -106
@@ -0,0 +1,2986 @@
|
|
1
|
+
// Generated by CoffeeScript 1.3.3
|
2
|
+
(function() {
|
3
|
+
var Access, Arr, Assign, Base, Block, Call, Class, Closure, Code, Comment, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, STRICT_PROSCRIBED, Scope, Slice, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, unfoldSoak, utility, _ref, _ref1,
|
4
|
+
__hasProp = {}.hasOwnProperty,
|
5
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
6
|
+
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
7
|
+
|
8
|
+
Scope = require('./scope').Scope;
|
9
|
+
|
10
|
+
_ref = require('./lexer'), RESERVED = _ref.RESERVED, STRICT_PROSCRIBED = _ref.STRICT_PROSCRIBED;
|
11
|
+
|
12
|
+
_ref1 = require('./helpers'), compact = _ref1.compact, flatten = _ref1.flatten, extend = _ref1.extend, merge = _ref1.merge, del = _ref1.del, starts = _ref1.starts, ends = _ref1.ends, last = _ref1.last;
|
13
|
+
|
14
|
+
exports.extend = extend;
|
15
|
+
|
16
|
+
YES = function() {
|
17
|
+
return true;
|
18
|
+
};
|
19
|
+
|
20
|
+
NO = function() {
|
21
|
+
return false;
|
22
|
+
};
|
23
|
+
|
24
|
+
THIS = function() {
|
25
|
+
return this;
|
26
|
+
};
|
27
|
+
|
28
|
+
NEGATE = function() {
|
29
|
+
this.negated = !this.negated;
|
30
|
+
return this;
|
31
|
+
};
|
32
|
+
|
33
|
+
exports.Base = Base = (function() {
|
34
|
+
|
35
|
+
function Base() {}
|
36
|
+
|
37
|
+
Base.prototype.compile = function(o, lvl) {
|
38
|
+
var node;
|
39
|
+
o = extend({}, o);
|
40
|
+
if (lvl) {
|
41
|
+
o.level = lvl;
|
42
|
+
}
|
43
|
+
node = this.unfoldSoak(o) || this;
|
44
|
+
node.tab = o.indent;
|
45
|
+
if (o.level === LEVEL_TOP || !node.isStatement(o)) {
|
46
|
+
return node.compileNode(o);
|
47
|
+
} else {
|
48
|
+
return node.compileClosure(o);
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
Base.prototype.compileClosure = function(o) {
|
53
|
+
if (this.jumps()) {
|
54
|
+
throw SyntaxError('cannot use a pure statement in an expression.');
|
55
|
+
}
|
56
|
+
o.sharedScope = true;
|
57
|
+
return Closure.wrap(this).compileNode(o);
|
58
|
+
};
|
59
|
+
|
60
|
+
Base.prototype.cache = function(o, level, reused) {
|
61
|
+
var ref, sub;
|
62
|
+
if (!this.isComplex()) {
|
63
|
+
ref = level ? this.compile(o, level) : this;
|
64
|
+
return [ref, ref];
|
65
|
+
} else {
|
66
|
+
ref = new Literal(reused || o.scope.freeVariable('ref'));
|
67
|
+
sub = new Assign(ref, this);
|
68
|
+
if (level) {
|
69
|
+
return [sub.compile(o, level), ref.value];
|
70
|
+
} else {
|
71
|
+
return [sub, ref];
|
72
|
+
}
|
73
|
+
}
|
74
|
+
};
|
75
|
+
|
76
|
+
Base.prototype.compileLoopReference = function(o, name) {
|
77
|
+
var src, tmp;
|
78
|
+
src = tmp = this.compile(o, LEVEL_LIST);
|
79
|
+
if (!((-Infinity < +src && +src < Infinity) || IDENTIFIER.test(src) && o.scope.check(src, true))) {
|
80
|
+
src = "" + (tmp = o.scope.freeVariable(name)) + " = " + src;
|
81
|
+
}
|
82
|
+
return [src, tmp];
|
83
|
+
};
|
84
|
+
|
85
|
+
Base.prototype.makeReturn = function(res) {
|
86
|
+
var me;
|
87
|
+
me = this.unwrapAll();
|
88
|
+
if (res) {
|
89
|
+
return new Call(new Literal("" + res + ".push"), [me]);
|
90
|
+
} else {
|
91
|
+
return new Return(me);
|
92
|
+
}
|
93
|
+
};
|
94
|
+
|
95
|
+
Base.prototype.contains = function(pred) {
|
96
|
+
var contains;
|
97
|
+
contains = false;
|
98
|
+
this.traverseChildren(false, function(node) {
|
99
|
+
if (pred(node)) {
|
100
|
+
contains = true;
|
101
|
+
return false;
|
102
|
+
}
|
103
|
+
});
|
104
|
+
return contains;
|
105
|
+
};
|
106
|
+
|
107
|
+
Base.prototype.containsType = function(type) {
|
108
|
+
return this instanceof type || this.contains(function(node) {
|
109
|
+
return node instanceof type;
|
110
|
+
});
|
111
|
+
};
|
112
|
+
|
113
|
+
Base.prototype.lastNonComment = function(list) {
|
114
|
+
var i;
|
115
|
+
i = list.length;
|
116
|
+
while (i--) {
|
117
|
+
if (!(list[i] instanceof Comment)) {
|
118
|
+
return list[i];
|
119
|
+
}
|
120
|
+
}
|
121
|
+
return null;
|
122
|
+
};
|
123
|
+
|
124
|
+
Base.prototype.toString = function(idt, name) {
|
125
|
+
var tree;
|
126
|
+
if (idt == null) {
|
127
|
+
idt = '';
|
128
|
+
}
|
129
|
+
if (name == null) {
|
130
|
+
name = this.constructor.name;
|
131
|
+
}
|
132
|
+
tree = '\n' + idt + name;
|
133
|
+
if (this.soak) {
|
134
|
+
tree += '?';
|
135
|
+
}
|
136
|
+
this.eachChild(function(node) {
|
137
|
+
return tree += node.toString(idt + TAB);
|
138
|
+
});
|
139
|
+
return tree;
|
140
|
+
};
|
141
|
+
|
142
|
+
Base.prototype.eachChild = function(func) {
|
143
|
+
var attr, child, _i, _j, _len, _len1, _ref2, _ref3;
|
144
|
+
if (!this.children) {
|
145
|
+
return this;
|
146
|
+
}
|
147
|
+
_ref2 = this.children;
|
148
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
149
|
+
attr = _ref2[_i];
|
150
|
+
if (this[attr]) {
|
151
|
+
_ref3 = flatten([this[attr]]);
|
152
|
+
for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
|
153
|
+
child = _ref3[_j];
|
154
|
+
if (func(child) === false) {
|
155
|
+
return this;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}
|
160
|
+
return this;
|
161
|
+
};
|
162
|
+
|
163
|
+
Base.prototype.traverseChildren = function(crossScope, func) {
|
164
|
+
return this.eachChild(function(child) {
|
165
|
+
if (func(child) === false) {
|
166
|
+
return false;
|
167
|
+
}
|
168
|
+
return child.traverseChildren(crossScope, func);
|
169
|
+
});
|
170
|
+
};
|
171
|
+
|
172
|
+
Base.prototype.invert = function() {
|
173
|
+
return new Op('!', this);
|
174
|
+
};
|
175
|
+
|
176
|
+
Base.prototype.unwrapAll = function() {
|
177
|
+
var node;
|
178
|
+
node = this;
|
179
|
+
while (node !== (node = node.unwrap())) {
|
180
|
+
continue;
|
181
|
+
}
|
182
|
+
return node;
|
183
|
+
};
|
184
|
+
|
185
|
+
Base.prototype.children = [];
|
186
|
+
|
187
|
+
Base.prototype.isStatement = NO;
|
188
|
+
|
189
|
+
Base.prototype.jumps = NO;
|
190
|
+
|
191
|
+
Base.prototype.isComplex = YES;
|
192
|
+
|
193
|
+
Base.prototype.isChainable = NO;
|
194
|
+
|
195
|
+
Base.prototype.isAssignable = NO;
|
196
|
+
|
197
|
+
Base.prototype.unwrap = THIS;
|
198
|
+
|
199
|
+
Base.prototype.unfoldSoak = NO;
|
200
|
+
|
201
|
+
Base.prototype.assigns = NO;
|
202
|
+
|
203
|
+
return Base;
|
204
|
+
|
205
|
+
})();
|
206
|
+
|
207
|
+
exports.Block = Block = (function(_super) {
|
208
|
+
|
209
|
+
__extends(Block, _super);
|
210
|
+
|
211
|
+
function Block(nodes) {
|
212
|
+
this.expressions = compact(flatten(nodes || []));
|
213
|
+
}
|
214
|
+
|
215
|
+
Block.prototype.children = ['expressions'];
|
216
|
+
|
217
|
+
Block.prototype.push = function(node) {
|
218
|
+
this.expressions.push(node);
|
219
|
+
return this;
|
220
|
+
};
|
221
|
+
|
222
|
+
Block.prototype.pop = function() {
|
223
|
+
return this.expressions.pop();
|
224
|
+
};
|
225
|
+
|
226
|
+
Block.prototype.unshift = function(node) {
|
227
|
+
this.expressions.unshift(node);
|
228
|
+
return this;
|
229
|
+
};
|
230
|
+
|
231
|
+
Block.prototype.unwrap = function() {
|
232
|
+
if (this.expressions.length === 1) {
|
233
|
+
return this.expressions[0];
|
234
|
+
} else {
|
235
|
+
return this;
|
236
|
+
}
|
237
|
+
};
|
238
|
+
|
239
|
+
Block.prototype.isEmpty = function() {
|
240
|
+
return !this.expressions.length;
|
241
|
+
};
|
242
|
+
|
243
|
+
Block.prototype.isStatement = function(o) {
|
244
|
+
var exp, _i, _len, _ref2;
|
245
|
+
_ref2 = this.expressions;
|
246
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
247
|
+
exp = _ref2[_i];
|
248
|
+
if (exp.isStatement(o)) {
|
249
|
+
return true;
|
250
|
+
}
|
251
|
+
}
|
252
|
+
return false;
|
253
|
+
};
|
254
|
+
|
255
|
+
Block.prototype.jumps = function(o) {
|
256
|
+
var exp, _i, _len, _ref2;
|
257
|
+
_ref2 = this.expressions;
|
258
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
259
|
+
exp = _ref2[_i];
|
260
|
+
if (exp.jumps(o)) {
|
261
|
+
return exp;
|
262
|
+
}
|
263
|
+
}
|
264
|
+
};
|
265
|
+
|
266
|
+
Block.prototype.makeReturn = function(res) {
|
267
|
+
var expr, len;
|
268
|
+
len = this.expressions.length;
|
269
|
+
while (len--) {
|
270
|
+
expr = this.expressions[len];
|
271
|
+
if (!(expr instanceof Comment)) {
|
272
|
+
this.expressions[len] = expr.makeReturn(res);
|
273
|
+
if (expr instanceof Return && !expr.expression) {
|
274
|
+
this.expressions.splice(len, 1);
|
275
|
+
}
|
276
|
+
break;
|
277
|
+
}
|
278
|
+
}
|
279
|
+
return this;
|
280
|
+
};
|
281
|
+
|
282
|
+
Block.prototype.compile = function(o, level) {
|
283
|
+
if (o == null) {
|
284
|
+
o = {};
|
285
|
+
}
|
286
|
+
if (o.scope) {
|
287
|
+
return Block.__super__.compile.call(this, o, level);
|
288
|
+
} else {
|
289
|
+
return this.compileRoot(o);
|
290
|
+
}
|
291
|
+
};
|
292
|
+
|
293
|
+
Block.prototype.compileNode = function(o) {
|
294
|
+
var code, codes, node, top, _i, _len, _ref2;
|
295
|
+
this.tab = o.indent;
|
296
|
+
top = o.level === LEVEL_TOP;
|
297
|
+
codes = [];
|
298
|
+
_ref2 = this.expressions;
|
299
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
300
|
+
node = _ref2[_i];
|
301
|
+
node = node.unwrapAll();
|
302
|
+
node = node.unfoldSoak(o) || node;
|
303
|
+
if (node instanceof Block) {
|
304
|
+
codes.push(node.compileNode(o));
|
305
|
+
} else if (top) {
|
306
|
+
node.front = true;
|
307
|
+
code = node.compile(o);
|
308
|
+
if (!node.isStatement(o)) {
|
309
|
+
code = "" + this.tab + code + ";";
|
310
|
+
if (node instanceof Literal) {
|
311
|
+
code = "" + code + "\n";
|
312
|
+
}
|
313
|
+
}
|
314
|
+
codes.push(code);
|
315
|
+
} else {
|
316
|
+
codes.push(node.compile(o, LEVEL_LIST));
|
317
|
+
}
|
318
|
+
}
|
319
|
+
if (top) {
|
320
|
+
if (this.spaced) {
|
321
|
+
return "\n" + (codes.join('\n\n')) + "\n";
|
322
|
+
} else {
|
323
|
+
return codes.join('\n');
|
324
|
+
}
|
325
|
+
}
|
326
|
+
code = codes.join(', ') || 'void 0';
|
327
|
+
if (codes.length > 1 && o.level >= LEVEL_LIST) {
|
328
|
+
return "(" + code + ")";
|
329
|
+
} else {
|
330
|
+
return code;
|
331
|
+
}
|
332
|
+
};
|
333
|
+
|
334
|
+
Block.prototype.compileRoot = function(o) {
|
335
|
+
var code, exp, i, prelude, preludeExps, rest;
|
336
|
+
o.indent = o.bare ? '' : TAB;
|
337
|
+
o.scope = new Scope(null, this, null);
|
338
|
+
o.level = LEVEL_TOP;
|
339
|
+
this.spaced = true;
|
340
|
+
prelude = "";
|
341
|
+
if (!o.bare) {
|
342
|
+
preludeExps = (function() {
|
343
|
+
var _i, _len, _ref2, _results;
|
344
|
+
_ref2 = this.expressions;
|
345
|
+
_results = [];
|
346
|
+
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
347
|
+
exp = _ref2[i];
|
348
|
+
if (!(exp.unwrap() instanceof Comment)) {
|
349
|
+
break;
|
350
|
+
}
|
351
|
+
_results.push(exp);
|
352
|
+
}
|
353
|
+
return _results;
|
354
|
+
}).call(this);
|
355
|
+
rest = this.expressions.slice(preludeExps.length);
|
356
|
+
this.expressions = preludeExps;
|
357
|
+
if (preludeExps.length) {
|
358
|
+
prelude = "" + (this.compileNode(merge(o, {
|
359
|
+
indent: ''
|
360
|
+
}))) + "\n";
|
361
|
+
}
|
362
|
+
this.expressions = rest;
|
363
|
+
}
|
364
|
+
code = this.compileWithDeclarations(o);
|
365
|
+
if (o.bare) {
|
366
|
+
return code;
|
367
|
+
}
|
368
|
+
return "" + prelude + "(function() {\n" + code + "\n}).call(this);\n";
|
369
|
+
};
|
370
|
+
|
371
|
+
Block.prototype.compileWithDeclarations = function(o) {
|
372
|
+
var assigns, code, declars, exp, i, post, rest, scope, spaced, _i, _len, _ref2, _ref3, _ref4;
|
373
|
+
code = post = '';
|
374
|
+
_ref2 = this.expressions;
|
375
|
+
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
376
|
+
exp = _ref2[i];
|
377
|
+
exp = exp.unwrap();
|
378
|
+
if (!(exp instanceof Comment || exp instanceof Literal)) {
|
379
|
+
break;
|
380
|
+
}
|
381
|
+
}
|
382
|
+
o = merge(o, {
|
383
|
+
level: LEVEL_TOP
|
384
|
+
});
|
385
|
+
if (i) {
|
386
|
+
rest = this.expressions.splice(i, 9e9);
|
387
|
+
_ref3 = [this.spaced, false], spaced = _ref3[0], this.spaced = _ref3[1];
|
388
|
+
_ref4 = [this.compileNode(o), spaced], code = _ref4[0], this.spaced = _ref4[1];
|
389
|
+
this.expressions = rest;
|
390
|
+
}
|
391
|
+
post = this.compileNode(o);
|
392
|
+
scope = o.scope;
|
393
|
+
if (scope.expressions === this) {
|
394
|
+
declars = o.scope.hasDeclarations();
|
395
|
+
assigns = scope.hasAssignments;
|
396
|
+
if (declars || assigns) {
|
397
|
+
if (i) {
|
398
|
+
code += '\n';
|
399
|
+
}
|
400
|
+
code += "" + this.tab + "var ";
|
401
|
+
if (declars) {
|
402
|
+
code += scope.declaredVariables().join(', ');
|
403
|
+
}
|
404
|
+
if (assigns) {
|
405
|
+
if (declars) {
|
406
|
+
code += ",\n" + (this.tab + TAB);
|
407
|
+
}
|
408
|
+
code += scope.assignedVariables().join(",\n" + (this.tab + TAB));
|
409
|
+
}
|
410
|
+
code += ';\n';
|
411
|
+
}
|
412
|
+
}
|
413
|
+
return code + post;
|
414
|
+
};
|
415
|
+
|
416
|
+
Block.wrap = function(nodes) {
|
417
|
+
if (nodes.length === 1 && nodes[0] instanceof Block) {
|
418
|
+
return nodes[0];
|
419
|
+
}
|
420
|
+
return new Block(nodes);
|
421
|
+
};
|
422
|
+
|
423
|
+
return Block;
|
424
|
+
|
425
|
+
})(Base);
|
426
|
+
|
427
|
+
exports.Literal = Literal = (function(_super) {
|
428
|
+
|
429
|
+
__extends(Literal, _super);
|
430
|
+
|
431
|
+
function Literal(value) {
|
432
|
+
this.value = value;
|
433
|
+
}
|
434
|
+
|
435
|
+
Literal.prototype.makeReturn = function() {
|
436
|
+
if (this.isStatement()) {
|
437
|
+
return this;
|
438
|
+
} else {
|
439
|
+
return Literal.__super__.makeReturn.apply(this, arguments);
|
440
|
+
}
|
441
|
+
};
|
442
|
+
|
443
|
+
Literal.prototype.isAssignable = function() {
|
444
|
+
return IDENTIFIER.test(this.value);
|
445
|
+
};
|
446
|
+
|
447
|
+
Literal.prototype.isStatement = function() {
|
448
|
+
var _ref2;
|
449
|
+
return (_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger';
|
450
|
+
};
|
451
|
+
|
452
|
+
Literal.prototype.isComplex = NO;
|
453
|
+
|
454
|
+
Literal.prototype.assigns = function(name) {
|
455
|
+
return name === this.value;
|
456
|
+
};
|
457
|
+
|
458
|
+
Literal.prototype.jumps = function(o) {
|
459
|
+
if (this.value === 'break' && !((o != null ? o.loop : void 0) || (o != null ? o.block : void 0))) {
|
460
|
+
return this;
|
461
|
+
}
|
462
|
+
if (this.value === 'continue' && !(o != null ? o.loop : void 0)) {
|
463
|
+
return this;
|
464
|
+
}
|
465
|
+
};
|
466
|
+
|
467
|
+
Literal.prototype.compileNode = function(o) {
|
468
|
+
var code, _ref2;
|
469
|
+
code = this.value === 'this' ? ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved ? "\"" + this.value + "\"" : this.value;
|
470
|
+
if (this.isStatement()) {
|
471
|
+
return "" + this.tab + code + ";";
|
472
|
+
} else {
|
473
|
+
return code;
|
474
|
+
}
|
475
|
+
};
|
476
|
+
|
477
|
+
Literal.prototype.toString = function() {
|
478
|
+
return ' "' + this.value + '"';
|
479
|
+
};
|
480
|
+
|
481
|
+
return Literal;
|
482
|
+
|
483
|
+
})(Base);
|
484
|
+
|
485
|
+
exports.Undefined = (function(_super) {
|
486
|
+
|
487
|
+
__extends(Undefined, _super);
|
488
|
+
|
489
|
+
function Undefined() {
|
490
|
+
return Undefined.__super__.constructor.apply(this, arguments);
|
491
|
+
}
|
492
|
+
|
493
|
+
Undefined.prototype.isAssignable = NO;
|
494
|
+
|
495
|
+
Undefined.prototype.isComplex = NO;
|
496
|
+
|
497
|
+
Undefined.prototype.compileNode = function(o) {
|
498
|
+
if (o.level >= LEVEL_ACCESS) {
|
499
|
+
return '(void 0)';
|
500
|
+
} else {
|
501
|
+
return 'void 0';
|
502
|
+
}
|
503
|
+
};
|
504
|
+
|
505
|
+
return Undefined;
|
506
|
+
|
507
|
+
})(Base);
|
508
|
+
|
509
|
+
exports.Null = (function(_super) {
|
510
|
+
|
511
|
+
__extends(Null, _super);
|
512
|
+
|
513
|
+
function Null() {
|
514
|
+
return Null.__super__.constructor.apply(this, arguments);
|
515
|
+
}
|
516
|
+
|
517
|
+
Null.prototype.isAssignable = NO;
|
518
|
+
|
519
|
+
Null.prototype.isComplex = NO;
|
520
|
+
|
521
|
+
Null.prototype.compileNode = function() {
|
522
|
+
return "null";
|
523
|
+
};
|
524
|
+
|
525
|
+
return Null;
|
526
|
+
|
527
|
+
})(Base);
|
528
|
+
|
529
|
+
exports.Bool = (function(_super) {
|
530
|
+
|
531
|
+
__extends(Bool, _super);
|
532
|
+
|
533
|
+
Bool.prototype.isAssignable = NO;
|
534
|
+
|
535
|
+
Bool.prototype.isComplex = NO;
|
536
|
+
|
537
|
+
Bool.prototype.compileNode = function() {
|
538
|
+
return this.val;
|
539
|
+
};
|
540
|
+
|
541
|
+
function Bool(val) {
|
542
|
+
this.val = val;
|
543
|
+
}
|
544
|
+
|
545
|
+
return Bool;
|
546
|
+
|
547
|
+
})(Base);
|
548
|
+
|
549
|
+
exports.Return = Return = (function(_super) {
|
550
|
+
|
551
|
+
__extends(Return, _super);
|
552
|
+
|
553
|
+
function Return(expr) {
|
554
|
+
if (expr && !expr.unwrap().isUndefined) {
|
555
|
+
this.expression = expr;
|
556
|
+
}
|
557
|
+
}
|
558
|
+
|
559
|
+
Return.prototype.children = ['expression'];
|
560
|
+
|
561
|
+
Return.prototype.isStatement = YES;
|
562
|
+
|
563
|
+
Return.prototype.makeReturn = THIS;
|
564
|
+
|
565
|
+
Return.prototype.jumps = THIS;
|
566
|
+
|
567
|
+
Return.prototype.compile = function(o, level) {
|
568
|
+
var expr, _ref2;
|
569
|
+
expr = (_ref2 = this.expression) != null ? _ref2.makeReturn() : void 0;
|
570
|
+
if (expr && !(expr instanceof Return)) {
|
571
|
+
return expr.compile(o, level);
|
572
|
+
} else {
|
573
|
+
return Return.__super__.compile.call(this, o, level);
|
574
|
+
}
|
575
|
+
};
|
576
|
+
|
577
|
+
Return.prototype.compileNode = function(o) {
|
578
|
+
return this.tab + ("return" + [this.expression ? " " + (this.expression.compile(o, LEVEL_PAREN)) : void 0] + ";");
|
579
|
+
};
|
580
|
+
|
581
|
+
return Return;
|
582
|
+
|
583
|
+
})(Base);
|
584
|
+
|
585
|
+
exports.Value = Value = (function(_super) {
|
586
|
+
|
587
|
+
__extends(Value, _super);
|
588
|
+
|
589
|
+
function Value(base, props, tag) {
|
590
|
+
if (!props && base instanceof Value) {
|
591
|
+
return base;
|
592
|
+
}
|
593
|
+
this.base = base;
|
594
|
+
this.properties = props || [];
|
595
|
+
if (tag) {
|
596
|
+
this[tag] = true;
|
597
|
+
}
|
598
|
+
return this;
|
599
|
+
}
|
600
|
+
|
601
|
+
Value.prototype.children = ['base', 'properties'];
|
602
|
+
|
603
|
+
Value.prototype.add = function(props) {
|
604
|
+
this.properties = this.properties.concat(props);
|
605
|
+
return this;
|
606
|
+
};
|
607
|
+
|
608
|
+
Value.prototype.hasProperties = function() {
|
609
|
+
return !!this.properties.length;
|
610
|
+
};
|
611
|
+
|
612
|
+
Value.prototype.isArray = function() {
|
613
|
+
return !this.properties.length && this.base instanceof Arr;
|
614
|
+
};
|
615
|
+
|
616
|
+
Value.prototype.isComplex = function() {
|
617
|
+
return this.hasProperties() || this.base.isComplex();
|
618
|
+
};
|
619
|
+
|
620
|
+
Value.prototype.isAssignable = function() {
|
621
|
+
return this.hasProperties() || this.base.isAssignable();
|
622
|
+
};
|
623
|
+
|
624
|
+
Value.prototype.isSimpleNumber = function() {
|
625
|
+
return this.base instanceof Literal && SIMPLENUM.test(this.base.value);
|
626
|
+
};
|
627
|
+
|
628
|
+
Value.prototype.isString = function() {
|
629
|
+
return this.base instanceof Literal && IS_STRING.test(this.base.value);
|
630
|
+
};
|
631
|
+
|
632
|
+
Value.prototype.isAtomic = function() {
|
633
|
+
var node, _i, _len, _ref2;
|
634
|
+
_ref2 = this.properties.concat(this.base);
|
635
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
636
|
+
node = _ref2[_i];
|
637
|
+
if (node.soak || node instanceof Call) {
|
638
|
+
return false;
|
639
|
+
}
|
640
|
+
}
|
641
|
+
return true;
|
642
|
+
};
|
643
|
+
|
644
|
+
Value.prototype.isStatement = function(o) {
|
645
|
+
return !this.properties.length && this.base.isStatement(o);
|
646
|
+
};
|
647
|
+
|
648
|
+
Value.prototype.assigns = function(name) {
|
649
|
+
return !this.properties.length && this.base.assigns(name);
|
650
|
+
};
|
651
|
+
|
652
|
+
Value.prototype.jumps = function(o) {
|
653
|
+
return !this.properties.length && this.base.jumps(o);
|
654
|
+
};
|
655
|
+
|
656
|
+
Value.prototype.isObject = function(onlyGenerated) {
|
657
|
+
if (this.properties.length) {
|
658
|
+
return false;
|
659
|
+
}
|
660
|
+
return (this.base instanceof Obj) && (!onlyGenerated || this.base.generated);
|
661
|
+
};
|
662
|
+
|
663
|
+
Value.prototype.isSplice = function() {
|
664
|
+
return last(this.properties) instanceof Slice;
|
665
|
+
};
|
666
|
+
|
667
|
+
Value.prototype.unwrap = function() {
|
668
|
+
if (this.properties.length) {
|
669
|
+
return this;
|
670
|
+
} else {
|
671
|
+
return this.base;
|
672
|
+
}
|
673
|
+
};
|
674
|
+
|
675
|
+
Value.prototype.cacheReference = function(o) {
|
676
|
+
var base, bref, name, nref;
|
677
|
+
name = last(this.properties);
|
678
|
+
if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) {
|
679
|
+
return [this, this];
|
680
|
+
}
|
681
|
+
base = new Value(this.base, this.properties.slice(0, -1));
|
682
|
+
if (base.isComplex()) {
|
683
|
+
bref = new Literal(o.scope.freeVariable('base'));
|
684
|
+
base = new Value(new Parens(new Assign(bref, base)));
|
685
|
+
}
|
686
|
+
if (!name) {
|
687
|
+
return [base, bref];
|
688
|
+
}
|
689
|
+
if (name.isComplex()) {
|
690
|
+
nref = new Literal(o.scope.freeVariable('name'));
|
691
|
+
name = new Index(new Assign(nref, name.index));
|
692
|
+
nref = new Index(nref);
|
693
|
+
}
|
694
|
+
return [base.add(name), new Value(bref || base.base, [nref || name])];
|
695
|
+
};
|
696
|
+
|
697
|
+
Value.prototype.compileNode = function(o) {
|
698
|
+
var code, prop, props, _i, _len;
|
699
|
+
this.base.front = this.front;
|
700
|
+
props = this.properties;
|
701
|
+
code = this.base.compile(o, props.length ? LEVEL_ACCESS : null);
|
702
|
+
if ((this.base instanceof Parens || props.length) && SIMPLENUM.test(code)) {
|
703
|
+
code = "" + code + ".";
|
704
|
+
}
|
705
|
+
for (_i = 0, _len = props.length; _i < _len; _i++) {
|
706
|
+
prop = props[_i];
|
707
|
+
code += prop.compile(o);
|
708
|
+
}
|
709
|
+
return code;
|
710
|
+
};
|
711
|
+
|
712
|
+
Value.prototype.unfoldSoak = function(o) {
|
713
|
+
var result,
|
714
|
+
_this = this;
|
715
|
+
if (this.unfoldedSoak != null) {
|
716
|
+
return this.unfoldedSoak;
|
717
|
+
}
|
718
|
+
result = (function() {
|
719
|
+
var fst, i, ifn, prop, ref, snd, _i, _len, _ref2;
|
720
|
+
if (ifn = _this.base.unfoldSoak(o)) {
|
721
|
+
Array.prototype.push.apply(ifn.body.properties, _this.properties);
|
722
|
+
return ifn;
|
723
|
+
}
|
724
|
+
_ref2 = _this.properties;
|
725
|
+
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
726
|
+
prop = _ref2[i];
|
727
|
+
if (!prop.soak) {
|
728
|
+
continue;
|
729
|
+
}
|
730
|
+
prop.soak = false;
|
731
|
+
fst = new Value(_this.base, _this.properties.slice(0, i));
|
732
|
+
snd = new Value(_this.base, _this.properties.slice(i));
|
733
|
+
if (fst.isComplex()) {
|
734
|
+
ref = new Literal(o.scope.freeVariable('ref'));
|
735
|
+
fst = new Parens(new Assign(ref, fst));
|
736
|
+
snd.base = ref;
|
737
|
+
}
|
738
|
+
return new If(new Existence(fst), snd, {
|
739
|
+
soak: true
|
740
|
+
});
|
741
|
+
}
|
742
|
+
return null;
|
743
|
+
})();
|
744
|
+
return this.unfoldedSoak = result || false;
|
745
|
+
};
|
746
|
+
|
747
|
+
return Value;
|
748
|
+
|
749
|
+
})(Base);
|
750
|
+
|
751
|
+
exports.Comment = Comment = (function(_super) {
|
752
|
+
|
753
|
+
__extends(Comment, _super);
|
754
|
+
|
755
|
+
function Comment(comment) {
|
756
|
+
this.comment = comment;
|
757
|
+
}
|
758
|
+
|
759
|
+
Comment.prototype.isStatement = YES;
|
760
|
+
|
761
|
+
Comment.prototype.makeReturn = THIS;
|
762
|
+
|
763
|
+
Comment.prototype.compileNode = function(o, level) {
|
764
|
+
var code;
|
765
|
+
code = '/*' + multident(this.comment, this.tab) + ("\n" + this.tab + "*/\n");
|
766
|
+
if ((level || o.level) === LEVEL_TOP) {
|
767
|
+
code = o.indent + code;
|
768
|
+
}
|
769
|
+
return code;
|
770
|
+
};
|
771
|
+
|
772
|
+
return Comment;
|
773
|
+
|
774
|
+
})(Base);
|
775
|
+
|
776
|
+
exports.Call = Call = (function(_super) {
|
777
|
+
|
778
|
+
__extends(Call, _super);
|
779
|
+
|
780
|
+
function Call(variable, args, soak) {
|
781
|
+
this.args = args != null ? args : [];
|
782
|
+
this.soak = soak;
|
783
|
+
this.isNew = false;
|
784
|
+
this.isSuper = variable === 'super';
|
785
|
+
this.variable = this.isSuper ? null : variable;
|
786
|
+
}
|
787
|
+
|
788
|
+
Call.prototype.children = ['variable', 'args'];
|
789
|
+
|
790
|
+
Call.prototype.newInstance = function() {
|
791
|
+
var base, _ref2;
|
792
|
+
base = ((_ref2 = this.variable) != null ? _ref2.base : void 0) || this.variable;
|
793
|
+
if (base instanceof Call && !base.isNew) {
|
794
|
+
base.newInstance();
|
795
|
+
} else {
|
796
|
+
this.isNew = true;
|
797
|
+
}
|
798
|
+
return this;
|
799
|
+
};
|
800
|
+
|
801
|
+
Call.prototype.superReference = function(o) {
|
802
|
+
var accesses, method, name;
|
803
|
+
method = o.scope.namedMethod();
|
804
|
+
if (!method) {
|
805
|
+
throw SyntaxError('cannot call super outside of a function.');
|
806
|
+
}
|
807
|
+
name = method.name;
|
808
|
+
if (name == null) {
|
809
|
+
throw SyntaxError('cannot call super on an anonymous function.');
|
810
|
+
}
|
811
|
+
if (method.klass) {
|
812
|
+
accesses = [new Access(new Literal('__super__'))];
|
813
|
+
if (method["static"]) {
|
814
|
+
accesses.push(new Access(new Literal('constructor')));
|
815
|
+
}
|
816
|
+
accesses.push(new Access(new Literal(name)));
|
817
|
+
return (new Value(new Literal(method.klass), accesses)).compile(o);
|
818
|
+
} else {
|
819
|
+
return "" + name + ".__super__.constructor";
|
820
|
+
}
|
821
|
+
};
|
822
|
+
|
823
|
+
Call.prototype.superThis = function(o) {
|
824
|
+
var method;
|
825
|
+
method = o.scope.method;
|
826
|
+
return (method && !method.klass && method.context) || "this";
|
827
|
+
};
|
828
|
+
|
829
|
+
Call.prototype.unfoldSoak = function(o) {
|
830
|
+
var call, ifn, left, list, rite, _i, _len, _ref2, _ref3;
|
831
|
+
if (this.soak) {
|
832
|
+
if (this.variable) {
|
833
|
+
if (ifn = unfoldSoak(o, this, 'variable')) {
|
834
|
+
return ifn;
|
835
|
+
}
|
836
|
+
_ref2 = new Value(this.variable).cacheReference(o), left = _ref2[0], rite = _ref2[1];
|
837
|
+
} else {
|
838
|
+
left = new Literal(this.superReference(o));
|
839
|
+
rite = new Value(left);
|
840
|
+
}
|
841
|
+
rite = new Call(rite, this.args);
|
842
|
+
rite.isNew = this.isNew;
|
843
|
+
left = new Literal("typeof " + (left.compile(o)) + " === \"function\"");
|
844
|
+
return new If(left, new Value(rite), {
|
845
|
+
soak: true
|
846
|
+
});
|
847
|
+
}
|
848
|
+
call = this;
|
849
|
+
list = [];
|
850
|
+
while (true) {
|
851
|
+
if (call.variable instanceof Call) {
|
852
|
+
list.push(call);
|
853
|
+
call = call.variable;
|
854
|
+
continue;
|
855
|
+
}
|
856
|
+
if (!(call.variable instanceof Value)) {
|
857
|
+
break;
|
858
|
+
}
|
859
|
+
list.push(call);
|
860
|
+
if (!((call = call.variable.base) instanceof Call)) {
|
861
|
+
break;
|
862
|
+
}
|
863
|
+
}
|
864
|
+
_ref3 = list.reverse();
|
865
|
+
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
866
|
+
call = _ref3[_i];
|
867
|
+
if (ifn) {
|
868
|
+
if (call.variable instanceof Call) {
|
869
|
+
call.variable = ifn;
|
870
|
+
} else {
|
871
|
+
call.variable.base = ifn;
|
872
|
+
}
|
873
|
+
}
|
874
|
+
ifn = unfoldSoak(o, call, 'variable');
|
875
|
+
}
|
876
|
+
return ifn;
|
877
|
+
};
|
878
|
+
|
879
|
+
Call.prototype.filterImplicitObjects = function(list) {
|
880
|
+
var node, nodes, obj, prop, properties, _i, _j, _len, _len1, _ref2;
|
881
|
+
nodes = [];
|
882
|
+
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
883
|
+
node = list[_i];
|
884
|
+
if (!((typeof node.isObject === "function" ? node.isObject() : void 0) && node.base.generated)) {
|
885
|
+
nodes.push(node);
|
886
|
+
continue;
|
887
|
+
}
|
888
|
+
obj = null;
|
889
|
+
_ref2 = node.base.properties;
|
890
|
+
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
891
|
+
prop = _ref2[_j];
|
892
|
+
if (prop instanceof Assign || prop instanceof Comment) {
|
893
|
+
if (!obj) {
|
894
|
+
nodes.push(obj = new Obj(properties = [], true));
|
895
|
+
}
|
896
|
+
properties.push(prop);
|
897
|
+
} else {
|
898
|
+
nodes.push(prop);
|
899
|
+
obj = null;
|
900
|
+
}
|
901
|
+
}
|
902
|
+
}
|
903
|
+
return nodes;
|
904
|
+
};
|
905
|
+
|
906
|
+
Call.prototype.compileNode = function(o) {
|
907
|
+
var arg, args, code, _ref2;
|
908
|
+
if ((_ref2 = this.variable) != null) {
|
909
|
+
_ref2.front = this.front;
|
910
|
+
}
|
911
|
+
if (code = Splat.compileSplattedArray(o, this.args, true)) {
|
912
|
+
return this.compileSplat(o, code);
|
913
|
+
}
|
914
|
+
args = this.filterImplicitObjects(this.args);
|
915
|
+
args = ((function() {
|
916
|
+
var _i, _len, _results;
|
917
|
+
_results = [];
|
918
|
+
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
919
|
+
arg = args[_i];
|
920
|
+
_results.push(arg.compile(o, LEVEL_LIST));
|
921
|
+
}
|
922
|
+
return _results;
|
923
|
+
})()).join(', ');
|
924
|
+
if (this.isSuper) {
|
925
|
+
return this.superReference(o) + (".call(" + (this.superThis(o)) + (args && ', ' + args) + ")");
|
926
|
+
} else {
|
927
|
+
return (this.isNew ? 'new ' : '') + this.variable.compile(o, LEVEL_ACCESS) + ("(" + args + ")");
|
928
|
+
}
|
929
|
+
};
|
930
|
+
|
931
|
+
Call.prototype.compileSuper = function(args, o) {
|
932
|
+
return "" + (this.superReference(o)) + ".call(" + (this.superThis(o)) + (args.length ? ', ' : '') + args + ")";
|
933
|
+
};
|
934
|
+
|
935
|
+
Call.prototype.compileSplat = function(o, splatArgs) {
|
936
|
+
var base, fun, idt, name, ref;
|
937
|
+
if (this.isSuper) {
|
938
|
+
return "" + (this.superReference(o)) + ".apply(" + (this.superThis(o)) + ", " + splatArgs + ")";
|
939
|
+
}
|
940
|
+
if (this.isNew) {
|
941
|
+
idt = this.tab + TAB;
|
942
|
+
return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args), t = typeof result;\n" + idt + "return t == \"object\" || t == \"function\" ? result || child : child;\n" + this.tab + "})(" + (this.variable.compile(o, LEVEL_LIST)) + ", " + splatArgs + ", function(){})";
|
943
|
+
}
|
944
|
+
base = new Value(this.variable);
|
945
|
+
if ((name = base.properties.pop()) && base.isComplex()) {
|
946
|
+
ref = o.scope.freeVariable('ref');
|
947
|
+
fun = "(" + ref + " = " + (base.compile(o, LEVEL_LIST)) + ")" + (name.compile(o));
|
948
|
+
} else {
|
949
|
+
fun = base.compile(o, LEVEL_ACCESS);
|
950
|
+
if (SIMPLENUM.test(fun)) {
|
951
|
+
fun = "(" + fun + ")";
|
952
|
+
}
|
953
|
+
if (name) {
|
954
|
+
ref = fun;
|
955
|
+
fun += name.compile(o);
|
956
|
+
} else {
|
957
|
+
ref = 'null';
|
958
|
+
}
|
959
|
+
}
|
960
|
+
return "" + fun + ".apply(" + ref + ", " + splatArgs + ")";
|
961
|
+
};
|
962
|
+
|
963
|
+
return Call;
|
964
|
+
|
965
|
+
})(Base);
|
966
|
+
|
967
|
+
exports.Extends = Extends = (function(_super) {
|
968
|
+
|
969
|
+
__extends(Extends, _super);
|
970
|
+
|
971
|
+
function Extends(child, parent) {
|
972
|
+
this.child = child;
|
973
|
+
this.parent = parent;
|
974
|
+
}
|
975
|
+
|
976
|
+
Extends.prototype.children = ['child', 'parent'];
|
977
|
+
|
978
|
+
Extends.prototype.compile = function(o) {
|
979
|
+
return new Call(new Value(new Literal(utility('extends'))), [this.child, this.parent]).compile(o);
|
980
|
+
};
|
981
|
+
|
982
|
+
return Extends;
|
983
|
+
|
984
|
+
})(Base);
|
985
|
+
|
986
|
+
exports.Access = Access = (function(_super) {
|
987
|
+
|
988
|
+
__extends(Access, _super);
|
989
|
+
|
990
|
+
function Access(name, tag) {
|
991
|
+
this.name = name;
|
992
|
+
this.name.asKey = true;
|
993
|
+
this.soak = tag === 'soak';
|
994
|
+
}
|
995
|
+
|
996
|
+
Access.prototype.children = ['name'];
|
997
|
+
|
998
|
+
Access.prototype.compile = function(o) {
|
999
|
+
var name;
|
1000
|
+
name = this.name.compile(o);
|
1001
|
+
if (IDENTIFIER.test(name)) {
|
1002
|
+
return "." + name;
|
1003
|
+
} else {
|
1004
|
+
return "[" + name + "]";
|
1005
|
+
}
|
1006
|
+
};
|
1007
|
+
|
1008
|
+
Access.prototype.isComplex = NO;
|
1009
|
+
|
1010
|
+
return Access;
|
1011
|
+
|
1012
|
+
})(Base);
|
1013
|
+
|
1014
|
+
exports.Index = Index = (function(_super) {
|
1015
|
+
|
1016
|
+
__extends(Index, _super);
|
1017
|
+
|
1018
|
+
function Index(index) {
|
1019
|
+
this.index = index;
|
1020
|
+
}
|
1021
|
+
|
1022
|
+
Index.prototype.children = ['index'];
|
1023
|
+
|
1024
|
+
Index.prototype.compile = function(o) {
|
1025
|
+
return "[" + (this.index.compile(o, LEVEL_PAREN)) + "]";
|
1026
|
+
};
|
1027
|
+
|
1028
|
+
Index.prototype.isComplex = function() {
|
1029
|
+
return this.index.isComplex();
|
1030
|
+
};
|
1031
|
+
|
1032
|
+
return Index;
|
1033
|
+
|
1034
|
+
})(Base);
|
1035
|
+
|
1036
|
+
exports.Range = Range = (function(_super) {
|
1037
|
+
|
1038
|
+
__extends(Range, _super);
|
1039
|
+
|
1040
|
+
Range.prototype.children = ['from', 'to'];
|
1041
|
+
|
1042
|
+
function Range(from, to, tag) {
|
1043
|
+
this.from = from;
|
1044
|
+
this.to = to;
|
1045
|
+
this.exclusive = tag === 'exclusive';
|
1046
|
+
this.equals = this.exclusive ? '' : '=';
|
1047
|
+
}
|
1048
|
+
|
1049
|
+
Range.prototype.compileVariables = function(o) {
|
1050
|
+
var step, _ref2, _ref3, _ref4, _ref5;
|
1051
|
+
o = merge(o, {
|
1052
|
+
top: true
|
1053
|
+
});
|
1054
|
+
_ref2 = this.from.cache(o, LEVEL_LIST), this.fromC = _ref2[0], this.fromVar = _ref2[1];
|
1055
|
+
_ref3 = this.to.cache(o, LEVEL_LIST), this.toC = _ref3[0], this.toVar = _ref3[1];
|
1056
|
+
if (step = del(o, 'step')) {
|
1057
|
+
_ref4 = step.cache(o, LEVEL_LIST), this.step = _ref4[0], this.stepVar = _ref4[1];
|
1058
|
+
}
|
1059
|
+
_ref5 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref5[0], this.toNum = _ref5[1];
|
1060
|
+
if (this.stepVar) {
|
1061
|
+
return this.stepNum = this.stepVar.match(SIMPLENUM);
|
1062
|
+
}
|
1063
|
+
};
|
1064
|
+
|
1065
|
+
Range.prototype.compileNode = function(o) {
|
1066
|
+
var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, stepPart, to, varPart, _ref2, _ref3;
|
1067
|
+
if (!this.fromVar) {
|
1068
|
+
this.compileVariables(o);
|
1069
|
+
}
|
1070
|
+
if (!o.index) {
|
1071
|
+
return this.compileArray(o);
|
1072
|
+
}
|
1073
|
+
known = this.fromNum && this.toNum;
|
1074
|
+
idx = del(o, 'index');
|
1075
|
+
idxName = del(o, 'name');
|
1076
|
+
namedIndex = idxName && idxName !== idx;
|
1077
|
+
varPart = "" + idx + " = " + this.fromC;
|
1078
|
+
if (this.toC !== this.toVar) {
|
1079
|
+
varPart += ", " + this.toC;
|
1080
|
+
}
|
1081
|
+
if (this.step !== this.stepVar) {
|
1082
|
+
varPart += ", " + this.step;
|
1083
|
+
}
|
1084
|
+
_ref2 = ["" + idx + " <" + this.equals, "" + idx + " >" + this.equals], lt = _ref2[0], gt = _ref2[1];
|
1085
|
+
condPart = this.stepNum ? +this.stepNum > 0 ? "" + lt + " " + this.toVar : "" + gt + " " + this.toVar : known ? ((_ref3 = [+this.fromNum, +this.toNum], from = _ref3[0], to = _ref3[1], _ref3), from <= to ? "" + lt + " " + to : "" + gt + " " + to) : (cond = "" + this.fromVar + " <= " + this.toVar, "" + cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar);
|
1086
|
+
stepPart = this.stepVar ? "" + idx + " += " + this.stepVar : known ? namedIndex ? from <= to ? "++" + idx : "--" + idx : from <= to ? "" + idx + "++" : "" + idx + "--" : namedIndex ? "" + cond + " ? ++" + idx + " : --" + idx : "" + cond + " ? " + idx + "++ : " + idx + "--";
|
1087
|
+
if (namedIndex) {
|
1088
|
+
varPart = "" + idxName + " = " + varPart;
|
1089
|
+
}
|
1090
|
+
if (namedIndex) {
|
1091
|
+
stepPart = "" + idxName + " = " + stepPart;
|
1092
|
+
}
|
1093
|
+
return "" + varPart + "; " + condPart + "; " + stepPart;
|
1094
|
+
};
|
1095
|
+
|
1096
|
+
Range.prototype.compileArray = function(o) {
|
1097
|
+
var args, body, cond, hasArgs, i, idt, post, pre, range, result, vars, _i, _ref2, _ref3, _results;
|
1098
|
+
if (this.fromNum && this.toNum && Math.abs(this.fromNum - this.toNum) <= 20) {
|
1099
|
+
range = (function() {
|
1100
|
+
_results = [];
|
1101
|
+
for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i++ : _i--){ _results.push(_i); }
|
1102
|
+
return _results;
|
1103
|
+
}).apply(this);
|
1104
|
+
if (this.exclusive) {
|
1105
|
+
range.pop();
|
1106
|
+
}
|
1107
|
+
return "[" + (range.join(', ')) + "]";
|
1108
|
+
}
|
1109
|
+
idt = this.tab + TAB;
|
1110
|
+
i = o.scope.freeVariable('i');
|
1111
|
+
result = o.scope.freeVariable('results');
|
1112
|
+
pre = "\n" + idt + result + " = [];";
|
1113
|
+
if (this.fromNum && this.toNum) {
|
1114
|
+
o.index = i;
|
1115
|
+
body = this.compileNode(o);
|
1116
|
+
} else {
|
1117
|
+
vars = ("" + i + " = " + this.fromC) + (this.toC !== this.toVar ? ", " + this.toC : '');
|
1118
|
+
cond = "" + this.fromVar + " <= " + this.toVar;
|
1119
|
+
body = "var " + vars + "; " + cond + " ? " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + cond + " ? " + i + "++ : " + i + "--";
|
1120
|
+
}
|
1121
|
+
post = "{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + o.indent;
|
1122
|
+
hasArgs = function(node) {
|
1123
|
+
return node != null ? node.contains(function(n) {
|
1124
|
+
return n instanceof Literal && n.value === 'arguments' && !n.asKey;
|
1125
|
+
}) : void 0;
|
1126
|
+
};
|
1127
|
+
if (hasArgs(this.from) || hasArgs(this.to)) {
|
1128
|
+
args = ', arguments';
|
1129
|
+
}
|
1130
|
+
return "(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).apply(this" + (args != null ? args : '') + ")";
|
1131
|
+
};
|
1132
|
+
|
1133
|
+
return Range;
|
1134
|
+
|
1135
|
+
})(Base);
|
1136
|
+
|
1137
|
+
exports.Slice = Slice = (function(_super) {
|
1138
|
+
|
1139
|
+
__extends(Slice, _super);
|
1140
|
+
|
1141
|
+
Slice.prototype.children = ['range'];
|
1142
|
+
|
1143
|
+
function Slice(range) {
|
1144
|
+
this.range = range;
|
1145
|
+
Slice.__super__.constructor.call(this);
|
1146
|
+
}
|
1147
|
+
|
1148
|
+
Slice.prototype.compileNode = function(o) {
|
1149
|
+
var compiled, from, fromStr, to, toStr, _ref2;
|
1150
|
+
_ref2 = this.range, to = _ref2.to, from = _ref2.from;
|
1151
|
+
fromStr = from && from.compile(o, LEVEL_PAREN) || '0';
|
1152
|
+
compiled = to && to.compile(o, LEVEL_PAREN);
|
1153
|
+
if (to && !(!this.range.exclusive && +compiled === -1)) {
|
1154
|
+
toStr = ', ' + (this.range.exclusive ? compiled : SIMPLENUM.test(compiled) ? "" + (+compiled + 1) : (compiled = to.compile(o, LEVEL_ACCESS), "" + compiled + " + 1 || 9e9"));
|
1155
|
+
}
|
1156
|
+
return ".slice(" + fromStr + (toStr || '') + ")";
|
1157
|
+
};
|
1158
|
+
|
1159
|
+
return Slice;
|
1160
|
+
|
1161
|
+
})(Base);
|
1162
|
+
|
1163
|
+
exports.Obj = Obj = (function(_super) {
|
1164
|
+
|
1165
|
+
__extends(Obj, _super);
|
1166
|
+
|
1167
|
+
function Obj(props, generated) {
|
1168
|
+
this.generated = generated != null ? generated : false;
|
1169
|
+
this.objects = this.properties = props || [];
|
1170
|
+
}
|
1171
|
+
|
1172
|
+
Obj.prototype.children = ['properties'];
|
1173
|
+
|
1174
|
+
Obj.prototype.compileNode = function(o) {
|
1175
|
+
var i, idt, indent, join, lastNoncom, node, obj, prop, propName, propNames, props, _i, _j, _len, _len1, _ref2;
|
1176
|
+
props = this.properties;
|
1177
|
+
propNames = [];
|
1178
|
+
_ref2 = this.properties;
|
1179
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1180
|
+
prop = _ref2[_i];
|
1181
|
+
if (prop.isComplex()) {
|
1182
|
+
prop = prop.variable;
|
1183
|
+
}
|
1184
|
+
if (prop != null) {
|
1185
|
+
propName = prop.unwrapAll().value.toString();
|
1186
|
+
if (__indexOf.call(propNames, propName) >= 0) {
|
1187
|
+
throw SyntaxError("multiple object literal properties named \"" + propName + "\"");
|
1188
|
+
}
|
1189
|
+
propNames.push(propName);
|
1190
|
+
}
|
1191
|
+
}
|
1192
|
+
if (!props.length) {
|
1193
|
+
return (this.front ? '({})' : '{}');
|
1194
|
+
}
|
1195
|
+
if (this.generated) {
|
1196
|
+
for (_j = 0, _len1 = props.length; _j < _len1; _j++) {
|
1197
|
+
node = props[_j];
|
1198
|
+
if (node instanceof Value) {
|
1199
|
+
throw new Error('cannot have an implicit value in an implicit object');
|
1200
|
+
}
|
1201
|
+
}
|
1202
|
+
}
|
1203
|
+
idt = o.indent += TAB;
|
1204
|
+
lastNoncom = this.lastNonComment(this.properties);
|
1205
|
+
props = (function() {
|
1206
|
+
var _k, _len2, _results;
|
1207
|
+
_results = [];
|
1208
|
+
for (i = _k = 0, _len2 = props.length; _k < _len2; i = ++_k) {
|
1209
|
+
prop = props[i];
|
1210
|
+
join = i === props.length - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n';
|
1211
|
+
indent = prop instanceof Comment ? '' : idt;
|
1212
|
+
if (prop instanceof Value && prop["this"]) {
|
1213
|
+
prop = new Assign(prop.properties[0].name, prop, 'object');
|
1214
|
+
}
|
1215
|
+
if (!(prop instanceof Comment)) {
|
1216
|
+
if (!(prop instanceof Assign)) {
|
1217
|
+
prop = new Assign(prop, prop, 'object');
|
1218
|
+
}
|
1219
|
+
(prop.variable.base || prop.variable).asKey = true;
|
1220
|
+
}
|
1221
|
+
_results.push(indent + prop.compile(o, LEVEL_TOP) + join);
|
1222
|
+
}
|
1223
|
+
return _results;
|
1224
|
+
})();
|
1225
|
+
props = props.join('');
|
1226
|
+
obj = "{" + (props && '\n' + props + '\n' + this.tab) + "}";
|
1227
|
+
if (this.front) {
|
1228
|
+
return "(" + obj + ")";
|
1229
|
+
} else {
|
1230
|
+
return obj;
|
1231
|
+
}
|
1232
|
+
};
|
1233
|
+
|
1234
|
+
Obj.prototype.assigns = function(name) {
|
1235
|
+
var prop, _i, _len, _ref2;
|
1236
|
+
_ref2 = this.properties;
|
1237
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1238
|
+
prop = _ref2[_i];
|
1239
|
+
if (prop.assigns(name)) {
|
1240
|
+
return true;
|
1241
|
+
}
|
1242
|
+
}
|
1243
|
+
return false;
|
1244
|
+
};
|
1245
|
+
|
1246
|
+
return Obj;
|
1247
|
+
|
1248
|
+
})(Base);
|
1249
|
+
|
1250
|
+
exports.Arr = Arr = (function(_super) {
|
1251
|
+
|
1252
|
+
__extends(Arr, _super);
|
1253
|
+
|
1254
|
+
function Arr(objs) {
|
1255
|
+
this.objects = objs || [];
|
1256
|
+
}
|
1257
|
+
|
1258
|
+
Arr.prototype.children = ['objects'];
|
1259
|
+
|
1260
|
+
Arr.prototype.filterImplicitObjects = Call.prototype.filterImplicitObjects;
|
1261
|
+
|
1262
|
+
Arr.prototype.compileNode = function(o) {
|
1263
|
+
var code, obj, objs;
|
1264
|
+
if (!this.objects.length) {
|
1265
|
+
return '[]';
|
1266
|
+
}
|
1267
|
+
o.indent += TAB;
|
1268
|
+
objs = this.filterImplicitObjects(this.objects);
|
1269
|
+
if (code = Splat.compileSplattedArray(o, objs)) {
|
1270
|
+
return code;
|
1271
|
+
}
|
1272
|
+
code = ((function() {
|
1273
|
+
var _i, _len, _results;
|
1274
|
+
_results = [];
|
1275
|
+
for (_i = 0, _len = objs.length; _i < _len; _i++) {
|
1276
|
+
obj = objs[_i];
|
1277
|
+
_results.push(obj.compile(o, LEVEL_LIST));
|
1278
|
+
}
|
1279
|
+
return _results;
|
1280
|
+
})()).join(', ');
|
1281
|
+
if (code.indexOf('\n') >= 0) {
|
1282
|
+
return "[\n" + o.indent + code + "\n" + this.tab + "]";
|
1283
|
+
} else {
|
1284
|
+
return "[" + code + "]";
|
1285
|
+
}
|
1286
|
+
};
|
1287
|
+
|
1288
|
+
Arr.prototype.assigns = function(name) {
|
1289
|
+
var obj, _i, _len, _ref2;
|
1290
|
+
_ref2 = this.objects;
|
1291
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1292
|
+
obj = _ref2[_i];
|
1293
|
+
if (obj.assigns(name)) {
|
1294
|
+
return true;
|
1295
|
+
}
|
1296
|
+
}
|
1297
|
+
return false;
|
1298
|
+
};
|
1299
|
+
|
1300
|
+
return Arr;
|
1301
|
+
|
1302
|
+
})(Base);
|
1303
|
+
|
1304
|
+
exports.Class = Class = (function(_super) {
|
1305
|
+
|
1306
|
+
__extends(Class, _super);
|
1307
|
+
|
1308
|
+
function Class(variable, parent, body) {
|
1309
|
+
this.variable = variable;
|
1310
|
+
this.parent = parent;
|
1311
|
+
this.body = body != null ? body : new Block;
|
1312
|
+
this.boundFuncs = [];
|
1313
|
+
this.body.classBody = true;
|
1314
|
+
}
|
1315
|
+
|
1316
|
+
Class.prototype.children = ['variable', 'parent', 'body'];
|
1317
|
+
|
1318
|
+
Class.prototype.determineName = function() {
|
1319
|
+
var decl, tail;
|
1320
|
+
if (!this.variable) {
|
1321
|
+
return null;
|
1322
|
+
}
|
1323
|
+
decl = (tail = last(this.variable.properties)) ? tail instanceof Access && tail.name.value : this.variable.base.value;
|
1324
|
+
if (__indexOf.call(STRICT_PROSCRIBED, decl) >= 0) {
|
1325
|
+
throw SyntaxError("variable name may not be " + decl);
|
1326
|
+
}
|
1327
|
+
return decl && (decl = IDENTIFIER.test(decl) && decl);
|
1328
|
+
};
|
1329
|
+
|
1330
|
+
Class.prototype.setContext = function(name) {
|
1331
|
+
return this.body.traverseChildren(false, function(node) {
|
1332
|
+
if (node.classBody) {
|
1333
|
+
return false;
|
1334
|
+
}
|
1335
|
+
if (node instanceof Literal && node.value === 'this') {
|
1336
|
+
return node.value = name;
|
1337
|
+
} else if (node instanceof Code) {
|
1338
|
+
node.klass = name;
|
1339
|
+
if (node.bound) {
|
1340
|
+
return node.context = name;
|
1341
|
+
}
|
1342
|
+
}
|
1343
|
+
});
|
1344
|
+
};
|
1345
|
+
|
1346
|
+
Class.prototype.addBoundFunctions = function(o) {
|
1347
|
+
var bvar, lhs, _i, _len, _ref2, _results;
|
1348
|
+
if (this.boundFuncs.length) {
|
1349
|
+
_ref2 = this.boundFuncs;
|
1350
|
+
_results = [];
|
1351
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1352
|
+
bvar = _ref2[_i];
|
1353
|
+
lhs = (new Value(new Literal("this"), [new Access(bvar)])).compile(o);
|
1354
|
+
_results.push(this.ctor.body.unshift(new Literal("" + lhs + " = " + (utility('bind')) + "(" + lhs + ", this)")));
|
1355
|
+
}
|
1356
|
+
return _results;
|
1357
|
+
}
|
1358
|
+
};
|
1359
|
+
|
1360
|
+
Class.prototype.addProperties = function(node, name, o) {
|
1361
|
+
var assign, base, exprs, func, props;
|
1362
|
+
props = node.base.properties.slice(0);
|
1363
|
+
exprs = (function() {
|
1364
|
+
var _results;
|
1365
|
+
_results = [];
|
1366
|
+
while (assign = props.shift()) {
|
1367
|
+
if (assign instanceof Assign) {
|
1368
|
+
base = assign.variable.base;
|
1369
|
+
delete assign.context;
|
1370
|
+
func = assign.value;
|
1371
|
+
if (base.value === 'constructor') {
|
1372
|
+
if (this.ctor) {
|
1373
|
+
throw new Error('cannot define more than one constructor in a class');
|
1374
|
+
}
|
1375
|
+
if (func.bound) {
|
1376
|
+
throw new Error('cannot define a constructor as a bound function');
|
1377
|
+
}
|
1378
|
+
if (func instanceof Code) {
|
1379
|
+
assign = this.ctor = func;
|
1380
|
+
} else {
|
1381
|
+
this.externalCtor = o.scope.freeVariable('class');
|
1382
|
+
assign = new Assign(new Literal(this.externalCtor), func);
|
1383
|
+
}
|
1384
|
+
} else {
|
1385
|
+
if (assign.variable["this"]) {
|
1386
|
+
func["static"] = true;
|
1387
|
+
if (func.bound) {
|
1388
|
+
func.context = name;
|
1389
|
+
}
|
1390
|
+
} else {
|
1391
|
+
assign.variable = new Value(new Literal(name), [new Access(new Literal('prototype')), new Access(base)]);
|
1392
|
+
if (func instanceof Code && func.bound) {
|
1393
|
+
this.boundFuncs.push(base);
|
1394
|
+
func.bound = false;
|
1395
|
+
}
|
1396
|
+
}
|
1397
|
+
}
|
1398
|
+
}
|
1399
|
+
_results.push(assign);
|
1400
|
+
}
|
1401
|
+
return _results;
|
1402
|
+
}).call(this);
|
1403
|
+
return compact(exprs);
|
1404
|
+
};
|
1405
|
+
|
1406
|
+
Class.prototype.walkBody = function(name, o) {
|
1407
|
+
var _this = this;
|
1408
|
+
return this.traverseChildren(false, function(child) {
|
1409
|
+
var exps, i, node, _i, _len, _ref2;
|
1410
|
+
if (child instanceof Class) {
|
1411
|
+
return false;
|
1412
|
+
}
|
1413
|
+
if (child instanceof Block) {
|
1414
|
+
_ref2 = exps = child.expressions;
|
1415
|
+
for (i = _i = 0, _len = _ref2.length; _i < _len; i = ++_i) {
|
1416
|
+
node = _ref2[i];
|
1417
|
+
if (node instanceof Value && node.isObject(true)) {
|
1418
|
+
exps[i] = _this.addProperties(node, name, o);
|
1419
|
+
}
|
1420
|
+
}
|
1421
|
+
return child.expressions = exps = flatten(exps);
|
1422
|
+
}
|
1423
|
+
});
|
1424
|
+
};
|
1425
|
+
|
1426
|
+
Class.prototype.hoistDirectivePrologue = function() {
|
1427
|
+
var expressions, index, node;
|
1428
|
+
index = 0;
|
1429
|
+
expressions = this.body.expressions;
|
1430
|
+
while ((node = expressions[index]) && node instanceof Comment || node instanceof Value && node.isString()) {
|
1431
|
+
++index;
|
1432
|
+
}
|
1433
|
+
return this.directives = expressions.splice(0, index);
|
1434
|
+
};
|
1435
|
+
|
1436
|
+
Class.prototype.ensureConstructor = function(name) {
|
1437
|
+
if (!this.ctor) {
|
1438
|
+
this.ctor = new Code;
|
1439
|
+
if (this.parent) {
|
1440
|
+
this.ctor.body.push(new Literal("" + name + ".__super__.constructor.apply(this, arguments)"));
|
1441
|
+
}
|
1442
|
+
if (this.externalCtor) {
|
1443
|
+
this.ctor.body.push(new Literal("" + this.externalCtor + ".apply(this, arguments)"));
|
1444
|
+
}
|
1445
|
+
this.ctor.body.makeReturn();
|
1446
|
+
this.body.expressions.unshift(this.ctor);
|
1447
|
+
}
|
1448
|
+
this.ctor.ctor = this.ctor.name = name;
|
1449
|
+
this.ctor.klass = null;
|
1450
|
+
return this.ctor.noReturn = true;
|
1451
|
+
};
|
1452
|
+
|
1453
|
+
Class.prototype.compileNode = function(o) {
|
1454
|
+
var call, decl, klass, lname, name, params, _ref2;
|
1455
|
+
decl = this.determineName();
|
1456
|
+
name = decl || '_Class';
|
1457
|
+
if (name.reserved) {
|
1458
|
+
name = "_" + name;
|
1459
|
+
}
|
1460
|
+
lname = new Literal(name);
|
1461
|
+
this.hoistDirectivePrologue();
|
1462
|
+
this.setContext(name);
|
1463
|
+
this.walkBody(name, o);
|
1464
|
+
this.ensureConstructor(name);
|
1465
|
+
this.body.spaced = true;
|
1466
|
+
if (!(this.ctor instanceof Code)) {
|
1467
|
+
this.body.expressions.unshift(this.ctor);
|
1468
|
+
}
|
1469
|
+
this.body.expressions.push(lname);
|
1470
|
+
(_ref2 = this.body.expressions).unshift.apply(_ref2, this.directives);
|
1471
|
+
this.addBoundFunctions(o);
|
1472
|
+
call = Closure.wrap(this.body);
|
1473
|
+
if (this.parent) {
|
1474
|
+
this.superClass = new Literal(o.scope.freeVariable('super', false));
|
1475
|
+
this.body.expressions.unshift(new Extends(lname, this.superClass));
|
1476
|
+
call.args.push(this.parent);
|
1477
|
+
params = call.variable.params || call.variable.base.params;
|
1478
|
+
params.push(new Param(this.superClass));
|
1479
|
+
}
|
1480
|
+
klass = new Parens(call, true);
|
1481
|
+
if (this.variable) {
|
1482
|
+
klass = new Assign(this.variable, klass);
|
1483
|
+
}
|
1484
|
+
return klass.compile(o);
|
1485
|
+
};
|
1486
|
+
|
1487
|
+
return Class;
|
1488
|
+
|
1489
|
+
})(Base);
|
1490
|
+
|
1491
|
+
exports.Assign = Assign = (function(_super) {
|
1492
|
+
|
1493
|
+
__extends(Assign, _super);
|
1494
|
+
|
1495
|
+
function Assign(variable, value, context, options) {
|
1496
|
+
var forbidden, name, _ref2;
|
1497
|
+
this.variable = variable;
|
1498
|
+
this.value = value;
|
1499
|
+
this.context = context;
|
1500
|
+
this.param = options && options.param;
|
1501
|
+
this.subpattern = options && options.subpattern;
|
1502
|
+
forbidden = (_ref2 = (name = this.variable.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0);
|
1503
|
+
if (forbidden && this.context !== 'object') {
|
1504
|
+
throw SyntaxError("variable name may not be \"" + name + "\"");
|
1505
|
+
}
|
1506
|
+
}
|
1507
|
+
|
1508
|
+
Assign.prototype.children = ['variable', 'value'];
|
1509
|
+
|
1510
|
+
Assign.prototype.isStatement = function(o) {
|
1511
|
+
return (o != null ? o.level : void 0) === LEVEL_TOP && (this.context != null) && __indexOf.call(this.context, "?") >= 0;
|
1512
|
+
};
|
1513
|
+
|
1514
|
+
Assign.prototype.assigns = function(name) {
|
1515
|
+
return this[this.context === 'object' ? 'value' : 'variable'].assigns(name);
|
1516
|
+
};
|
1517
|
+
|
1518
|
+
Assign.prototype.unfoldSoak = function(o) {
|
1519
|
+
return unfoldSoak(o, this, 'variable');
|
1520
|
+
};
|
1521
|
+
|
1522
|
+
Assign.prototype.compileNode = function(o) {
|
1523
|
+
var isValue, match, name, val, varBase, _ref2, _ref3, _ref4, _ref5;
|
1524
|
+
if (isValue = this.variable instanceof Value) {
|
1525
|
+
if (this.variable.isArray() || this.variable.isObject()) {
|
1526
|
+
return this.compilePatternMatch(o);
|
1527
|
+
}
|
1528
|
+
if (this.variable.isSplice()) {
|
1529
|
+
return this.compileSplice(o);
|
1530
|
+
}
|
1531
|
+
if ((_ref2 = this.context) === '||=' || _ref2 === '&&=' || _ref2 === '?=') {
|
1532
|
+
return this.compileConditional(o);
|
1533
|
+
}
|
1534
|
+
}
|
1535
|
+
name = this.variable.compile(o, LEVEL_LIST);
|
1536
|
+
if (!this.context) {
|
1537
|
+
if (!(varBase = this.variable.unwrapAll()).isAssignable()) {
|
1538
|
+
throw SyntaxError("\"" + (this.variable.compile(o)) + "\" cannot be assigned.");
|
1539
|
+
}
|
1540
|
+
if (!(typeof varBase.hasProperties === "function" ? varBase.hasProperties() : void 0)) {
|
1541
|
+
if (this.param) {
|
1542
|
+
o.scope.add(name, 'var');
|
1543
|
+
} else {
|
1544
|
+
o.scope.find(name);
|
1545
|
+
}
|
1546
|
+
}
|
1547
|
+
}
|
1548
|
+
if (this.value instanceof Code && (match = METHOD_DEF.exec(name))) {
|
1549
|
+
if (match[1]) {
|
1550
|
+
this.value.klass = match[1];
|
1551
|
+
}
|
1552
|
+
this.value.name = (_ref3 = (_ref4 = (_ref5 = match[2]) != null ? _ref5 : match[3]) != null ? _ref4 : match[4]) != null ? _ref3 : match[5];
|
1553
|
+
}
|
1554
|
+
val = this.value.compile(o, LEVEL_LIST);
|
1555
|
+
if (this.context === 'object') {
|
1556
|
+
return "" + name + ": " + val;
|
1557
|
+
}
|
1558
|
+
val = name + (" " + (this.context || '=') + " ") + val;
|
1559
|
+
if (o.level <= LEVEL_LIST) {
|
1560
|
+
return val;
|
1561
|
+
} else {
|
1562
|
+
return "(" + val + ")";
|
1563
|
+
}
|
1564
|
+
};
|
1565
|
+
|
1566
|
+
Assign.prototype.compilePatternMatch = function(o) {
|
1567
|
+
var acc, assigns, code, i, idx, isObject, ivar, name, obj, objects, olen, ref, rest, splat, top, val, value, vvar, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
1568
|
+
top = o.level === LEVEL_TOP;
|
1569
|
+
value = this.value;
|
1570
|
+
objects = this.variable.base.objects;
|
1571
|
+
if (!(olen = objects.length)) {
|
1572
|
+
code = value.compile(o);
|
1573
|
+
if (o.level >= LEVEL_OP) {
|
1574
|
+
return "(" + code + ")";
|
1575
|
+
} else {
|
1576
|
+
return code;
|
1577
|
+
}
|
1578
|
+
}
|
1579
|
+
isObject = this.variable.isObject();
|
1580
|
+
if (top && olen === 1 && !((obj = objects[0]) instanceof Splat)) {
|
1581
|
+
if (obj instanceof Assign) {
|
1582
|
+
_ref2 = obj, (_ref3 = _ref2.variable, idx = _ref3.base), obj = _ref2.value;
|
1583
|
+
} else {
|
1584
|
+
if (obj.base instanceof Parens) {
|
1585
|
+
_ref4 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref4[0], idx = _ref4[1];
|
1586
|
+
} else {
|
1587
|
+
idx = isObject ? obj["this"] ? obj.properties[0].name : obj : new Literal(0);
|
1588
|
+
}
|
1589
|
+
}
|
1590
|
+
acc = IDENTIFIER.test(idx.unwrap().value || 0);
|
1591
|
+
value = new Value(value);
|
1592
|
+
value.properties.push(new (acc ? Access : Index)(idx));
|
1593
|
+
if (_ref5 = obj.unwrap().value, __indexOf.call(RESERVED, _ref5) >= 0) {
|
1594
|
+
throw new SyntaxError("assignment to a reserved word: " + (obj.compile(o)) + " = " + (value.compile(o)));
|
1595
|
+
}
|
1596
|
+
return new Assign(obj, value, null, {
|
1597
|
+
param: this.param
|
1598
|
+
}).compile(o, LEVEL_TOP);
|
1599
|
+
}
|
1600
|
+
vvar = value.compile(o, LEVEL_LIST);
|
1601
|
+
assigns = [];
|
1602
|
+
splat = false;
|
1603
|
+
if (!IDENTIFIER.test(vvar) || this.variable.assigns(vvar)) {
|
1604
|
+
assigns.push("" + (ref = o.scope.freeVariable('ref')) + " = " + vvar);
|
1605
|
+
vvar = ref;
|
1606
|
+
}
|
1607
|
+
for (i = _i = 0, _len = objects.length; _i < _len; i = ++_i) {
|
1608
|
+
obj = objects[i];
|
1609
|
+
idx = i;
|
1610
|
+
if (isObject) {
|
1611
|
+
if (obj instanceof Assign) {
|
1612
|
+
_ref6 = obj, (_ref7 = _ref6.variable, idx = _ref7.base), obj = _ref6.value;
|
1613
|
+
} else {
|
1614
|
+
if (obj.base instanceof Parens) {
|
1615
|
+
_ref8 = new Value(obj.unwrapAll()).cacheReference(o), obj = _ref8[0], idx = _ref8[1];
|
1616
|
+
} else {
|
1617
|
+
idx = obj["this"] ? obj.properties[0].name : obj;
|
1618
|
+
}
|
1619
|
+
}
|
1620
|
+
}
|
1621
|
+
if (!splat && obj instanceof Splat) {
|
1622
|
+
name = obj.name.unwrap().value;
|
1623
|
+
obj = obj.unwrap();
|
1624
|
+
val = "" + olen + " <= " + vvar + ".length ? " + (utility('slice')) + ".call(" + vvar + ", " + i;
|
1625
|
+
if (rest = olen - i - 1) {
|
1626
|
+
ivar = o.scope.freeVariable('i');
|
1627
|
+
val += ", " + ivar + " = " + vvar + ".length - " + rest + ") : (" + ivar + " = " + i + ", [])";
|
1628
|
+
} else {
|
1629
|
+
val += ") : []";
|
1630
|
+
}
|
1631
|
+
val = new Literal(val);
|
1632
|
+
splat = "" + ivar + "++";
|
1633
|
+
} else {
|
1634
|
+
name = obj.unwrap().value;
|
1635
|
+
if (obj instanceof Splat) {
|
1636
|
+
obj = obj.name.compile(o);
|
1637
|
+
throw new SyntaxError("multiple splats are disallowed in an assignment: " + obj + "...");
|
1638
|
+
}
|
1639
|
+
if (typeof idx === 'number') {
|
1640
|
+
idx = new Literal(splat || idx);
|
1641
|
+
acc = false;
|
1642
|
+
} else {
|
1643
|
+
acc = isObject && IDENTIFIER.test(idx.unwrap().value || 0);
|
1644
|
+
}
|
1645
|
+
val = new Value(new Literal(vvar), [new (acc ? Access : Index)(idx)]);
|
1646
|
+
}
|
1647
|
+
if ((name != null) && __indexOf.call(RESERVED, name) >= 0) {
|
1648
|
+
throw new SyntaxError("assignment to a reserved word: " + (obj.compile(o)) + " = " + (val.compile(o)));
|
1649
|
+
}
|
1650
|
+
assigns.push(new Assign(obj, val, null, {
|
1651
|
+
param: this.param,
|
1652
|
+
subpattern: true
|
1653
|
+
}).compile(o, LEVEL_LIST));
|
1654
|
+
}
|
1655
|
+
if (!(top || this.subpattern)) {
|
1656
|
+
assigns.push(vvar);
|
1657
|
+
}
|
1658
|
+
code = assigns.join(', ');
|
1659
|
+
if (o.level < LEVEL_LIST) {
|
1660
|
+
return code;
|
1661
|
+
} else {
|
1662
|
+
return "(" + code + ")";
|
1663
|
+
}
|
1664
|
+
};
|
1665
|
+
|
1666
|
+
Assign.prototype.compileConditional = function(o) {
|
1667
|
+
var left, right, _ref2;
|
1668
|
+
_ref2 = this.variable.cacheReference(o), left = _ref2[0], right = _ref2[1];
|
1669
|
+
if (!left.properties.length && left.base instanceof Literal && left.base.value !== "this" && !o.scope.check(left.base.value)) {
|
1670
|
+
throw new Error("the variable \"" + left.base.value + "\" can't be assigned with " + this.context + " because it has not been defined.");
|
1671
|
+
}
|
1672
|
+
if (__indexOf.call(this.context, "?") >= 0) {
|
1673
|
+
o.isExistentialEquals = true;
|
1674
|
+
}
|
1675
|
+
return new Op(this.context.slice(0, -1), left, new Assign(right, this.value, '=')).compile(o);
|
1676
|
+
};
|
1677
|
+
|
1678
|
+
Assign.prototype.compileSplice = function(o) {
|
1679
|
+
var code, exclusive, from, fromDecl, fromRef, name, to, valDef, valRef, _ref2, _ref3, _ref4;
|
1680
|
+
_ref2 = this.variable.properties.pop().range, from = _ref2.from, to = _ref2.to, exclusive = _ref2.exclusive;
|
1681
|
+
name = this.variable.compile(o);
|
1682
|
+
_ref3 = (from != null ? from.cache(o, LEVEL_OP) : void 0) || ['0', '0'], fromDecl = _ref3[0], fromRef = _ref3[1];
|
1683
|
+
if (to) {
|
1684
|
+
if ((from != null ? from.isSimpleNumber() : void 0) && to.isSimpleNumber()) {
|
1685
|
+
to = +to.compile(o) - +fromRef;
|
1686
|
+
if (!exclusive) {
|
1687
|
+
to += 1;
|
1688
|
+
}
|
1689
|
+
} else {
|
1690
|
+
to = to.compile(o, LEVEL_ACCESS) + ' - ' + fromRef;
|
1691
|
+
if (!exclusive) {
|
1692
|
+
to += ' + 1';
|
1693
|
+
}
|
1694
|
+
}
|
1695
|
+
} else {
|
1696
|
+
to = "9e9";
|
1697
|
+
}
|
1698
|
+
_ref4 = this.value.cache(o, LEVEL_LIST), valDef = _ref4[0], valRef = _ref4[1];
|
1699
|
+
code = "[].splice.apply(" + name + ", [" + fromDecl + ", " + to + "].concat(" + valDef + ")), " + valRef;
|
1700
|
+
if (o.level > LEVEL_TOP) {
|
1701
|
+
return "(" + code + ")";
|
1702
|
+
} else {
|
1703
|
+
return code;
|
1704
|
+
}
|
1705
|
+
};
|
1706
|
+
|
1707
|
+
return Assign;
|
1708
|
+
|
1709
|
+
})(Base);
|
1710
|
+
|
1711
|
+
exports.Code = Code = (function(_super) {
|
1712
|
+
|
1713
|
+
__extends(Code, _super);
|
1714
|
+
|
1715
|
+
function Code(params, body, tag) {
|
1716
|
+
this.params = params || [];
|
1717
|
+
this.body = body || new Block;
|
1718
|
+
this.bound = tag === 'boundfunc';
|
1719
|
+
if (this.bound) {
|
1720
|
+
this.context = '_this';
|
1721
|
+
}
|
1722
|
+
}
|
1723
|
+
|
1724
|
+
Code.prototype.children = ['params', 'body'];
|
1725
|
+
|
1726
|
+
Code.prototype.isStatement = function() {
|
1727
|
+
return !!this.ctor;
|
1728
|
+
};
|
1729
|
+
|
1730
|
+
Code.prototype.jumps = NO;
|
1731
|
+
|
1732
|
+
Code.prototype.compileNode = function(o) {
|
1733
|
+
var code, exprs, i, idt, lit, name, p, param, params, ref, splats, uniqs, val, wasEmpty, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _m, _n, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
|
1734
|
+
o.scope = new Scope(o.scope, this.body, this);
|
1735
|
+
o.scope.shared = del(o, 'sharedScope');
|
1736
|
+
o.indent += TAB;
|
1737
|
+
delete o.bare;
|
1738
|
+
delete o.isExistentialEquals;
|
1739
|
+
params = [];
|
1740
|
+
exprs = [];
|
1741
|
+
_ref2 = this.paramNames();
|
1742
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1743
|
+
name = _ref2[_i];
|
1744
|
+
if (!o.scope.check(name)) {
|
1745
|
+
o.scope.parameter(name);
|
1746
|
+
}
|
1747
|
+
}
|
1748
|
+
_ref3 = this.params;
|
1749
|
+
for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
|
1750
|
+
param = _ref3[_j];
|
1751
|
+
if (!param.splat) {
|
1752
|
+
continue;
|
1753
|
+
}
|
1754
|
+
_ref4 = this.params;
|
1755
|
+
for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) {
|
1756
|
+
p = _ref4[_k].name;
|
1757
|
+
if (p["this"]) {
|
1758
|
+
p = p.properties[0].name;
|
1759
|
+
}
|
1760
|
+
if (p.value) {
|
1761
|
+
o.scope.add(p.value, 'var', true);
|
1762
|
+
}
|
1763
|
+
}
|
1764
|
+
splats = new Assign(new Value(new Arr((function() {
|
1765
|
+
var _l, _len3, _ref5, _results;
|
1766
|
+
_ref5 = this.params;
|
1767
|
+
_results = [];
|
1768
|
+
for (_l = 0, _len3 = _ref5.length; _l < _len3; _l++) {
|
1769
|
+
p = _ref5[_l];
|
1770
|
+
_results.push(p.asReference(o));
|
1771
|
+
}
|
1772
|
+
return _results;
|
1773
|
+
}).call(this))), new Value(new Literal('arguments')));
|
1774
|
+
break;
|
1775
|
+
}
|
1776
|
+
_ref5 = this.params;
|
1777
|
+
for (_l = 0, _len3 = _ref5.length; _l < _len3; _l++) {
|
1778
|
+
param = _ref5[_l];
|
1779
|
+
if (param.isComplex()) {
|
1780
|
+
val = ref = param.asReference(o);
|
1781
|
+
if (param.value) {
|
1782
|
+
val = new Op('?', ref, param.value);
|
1783
|
+
}
|
1784
|
+
exprs.push(new Assign(new Value(param.name), val, '=', {
|
1785
|
+
param: true
|
1786
|
+
}));
|
1787
|
+
} else {
|
1788
|
+
ref = param;
|
1789
|
+
if (param.value) {
|
1790
|
+
lit = new Literal(ref.name.value + ' == null');
|
1791
|
+
val = new Assign(new Value(param.name), param.value, '=');
|
1792
|
+
exprs.push(new If(lit, val));
|
1793
|
+
}
|
1794
|
+
}
|
1795
|
+
if (!splats) {
|
1796
|
+
params.push(ref);
|
1797
|
+
}
|
1798
|
+
}
|
1799
|
+
wasEmpty = this.body.isEmpty();
|
1800
|
+
if (splats) {
|
1801
|
+
exprs.unshift(splats);
|
1802
|
+
}
|
1803
|
+
if (exprs.length) {
|
1804
|
+
(_ref6 = this.body.expressions).unshift.apply(_ref6, exprs);
|
1805
|
+
}
|
1806
|
+
for (i = _m = 0, _len4 = params.length; _m < _len4; i = ++_m) {
|
1807
|
+
p = params[i];
|
1808
|
+
o.scope.parameter(params[i] = p.compile(o));
|
1809
|
+
}
|
1810
|
+
uniqs = [];
|
1811
|
+
_ref7 = this.paramNames();
|
1812
|
+
for (_n = 0, _len5 = _ref7.length; _n < _len5; _n++) {
|
1813
|
+
name = _ref7[_n];
|
1814
|
+
if (__indexOf.call(uniqs, name) >= 0) {
|
1815
|
+
throw SyntaxError("multiple parameters named '" + name + "'");
|
1816
|
+
}
|
1817
|
+
uniqs.push(name);
|
1818
|
+
}
|
1819
|
+
if (!(wasEmpty || this.noReturn)) {
|
1820
|
+
this.body.makeReturn();
|
1821
|
+
}
|
1822
|
+
if (this.bound) {
|
1823
|
+
if ((_ref8 = o.scope.parent.method) != null ? _ref8.bound : void 0) {
|
1824
|
+
this.bound = this.context = o.scope.parent.method.context;
|
1825
|
+
} else if (!this["static"]) {
|
1826
|
+
o.scope.parent.assign('_this', 'this');
|
1827
|
+
}
|
1828
|
+
}
|
1829
|
+
idt = o.indent;
|
1830
|
+
code = 'function';
|
1831
|
+
if (this.ctor) {
|
1832
|
+
code += ' ' + this.name;
|
1833
|
+
}
|
1834
|
+
code += '(' + params.join(', ') + ') {';
|
1835
|
+
if (!this.body.isEmpty()) {
|
1836
|
+
code += "\n" + (this.body.compileWithDeclarations(o)) + "\n" + this.tab;
|
1837
|
+
}
|
1838
|
+
code += '}';
|
1839
|
+
if (this.ctor) {
|
1840
|
+
return this.tab + code;
|
1841
|
+
}
|
1842
|
+
if (this.front || (o.level >= LEVEL_ACCESS)) {
|
1843
|
+
return "(" + code + ")";
|
1844
|
+
} else {
|
1845
|
+
return code;
|
1846
|
+
}
|
1847
|
+
};
|
1848
|
+
|
1849
|
+
Code.prototype.paramNames = function() {
|
1850
|
+
var names, param, _i, _len, _ref2;
|
1851
|
+
names = [];
|
1852
|
+
_ref2 = this.params;
|
1853
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1854
|
+
param = _ref2[_i];
|
1855
|
+
names.push.apply(names, param.names());
|
1856
|
+
}
|
1857
|
+
return names;
|
1858
|
+
};
|
1859
|
+
|
1860
|
+
Code.prototype.traverseChildren = function(crossScope, func) {
|
1861
|
+
if (crossScope) {
|
1862
|
+
return Code.__super__.traverseChildren.call(this, crossScope, func);
|
1863
|
+
}
|
1864
|
+
};
|
1865
|
+
|
1866
|
+
return Code;
|
1867
|
+
|
1868
|
+
})(Base);
|
1869
|
+
|
1870
|
+
exports.Param = Param = (function(_super) {
|
1871
|
+
|
1872
|
+
__extends(Param, _super);
|
1873
|
+
|
1874
|
+
function Param(name, value, splat) {
|
1875
|
+
var _ref2;
|
1876
|
+
this.name = name;
|
1877
|
+
this.value = value;
|
1878
|
+
this.splat = splat;
|
1879
|
+
if (_ref2 = (name = this.name.unwrapAll().value), __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0) {
|
1880
|
+
throw SyntaxError("parameter name \"" + name + "\" is not allowed");
|
1881
|
+
}
|
1882
|
+
}
|
1883
|
+
|
1884
|
+
Param.prototype.children = ['name', 'value'];
|
1885
|
+
|
1886
|
+
Param.prototype.compile = function(o) {
|
1887
|
+
return this.name.compile(o, LEVEL_LIST);
|
1888
|
+
};
|
1889
|
+
|
1890
|
+
Param.prototype.asReference = function(o) {
|
1891
|
+
var node;
|
1892
|
+
if (this.reference) {
|
1893
|
+
return this.reference;
|
1894
|
+
}
|
1895
|
+
node = this.name;
|
1896
|
+
if (node["this"]) {
|
1897
|
+
node = node.properties[0].name;
|
1898
|
+
if (node.value.reserved) {
|
1899
|
+
node = new Literal(o.scope.freeVariable(node.value));
|
1900
|
+
}
|
1901
|
+
} else if (node.isComplex()) {
|
1902
|
+
node = new Literal(o.scope.freeVariable('arg'));
|
1903
|
+
}
|
1904
|
+
node = new Value(node);
|
1905
|
+
if (this.splat) {
|
1906
|
+
node = new Splat(node);
|
1907
|
+
}
|
1908
|
+
return this.reference = node;
|
1909
|
+
};
|
1910
|
+
|
1911
|
+
Param.prototype.isComplex = function() {
|
1912
|
+
return this.name.isComplex();
|
1913
|
+
};
|
1914
|
+
|
1915
|
+
Param.prototype.names = function(name) {
|
1916
|
+
var atParam, names, obj, _i, _len, _ref2;
|
1917
|
+
if (name == null) {
|
1918
|
+
name = this.name;
|
1919
|
+
}
|
1920
|
+
atParam = function(obj) {
|
1921
|
+
var value;
|
1922
|
+
value = obj.properties[0].name.value;
|
1923
|
+
if (value.reserved) {
|
1924
|
+
return [];
|
1925
|
+
} else {
|
1926
|
+
return [value];
|
1927
|
+
}
|
1928
|
+
};
|
1929
|
+
if (name instanceof Literal) {
|
1930
|
+
return [name.value];
|
1931
|
+
}
|
1932
|
+
if (name instanceof Value) {
|
1933
|
+
return atParam(name);
|
1934
|
+
}
|
1935
|
+
names = [];
|
1936
|
+
_ref2 = name.objects;
|
1937
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
1938
|
+
obj = _ref2[_i];
|
1939
|
+
if (obj instanceof Assign) {
|
1940
|
+
names.push(obj.value.unwrap().value);
|
1941
|
+
} else if (obj instanceof Splat) {
|
1942
|
+
names.push(obj.name.unwrap().value);
|
1943
|
+
} else if (obj instanceof Value) {
|
1944
|
+
if (obj.isArray() || obj.isObject()) {
|
1945
|
+
names.push.apply(names, this.names(obj.base));
|
1946
|
+
} else if (obj["this"]) {
|
1947
|
+
names.push.apply(names, atParam(obj));
|
1948
|
+
} else {
|
1949
|
+
names.push(obj.base.value);
|
1950
|
+
}
|
1951
|
+
} else {
|
1952
|
+
throw SyntaxError("illegal parameter " + (obj.compile()));
|
1953
|
+
}
|
1954
|
+
}
|
1955
|
+
return names;
|
1956
|
+
};
|
1957
|
+
|
1958
|
+
return Param;
|
1959
|
+
|
1960
|
+
})(Base);
|
1961
|
+
|
1962
|
+
exports.Splat = Splat = (function(_super) {
|
1963
|
+
|
1964
|
+
__extends(Splat, _super);
|
1965
|
+
|
1966
|
+
Splat.prototype.children = ['name'];
|
1967
|
+
|
1968
|
+
Splat.prototype.isAssignable = YES;
|
1969
|
+
|
1970
|
+
function Splat(name) {
|
1971
|
+
this.name = name.compile ? name : new Literal(name);
|
1972
|
+
}
|
1973
|
+
|
1974
|
+
Splat.prototype.assigns = function(name) {
|
1975
|
+
return this.name.assigns(name);
|
1976
|
+
};
|
1977
|
+
|
1978
|
+
Splat.prototype.compile = function(o) {
|
1979
|
+
if (this.index != null) {
|
1980
|
+
return this.compileParam(o);
|
1981
|
+
} else {
|
1982
|
+
return this.name.compile(o);
|
1983
|
+
}
|
1984
|
+
};
|
1985
|
+
|
1986
|
+
Splat.prototype.unwrap = function() {
|
1987
|
+
return this.name;
|
1988
|
+
};
|
1989
|
+
|
1990
|
+
Splat.compileSplattedArray = function(o, list, apply) {
|
1991
|
+
var args, base, code, i, index, node, _i, _len;
|
1992
|
+
index = -1;
|
1993
|
+
while ((node = list[++index]) && !(node instanceof Splat)) {
|
1994
|
+
continue;
|
1995
|
+
}
|
1996
|
+
if (index >= list.length) {
|
1997
|
+
return '';
|
1998
|
+
}
|
1999
|
+
if (list.length === 1) {
|
2000
|
+
code = list[0].compile(o, LEVEL_LIST);
|
2001
|
+
if (apply) {
|
2002
|
+
return code;
|
2003
|
+
}
|
2004
|
+
return "" + (utility('slice')) + ".call(" + code + ")";
|
2005
|
+
}
|
2006
|
+
args = list.slice(index);
|
2007
|
+
for (i = _i = 0, _len = args.length; _i < _len; i = ++_i) {
|
2008
|
+
node = args[i];
|
2009
|
+
code = node.compile(o, LEVEL_LIST);
|
2010
|
+
args[i] = node instanceof Splat ? "" + (utility('slice')) + ".call(" + code + ")" : "[" + code + "]";
|
2011
|
+
}
|
2012
|
+
if (index === 0) {
|
2013
|
+
return args[0] + (".concat(" + (args.slice(1).join(', ')) + ")");
|
2014
|
+
}
|
2015
|
+
base = (function() {
|
2016
|
+
var _j, _len1, _ref2, _results;
|
2017
|
+
_ref2 = list.slice(0, index);
|
2018
|
+
_results = [];
|
2019
|
+
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
2020
|
+
node = _ref2[_j];
|
2021
|
+
_results.push(node.compile(o, LEVEL_LIST));
|
2022
|
+
}
|
2023
|
+
return _results;
|
2024
|
+
})();
|
2025
|
+
return "[" + (base.join(', ')) + "].concat(" + (args.join(', ')) + ")";
|
2026
|
+
};
|
2027
|
+
|
2028
|
+
return Splat;
|
2029
|
+
|
2030
|
+
})(Base);
|
2031
|
+
|
2032
|
+
exports.While = While = (function(_super) {
|
2033
|
+
|
2034
|
+
__extends(While, _super);
|
2035
|
+
|
2036
|
+
function While(condition, options) {
|
2037
|
+
this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition;
|
2038
|
+
this.guard = options != null ? options.guard : void 0;
|
2039
|
+
}
|
2040
|
+
|
2041
|
+
While.prototype.children = ['condition', 'guard', 'body'];
|
2042
|
+
|
2043
|
+
While.prototype.isStatement = YES;
|
2044
|
+
|
2045
|
+
While.prototype.makeReturn = function(res) {
|
2046
|
+
if (res) {
|
2047
|
+
return While.__super__.makeReturn.apply(this, arguments);
|
2048
|
+
} else {
|
2049
|
+
this.returns = !this.jumps({
|
2050
|
+
loop: true
|
2051
|
+
});
|
2052
|
+
return this;
|
2053
|
+
}
|
2054
|
+
};
|
2055
|
+
|
2056
|
+
While.prototype.addBody = function(body) {
|
2057
|
+
this.body = body;
|
2058
|
+
return this;
|
2059
|
+
};
|
2060
|
+
|
2061
|
+
While.prototype.jumps = function() {
|
2062
|
+
var expressions, node, _i, _len;
|
2063
|
+
expressions = this.body.expressions;
|
2064
|
+
if (!expressions.length) {
|
2065
|
+
return false;
|
2066
|
+
}
|
2067
|
+
for (_i = 0, _len = expressions.length; _i < _len; _i++) {
|
2068
|
+
node = expressions[_i];
|
2069
|
+
if (node.jumps({
|
2070
|
+
loop: true
|
2071
|
+
})) {
|
2072
|
+
return node;
|
2073
|
+
}
|
2074
|
+
}
|
2075
|
+
return false;
|
2076
|
+
};
|
2077
|
+
|
2078
|
+
While.prototype.compileNode = function(o) {
|
2079
|
+
var body, code, rvar, set;
|
2080
|
+
o.indent += TAB;
|
2081
|
+
set = '';
|
2082
|
+
body = this.body;
|
2083
|
+
if (body.isEmpty()) {
|
2084
|
+
body = '';
|
2085
|
+
} else {
|
2086
|
+
if (this.returns) {
|
2087
|
+
body.makeReturn(rvar = o.scope.freeVariable('results'));
|
2088
|
+
set = "" + this.tab + rvar + " = [];\n";
|
2089
|
+
}
|
2090
|
+
if (this.guard) {
|
2091
|
+
if (body.expressions.length > 1) {
|
2092
|
+
body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));
|
2093
|
+
} else {
|
2094
|
+
if (this.guard) {
|
2095
|
+
body = Block.wrap([new If(this.guard, body)]);
|
2096
|
+
}
|
2097
|
+
}
|
2098
|
+
}
|
2099
|
+
body = "\n" + (body.compile(o, LEVEL_TOP)) + "\n" + this.tab;
|
2100
|
+
}
|
2101
|
+
code = set + this.tab + ("while (" + (this.condition.compile(o, LEVEL_PAREN)) + ") {" + body + "}");
|
2102
|
+
if (this.returns) {
|
2103
|
+
code += "\n" + this.tab + "return " + rvar + ";";
|
2104
|
+
}
|
2105
|
+
return code;
|
2106
|
+
};
|
2107
|
+
|
2108
|
+
return While;
|
2109
|
+
|
2110
|
+
})(Base);
|
2111
|
+
|
2112
|
+
exports.Op = Op = (function(_super) {
|
2113
|
+
var CONVERSIONS, INVERSIONS;
|
2114
|
+
|
2115
|
+
__extends(Op, _super);
|
2116
|
+
|
2117
|
+
function Op(op, first, second, flip) {
|
2118
|
+
if (op === 'in') {
|
2119
|
+
return new In(first, second);
|
2120
|
+
}
|
2121
|
+
if (op === 'do') {
|
2122
|
+
return this.generateDo(first);
|
2123
|
+
}
|
2124
|
+
if (op === 'new') {
|
2125
|
+
if (first instanceof Call && !first["do"] && !first.isNew) {
|
2126
|
+
return first.newInstance();
|
2127
|
+
}
|
2128
|
+
if (first instanceof Code && first.bound || first["do"]) {
|
2129
|
+
first = new Parens(first);
|
2130
|
+
}
|
2131
|
+
}
|
2132
|
+
this.operator = CONVERSIONS[op] || op;
|
2133
|
+
this.first = first;
|
2134
|
+
this.second = second;
|
2135
|
+
this.flip = !!flip;
|
2136
|
+
return this;
|
2137
|
+
}
|
2138
|
+
|
2139
|
+
CONVERSIONS = {
|
2140
|
+
'==': '===',
|
2141
|
+
'!=': '!==',
|
2142
|
+
'of': 'in'
|
2143
|
+
};
|
2144
|
+
|
2145
|
+
INVERSIONS = {
|
2146
|
+
'!==': '===',
|
2147
|
+
'===': '!=='
|
2148
|
+
};
|
2149
|
+
|
2150
|
+
Op.prototype.children = ['first', 'second'];
|
2151
|
+
|
2152
|
+
Op.prototype.isSimpleNumber = NO;
|
2153
|
+
|
2154
|
+
Op.prototype.isUnary = function() {
|
2155
|
+
return !this.second;
|
2156
|
+
};
|
2157
|
+
|
2158
|
+
Op.prototype.isComplex = function() {
|
2159
|
+
var _ref2;
|
2160
|
+
return !(this.isUnary() && ((_ref2 = this.operator) === '+' || _ref2 === '-')) || this.first.isComplex();
|
2161
|
+
};
|
2162
|
+
|
2163
|
+
Op.prototype.isChainable = function() {
|
2164
|
+
var _ref2;
|
2165
|
+
return (_ref2 = this.operator) === '<' || _ref2 === '>' || _ref2 === '>=' || _ref2 === '<=' || _ref2 === '===' || _ref2 === '!==';
|
2166
|
+
};
|
2167
|
+
|
2168
|
+
Op.prototype.invert = function() {
|
2169
|
+
var allInvertable, curr, fst, op, _ref2;
|
2170
|
+
if (this.isChainable() && this.first.isChainable()) {
|
2171
|
+
allInvertable = true;
|
2172
|
+
curr = this;
|
2173
|
+
while (curr && curr.operator) {
|
2174
|
+
allInvertable && (allInvertable = curr.operator in INVERSIONS);
|
2175
|
+
curr = curr.first;
|
2176
|
+
}
|
2177
|
+
if (!allInvertable) {
|
2178
|
+
return new Parens(this).invert();
|
2179
|
+
}
|
2180
|
+
curr = this;
|
2181
|
+
while (curr && curr.operator) {
|
2182
|
+
curr.invert = !curr.invert;
|
2183
|
+
curr.operator = INVERSIONS[curr.operator];
|
2184
|
+
curr = curr.first;
|
2185
|
+
}
|
2186
|
+
return this;
|
2187
|
+
} else if (op = INVERSIONS[this.operator]) {
|
2188
|
+
this.operator = op;
|
2189
|
+
if (this.first.unwrap() instanceof Op) {
|
2190
|
+
this.first.invert();
|
2191
|
+
}
|
2192
|
+
return this;
|
2193
|
+
} else if (this.second) {
|
2194
|
+
return new Parens(this).invert();
|
2195
|
+
} else if (this.operator === '!' && (fst = this.first.unwrap()) instanceof Op && ((_ref2 = fst.operator) === '!' || _ref2 === 'in' || _ref2 === 'instanceof')) {
|
2196
|
+
return fst;
|
2197
|
+
} else {
|
2198
|
+
return new Op('!', this);
|
2199
|
+
}
|
2200
|
+
};
|
2201
|
+
|
2202
|
+
Op.prototype.unfoldSoak = function(o) {
|
2203
|
+
var _ref2;
|
2204
|
+
return ((_ref2 = this.operator) === '++' || _ref2 === '--' || _ref2 === 'delete') && unfoldSoak(o, this, 'first');
|
2205
|
+
};
|
2206
|
+
|
2207
|
+
Op.prototype.generateDo = function(exp) {
|
2208
|
+
var call, func, param, passedParams, ref, _i, _len, _ref2;
|
2209
|
+
passedParams = [];
|
2210
|
+
func = exp instanceof Assign && (ref = exp.value.unwrap()) instanceof Code ? ref : exp;
|
2211
|
+
_ref2 = func.params || [];
|
2212
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
2213
|
+
param = _ref2[_i];
|
2214
|
+
if (param.value) {
|
2215
|
+
passedParams.push(param.value);
|
2216
|
+
delete param.value;
|
2217
|
+
} else {
|
2218
|
+
passedParams.push(param);
|
2219
|
+
}
|
2220
|
+
}
|
2221
|
+
call = new Call(exp, passedParams);
|
2222
|
+
call["do"] = true;
|
2223
|
+
return call;
|
2224
|
+
};
|
2225
|
+
|
2226
|
+
Op.prototype.compileNode = function(o) {
|
2227
|
+
var code, isChain, _ref2, _ref3;
|
2228
|
+
isChain = this.isChainable() && this.first.isChainable();
|
2229
|
+
if (!isChain) {
|
2230
|
+
this.first.front = this.front;
|
2231
|
+
}
|
2232
|
+
if (this.operator === 'delete' && o.scope.check(this.first.unwrapAll().value)) {
|
2233
|
+
throw SyntaxError('delete operand may not be argument or var');
|
2234
|
+
}
|
2235
|
+
if (((_ref2 = this.operator) === '--' || _ref2 === '++') && (_ref3 = this.first.unwrapAll().value, __indexOf.call(STRICT_PROSCRIBED, _ref3) >= 0)) {
|
2236
|
+
throw SyntaxError('prefix increment/decrement may not have eval or arguments operand');
|
2237
|
+
}
|
2238
|
+
if (this.isUnary()) {
|
2239
|
+
return this.compileUnary(o);
|
2240
|
+
}
|
2241
|
+
if (isChain) {
|
2242
|
+
return this.compileChain(o);
|
2243
|
+
}
|
2244
|
+
if (this.operator === '?') {
|
2245
|
+
return this.compileExistence(o);
|
2246
|
+
}
|
2247
|
+
code = this.first.compile(o, LEVEL_OP) + ' ' + this.operator + ' ' + this.second.compile(o, LEVEL_OP);
|
2248
|
+
if (o.level <= LEVEL_OP) {
|
2249
|
+
return code;
|
2250
|
+
} else {
|
2251
|
+
return "(" + code + ")";
|
2252
|
+
}
|
2253
|
+
};
|
2254
|
+
|
2255
|
+
Op.prototype.compileChain = function(o) {
|
2256
|
+
var code, fst, shared, _ref2;
|
2257
|
+
_ref2 = this.first.second.cache(o), this.first.second = _ref2[0], shared = _ref2[1];
|
2258
|
+
fst = this.first.compile(o, LEVEL_OP);
|
2259
|
+
code = "" + fst + " " + (this.invert ? '&&' : '||') + " " + (shared.compile(o)) + " " + this.operator + " " + (this.second.compile(o, LEVEL_OP));
|
2260
|
+
return "(" + code + ")";
|
2261
|
+
};
|
2262
|
+
|
2263
|
+
Op.prototype.compileExistence = function(o) {
|
2264
|
+
var fst, ref;
|
2265
|
+
if (this.first.isComplex()) {
|
2266
|
+
ref = new Literal(o.scope.freeVariable('ref'));
|
2267
|
+
fst = new Parens(new Assign(ref, this.first));
|
2268
|
+
} else {
|
2269
|
+
fst = this.first;
|
2270
|
+
ref = fst;
|
2271
|
+
}
|
2272
|
+
return new If(new Existence(fst), ref, {
|
2273
|
+
type: 'if'
|
2274
|
+
}).addElse(this.second).compile(o);
|
2275
|
+
};
|
2276
|
+
|
2277
|
+
Op.prototype.compileUnary = function(o) {
|
2278
|
+
var op, parts, plusMinus;
|
2279
|
+
if (o.level >= LEVEL_ACCESS) {
|
2280
|
+
return (new Parens(this)).compile(o);
|
2281
|
+
}
|
2282
|
+
parts = [op = this.operator];
|
2283
|
+
plusMinus = op === '+' || op === '-';
|
2284
|
+
if ((op === 'new' || op === 'typeof' || op === 'delete') || plusMinus && this.first instanceof Op && this.first.operator === op) {
|
2285
|
+
parts.push(' ');
|
2286
|
+
}
|
2287
|
+
if ((plusMinus && this.first instanceof Op) || (op === 'new' && this.first.isStatement(o))) {
|
2288
|
+
this.first = new Parens(this.first);
|
2289
|
+
}
|
2290
|
+
parts.push(this.first.compile(o, LEVEL_OP));
|
2291
|
+
if (this.flip) {
|
2292
|
+
parts.reverse();
|
2293
|
+
}
|
2294
|
+
return parts.join('');
|
2295
|
+
};
|
2296
|
+
|
2297
|
+
Op.prototype.toString = function(idt) {
|
2298
|
+
return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
|
2299
|
+
};
|
2300
|
+
|
2301
|
+
return Op;
|
2302
|
+
|
2303
|
+
})(Base);
|
2304
|
+
|
2305
|
+
exports.In = In = (function(_super) {
|
2306
|
+
|
2307
|
+
__extends(In, _super);
|
2308
|
+
|
2309
|
+
function In(object, array) {
|
2310
|
+
this.object = object;
|
2311
|
+
this.array = array;
|
2312
|
+
}
|
2313
|
+
|
2314
|
+
In.prototype.children = ['object', 'array'];
|
2315
|
+
|
2316
|
+
In.prototype.invert = NEGATE;
|
2317
|
+
|
2318
|
+
In.prototype.compileNode = function(o) {
|
2319
|
+
var hasSplat, obj, _i, _len, _ref2;
|
2320
|
+
if (this.array instanceof Value && this.array.isArray()) {
|
2321
|
+
_ref2 = this.array.base.objects;
|
2322
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
2323
|
+
obj = _ref2[_i];
|
2324
|
+
if (!(obj instanceof Splat)) {
|
2325
|
+
continue;
|
2326
|
+
}
|
2327
|
+
hasSplat = true;
|
2328
|
+
break;
|
2329
|
+
}
|
2330
|
+
if (!hasSplat) {
|
2331
|
+
return this.compileOrTest(o);
|
2332
|
+
}
|
2333
|
+
}
|
2334
|
+
return this.compileLoopTest(o);
|
2335
|
+
};
|
2336
|
+
|
2337
|
+
In.prototype.compileOrTest = function(o) {
|
2338
|
+
var cmp, cnj, i, item, ref, sub, tests, _ref2, _ref3;
|
2339
|
+
if (this.array.base.objects.length === 0) {
|
2340
|
+
return "" + (!!this.negated);
|
2341
|
+
}
|
2342
|
+
_ref2 = this.object.cache(o, LEVEL_OP), sub = _ref2[0], ref = _ref2[1];
|
2343
|
+
_ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1];
|
2344
|
+
tests = (function() {
|
2345
|
+
var _i, _len, _ref4, _results;
|
2346
|
+
_ref4 = this.array.base.objects;
|
2347
|
+
_results = [];
|
2348
|
+
for (i = _i = 0, _len = _ref4.length; _i < _len; i = ++_i) {
|
2349
|
+
item = _ref4[i];
|
2350
|
+
_results.push((i ? ref : sub) + cmp + item.compile(o, LEVEL_ACCESS));
|
2351
|
+
}
|
2352
|
+
return _results;
|
2353
|
+
}).call(this);
|
2354
|
+
tests = tests.join(cnj);
|
2355
|
+
if (o.level < LEVEL_OP) {
|
2356
|
+
return tests;
|
2357
|
+
} else {
|
2358
|
+
return "(" + tests + ")";
|
2359
|
+
}
|
2360
|
+
};
|
2361
|
+
|
2362
|
+
In.prototype.compileLoopTest = function(o) {
|
2363
|
+
var code, ref, sub, _ref2;
|
2364
|
+
_ref2 = this.object.cache(o, LEVEL_LIST), sub = _ref2[0], ref = _ref2[1];
|
2365
|
+
code = utility('indexOf') + (".call(" + (this.array.compile(o, LEVEL_LIST)) + ", " + ref + ") ") + (this.negated ? '< 0' : '>= 0');
|
2366
|
+
if (sub === ref) {
|
2367
|
+
return code;
|
2368
|
+
}
|
2369
|
+
code = sub + ', ' + code;
|
2370
|
+
if (o.level < LEVEL_LIST) {
|
2371
|
+
return code;
|
2372
|
+
} else {
|
2373
|
+
return "(" + code + ")";
|
2374
|
+
}
|
2375
|
+
};
|
2376
|
+
|
2377
|
+
In.prototype.toString = function(idt) {
|
2378
|
+
return In.__super__.toString.call(this, idt, this.constructor.name + (this.negated ? '!' : ''));
|
2379
|
+
};
|
2380
|
+
|
2381
|
+
return In;
|
2382
|
+
|
2383
|
+
})(Base);
|
2384
|
+
|
2385
|
+
exports.Try = Try = (function(_super) {
|
2386
|
+
|
2387
|
+
__extends(Try, _super);
|
2388
|
+
|
2389
|
+
function Try(attempt, error, recovery, ensure) {
|
2390
|
+
this.attempt = attempt;
|
2391
|
+
this.error = error;
|
2392
|
+
this.recovery = recovery;
|
2393
|
+
this.ensure = ensure;
|
2394
|
+
}
|
2395
|
+
|
2396
|
+
Try.prototype.children = ['attempt', 'recovery', 'ensure'];
|
2397
|
+
|
2398
|
+
Try.prototype.isStatement = YES;
|
2399
|
+
|
2400
|
+
Try.prototype.jumps = function(o) {
|
2401
|
+
var _ref2;
|
2402
|
+
return this.attempt.jumps(o) || ((_ref2 = this.recovery) != null ? _ref2.jumps(o) : void 0);
|
2403
|
+
};
|
2404
|
+
|
2405
|
+
Try.prototype.makeReturn = function(res) {
|
2406
|
+
if (this.attempt) {
|
2407
|
+
this.attempt = this.attempt.makeReturn(res);
|
2408
|
+
}
|
2409
|
+
if (this.recovery) {
|
2410
|
+
this.recovery = this.recovery.makeReturn(res);
|
2411
|
+
}
|
2412
|
+
return this;
|
2413
|
+
};
|
2414
|
+
|
2415
|
+
Try.prototype.compileNode = function(o) {
|
2416
|
+
var catchPart, ensurePart, errorPart, tryPart;
|
2417
|
+
o.indent += TAB;
|
2418
|
+
errorPart = this.error ? " (" + (this.error.compile(o)) + ") " : ' ';
|
2419
|
+
tryPart = this.attempt.compile(o, LEVEL_TOP);
|
2420
|
+
catchPart = (function() {
|
2421
|
+
var _ref2;
|
2422
|
+
if (this.recovery) {
|
2423
|
+
if (_ref2 = this.error.value, __indexOf.call(STRICT_PROSCRIBED, _ref2) >= 0) {
|
2424
|
+
throw SyntaxError("catch variable may not be \"" + this.error.value + "\"");
|
2425
|
+
}
|
2426
|
+
if (!o.scope.check(this.error.value)) {
|
2427
|
+
o.scope.add(this.error.value, 'param');
|
2428
|
+
}
|
2429
|
+
return " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}";
|
2430
|
+
} else if (!(this.ensure || this.recovery)) {
|
2431
|
+
return ' catch (_error) {}';
|
2432
|
+
}
|
2433
|
+
}).call(this);
|
2434
|
+
ensurePart = this.ensure ? " finally {\n" + (this.ensure.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : '';
|
2435
|
+
return "" + this.tab + "try {\n" + tryPart + "\n" + this.tab + "}" + (catchPart || '') + ensurePart;
|
2436
|
+
};
|
2437
|
+
|
2438
|
+
return Try;
|
2439
|
+
|
2440
|
+
})(Base);
|
2441
|
+
|
2442
|
+
exports.Throw = Throw = (function(_super) {
|
2443
|
+
|
2444
|
+
__extends(Throw, _super);
|
2445
|
+
|
2446
|
+
function Throw(expression) {
|
2447
|
+
this.expression = expression;
|
2448
|
+
}
|
2449
|
+
|
2450
|
+
Throw.prototype.children = ['expression'];
|
2451
|
+
|
2452
|
+
Throw.prototype.isStatement = YES;
|
2453
|
+
|
2454
|
+
Throw.prototype.jumps = NO;
|
2455
|
+
|
2456
|
+
Throw.prototype.makeReturn = THIS;
|
2457
|
+
|
2458
|
+
Throw.prototype.compileNode = function(o) {
|
2459
|
+
return this.tab + ("throw " + (this.expression.compile(o)) + ";");
|
2460
|
+
};
|
2461
|
+
|
2462
|
+
return Throw;
|
2463
|
+
|
2464
|
+
})(Base);
|
2465
|
+
|
2466
|
+
exports.Existence = Existence = (function(_super) {
|
2467
|
+
|
2468
|
+
__extends(Existence, _super);
|
2469
|
+
|
2470
|
+
function Existence(expression) {
|
2471
|
+
this.expression = expression;
|
2472
|
+
}
|
2473
|
+
|
2474
|
+
Existence.prototype.children = ['expression'];
|
2475
|
+
|
2476
|
+
Existence.prototype.invert = NEGATE;
|
2477
|
+
|
2478
|
+
Existence.prototype.compileNode = function(o) {
|
2479
|
+
var cmp, cnj, code, _ref2;
|
2480
|
+
this.expression.front = this.front;
|
2481
|
+
code = this.expression.compile(o, LEVEL_OP);
|
2482
|
+
if (IDENTIFIER.test(code) && !o.scope.check(code)) {
|
2483
|
+
_ref2 = this.negated ? ['===', '||'] : ['!==', '&&'], cmp = _ref2[0], cnj = _ref2[1];
|
2484
|
+
code = "typeof " + code + " " + cmp + " \"undefined\" " + cnj + " " + code + " " + cmp + " null";
|
2485
|
+
} else {
|
2486
|
+
code = "" + code + " " + (this.negated ? '==' : '!=') + " null";
|
2487
|
+
}
|
2488
|
+
if (o.level <= LEVEL_COND) {
|
2489
|
+
return code;
|
2490
|
+
} else {
|
2491
|
+
return "(" + code + ")";
|
2492
|
+
}
|
2493
|
+
};
|
2494
|
+
|
2495
|
+
return Existence;
|
2496
|
+
|
2497
|
+
})(Base);
|
2498
|
+
|
2499
|
+
exports.Parens = Parens = (function(_super) {
|
2500
|
+
|
2501
|
+
__extends(Parens, _super);
|
2502
|
+
|
2503
|
+
function Parens(body) {
|
2504
|
+
this.body = body;
|
2505
|
+
}
|
2506
|
+
|
2507
|
+
Parens.prototype.children = ['body'];
|
2508
|
+
|
2509
|
+
Parens.prototype.unwrap = function() {
|
2510
|
+
return this.body;
|
2511
|
+
};
|
2512
|
+
|
2513
|
+
Parens.prototype.isComplex = function() {
|
2514
|
+
return this.body.isComplex();
|
2515
|
+
};
|
2516
|
+
|
2517
|
+
Parens.prototype.compileNode = function(o) {
|
2518
|
+
var bare, code, expr;
|
2519
|
+
expr = this.body.unwrap();
|
2520
|
+
if (expr instanceof Value && expr.isAtomic()) {
|
2521
|
+
expr.front = this.front;
|
2522
|
+
return expr.compile(o);
|
2523
|
+
}
|
2524
|
+
code = expr.compile(o, LEVEL_PAREN);
|
2525
|
+
bare = o.level < LEVEL_OP && (expr instanceof Op || expr instanceof Call || (expr instanceof For && expr.returns));
|
2526
|
+
if (bare) {
|
2527
|
+
return code;
|
2528
|
+
} else {
|
2529
|
+
return "(" + code + ")";
|
2530
|
+
}
|
2531
|
+
};
|
2532
|
+
|
2533
|
+
return Parens;
|
2534
|
+
|
2535
|
+
})(Base);
|
2536
|
+
|
2537
|
+
exports.For = For = (function(_super) {
|
2538
|
+
|
2539
|
+
__extends(For, _super);
|
2540
|
+
|
2541
|
+
function For(body, source) {
|
2542
|
+
var _ref2;
|
2543
|
+
this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;
|
2544
|
+
this.body = Block.wrap([body]);
|
2545
|
+
this.own = !!source.own;
|
2546
|
+
this.object = !!source.object;
|
2547
|
+
if (this.object) {
|
2548
|
+
_ref2 = [this.index, this.name], this.name = _ref2[0], this.index = _ref2[1];
|
2549
|
+
}
|
2550
|
+
if (this.index instanceof Value) {
|
2551
|
+
throw SyntaxError('index cannot be a pattern matching expression');
|
2552
|
+
}
|
2553
|
+
this.range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
|
2554
|
+
this.pattern = this.name instanceof Value;
|
2555
|
+
if (this.range && this.index) {
|
2556
|
+
throw SyntaxError('indexes do not apply to range loops');
|
2557
|
+
}
|
2558
|
+
if (this.range && this.pattern) {
|
2559
|
+
throw SyntaxError('cannot pattern match over range loops');
|
2560
|
+
}
|
2561
|
+
this.returns = false;
|
2562
|
+
}
|
2563
|
+
|
2564
|
+
For.prototype.children = ['body', 'source', 'guard', 'step'];
|
2565
|
+
|
2566
|
+
For.prototype.compileNode = function(o) {
|
2567
|
+
var body, defPart, forPart, forVarPart, guardPart, idt1, index, ivar, kvar, kvarAssign, lastJumps, lvar, name, namePart, ref, resultPart, returnResult, rvar, scope, source, stepPart, stepvar, svar, varPart, _ref2;
|
2568
|
+
body = Block.wrap([this.body]);
|
2569
|
+
lastJumps = (_ref2 = last(body.expressions)) != null ? _ref2.jumps() : void 0;
|
2570
|
+
if (lastJumps && lastJumps instanceof Return) {
|
2571
|
+
this.returns = false;
|
2572
|
+
}
|
2573
|
+
source = this.range ? this.source.base : this.source;
|
2574
|
+
scope = o.scope;
|
2575
|
+
name = this.name && this.name.compile(o, LEVEL_LIST);
|
2576
|
+
index = this.index && this.index.compile(o, LEVEL_LIST);
|
2577
|
+
if (name && !this.pattern) {
|
2578
|
+
scope.find(name);
|
2579
|
+
}
|
2580
|
+
if (index) {
|
2581
|
+
scope.find(index);
|
2582
|
+
}
|
2583
|
+
if (this.returns) {
|
2584
|
+
rvar = scope.freeVariable('results');
|
2585
|
+
}
|
2586
|
+
ivar = (this.object && index) || scope.freeVariable('i');
|
2587
|
+
kvar = (this.range && name) || index || ivar;
|
2588
|
+
kvarAssign = kvar !== ivar ? "" + kvar + " = " : "";
|
2589
|
+
if (this.step && !this.range) {
|
2590
|
+
stepvar = scope.freeVariable("step");
|
2591
|
+
}
|
2592
|
+
if (this.pattern) {
|
2593
|
+
name = ivar;
|
2594
|
+
}
|
2595
|
+
varPart = '';
|
2596
|
+
guardPart = '';
|
2597
|
+
defPart = '';
|
2598
|
+
idt1 = this.tab + TAB;
|
2599
|
+
if (this.range) {
|
2600
|
+
forPart = source.compile(merge(o, {
|
2601
|
+
index: ivar,
|
2602
|
+
name: name,
|
2603
|
+
step: this.step
|
2604
|
+
}));
|
2605
|
+
} else {
|
2606
|
+
svar = this.source.compile(o, LEVEL_LIST);
|
2607
|
+
if ((name || this.own) && !IDENTIFIER.test(svar)) {
|
2608
|
+
defPart = "" + this.tab + (ref = scope.freeVariable('ref')) + " = " + svar + ";\n";
|
2609
|
+
svar = ref;
|
2610
|
+
}
|
2611
|
+
if (name && !this.pattern) {
|
2612
|
+
namePart = "" + name + " = " + svar + "[" + kvar + "]";
|
2613
|
+
}
|
2614
|
+
if (!this.object) {
|
2615
|
+
lvar = scope.freeVariable('len');
|
2616
|
+
forVarPart = "" + kvarAssign + ivar + " = 0, " + lvar + " = " + svar + ".length";
|
2617
|
+
if (this.step) {
|
2618
|
+
forVarPart += ", " + stepvar + " = " + (this.step.compile(o, LEVEL_OP));
|
2619
|
+
}
|
2620
|
+
stepPart = "" + kvarAssign + (this.step ? "" + ivar + " += " + stepvar : (kvar !== ivar ? "++" + ivar : "" + ivar + "++"));
|
2621
|
+
forPart = "" + forVarPart + "; " + ivar + " < " + lvar + "; " + stepPart;
|
2622
|
+
}
|
2623
|
+
}
|
2624
|
+
if (this.returns) {
|
2625
|
+
resultPart = "" + this.tab + rvar + " = [];\n";
|
2626
|
+
returnResult = "\n" + this.tab + "return " + rvar + ";";
|
2627
|
+
body.makeReturn(rvar);
|
2628
|
+
}
|
2629
|
+
if (this.guard) {
|
2630
|
+
if (body.expressions.length > 1) {
|
2631
|
+
body.expressions.unshift(new If((new Parens(this.guard)).invert(), new Literal("continue")));
|
2632
|
+
} else {
|
2633
|
+
if (this.guard) {
|
2634
|
+
body = Block.wrap([new If(this.guard, body)]);
|
2635
|
+
}
|
2636
|
+
}
|
2637
|
+
}
|
2638
|
+
if (this.pattern) {
|
2639
|
+
body.expressions.unshift(new Assign(this.name, new Literal("" + svar + "[" + kvar + "]")));
|
2640
|
+
}
|
2641
|
+
defPart += this.pluckDirectCall(o, body);
|
2642
|
+
if (namePart) {
|
2643
|
+
varPart = "\n" + idt1 + namePart + ";";
|
2644
|
+
}
|
2645
|
+
if (this.object) {
|
2646
|
+
forPart = "" + kvar + " in " + svar;
|
2647
|
+
if (this.own) {
|
2648
|
+
guardPart = "\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + kvar + ")) continue;";
|
2649
|
+
}
|
2650
|
+
}
|
2651
|
+
body = body.compile(merge(o, {
|
2652
|
+
indent: idt1
|
2653
|
+
}), LEVEL_TOP);
|
2654
|
+
if (body) {
|
2655
|
+
body = '\n' + body + '\n';
|
2656
|
+
}
|
2657
|
+
return "" + defPart + (resultPart || '') + this.tab + "for (" + forPart + ") {" + guardPart + varPart + body + this.tab + "}" + (returnResult || '');
|
2658
|
+
};
|
2659
|
+
|
2660
|
+
For.prototype.pluckDirectCall = function(o, body) {
|
2661
|
+
var base, defs, expr, fn, idx, ref, val, _i, _len, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7;
|
2662
|
+
defs = '';
|
2663
|
+
_ref2 = body.expressions;
|
2664
|
+
for (idx = _i = 0, _len = _ref2.length; _i < _len; idx = ++_i) {
|
2665
|
+
expr = _ref2[idx];
|
2666
|
+
expr = expr.unwrapAll();
|
2667
|
+
if (!(expr instanceof Call)) {
|
2668
|
+
continue;
|
2669
|
+
}
|
2670
|
+
val = expr.variable.unwrapAll();
|
2671
|
+
if (!((val instanceof Code) || (val instanceof Value && ((_ref3 = val.base) != null ? _ref3.unwrapAll() : void 0) instanceof Code && val.properties.length === 1 && ((_ref4 = (_ref5 = val.properties[0].name) != null ? _ref5.value : void 0) === 'call' || _ref4 === 'apply')))) {
|
2672
|
+
continue;
|
2673
|
+
}
|
2674
|
+
fn = ((_ref6 = val.base) != null ? _ref6.unwrapAll() : void 0) || val;
|
2675
|
+
ref = new Literal(o.scope.freeVariable('fn'));
|
2676
|
+
base = new Value(ref);
|
2677
|
+
if (val.base) {
|
2678
|
+
_ref7 = [base, val], val.base = _ref7[0], base = _ref7[1];
|
2679
|
+
}
|
2680
|
+
body.expressions[idx] = new Call(base, expr.args);
|
2681
|
+
defs += this.tab + new Assign(ref, fn).compile(o, LEVEL_TOP) + ';\n';
|
2682
|
+
}
|
2683
|
+
return defs;
|
2684
|
+
};
|
2685
|
+
|
2686
|
+
return For;
|
2687
|
+
|
2688
|
+
})(While);
|
2689
|
+
|
2690
|
+
exports.Switch = Switch = (function(_super) {
|
2691
|
+
|
2692
|
+
__extends(Switch, _super);
|
2693
|
+
|
2694
|
+
function Switch(subject, cases, otherwise) {
|
2695
|
+
this.subject = subject;
|
2696
|
+
this.cases = cases;
|
2697
|
+
this.otherwise = otherwise;
|
2698
|
+
}
|
2699
|
+
|
2700
|
+
Switch.prototype.children = ['subject', 'cases', 'otherwise'];
|
2701
|
+
|
2702
|
+
Switch.prototype.isStatement = YES;
|
2703
|
+
|
2704
|
+
Switch.prototype.jumps = function(o) {
|
2705
|
+
var block, conds, _i, _len, _ref2, _ref3, _ref4;
|
2706
|
+
if (o == null) {
|
2707
|
+
o = {
|
2708
|
+
block: true
|
2709
|
+
};
|
2710
|
+
}
|
2711
|
+
_ref2 = this.cases;
|
2712
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
2713
|
+
_ref3 = _ref2[_i], conds = _ref3[0], block = _ref3[1];
|
2714
|
+
if (block.jumps(o)) {
|
2715
|
+
return block;
|
2716
|
+
}
|
2717
|
+
}
|
2718
|
+
return (_ref4 = this.otherwise) != null ? _ref4.jumps(o) : void 0;
|
2719
|
+
};
|
2720
|
+
|
2721
|
+
Switch.prototype.makeReturn = function(res) {
|
2722
|
+
var pair, _i, _len, _ref2, _ref3;
|
2723
|
+
_ref2 = this.cases;
|
2724
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
2725
|
+
pair = _ref2[_i];
|
2726
|
+
pair[1].makeReturn(res);
|
2727
|
+
}
|
2728
|
+
if (res) {
|
2729
|
+
this.otherwise || (this.otherwise = new Block([new Literal('void 0')]));
|
2730
|
+
}
|
2731
|
+
if ((_ref3 = this.otherwise) != null) {
|
2732
|
+
_ref3.makeReturn(res);
|
2733
|
+
}
|
2734
|
+
return this;
|
2735
|
+
};
|
2736
|
+
|
2737
|
+
Switch.prototype.compileNode = function(o) {
|
2738
|
+
var block, body, code, cond, conditions, expr, i, idt1, idt2, _i, _j, _len, _len1, _ref2, _ref3, _ref4, _ref5;
|
2739
|
+
idt1 = o.indent + TAB;
|
2740
|
+
idt2 = o.indent = idt1 + TAB;
|
2741
|
+
code = this.tab + ("switch (" + (((_ref2 = this.subject) != null ? _ref2.compile(o, LEVEL_PAREN) : void 0) || false) + ") {\n");
|
2742
|
+
_ref3 = this.cases;
|
2743
|
+
for (i = _i = 0, _len = _ref3.length; _i < _len; i = ++_i) {
|
2744
|
+
_ref4 = _ref3[i], conditions = _ref4[0], block = _ref4[1];
|
2745
|
+
_ref5 = flatten([conditions]);
|
2746
|
+
for (_j = 0, _len1 = _ref5.length; _j < _len1; _j++) {
|
2747
|
+
cond = _ref5[_j];
|
2748
|
+
if (!this.subject) {
|
2749
|
+
cond = cond.invert();
|
2750
|
+
}
|
2751
|
+
code += idt1 + ("case " + (cond.compile(o, LEVEL_PAREN)) + ":\n");
|
2752
|
+
}
|
2753
|
+
if (body = block.compile(o, LEVEL_TOP)) {
|
2754
|
+
code += body + '\n';
|
2755
|
+
}
|
2756
|
+
if (i === this.cases.length - 1 && !this.otherwise) {
|
2757
|
+
break;
|
2758
|
+
}
|
2759
|
+
expr = this.lastNonComment(block.expressions);
|
2760
|
+
if (expr instanceof Return || (expr instanceof Literal && expr.jumps() && expr.value !== 'debugger')) {
|
2761
|
+
continue;
|
2762
|
+
}
|
2763
|
+
code += idt2 + 'break;\n';
|
2764
|
+
}
|
2765
|
+
if (this.otherwise && this.otherwise.expressions.length) {
|
2766
|
+
code += idt1 + ("default:\n" + (this.otherwise.compile(o, LEVEL_TOP)) + "\n");
|
2767
|
+
}
|
2768
|
+
return code + this.tab + '}';
|
2769
|
+
};
|
2770
|
+
|
2771
|
+
return Switch;
|
2772
|
+
|
2773
|
+
})(Base);
|
2774
|
+
|
2775
|
+
exports.If = If = (function(_super) {
|
2776
|
+
|
2777
|
+
__extends(If, _super);
|
2778
|
+
|
2779
|
+
function If(condition, body, options) {
|
2780
|
+
this.body = body;
|
2781
|
+
if (options == null) {
|
2782
|
+
options = {};
|
2783
|
+
}
|
2784
|
+
this.condition = options.type === 'unless' ? condition.invert() : condition;
|
2785
|
+
this.elseBody = null;
|
2786
|
+
this.isChain = false;
|
2787
|
+
this.soak = options.soak;
|
2788
|
+
}
|
2789
|
+
|
2790
|
+
If.prototype.children = ['condition', 'body', 'elseBody'];
|
2791
|
+
|
2792
|
+
If.prototype.bodyNode = function() {
|
2793
|
+
var _ref2;
|
2794
|
+
return (_ref2 = this.body) != null ? _ref2.unwrap() : void 0;
|
2795
|
+
};
|
2796
|
+
|
2797
|
+
If.prototype.elseBodyNode = function() {
|
2798
|
+
var _ref2;
|
2799
|
+
return (_ref2 = this.elseBody) != null ? _ref2.unwrap() : void 0;
|
2800
|
+
};
|
2801
|
+
|
2802
|
+
If.prototype.addElse = function(elseBody) {
|
2803
|
+
if (this.isChain) {
|
2804
|
+
this.elseBodyNode().addElse(elseBody);
|
2805
|
+
} else {
|
2806
|
+
this.isChain = elseBody instanceof If;
|
2807
|
+
this.elseBody = this.ensureBlock(elseBody);
|
2808
|
+
}
|
2809
|
+
return this;
|
2810
|
+
};
|
2811
|
+
|
2812
|
+
If.prototype.isStatement = function(o) {
|
2813
|
+
var _ref2;
|
2814
|
+
return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref2 = this.elseBodyNode()) != null ? _ref2.isStatement(o) : void 0);
|
2815
|
+
};
|
2816
|
+
|
2817
|
+
If.prototype.jumps = function(o) {
|
2818
|
+
var _ref2;
|
2819
|
+
return this.body.jumps(o) || ((_ref2 = this.elseBody) != null ? _ref2.jumps(o) : void 0);
|
2820
|
+
};
|
2821
|
+
|
2822
|
+
If.prototype.compileNode = function(o) {
|
2823
|
+
if (this.isStatement(o)) {
|
2824
|
+
return this.compileStatement(o);
|
2825
|
+
} else {
|
2826
|
+
return this.compileExpression(o);
|
2827
|
+
}
|
2828
|
+
};
|
2829
|
+
|
2830
|
+
If.prototype.makeReturn = function(res) {
|
2831
|
+
if (res) {
|
2832
|
+
this.elseBody || (this.elseBody = new Block([new Literal('void 0')]));
|
2833
|
+
}
|
2834
|
+
this.body && (this.body = new Block([this.body.makeReturn(res)]));
|
2835
|
+
this.elseBody && (this.elseBody = new Block([this.elseBody.makeReturn(res)]));
|
2836
|
+
return this;
|
2837
|
+
};
|
2838
|
+
|
2839
|
+
If.prototype.ensureBlock = function(node) {
|
2840
|
+
if (node instanceof Block) {
|
2841
|
+
return node;
|
2842
|
+
} else {
|
2843
|
+
return new Block([node]);
|
2844
|
+
}
|
2845
|
+
};
|
2846
|
+
|
2847
|
+
If.prototype.compileStatement = function(o) {
|
2848
|
+
var body, child, cond, exeq, ifPart;
|
2849
|
+
child = del(o, 'chainChild');
|
2850
|
+
exeq = del(o, 'isExistentialEquals');
|
2851
|
+
if (exeq) {
|
2852
|
+
return new If(this.condition.invert(), this.elseBodyNode(), {
|
2853
|
+
type: 'if'
|
2854
|
+
}).compile(o);
|
2855
|
+
}
|
2856
|
+
cond = this.condition.compile(o, LEVEL_PAREN);
|
2857
|
+
o.indent += TAB;
|
2858
|
+
body = this.ensureBlock(this.body);
|
2859
|
+
ifPart = "if (" + cond + ") {\n" + (body.compile(o)) + "\n" + this.tab + "}";
|
2860
|
+
if (!child) {
|
2861
|
+
ifPart = this.tab + ifPart;
|
2862
|
+
}
|
2863
|
+
if (!this.elseBody) {
|
2864
|
+
return ifPart;
|
2865
|
+
}
|
2866
|
+
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 + "}");
|
2867
|
+
};
|
2868
|
+
|
2869
|
+
If.prototype.compileExpression = function(o) {
|
2870
|
+
var alt, body, code, cond;
|
2871
|
+
cond = this.condition.compile(o, LEVEL_COND);
|
2872
|
+
body = this.bodyNode().compile(o, LEVEL_LIST);
|
2873
|
+
alt = this.elseBodyNode() ? this.elseBodyNode().compile(o, LEVEL_LIST) : 'void 0';
|
2874
|
+
code = "" + cond + " ? " + body + " : " + alt;
|
2875
|
+
if (o.level >= LEVEL_COND) {
|
2876
|
+
return "(" + code + ")";
|
2877
|
+
} else {
|
2878
|
+
return code;
|
2879
|
+
}
|
2880
|
+
};
|
2881
|
+
|
2882
|
+
If.prototype.unfoldSoak = function() {
|
2883
|
+
return this.soak && this;
|
2884
|
+
};
|
2885
|
+
|
2886
|
+
return If;
|
2887
|
+
|
2888
|
+
})(Base);
|
2889
|
+
|
2890
|
+
Closure = {
|
2891
|
+
wrap: function(expressions, statement, noReturn) {
|
2892
|
+
var args, call, func, mentionsArgs, meth;
|
2893
|
+
if (expressions.jumps()) {
|
2894
|
+
return expressions;
|
2895
|
+
}
|
2896
|
+
func = new Code([], Block.wrap([expressions]));
|
2897
|
+
args = [];
|
2898
|
+
if ((mentionsArgs = expressions.contains(this.literalArgs)) || expressions.contains(this.literalThis)) {
|
2899
|
+
meth = new Literal(mentionsArgs ? 'apply' : 'call');
|
2900
|
+
args = [new Literal('this')];
|
2901
|
+
if (mentionsArgs) {
|
2902
|
+
args.push(new Literal('arguments'));
|
2903
|
+
}
|
2904
|
+
func = new Value(func, [new Access(meth)]);
|
2905
|
+
}
|
2906
|
+
func.noReturn = noReturn;
|
2907
|
+
call = new Call(func, args);
|
2908
|
+
if (statement) {
|
2909
|
+
return Block.wrap([call]);
|
2910
|
+
} else {
|
2911
|
+
return call;
|
2912
|
+
}
|
2913
|
+
},
|
2914
|
+
literalArgs: function(node) {
|
2915
|
+
return node instanceof Literal && node.value === 'arguments' && !node.asKey;
|
2916
|
+
},
|
2917
|
+
literalThis: function(node) {
|
2918
|
+
return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound) || (node instanceof Call && node.isSuper);
|
2919
|
+
}
|
2920
|
+
};
|
2921
|
+
|
2922
|
+
unfoldSoak = function(o, parent, name) {
|
2923
|
+
var ifn;
|
2924
|
+
if (!(ifn = parent[name].unfoldSoak(o))) {
|
2925
|
+
return;
|
2926
|
+
}
|
2927
|
+
parent[name] = ifn.body;
|
2928
|
+
ifn.body = new Value(parent);
|
2929
|
+
return ifn;
|
2930
|
+
};
|
2931
|
+
|
2932
|
+
UTILITIES = {
|
2933
|
+
"extends": function() {
|
2934
|
+
return "function(child, parent) { for (var key in parent) { if (" + (utility('hasProp')) + ".call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }";
|
2935
|
+
},
|
2936
|
+
bind: function() {
|
2937
|
+
return 'function(fn, me){ return function(){ return fn.apply(me, arguments); }; }';
|
2938
|
+
},
|
2939
|
+
indexOf: function() {
|
2940
|
+
return "[].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }";
|
2941
|
+
},
|
2942
|
+
hasProp: function() {
|
2943
|
+
return '{}.hasOwnProperty';
|
2944
|
+
},
|
2945
|
+
slice: function() {
|
2946
|
+
return '[].slice';
|
2947
|
+
}
|
2948
|
+
};
|
2949
|
+
|
2950
|
+
LEVEL_TOP = 1;
|
2951
|
+
|
2952
|
+
LEVEL_PAREN = 2;
|
2953
|
+
|
2954
|
+
LEVEL_LIST = 3;
|
2955
|
+
|
2956
|
+
LEVEL_COND = 4;
|
2957
|
+
|
2958
|
+
LEVEL_OP = 5;
|
2959
|
+
|
2960
|
+
LEVEL_ACCESS = 6;
|
2961
|
+
|
2962
|
+
TAB = ' ';
|
2963
|
+
|
2964
|
+
IDENTIFIER_STR = "[$A-Za-z_\\x7f-\\uffff][$\\w\\x7f-\\uffff]*";
|
2965
|
+
|
2966
|
+
IDENTIFIER = RegExp("^" + IDENTIFIER_STR + "$");
|
2967
|
+
|
2968
|
+
SIMPLENUM = /^[+-]?\d+$/;
|
2969
|
+
|
2970
|
+
METHOD_DEF = RegExp("^(?:(" + IDENTIFIER_STR + ")\\.prototype(?:\\.(" + IDENTIFIER_STR + ")|\\[(\"(?:[^\\\\\"\\r\\n]|\\\\.)*\"|'(?:[^\\\\'\\r\\n]|\\\\.)*')\\]|\\[(0x[\\da-fA-F]+|\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\]))|(" + IDENTIFIER_STR + ")$");
|
2971
|
+
|
2972
|
+
IS_STRING = /^['"]/;
|
2973
|
+
|
2974
|
+
utility = function(name) {
|
2975
|
+
var ref;
|
2976
|
+
ref = "__" + name;
|
2977
|
+
Scope.root.assign(ref, UTILITIES[name]());
|
2978
|
+
return ref;
|
2979
|
+
};
|
2980
|
+
|
2981
|
+
multident = function(code, tab) {
|
2982
|
+
code = code.replace(/\n/g, '$&' + tab);
|
2983
|
+
return code.replace(/\s+$/, '');
|
2984
|
+
};
|
2985
|
+
|
2986
|
+
}).call(this);
|