Update the entry point to return property symbol of destructuring assignment
This commit is contained in:
parent
958a6a41ad
commit
c492fc6369
3 changed files with 17 additions and 10 deletions
|
@ -83,7 +83,7 @@ namespace ts {
|
|||
getShorthandAssignmentValueSymbol,
|
||||
getExportSpecifierLocalTargetSymbol,
|
||||
getTypeAtLocation: getTypeOfNode,
|
||||
getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment,
|
||||
getPropertySymbolOfDestructuringAssignment,
|
||||
typeToString,
|
||||
getSymbolDisplayBuilder,
|
||||
symbolToString,
|
||||
|
@ -16568,6 +16568,7 @@ namespace ts {
|
|||
// [ a ] from
|
||||
// [a] = [ some array ...]
|
||||
function getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(expr: Expression): Type {
|
||||
Debug.assert(expr.kind === SyntaxKind.ObjectLiteralExpression || expr.kind === SyntaxKind.ArrayLiteralExpression);
|
||||
// If this is from "for of"
|
||||
// for ( { a } of elems) {
|
||||
// }
|
||||
|
@ -16596,6 +16597,18 @@ namespace ts {
|
|||
indexOf((<ArrayLiteralExpression>expr.parent).elements, expr), elementType || unknownType);
|
||||
}
|
||||
|
||||
// Gets the property symbol corresponding to the property in destructuring assignment
|
||||
// 'property1' from
|
||||
// for ( { property1: a } of elems) {
|
||||
// }
|
||||
// 'property1' at location 'a' from:
|
||||
// [a] = [ property1, property2 ]
|
||||
function getPropertySymbolOfDestructuringAssignment(location: Identifier) {
|
||||
// Get the type of the object or array literal and then look for property of given name in the type
|
||||
const typeOfObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(<Expression>location.parent.parent);
|
||||
return typeOfObjectLiteral && getPropertyOfType(typeOfObjectLiteral, location.text);
|
||||
}
|
||||
|
||||
function getTypeOfExpression(expr: Expression): Type {
|
||||
if (isRightSideOfQualifiedNameOrPropertyAccess(expr)) {
|
||||
expr = <Expression>expr.parent;
|
||||
|
|
|
@ -1735,7 +1735,7 @@ namespace ts {
|
|||
getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): Symbol[];
|
||||
getShorthandAssignmentValueSymbol(location: Node): Symbol;
|
||||
getExportSpecifierLocalTargetSymbol(location: ExportSpecifier): Symbol;
|
||||
getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(expression: Expression): Type;
|
||||
getPropertySymbolOfDestructuringAssignment(location: Identifier): Symbol;
|
||||
getTypeAtLocation(node: Node): Type;
|
||||
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
|
||||
symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string;
|
||||
|
|
|
@ -5651,14 +5651,8 @@ namespace ts {
|
|||
}
|
||||
|
||||
function getPropertySymbolOfDestructuringAssignment(location: Node) {
|
||||
if (isArrayLiteralOrObjectLiteralDestructuringPattern(location.parent.parent)) {
|
||||
// Do work to determine if this is a property symbol corresponding to the search symbol
|
||||
const typeOfObjectLiteral = typeChecker.getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(<Expression>location.parent.parent);
|
||||
if (typeOfObjectLiteral) {
|
||||
return typeChecker.getPropertyOfType(typeOfObjectLiteral, (<Identifier>location).text);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
return isArrayLiteralOrObjectLiteralDestructuringPattern(location.parent.parent) &&
|
||||
typeChecker.getPropertySymbolOfDestructuringAssignment(<Identifier>location);
|
||||
}
|
||||
|
||||
function isObjectBindingPatternElementWithoutPropertyName(symbol: Symbol) {
|
||||
|
|
Loading…
Reference in a new issue