Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions closure.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,11 @@ 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 && String(key.name || key.value);
if (propName) interpretComments(
prop, key._closureComment, node.objType.getProp(propName));
}
},
MemberExpression: function(node, scope) {
Expand Down Expand Up @@ -275,7 +277,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.
Expand All @@ -285,17 +289,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;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"doctrine": "^0.5.2"
},
"peerDependencies": {
"tern": "^0.13.0"
"tern": ">=0.15"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tern is 0.16.0 version today.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware, and that is what I tested against, but this is compatible with >=0.15

},
"devDependencies": {
"chai": "^1.9.1",
Expand Down