Skip to content

Commit c737bce

Browse files
Do not add alias back if it was never removed (such as in the case of keyword properties)
1 parent 44a6dd9 commit c737bce

6 files changed

+156
-115
lines changed

src/compiler/transformers/declarations.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,9 @@ export function transformDeclarations(context: TransformationContext) {
888888
return elem;
889889
}
890890
const usedAlias = aliases!.get(getOriginalNode(elem));
891-
if (usedAlias) {
891+
// If alias is used and property name was removed by filterBindingPatternInitializersAndRenamings
892+
// The alias can be preserved if it is a non contextual keyword.
893+
if (usedAlias && !elem.propertyName) {
892894
return factory.updateBindingElement(
893895
elem,
894896
elem.dotDotDotToken,

tests/baselines/reference/declarationEmitBindingPatternsUnused.errors.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
declarationEmitBindingPatternsUnused.ts(81,35): error TS2842: 'alias' is an unused renaming of 'name'. Did you intend to use it as a type annotation?
2-
declarationEmitBindingPatternsUnused.ts(85,41): error TS2842: 'alias' is an unused renaming of 'name'. Did you intend to use it as a type annotation?
3-
declarationEmitBindingPatternsUnused.ts(91,11): error TS2842: 'alias' is an unused renaming of 'name'. Did you intend to use it as a type annotation?
4-
declarationEmitBindingPatternsUnused.ts(92,15): error TS2842: 'alias' is an unused renaming of 'name'. Did you intend to use it as a type annotation?
5-
declarationEmitBindingPatternsUnused.ts(93,16): error TS2842: 'alias' is an unused renaming of 'name'. Did you intend to use it as a type annotation?
6-
declarationEmitBindingPatternsUnused.ts(94,12): error TS2842: 'alias' is an unused renaming of 'name'. Did you intend to use it as a type annotation?
1+
declarationEmitBindingPatternsUnused.ts(85,35): error TS2842: 'alias' is an unused renaming of 'name'. Did you intend to use it as a type annotation?
2+
declarationEmitBindingPatternsUnused.ts(89,41): error TS2842: 'alias' is an unused renaming of 'name'. Did you intend to use it as a type annotation?
3+
declarationEmitBindingPatternsUnused.ts(95,11): error TS2842: 'alias' is an unused renaming of 'name'. Did you intend to use it as a type annotation?
4+
declarationEmitBindingPatternsUnused.ts(96,15): error TS2842: 'alias' is an unused renaming of 'name'. Did you intend to use it as a type annotation?
5+
declarationEmitBindingPatternsUnused.ts(97,16): error TS2842: 'alias' is an unused renaming of 'name'. Did you intend to use it as a type annotation?
6+
declarationEmitBindingPatternsUnused.ts(98,12): error TS2842: 'alias' is an unused renaming of 'name'. Did you intend to use it as a type annotation?
77

88

99
==== declarationEmitBindingPatternsUnused.ts (6 errors) ====
@@ -26,6 +26,10 @@ declarationEmitBindingPatternsUnused.ts(94,12): error TS2842: 'alias' is an unus
2626
return alias;
2727
}
2828

29+
function referencedInSignartureKeyword({ function: alias }: { function: string }): typeof alias {
30+
return null!;
31+
}
32+
2933
function referencedInInferredType({ name: alias }: Named) {
3034
type Named2 = { name: typeof alias }
3135
return null! as Named2

tests/baselines/reference/declarationEmitBindingPatternsUnused.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ function referencedInSignarture({ name: alias }: Named): typeof alias {
2020
return alias;
2121
}
2222

23+
function referencedInSignartureKeyword({ function: alias }: { function: string }): typeof alias {
24+
return null!;
25+
}
26+
2327
function referencedInInferredType({ name: alias }: Named) {
2428
type Named2 = { name: typeof alias }
2529
return null! as Named2
@@ -122,6 +126,9 @@ function referencedInCode({ name: alias }) {
122126
function referencedInSignarture({ name: alias }) {
123127
return alias;
124128
}
129+
function referencedInSignartureKeyword({ function: alias }) {
130+
return null;
131+
}
125132
function referencedInInferredType({ name: alias }) {
126133
return null;
127134
}
@@ -191,6 +198,9 @@ declare function notReferencedNestedAlias({ p: { name } }: {
191198
declare function notReferencedArrayAlias([a, b, { name }]: Named[]): void;
192199
declare function referencedInCode({ name }: Named): string;
193200
declare function referencedInSignarture({ name: alias }: Named): typeof alias;
201+
declare function referencedInSignartureKeyword({ function: alias }: {
202+
function: string;
203+
}): typeof alias;
194204
declare function referencedInInferredType({ name: alias }: Named): {
195205
name: typeof alias;
196206
};

0 commit comments

Comments
 (0)