UglifyJS/lib/ast.js

1063 lines
35 KiB
JavaScript
Raw Normal View History

2012-08-22 18:28:59 +00:00
/***********************************************************************
A JavaScript tokenizer / parser / beautifier / compressor.
https://github.com/mishoo/UglifyJS2
2014-04-15 12:57:14 +00:00
Edited for parsing ColaScript.
2012-08-22 18:28:59 +00:00
-------------------------------- (C) ---------------------------------
Author: Mihai Bazon
<mihai.bazon@gmail.com>
http://mihai.bazon.net/blog
Distributed under the BSD license:
2012-08-27 08:01:27 +00:00
Copyright 2012 (c) Mihai Bazon <mihai.bazon@gmail.com>
2014-04-15 12:57:14 +00:00
Copyright 2014 (c) TrigenSoftware <danon0404@gmail.com>
2012-08-22 18:28:59 +00:00
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AS IS AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
***********************************************************************/
2012-10-02 09:45:31 +00:00
"use strict";
2014-04-22 13:33:43 +00:00
!this.Cola && (this.Cola = {});
2012-10-02 09:45:31 +00:00
2014-04-16 16:43:40 +00:00
Cola.DEFNODE = function (type, props, methods, base) {
if (arguments.length < 4) base = Cola.AST_Node;
2012-05-27 11:09:01 +00:00
if (!props) props = [];
else props = props.split(/\s+/);
var self_props = props;
2012-05-27 11:09:01 +00:00
if (base && base.PROPS)
props = props.concat(base.PROPS);
var code = "return function AST_" + type + "(props){ if (props) { ";
for (var i = props.length; --i >= 0;) {
code += "this." + props[i] + " = props." + props[i] + ";";
}
var proto = base && new base;
if (proto && proto.initialize || (methods && methods.initialize))
code += "this.initialize();";
code += "}}";
2012-05-27 11:09:01 +00:00
var ctor = new Function(code)();
if (proto) {
ctor.prototype = proto;
ctor.BASE = base;
2012-05-27 11:09:01 +00:00
}
if (base) base.SUBCLASSES.push(ctor);
2012-05-27 11:09:01 +00:00
ctor.prototype.CTOR = ctor;
ctor.PROPS = props || null;
ctor.SELF_PROPS = self_props;
ctor.SUBCLASSES = [];
2012-05-27 11:09:01 +00:00
if (type) {
ctor.prototype.TYPE = ctor.TYPE = type;
}
if (methods) for (i in methods) if (methods.hasOwnProperty(i)) {
if (/^\$/.test(i)) {
ctor[i.substr(1)] = methods[i];
} else {
ctor.prototype[i] = methods[i];
}
2012-05-27 11:09:01 +00:00
}
2012-08-16 15:11:04 +00:00
ctor.DEFMETHOD = function(name, method) {
this.prototype[name] = method;
};
2012-05-27 11:09:01 +00:00
return ctor;
};
2014-04-16 16:43:40 +00:00
Cola.AST_Token = Cola.DEFNODE("Token", "type value line col pos endpos nlb comments_before file", {
2014-04-19 18:04:11 +00:00
clone: function() {
return new this.CTOR(this);
}
2012-05-27 11:09:01 +00:00
}, null);
2014-04-16 16:43:40 +00:00
Cola.AST_Node = Cola.DEFNODE("Node", "start end", {
clone: function() {
return new this.CTOR(this);
},
2012-08-19 19:46:00 +00:00
$documentation: "Base class of all AST nodes",
$propdoc: {
start: "[AST_Token] The first token of this node",
end: "[AST_Token] The last token of this node"
},
_walk: function(visitor) {
return visitor._visit(this);
},
walk: function(visitor) {
return this._walk(visitor); // not sure the indirection will be any help
}
2012-05-27 11:09:01 +00:00
}, null);
Cola.AST_Noop = Cola.DEFNODE("Noop", null, null, Cola.AST_Node);
2014-04-16 16:43:40 +00:00
Cola.AST_Node.warn_function = null;
Cola.AST_Node.warn = function(txt, props) {
if (Cola.AST_Node.warn_function)
Cola.AST_Node.warn_function(Cola.string_template(txt, props));
2012-08-20 14:19:30 +00:00
};
2012-09-07 15:55:13 +00:00
/* -----[ statements ]----- */
2012-08-16 15:11:04 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Statement = Cola.DEFNODE("Statement", null, {
$documentation: "Base class of all statements",
2012-05-27 11:09:01 +00:00
});
2014-04-16 16:43:40 +00:00
Cola.AST_Debugger = Cola.DEFNODE("Debugger", null, {
$documentation: "Represents a debugger statement",
2014-04-16 16:43:40 +00:00
}, Cola.AST_Statement);
2014-04-16 16:43:40 +00:00
Cola.AST_Directive = Cola.DEFNODE("Directive", "value scope", {
$documentation: "Represents a directive, like \"use strict\";",
$propdoc: {
value: "[string] The value of this directive as a plain string (it's not an AST_String!)",
scope: "[AST_Scope/S] The scope that this directive affects"
},
2014-04-16 16:43:40 +00:00
}, Cola.AST_Statement);
2014-04-16 16:43:40 +00:00
Cola.AST_SimpleStatement = Cola.DEFNODE("SimpleStatement", "body", {
$documentation: "A statement consisting of an expression, i.e. a = 1 + 2",
$propdoc: {
2014-04-16 16:43:40 +00:00
body: "[AST_Node] an expression node (should not be instanceof Cola.AST_Statement)"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.body._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Statement);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.walk_body = function (node, visitor) {
if (node.body instanceof Cola.AST_Statement) {
node.body._walk(visitor);
}
else node.body.forEach(function(stat){
stat._walk(visitor);
2012-09-07 15:55:13 +00:00
});
};
2014-04-16 16:43:40 +00:00
Cola.AST_Block = Cola.DEFNODE("Block", "body", {
$documentation: "A body of statements (usually bracketed)",
$propdoc: {
body: "[AST_Statement*] an array of statements"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
2014-04-16 16:43:40 +00:00
Cola.walk_body(this, visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Statement);
2014-04-16 16:43:40 +00:00
Cola.AST_BlockStatement = Cola.DEFNODE("BlockStatement", null, {
$documentation: "A block statement",
2014-04-16 16:43:40 +00:00
}, Cola.AST_Block);
2014-04-16 16:43:40 +00:00
Cola.AST_EmptyStatement = Cola.DEFNODE("EmptyStatement", null, {
$documentation: "The empty statement (empty block or simply a semicolon)",
_walk: function(visitor) {
return visitor._visit(this);
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Statement);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_StatementWithBody = Cola.DEFNODE("StatementWithBody", "body", {
$documentation: "Base class for all statements that contain one nested body: `For`, `ForIn`, `Do`, `While`, `With`",
$propdoc: {
body: "[AST_Statement] the body; this should always be present, even if it's an AST_EmptyStatement"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.body._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Statement);
2014-04-16 16:43:40 +00:00
Cola.AST_LabeledStatement = Cola.DEFNODE("LabeledStatement", "label", {
$documentation: "Statement with a label",
$propdoc: {
label: "[AST_Label] a label definition"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.label._walk(visitor);
this.body._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_StatementWithBody);
2014-04-16 16:43:40 +00:00
Cola.AST_IterationStatement = Cola.DEFNODE("IterationStatement", null, {
$documentation: "Internal class. All loops inherit from it."
2014-04-16 16:43:40 +00:00
}, Cola.AST_StatementWithBody);
2014-04-16 16:43:40 +00:00
Cola.AST_DWLoop = Cola.DEFNODE("DWLoop", "condition", {
$documentation: "Base class for do/while statements",
$propdoc: {
2014-04-16 16:43:40 +00:00
condition: "[AST_Node] the loop condition. Should not be instanceof Cola.AST_Statement"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.condition._walk(visitor);
this.body._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_IterationStatement);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Do = Cola.DEFNODE("Do", null, {
$documentation: "A `do` statement",
2014-04-16 16:43:40 +00:00
}, Cola.AST_DWLoop);
2014-04-16 16:43:40 +00:00
Cola.AST_While = Cola.DEFNODE("While", null, {
$documentation: "A `while` statement",
2014-04-16 16:43:40 +00:00
}, Cola.AST_DWLoop);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_For = Cola.DEFNODE("For", "init condition step", {
2012-08-19 19:46:00 +00:00
$documentation: "A `for` statement",
$propdoc: {
init: "[AST_Node?] the `for` initialization code, or null if empty",
condition: "[AST_Node?] the `for` termination clause, or null if empty",
step: "[AST_Node?] the `for` update clause, or null if empty"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
if (this.init) this.init._walk(visitor);
if (this.condition) this.condition._walk(visitor);
if (this.step) this.step._walk(visitor);
2012-08-20 14:19:30 +00:00
this.body._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_IterationStatement);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_ForIn = Cola.DEFNODE("ForIn", "init name object", {
2012-08-19 19:46:00 +00:00
$documentation: "A `for ... in` statement",
$propdoc: {
init: "[AST_Node] the `for/in` initialization code",
name: "[AST_SymbolRef?] the loop variable, only if `init` is AST_Var",
object: "[AST_Node] the object that we're looping through"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.init._walk(visitor);
this.object._walk(visitor);
2012-08-20 14:19:30 +00:00
this.body._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_IterationStatement);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_With = Cola.DEFNODE("With", "expression", {
2012-08-19 19:46:00 +00:00
$documentation: "A `with` statement",
$propdoc: {
expression: "[AST_Node] the `with` expression"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expression._walk(visitor);
this.body._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_StatementWithBody);
2012-05-27 11:09:01 +00:00
/* -----[ scope and functions ]----- */
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Scope = Cola.DEFNODE("Scope", "directives variables functions uses_with uses_eval parent_scope enclosed cname", {
$documentation: "Base class for all statements introducing a lexical scope",
$propdoc: {
directives: "[string*/S] an array of directives declared in this scope",
variables: "[Object/S] a map of name -> SymbolDef for all variables/functions defined in this scope",
functions: "[Object/S] like `variables`, but only lists function declarations",
uses_with: "[boolean/S] tells whether this scope uses the `with` statement",
uses_eval: "[boolean/S] tells whether this scope contains a direct call to the global `eval`",
parent_scope: "[AST_Scope?/S] link to the parent scope",
enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",
cname: "[integer/S] current index for mangling variables (used internally by the mangler)",
},
2014-04-16 16:43:40 +00:00
}, Cola.AST_Block);
2012-05-27 11:09:01 +00:00
2014-04-17 16:21:45 +00:00
Cola.AST_Toplevel = Cola.DEFNODE("Toplevel", "globals language", {
$documentation: "The toplevel scope",
$propdoc: {
globals: "[Object/S] a map of name -> SymbolDef for all undeclared names",
},
wrap_enclose: function(arg_parameter_pairs) {
var self = this;
var args = [];
var parameters = [];
arg_parameter_pairs.forEach(function(pair) {
var split = pair.split(":");
args.push(split[0]);
parameters.push(split[1]);
});
var wrapped_tl = "(function(" + parameters.join(",") + "){ '$ORIG'; })(" + args.join(",") + ")";
2014-04-16 16:43:40 +00:00
wrapped_tl = Cola.parse(wrapped_tl);
2014-04-17 16:21:45 +00:00
wrapped_tl = wrapped_tl.transform(new Cola.TreeTransformer(function before(node){
2014-04-16 16:43:40 +00:00
if (node instanceof Cola.AST_Directive && node.value == "$ORIG") {
return Cola.MAP.splice(self.body);
}
}));
return wrapped_tl;
},
wrap_commonjs: function(name, export_all) {
var self = this;
2012-11-24 08:02:08 +00:00
var to_export = [];
if (export_all) {
self.figure_out_scope();
self.walk(new TreeWalker(function(node){
2014-04-16 16:43:40 +00:00
if (node instanceof Cola.AST_SymbolDeclaration && node.definition().global) {
if (!Cola.find_if(function(n){ return n.name == node.name }, to_export))
to_export.push(node);
}
}));
}
var wrapped_tl = "(function(exports, global){ global['" + name + "'] = exports; '$ORIG'; '$EXPORTS'; }({}, (function(){return this}())))";
2014-04-16 16:43:40 +00:00
wrapped_tl = Cola.parse(wrapped_tl);
2014-04-17 16:21:45 +00:00
wrapped_tl = wrapped_tl.transform(new Cola.TreeTransformer(function before(node){
2014-04-16 16:43:40 +00:00
if (node instanceof Cola.AST_SimpleStatement) {
node = node.body;
2014-04-16 16:43:40 +00:00
if (node instanceof Cola.AST_String) switch (node.getValue()) {
case "$ORIG":
2014-04-16 16:43:40 +00:00
return Cola.MAP.splice(self.body);
case "$EXPORTS":
var body = [];
to_export.forEach(function(sym){
2014-04-16 16:43:40 +00:00
body.push(new Cola.AST_SimpleStatement({
body: new Cola.AST_Assign({
left: new Cola.AST_Sub({
expression: new Cola.AST_SymbolRef({ name: "exports" }),
property: new Cola.AST_String({ value: sym.name }),
}),
operator: "=",
2014-04-16 16:43:40 +00:00
right: new Cola.AST_SymbolRef(sym),
}),
}));
});
2014-04-16 16:43:40 +00:00
return Cola.MAP.splice(body);
}
}
}));
return wrapped_tl;
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Scope);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Lambda = Cola.DEFNODE("Lambda", "name argnames uses_arguments", {
2012-08-19 19:46:00 +00:00
$documentation: "Base class for functions",
$propdoc: {
name: "[AST_SymbolDeclaration?] the name of this function",
argnames: "[AST_SymbolFunarg*] array of function arguments",
uses_arguments: "[boolean/S] tells whether this function accesses the arguments array"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
if (this.name) this.name._walk(visitor);
this.argnames.forEach(function(arg){
arg._walk(visitor);
});
2014-04-16 16:43:40 +00:00
Cola.walk_body(this, visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Scope);
2012-05-27 14:25:31 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Accessor = Cola.DEFNODE("Accessor", null, {
$documentation: "A setter/getter function. The `name` property is always null."
2014-04-16 16:43:40 +00:00
}, Cola.AST_Lambda);
Cola.AST_Function = Cola.DEFNODE("Function", "type", {
2012-08-19 19:46:00 +00:00
$documentation: "A function expression"
2014-04-16 16:43:40 +00:00
}, Cola.AST_Lambda);
2012-05-27 14:25:31 +00:00
2014-04-19 18:04:11 +00:00
Cola.AST_Defun = Cola.DEFNODE("Defun", "type", {
2012-08-19 19:46:00 +00:00
$documentation: "A function definition"
2014-04-16 16:43:40 +00:00
}, Cola.AST_Lambda);
2012-05-27 11:09:01 +00:00
2014-04-27 20:30:25 +00:00
Cola.AST_Namedarg = Cola.DEFNODE("Namedarg", "start end name value", {
$documentation: "Named argument",
$propdoc: {
value: "Value of named argument"
}
}, Cola.AST_SymbolRef);
2014-05-16 12:27:51 +00:00
Cola.AST_ArgDef = Cola.DEFNODE("ArgDef", "start end name type argtype defval", {
2014-04-27 20:30:25 +00:00
$documentation: "A function argument expression",
$propdoc: {
type: "Data type",
argtype: "positional/named/splated"
}
}, Cola.AST_SymbolFunarg);
2012-05-27 11:09:01 +00:00
/* -----[ JUMPS ]----- */
2014-04-16 16:43:40 +00:00
Cola.AST_Jump = Cola.DEFNODE("Jump", null, {
2012-08-19 19:46:00 +00:00
$documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)"
2014-04-16 16:43:40 +00:00
}, Cola.AST_Statement);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Exit = Cola.DEFNODE("Exit", "value", {
2012-08-19 19:46:00 +00:00
$documentation: "Base class for “exits” (`return` and `throw`)",
$propdoc: {
value: "[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return"
},
_walk: function(visitor) {
return visitor._visit(this, this.value && function(){
this.value._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Jump);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Return = Cola.DEFNODE("Return", null, {
2012-08-19 19:46:00 +00:00
$documentation: "A `return` statement"
2014-04-16 16:43:40 +00:00
}, Cola.AST_Exit);
2012-05-27 14:25:31 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Throw = Cola.DEFNODE("Throw", null, {
2012-08-19 19:46:00 +00:00
$documentation: "A `throw` statement"
2014-04-16 16:43:40 +00:00
}, Cola.AST_Exit);
2012-05-27 14:25:31 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_LoopControl = Cola.DEFNODE("LoopControl", "label", {
2012-08-19 19:46:00 +00:00
$documentation: "Base class for loop control statements (`break` and `continue`)",
$propdoc: {
label: "[AST_LabelRef?] the label, or null if none",
},
_walk: function(visitor) {
return visitor._visit(this, this.label && function(){
this.label._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Jump);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Break = Cola.DEFNODE("Break", null, {
2012-08-19 19:46:00 +00:00
$documentation: "A `break` statement"
2014-04-16 16:43:40 +00:00
}, Cola.AST_LoopControl);
2012-05-27 14:25:31 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Continue = Cola.DEFNODE("Continue", null, {
2012-08-19 19:46:00 +00:00
$documentation: "A `continue` statement"
2014-04-16 16:43:40 +00:00
}, Cola.AST_LoopControl);
2012-05-27 14:25:31 +00:00
2012-05-27 11:09:01 +00:00
/* -----[ IF ]----- */
2014-04-16 16:43:40 +00:00
Cola.AST_If = Cola.DEFNODE("If", "condition alternative", {
2012-08-19 19:46:00 +00:00
$documentation: "A `if` statement",
$propdoc: {
condition: "[AST_Node] the `if` condition",
alternative: "[AST_Statement?] the `else` part, or null if not present"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.condition._walk(visitor);
2012-09-03 09:11:44 +00:00
this.body._walk(visitor);
if (this.alternative) this.alternative._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_StatementWithBody);
2012-05-27 11:09:01 +00:00
/* -----[ SWITCH ]----- */
2014-04-16 16:43:40 +00:00
Cola.AST_Switch = Cola.DEFNODE("Switch", "expression", {
2012-08-19 19:46:00 +00:00
$documentation: "A `switch` statement",
$propdoc: {
expression: "[AST_Node] the `switch` “discriminant”"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expression._walk(visitor);
2014-04-16 16:43:40 +00:00
Cola.walk_body(this, visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Block);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_SwitchBranch = Cola.DEFNODE("SwitchBranch", null, {
$documentation: "Base class for `switch` branches",
2014-04-16 16:43:40 +00:00
}, Cola.AST_Block);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Default = Cola.DEFNODE("Default", null, {
2012-08-19 19:46:00 +00:00
$documentation: "A `default` switch branch",
2014-04-16 16:43:40 +00:00
}, Cola.AST_SwitchBranch);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Case = Cola.DEFNODE("Case", "expression", {
2012-08-19 19:46:00 +00:00
$documentation: "A `case` switch branch",
$propdoc: {
expression: "[AST_Node] the `case` expression"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expression._walk(visitor);
2014-04-16 16:43:40 +00:00
Cola.walk_body(this, visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_SwitchBranch);
2012-05-27 11:09:01 +00:00
2014-05-19 09:58:17 +00:00
Cola.AST_When = Cola.DEFNODE("When", null, {
$documentation: "A `when` switch branch"
}, Cola.AST_Case);
2012-05-27 11:09:01 +00:00
/* -----[ EXCEPTIONS ]----- */
2014-04-16 16:43:40 +00:00
Cola.AST_Try = Cola.DEFNODE("Try", "bcatch bfinally", {
2012-08-19 19:46:00 +00:00
$documentation: "A `try` statement",
$propdoc: {
bcatch: "[AST_Catch?] the catch block, or null if not present",
bfinally: "[AST_Finally?] the finally block, or null if not present"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
2014-04-16 16:43:40 +00:00
Cola.walk_body(this, visitor);
if (this.bcatch) this.bcatch._walk(visitor);
if (this.bfinally) this.bfinally._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Block);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Catch = Cola.DEFNODE("Catch", "argname", {
2012-08-19 19:46:00 +00:00
$documentation: "A `catch` node; only makes sense as part of a `try` statement",
$propdoc: {
argname: "[AST_SymbolCatch] symbol for the exception"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.argname._walk(visitor);
2014-04-16 16:43:40 +00:00
Cola.walk_body(this, visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Block);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Finally = Cola.DEFNODE("Finally", null, {
$documentation: "A `finally` node; only makes sense as part of a `try` statement"
2014-04-16 16:43:40 +00:00
}, Cola.AST_Block);
2012-05-27 11:09:01 +00:00
/* -----[ VAR/CONST ]----- */
2014-04-16 16:43:40 +00:00
Cola.AST_Definitions = Cola.DEFNODE("Definitions", "definitions", {
2012-08-19 19:46:00 +00:00
$documentation: "Base class for `var` or `const` nodes (variable declarations/initializations)",
$propdoc: {
definitions: "[AST_VarDef*] array of variable definitions"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.definitions.forEach(function(def){
def._walk(visitor);
});
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Statement);
2012-05-27 11:09:01 +00:00
Cola.AST_Var = Cola.DEFNODE("Var", "type", {
2012-08-19 19:46:00 +00:00
$documentation: "A `var` statement"
2014-04-16 16:43:40 +00:00
}, Cola.AST_Definitions);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Const = Cola.DEFNODE("Const", null, {
2012-08-19 19:46:00 +00:00
$documentation: "A `const` statement"
2014-04-16 16:43:40 +00:00
}, Cola.AST_Definitions);
2012-05-27 11:09:01 +00:00
2014-05-16 12:27:51 +00:00
Cola.AST_VarDef = Cola.DEFNODE("VarDef", "name value type", {
2012-08-19 19:46:00 +00:00
$documentation: "A variable declaration; only appears in a AST_Definitions node",
$propdoc: {
name: "[AST_SymbolVar|AST_SymbolConst] name of the variable",
value: "[AST_Node?] initializer, or null of there's no initializer"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.name._walk(visitor);
if (this.value) this.value._walk(visitor);
});
}
2012-05-27 11:09:01 +00:00
});
/* -----[ OTHER ]----- */
2014-04-16 16:43:40 +00:00
Cola.AST_Call = Cola.DEFNODE("Call", "expression args", {
2012-08-19 19:46:00 +00:00
$documentation: "A function call expression",
$propdoc: {
expression: "[AST_Node] expression to invoke as function",
args: "[AST_Node*] array of arguments"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expression._walk(visitor);
this.args.forEach(function(arg){
arg._walk(visitor);
});
});
}
2012-05-27 11:09:01 +00:00
});
2014-04-16 16:43:40 +00:00
Cola.AST_New = Cola.DEFNODE("New", null, {
$documentation: "An object instantiation. Derives from a function call since it has exactly the same properties"
2014-04-16 16:43:40 +00:00
}, Cola.AST_Call);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Seq = Cola.DEFNODE("Seq", "car cdr", {
2012-08-19 19:46:00 +00:00
$documentation: "A sequence expression (two comma-separated expressions)",
$propdoc: {
car: "[AST_Node] first element in sequence",
cdr: "[AST_Node] second element in sequence"
},
$cons: function(x, y) {
2014-04-16 16:43:40 +00:00
var seq = new Cola.AST_Seq(x);
seq.car = x;
seq.cdr = y;
return seq;
},
$from_array: function(array) {
if (array.length == 0) return null;
if (array.length == 1) return array[0].clone();
var list = null;
for (var i = array.length; --i >= 0;) {
2014-04-16 16:43:40 +00:00
list = Cola.AST_Seq.cons(array[i], list);
}
var p = list;
while (p) {
if (p.cdr && !p.cdr.cdr) {
p.cdr = p.cdr.car;
break;
}
p = p.cdr;
}
return list;
},
to_array: function() {
var p = this, a = [];
while (p) {
a.push(p.car);
2014-04-16 16:43:40 +00:00
if (p.cdr && !(p.cdr instanceof Cola.AST_Seq)) {
a.push(p.cdr);
break;
}
p = p.cdr;
}
return a;
},
add: function(node) {
var p = this;
while (p) {
2014-04-16 16:43:40 +00:00
if (!(p.cdr instanceof Cola.AST_Seq)) {
var cell = Cola.AST_Seq.cons(p.cdr, node);
return p.cdr = cell;
}
p = p.cdr;
}
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.car._walk(visitor);
if (this.cdr) this.cdr._walk(visitor);
});
}
2012-05-27 11:09:01 +00:00
});
2014-04-16 16:43:40 +00:00
Cola.AST_PropAccess = Cola.DEFNODE("PropAccess", "expression property", {
$documentation: "Base class for property access expressions, i.e. `a.foo` or `a[\"foo\"]`",
$propdoc: {
expression: "[AST_Node] the “container” expression",
property: "[AST_Node|string] the property to access. For AST_Dot this is always a plain string, while for AST_Sub it's an arbitrary AST_Node"
}
2012-05-27 11:09:01 +00:00
});
2014-04-16 16:43:40 +00:00
Cola.AST_Dot = Cola.DEFNODE("Dot", null, {
$documentation: "A dotted property access expression",
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expression._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_PropAccess);
2012-05-27 11:09:01 +00:00
Cola.AST_Cascade = Cola.DEFNODE("Cascade", "expression subexpressions", {
$documentation: "Base class for properties access expressions, i.e. `a..foo..bar`",
$propdoc: {
expression: "[AST_Node] the “container” expression",
subexpressions: "[AST_Node*] actions with properties"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expression._walk(visitor);
this.subexpressions.forEach(function(el){
el._walk(visitor);
});
});
}
});
2014-04-16 16:43:40 +00:00
Cola.AST_Sub = Cola.DEFNODE("Sub", null, {
$documentation: "Index-style property access, i.e. `a[\"foo\"]`",
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expression._walk(visitor);
this.property._walk(visitor);
});
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_PropAccess);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Unary = Cola.DEFNODE("Unary", "operator expression", {
$documentation: "Base class for unary expressions",
$propdoc: {
operator: "[string] the operator",
expression: "[AST_Node] expression that this unary operator applies to"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.expression._walk(visitor);
});
}
2012-05-27 11:09:01 +00:00
});
2014-04-16 16:43:40 +00:00
Cola.AST_UnaryPrefix = Cola.DEFNODE("UnaryPrefix", null, {
$documentation: "Unary prefix expression, i.e. `typeof i` or `++i`"
2014-04-16 16:43:40 +00:00
}, Cola.AST_Unary);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_UnaryPostfix = Cola.DEFNODE("UnaryPostfix", null, {
$documentation: "Unary postfix expression, i.e. `i++`"
2014-04-16 16:43:40 +00:00
}, Cola.AST_Unary);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Binary = Cola.DEFNODE("Binary", "left operator right", {
$documentation: "Binary expression, i.e. `a + b`",
$propdoc: {
left: "[AST_Node] left-hand side expression",
operator: "[string] the operator",
right: "[AST_Node] right-hand side expression"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.left._walk(visitor);
this.right._walk(visitor);
});
}
2012-05-27 11:09:01 +00:00
});
2014-04-16 16:43:40 +00:00
Cola.AST_Conditional = Cola.DEFNODE("Conditional", "condition consequent alternative", {
$documentation: "Conditional expression using the ternary operator, i.e. `a ? b : c`",
$propdoc: {
condition: "[AST_Node]",
consequent: "[AST_Node]",
alternative: "[AST_Node]"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.condition._walk(visitor);
this.consequent._walk(visitor);
this.alternative._walk(visitor);
});
}
2012-05-27 11:09:01 +00:00
});
2014-04-16 16:43:40 +00:00
Cola.AST_Assign = Cola.DEFNODE("Assign", null, {
$documentation: "An assignment expression — `a = b + 5`",
2014-04-16 16:43:40 +00:00
}, Cola.AST_Binary);
2012-05-27 11:09:01 +00:00
/* -----[ LITERALS ]----- */
2014-05-16 12:27:51 +00:00
Cola.AST_Array = Cola.DEFNODE("Array", "elements template vardef", {
$documentation: "An array literal",
$propdoc: {
elements: "[AST_Node*] array of elements"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.elements.forEach(function(el){
el._walk(visitor);
});
});
}
2012-05-27 11:09:01 +00:00
});
2014-05-16 12:27:51 +00:00
Cola.AST_ArrayTemplate = Cola.DEFNODE("ArrayTemplate", null, {
$documentation: "Array assignment template.",
}, Cola.AST_Array);
Cola.AST_ArrayRange = Cola.DEFNODE("ArrayRange", "from to triple", {
2014-04-22 13:33:43 +00:00
$documentation: "An array range.",
$propdoc: {
from: "[AST_Node] range from",
to: "[AST_Node] range to"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.from._walk(visitor);
this.to._walk(visitor);
});
}
});
2014-05-16 12:27:51 +00:00
Cola.AST_Object = Cola.DEFNODE("Object", "properties template vardef", {
$documentation: "An object literal",
$propdoc: {
properties: "[AST_ObjectProperty*] array of properties"
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.properties.forEach(function(prop){
prop._walk(visitor);
});
});
}
2012-05-27 11:09:01 +00:00
});
2014-05-16 12:27:51 +00:00
Cola.AST_ObjectTemplate = Cola.DEFNODE("ObjectTemplate", null, {
$documentation: "Object assignment template.",
}, Cola.AST_Object);
Cola.AST_ObjectProperty = Cola.DEFNODE("ObjectProperty", "key value type", {
$documentation: "Base class for literal object properties",
$propdoc: {
key: "[string] the property name converted to a string for ObjectKeyVal. For setters and getters this is an arbitrary AST_Node.",
value: "[AST_Node] property value. For setters and getters this is an AST_Function."
},
_walk: function(visitor) {
return visitor._visit(this, function(){
this.value._walk(visitor);
});
}
});
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_ObjectKeyVal = Cola.DEFNODE("ObjectKeyVal", null, {
$documentation: "A key: value object property",
2014-04-16 16:43:40 +00:00
}, Cola.AST_ObjectProperty);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_ObjectSetter = Cola.DEFNODE("ObjectSetter", null, {
$documentation: "An object setter property",
2014-04-16 16:43:40 +00:00
}, Cola.AST_ObjectProperty);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_ObjectGetter = Cola.DEFNODE("ObjectGetter", null, {
$documentation: "An object getter property",
2014-04-16 16:43:40 +00:00
}, Cola.AST_ObjectProperty);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Symbol = Cola.DEFNODE("Symbol", "scope name thedef", {
$propdoc: {
name: "[string] name of this symbol",
scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)",
thedef: "[SymbolDef/S] the definition of this symbol"
},
$documentation: "Base class for all symbols",
2012-05-27 14:25:31 +00:00
});
2014-04-16 16:43:40 +00:00
Cola.AST_SymbolAccessor = Cola.DEFNODE("SymbolAccessor", null, {
$documentation: "The name of a property accessor (setter/getter function)"
2014-04-16 16:43:40 +00:00
}, Cola.AST_Symbol);
2014-04-16 16:43:40 +00:00
Cola.AST_SymbolDeclaration = Cola.DEFNODE("SymbolDeclaration", "init", {
$documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)",
$propdoc: {
init: "[AST_Node*/S] array of initializers for this declaration."
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Symbol);
2012-05-27 14:25:31 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_SymbolVar = Cola.DEFNODE("SymbolVar", null, {
$documentation: "Symbol defining a variable",
2014-04-16 16:43:40 +00:00
}, Cola.AST_SymbolDeclaration);
2014-04-16 16:43:40 +00:00
Cola.AST_SymbolConst = Cola.DEFNODE("SymbolConst", null, {
$documentation: "A constant declaration"
2014-04-16 16:43:40 +00:00
}, Cola.AST_SymbolDeclaration);
2012-05-27 14:25:31 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_SymbolFunarg = Cola.DEFNODE("SymbolFunarg", null, {
$documentation: "Symbol naming a function argument",
2014-04-16 16:43:40 +00:00
}, Cola.AST_SymbolVar);
2014-04-16 16:43:40 +00:00
Cola.AST_SymbolDefun = Cola.DEFNODE("SymbolDefun", null, {
$documentation: "Symbol defining a function",
2014-04-16 16:43:40 +00:00
}, Cola.AST_SymbolDeclaration);
2014-04-16 16:43:40 +00:00
Cola.AST_SymbolLambda = Cola.DEFNODE("SymbolLambda", null, {
$documentation: "Symbol naming a function expression",
2014-04-16 16:43:40 +00:00
}, Cola.AST_SymbolDeclaration);
2014-04-16 16:43:40 +00:00
Cola.AST_SymbolCatch = Cola.DEFNODE("SymbolCatch", null, {
$documentation: "Symbol naming the exception in catch",
2014-04-16 16:43:40 +00:00
}, Cola.AST_SymbolDeclaration);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Label = Cola.DEFNODE("Label", "references", {
$documentation: "Symbol naming a label (declaration)",
$propdoc: {
references: "[AST_LoopControl*] a list of nodes referring to this label"
},
initialize: function() {
this.references = [];
this.thedef = this;
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Symbol);
2014-04-16 16:43:40 +00:00
Cola.AST_SymbolRef = Cola.DEFNODE("SymbolRef", null, {
$documentation: "Reference to some symbol (not definition/declaration)",
2014-04-16 16:43:40 +00:00
}, Cola.AST_Symbol);
2012-05-27 14:25:31 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_LabelRef = Cola.DEFNODE("LabelRef", null, {
$documentation: "Reference to a label symbol",
2014-04-16 16:43:40 +00:00
}, Cola.AST_Symbol);
2012-05-27 14:25:31 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_This = Cola.DEFNODE("This", null, {
$documentation: "The `this` symbol",
2014-04-16 16:43:40 +00:00
}, Cola.AST_Symbol);
2014-04-16 16:43:40 +00:00
Cola.AST_Constant = Cola.DEFNODE("Constant", null, {
$documentation: "Base class for all constants",
2012-05-27 14:25:31 +00:00
getValue: function() {
return this.value;
}
2012-05-27 11:09:01 +00:00
});
2014-04-16 16:43:40 +00:00
Cola.AST_String = Cola.DEFNODE("String", "value", {
$documentation: "A string literal",
$propdoc: {
value: "[string] the contents of this string"
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Constant);
2012-05-27 11:09:01 +00:00
2014-05-19 09:58:17 +00:00
Cola.AST_StringTemplate = Cola.DEFNODE("StringTemplate", "body", {
$documentation: "A string template",
$propdoc: {
body: "[AST_Statement*] the contents of this string template"
2014-05-19 09:58:17 +00:00
},
_walk: function(visitor) {
return visitor._visit(this, function(){
Cola.walk_body(this, visitor);
});
}
2014-05-19 09:58:17 +00:00
}, Cola.AST_Statement);
2014-04-16 16:43:40 +00:00
Cola.AST_Number = Cola.DEFNODE("Number", "value", {
$documentation: "A number literal",
$propdoc: {
value: "[number] the numeric value"
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Constant);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_RegExp = Cola.DEFNODE("RegExp", "value", {
$documentation: "A regexp literal",
$propdoc: {
value: "[RegExp] the actual regexp"
2012-05-27 14:25:31 +00:00
}
2014-04-16 16:43:40 +00:00
}, Cola.AST_Constant);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Atom = Cola.DEFNODE("Atom", null, {
$documentation: "Base class for atoms",
2014-04-16 16:43:40 +00:00
}, Cola.AST_Constant);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Null = Cola.DEFNODE("Null", null, {
$documentation: "The `null` atom",
2012-08-15 10:32:37 +00:00
value: null
2014-04-16 16:43:40 +00:00
}, Cola.AST_Atom);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_NaN = Cola.DEFNODE("NaN", null, {
2012-09-18 07:53:46 +00:00
$documentation: "The impossible value",
value: 0/0
2014-04-16 16:43:40 +00:00
}, Cola.AST_Atom);
2012-09-18 07:53:46 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Undefined = Cola.DEFNODE("Undefined", null, {
$documentation: "The `undefined` value",
2012-08-15 10:32:37 +00:00
value: (function(){}())
2014-04-16 16:43:40 +00:00
}, Cola.AST_Atom);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Hole = Cola.DEFNODE("Hole", null, {
$documentation: "A hole in an array",
value: (function(){}())
2014-04-16 16:43:40 +00:00
}, Cola.AST_Atom);
2014-04-16 16:43:40 +00:00
Cola.AST_Infinity = Cola.DEFNODE("Infinity", null, {
2012-10-09 15:35:53 +00:00
$documentation: "The `Infinity` value",
value: 1/0
2014-04-16 16:43:40 +00:00
}, Cola.AST_Atom);
2012-10-09 15:35:53 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_Boolean = Cola.DEFNODE("Boolean", null, {
$documentation: "Base class for booleans",
2014-04-16 16:43:40 +00:00
}, Cola.AST_Atom);
2014-04-16 16:43:40 +00:00
Cola.AST_False = Cola.DEFNODE("False", null, {
$documentation: "The `false` atom",
2012-08-15 10:32:37 +00:00
value: false
2014-04-16 16:43:40 +00:00
}, Cola.AST_Boolean);
2012-05-27 11:09:01 +00:00
2014-04-16 16:43:40 +00:00
Cola.AST_True = Cola.DEFNODE("True", null, {
$documentation: "The `true` atom",
2012-08-15 10:32:37 +00:00
value: true
2014-04-16 16:43:40 +00:00
}, Cola.AST_Boolean);
/* -----[ TreeWalker ]----- */
2014-04-16 16:43:40 +00:00
Cola.TreeWalker = function (callback) {
this.visit = callback;
this.stack = [];
};
2014-04-16 16:43:40 +00:00
Cola.TreeWalker.prototype = {
_visit: function(node, descend) {
this.stack.push(node);
2012-09-28 08:12:47 +00:00
var ret = this.visit(node, descend ? function(){
descend.call(node);
2014-04-16 16:43:40 +00:00
} : Cola.noop);
if (!ret && descend) {
descend.call(node);
}
this.stack.pop();
return ret;
},
parent: function(n) {
return this.stack[this.stack.length - 2 - (n || 0)];
2012-09-26 09:16:16 +00:00
},
push: function (node) {
this.stack.push(node);
},
pop: function() {
return this.stack.pop();
},
self: function() {
return this.stack[this.stack.length - 1];
},
find_parent: function(type) {
var stack = this.stack;
for (var i = stack.length; --i >= 0;) {
var x = stack[i];
if (x instanceof type) return x;
}
},
has_directive: function(type) {
2014-04-16 16:43:40 +00:00
return this.find_parent(Cola.AST_Scope).has_directive(type);
},
2012-09-26 09:16:16 +00:00
in_boolean_context: function() {
var stack = this.stack;
var i = stack.length, self = stack[--i];
2012-09-26 09:16:16 +00:00
while (i > 0) {
var p = stack[--i];
2014-04-16 16:43:40 +00:00
if ((p instanceof Cola.AST_If && p.condition === self) ||
(p instanceof Cola.AST_Conditional && p.condition === self) ||
(p instanceof Cola.AST_DWLoop && p.condition === self) ||
(p instanceof Cola.AST_For && p.condition === self) ||
(p instanceof Cola.AST_UnaryPrefix && p.operator == "!" && p.expression === self))
2012-09-26 09:16:16 +00:00
{
return true;
}
2014-04-16 16:43:40 +00:00
if (!(p instanceof Cola.AST_Binary && (p.operator == "&&" || p.operator == "||")))
2012-09-26 09:16:16 +00:00
return false;
self = p;
2012-09-26 09:16:16 +00:00
}
},
loopcontrol_target: function(label) {
var stack = this.stack;
2013-09-06 06:52:56 +00:00
if (label) for (var i = stack.length; --i >= 0;) {
var x = stack[i];
2014-04-16 16:43:40 +00:00
if (x instanceof Cola.AST_LabeledStatement && x.label.name == label.name) {
2013-09-06 06:52:56 +00:00
return x.body;
}
2013-09-06 06:52:56 +00:00
} else for (var i = stack.length; --i >= 0;) {
var x = stack[i];
2014-04-16 16:43:40 +00:00
if (x instanceof Cola.AST_Switch || x instanceof Cola.AST_IterationStatement)
2013-09-06 06:52:56 +00:00
return x;
}
}
};