Skip to content

Commit 0055c91

Browse files
committed
Bring back renamings in emitted d.ts files
1 parent 899117c commit 0055c91

6 files changed

+25
-37
lines changed

src/compiler/transformers/declarations.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ import {
116116
isFunctionDeclaration,
117117
isFunctionLike,
118118
isGlobalScopeAugmentation,
119-
isIdentifier,
120-
isIdentifierANonContextualKeyword,
121119
isIdentifierText,
122120
isImportDeclaration,
123121
isImportEqualsDeclaration,
@@ -684,7 +682,7 @@ export function transformDeclarations(context: TransformationContext) {
684682
return ret;
685683
}
686684

687-
function filterBindingPatternInitializersAndRenamings(name: BindingName) {
685+
function filterBindingPatternInitializers(name: BindingName) {
688686
if (name.kind === SyntaxKind.Identifier) {
689687
return name;
690688
}
@@ -705,21 +703,11 @@ export function transformDeclarations(context: TransformationContext) {
705703
if (elem.propertyName && isComputedPropertyName(elem.propertyName) && isEntityNameExpression(elem.propertyName.expression)) {
706704
checkEntityNameVisibility(elem.propertyName.expression, enclosingDeclaration);
707705
}
708-
if (elem.propertyName && isIdentifier(elem.propertyName) && isIdentifier(elem.name) && !elem.symbol.isReferenced && !isIdentifierANonContextualKeyword(elem.propertyName)) {
709-
// Unnecessary property renaming is forbidden in types, so remove renaming
710-
return factory.updateBindingElement(
711-
elem,
712-
elem.dotDotDotToken,
713-
/*propertyName*/ undefined,
714-
elem.propertyName,
715-
shouldPrintWithInitializer(elem) ? elem.initializer : undefined,
716-
);
717-
}
718706
return factory.updateBindingElement(
719707
elem,
720708
elem.dotDotDotToken,
721709
elem.propertyName,
722-
filterBindingPatternInitializersAndRenamings(elem.name),
710+
filterBindingPatternInitializers(elem.name),
723711
shouldPrintWithInitializer(elem) ? elem.initializer : undefined,
724712
);
725713
}
@@ -735,7 +723,7 @@ export function transformDeclarations(context: TransformationContext) {
735723
p,
736724
maskModifiers(factory, p, modifierMask),
737725
p.dotDotDotToken,
738-
filterBindingPatternInitializersAndRenamings(p.name),
726+
filterBindingPatternInitializers(p.name),
739727
resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(SyntaxKind.QuestionToken)) : undefined,
740728
ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param
741729
ensureNoInitializer(p),

tests/baselines/reference/declarationEmitBindingPatternsUnused.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function shouldKeep({ name: alias }) {
2626

2727

2828
//// [declarationEmitBindingPatternsUnused.d.ts]
29-
declare function shouldNotKeep({ name }: {
29+
declare function shouldNotKeep({ name: alias }: {
3030
name: string;
3131
}): void;
3232
declare function shouldNotKeepButIsKept({ name: alias }: {

tests/baselines/reference/declarationEmitKeywordDestructuring.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@ declare function f2({ function: _function, ...rest }: P): {
8888
await: boolean;
8989
one: boolean;
9090
};
91-
declare function f3({ abstract, ...rest }: P): {
91+
declare function f3({ abstract: _abstract, ...rest }: P): {
9292
enum: boolean;
9393
function: boolean;
9494
async: boolean;
9595
await: boolean;
9696
one: boolean;
9797
};
98-
declare function f4({ async, ...rest }: P): {
98+
declare function f4({ async: _async, ...rest }: P): {
9999
enum: boolean;
100100
function: boolean;
101101
abstract: boolean;
102102
await: boolean;
103103
one: boolean;
104104
};
105-
declare function f5({ await, ...rest }: P): {
105+
declare function f5({ await: _await, ...rest }: P): {
106106
enum: boolean;
107107
function: boolean;
108108
abstract: boolean;

tests/baselines/reference/destructuringInFunctionType.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type T3 = ([{
5454
}, {
5555
b: a;
5656
}]);
57-
type F3 = ([{ a }, { b }]: [{
57+
type F3 = ([{ a: b }, { b: a }]: [{
5858
a: any;
5959
}, {
6060
b: any;

tests/baselines/reference/paramterDestrcuturingDeclaration.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ interface C {
1212

1313
//// [paramterDestrcuturingDeclaration.d.ts]
1414
interface C {
15-
({ p }: {
15+
({ p: name }: {
1616
p: any;
1717
}): any;
18-
new ({ p }: {
18+
new ({ p: boolean }: {
1919
p: any;
2020
}): any;
2121
}

tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ type O = {
101101
c: number;
102102
};
103103
type F1 = (arg: number) => any;
104-
type F2 = ({ a }: O) => any;
105-
type F3 = ({ a, b, c }: O) => any;
106-
type F4 = ({ a }: O) => any;
107-
type F5 = ({ a, b, c }: O) => any;
104+
type F2 = ({ a: string }: O) => any;
105+
type F3 = ({ a: string, b, c }: O) => any;
106+
type F4 = ({ a: string }: O) => any;
107+
type F5 = ({ a: string, b, c }: O) => any;
108108
type F6 = ({ a: string }: {
109109
a: any;
110110
}) => typeof string;
111-
type F7 = ({ a, b: number }: {
111+
type F7 = ({ a: string, b: number }: {
112112
a: any;
113113
b: any;
114114
}) => typeof number;
@@ -118,14 +118,14 @@ type F8 = ({ a, b: number }: {
118118
}) => typeof number;
119119
type F9 = ([a, b, c]: [any, any, any]) => void;
120120
type G1 = new (arg: number) => any;
121-
type G2 = new ({ a }: O) => any;
122-
type G3 = new ({ a, b, c }: O) => any;
123-
type G4 = new ({ a }: O) => any;
124-
type G5 = new ({ a, b, c }: O) => any;
121+
type G2 = new ({ a: string }: O) => any;
122+
type G3 = new ({ a: string, b, c }: O) => any;
123+
type G4 = new ({ a: string }: O) => any;
124+
type G5 = new ({ a: string, b, c }: O) => any;
125125
type G6 = new ({ a: string }: {
126126
a: any;
127127
}) => typeof string;
128-
type G7 = new ({ a, b: number }: {
128+
type G7 = new ({ a: string, b: number }: {
129129
a: any;
130130
b: any;
131131
}) => typeof number;
@@ -156,19 +156,19 @@ type G13 = new ({ [2]: string }: {
156156
}) => void;
157157
interface I {
158158
method1(arg: number): any;
159-
method2({ a }: {
159+
method2({ a: string }: {
160160
a: any;
161161
}): any;
162162
(arg: number): any;
163-
({ a }: {
163+
({ a: string }: {
164164
a: any;
165165
}): any;
166166
new (arg: number): any;
167-
new ({ a }: {
167+
new ({ a: string }: {
168168
a: any;
169169
}): any;
170170
}
171-
declare function f1({ a }: O): void;
171+
declare function f1({ a: string }: O): void;
172172
declare const f2: ({ a: string }: O) => void;
173173
declare const f3: ({ a: string, b, c }: O) => void;
174174
declare const f4: ({ a: string }: O) => string;
@@ -179,7 +179,7 @@ declare const obj1: {
179179
declare const obj2: {
180180
method({ a: string }: O): string;
181181
};
182-
declare function f6({ a }: O): void;
182+
declare function f6({ a: string }: O): void;
183183
declare const f7: ({ a: string, b, c }: O) => void;
184184
declare const f8: ({ "a": string }: O) => void;
185185
declare function f9({ 2: string }: {

0 commit comments

Comments
 (0)