mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Expose getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment with better name (#31564)
This commit is contained in:
parent
dfd28d2751
commit
b460d8cd26
@ -182,6 +182,10 @@ namespace ts {
|
||||
node = getParseTreeNode(node);
|
||||
return node ? getTypeOfNode(node) : errorType;
|
||||
},
|
||||
getTypeOfAssignmentPattern: nodeIn => {
|
||||
const node = getParseTreeNode(nodeIn, isAssignmentPattern);
|
||||
return node && getTypeOfAssignmentPattern(node) || errorType;
|
||||
},
|
||||
getPropertySymbolOfDestructuringAssignment: locationIn => {
|
||||
const location = getParseTreeNode(locationIn, isIdentifier);
|
||||
return location ? getPropertySymbolOfDestructuringAssignment(location) : undefined;
|
||||
@ -29982,7 +29986,7 @@ namespace ts {
|
||||
// }
|
||||
// [ a ] from
|
||||
// [a] = [ some array ...]
|
||||
function getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(expr: Expression): Type {
|
||||
function getTypeOfAssignmentPattern(expr: AssignmentPattern): Type | undefined {
|
||||
Debug.assert(expr.kind === SyntaxKind.ObjectLiteralExpression || expr.kind === SyntaxKind.ArrayLiteralExpression);
|
||||
// If this is from "for of"
|
||||
// for ( { a } of elems) {
|
||||
@ -30001,17 +30005,16 @@ namespace ts {
|
||||
// for ({ skills: { primary, secondary } } = multiRobot, i = 0; i < 1; i++) {
|
||||
if (expr.parent.kind === SyntaxKind.PropertyAssignment) {
|
||||
const node = cast(expr.parent.parent, isObjectLiteralExpression);
|
||||
const typeOfParentObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(node);
|
||||
const typeOfParentObjectLiteral = getTypeOfAssignmentPattern(node) || errorType;
|
||||
const propertyIndex = indexOfNode(node.properties, expr.parent);
|
||||
return checkObjectLiteralDestructuringPropertyAssignment(node, typeOfParentObjectLiteral || errorType, propertyIndex)!; // TODO: GH#18217
|
||||
return checkObjectLiteralDestructuringPropertyAssignment(node, typeOfParentObjectLiteral, propertyIndex);
|
||||
}
|
||||
// Array literal assignment - array destructuring pattern
|
||||
Debug.assert(expr.parent.kind === SyntaxKind.ArrayLiteralExpression);
|
||||
const node = cast(expr.parent, isArrayLiteralExpression);
|
||||
// [{ property1: p1, property2 }] = elems;
|
||||
const typeOfArrayLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(<Expression>expr.parent);
|
||||
const elementType = checkIteratedTypeOrElementType(typeOfArrayLiteral || errorType, expr.parent, /*allowStringInput*/ false, /*allowAsyncIterables*/ false) || errorType;
|
||||
return checkArrayLiteralDestructuringElementAssignment(<ArrayLiteralExpression>expr.parent, typeOfArrayLiteral,
|
||||
(<ArrayLiteralExpression>expr.parent).elements.indexOf(expr), elementType || errorType)!; // TODO: GH#18217
|
||||
const typeOfArrayLiteral = getTypeOfAssignmentPattern(node) || errorType;
|
||||
const elementType = checkIteratedTypeOrElementType(typeOfArrayLiteral, expr.parent, /*allowStringInput*/ false, /*allowAsyncIterables*/ false) || errorType;
|
||||
return checkArrayLiteralDestructuringElementAssignment(node, typeOfArrayLiteral, node.elements.indexOf(expr), elementType);
|
||||
}
|
||||
|
||||
// Gets the property symbol corresponding to the property in destructuring assignment
|
||||
@ -30022,7 +30025,7 @@ namespace ts {
|
||||
// [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);
|
||||
const typeOfObjectLiteral = getTypeOfAssignmentPattern(cast(location.parent.parent, isAssignmentPattern));
|
||||
return typeOfObjectLiteral && getPropertyOfType(typeOfObjectLiteral, location.escapedText);
|
||||
}
|
||||
|
||||
|
||||
@ -3154,6 +3154,7 @@ namespace ts {
|
||||
*/
|
||||
getExportSymbolOfSymbol(symbol: Symbol): Symbol;
|
||||
getPropertySymbolOfDestructuringAssignment(location: Identifier): Symbol | undefined;
|
||||
getTypeOfAssignmentPattern(pattern: AssignmentPattern): Type;
|
||||
getTypeAtLocation(node: Node): Type;
|
||||
getTypeFromTypeNode(node: TypeNode): Type;
|
||||
|
||||
|
||||
@ -1969,6 +1969,7 @@ declare namespace ts {
|
||||
*/
|
||||
getExportSymbolOfSymbol(symbol: Symbol): Symbol;
|
||||
getPropertySymbolOfDestructuringAssignment(location: Identifier): Symbol | undefined;
|
||||
getTypeOfAssignmentPattern(pattern: AssignmentPattern): Type;
|
||||
getTypeAtLocation(node: Node): Type;
|
||||
getTypeFromTypeNode(node: TypeNode): Type;
|
||||
signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): string;
|
||||
|
||||
@ -1969,6 +1969,7 @@ declare namespace ts {
|
||||
*/
|
||||
getExportSymbolOfSymbol(symbol: Symbol): Symbol;
|
||||
getPropertySymbolOfDestructuringAssignment(location: Identifier): Symbol | undefined;
|
||||
getTypeOfAssignmentPattern(pattern: AssignmentPattern): Type;
|
||||
getTypeAtLocation(node: Node): Type;
|
||||
getTypeFromTypeNode(node: TypeNode): Type;
|
||||
signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): string;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user