Skip to content

Commit

Permalink
Correct cases where arrow functions contain deeply nested expressions
Browse files Browse the repository at this point in the history
containing await and logical/conditional operators
Fix edge cases in code output (sparse array constants, object pattern
precedence, generator member functions), add everything.js syntax tests
  • Loading branch information
matAtWork committed Dec 16, 2015
1 parent 84d0157 commit f0d07e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,11 @@ The test is a simple set of nested loops calling async functions that don't do m
Changelog
==========

16-Dec-15 v2.3.9

- Correct cases where arrow functions contain deeply nested expressions containing await and logical/conditional operators
- Fix edge cases in code output (sparse array constants, object pattern precedence, generator member functions), add everything.js syntax tests

10-Dec-15 v2.3.7

- Correctly asynchronize ES6 `for...in` loops.
Expand Down
29 changes: 18 additions & 11 deletions lib/arboriculture.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ function asynchronize(pr,__sourceMapping,opts,logger) {
return null ;
}

function makeArrowFunctionBlock(node) {
if (node.type==='ArrowFunctionExpression' && node.body.type !== 'BlockStatement') {
node.body = {
type: "BlockStatement",
body: [{
type: "ReturnStatement",
argument: node.body
}]
} ;
}
}

pr.ast = fixSuperReferences(pr.ast) ;
if (opts.generators) {
pr.ast = asyncSpawn(pr.ast) ;
Expand Down Expand Up @@ -589,6 +601,7 @@ function asynchronize(pr,__sourceMapping,opts,logger) {
} ;
node.right = r ;
}

var stmt,body ;
for (var n=1; n<path.length; n++) {
if (body = examine(path[n].self).isBlockStatement) {
Expand Down Expand Up @@ -936,16 +949,6 @@ function asynchronize(pr,__sourceMapping,opts,logger) {
node.alternate = {type:'BlockStatement',body:[node.alternate]} ;
}

if (node.type==='ArrowFunctionExpression' && node.body.type !== 'BlockStatement' && containsAwait(node.body)) {
node.body = {
type: "BlockStatement",
body: [{
type: "ReturnStatement",
argument: node.body
}]
} ;
}

descend();

if (examine(node).isAwait) {
Expand Down Expand Up @@ -2149,9 +2152,13 @@ function asynchronize(pr,__sourceMapping,opts,logger) {
* must be initialized at the point on declaration, and the dependent RHS could easily be async */
function hoistScopedDeclarations(ast) {
parser.treeWalker(ast,function(node, descend,path){
var awaiting = containsAwait(node) ;
if (awaiting)
makeArrowFunctionBlock(node) ;

descend() ;
var block;
if ((block = examine(node).isBlockStatement) && containsAwait(node)) {
if ((block = examine(node).isBlockStatement) && awaiting) {
// For this block, find all the hoistable classes, lets and consts
var classes = [] ;
var lets = [] ;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodent",
"version": "2.3.8",
"version": "2.3.9",
"description": "NoDent - Asynchronous Javascript language extensions",
"main": "nodent.js",
"scripts": {
Expand Down

0 comments on commit f0d07e9

Please sign in to comment.