Skip to content
Closed
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
17 changes: 17 additions & 0 deletions lib/infer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,10 @@
scope.fnType && scope.fnType.args.indexOf(self) > -1)
maybeInstantiate(scope, 30);
self.propagate(new HasMethodCall(pName, args, node.arguments, out));
if (self.getType() && self.getType().hasProp && self.getType().hasProp(pName) && self.getType().hasProp(pName).getFunctionType()) {
var fnType = self.getType().hasProp(pName).getFunctionType();
expObjType(fnType, node, scope);
}
} else {
var callee = infer(node.callee, scope, c);
if (scope.fnType && scope.fnType.args.indexOf(callee) > -1)
Expand Down Expand Up @@ -1095,6 +1099,18 @@
})
};

function expObjType(fnType, node, scope) {
var fnArgs = fnType.args, argNodes = node.arguments;
for (var i = 0; i < argNodes.length; ++i) {
if (fnArgs && fnArgs[i] && fnArgs[i] instanceof Obj) {
if (argNodes[i].type == "Identifier") {
var refNode = scope.props[argNodes[i].name];
if (refNode && refNode.getType() && refNode.getType().originNode) refNode.getType().originNode.expObjType = fnArgs[i];
} else argNodes[i].expObjType = fnArgs[i];
}
}
}

function infer(node, scope, c, out, name) {
return inferExprVisitor[node.type](node, scope, c, out, name);
}
Expand Down Expand Up @@ -1314,6 +1330,7 @@
CallExpression: function(node, scope) {
var f = findType(node.callee, scope).getFunctionType();
if (!f) return ANull;
expObjType(f, node, scope);
if (f.computeRet) {
for (var i = 0, args = []; i < node.arguments.length; ++i)
args.push(findType(node.arguments[i], scope));
Expand Down
13 changes: 13 additions & 0 deletions lib/tern.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,19 @@
objType = infer.def.parsePath(path, file.scope).getType();
prop = word;
}
} else {
// completion for properties of object literal.
var objExpr = infer.findExpressionAround(file.ast, null, wordStart, file.scope, "ObjectExpression");
if (objExpr) {
if (!objExpr.node.expObjType) {
var callExpr = infer.findExpressionAround(file.ast, null, wordStart, file.scope, "CallExpression");
if (callExpr) infer.expressionType(callExpr);
}
if (objExpr && objExpr.node && objExpr.node.expObjType) {
objType = objExpr.node.expObjType.getType();
prop = word;
}
}
}

if (prop != null) {
Expand Down
42 changes: 41 additions & 1 deletion plugin/requirejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,53 @@
uri: "string",
config: "fn() -> ?",
exports: "?"
},
config: {
baseUrl: {
"!type": "string",
"!doc": "the root path to use for all module lookups",
"!url": "http://requirejs.org/docs/api.html#config-baseUrl"
},
paths: {
"!type": "?",
"!doc": "path mappings for module names not found directly under baseUrl. The path settings are assumed to be relative to baseUrl, unless the paths setting starts with a '/' or has a URL protocol in it ('like http:').",
"!url": "http://requirejs.org/docs/api.html#config-paths"
},
shim: {
"!type": "?",
"!url": "http://requirejs.org/docs/api.html#config-shim"
},
map: {
"!type": "?",
"!url": "http://requirejs.org/docs/api.html#config-map"
},
config: {
"!type": "?",
"!url": "http://requirejs.org/docs/api.html#config-moduleconfig"
},
packages: {
"!type": "?",
"!url": "http://requirejs.org/docs/api.html#config-packages"
},
nodeIdCompat: {
"!type": "?",
"!url": "http://requirejs.org/docs/api.html#config-nodeIdCompat"
},
waitSeconds: {
"!type": "number",
"!url": "http://requirejs.org/docs/api.html#config-waitSeconds"
},
context: {
"!type": "number",
"!url": "http://requirejs.org/docs/api.html#config-context"
}
}
},
requirejs: {
"!type": "fn(deps: [string], callback: fn(), errback: fn()) -> !custom:requireJS",
onError: "fn(err: +Error)",
load: "fn(context: ?, moduleName: string, url: string)",
config: "fn(config: ?) -> !custom:requireJSConfig",
config: "fn(config: +config) -> !custom:requireJSConfig",
version: "string",
isBrowser: "bool"
},
Expand Down