mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Merge pull request #853 from Microsoft/objectLiteralCompletion
Fix crash when getting member completion for an object literal
This commit is contained in:
commit
2d2c4a907d
@ -4508,8 +4508,21 @@ module ts {
|
||||
}
|
||||
else {
|
||||
error(node, Diagnostics.Supplied_parameters_do_not_match_any_signature_of_call_target);
|
||||
return resolveErrorCall(node);
|
||||
}
|
||||
|
||||
// No signature was applicable. We have already reported the errors for the invalid signature.
|
||||
// If this is a type resolution session, e.g. Language Service, try to get better information that anySignature.
|
||||
// Pick the first candidate that matches the arity. This way we can get a contextual type for cases like:
|
||||
// declare function f(a: { xa: number; xb: number; });
|
||||
// f({ |
|
||||
if (!fullTypeCheck) {
|
||||
for (var i = 0, n = candidates.length; i < n; i++) {
|
||||
if (signatureHasCorrectArity(node, candidates[i])) {
|
||||
return candidates[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resolveErrorCall(node);
|
||||
|
||||
// The candidate list orders groups in reverse, but within a group signatures are kept in declaration order
|
||||
|
||||
@ -1204,7 +1204,8 @@ module ts {
|
||||
}
|
||||
|
||||
public static toString(parts: SymbolDisplayPart[]) {
|
||||
return parts.map(p => p.text).join("");
|
||||
var result = map(parts, p => p.text);
|
||||
return result ? result.join("") : "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2162,9 +2162,16 @@ module ts {
|
||||
}
|
||||
|
||||
// TODO: this is a hack for now, we need a proper walking mechanism to verify that we have the correct node
|
||||
var mappedNode = getTouchingToken(sourceFile, TypeScript.end(node) - 1);
|
||||
if (isPunctuation(mappedNode.kind)) {
|
||||
mappedNode = mappedNode.parent;
|
||||
var precedingToken = findTokenOnLeftOfPosition(sourceFile, TypeScript.end(node));
|
||||
var mappedNode: Node;
|
||||
if (!precedingToken) {
|
||||
mappedNode = sourceFile;
|
||||
}
|
||||
else if (isPunctuation(precedingToken.kind)) {
|
||||
mappedNode = precedingToken.parent;
|
||||
}
|
||||
else {
|
||||
mappedNode = precedingToken;
|
||||
}
|
||||
|
||||
Debug.assert(mappedNode, "Could not map a Fidelity node to an AST node");
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////function f(a: { xa: number; xb: number; }) { }
|
||||
////var xc;
|
||||
////f({
|
||||
//// /**/
|
||||
|
||||
goTo.marker()
|
||||
verify.memberListContains('xa');
|
||||
verify.memberListContains('xb');
|
||||
verify.memberListCount(2);
|
||||
Loading…
x
Reference in New Issue
Block a user