Skip to content

Commit 488d0ee

Browse files
authoredAug 30, 2022
Retain name and propertyName in declaration emit copies of binding patterns if property name is a keyword (#50537)
* Retain name and propertyName in declaration emit copies of binding patterns if property name is a keyword * Accept baselines * Remove out of date file
1 parent 8b482b5 commit 488d0ee

7 files changed

+209
-8
lines changed
 

‎src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6122,7 +6122,7 @@ namespace ts {
61226122
}
61236123
let visited = visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags)!;
61246124
if (isBindingElement(visited)) {
6125-
if (visited.propertyName && isIdentifier(visited.propertyName) && isIdentifier(visited.name)) {
6125+
if (visited.propertyName && isIdentifier(visited.propertyName) && isIdentifier(visited.name) && !isStringAKeyword(idText(visited.propertyName))) {
61266126
visited = factory.updateBindingElement(
61276127
visited,
61286128
visited.dotDotDotToken,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//// [declarationEmitBindingPatternWithReservedWord.ts]
2+
type LocaleData = Record<string, never>
3+
type ConvertLocaleConfig<T extends LocaleData = LocaleData> = Record<
4+
string,
5+
T
6+
>;
7+
type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>>;
8+
9+
export interface GetLocalesOptions<T extends LocaleData> {
10+
app: unknown;
11+
default: ConvertLocaleConfig<T>;
12+
config?: LocaleConfig<T> | undefined;
13+
name?: string;
14+
}
15+
16+
export const getLocales = <T extends LocaleData>({
17+
app,
18+
name,
19+
default: defaultLocalesConfig,
20+
config: userLocalesConfig = {},
21+
}: GetLocalesOptions<T>): ConvertLocaleConfig<T> => {
22+
return defaultLocalesConfig;
23+
};
24+
25+
26+
//// [declarationEmitBindingPatternWithReservedWord.js]
27+
"use strict";
28+
exports.__esModule = true;
29+
exports.getLocales = void 0;
30+
var getLocales = function (_a) {
31+
var app = _a.app, name = _a.name, defaultLocalesConfig = _a["default"], _b = _a.config, userLocalesConfig = _b === void 0 ? {} : _b;
32+
return defaultLocalesConfig;
33+
};
34+
exports.getLocales = getLocales;
35+
36+
37+
//// [declarationEmitBindingPatternWithReservedWord.d.ts]
38+
type LocaleData = Record<string, never>;
39+
type ConvertLocaleConfig<T extends LocaleData = LocaleData> = Record<string, T>;
40+
type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>>;
41+
export interface GetLocalesOptions<T extends LocaleData> {
42+
app: unknown;
43+
default: ConvertLocaleConfig<T>;
44+
config?: LocaleConfig<T> | undefined;
45+
name?: string;
46+
}
47+
export declare const getLocales: <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>;
48+
export {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
=== tests/cases/compiler/declarationEmitBindingPatternWithReservedWord.ts ===
2+
type LocaleData = Record<string, never>
3+
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
4+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
5+
6+
type ConvertLocaleConfig<T extends LocaleData = LocaleData> = Record<
7+
>ConvertLocaleConfig : Symbol(ConvertLocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 39))
8+
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 1, 25))
9+
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
10+
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
11+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
12+
13+
string,
14+
T
15+
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 1, 25))
16+
17+
>;
18+
type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>>;
19+
>LocaleConfig : Symbol(LocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 4, 2))
20+
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 5, 18))
21+
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
22+
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
23+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
24+
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
25+
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 5, 18))
26+
27+
export interface GetLocalesOptions<T extends LocaleData> {
28+
>GetLocalesOptions : Symbol(GetLocalesOptions, Decl(declarationEmitBindingPatternWithReservedWord.ts, 5, 82))
29+
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 7, 35))
30+
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
31+
32+
app: unknown;
33+
>app : Symbol(GetLocalesOptions.app, Decl(declarationEmitBindingPatternWithReservedWord.ts, 7, 58))
34+
35+
default: ConvertLocaleConfig<T>;
36+
>default : Symbol(GetLocalesOptions.default, Decl(declarationEmitBindingPatternWithReservedWord.ts, 8, 17))
37+
>ConvertLocaleConfig : Symbol(ConvertLocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 39))
38+
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 7, 35))
39+
40+
config?: LocaleConfig<T> | undefined;
41+
>config : Symbol(GetLocalesOptions.config, Decl(declarationEmitBindingPatternWithReservedWord.ts, 9, 36))
42+
>LocaleConfig : Symbol(LocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 4, 2))
43+
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 7, 35))
44+
45+
name?: string;
46+
>name : Symbol(GetLocalesOptions.name, Decl(declarationEmitBindingPatternWithReservedWord.ts, 10, 41))
47+
}
48+
49+
export const getLocales = <T extends LocaleData>({
50+
>getLocales : Symbol(getLocales, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 12))
51+
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 27))
52+
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
53+
54+
app,
55+
>app : Symbol(app, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 50))
56+
57+
name,
58+
>name : Symbol(name, Decl(declarationEmitBindingPatternWithReservedWord.ts, 15, 8))
59+
60+
default: defaultLocalesConfig,
61+
>default : Symbol(GetLocalesOptions.default, Decl(declarationEmitBindingPatternWithReservedWord.ts, 8, 17))
62+
>defaultLocalesConfig : Symbol(defaultLocalesConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 16, 9))
63+
64+
config: userLocalesConfig = {},
65+
>config : Symbol(GetLocalesOptions.config, Decl(declarationEmitBindingPatternWithReservedWord.ts, 9, 36))
66+
>userLocalesConfig : Symbol(userLocalesConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 17, 34))
67+
68+
}: GetLocalesOptions<T>): ConvertLocaleConfig<T> => {
69+
>GetLocalesOptions : Symbol(GetLocalesOptions, Decl(declarationEmitBindingPatternWithReservedWord.ts, 5, 82))
70+
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 27))
71+
>ConvertLocaleConfig : Symbol(ConvertLocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 39))
72+
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 27))
73+
74+
return defaultLocalesConfig;
75+
>defaultLocalesConfig : Symbol(defaultLocalesConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 16, 9))
76+
77+
};
78+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
=== tests/cases/compiler/declarationEmitBindingPatternWithReservedWord.ts ===
2+
type LocaleData = Record<string, never>
3+
>LocaleData : { [x: string]: never; }
4+
5+
type ConvertLocaleConfig<T extends LocaleData = LocaleData> = Record<
6+
>ConvertLocaleConfig : ConvertLocaleConfig<T>
7+
8+
string,
9+
T
10+
>;
11+
type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>>;
12+
>LocaleConfig : LocaleConfig<T>
13+
14+
export interface GetLocalesOptions<T extends LocaleData> {
15+
app: unknown;
16+
>app : unknown
17+
18+
default: ConvertLocaleConfig<T>;
19+
>default : ConvertLocaleConfig<T>
20+
21+
config?: LocaleConfig<T> | undefined;
22+
>config : LocaleConfig<T>
23+
24+
name?: string;
25+
>name : string
26+
}
27+
28+
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>
31+
32+
app,
33+
>app : unknown
34+
35+
name,
36+
>name : string
37+
38+
default: defaultLocalesConfig,
39+
>default : any
40+
>defaultLocalesConfig : ConvertLocaleConfig<T>
41+
42+
config: userLocalesConfig = {},
43+
>config : any
44+
>userLocalesConfig : LocaleConfig<T>
45+
>{} : {}
46+
47+
}: GetLocalesOptions<T>): ConvertLocaleConfig<T> => {
48+
return defaultLocalesConfig;
49+
>defaultLocalesConfig : ConvertLocaleConfig<T>
50+
51+
};
52+

