From 1df739cca22c5fad5239ea96e9f1153b4b041180 Mon Sep 17 00:00:00 2001 From: Bruno Jouhier Date: Mon, 2 Mar 2015 14:46:30 +0100 Subject: [PATCH] issue #254 - fixed bugs in esprima transform --- lib/callbacks/transform-esprima.js | 336 ++++++++++++++++++----------- test/common/stack-test._js | 324 ++++++++++++++++++++++------ test/common/transform-test.js | 286 ++++++++++++------------ 3 files changed, 619 insertions(+), 327 deletions(-) diff --git a/lib/callbacks/transform-esprima.js b/lib/callbacks/transform-esprima.js index 3587ba78..9c5a1c0e 100644 --- a/lib/callbacks/transform-esprima.js +++ b/lib/callbacks/transform-esprima.js @@ -65,15 +65,15 @@ if (typeof exports !== 'undefined') { */ function originalLine(options, line, col) { - if (!options.prevMap) return line; + if (!options.prevMap) return line || 0; // Work around a bug in CoffeeScript's source maps; column number 0 is faulty. if (col == null) col = 1000; var r = options.prevMap.originalPositionFor({ line: line, column: col }).line - return r == null ? line : r; + return r == null ? line || 0 : r; } function originalCol(options, line, col) { - if (!options.prevMap) return col; + if (!options.prevMap) return col || 0; return options.prevMap.originalPositionFor({ line: line, column: col }).column || 0; } @@ -82,6 +82,8 @@ if (typeof exports !== 'undefined') { _scope: ref && ref._scope, _async: ref && ref._async, type: type, + loc: ref && ref.loc, + range: ref && ref.range, }; if (Array.isArray(init)) throw new Error("INTERNAL ERROR: children in esprima!"); if (init) Object.keys(init).forEach(function(k) { @@ -233,7 +235,6 @@ if (typeof exports !== 'undefined') { else _root = _node(_root[0], Syntax.BlockStatement, { body: _root, }); - // if template is an expression rather than a full statement, go one more step down //if (isExpression) // _root = _root.expression; @@ -365,7 +366,7 @@ if (typeof exports !== 'undefined') { return node; } // void _ -> null - if (node.type === Syntax.UnaryExpression && node.operator === 'void' && _isMarker(node.left)) { + if (node.type === Syntax.UnaryExpression && node.operator === 'void' && _isMarker(node.argument)) { options.needsTransform = true; node.type = Syntax.Literal; node.value = null; @@ -539,7 +540,7 @@ if (typeof exports !== 'undefined') { // create new scope for the body var bodyScope = new Scope(node.body, options); node.body._scope = bodyScope; - bodyScope.name = node.name; + bodyScope.name = node.id && node.id.name; bodyScope.cbIndex = cbIndex; bodyScope.line = node.loc && node.loc.start.line; node.body = _propagate(node.body, _doIt); @@ -638,11 +639,13 @@ if (typeof exports !== 'undefined') { default: if (node.type === Syntax.SwitchCase) { // wrap consequent into a block, to reuse block logic in subsequent steps - node.consequent = [_node(node, Syntax.BlockStatement, { - body: node.consequent, - })]; + if (node.consequent.length !== 1 || node.consequent[0].type !== Syntax.BlockStatement) { + node.consequent = [_node(node, Syntax.BlockStatement, { + body: node.consequent, + })]; + } + if (node.test == null) parent.hasDefault = true; } - // todo: set breaks flag node = _propagate(node, _doIt); _setBreaks(node); parent._async |= node._async; @@ -760,7 +763,8 @@ if (typeof exports !== 'undefined') { var paramI = -1; var skip = 0; for (var i = 0; i < node.body.body.length; i++) { - var child = node.body.body[i]; + var child = node.body. + body[i]; if (i === 0 && child.type === Syntax.VariableDeclaration) { skip = 1; continue; @@ -770,11 +774,12 @@ if (typeof exports !== 'undefined') { var ident = child.test.left; if (ident.type !== Syntax.Identifier) return false; if (child.test.right.type !== Syntax.Literal || child.test.right.value !== null) return false; - if (!child.consequent || child.consequent.length !== 1) return false; - var assign = child.consequent[0]; + if (!child.consequent.body || child.consequent.body.length !== 1) return false; + var assign = child.consequent.body[0]; if (assign.type !== Syntax.ExpressionStatement) return false; assign = assign.expression; - if (assign.type !== Syntax.AssignmentExpression) if (assign.left.type !== Syntax.Identifier) return false; + if (assign.type !== Syntax.AssignmentExpression) return false; + if (assign.left.type !== Syntax.Identifier) return false; if (assign.left.name !== ident.name) return false; // we got a candidate - let us find the param while (++paramI < node.params.length) { @@ -808,9 +813,8 @@ if (typeof exports !== 'undefined') { callee: _node(node, Syntax.MemberExpression, { object: _node(node, Syntax.FunctionExpression, { params: originalParams, - body: remain, + body: _node(node, Syntax.BlockStatement, { body: remain }), parenthesized: true, - lineno: node.lineno, }), property: _identifier("apply"), }), @@ -850,20 +854,18 @@ if (typeof exports !== 'undefined') { node._breaks = node.consequent._breaks && node.alternate && node.alternate._breaks; break; case Syntax.SwitchStatement: + if (!node.hasDefault && node._async) { + node.cases.push(_node(node, Syntax.SwitchCase, { + consequent: [_node(node, Syntax.BlockStatement, { + body: [_node(node, Syntax.BreakStatement)], + })], + })); + } for (var i = 0; i < node.cases.length; i++) { var stmts = node.cases[i]; - if (node._async && stmts.consequent.length > 0 && !stmts._breaks) { - // narcissus has the strange idea of inserting an empty default after last case. - // If we detect this and if the last case is not terminated by a break, we do not consider it an error - // and we just fix it by adding a break. - if (i == node.cases.length - 2 && node.cases[i + 1].test == null // - && node.cases[i + 1].consequent.length === 1 // - && node.cases[i + 1].consequent[0].type === Syntax.ExpressionStatement // - && node.cases[i + 1].consequent[0].expression == null) { - stmts.consequent.push(_node(node, Syntax.BreakStatement)); - stmts._breaks = true; - } else if (i === node.cases.length - 1) { - stmts.consequent.push(_node(node, Syntax.BreakStatement)); + if (node._async && stmts.consequent[0].body.length > 0 && !stmts._breaks) { + if (i === node.cases.length - 1) { + stmts.consequent[0].body.push(_node(node, Syntax.BreakStatement)); stmts._breaks = true; } else { // we rewrite: @@ -879,14 +881,13 @@ if (typeof exports !== 'undefined') { // if (__B) no_break_B // breaking_C var v = _identifier(_genId(node)); - node.cases[i].consequent = [_node(node, Syntax.BlockStatement, { - body: [_switchVarTemplate.generate(node.cases[i], { - $v: v, - })], + var body = stmts.consequent[0]; + node.cases[i].consequent = [_switchVarTemplate.generate(node.cases[i], { + $v: v, })]; var ifStmt = _switchIfTemplate.generate(node.cases[i], { $v: v, - $block: stmts.consequent[0], + $block: body, }); node.cases[i + 1].consequent[0].body.splice(0, 0, ifStmt); } @@ -903,7 +904,7 @@ if (typeof exports !== 'undefined') { }); break; case Syntax.SwitchCase: - if (node.consequent.length !== 1) throw new Error("internal error: SwitchCase not wrapped: " + node.consequent.length); + if (node.consequent.length !== 1 || node.consequent[0].type !== Syntax.BlockStatement) throw new Error("internal error: SwitchCase not wrapped: " + node.consequent.length); node._breaks |= node.consequent[0]._breaks; break; case Syntax.ReturnStatement: @@ -1033,8 +1034,20 @@ if (typeof exports !== 'undefined') { }; function _canonFlows(node, options) { + var targets = {}; function _doIt(node, parent, force) { var scope = node._scope; + function withTarget(node, label, isLoop, fn) { + label = label || ''; + var breakTarget = targets['break_' + label]; + var continueTarget = targets['continue_' + label]; + targets['break_' + label] = node; + if (isLoop) targets['continue_' + label] = node; + var result = fn(); + targets['break_' + label] = breakTarget; + targets['continue_' + label] = continueTarget; + return result; + } function _doAsyncFor(node) { // extra pass to wrap async test and update @@ -1056,76 +1069,86 @@ if (typeof exports !== 'undefined') { node.alternate = _blockify(node.alternate); break; case Syntax.SwitchStatement: - if (node._async) { - var def = node.cases.filter(function(n) { - return n.test == null - })[0]; - if (!def) { - def = _node(node, Syntax.SwitchCase, { - consequent: [_node(node, Syntax.BlockStatement, { - body: [], - })], - }); - node.cases.push(def); - } - if (!def._breaks) { - def.consequent.push(_node(node, Syntax.BreakStatement)); + return withTarget(node, null, false, function() { + if (node._async) { + var def = node.cases.filter(function(n) { + return n.test == null + })[0]; + if (!def) { + def = _node(node, Syntax.SwitchCase, { + consequent: [_node(node, Syntax.BlockStatement, { + body: [], + })], + }); + node.cases.push(def); + } + if (!def._breaks) { + def.consequent[0].body.push(_node(node, Syntax.BreakStatement)); + } } - } - break; + return _propagate(node, _doIt); + }); case Syntax.WhileStatement: node.body = _blockify(node.body); - if (node._async) { - node = _flowsTemplates.WHILE.generate(node, { - $test: node.test, - $body: node.body - }); - } - break; + return withTarget(node, null, true, function() { + if (node._async) { + node = _flowsTemplates.WHILE.generate(node, { + $test: node.test, + $body: node.body + }); + } + return _propagate(node, _doIt); + }); case Syntax.DoWhileStatement: node.body = _blockify(node.body); - if (node._async) { - node = _flowsTemplates.DO.generate(node, { - $firstTime: _identifier(_genId(node)), - $test: node.test, - $body: node.body - }); - } - break; - case Syntax.ForStatement: - node.test = node.test || _literal(1); - node.body = _blockify(node.body); - if (node._async) { - if (node.init) { - node = _flowsTemplates.FOR.generate(node, { - $init: _statementify(node.init), + return withTarget(node, null, true, function() { + if (node._async) { + node = _flowsTemplates.DO.generate(node, { + $firstTime: _identifier(_genId(node)), $test: node.test, - $update: node.update, $body: node.body }); - } else { - if (node._pass !== "flows") { - node._pass = "flows"; - _doAsyncFor(node); + } + return _propagate(node, _doIt); + }); + case Syntax.ForStatement: + node.test = node.test || _literal(1); + node.body = _blockify(node.body); + return withTarget(node, null, true, function() { + if (node._async) { + if (node.init) { + node = _flowsTemplates.FOR.generate(node, { + $init: _statementify(node.init), + $test: node.test, + $update: node.update, + $body: node.body + }); + } else { + if (node._pass !== "flows") { + node._pass = "flows"; + _doAsyncFor(node); + } } } - } - break; + return _propagate(node, _doIt); + }); case Syntax.ForInStatement: node.body = _blockify(node.body); - if (node._async) { - if (node.left.type != Syntax.Identifier) { - throw new Error("unsupported 'for ... in' syntax: type=" + node.left.type); + return withTarget(node, null, true, function() { + if (node._async) { + if (node.left.type != Syntax.Identifier) { + throw new Error("unsupported 'for ... in' syntax: type=" + node.left.type); + } + node = _flowsTemplates.FOR_IN.generate(node, { + $array: _identifier(_genId(node)), + $i: _identifier(_genId(node)), + $object: node.right, + $iter: node.left, + $body: node.body + }); } - node = _flowsTemplates.FOR_IN.generate(node, { - $array: _identifier(_genId(node)), - $i: _identifier(_genId(node)), - $object: node.right, - $iter: node.left, - $body: node.body - }); - } - break; + return _propagate(node, _doIt); + }); case Syntax.TryStatement: if (node.block && node.handlers.length && node.finalizer) { node = _flowsTemplates.TRY.generate(node, { @@ -1169,6 +1192,20 @@ if (typeof exports !== 'undefined') { }); } break; + case Syntax.LabeledStatement: + return withTarget(node, node.label.name, true, function() { + return _propagate(node, _doIt); + }); + case Syntax.BreakStatement: + var target = targets['break_' + (node.label ? node.label.name : '')]; + if (!target) throw new Error("internal error: break target not set"); + node._async = target._async; + break; + case Syntax.ContinueStatement: + var target = targets['continue_' + (node.label ? node.label.name : '')]; + if (!target) throw new Error("internal error: continue target not set"); + node._async = target._async; + break; } return _propagate(node, _doIt); } @@ -1449,7 +1486,7 @@ if (typeof exports !== 'undefined') { //node._scope.name ? _identifier(node._scope.name) : _node(node, NULL), $name: "__$" + node._scope.name, $fname: _literal(parent.id.name), - $line: _literal(0), // see later originalLine(options, node._scope.line)), + $line: _literal(originalLine(options, node._scope.line)), $index: _literal(node._scope.cbIndex), $decls: _node(node, Syntax.BlockStatement, { body: decls || [] @@ -1492,9 +1529,7 @@ if (typeof exports !== 'undefined') { }); break; case Syntax.BreakStatement: - if (node.target && !node.target._async) { - break; - } + if (!node._async) break; _extractTail(parent, i); if (node.label) { node = _cbTemplates.LABELLED_BREAK.generate(node, { @@ -1505,9 +1540,7 @@ if (typeof exports !== 'undefined') { } break; case Syntax.ContinueStatement: - if (node.target && !node.target._async) { - break; - } + if (!node._async) break; _extractTail(parent, i); if (node.label) { node = _cbTemplates.LABELLED_CONTINUE.generate(node, { @@ -1645,8 +1678,8 @@ if (typeof exports !== 'undefined') { args[i] = (result ? result.indexOf('__') === 0 ? _cbTemplates.CALL_TMP : _cbTemplates.CALL_RESULT : _cbTemplates.CALL_VOID).generate(node, { $v: _genId(node), $frameName: _literal(node._scope.name), - $offset: _literal(0), // fix later: originalLine(options, identifier.lineno, col) - originalLine(options, node._scope.line)), - $col: _literal(0), // originalCol(options, identifier.lineno, col)), + $offset: _literal(Math.max(originalLine(options, identifier.loc && identifier.loc.start.line, col) - originalLine(options, node._scope.line), 0)), + $col: _literal(originalCol(options, identifier.loc && identifier.loc.start.column, col)), $name: "__$" + node._scope.name, $returnArray: _node(node, Syntax.Literal, { value: !!returnArray, @@ -1678,26 +1711,35 @@ if (typeof exports !== 'undefined') { var _optims = { function__0$fn: new Template("simplify", "return function ___(__0) { $fn(); }", true).root, function$return: new Template("simplify", "return function $fn1() { return $fn2(); }", true).root, - function__0$arg1return_null$arg2: new Template("simplify", "return function ___(__0, $arg1) { return _(null, $arg2); }", true).root, + function__0$arg1return_null$arg2: new Template("simplify", "return function ___(__0, $arg1) { var $arg2 = $arg3; return _(null, $arg4); }", true).root, __cb__: new Template("simplify", "return __cb(_, $frameVar, $line, $col, _)", true).root, - __cbt__: new Template("simplify", "return __cb(_, $frameVar, $line, $col, _, true)", true).root, + __cbt__: new Template("simplify", "return __cb(_, $frameVar, $line, $col, _, true, false)", true).root, function$fn: new Template("simplify", "return function $fn1() { $fn2(); }", true).root, - closure: new Template("simplify", "return (function ___closure(_){ $body; })(__cb(_,$frameVar,$line,$col,function $fnName(){_();},true))", true).root, + closure: new Template("simplify", "return (function ___closure(_){ $body; })(__cb(_,$frameVar,$line,$col,function $fnName(){_();},true,false))", true).root, safeParam: new Template("simplify", "return (function $fnName($param){ $body; })(function $fnName(){_();})", true).root, } function _simplify(node, options, used) { if (node._simplified) return node; node._simplified = true; + // eliminate extra braces on switch cases + if (node.type === 'SwitchCase') { + if (node.consequent.length === 1 && node.consequent[0].type === Syntax.BlockStatement) // + node.consequent = node.consequent[0].body; + } + _propagate(node, function(child) { return _simplify(child, options, used) }); _checkUsed(node.name, used); function _match(prop, v1, v2, result) { - var ignored = ["parenthesized", "lineno", "start", "end", "tokenizer", "hasReturnWithValue"]; + var ignored = ["loc", "range", "raw"]; if (prop.indexOf('_') == 0 || ignored.indexOf(prop) >= 0) return true; - if (v1 == v2) return true; + if (v1 == v2) { + //console.log("MATCHING1: " + v1); + return true; + } if (v1 == null || v2 == null) { // ignore difference between null and empty array if (prop == "body" && v1 && v1.length === 0) return true; @@ -1711,17 +1753,19 @@ if (typeof exports !== 'undefined') { return true; } if (v1.type === Syntax.Identifier && v1.name[0] === "$" && typeof v2.value === "number") { - result[v1.value] = v2.value; + //console.log("MATCHING2: " + v1.name + " with " + v2.value); + result[v1.name] = v2.value; return true; } if (typeof v1 == "string" && v1[0] == "$" && typeof v2 == "string") { + //console.log("MATCHING3: " + v1 + " with " + v2); result[v1] = v2; return true; } if (v1.type) { var exp; - if (v1.type == Syntax.Program && v1.body[0] && (exp = v1.body[0].expression) && typeof exp.value == "string" && exp.value[0] == '$') { - result[exp.value] = v2; + if (v1.type == Syntax.BlockStatement && v1.body[0] && (exp = v1.body[0].expression) && typeof exp.name == "string" && exp.name[0] == '$') { + result[exp.name] = v2; return true; } if (v1.type != v2.type) return false; @@ -1743,12 +1787,12 @@ if (typeof exports !== 'undefined') { var result = {}; if (_match("", _optims.function__0$fn, node, result)) return _identifier(result.$fn); if (_match("", _optims.function$return, node, result) && (result.$fn1 === '___' || result.$fn1.indexOf('__$') === 0) && (result.$fn2 === '__break')) return _identifier(result.$fn2); - if (_match("", _optims.function__0$arg1return_null$arg2, node, result) && result.$arg1 == result.$arg2) return _identifier("_"); + if (_match("", _optims.function__0$arg1return_null$arg2, node, result) && result.$arg1 == result.$arg3 && result.$arg2 == result.$arg4) return _identifier("_"); if (options.optimize && _match("", _optims.__cb__, node, result)) return _identifier("_"); if (options.optimize && _match("", _optims.__cbt__, node, result)) return _identifier("_"); if (_match("", _optims.function$fn, node, result) && (result.$fn1 === '___' || result.$fn1.indexOf('__$') === 0) && (result.$fn2 === '__then' || result.$fn2 === '__loop')) return _identifier(result.$fn2); - if (_match("", _optims.closure, node, result)) node.body[1] = _identifier("_"); - if (_match("", _optims.safeParam, node, result) && (result.$param === '__then' || result.$param === '__break')) node.children[1] = _identifier("_"); + if (_match("", _optims.closure, node, result)) { node.arguments[0] = _identifier("_"); } + if (_match("", _optims.safeParam, node, result) && (result.$param === '__then' || result.$param === '__break')) node.arguments[0] = _identifier("_"); _flatten(node); return node; } @@ -1764,21 +1808,65 @@ if (typeof exports !== 'undefined') { return _extend({}, obj); } + var visit = 0; function dump(obj) { function fix(obj) { - if (!obj || typeof obj !== 'object') return '<' + obj + '>'; - if (obj._visited) return ""; + if (!obj || typeof obj !== 'object') return '' + obj; + if (obj._visited === visit) return ""; + obj._visited = visit; if (Array.isArray(obj)) return obj.map(fix); - obj._visited = true; return Object.keys(obj).filter(function(k) { - return !/^(_|loc)/.test(k); + return !/^(_|loc)/.test(k) || k === '_async'; }).reduce(function(r, k) { r[k] = fix(obj[k]); return r; }, {}); } + visit++; return JSON.stringify(fix(obj), null, ' '); } + + function fixRanges(node) { + function fix1(obj) { + if (!obj || typeof obj !== 'object') return null; + if (obj._visited === visit) return null; + obj._visited = visit; + function combine(r1, r2) { + if (!r1) return r2; + if (!r2) return r1; + return [Math.min(r1[0], r2[0]), Math.max(r1[1], r2[1])]; + } + if (Array.isArray(obj)) { + return obj.reduce(function(r, o) { + return combine(r, fix1(o)); + }, null); + } + if (!obj.type) return null; + return obj.range = Object.keys(obj).reduce(function(r, k) { + return combine(r, fix1(obj[k])); + }, null); + } + function fix2(obj, val) { + if (!obj || typeof obj !== 'object') return; + if (obj._visited === visit) return; + obj._visited = visit; + if (Array.isArray(obj)) { + obj.forEach(function(o) { + fix2(o, val); + }); + } + if (!obj.type) return; + if (!obj.range) obj.range = [val, val]; + Object.keys(obj).forEach(function(k) { + fix2(obj[k], obj.range[0]); + }); + } + visit++; + fix1(node); + visit++; + fix2(node, 0); + } + /// * `transformed = transform.transform(source, options)` /// Transforms streamline source. /// The following `options` may be specified: @@ -1804,10 +1892,13 @@ if (typeof exports !== 'undefined') { //console.log("source=" + source); // esprima does not like return at top level so we wrap into a function // also \n is needed before } in case last line ends on a // comment - var node = esprima.parse("function dummy(){" + source + "\n}", { + source = "function dummy(){" + source + "\n}"; + var node = esprima.parse(source, { loc: true, + range: true, }); node = node.body[0].body; + if (node.type !== Syntax.BlockStatement) throw new Error("source wrapper error: " + node.type); //console.log(JSON.stringify(node, null, ' ')); var strict = node.body[0] && node.body[0].expression && node.body[0].expression.value == "use strict"; strict && node.body.splice(0, 1); @@ -1817,7 +1908,7 @@ if (typeof exports !== 'undefined') { //console.log("CANONTOPLEVEL=" + escodegen.generate(node)); node = _canonScopes(node, options); //console.log("CANONSCOPES=" + escodegen.generate(node)); - if (!options.needsTransform) return source; + if (!options.needsTransform) return options.source; // original source! node = _canonFlows(node, options); //console.log("CANONFLOWS=" + escodegen.generate(node)); node = _disassemble(node, options); @@ -1827,10 +1918,15 @@ if (typeof exports !== 'undefined') { //console.log("CALLBACKIFY=" + escodegen.generate(node)) var used = {}; node = _simplify(node, options, used); - - var result = escodegen.generate(node); //, options.lines); + //fixRanges(node); + var result = escodegen.generate(node, { + //sourceCode: source, + format: { + //preserveBlankLines: true, + } + }); //, options.lines); // remove curly braces around generated source - result = result.substring(1, result.length - 1); + result = result[0] === '{' ? result.substring(1, result.length - 1) : result; // add helpers at beginning so that __g is initialized before any other code diff --git a/test/common/stack-test._js b/test/common/stack-test._js index 294bd236..5d5df38a 100644 --- a/test/common/stack-test._js +++ b/test/common/stack-test._js @@ -10,11 +10,16 @@ var nextTick = _(function(cb) { }, 0); - function failAsync(_, code){ throw new Error(code); } + + + + + + function failSync(_, code){ (function fail(dummy){ // dummy to defeat CoffeeScript compat rule throw new Error(code); @@ -101,6 +106,196 @@ function I(_, code){ s += H(_, i); return s; } + + +// Lots of mpty lines to sync with escodegen formatting ... + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + function issue233(_, code) { function customThrow() { @@ -113,8 +308,20 @@ function issue233(_, code) { } } -// You can insert lines and/or comments after this point. + + + + + + + +asyncTest("issue233", 1, function(_) { + stackEqual(T(_, issue233, 0, failSync), "Error: foo/customThrow:305/issue233:320"); + start(); +}); + +// Code below can be moved down function T(_, fn, code, failFn){ fail = failFn; var s = "{" @@ -146,72 +353,72 @@ var rawStack = new Error().stack ? function(raw) { } asyncTest("stacks", 20, function(_) { - stackEqual(T(_, A, 1, failAsync), rawStack("Error: 1/failAsync:15") + "/A:28"); - stackEqual(T(_, A, 1, failSync), rawStack("Error: 1/fail:20/failSync:21") + "/A:28"); - stackEqual(T(_, A, 2, failAsync), rawStack("Error: 2/failAsync:15") + "/A:30"); - stackEqual(T(_, A, 2, failSync), rawStack("Error: 2/fail:20/failSync:21") + "/A:30"); - stackEqual(T(_, A, 3, failAsync), rawStack("Error: 3/failAsync:15") + "/A:33"); - stackEqual(T(_, A, 3, failSync), rawStack("Error: 3/fail:20/failSync:21") + "/A:33"); - stackEqual(T(_, A, 4, failAsync), rawStack("Error: 4/failAsync:15") + "/A:36"); - stackEqual(T(_, A, 4, failSync), rawStack("Error: 4/fail:20/failSync:21") + "/A:36"); - stackEqual(T(_, A, 5, failAsync), rawStack("Error: 5/failAsync:15") + "/A:36"); - stackEqual(T(_, A, 5, failSync), rawStack("Error: 5/fail:20/failSync:21") + "/A:36"); - stackEqual(T(_, A, 6, failAsync), rawStack("Error: 6/failAsync:15") + "/A:40"); - stackEqual(T(_, A, 6, failSync), rawStack("Error: 6/fail:20/failSync:21") + "/A:40"); - stackEqual(T(_, A, 7, failAsync), rawStack("Error: 7/failAsync:15") + "/B:49/A:42"); - stackEqual(T(_, A, 7, failSync), rawStack("Error: 7/fail:20/failSync:21") + "/B:49/A:42"); - stackEqual(T(_, A, 8, failAsync), rawStack("Error: 8/failAsync:15") + "/C:58/B:50/A:42"); - stackEqual(T(_, A, 8, failSync), rawStack("Error: 8/fail:20/failSync:21") + "/C:58/B:50/A:42"); - stackEqual(T(_, A, 9, failAsync), rawStack("Error: 9/failAsync:15") + "/D:63/B:53/A:42"); - stackEqual(T(_, A, 9, failSync), rawStack("Error: 9/fail:20/failSync:21") + "/D:63/B:53/A:42"); + stackEqual(T(_, A, 1, failAsync), rawStack("Error: 1/failAsync:14") + "/A:33"); + stackEqual(T(_, A, 1, failSync), rawStack("Error: 1/fail:24/failSync:25") + "/A:33"); + stackEqual(T(_, A, 2, failAsync), rawStack("Error: 2/failAsync:14") + "/A:35"); + stackEqual(T(_, A, 2, failSync), rawStack("Error: 2/fail:24/failSync:25") + "/A:35"); + stackEqual(T(_, A, 3, failAsync), rawStack("Error: 3/failAsync:14") + "/A:38"); + stackEqual(T(_, A, 3, failSync), rawStack("Error: 3/fail:24/failSync:25") + "/A:38"); + stackEqual(T(_, A, 4, failAsync), rawStack("Error: 4/failAsync:14") + "/A:41"); + stackEqual(T(_, A, 4, failSync), rawStack("Error: 4/fail:24/failSync:25") + "/A:41"); + stackEqual(T(_, A, 5, failAsync), rawStack("Error: 5/failAsync:14") + "/A:41"); + stackEqual(T(_, A, 5, failSync), rawStack("Error: 5/fail:24/failSync:25") + "/A:41"); + stackEqual(T(_, A, 6, failAsync), rawStack("Error: 6/failAsync:14") + "/A:45"); + stackEqual(T(_, A, 6, failSync), rawStack("Error: 6/fail:24/failSync:25") + "/A:45"); + stackEqual(T(_, A, 7, failAsync), rawStack("Error: 7/failAsync:14") + "/B:54/A:47"); + stackEqual(T(_, A, 7, failSync), rawStack("Error: 7/fail:24/failSync:25") + "/B:54/A:47"); + stackEqual(T(_, A, 8, failAsync), rawStack("Error: 8/failAsync:14") + "/C:63/B:55/A:47"); + stackEqual(T(_, A, 8, failSync), rawStack("Error: 8/fail:24/failSync:25") + "/C:63/B:55/A:47"); + stackEqual(T(_, A, 9, failAsync), rawStack("Error: 9/failAsync:14") + "/D:68/B:58/A:47"); + stackEqual(T(_, A, 9, failSync), rawStack("Error: 9/fail:24/failSync:25") + "/D:68/B:58/A:47"); stackEqual(T(_, A, 10, failAsync), "END"); stackEqual(T(_, A, 10, failSync), "END"); start(); }) asyncTest("catch", 20, function(_) { - stackEqual(T(_, E, 1, failAsync), rawStack("Error: 1/failAsync:15") + "/E:72"); - stackEqual(T(_, E, 1, failSync), rawStack("Error: 1/fail:20/failSync:21") + "/E:72"); - stackEqual(T(_, E, 2, failAsync), rawStack("Error: 2/failAsync:15") + "/A:30/E:74"); - stackEqual(T(_, E, 2, failSync), rawStack("Error: 2/fail:20/failSync:21") + "/A:30/E:74"); + stackEqual(T(_, E, 1, failAsync), rawStack("Error: 1/failAsync:14") + "/E:77"); + stackEqual(T(_, E, 1, failSync), rawStack("Error: 1/fail:24/failSync:25") + "/E:77"); + stackEqual(T(_, E, 2, failAsync), rawStack("Error: 2/failAsync:14") + "/A:35/E:79"); + stackEqual(T(_, E, 2, failSync), rawStack("Error: 2/fail:24/failSync:25") + "/A:35/E:79"); stackEqual(T(_, E, 3, failAsync), "OK 3"); stackEqual(T(_, E, 3, failSync), "OK 3"); - stackEqual(T(_, E, 4, failAsync), rawStack("Error: 4/failAsync:15") + "/E:72"); - stackEqual(T(_, E, 4, failSync), rawStack("Error: 4/fail:20/failSync:21") + "/E:72"); - stackEqual(T(_, E, 5, failAsync), rawStack("Error: 5/failAsync:15") + "/A:36/E:74"); - stackEqual(T(_, E, 5, failSync), rawStack("Error: 5/fail:20/failSync:21") + "/A:36/E:74"); + stackEqual(T(_, E, 4, failAsync), rawStack("Error: 4/failAsync:14") + "/E:77"); + stackEqual(T(_, E, 4, failSync), rawStack("Error: 4/fail:24/failSync:25") + "/E:77"); + stackEqual(T(_, E, 5, failAsync), rawStack("Error: 5/failAsync:14") + "/A:41/E:79"); + stackEqual(T(_, E, 5, failSync), rawStack("Error: 5/fail:24/failSync:25") + "/A:41/E:79"); stackEqual(T(_, E, 6, failAsync), "OK 6"); stackEqual(T(_, E, 6, failSync), "OK 6"); - stackEqual(T(_, E, 7, failAsync), rawStack("Error: 7/failAsync:15") + "/E:72"); - stackEqual(T(_, E, 7, failSync), rawStack("Error: 7/fail:20/failSync:21") + "/E:72"); - stackEqual(T(_, E, 8, failAsync), rawStack("Error: 8/failAsync:15") + "/C:58/B:50/A:42/E:74"); - stackEqual(T(_, E, 8, failSync), rawStack("Error: 8/fail:20/failSync:21") + "/C:58/B:50/A:42/E:74"); + stackEqual(T(_, E, 7, failAsync), rawStack("Error: 7/failAsync:14") + "/E:77"); + stackEqual(T(_, E, 7, failSync), rawStack("Error: 7/fail:24/failSync:25") + "/E:77"); + stackEqual(T(_, E, 8, failAsync), rawStack("Error: 8/failAsync:14") + "/C:63/B:55/A:47/E:79"); + stackEqual(T(_, E, 8, failSync), rawStack("Error: 8/fail:24/failSync:25") + "/C:63/B:55/A:47/E:79"); stackEqual(T(_, E, 9, failAsync), "OK 9"); stackEqual(T(_, E, 9, failSync), "OK 9"); - stackEqual(T(_, E, 10, failAsync), rawStack("Error: 10/failAsync:15") + "/E:72"); - stackEqual(T(_, E, 10, failSync), rawStack("Error: 10/fail:20/failSync:21") + "/E:72"); + stackEqual(T(_, E, 10, failAsync), rawStack("Error: 10/failAsync:14") + "/E:77"); + stackEqual(T(_, E, 10, failSync), rawStack("Error: 10/fail:24/failSync:25") + "/E:77"); start(); }) asyncTest("futures", 20, function(_) { - stackEqual(T(_, F, 1, failAsync), rawStack("Error: 1/failAsync:15") + "/A:28/F:83"); - stackEqual(T(_, F, 1, failSync), rawStack("Error: 1/fail:20/failSync:21") + "/A:28/F:83"); - stackEqual(T(_, F, 2, failAsync), rawStack("Error: 2/failAsync:15") + "/A:30/F:83"); - stackEqual(T(_, F, 2, failSync), rawStack("Error: 2/fail:20/failSync:21") + "/A:30/F:83"); - stackEqual(T(_, F, 3, failAsync), rawStack("Error: 3/failAsync:15") + "/A:33/F:83"); - stackEqual(T(_, F, 3, failSync), rawStack("Error: 3/fail:20/failSync:21") + "/A:33/F:83"); - stackEqual(T(_, F, 4, failAsync), rawStack("Error: 4/failAsync:15") + "/A:36/F:83"); - stackEqual(T(_, F, 4, failSync), rawStack("Error: 4/fail:20/failSync:21") + "/A:36/F:83"); - stackEqual(T(_, F, 5, failAsync), rawStack("Error: 5/failAsync:15") + "/A:36/F:83"); - stackEqual(T(_, F, 5, failSync), rawStack("Error: 5/fail:20/failSync:21") + "/A:36/F:83"); - stackEqual(T(_, F, 6, failAsync), rawStack("Error: 6/failAsync:15") + "/A:40/F:83"); - stackEqual(T(_, F, 6, failSync), rawStack("Error: 6/fail:20/failSync:21") + "/A:40/F:83"); - stackEqual(T(_, F, 7, failAsync), rawStack("Error: 7/failAsync:15") + "/B:49/A:42/F:83"); - stackEqual(T(_, F, 7, failSync), rawStack("Error: 7/fail:20/failSync:21") + "/B:49/A:42/F:83"); - stackEqual(T(_, F, 8, failAsync), rawStack("Error: 8/failAsync:15") + "/C:58/B:50/A:42/F:83"); - stackEqual(T(_, F, 8, failSync), rawStack("Error: 8/fail:20/failSync:21") + "/C:58/B:50/A:42/F:83"); - stackEqual(T(_, F, 9, failAsync), rawStack("Error: 9/failAsync:15") + "/D:63/B:53/A:42/F:83"); - stackEqual(T(_, F, 9, failSync), rawStack("Error: 9/fail:20/failSync:21") + "/D:63/B:53/A:42/F:83"); + stackEqual(T(_, F, 1, failAsync), rawStack("Error: 1/failAsync:14") + "/A:33/F:88"); + stackEqual(T(_, F, 1, failSync), rawStack("Error: 1/fail:24/failSync:25") + "/A:33/F:88"); + stackEqual(T(_, F, 2, failAsync), rawStack("Error: 2/failAsync:14") + "/A:35/F:88"); + stackEqual(T(_, F, 2, failSync), rawStack("Error: 2/fail:24/failSync:25") + "/A:35/F:88"); + stackEqual(T(_, F, 3, failAsync), rawStack("Error: 3/failAsync:14") + "/A:38/F:88"); + stackEqual(T(_, F, 3, failSync), rawStack("Error: 3/fail:24/failSync:25") + "/A:38/F:88"); + stackEqual(T(_, F, 4, failAsync), rawStack("Error: 4/failAsync:14") + "/A:41/F:88"); + stackEqual(T(_, F, 4, failSync), rawStack("Error: 4/fail:24/failSync:25") + "/A:41/F:88"); + stackEqual(T(_, F, 5, failAsync), rawStack("Error: 5/failAsync:14") + "/A:41/F:88"); + stackEqual(T(_, F, 5, failSync), rawStack("Error: 5/fail:24/failSync:25") + "/A:41/F:88"); + stackEqual(T(_, F, 6, failAsync), rawStack("Error: 6/failAsync:14") + "/A:45/F:88"); + stackEqual(T(_, F, 6, failSync), rawStack("Error: 6/fail:24/failSync:25") + "/A:45/F:88"); + stackEqual(T(_, F, 7, failAsync), rawStack("Error: 7/failAsync:14") + "/B:54/A:47/F:88"); + stackEqual(T(_, F, 7, failSync), rawStack("Error: 7/fail:24/failSync:25") + "/B:54/A:47/F:88"); + stackEqual(T(_, F, 8, failAsync), rawStack("Error: 8/failAsync:14") + "/C:63/B:55/A:47/F:88"); + stackEqual(T(_, F, 8, failSync), rawStack("Error: 8/fail:24/failSync:25") + "/C:63/B:55/A:47/F:88"); + stackEqual(T(_, F, 9, failAsync), rawStack("Error: 9/failAsync:14") + "/D:68/B:58/A:47/F:88"); + stackEqual(T(_, F, 9, failSync), rawStack("Error: 9/fail:24/failSync:25") + "/D:68/B:58/A:47/F:88"); stackEqual(T(_, F, 10, failAsync), "END & END"); stackEqual(T(_, F, 10, failSync), "END & END"); start(); @@ -222,14 +429,11 @@ asyncTest("loop", 8, function(_) { stackEqual(T(_, I, 4, failSync), "0123"); stackEqual(T(_, I, 5, failAsync), "01234"); stackEqual(T(_, I, 5, failSync), "01234"); - stackEqual(T(_, I, 6, failAsync), rawStack("Error: 5/failAsync:15") + "/G:88/H:95/I:101"); - stackEqual(T(_, I, 6, failSync), rawStack("Error: 5/fail:20/failSync:21") + "/G:88/H:95/I:101"); - stackEqual(T(_, I, 7, failAsync), rawStack("Error: 5/failAsync:15") + "/G:88/H:95/I:101"); - stackEqual(T(_, I, 7, failSync), rawStack("Error: 5/fail:20/failSync:21") + "/G:88/H:95/I:101"); + stackEqual(T(_, I, 6, failAsync), rawStack("Error: 5/failAsync:14") + "/G:93/H:100/I:106"); + stackEqual(T(_, I, 6, failSync), rawStack("Error: 5/fail:24/failSync:25") + "/G:93/H:100/I:106"); + stackEqual(T(_, I, 7, failAsync), rawStack("Error: 5/failAsync:14") + "/G:93/H:100/I:106"); + stackEqual(T(_, I, 7, failSync), rawStack("Error: 5/fail:24/failSync:25") + "/G:93/H:100/I:106"); start(); }) -asyncTest("issue233", 1, function(_) { - stackEqual(T(_, issue233, 0, failSync), "Error: foo/customThrow:107/issue233:112"); - start(); -}); + diff --git a/test/common/transform-test.js b/test/common/transform-test.js index 9fa3bcf8..a43b0f18 100644 --- a/test/common/transform-test.js +++ b/test/common/transform-test.js @@ -26,14 +26,14 @@ test("basic", 1, function() { f2(); }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { return f1(__cb(_, __frame, 1, 4, function __$f() { f2(); _(); - }, true)); + }, true, false)); }); }); }); @@ -45,7 +45,7 @@ test("var return", 1, function() { }, function f(_) { var x; var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { @@ -53,7 +53,7 @@ test("var return", 1, function() { x = __1; f2(); return _(null, x); - }, true)); + }, true, false)); }); }); }); @@ -63,7 +63,7 @@ test("return", 1, function() { return f2(_); }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { @@ -83,22 +83,22 @@ test("if", 1, function() { f5(); }, function f(_, b) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); - return (function __$f(__then) { + return function __$f(__then) { if (b) { f2(); return f3(__cb(_, __frame, 4, 8, function __$f() { f4(); __then(); - }, true)); + }, true, false)); } else { __then(); } - })(function __$f() { + }(function __$f() { f5(); _(); }); @@ -115,22 +115,22 @@ test("simplified if", 1, function() { } }, function f(_, b) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); - return (function __$f(__then) { + return function __$f(__then) { if (b) { f2(); return f3(__cb(_, __frame, 4, 8, function __$f() { f4(); __then(); - }, true)); + }, true, false)); } else { __then(); } - })(_); + }(_); }); }); }); @@ -149,26 +149,26 @@ test("if else", 1, function() { f8(); }, function f(_, b) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); - return (function __$f(__then) { + return function __$f(__then) { if (b) { f2(); return f3(__cb(_, __frame, 4, 8, function __$f() { f4(); __then(); - }, true)); + }, true, false)); } else { f5(); return f6(__cb(_, __frame, 8, 8, function __$f() { f7(); __then(); - }, true)); + }, true, false)); } - })(function __$f() { + }(function __$f() { f8(); _(); }); @@ -190,23 +190,23 @@ test("if else 2", 1, function() { return 2; }, function f(_, b) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); - return (function __$f(__then) { + return function __$f(__then) { if (b) { f2(); return f3(__cb(_, __frame, 4, 8, function __$f() { f4(); return _(null, 1); - }, true)); + }, true, false)); } else { f5(); __then(); } - })(function __$f() { + }(function __$f() { f6(); return _(null, 2); }); @@ -223,7 +223,7 @@ test("each", 1, function() { f4(); }, function f(_, arr) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { @@ -231,16 +231,16 @@ test("each", 1, function() { return each(__cb(_, __frame, 2, 4, function __$f() { f4(); _(); - }, true), arr, function __1(_, elt) { + }, true, false), arr, function __1(_, elt) { var __frame = { - name: "__1", + name: '__1', line: 3 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() { return f2(__cb(_, __frame, 0, 36, function __$__1() { f3(); _(); - }, true), elt); + }, true, false), elt); }); }); }); @@ -256,12 +256,12 @@ test("while", 1, function() { f4(); }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); - return (function ___(__break) { + return function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$f() { __more = false; @@ -273,7 +273,7 @@ test("while", 1, function() { __loop(); } __more = true; - }, true)); + }, true, false)); } else { __break(); } @@ -283,7 +283,7 @@ test("while", 1, function() { } while (__more); __more = true; - })(function __$f() { + }(function __$f() { f4(); _(); }); @@ -301,17 +301,17 @@ test("do while", 1, function() { f4(); }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); var __1 = true; - return (function ___(__break) { + return function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$f() { __more = false; - var __2 = (__1 || cond); + var __2 = __1 || cond; if (__2) { __1 = false; return f2(__cb(_, __frame, 3, 8, function __$f() { @@ -320,7 +320,7 @@ test("do while", 1, function() { __loop(); } __more = true; - }, true)); + }, true, false)); } else { __break(); } @@ -330,7 +330,7 @@ test("do while", 1, function() { } while (__more); __more = true; - })(function __$f() { + }(function __$f() { f4(); _(); }); @@ -348,14 +348,14 @@ test("for", 1, function() { }, function f(_, arr) { var i; var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); i = 0; var __2 = false; - return (function ___(__break) { + return function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$f() { __more = false; @@ -364,7 +364,7 @@ test("for", 1, function() { } else { __2 = true; } - var __1 = (i < arr.length); + var __1 = i < arr.length; if (__1) { return f2(__cb(_, __frame, 3, 8, function __$f() { f3(); @@ -372,7 +372,7 @@ test("for", 1, function() { __loop(); } __more = true; - }, true)); + }, true, false)); } else { __break(); } @@ -382,7 +382,7 @@ test("for", 1, function() { } while (__more); __more = true; - })(function __$f() { + }(function __$f() { f4(); _(); }); @@ -400,18 +400,18 @@ test("for in", 1, function() { }, function f(_) { var k; var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); var __1 = __forIn(obj); var __2 = 0; - return (function ___(__break) { + return function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$f() { __more = false; - var __3 = (__2 < __1.length); + var __3 = __2 < __1.length; if (__3) { k = __1[__2++]; return f2(__cb(_, __frame, 3, 8, function __$f() { @@ -420,7 +420,7 @@ test("for in", 1, function() { __loop(); } __more = true; - }, true), k); + }, true, false), k); } else { __break(); } @@ -430,7 +430,7 @@ test("for in", 1, function() { } while (__more); __more = true; - })(function __$f() { + }(function __$f() { f4(); _(); }); @@ -449,18 +449,18 @@ test("for in (without var)", 1, function() { }, function f(_) { var k; var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); var __1 = __forIn(obj); var __2 = 0; - return (function ___(__break) { + return function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$f() { __more = false; - var __3 = (__2 < __1.length); + var __3 = __2 < __1.length; if (__3) { k = __1[__2++]; return f2(__cb(_, __frame, 4, 8, function __$f() { @@ -469,7 +469,7 @@ test("for in (without var)", 1, function() { __loop(); } __more = true; - }, true), k); + }, true, false), k); } else { __break(); } @@ -479,7 +479,7 @@ test("for in (without var)", 1, function() { } while (__more); __more = true; - })(function __$f() { + }(function __$f() { f4(); _(); }); @@ -506,27 +506,27 @@ test("switch", 1, function() { f7(); }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); - return (function __$f(__break) { + return function __$f(__break) { switch (exp) { - case "a": + case 'a': return f2(__cb(_, __frame, 4, 8, function __$f() { f3(); return __break(); - }, true)); - case "b": - case "c": + }, true, false)); + case 'b': + case 'c': f4(); - return f5(__cb(_, __frame, 10, 8, __break, true)); + return f5(__cb(_, __frame, 10, 8, __break, true, false)); default: f6(); return __break(); } - })(function __$f() { + }(function __$f() { f7(); _(); }); @@ -546,24 +546,24 @@ test("nested switch", 1, function() { } }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { - return (function __$f(__break) { + return function __$f(__break) { switch (exp) { - case "a": + case 'a': return f2(__cb(_, __frame, 3, 8, function __$f() { switch (exp2) { - case "b": + case 'b': break; } return __break(); - }, true)); + }, true, false)); default: return __break(); } - })(_); + }(_); }); }); }) @@ -590,47 +590,47 @@ test("switch fall through", 1, function() { f9(); }, function f(_) { var__frame = { - name: "f", + name: 'f', line: 1 } return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); - return (function __$f(__break) { + return function __$f(__break) { switch (exp) { - case "a": + case 'a': return f2(__cb(_, __frame, 0, 0, function __$f() { f3(); return__break(); - }, true)); - case "b": + }, true, false)); + case 'b': var__1 = true; - case "c": + case 'c': var__2 = true; - case "d": - return (function __$f(__then) { + case 'd': + return function __$f(__then) { if (__2) { - return (function __$f(__then) { + return function __$f(__then) { if (__1) { - return f4(__cb(_, __frame, 0, 0, __then, true)); + return f4(__cb(_, __frame, 0, 0, __then, true, false)); } else { __then(); } - })(function __$f() { + }(function __$f() { f5(); __then(); }); } else { __then(); } - })(function __$f() { + }(function __$f() { f6(); - return f7(__cb(_, __frame, 0, 0, __break, true)); + return f7(__cb(_, __frame, 0, 0, __break, true, false)); }); default: f8(); return __break(); } - })(function __$f() { + }(function __$f() { f9(); _(); }); @@ -644,7 +644,7 @@ test("nested calls", 1, function() { f7(); }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { @@ -655,10 +655,10 @@ test("nested calls", 1, function() { return f2(__cb(_, __frame, 2, 4, function __$f() { f7(); _(); - }, true), __2, __3); - }, true), f6()); - }, true), __1); - }, true)); + }, true, false), __2, __3); + }, true, false), f6()); + }, true, false), __1); + }, true, false)); }); }); }) @@ -670,12 +670,12 @@ test("async while condition", 1, function() { f4(); }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); - return (function ___(__break) { + return function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$f() { __more = false; @@ -689,14 +689,14 @@ test("async while condition", 1, function() { } else { __break(); } - }, true)); + }, true, false)); }); do { __loop(); } while (__more); __more = true; - })(function __$f() { + }(function __$f() { f4(); _(); }); @@ -718,35 +718,35 @@ test("try catch", 1, function() { f8(); }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); - return (function ___(__then) { + return function ___(__then) { (function ___(_) { __tryCatch(_, function __$f() { f2(); return f3(__cb(_, __frame, 4, 8, function __$f() { f4(); __then(); - }, true)); + }, true, false)); }); - })(function ___(ex, __result) { + }(function ___(ex, __result) { __catch(function __$f() { if (ex) { f5(); return f6(__cb(_, __frame, 8, 8, function __$f() { f7(); __then(); - }, true)); + }, true, false)); } else { _(null, __result); } }, _); - }); - })(function ___() { + })); + }(function ___() { __tryCatch(_, function __$f() { f8(); _(); @@ -770,40 +770,37 @@ test("try finally", 1, function() { f8(); }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); - return (function ___(__then) { + return function ___(__then) { (function ___(_) { __tryCatch(_, function __$f() { f2(); return f3(__cb(_, __frame, 4, 8, function __$f() { f4(); _(null, null, true); - }, true)); + }, true, false)); }); - })(function ___(__e, __r, __cont) { + }(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$f() { f5(); return f6(__cb(_, __frame, 8, 8, function __$f() { f7(); __then(); - }, true)); + }, true, false)); }); - })(function ___() { + }(function ___() { __tryCatch(_, function ___() { - if (__cont) { - __then(); - } else { - _(__e, __r); - } + if (__cont) __then(); + else _(__e, __r); }); - }); - }); - })(function ___() { + })); + })); + }(function ___() { __tryCatch(_, function __$f() { f8(); _(); @@ -824,48 +821,43 @@ test("lazy and", 1, function() { f7(); }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { f1(); - return (function __$f(_) { - return f2(__cb(_, __frame, 2, 8, function ___(__0, __1) { - var __2 = !__1; - return (function __$f(__then) { - if (__2) { - var __3 = __1; - return _(null, __3); - } else { - __then(); - } - })(function __$f() { - return f3(_); - }); - }, true)); - })(__cb(_, __frame, 0, 5, function ___(__0, __2) { - return (function __$f(__then) { + return function __$f(_) { + return f2(__cb(_, __frame, 2, 8, function ___(__0, __2) { + var __1 = __2; + if (!__1) { + return _(null, __1); + } + return f3(_); + }, true, false)); + }(__cb(_, __frame, 0, 5, function ___(__0, __3) { + var __2 = __3; + return function __$f(__then) { if (__2) { f4(); return f5(__cb(_, __frame, 4, 8, function __$f() { f6(); __then(); - }, true)); + }, true, false)); } else { __then(); } - })(function __$f() { + }(function __$f() { f7(); _(); }); - }, true)); + }, true, false)); }); }) }) test("empty body", 1, function() { genTest(function f(_) {}, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { @@ -878,7 +870,7 @@ test("only return in body", 1, function() { return 4; }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { @@ -891,7 +883,7 @@ test("optim pass _", 1, function() { return g(_, arg2); }, function f(_, arg1) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { @@ -904,14 +896,14 @@ test("wrappers", 1, function() { return g(__wrap1(_), arg2) + 5; }, function f(_, arg1) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { return g(__wrap1(__cb(_, __frame, 1, 11, function ___(__0, __2) { - var __1 = (__2 + 5); + var __1 = __2 + 5; return _(null, __1); - }, true)), arg2); + }, true, false)), arg2); }); }); }) @@ -936,7 +928,7 @@ test("scoping", 1, function() { }, function f(_) { var a1, a2, a3, b1, b2, b3, c1, c2; var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { @@ -956,7 +948,7 @@ test("scoping", 1, function() { b3++; c2 = 2; _(); - }, true)); + }, true, false)); }); }); }) @@ -1006,14 +998,14 @@ test("function forward reference", 1, function() { }, function f(_) { function foo() {} var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { foo(); return g(__cb(_, __frame, 1, 1, function __$f() { _(); - }, true)); + }, true, false)); }); }); }) @@ -1024,13 +1016,13 @@ test("CoffeeScript closure ()", 1, function() { })(); }, function f(_) { var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { - return (function ___closure(_) { + return function ___closure(_) { return g(_); - })(_); + }(_); }); }); }) @@ -1042,13 +1034,13 @@ test("CoffeeScript closure (this)", 1, function() { }, function f(_) { var __this = this; var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { - return (function ___closure(_) { + return function ___closure(_) { return g(_, __this); - })(_); + }(_); }); }); }) @@ -1061,13 +1053,13 @@ test("CoffeeScript closure (this, arguments)", 1, function() { var __this = this, __arguments = arguments; var __frame = { - name: "f", + name: 'f', line: 1 }; return __func(_, this, arguments, f, 0, __frame, function __$f() { - return (function ___closure(_) { + return function ___closure(_) { return g(_, __this, __arguments); - })(_); + }(_); }); }); })