@@ -23370,14 +23370,16 @@ namespace ts {
23370
23370
if (strictNullChecks && properties.length === 0) {
23371
23371
return checkNonNullType(sourceType, node);
23372
23372
}
23373
- for (const p of properties) {
23374
- checkObjectLiteralDestructuringPropertyAssignment(sourceType, p , properties, rightIsThis);
23373
+ for (let i = 0; i < properties.length; i++ ) {
23374
+ checkObjectLiteralDestructuringPropertyAssignment(node, sourceType, i , properties, rightIsThis);
23375
23375
}
23376
23376
return sourceType;
23377
23377
}
23378
23378
23379
23379
/** Note: If property cannot be a SpreadAssignment, then allProperties does not need to be provided */
23380
- function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike, allProperties?: NodeArray<ObjectLiteralElementLike>, rightIsThis = false) {
23380
+ function checkObjectLiteralDestructuringPropertyAssignment(node: ObjectLiteralExpression, objectLiteralType: Type, propertyIndex: number, allProperties?: NodeArray<ObjectLiteralElementLike>, rightIsThis = false) {
23381
+ const properties = node.properties;
23382
+ const property = properties[propertyIndex];
23381
23383
if (property.kind === SyntaxKind.PropertyAssignment || property.kind === SyntaxKind.ShorthandPropertyAssignment) {
23382
23384
const name = property.name;
23383
23385
const exprType = getLiteralTypeFromPropertyName(name);
@@ -23394,18 +23396,25 @@ namespace ts {
23394
23396
return checkDestructuringAssignment(property.kind === SyntaxKind.ShorthandPropertyAssignment ? property : property.initializer, type);
23395
23397
}
23396
23398
else if (property.kind === SyntaxKind.SpreadAssignment) {
23397
- if (languageVersion < ScriptTarget.ESNext ) {
23398
- checkExternalEmitHelpers (property, ExternalEmitHelpers.Rest );
23399
+ if (propertyIndex < properties.length - 1 ) {
23400
+ error (property, Diagnostics.A_rest_element_must_be_last_in_a_destructuring_pattern );
23399
23401
}
23400
- const nonRestNames: PropertyName[] = [];
23401
- if (allProperties) {
23402
- for (let i = 0; i < allProperties.length - 1; i++) {
23403
- nonRestNames.push(allProperties[i].name!);
23402
+ else {
23403
+ if (languageVersion < ScriptTarget.ESNext) {
23404
+ checkExternalEmitHelpers(property, ExternalEmitHelpers.Rest);
23405
+ }
23406
+ const nonRestNames: PropertyName[] = [];
23407
+ if (allProperties) {
23408
+ for (const otherProperty of allProperties) {
23409
+ if (!isSpreadAssignment(otherProperty)) {
23410
+ nonRestNames.push(otherProperty.name);
23411
+ }
23412
+ }
23404
23413
}
23414
+ const type = getRestType(objectLiteralType, nonRestNames, objectLiteralType.symbol);
23415
+ checkGrammarForDisallowedTrailingComma(allProperties, Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma);
23416
+ return checkDestructuringAssignment(property.expression, type);
23405
23417
}
23406
- const type = getRestType(objectLiteralType, nonRestNames, objectLiteralType.symbol);
23407
- checkGrammarForDisallowedTrailingComma(allProperties, Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma);
23408
- return checkDestructuringAssignment(property.expression, type);
23409
23418
}
23410
23419
else {
23411
23420
error(property, Diagnostics.Property_assignment_expected);
@@ -29964,8 +29973,10 @@ namespace ts {
29964
29973
// If this is from nested object binding pattern
29965
29974
// for ({ skills: { primary, secondary } } = multiRobot, i = 0; i < 1; i++) {
29966
29975
if (expr.parent.kind === SyntaxKind.PropertyAssignment) {
29967
- const typeOfParentObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(<Expression>expr.parent.parent);
29968
- return checkObjectLiteralDestructuringPropertyAssignment(typeOfParentObjectLiteral || errorType, <ObjectLiteralElementLike>expr.parent)!; // TODO: GH#18217
29976
+ const node = cast(expr.parent.parent, isObjectLiteralExpression);
29977
+ const typeOfParentObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(node);
29978
+ const propertyIndex = indexOfNode(node.properties, expr.parent);
29979
+ return checkObjectLiteralDestructuringPropertyAssignment(node, typeOfParentObjectLiteral || errorType, propertyIndex)!; // TODO: GH#18217
29969
29980
}
29970
29981
// Array literal assignment - array destructuring pattern
29971
29982
Debug.assert(expr.parent.kind === SyntaxKind.ArrayLiteralExpression);
0 commit comments