‎tests/baselines/reference/destructuringParameterDeclaration6.types

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// Error
99
function a({while}) { }
10-
>a : ({ while }: { while: any; }) => void
10+
>a : ({ while: }: { while: any; }) => void
1111
>while : any
1212
> : any
1313

@@ -42,32 +42,32 @@ function a7(...a: string) { }
4242

4343
a({ while: 1 });
4444
>a({ while: 1 }) : void
45-
>a : ({ while }: { while: any; }) => void
45+
>a : ({ while: }: { while: any; }) => void
4646
>{ while: 1 } : { while: number; }
4747
>while : number
4848
>1 : 1
4949

5050
// No Error
5151
function b1({public: x}) { }
52-
>b1 : ({ public }: { public: any; }) => void
52+
>b1 : ({ public: x }: { public: any; }) => void
5353
>public : any
5454
>x : any
5555

5656
function b2({while: y}) { }
57-
>b2 : ({ while }: { while: any; }) => void
57+
>b2 : ({ while: y }: { while: any; }) => void
5858
>while : any
5959
>y : any
6060

6161
b1({ public: 1 });
6262
>b1({ public: 1 }) : void
63-
>b1 : ({ public }: { public: any; }) => void
63+
>b1 : ({ public: x }: { public: any; }) => void
6464
>{ public: 1 } : { public: number; }
6565
>public : number
6666
>1 : 1
6767

6868
b2({ while: 1 });
6969
>b2({ while: 1 }) : void
70-
>b2 : ({ while }: { while: any; }) => void
70+
>b2 : ({ while: y }: { while: any; }) => void
7171
>{ while: 1 } : { while: number; }
7272
>while : number
7373
>1 : 1

‎tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import("package").then(({default: foo}) => foo(42));
1313
>import("package") : Promise<{ default: (x: number) => string; }>
1414
>"package" : "package"
1515
>then : <TResult1 = { default: (x: number) => string; }, TResult2 = never>(onfulfilled?: (value: { default: (x: number) => string; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
16-
>({default: foo}) => foo(42) : ({ default }: { default: (x: number) => string; }) => string
16+
>({default: foo}) => foo(42) : ({ default: foo }: { default: (x: number) => string; }) => string
1717
>default : any
1818
>foo : (x: number) => string
1919
>foo(42) : string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @declaration: true
2+
type LocaleData = Record<string, never>
3+
type ConvertLocaleConfig<T extends LocaleData = LocaleData> = Record<
4+
string,
5+
T
6+
>;
7+
type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>>;
8+
9+
export interface GetLocalesOptions<T extends LocaleData> {
10+
app: unknown;
11+
default: ConvertLocaleConfig<T>;
12+
config?: LocaleConfig<T> | undefined;
13+
name?: string;
14+
}
15+
16+
export const getLocales = <T extends LocaleData>({
17+
app,
18+
name,
19+
default: defaultLocalesConfig,
20+
config: userLocalesConfig = {},
21+
}: GetLocalesOptions<T>): ConvertLocaleConfig<T> => {
22+
return defaultLocalesConfig;
23+
};

0 commit comments

Comments
 (0)
Please sign in to comment.