diff --git a/arboriculture.js b/arboriculture.js index b52b646..caa66d2 100644 --- a/arboriculture.js +++ b/arboriculture.js @@ -105,7 +105,7 @@ var examinations = { case 'ClassExpression': return true; case 'VariableDeclaration': - return this.node.kind && this.node.kind !== 'var'; + return this.node.kind && this.node.kind === 'let'; case 'FunctionDeclaration': case 'FunctionExpression': return !(!this.node.generator); @@ -183,6 +183,7 @@ function asynchronize(pr, opts, logger, parsePart, printNode) { var continuations = {}; var generatedSymbol = 1; var genIdent = {}; + Object.keys(opts).filter(function (k) { return k[0] === '$'; }).forEach(function (k) { @@ -429,7 +430,12 @@ function asynchronize(pr, opts, logger, parsePart, printNode) { } return null; } - + + + var looksLikeES6 = opts.es6target || pr.ast.type === 'Program' && pr.ast.sourceType === 'module' || contains(pr.ast, function (n) { + return examine(n).isES6; + }, true); + // actually do the transforms if (opts.engine) { // Only Transform extensions: @@ -454,18 +460,8 @@ function asynchronize(pr, opts, logger, parsePart, printNode) { pr.ast = fixSuperReferences(pr.ast); asyncTransforms(pr.ast); } - /* - if (opts.babelTree) { - treeWalk(pr.ast, function (node, descend, path) { - if (node.type === 'Literal') { - coerce(node, literal(node.value)); - } else { - descend(); - } - }); - } - */ return pr; + function asyncTransforms(ast, awaitFlag) { var useLazyLoops = !(opts.promises || opts.generators || opts.engine) && opts.lazyThenables; // Because we create functions (and scopes), we need all declarations before use @@ -1956,6 +1952,7 @@ function asynchronize(pr, opts, logger, parsePart, printNode) { /* Find all nodes within this scope matching the specified function */ function scopedNodes(ast, matching, flat) { + if (!flat) flat = ['isScope','isLoop'] ; var matches = []; treeWalk(ast, function (node, descend, path) { if (node === ast) @@ -1964,9 +1961,11 @@ function asynchronize(pr, opts, logger, parsePart, printNode) { matches.push([].concat(path)); return; } - if (flat || examine(node).isScope) { - return; - } + if (flat === true) return ; + var x = examine(node) ; + for (var i=0; i