Skip to content

Commit ec6ae1c

Browse files
authored
Partially revert #41044, restoring parameter destructurings in d.ts files (#50779)
1 parent 28232ca commit ec6ae1c

26 files changed

+190
-129
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6116,29 +6116,19 @@ namespace ts {
61166116
return parameterNode;
61176117

61186118
function cloneBindingName(node: BindingName): BindingName {
6119-
return elideInitializerAndPropertyRenamingAndSetEmitFlags(node) as BindingName;
6120-
function elideInitializerAndPropertyRenamingAndSetEmitFlags(node: Node): Node {
6119+
return elideInitializerAndSetEmitFlags(node) as BindingName;
6120+
function elideInitializerAndSetEmitFlags(node: Node): Node {
61216121
if (context.tracker.trackSymbol && isComputedPropertyName(node) && isLateBindableName(node)) {
61226122
trackComputedName(node.expression, context.enclosingDeclaration, context);
61236123
}
6124-
let visited = visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags)!;
6124+
let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!;
61256125
if (isBindingElement(visited)) {
6126-
if (visited.propertyName && isIdentifier(visited.propertyName) && isIdentifier(visited.name) && !isStringAKeyword(idText(visited.propertyName))) {
6127-
visited = factory.updateBindingElement(
6128-
visited,
6129-
visited.dotDotDotToken,
6130-
/* propertyName*/ undefined,
6131-
visited.propertyName,
6132-
/*initializer*/ undefined);
6133-
}
6134-
else {
6135-
visited = factory.updateBindingElement(
6136-
visited,
6137-
visited.dotDotDotToken,
6138-
visited.propertyName,
6139-
visited.name,
6140-
/*initializer*/ undefined);
6141-
}
6126+
visited = factory.updateBindingElement(
6127+
visited,
6128+
visited.dotDotDotToken,
6129+
visited.propertyName,
6130+
visited.name,
6131+
/*initializer*/ undefined);
61426132
}
61436133
if (!nodeIsSynthesized(visited)) {
61446134
visited = factory.cloneNode(visited);

tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface Show {
55
>x : number
66
}
77
function f({ show: showRename = v => v }: Show) {}
8-
>f : ({ show }: Show) => void
8+
>f : ({ show: showRename }: Show) => void
99
>show : any
1010
>showRename : (x: number) => string
1111
>v => v : (v: number) => number
@@ -32,7 +32,7 @@ interface Nested {
3232
>nested : Show
3333
}
3434
function ff({ nested: nestedRename = { show: v => v } }: Nested) {}
35-
>ff : ({ nested }: Nested) => void
35+
>ff : ({ nested: nestedRename }: Nested) => void
3636
>nested : any
3737
>nestedRename : Show
3838
>{ show: v => v } : { show: (v: number) => number; }

tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ export interface GetLocalesOptions<T extends LocaleData> {
4444
config?: LocaleConfig<T> | undefined;
4545
name?: string;
4646
}
47-
export declare const getLocales: <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>;
47+
export declare const getLocales: <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>;
4848
export {};

tests/baselines/reference/declarationEmitBindingPatternWithReservedWord.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export interface GetLocalesOptions<T extends LocaleData> {
2626
}
2727

2828
export const getLocales = <T extends LocaleData>({
29-
>getLocales : <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>
30-
><T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig = {},}: GetLocalesOptions<T>): ConvertLocaleConfig<T> => { return defaultLocalesConfig;} : <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>
29+
>getLocales : <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>
30+
><T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig = {},}: GetLocalesOptions<T>): ConvertLocaleConfig<T> => { return defaultLocalesConfig;} : <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>
3131

3232
app,
3333
>app : unknown

tests/baselines/reference/declarationEmitBindingPatterns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function f(_a, _b, _c) {
1818

1919

2020
//// [declarationEmitBindingPatterns.d.ts]
21-
declare const k: ({ x }: {
21+
declare const k: ({ x: z }: {
2222
x?: string;
2323
}) => void;
2424
declare var a: any;

tests/baselines/reference/declarationEmitBindingPatterns.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== tests/cases/compiler/declarationEmitBindingPatterns.ts ===
22
const k = ({x: z = 'y'}) => { }
3-
>k : ({ x }: { x?: string; }) => void
4-
>({x: z = 'y'}) => { } : ({ x }: { x?: string; }) => void
3+
>k : ({ x: z }: { x?: string; }) => void
4+
>({x: z = 'y'}) => { } : ({ x: z }: { x?: string; }) => void
55
>x : any
66
>z : string
77
>'y' : "y"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [declarationEmitDuplicateParameterDestructuring.ts]
2+
export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b;
3+
4+
export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b;
5+
6+
7+
8+
9+
//// [declarationEmitDuplicateParameterDestructuring.d.ts]
10+
export declare const fn1: ({ prop: a, prop: b }: {
11+
prop: number;
12+
}) => number;
13+
export declare const fn2: ({ prop: a }: {
14+
prop: number;
15+
}, { prop: b }: {
16+
prop: number;
17+
}) => number;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/compiler/declarationEmitDuplicateParameterDestructuring.ts ===
2+
export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b;
3+
>fn1 : Symbol(fn1, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 12))
4+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 43))
5+
>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 21))
6+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 43))
7+
>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 30))
8+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 43))
9+
>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 21))
10+
>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 30))
11+
12+
export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b;
13+
>fn2 : Symbol(fn2, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 12))
14+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 34))
15+
>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 21))
16+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 34))
17+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 65))
18+
>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 52))
19+
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 65))
20+
>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 21))
21+
>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 52))
22+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/compiler/declarationEmitDuplicateParameterDestructuring.ts ===
2+
export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b;
3+
>fn1 : ({ prop: a, prop: b }: { prop: number;}) => number
4+
>({ prop: a, prop: b }: { prop: number }) => a + b : ({ prop: a, prop: b }: { prop: number;}) => number
5+
>prop : any
6+
>a : number
7+
>prop : any
8+
>b : number
9+
>prop : number
10+
>a + b : number
11+
>a : number
12+
>b : number
13+
14+
export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b;
15+
>fn2 : ({ prop: a }: { prop: number;}, { prop: b }: { prop: number;}) => number
16+
>({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b : ({ prop: a }: { prop: number;}, { prop: b }: { prop: number;}) => number
17+
>prop : any
18+
>a : number
19+
>prop : number
20+
>prop : any
21+
>b : number
22+
>prop : number
23+
>a + b : number
24+
>a : number
25+
>b : number
26+

tests/baselines/reference/declarationsAndAssignments.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ function f13() {
417417
}
418418

419419
function f14([a = 1, [b = "hello", { x, y: c = false }]]) {
420-
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
420+
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
421421
>a : number
422422
>1 : 1
423423
>b : string
@@ -438,7 +438,7 @@ function f14([a = 1, [b = "hello", { x, y: c = false }]]) {
438438
}
439439
f14([2, ["abc", { x: 0, y: true }]]);
440440
>f14([2, ["abc", { x: 0, y: true }]]) : void
441-
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
441+
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
442442
>[2, ["abc", { x: 0, y: true }]] : [number, [string, { x: number; y: true; }]]
443443
>2 : 2
444444
>["abc", { x: 0, y: true }] : [string, { x: number; y: true; }]
@@ -451,7 +451,7 @@ f14([2, ["abc", { x: 0, y: true }]]);
451451

452452
f14([2, ["abc", { x: 0 }]]);
453453
>f14([2, ["abc", { x: 0 }]]) : void
454-
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
454+
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
455455
>[2, ["abc", { x: 0 }]] : [number, [string, { x: number; }]]
456456
>2 : 2
457457
>["abc", { x: 0 }] : [string, { x: number; }]
@@ -462,7 +462,7 @@ f14([2, ["abc", { x: 0 }]]);
462462

463463
f14([2, ["abc", { y: false }]]); // Error, no x
464464
>f14([2, ["abc", { y: false }]]) : void
465-
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
465+
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
466466
>[2, ["abc", { y: false }]] : [number, [string, { y: false; }]]
467467
>2 : 2
468468
>["abc", { y: false }] : [string, { y: false; }]

0 commit comments

Comments
 (0)