/lib/coffee-script/nodes.js
JavaScript | 3485 lines | 3036 code | 448 blank | 1 comment | 812 complexity | a514c6d377b241ff5302069b9659a7d1 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
1// Generated by CoffeeScript 1.10.0 2(function() { 3 var Access, Arr, Assign, Base, Block, BooleanLiteral, Call, Class, Code, CodeFragment, Comment, Existence, Expansion, Extends, For, IdentifierLiteral, If, In, Index, InfinityLiteral, JS_FORBIDDEN, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, NEGATE, NO, NaNLiteral, NullLiteral, NumberLiteral, Obj, Op, Param, Parens, PassthroughLiteral, PropertyName, Range, RegexLiteral, RegexWithInterpolations, Return, SIMPLENUM, Scope, Slice, Splat, StatementLiteral, StringLiteral, StringWithInterpolations, SuperCall, Switch, TAB, THIS, ThisLiteral, Throw, Try, UTILITIES, UndefinedLiteral, Value, While, YES, YieldReturn, addLocationDataFn, compact, del, ends, extend, flatten, fragmentsToText, isComplexOrAssignable, isLiteralArguments, isLiteralThis, isUnassignable, locationDataToString, merge, multident, ref1, ref2, some, starts, throwSyntaxError, unfoldSoak, utility, 4 extend1 = 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; }, 5 hasProp = {}.hasOwnProperty, 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 slice = [].slice; 8 9 Error.stackTraceLimit = 2e308; 10 11 Scope = require('./scope').Scope; 12 13 ref1 = require('./lexer'), isUnassignable = ref1.isUnassignable, JS_FORBIDDEN = ref1.JS_FORBIDDEN; 14 15 ref2 = require('./helpers'), compact = ref2.compact, flatten = ref2.flatten, extend = ref2.extend, merge = ref2.merge, del = ref2.del, starts = ref2.starts, ends = ref2.ends, some = ref2.some, addLocationDataFn = ref2.addLocationDataFn, locationDataToString = ref2.locationDataToString, throwSyntaxError = ref2.throwSyntaxError; 16 17 exports.extend = extend; 18 19 exports.addLocationDataFn = addLocationDataFn; 20 21 YES = function() { 22 return true; 23 }; 24 25 NO = function() { 26 return false; 27 }; 28 29 THIS = function() { 30 return this; 31 }; 32 33 NEGATE = function() { 34 this.negated = !this.negated; 35 return this; 36 }; 37 38 exports.CodeFragment = CodeFragment = (function() { 39 function CodeFragment(parent, code) { 40 var ref3; 41 this.code = "" + code; 42 this.locationData = parent != null ? parent.locationData : void 0; 43 this.type = (parent != null ? (ref3 = parent.constructor) != null ? ref3.name : void 0 : void 0) || 'unknown'; 44 } 45 46 CodeFragment.prototype.toString = function() { 47 return "" + this.code + (this.locationData ? ": " + locationDataToString(this.locationData) : ''); 48 }; 49 50 return CodeFragment; 51 52 })(); 53 54 fragmentsToText = function(fragments) { 55 var fragment; 56 return ((function() { 57 var j, len1, results; 58 results = []; 59 for (j = 0, len1 = fragments.length; j < len1; j++) { 60 fragment = fragments[j]; 61 results.push(fragment.code); 62 } 63 return results; 64 })()).join(''); 65 }; 66 67 exports.Base = Base = (function() { 68 function Base() {} 69 70 Base.prototype.compile = function(o, lvl) { 71 return fragmentsToText(this.compileToFragments(o, lvl)); 72 }; 73 74 Base.prototype.compileToFragments = function(o, lvl) { 75 var node; 76 o = extend({}, o); 77 if (lvl) { 78 o.level = lvl; 79 } 80 node = this.unfoldSoak(o) || this; 81 node.tab = o.indent; 82 if (o.level === LEVEL_TOP || !node.isStatement(o)) { 83 return node.compileNode(o); 84 } else { 85 return node.compileClosure(o); 86 } 87 }; 88 89 Base.prototype.compileClosure = function(o) { 90 var args, argumentsNode, func, jumpNode, meth, parts, ref3; 91 if (jumpNode = this.jumps()) { 92 jumpNode.error('cannot use a pure statement in an expression'); 93 } 94 o.sharedScope = true; 95 func = new Code([], Block.wrap([this])); 96 args = []; 97 if ((argumentsNode = this.contains(isLiteralArguments)) || this.contains(isLiteralThis)) { 98 args = [new ThisLiteral]; 99 if (argumentsNode) { 100 meth = 'apply'; 101 args.push(new IdentifierLiteral('arguments')); 102 } else { 103 meth = 'call'; 104 } 105 func = new Value(func, [new Access(new PropertyName(meth))]); 106 } 107 parts = (new Call(func, args)).compileNode(o); 108 if (func.isGenerator || ((ref3 = func.base) != null ? ref3.isGenerator : void 0)) { 109 parts.unshift(this.makeCode("(yield* ")); 110 parts.push(this.makeCode(")")); 111 } 112 return parts; 113 }; 114 115 Base.prototype.cache = function(o, level, isComplex) { 116 var complex, ref, sub; 117 complex = isComplex != null ? isComplex(this) : this.isComplex(); 118 if (complex) { 119 ref = new IdentifierLiteral(o.scope.freeVariable('ref')); 120 sub = new Assign(ref, this); 121 if (level) { 122 return [sub.compileToFragments(o, level), [this.makeCode(ref.value)]]; 123 } else { 124 return [sub, ref]; 125 } 126 } else { 127 ref = level ? this.compileToFragments(o, level) : this; 128 return [ref, ref]; 129 } 130 }; 131 132 Base.prototype.cacheToCodeFragments = function(cacheValues) { 133 return [fragmentsToText(cacheValues[0]), fragmentsToText(cacheValues[1])]; 134 }; 135 136 Base.prototype.makeReturn = function(res) { 137 var me; 138 me = this.unwrapAll(); 139 if (res) { 140 return new Call(new Literal(res + ".push"), [me]); 141 } else { 142 return new Return(me); 143 } 144 }; 145 146 Base.prototype.contains = function(pred) { 147 var node; 148 node = void 0; 149 this.traverseChildren(false, function(n) { 150 if (pred(n)) { 151 node = n; 152 return false; 153 } 154 }); 155 return node; 156 }; 157 158 Base.prototype.lastNonComment = function(list) { 159 var i; 160 i = list.length; 161 while (i--) { 162 if (!(list[i] instanceof Comment)) { 163 return list[i]; 164 } 165 } 166 return null; 167 }; 168 169 Base.prototype.toString = function(idt, name) { 170 var tree; 171 if (idt == null) { 172 idt = ''; 173 } 174 if (name == null) { 175 name = this.constructor.name; 176 } 177 tree = '\n' + idt + name; 178 if (this.soak) { 179 tree += '?'; 180 } 181 this.eachChild(function(node) { 182 return tree += node.toString(idt + TAB); 183 }); 184 return tree; 185 }; 186 187 Base.prototype.eachChild = function(func) { 188 var attr, child, j, k, len1, len2, ref3, ref4; 189 if (!this.children) { 190 return this; 191 } 192 ref3 = this.children; 193 for (j = 0, len1 = ref3.length; j < len1; j++) { 194 attr = ref3[j]; 195 if (this[attr]) { 196 ref4 = flatten([this[attr]]); 197 for (k = 0, len2 = ref4.length; k < len2; k++) { 198 child = ref4[k]; 199 if (func(child) === false) { 200 return this; 201 } 202 } 203 } 204 } 205 return this; 206 }; 207 208 Base.prototype.traverseChildren = function(crossScope, func) { 209 return this.eachChild(function(child) { 210 var recur; 211 recur = func(child); 212 if (recur !== false) { 213 return child.traverseChildren(crossScope, func); 214 } 215 }); 216 }; 217 218 Base.prototype.invert = function() { 219 return new Op('!', this); 220 }; 221 222 Base.prototype.unwrapAll = function() { 223 var node; 224 node = this; 225 while (node !== (node = node.unwrap())) { 226 continue; 227 } 228 return node; 229 }; 230 231 Base.prototype.children = []; 232 233 Base.prototype.isStatement = NO; 234 235 Base.prototype.jumps = NO; 236 237 Base.prototype.isComplex = YES; 238 239 Base.prototype.isChainable = NO; 240 241 Base.prototype.isAssignable = NO; 242 243 Base.prototype.isNumber = NO; 244 245 Base.prototype.unwrap = THIS; 246 247 Base.prototype.unfoldSoak = NO; 248 249 Base.prototype.assigns = NO; 250 251 Base.prototype.updateLocationDataIfMissing = function(locationData) { 252 if (this.locationData) { 253 return this; 254 } 255 this.locationData = locationData; 256 return this.eachChild(function(child) { 257 return child.updateLocationDataIfMissing(locationData); 258 }); 259 }; 260 261 Base.prototype.error = function(message) { 262 return throwSyntaxError(message, this.locationData); 263 }; 264 265 Base.prototype.makeCode = function(code) { 266 return new CodeFragment(this, code); 267 }; 268 269 Base.prototype.wrapInBraces = function(fragments) { 270 return [].concat(this.makeCode('('), fragments, this.makeCode(')')); 271 }; 272 273 Base.prototype.joinFragmentArrays = function(fragmentsList, joinStr) { 274 var answer, fragments, i, j, len1; 275 answer = []; 276 for (i = j = 0, len1 = fragmentsList.length; j < len1; i = ++j) { 277 fragments = fragmentsList[i]; 278 if (i) { 279 answer.push(this.makeCode(joinStr)); 280 } 281 answer = answer.concat(fragments); 282 } 283 return answer; 284 }; 285 286 return Base; 287 288 })(); 289 290 exports.Block = Block = (function(superClass1) { 291 extend1(Block, superClass1); 292 293 function Block(nodes) { 294 this.expressions = compact(flatten(nodes || [])); 295 } 296 297 Block.prototype.children = ['expressions']; 298 299 Block.prototype.push = function(node) { 300 this.expressions.push(node); 301 return this; 302 }; 303 304 Block.prototype.pop = function() { 305 return this.expressions.pop(); 306 }; 307 308 Block.prototype.unshift = function(node) { 309 this.expressions.unshift(node); 310 return this; 311 }; 312 313 Block.prototype.unwrap = function() { 314 if (this.expressions.length === 1) { 315 return this.expressions[0]; 316 } else { 317 return this; 318 } 319 }; 320 321 Block.prototype.isEmpty = function() { 322 return !this.expressions.length; 323 }; 324 325 Block.prototype.isStatement = function(o) { 326 var exp, j, len1, ref3; 327 ref3 = this.expressions; 328 for (j = 0, len1 = ref3.length; j < len1; j++) { 329 exp = ref3[j]; 330 if (exp.isStatement(o)) { 331 return true; 332 } 333 } 334 return false; 335 }; 336 337 Block.prototype.jumps = function(o) { 338 var exp, j, jumpNode, len1, ref3; 339 ref3 = this.expressions; 340 for (j = 0, len1 = ref3.length; j < len1; j++) { 341 exp = ref3[j]; 342 if (jumpNode = exp.jumps(o)) { 343 return jumpNode; 344 } 345 } 346 }; 347 348 Block.prototype.makeReturn = function(res) { 349 var expr, len; 350 len = this.expressions.length; 351 while (len--) { 352 expr = this.expressions[len]; 353 if (!(expr instanceof Comment)) { 354 this.expressions[len] = expr.makeReturn(res); 355 if (expr instanceof Return && !expr.expression) { 356 this.expressions.splice(len, 1); 357 } 358 break; 359 } 360 } 361 return this; 362 }; 363 364 Block.prototype.compileToFragments = function(o, level) { 365 if (o == null) { 366 o = {}; 367 } 368 if (o.scope) { 369 return Block.__super__.compileToFragments.call(this, o, level); 370 } else { 371 return this.compileRoot(o); 372 } 373 }; 374 375 Block.prototype.compileNode = function(o) { 376 var answer, compiledNodes, fragments, index, j, len1, node, ref3, top; 377 this.tab = o.indent; 378 top = o.level === LEVEL_TOP; 379 compiledNodes = []; 380 ref3 = this.expressions; 381 for (index = j = 0, len1 = ref3.length; j < len1; index = ++j) { 382 node = ref3[index]; 383 node = node.unwrapAll(); 384 node = node.unfoldSoak(o) || node; 385 if (node instanceof Block) { 386 compiledNodes.push(node.compileNode(o)); 387 } else if (top) { 388 node.front = true; 389 fragments = node.compileToFragments(o); 390 if (!node.isStatement(o)) { 391 fragments.unshift(this.makeCode("" + this.tab)); 392 fragments.push(this.makeCode(";")); 393 } 394 compiledNodes.push(fragments); 395 } else { 396 compiledNodes.push(node.compileToFragments(o, LEVEL_LIST)); 397 } 398 } 399 if (top) { 400 if (this.spaced) { 401 return [].concat(this.joinFragmentArrays(compiledNodes, '\n\n'), this.makeCode("\n")); 402 } else { 403 return this.joinFragmentArrays(compiledNodes, '\n'); 404 } 405 } 406 if (compiledNodes.length) { 407 answer = this.joinFragmentArrays(compiledNodes, ', '); 408 } else { 409 answer = [this.makeCode("void 0")]; 410 } 411 if (compiledNodes.length > 1 && o.level >= LEVEL_LIST) { 412 return this.wrapInBraces(answer); 413 } else { 414 return answer; 415 } 416 }; 417 418 Block.prototype.compileRoot = function(o) { 419 var exp, fragments, i, j, len1, name, prelude, preludeExps, ref3, ref4, rest; 420 o.indent = o.bare ? '' : TAB; 421 o.level = LEVEL_TOP; 422 this.spaced = true; 423 o.scope = new Scope(null, this, null, (ref3 = o.referencedVars) != null ? ref3 : []); 424 ref4 = o.locals || []; 425 for (j = 0, len1 = ref4.length; j < len1; j++) { 426 name = ref4[j]; 427 o.scope.parameter(name); 428 } 429 prelude = []; 430 if (!o.bare) { 431 preludeExps = (function() { 432 var k, len2, ref5, results; 433 ref5 = this.expressions; 434 results = []; 435 for (i = k = 0, len2 = ref5.length; k < len2; i = ++k) { 436 exp = ref5[i]; 437 if (!(exp.unwrap() instanceof Comment)) { 438 break; 439 } 440 results.push(exp); 441 } 442 return results; 443 }).call(this); 444 rest = this.expressions.slice(preludeExps.length); 445 this.expressions = preludeExps; 446 if (preludeExps.length) { 447 prelude = this.compileNode(merge(o, { 448 indent: '' 449 })); 450 prelude.push(this.makeCode("\n")); 451 } 452 this.expressions = rest; 453 } 454 fragments = this.compileWithDeclarations(o); 455 if (o.bare) { 456 return fragments; 457 } 458 return [].concat(prelude, this.makeCode("(function() {\n"), fragments, this.makeCode("\n}).call(this);\n")); 459 }; 460 461 Block.prototype.compileWithDeclarations = function(o) { 462 var assigns, declars, exp, fragments, i, j, len1, post, ref3, ref4, ref5, rest, scope, spaced; 463 fragments = []; 464 post = []; 465 ref3 = this.expressions; 466 for (i = j = 0, len1 = ref3.length; j < len1; i = ++j) { 467 exp = ref3[i]; 468 exp = exp.unwrap(); 469 if (!(exp instanceof Comment || exp instanceof Literal)) { 470 break; 471 } 472 } 473 o = merge(o, { 474 level: LEVEL_TOP 475 }); 476 if (i) { 477 rest = this.expressions.splice(i, 9e9); 478 ref4 = [this.spaced, false], spaced = ref4[0], this.spaced = ref4[1]; 479 ref5 = [this.compileNode(o), spaced], fragments = ref5[0], this.spaced = ref5[1]; 480 this.expressions = rest; 481 } 482 post = this.compileNode(o); 483 scope = o.scope; 484 if (scope.expressions === this) { 485 declars = o.scope.hasDeclarations(); 486 assigns = scope.hasAssignments; 487 if (declars || assigns) { 488 if (i) { 489 fragments.push(this.makeCode('\n')); 490 } 491 fragments.push(this.makeCode(this.tab + "var ")); 492 if (declars) { 493 fragments.push(this.makeCode(scope.declaredVariables().join(', '))); 494 } 495 if (assigns) { 496 if (declars) { 497 fragments.push(this.makeCode(",\n" + (this.tab + TAB))); 498 } 499 fragments.push(this.makeCode(scope.assignedVariables().join(",\n" + (this.tab + TAB)))); 500 } 501 fragments.push(this.makeCode(";\n" + (this.spaced ? '\n' : ''))); 502 } else if (fragments.length && post.length) { 503 fragments.push(this.makeCode("\n")); 504 } 505 } 506 return fragments.concat(post); 507 }; 508 509 Block.wrap = function(nodes) { 510 if (nodes.length === 1 && nodes[0] instanceof Block) { 511 return nodes[0]; 512 } 513 return new Block(nodes); 514 }; 515 516 return Block; 517 518 })(Base); 519 520 exports.Literal = Literal = (function(superClass1) { 521 extend1(Literal, superClass1); 522 523 function Literal(value1) { 524 this.value = value1; 525 } 526 527 Literal.prototype.isComplex = NO; 528 529 Literal.prototype.assigns = function(name) { 530 return name === this.value; 531 }; 532 533 Literal.prototype.compileNode = function(o) { 534 return [this.makeCode(this.value)]; 535 }; 536 537 Literal.prototype.toString = function() { 538 return " " + (this.isStatement() ? Literal.__super__.toString.apply(this, arguments) : this.constructor.name) + ": " + this.value; 539 }; 540 541 return Literal; 542 543 })(Base); 544 545 exports.NumberLiteral = NumberLiteral = (function(superClass1) { 546 extend1(NumberLiteral, superClass1); 547 548 function NumberLiteral() { 549 return NumberLiteral.__super__.constructor.apply(this, arguments); 550 } 551 552 return NumberLiteral; 553 554 })(Literal); 555 556 exports.InfinityLiteral = InfinityLiteral = (function(superClass1) { 557 extend1(InfinityLiteral, superClass1); 558 559 function InfinityLiteral() { 560 return InfinityLiteral.__super__.constructor.apply(this, arguments); 561 } 562 563 InfinityLiteral.prototype.compileNode = function() { 564 return [this.makeCode('2e308')]; 565 }; 566 567 return InfinityLiteral; 568 569 })(NumberLiteral); 570 571 exports.NaNLiteral = NaNLiteral = (function(superClass1) { 572 extend1(NaNLiteral, superClass1); 573 574 function NaNLiteral() { 575 NaNLiteral.__super__.constructor.call(this, 'NaN'); 576 } 577 578 NaNLiteral.prototype.compileNode = function(o) { 579 var code; 580 code = [this.makeCode('0/0')]; 581 if (o.level >= LEVEL_OP) { 582 return this.wrapInBraces(code); 583 } else { 584 return code; 585 } 586 }; 587 588 return NaNLiteral; 589 590 })(NumberLiteral); 591 592 exports.StringLiteral = StringLiteral = (function(superClass1) { 593 extend1(StringLiteral, superClass1); 594 595 function StringLiteral() { 596 return StringLiteral.__super__.constructor.apply(this, arguments); 597 } 598 599 return StringLiteral; 600 601 })(Literal); 602 603 exports.RegexLiteral = RegexLiteral = (function(superClass1) { 604 extend1(RegexLiteral, superClass1); 605 606 function RegexLiteral() { 607 return RegexLiteral.__super__.constructor.apply(this, arguments); 608 } 609 610 return RegexLiteral; 611 612 })(Literal); 613 614 exports.PassthroughLiteral = PassthroughLiteral = (function(superClass1) { 615 extend1(PassthroughLiteral, superClass1); 616 617 function PassthroughLiteral() { 618 return PassthroughLiteral.__super__.constructor.apply(this, arguments); 619 } 620 621 return PassthroughLiteral; 622 623 })(Literal); 624 625 exports.IdentifierLiteral = IdentifierLiteral = (function(superClass1) { 626 extend1(IdentifierLiteral, superClass1); 627 628 function IdentifierLiteral() { 629 return IdentifierLiteral.__super__.constructor.apply(this, arguments); 630 } 631 632 IdentifierLiteral.prototype.isAssignable = YES; 633 634 return IdentifierLiteral; 635 636 })(Literal); 637 638 exports.PropertyName = PropertyName = (function(superClass1) { 639 extend1(PropertyName, superClass1); 640 641 function PropertyName() { 642 return PropertyName.__super__.constructor.apply(this, arguments); 643 } 644 645 PropertyName.prototype.isAssignable = YES; 646 647 return PropertyName; 648 649 })(Literal); 650 651 exports.StatementLiteral = StatementLiteral = (function(superClass1) { 652 extend1(StatementLiteral, superClass1); 653 654 function StatementLiteral() { 655 return StatementLiteral.__super__.constructor.apply(this, arguments); 656 } 657 658 StatementLiteral.prototype.isStatement = YES; 659 660 StatementLiteral.prototype.makeReturn = THIS; 661 662 StatementLiteral.prototype.jumps = function(o) { 663 if (this.value === 'break' && !((o != null ? o.loop : void 0) || (o != null ? o.block : void 0))) { 664 return this; 665 } 666 if (this.value === 'continue' && !(o != null ? o.loop : void 0)) { 667 return this; 668 } 669 }; 670 671 StatementLiteral.prototype.compileNode = function(o) { 672 return [this.makeCode("" + this.tab + this.value + ";")]; 673 }; 674 675 return StatementLiteral; 676 677 })(Literal); 678 679 exports.ThisLiteral = ThisLiteral = (function(superClass1) { 680 extend1(ThisLiteral, superClass1); 681 682 function ThisLiteral() { 683 ThisLiteral.__super__.constructor.call(this, 'this'); 684 } 685 686 ThisLiteral.prototype.compileNode = function(o) { 687 var code, ref3; 688 code = ((ref3 = o.scope.method) != null ? ref3.bound : void 0) ? o.scope.method.context : this.value; 689 return [this.makeCode(code)]; 690 }; 691 692 return ThisLiteral; 693 694 })(Literal); 695 696 exports.UndefinedLiteral = UndefinedLiteral = (function(superClass1) { 697 extend1(UndefinedLiteral, superClass1); 698 699 function UndefinedLiteral() { 700 UndefinedLiteral.__super__.constructor.call(this, 'undefined'); 701 } 702 703 UndefinedLiteral.prototype.compileNode = function(o) { 704 return [this.makeCode(o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0')]; 705 }; 706 707 return UndefinedLiteral; 708 709 })(Literal); 710 711 exports.NullLiteral = NullLiteral = (function(superClass1) { 712 extend1(NullLiteral, superClass1); 713 714 function NullLiteral() { 715 NullLiteral.__super__.constructor.call(this, 'null'); 716 } 717 718 return NullLiteral; 719 720 })(Literal); 721 722 exports.BooleanLiteral = BooleanLiteral = (function(superClass1) { 723 extend1(BooleanLiteral, superClass1); 724 725 function BooleanLiteral() { 726 return BooleanLiteral.__super__.constructor.apply(this, arguments); 727 } 728 729 return BooleanLiteral; 730 731 })(Literal); 732 733 exports.Return = Return = (function(superClass1) { 734 extend1(Return, superClass1); 735 736 function Return(expression) { 737 this.expression = expression; 738 } 739 740 Return.prototype.children = ['expression']; 741 742 Return.prototype.isStatement = YES; 743 744 Return.prototype.makeReturn = THIS; 745 746 Return.prototype.jumps = THIS; 747 748 Return.prototype.compileToFragments = function(o, level) { 749 var expr, ref3; 750 expr = (ref3 = this.expression) != null ? ref3.makeReturn() : void 0; 751 if (expr && !(expr instanceof Return)) { 752 return expr.compileToFragments(o, level); 753 } else { 754 return Return.__super__.compileToFragments.call(this, o, level); 755 } 756 }; 757 758 Return.prototype.compileNode = function(o) { 759 var answer; 760 answer = []; 761 answer.push(this.makeCode(this.tab + ("return" + (this.expression ? " " : "")))); 762 if (this.expression) { 763 answer = answer.concat(this.expression.compileToFragments(o, LEVEL_PAREN)); 764 } 765 answer.push(this.makeCode(";")); 766 return answer; 767 }; 768 769 return Return; 770 771 })(Base); 772 773 exports.YieldReturn = YieldReturn = (function(superClass1) { 774 extend1(YieldReturn, superClass1); 775 776 function YieldReturn() { 777 return YieldReturn.__super__.constructor.apply(this, arguments); 778 } 779 780 YieldReturn.prototype.compileNode = function(o) { 781 if (o.scope.parent == null) { 782 this.error('yield can only occur inside functions'); 783 } 784 return YieldReturn.__super__.compileNode.apply(this, arguments); 785 }; 786 787 return YieldReturn; 788 789 })(Return); 790 791 exports.Value = Value = (function(superClass1) { 792 extend1(Value, superClass1); 793 794 function Value(base, props, tag) { 795 if (!props && base instanceof Value) { 796 return base; 797 } 798 this.base = base; 799 this.properties = props || []; 800 if (tag) { 801 this[tag] = true; 802 } 803 return this; 804 } 805 806 Value.prototype.children = ['base', 'properties']; 807 808 Value.prototype.add = function(props) { 809 this.properties = this.properties.concat(props); 810 return this; 811 }; 812 813 Value.prototype.hasProperties = function() { 814 return !!this.properties.length; 815 }; 816 817 Value.prototype.bareLiteral = function(type) { 818 return !this.properties.length && this.base instanceof type; 819 }; 820 821 Value.prototype.isArray = function() { 822 return this.bareLiteral(Arr); 823 }; 824 825 Value.prototype.isRange = function() { 826 return this.bareLiteral(Range); 827 }; 828 829 Value.prototype.isComplex = function() { 830 return this.hasProperties() || this.base.isComplex(); 831 }; 832 833 Value.prototype.isAssignable = function() { 834 return this.hasProperties() || this.base.isAssignable(); 835 }; 836 837 Value.prototype.isNumber = function() { 838 return this.bareLiteral(NumberLiteral); 839 }; 840 841 Value.prototype.isString = function() { 842 return this.bareLiteral(StringLiteral); 843 }; 844 845 Value.prototype.isRegex = function() { 846 return this.bareLiteral(RegexLiteral); 847 }; 848 849 Value.prototype.isUndefined = function() { 850 return this.bareLiteral(UndefinedLiteral); 851 }; 852 853 Value.prototype.isNull = function() { 854 return this.bareLiteral(NullLiteral); 855 }; 856 857 Value.prototype.isBoolean = function() { 858 return this.bareLiteral(BooleanLiteral); 859 }; 860 861 Value.prototype.isAtomic = function() { 862 var j, len1, node, ref3; 863 ref3 = this.properties.concat(this.base); 864 for (j = 0, len1 = ref3.length; j < len1; j++) { 865 node = ref3[j]; 866 if (node.soak || node instanceof Call) { 867 return false; 868 } 869 } 870 return true; 871 }; 872 873 Value.prototype.isNotCallable = function() { 874 return this.isNumber() || this.isString() || this.isRegex() || this.isArray() || this.isRange() || this.isSplice() || this.isObject() || this.isUndefined() || this.isNull() || this.isBoolean(); 875 }; 876 877 Value.prototype.isStatement = function(o) { 878 return !this.properties.length && this.base.isStatement(o); 879 }; 880 881 Value.prototype.assigns = function(name) { 882 return !this.properties.length && this.base.assigns(name); 883 }; 884 885 Value.prototype.jumps = function(o) { 886 return !this.properties.length && this.base.jumps(o); 887 }; 888 889 Value.prototype.isObject = function(onlyGenerated) { 890 if (this.properties.length) { 891 return false; 892 } 893 return (this.base instanceof Obj) && (!onlyGenerated || this.base.generated); 894 }; 895 896 Value.prototype.isSplice = function() { 897 var lastProp, ref3; 898 ref3 = this.properties, lastProp = ref3[ref3.length - 1]; 899 return lastProp instanceof Slice; 900 }; 901 902 Value.prototype.looksStatic = function(className) { 903 var ref3; 904 return this.base.value === className && this.properties.length === 1 && ((ref3 = this.properties[0].name) != null ? ref3.value : void 0) !== 'prototype'; 905 }; 906 907 Value.prototype.unwrap = function() { 908 if (this.properties.length) { 909 return this; 910 } else { 911 return this.base; 912 } 913 }; 914 915 Value.prototype.cacheReference = function(o) { 916 var base, bref, name, nref, ref3; 917 ref3 = this.properties, name = ref3[ref3.length - 1]; 918 if (this.properties.length < 2 && !this.base.isComplex() && !(name != null ? name.isComplex() : void 0)) { 919 return [this, this]; 920 } 921 base = new Value(this.base, this.properties.slice(0, -1)); 922 if (base.isComplex()) { 923 bref = new IdentifierLiteral(o.scope.freeVariable('base')); 924 base = new Value(new Parens(new Assign(bref, base))); 925 } 926 if (!name) { 927 return [base, bref]; 928 } 929 if (name.isComplex()) { 930 nref = new IdentifierLiteral(o.scope.freeVariable('name')); 931 name = new Index(new Assign(nref, name.index)); 932 nref = new Index(nref); 933 } 934 return [base.add(name), new Value(bref || base.base, [nref || name])]; 935 }; 936 937 Value.prototype.compileNode = function(o) { 938 var fragments, j, len1, prop, props; 939 this.base.front = this.front; 940 props = this.properties; 941 fragments = this.base.compileToFragments(o, (props.length ? LEVEL_ACCESS : null)); 942 if (props.length && SIMPLENUM.test(fragmentsToText(fragments))) { 943 fragments.push(this.makeCode('.')); 944 } 945 for (j = 0, len1 = props.length; j < len1; j++) { 946 prop = props[j]; 947 fragments.push.apply(fragments, prop.compileToFragments(o)); 948 } 949 return fragments; 950 }; 951 952 Value.prototype.unfoldSoak = function(o) { 953 return this.unfoldedSoak != null ? this.unfoldedSoak : this.unfoldedSoak = (function(_this) { 954 return function() { 955 var fst, i, ifn, j, len1, prop, ref, ref3, ref4, snd; 956 if (ifn = _this.base.unfoldSoak(o)) { 957 (ref3 = ifn.body.properties).push.apply(ref3, _this.properties); 958 return ifn; 959 } 960 ref4 = _this.properties; 961 for (i = j = 0, len1 = ref4.length; j < len1; i = ++j) { 962 prop = ref4[i]; 963 if (!prop.soak) { 964 continue; 965 } 966 prop.soak = false; 967 fst = new Value(_this.base, _this.properties.slice(0, i)); 968 snd = new Value(_this.base, _this.properties.slice(i)); 969 if (fst.isComplex()) { 970 ref = new IdentifierLiteral(o.scope.freeVariable('ref')); 971 fst = new Parens(new Assign(ref, fst)); 972 snd.base = ref; 973 } 974 return new If(new Existence(fst), snd, { 975 soak: true 976 }); 977 } 978 return false; 979 }; 980 })(this)(); 981 }; 982 983 return Value; 984 985 })(Base); 986 987 exports.Comment = Comment = (function(superClass1) { 988 extend1(Comment, superClass1); 989 990 function Comment(comment1) { 991 this.comment = comment1; 992 } 993 994 Comment.prototype.isStatement = YES; 995 996 Comment.prototype.makeReturn = THIS; 997 998 Comment.prototype.compileNode = function(o, level) { 999 var code, comment; 1000 comment = this.comment.replace(/^(\s*)#(?=\s)/gm, "$1 *"); 1001 code = "/*" + (multident(comment, this.tab)) + (indexOf.call(comment, '\n') >= 0 ? "\n" + this.tab : '') + " */"; 1002 if ((level || o.level) === LEVEL_TOP) { 1003 code = o.indent + code; 1004 } 1005 return [this.makeCode("\n"), this.makeCode(code)]; 1006 }; 1007 1008 return Comment; 1009 1010 })(Base); 1011 1012 exports.Call = Call = (function(superClass1) { 1013 extend1(Call, superClass1); 1014 1015 function Call(variable1, args1, soak) { 1016 this.variable = variable1; 1017 this.args = args1 != null ? args1 : []; 1018 this.soak = soak; 1019 this.isNew = false; 1020 if (this.variable instanceof Value && this.variable.isNotCallable()) { 1021 this.variable.error("literal is not a function"); 1022 } 1023 } 1024 1025 Call.prototype.children = ['variable', 'args']; 1026 1027 Call.prototype.newInstance = function() { 1028 var base, ref3; 1029 base = ((ref3 = this.variable) != null ? ref3.base : void 0) || this.variable; 1030 if (base instanceof Call && !base.isNew) { 1031 base.newInstance(); 1032 } else { 1033 this.isNew = true; 1034 } 1035 return this; 1036 }; 1037 1038 Call.prototype.unfoldSoak = function(o) { 1039 var call, ifn, j, left, len1, list, ref3, ref4, rite; 1040 if (this.soak) { 1041 if (this instanceof SuperCall) { 1042 left = new Literal(this.superReference(o)); 1043 rite = new Value(left); 1044 } else { 1045 if (ifn = unfoldSoak(o, this, 'variable')) { 1046 return ifn; 1047 } 1048 ref3 = new Value(this.variable).cacheReference(o), left = ref3[0], rite = ref3[1]; 1049 } 1050 rite = new Call(rite, this.args); 1051 rite.isNew = this.isNew; 1052 left = new Literal("typeof " + (left.compile(o)) + " === \"function\""); 1053 return new If(left, new Value(rite), { 1054 soak: true 1055 }); 1056 } 1057 call = this; 1058 list = []; 1059 while (true) { 1060 if (call.variable instanceof Call) { 1061 list.push(call); 1062 call = call.variable; 1063 continue; 1064 } 1065 if (!(call.variable instanceof Value)) { 1066 break; 1067 } 1068 list.push(call); 1069 if (!((call = call.variable.base) instanceof Call)) { 1070 break; 1071 } 1072 } 1073 ref4 = list.reverse(); 1074 for (j = 0, len1 = ref4.length; j < len1; j++) { 1075 call = ref4[j]; 1076 if (ifn) { 1077 if (call.variable instanceof Call) { 1078 call.variable = ifn; 1079 } else { 1080 call.variable.base = ifn; 1081 } 1082 } 1083 ifn = unfoldSoak(o, call, 'variable'); 1084 } 1085 return ifn; 1086 }; 1087 1088 Call.prototype.compileNode = function(o) { 1089 var arg, argIndex, compiledArgs, compiledArray, fragments, j, len1, preface, ref3, ref4; 1090 if ((ref3 = this.variable) != null) { 1091 ref3.front = this.front; 1092 } 1093 compiledArray = Splat.compileSplattedArray(o, this.args, true); 1094 if (compiledArray.length) { 1095 return this.compileSplat(o, compiledArray); 1096 } 1097 compiledArgs = []; 1098 ref4 = this.args; 1099 for (argIndex = j = 0, len1 = ref4.length; j < len1; argIndex = ++j) { 1100 arg = ref4[argIndex]; 1101 if (argIndex) { 1102 compiledArgs.push(this.makeCode(", ")); 1103 } 1104 compiledArgs.push.apply(compiledArgs, arg.compileToFragments(o, LEVEL_LIST)); 1105 } 1106 fragments = []; 1107 if (this instanceof SuperCall) { 1108 preface = this.superReference(o) + (".call(" + (this.superThis(o))); 1109 if (compiledArgs.length) { 1110 preface += ", "; 1111 } 1112 fragments.push(this.makeCode(preface)); 1113 } else { 1114 if (this.isNew) { 1115 fragments.push(this.makeCode('new ')); 1116 } 1117 fragments.push.apply(fragments, this.variable.compileToFragments(o, LEVEL_ACCESS)); 1118 fragments.push(this.makeCode("(")); 1119 } 1120 fragments.push.apply(fragments, compiledArgs); 1121 fragments.push(this.makeCode(")")); 1122 return fragments; 1123 }; 1124 1125 Call.prototype.compileSplat = function(o, splatArgs) { 1126 var answer, base, fun, idt, name, ref; 1127 if (this instanceof SuperCall) { 1128 return [].concat(this.makeCode((this.superReference(o)) + ".apply(" + (this.superThis(o)) + ", "), splatArgs, this.makeCode(")")); 1129 } 1130 if (this.isNew) { 1131 idt = this.tab + TAB; 1132 return [].concat(this.makeCode("(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return Object(result) === result ? result : child;\n" + this.tab + "})("), this.variable.compileToFragments(o, LEVEL_LIST), this.makeCode(", "), splatArgs, this.makeCode(", function(){})")); 1133 } 1134 answer = []; 1135 base = new Value(this.variable); 1136 if ((name = base.properties.pop()) && base.isComplex()) { 1137 ref = o.scope.freeVariable('ref'); 1138 answer = answer.concat(this.makeCode("(" + ref + " = "), base.compileToFragments(o, LEVEL_LIST), this.makeCode(")"), name.compileToFragments(o)); 1139 } else { 1140 fun = base.compileToFragments(o, LEVEL_ACCESS); 1141 if (SIMPLENUM.test(fragmentsToText(fun))) { 1142 fun = this.wrapInBraces(fun); 1143 } 1144 if (name) { 1145 ref = fragmentsToText(fun); 1146 fun.push.apply(fun, name.compileToFragments(o)); 1147 } else { 1148 ref = 'null'; 1149 } 1150 answer = answer.concat(fun); 1151 } 1152 return answer = answer.concat(this.makeCode(".apply(" + ref + ", "), splatArgs, this.makeCode(")")); 1153 }; 1154 1155 return Call; 1156 1157 })(Base); 1158 1159 exports.SuperCall = SuperCall = (function(superClass1) { 1160 extend1(SuperCall, superClass1); 1161 1162 function SuperCall(args) { 1163 SuperCall.__super__.constructor.call(this, null, args != null ? args : [new Splat(new IdentifierLiteral('arguments'))]); 1164 this.isBare = args != null; 1165 } 1166 1167 SuperCall.prototype.superReference = function(o) { 1168 var accesses, base, bref, klass, method, name, nref, variable; 1169 method = o.scope.namedMethod(); 1170 if (method != null ? method.klass : void 0) { 1171 klass = method.klass, name = method.name, variable = method.variable; 1172 if (klass.isComplex()) { 1173 bref = new IdentifierLiteral(o.scope.parent.freeVariable('base')); 1174 base = new Value(new Parens(new Assign(bref, klass))); 1175 variable.base = base; 1176 variable.properties.splice(0, klass.properties.length); 1177 } 1178 if (name.isComplex() || (name instanceof Index && name.index.isAssignable())) { 1179 nref = new IdentifierLiteral(o.scope.parent.freeVariable('name')); 1180 name = new Index(new Assign(nref, name.index)); 1181 variable.properties.pop(); 1182 variable.properties.push(name); 1183 } 1184 accesses = [new Access(new PropertyName('__super__'))]; 1185 if (method["static"]) { 1186 accesses.push(new Access(new PropertyName('constructor'))); 1187 } 1188 accesses.push(nref != null ? new Index(nref) : name); 1189 return (new Value(bref != null ? bref : klass, accesses)).compile(o); 1190 } else if (method != null ? method.ctor : void 0) { 1191 return method.name + ".__super__.constructor"; 1192 } else { 1193 return this.error('cannot call super outside of an instance method.'); 1194 } 1195 }; 1196 1197 SuperCall.prototype.superThis = function(o) { 1198 var method; 1199 method = o.scope.method; 1200 return (method && !method.klass && method.context) || "this"; 1201 }; 1202 1203 return SuperCall; 1204 1205 })(Call); 1206 1207 exports.RegexWithInterpolations = RegexWithInterpolations = (function(superClass1) { 1208 extend1(RegexWithInterpolations, superClass1); 1209 1210 function RegexWithInterpolations(args) { 1211 if (args == null) { 1212 args = []; 1213 } 1214 RegexWithInterpolations.__super__.constructor.call(this, new Value(new IdentifierLiteral('RegExp')), args, false); 1215 } 1216 1217 return RegexWithInterpolations; 1218 1219 })(Call); 1220 1221 exports.Extends = Extends = (function(superClass1) { 1222 extend1(Extends, superClass1); 1223 1224 function Extends(child1, parent1) { 1225 this.child = child1; 1226 this.parent = parent1; 1227 } 1228 1229 Extends.prototype.children = ['child', 'parent']; 1230 1231 Extends.prototype.compileToFragments = function(o) { 1232 return new Call(new Value(new Literal(utility('extend', o))), [this.child, this.parent]).compileToFragments(o); 1233 }; 1234 1235 return Extends; 1236 1237 })(Base); 1238 1239 exports.Access = Access = (function(superClass1) { 1240 extend1(Access, superClass1); 1241 1242 function Access(name1, tag) { 1243 this.name = name1; 1244 this.name.asKey = true; 1245 this.soak = tag === 'soak'; 1246 } 1247 1248 Access.prototype.children = ['name']; 1249 1250 Access.prototype.compileToFragments = function(o) { 1251 var name, node, ref3; 1252 name = this.name.compileToFragments(o); 1253 node = this.name.unwrap(); 1254 if (node instanceof PropertyName) { 1255 if (ref3 = node.value, indexOf.call(JS_FORBIDDEN, ref3) >= 0) { 1256 return [this.makeCode('["')].concat(slice.call(name), [this.makeCode('"]')]); 1257 } else { 1258 return [this.makeCode('.')].concat(slice.call(name)); 1259 } 1260 } else { 1261 return [this.makeCode('[')].concat(slice.call(name), [this.makeCode(']')]); 1262 } 1263 }; 1264 1265 Access.prototype.isComplex = NO; 1266 1267 return Access; 1268 1269 })(Base); 1270 1271 exports.Index = Index = (function(superClass1) { 1272 extend1(Index, superClass1); 1273 1274 function Index(index1) { 1275 this.index = index1; 1276 } 1277 1278 Index.prototype.children = ['index']; 1279 1280 Index.prototype.compileToFragments = function(o) { 1281 return [].concat(this.makeCode("["), this.index.compileToFragments(o, LEVEL_PAREN), this.makeCode("]")); 1282 }; 1283 1284 Index.prototype.isComplex = function() { 1285 return this.index.isComplex(); 1286 }; 1287 1288 return Index; 1289 1290 })(Base); 1291 1292 exports.Range = Range = (function(superClass1) { 1293 extend1(Range, superClass1); 1294 1295 Range.prototype.children = ['from', 'to']; 1296 1297 function Range(from1, to1, tag) { 1298 this.from = from1; 1299 this.to = to1; 1300 this.exclusive = tag === 'exclusive'; 1301 this.equals = this.exclusive ? '' : '='; 1302 } 1303 1304 Range.prototype.compileVariables = function(o) { 1305 var isComplex, ref3, ref4, ref5, step; 1306 o = merge(o, { 1307 top: true 1308 }); 1309 isComplex = del(o, 'isComplex'); 1310 ref3 = this.cacheToCodeFragments(this.from.cache(o, LEVEL_LIST, isComplex)), this.fromC = ref3[0], this.fromVar = ref3[1]; 1311 ref4 = this.cacheToCodeFragments(this.to.cache(o, LEVEL_LIST, isComplex)), this.toC = ref4[0], this.toVar = ref4[1]; 1312 if (step = del(o, 'step')) { 1313 ref5 = this.cacheToCodeFragments(step.cache(o, LEVEL_LIST, isComplex)), this.step = ref5[0], this.stepVar = ref5[1]; 1314 } 1315 this.fromNum = this.from.isNumber() ? Number(this.fromVar) : null; 1316 this.toNum = this.to.isNumber() ? Number(this.toVar) : null; 1317 return this.stepNum = (step != null ? step.isNumber() : void 0) ? Number(this.stepVar) : null; 1318 }; 1319 1320 Range.prototype.compileNode = function(o) { 1321 var cond, condPart, from, gt, idx, idxName, known, lt, namedIndex, ref3, ref4, stepPart, to, varPart; 1322 if (!this.fromVar) { 1323 this.compileVariables(o); 1324 } 1325 if (!o.index) { 1326 return this.compileArray(o); 1327 } 1328 known = (this.fromNum != null) && (this.toNum != null); 1329 idx = del(o, 'index'); 1330 idxName = del(o, 'name'); 1331 namedIndex = idxName && idxName !== idx; 1332 varPart = idx + " = " + this.fromC; 1333 if (this.toC !== this.toVar) { 1334 varPart += ", " + this.toC; 1335 } 1336 if (this.step !== this.stepVar) { 1337 varPart += ", " + this.step; 1338 } 1339 ref3 = [idx + " <" + this.equals, idx + " >" + this.equals], lt = ref3[0], gt = ref3[1]; 1340 condPart = this.stepNum != null ? this.stepNum > 0 ? lt + " " + this.toVar : gt + " " + this.toVar : known ? ((ref4 = [this.fromNum, this.toNum], from = ref4[0], to = ref4[1], ref4), from <= to ? lt + " " + to : gt + " " + to) : (cond = this.stepVar ? this.stepVar + " > 0" : this.fromVar + " <= " + this.toVar, cond + " ? " + lt + " " + this.toVar + " : " + gt + " " + this.toVar); 1341 stepPart = this.stepVar ? idx + " += " + this.stepVar : known ? namedIndex ? from <= to ? "++" + idx : "--" + idx : from <= to ? idx + "++" : idx + "--" : namedIndex ? cond + " ? ++" + idx + " : --" + idx : cond + " ? " + idx + "++ : " + idx + "--"; 1342 if (namedIndex) { 1343 varPart = idxName + " = " + varPart; 1344 } 1345 if (namedIndex) { 1346 stepPart = idxName + " = " + stepPart; 1347 } 1348 return [this.makeCode(varPart + "; " + condPart + "; " + stepPart)]; 1349 }; 1350 1351 Range.prototype.compileArray = function(o) { 1352 var args, body, cond, hasArgs, i, idt, j, known, post, pre, range, ref3, ref4, result, results, vars; 1353 known = (this.fromNum != null) && (this.toNum != null); 1354 if (known && Math.abs(this.fromNum - this.toNum) <= 20) { 1355 range = (function() { 1356 results = []; 1357 for (var j = ref3 = this.fromNum, ref4 = this.toNum; ref3 <= ref4 ? j <= ref4 : j >= ref4; ref3 <= ref4 ? j++ : j--){ results.push(j); } 1358 return results; 1359 }).apply(this); 1360 if (this.exclusive) { 1361 range.pop(); 1362 } 1363 return [this.makeCode("[" + (range.join(', ')) + "]")]; 1364 } 1365 idt = this.tab + TAB; 1366 i = o.scope.freeVariable('i', { 1367 single: true 1368 }); 1369 result = o.scope.freeVariable('results'); 1370 pre = "\n" + idt + result + " = [];"; 1371 if (known) { 1372 o.index = i; 1373 body = fragmentsToText(this.compileNode(o)); 1374 } else { 1375 vars = (i + " = " + this.fromC) + (this.toC !== this.toVar ? ", " + this.toC : ''); 1376 cond = this.fromVar + " <= " + this.toVar; 1377 body = "var " + vars + "; " + cond + " ? " + i + " <" + this.equals + " " + this.toVar + " : " + i + " >" + this.equals + " " + this.toVar + "; " + cond + " ? " + i + "++ : " + i + "--"; 1378 } 1379 post = "{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + o.indent; 1380 hasArgs = function(node) { 1381 return node != null ? node.contains(isLiteralArguments) : void 0; 1382 }; 1383 if (hasArgs(this.from) || hasArgs(this.to)) { 1384 args = ', arguments'; 1385 } 1386 return [this.makeCode("(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).apply(this" + (args != null ? args : '') + ")")]; 1387 }; 1388 1389 return Range; 1390 1391 })(Base); 1392 1393 exports.Slice = Slice = (function(superClass1) { 1394 extend1(Slice, superClass1); 1395 1396 Slice.prototype.children = ['range']; 1397 1398 function Slice(range1) { 1399 this.range = range1; 1400 Slice.__super__.constructor.call(this); 1401 } 1402 1403 Slice.prototype.compileNode = function(o) { 1404 var compiled, compiledText, from, fromCompiled, ref3, to, toStr; 1405 ref3 = this.range, to = ref3.to, from = ref3.from; 1406 fromCompiled = from && from.compileToFragments(o, LEVEL_PAREN) || [this.makeCode('0')]; 1407 if (to) { 1408 compiled = to.compileToFragments(o, LEVEL_PAREN); 1409 compiledText = fragmentsToText(compiled); 1410 if (!(!this.range.exclusive && +compiledText === -1)) { 1411 toStr = ', ' + (this.range.exclusive ? compiledText : to.isNumber() ? "" + (+compiledText + 1) : (compiled = to.compileToFragments(o, LEVEL_ACCESS), "+" + (fragmentsToText(compiled)) + " + 1 || 9e9")); 1412 } 1413 } 1414 return [this.makeCode(".slice(" + (fragmentsToText(fromCompiled)) + (toStr || '') + ")")]; 1415 }; 1416 1417 return Slice; 1418 1419 })(Base); 1420 1421 exports.Obj = Obj = (function(superClass1) { 1422 extend1(Obj, superClass1); 1423 1424 function Obj(props, generated) { 1425 this.generated = generated != null ? generated : false; 1426 this.objects = this.properties = props || []; 1427 } 1428 1429 Obj.prototype.children = ['properties']; 1430 1431 Obj.prototype.compileNode = function(o) { 1432 var answer, dynamicIndex, hasDynamic, i, idt, indent, j, join, k, key, l, lastNoncom, len1, len2, len3, node, oref, prop, props, ref3, value; 1433 props = this.properties; 1434 if (this.generated) { 1435 for (j = 0, len1 = props.length; j < len1; j++) { 1436 node = props[j]; 1437 if (node instanceof Value) { 1438 node.error('cannot have an implicit value in an implicit object'); 1439 } 1440 } 1441 } 1442 for (dynamicIndex = k = 0, len2 = props.length; k < len2; dynamicIndex = ++k) { 1443 prop = props[dynamicIndex]; 1444 if ((prop.variable || prop).base instanceof Parens) { 1445 break; 1446 } 1447 } 1448 hasDynamic = dynamicIndex < props.length; 1449 idt = o.indent += TAB; 1450 lastNoncom = this.lastNonComment(this.properties); 1451 answer = []; 1452 if (hasDynamic) { 1453 oref = o.scope.freeVariable('obj'); 1454 answer.push(this.makeCode("(\n" + idt + oref + " = ")); 1455 } 1456 answer.push(this.makeCode("{" + (props.length === 0 || dynamicIndex === 0 ? '}' : '\n'))); 1457 for (i = l = 0, len3 = props.length; l < len3; i = ++l) { 1458 prop = props[i]; 1459 if (i === dynamicIndex) { 1460 if (i !== 0) { 1461 answer.push(this.makeCode("\n" + idt + "}")); 1462 } 1463 answer.push(this.makeCode(',\n')); 1464 } 1465 join = i === props.length - 1 || i === dynamicIndex - 1 ? '' : prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n'; 1466 indent = prop instanceof Comment ? '' : idt; 1467 if (hasDynamic && i < dynamicIndex) { 1468 indent += TAB; 1469 } 1470 if (prop instanceof Assign) { 1471 if (prop.context !== 'object') { 1472 prop.operatorToken.error("unexpected " + prop.operatorToken.value); 1473 } 1474 if (prop.variable instanceof Value && prop.variable.hasProperties()) { 1475 prop.variable.error('invalid object key'); 1476 } 1477 } 1478 if (prop instanceof Value && prop["this"]) { 1479 prop = new Assign(prop.properties[0].name, prop, 'object'); 1480 } 1481 if (!(prop instanceof Comment)) { 1482 if (i < dynamicIndex) { 1483 if (!(prop instanceof Assign)) { 1484 prop = new Assign(prop, prop, 'object'); 1485 } 1486 (prop.variable.base || prop.variable).asKey = true; 1487 } else { 1488 if (prop instanceof Assign) { 1489 key = prop.variable; 1490 value = prop.value; 1491 } else { 1492 ref3 = prop.base.cache(o), key = ref3[0], value = ref3[1]; 1493 } 1494 prop = new Assign(new Value(new IdentifierLiteral(oref), [new Access(key)]), value); 1495 } 1496 } 1497 if (indent) { 1498 answer.push(this.makeCode(indent)); 1499 } 1500 answer.push.apply(answer, prop.compileToFragments(o, LEVEL_TOP)); 1501 if (join) { 1502 answer.push(this.makeCode(join)); 1503 } 1504 } 1505 if (hasDynamic) { 1506 answer.push(this.makeCode(",\n" + idt + oref + "\n" + this.tab + ")")); 1507 } else { 1508 if (props.length !== 0) { 1509 answer.push(this.makeCode("\n" + this.tab + "}")); 1510 } 1511 } 1512 if (this.front && !hasDynamic) { 1513 return this.wrapInBraces(answer); 1514 } else { 1515 return answer; 1516 } 1517 }; 1518 1519 Obj.prototype.assigns = function(name) { 1520 var j, len1, prop, ref3; 1521 ref3 = this.properties; 1522 for (j = 0, len1 = ref3.length; j < len1; j++) { 1523 prop = ref3[j]; 1524 if (prop.assigns(name)) { 1525 return true; 1526 } 1527 } 1528 return false; 1529 }; 1530 1531 return Obj; 1532 1533 })(Base); 1534 1535 exports.Arr = Arr = (function(superClass1) { 1536 extend1(Arr, superClass1); 1537 1538 function Arr(objs) { 1539 this.objects = objs || []; 1540 } 1541 1542 Arr.prototype.children = ['objects']; 1543 1544 Arr.prototype.compileNode = function(o) { 1545 var answer, compiledObjs, fragments, index, j, len1, obj; 1546 if (!this.objects.length) { 1547 return [this.makeCode('[]')]; 1548 } 1549 o.indent += TAB; 1550 answer = Splat.compileSplattedArray(o, this.objects); 1551 if (answer.length) { 1552 return answer; 1553 } 1554 answer = []; 1555 compiledObjs = (function() { 1556 var j, len1, ref3, results; 1557 ref3 = this.objects; 1558 results = []; 1559 for (j = 0, len1 = ref3.length; j < len1; j++) { 1560 obj = ref3[j]; 1561 results.push(obj.compileToFragments(o, LEVEL_LIST)); 1562 } 1563 return results; 1564 }).call(this); 1565 for (index = j = 0, len1 = compiledObjs.length; j < len1; index = ++j) { 1566 fragments = compiledObjs[index]; 1567 if (index) { 1568 answer.push(this.makeCode(", ")); 1569 } 1570 answer.push.apply(answer, fragments); 1571 } 1572 if (fragmentsToText(answer).indexOf('\n') >= 0) { 1573 answer.unshift(this.makeCode("[\n" + o.indent)); 1574 answer.push(this.makeCode("\n" + this.tab + "]")); 1575 } else { 1576 answer.unshift(this.makeCode("[")); 1577 …
Large files files are truncated, but you can click here to view the full file