* Aggregates relevant symbols for completion in object literals and object binding patterns. * Relevant symbols are stored in the captured 'symbols' variable. * * @returns true if 'symbols' was successfully populated; false otherwise.
()
| 134300 | * @returns true if 'symbols' was successfully populated; false otherwise. |
| 134301 | */ |
| 134302 | function tryGetObjectLikeCompletionSymbols() { |
| 134303 | var symbolsStartIndex = symbols.length; |
| 134304 | var objectLikeContainer = tryGetObjectLikeCompletionContainer(contextToken); |
| 134305 | if (!objectLikeContainer) |
| 134306 | return 0 /* GlobalsSearch.Continue */; |
| 134307 | // We're looking up possible property names from contextual/inferred/declared type. |
| 134308 | completionKind = 0 /* CompletionKind.ObjectPropertyDeclaration */; |
| 134309 | var typeMembers; |
| 134310 | var existingMembers; |
| 134311 | if (objectLikeContainer.kind === 205 /* SyntaxKind.ObjectLiteralExpression */) { |
| 134312 | var instantiatedType = tryGetObjectLiteralContextualType(objectLikeContainer, typeChecker); |
| 134313 | // Check completions for Object property value shorthand |
| 134314 | if (instantiatedType === undefined) { |
| 134315 | if (objectLikeContainer.flags & 33554432 /* NodeFlags.InWithStatement */) { |
| 134316 | return 2 /* GlobalsSearch.Fail */; |
| 134317 | } |
| 134318 | isNonContextualObjectLiteral = true; |
| 134319 | return 0 /* GlobalsSearch.Continue */; |
| 134320 | } |
| 134321 | var completionsType = typeChecker.getContextualType(objectLikeContainer, 4 /* ContextFlags.Completions */); |
| 134322 | var hasStringIndexType = (completionsType || instantiatedType).getStringIndexType(); |
| 134323 | var hasNumberIndextype = (completionsType || instantiatedType).getNumberIndexType(); |
| 134324 | isNewIdentifierLocation = !!hasStringIndexType || !!hasNumberIndextype; |
| 134325 | typeMembers = getPropertiesForObjectExpression(instantiatedType, completionsType, objectLikeContainer, typeChecker); |
| 134326 | existingMembers = objectLikeContainer.properties; |
| 134327 | if (typeMembers.length === 0) { |
| 134328 | // Edge case: If NumberIndexType exists |
| 134329 | if (!hasNumberIndextype) { |
| 134330 | isNonContextualObjectLiteral = true; |
| 134331 | return 0 /* GlobalsSearch.Continue */; |
| 134332 | } |
| 134333 | } |
| 134334 | } |
| 134335 | else { |
| 134336 | ts.Debug.assert(objectLikeContainer.kind === 201 /* SyntaxKind.ObjectBindingPattern */); |
| 134337 | // We are *only* completing on properties from the type being destructured. |
| 134338 | isNewIdentifierLocation = false; |
| 134339 | var rootDeclaration = ts.getRootDeclaration(objectLikeContainer.parent); |
| 134340 | if (!ts.isVariableLike(rootDeclaration)) |
| 134341 | return ts.Debug.fail("Root declaration is not variable-like."); |
| 134342 | // We don't want to complete using the type acquired by the shape |
| 134343 | // of the binding pattern; we are only interested in types acquired |
| 134344 | // through type declaration or inference. |
| 134345 | // Also proceed if rootDeclaration is a parameter and if its containing function expression/arrow function is contextually typed - |
| 134346 | // type of parameter will flow in from the contextual type of the function |
| 134347 | var canGetType = ts.hasInitializer(rootDeclaration) || !!ts.getEffectiveTypeAnnotationNode(rootDeclaration) || rootDeclaration.parent.parent.kind === 244 /* SyntaxKind.ForOfStatement */; |
| 134348 | if (!canGetType && rootDeclaration.kind === 164 /* SyntaxKind.Parameter */) { |
| 134349 | if (ts.isExpression(rootDeclaration.parent)) { |
| 134350 | canGetType = !!typeChecker.getContextualType(rootDeclaration.parent); |
| 134351 | } |
| 134352 | else if (rootDeclaration.parent.kind === 169 /* SyntaxKind.MethodDeclaration */ || rootDeclaration.parent.kind === 173 /* SyntaxKind.SetAccessor */) { |
| 134353 | canGetType = ts.isExpression(rootDeclaration.parent.parent) && !!typeChecker.getContextualType(rootDeclaration.parent.parent); |
| 134354 | } |
| 134355 | } |
| 134356 | if (canGetType) { |
| 134357 | var typeForObject_1 = typeChecker.getTypeAtLocation(objectLikeContainer); |
| 134358 | if (!typeForObject_1) |
| 134359 | return 2 /* GlobalsSearch.Fail */; |
no test coverage detected