@@ -2671,7 +2671,7 @@ namespace ts {
26712671 }
26722672 Debug.assert(bindingElement.kind === SyntaxKind.BindingElement);
26732673 if (bindingElement.propertyName) {
2674- writer.writeSymbol (getTextOfNode(bindingElement.propertyName), bindingElement.symbol );
2674+ writer.writeProperty (getTextOfNode(bindingElement.propertyName));
26752675 writePunctuation(writer, SyntaxKind.ColonToken);
26762676 writeSpace(writer);
26772677 }
@@ -10443,33 +10443,37 @@ namespace ts {
1044310443 return baseConstructorType === nullWideningType;
1044410444 }
1044510445
10446+ function checkThisBeforeSuper(node: Node, container: Node, diagnosticMessage: DiagnosticMessage) {
10447+ const containingClassDecl = <ClassDeclaration>container.parent;
10448+ const baseTypeNode = getClassExtendsHeritageClauseElement(containingClassDecl);
10449+
10450+ // If a containing class does not have extends clause or the class extends null
10451+ // skip checking whether super statement is called before "this" accessing.
10452+ if (baseTypeNode && !classDeclarationExtendsNull(containingClassDecl)) {
10453+ const superCall = getSuperCallInConstructor(<ConstructorDeclaration>container);
10454+
10455+ // We should give an error in the following cases:
10456+ // - No super-call
10457+ // - "this" is accessing before super-call.
10458+ // i.e super(this)
10459+ // this.x; super();
10460+ // We want to make sure that super-call is done before accessing "this" so that
10461+ // "this" is not accessed as a parameter of the super-call.
10462+ if (!superCall || superCall.end > node.pos) {
10463+ // In ES6, super inside constructor of class-declaration has to precede "this" accessing
10464+ error(node, diagnosticMessage);
10465+ }
10466+ }
10467+ }
10468+
1044610469 function checkThisExpression(node: Node): Type {
1044710470 // Stop at the first arrow function so that we can
1044810471 // tell whether 'this' needs to be captured.
1044910472 let container = getThisContainer(node, /* includeArrowFunctions */ true);
1045010473 let needToCaptureLexicalThis = false;
1045110474
1045210475 if (container.kind === SyntaxKind.Constructor) {
10453- const containingClassDecl = <ClassDeclaration>container.parent;
10454- const baseTypeNode = getClassExtendsHeritageClauseElement(containingClassDecl);
10455-
10456- // If a containing class does not have extends clause or the class extends null
10457- // skip checking whether super statement is called before "this" accessing.
10458- if (baseTypeNode && !classDeclarationExtendsNull(containingClassDecl)) {
10459- const superCall = getSuperCallInConstructor(<ConstructorDeclaration>container);
10460-
10461- // We should give an error in the following cases:
10462- // - No super-call
10463- // - "this" is accessing before super-call.
10464- // i.e super(this)
10465- // this.x; super();
10466- // We want to make sure that super-call is done before accessing "this" so that
10467- // "this" is not accessed as a parameter of the super-call.
10468- if (!superCall || superCall.end > node.pos) {
10469- // In ES6, super inside constructor of class-declaration has to precede "this" accessing
10470- error(node, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class);
10471- }
10472- }
10476+ checkThisBeforeSuper(node, container, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class);
1047310477 }
1047410478
1047510479 // Now skip arrow functions to get the "real" owner of 'this'.
@@ -10617,6 +10621,10 @@ namespace ts {
1061710621 return unknownType;
1061810622 }
1061910623
10624+ if (!isCallExpression && container.kind === SyntaxKind.Constructor) {
10625+ checkThisBeforeSuper(node, container, Diagnostics.super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class);
10626+ }
10627+
1062010628 if ((getModifierFlags(container) & ModifierFlags.Static) || isCallExpression) {
1062110629 nodeCheckFlag = NodeCheckFlags.SuperStatic;
1062210630 }
@@ -13505,13 +13513,14 @@ namespace ts {
1350513513 const containingClass = getContainingClass(node);
1350613514 if (containingClass) {
1350713515 const containingType = getTypeOfNode(containingClass);
13508- const baseTypes = getBaseTypes(<InterfaceType> containingType);
13509- if (baseTypes.length) {
13516+ let baseTypes = getBaseTypes(containingType as InterfaceType );
13517+ while (baseTypes.length) {
1351013518 const baseType = baseTypes[0];
1351113519 if (modifiers & ModifierFlags.Protected &&
1351213520 baseType.symbol === declaration.parent.symbol) {
1351313521 return true;
1351413522 }
13523+ baseTypes = getBaseTypes(baseType as InterfaceType);
1351513524 }
1351613525 }
1351713526 if (modifiers & ModifierFlags.Private) {
@@ -16237,7 +16246,7 @@ namespace ts {
1623716246 return undefined;
1623816247 }
1623916248
16240- const onfulfilledParameterType = getTypeWithFacts(getUnionType(map(thenSignatures, getTypeOfFirstParameterOfSignature)), TypeFacts.NEUndefined );
16249+ const onfulfilledParameterType = getTypeWithFacts(getUnionType(map(thenSignatures, getTypeOfFirstParameterOfSignature)), TypeFacts.NEUndefinedOrNull );
1624116250 if (isTypeAny(onfulfilledParameterType)) {
1624216251 return undefined;
1624316252 }
@@ -16731,6 +16740,14 @@ namespace ts {
1673116740 }
1673216741 }
1673316742
16743+ function isRemovedPropertyFromObjectSpread(node: Node) {
16744+ if (isBindingElement(node) && isObjectBindingPattern(node.parent)) {
16745+ const lastElement = lastOrUndefined(node.parent.elements);
16746+ return lastElement !== node && !!lastElement.dotDotDotToken;
16747+ }
16748+ return false;
16749+ }
16750+
1673416751 function errorUnusedLocal(node: Node, name: string) {
1673516752 if (isIdentifierThatStartsWithUnderScore(node)) {
1673616753 const declaration = getRootDeclaration(node.parent);
@@ -16740,7 +16757,10 @@ namespace ts {
1674016757 return;
1674116758 }
1674216759 }
16743- error(node, Diagnostics._0_is_declared_but_never_used, name);
16760+
16761+ if (!isRemovedPropertyFromObjectSpread(node.kind === SyntaxKind.Identifier ? node.parent : node)) {
16762+ error(node, Diagnostics._0_is_declared_but_never_used, name);
16763+ }
1674416764 }
1674516765
1674616766 function parameterNameStartsWithUnderscore(parameterName: DeclarationName) {
0 commit comments