From ac6c4944b0fa522d3efb3d9351fdb3277b4c21d9 Mon Sep 17 00:00:00 2001 From: Brian Frichette Date: Mon, 9 Nov 2015 23:08:32 -0800 Subject: [PATCH 1/3] Fix fnType for tern / acorn updates --- closure.js | 19 ++++++++++--------- package.json | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/closure.js b/closure.js index 1b5a3e5..b79ca62 100644 --- a/closure.js +++ b/closure.js @@ -275,7 +275,9 @@ function applyFnTypeInfo(fnType, comment) { } } - +function isFunExpr(node) { + return node.type == 'FunctionExpression' || node.type == 'ArrowFunctionExpression'; +} /** * If the given node is associated with a function, gets the type value for the * function. @@ -285,17 +287,16 @@ function applyFnTypeInfo(fnType, comment) { function getFnType(node) { if (node.type == 'VariableDeclaration') { var decl = node.declarations[0]; - if (decl.init && decl.init.type == 'FunctionExpression') { - return decl.init.body.scope.fnType; + if (decl.init && isFunExpr(decl.init)) { + return decl.init.scope.fnType; } } else if (node.type == 'FunctionDeclaration') { - return node.body.scope.fnType; - } else if (node.type == 'AssignmentExpression' && - node.right.type == 'FunctionExpression') { - return node.right.body.scope.fnType; - } else if (node.value && node.value.type == 'FunctionExpression') { + return node.scope.fnType; + } else if (node.type == 'AssignmentExpression' && isFunExpr(node.right)) { + return node.right.scope.fnType; + } else if (node.value && isFunExpr(node.value)) { // Object property. - return node.value.body.scope.fnType; + return node.value.scope.fnType; } return null; } diff --git a/package.json b/package.json index 3208a16..5078487 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "doctrine": "^0.5.2" }, "peerDependencies": { - "tern": "^0.13.0" + "tern": ">=0.15" }, "devDependencies": { "chai": "^1.9.1", From 26db26c7346d35da6d577eafcc8f581e8274f636 Mon Sep 17 00:00:00 2001 From: Brian Frichette Date: Wed, 18 Nov 2015 16:38:37 -0800 Subject: [PATCH 2/3] Fix loadEagerly --- closure.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/closure.js b/closure.js index b79ca62..f2b5c9f 100644 --- a/closure.js +++ b/closure.js @@ -177,9 +177,9 @@ function postInfer(ast, scope) { }, ObjectExpression: function(node) { for (var i = 0; i < node.properties.length; ++i) { - var prop = node.properties[i], key = prop.key; - interpretComments( - prop, key._closureComment, node.objType.getProp(key.name)); + var prop = node.properties[i], key = prop.key, propName = key && (key.name || key.value); + if (propName) interpretComments( + prop, key._closureComment, node.objType.getProp(propName)); } }, MemberExpression: function(node, scope) { From 0652e61e0e0c87f08cfb4f59c1e3ec40ee346aa1 Mon Sep 17 00:00:00 2001 From: Brian Frichette Date: Thu, 19 Nov 2015 01:59:12 -0800 Subject: [PATCH 3/3] Fix additional loadEagerly issue --- closure.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/closure.js b/closure.js index f2b5c9f..97167a1 100644 --- a/closure.js +++ b/closure.js @@ -177,7 +177,9 @@ function postInfer(ast, scope) { }, ObjectExpression: function(node) { for (var i = 0; i < node.properties.length; ++i) { - var prop = node.properties[i], key = prop.key, propName = key && (key.name || key.value); + var prop = node.properties[i], + key = prop.key, + propName = key && String(key.name || key.value); if (propName) interpretComments( prop, key._closureComment, node.objType.getProp(propName)); }