mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 07:45:18 -06:00
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
This commit is contained in:
parent
8b482b513d
commit
488d0eebd0
@ -6122,7 +6122,7 @@ namespace ts {
|
||||
}
|
||||
let visited = visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags)!;
|
||||
if (isBindingElement(visited)) {
|
||||
if (visited.propertyName && isIdentifier(visited.propertyName) && isIdentifier(visited.name)) {
|
||||
if (visited.propertyName && isIdentifier(visited.propertyName) && isIdentifier(visited.name) && !isStringAKeyword(idText(visited.propertyName))) {
|
||||
visited = factory.updateBindingElement(
|
||||
visited,
|
||||
visited.dotDotDotToken,
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
//// [declarationEmitBindingPatternWithReservedWord.ts]
|
||||
type LocaleData = Record<string, never>
|
||||
type ConvertLocaleConfig<T extends LocaleData = LocaleData> = Record<
|
||||
string,
|
||||
T
|
||||
>;
|
||||
type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>>;
|
||||
|
||||
export interface GetLocalesOptions<T extends LocaleData> {
|
||||
app: unknown;
|
||||
default: ConvertLocaleConfig<T>;
|
||||
config?: LocaleConfig<T> | undefined;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export const getLocales = <T extends LocaleData>({
|
||||
app,
|
||||
name,
|
||||
default: defaultLocalesConfig,
|
||||
config: userLocalesConfig = {},
|
||||
}: GetLocalesOptions<T>): ConvertLocaleConfig<T> => {
|
||||
return defaultLocalesConfig;
|
||||
};
|
||||
|
||||
|
||||
//// [declarationEmitBindingPatternWithReservedWord.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports.getLocales = void 0;
|
||||
var getLocales = function (_a) {
|
||||
var app = _a.app, name = _a.name, defaultLocalesConfig = _a["default"], _b = _a.config, userLocalesConfig = _b === void 0 ? {} : _b;
|
||||
return defaultLocalesConfig;
|
||||
};
|
||||
exports.getLocales = getLocales;
|
||||
|
||||
|
||||
//// [declarationEmitBindingPatternWithReservedWord.d.ts]
|
||||
type LocaleData = Record<string, never>;
|
||||
type ConvertLocaleConfig<T extends LocaleData = LocaleData> = Record<string, T>;
|
||||
type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>>;
|
||||
export interface GetLocalesOptions<T extends LocaleData> {
|
||||
app: unknown;
|
||||
default: ConvertLocaleConfig<T>;
|
||||
config?: LocaleConfig<T> | undefined;
|
||||
name?: string;
|
||||
}
|
||||
export declare const getLocales: <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>;
|
||||
export {};
|
||||
@ -0,0 +1,78 @@
|
||||
=== tests/cases/compiler/declarationEmitBindingPatternWithReservedWord.ts ===
|
||||
type LocaleData = Record<string, never>
|
||||
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
|
||||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
type ConvertLocaleConfig<T extends LocaleData = LocaleData> = Record<
|
||||
>ConvertLocaleConfig : Symbol(ConvertLocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 39))
|
||||
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 1, 25))
|
||||
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
|
||||
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
|
||||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
string,
|
||||
T
|
||||
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 1, 25))
|
||||
|
||||
>;
|
||||
type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>>;
|
||||
>LocaleConfig : Symbol(LocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 4, 2))
|
||||
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 5, 18))
|
||||
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
|
||||
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
|
||||
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
|
||||
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 5, 18))
|
||||
|
||||
export interface GetLocalesOptions<T extends LocaleData> {
|
||||
>GetLocalesOptions : Symbol(GetLocalesOptions, Decl(declarationEmitBindingPatternWithReservedWord.ts, 5, 82))
|
||||
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 7, 35))
|
||||
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
|
||||
|
||||
app: unknown;
|
||||
>app : Symbol(GetLocalesOptions.app, Decl(declarationEmitBindingPatternWithReservedWord.ts, 7, 58))
|
||||
|
||||
default: ConvertLocaleConfig<T>;
|
||||
>default : Symbol(GetLocalesOptions.default, Decl(declarationEmitBindingPatternWithReservedWord.ts, 8, 17))
|
||||
>ConvertLocaleConfig : Symbol(ConvertLocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 39))
|
||||
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 7, 35))
|
||||
|
||||
config?: LocaleConfig<T> | undefined;
|
||||
>config : Symbol(GetLocalesOptions.config, Decl(declarationEmitBindingPatternWithReservedWord.ts, 9, 36))
|
||||
>LocaleConfig : Symbol(LocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 4, 2))
|
||||
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 7, 35))
|
||||
|
||||
name?: string;
|
||||
>name : Symbol(GetLocalesOptions.name, Decl(declarationEmitBindingPatternWithReservedWord.ts, 10, 41))
|
||||
}
|
||||
|
||||
export const getLocales = <T extends LocaleData>({
|
||||
>getLocales : Symbol(getLocales, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 12))
|
||||
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 27))
|
||||
>LocaleData : Symbol(LocaleData, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 0))
|
||||
|
||||
app,
|
||||
>app : Symbol(app, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 50))
|
||||
|
||||
name,
|
||||
>name : Symbol(name, Decl(declarationEmitBindingPatternWithReservedWord.ts, 15, 8))
|
||||
|
||||
default: defaultLocalesConfig,
|
||||
>default : Symbol(GetLocalesOptions.default, Decl(declarationEmitBindingPatternWithReservedWord.ts, 8, 17))
|
||||
>defaultLocalesConfig : Symbol(defaultLocalesConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 16, 9))
|
||||
|
||||
config: userLocalesConfig = {},
|
||||
>config : Symbol(GetLocalesOptions.config, Decl(declarationEmitBindingPatternWithReservedWord.ts, 9, 36))
|
||||
>userLocalesConfig : Symbol(userLocalesConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 17, 34))
|
||||
|
||||
}: GetLocalesOptions<T>): ConvertLocaleConfig<T> => {
|
||||
>GetLocalesOptions : Symbol(GetLocalesOptions, Decl(declarationEmitBindingPatternWithReservedWord.ts, 5, 82))
|
||||
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 27))
|
||||
>ConvertLocaleConfig : Symbol(ConvertLocaleConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 0, 39))
|
||||
>T : Symbol(T, Decl(declarationEmitBindingPatternWithReservedWord.ts, 14, 27))
|
||||
|
||||
return defaultLocalesConfig;
|
||||
>defaultLocalesConfig : Symbol(defaultLocalesConfig, Decl(declarationEmitBindingPatternWithReservedWord.ts, 16, 9))
|
||||
|
||||
};
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
=== tests/cases/compiler/declarationEmitBindingPatternWithReservedWord.ts ===
|
||||
type LocaleData = Record<string, never>
|
||||
>LocaleData : { [x: string]: never; }
|
||||
|
||||
type ConvertLocaleConfig<T extends LocaleData = LocaleData> = Record<
|
||||
>ConvertLocaleConfig : ConvertLocaleConfig<T>
|
||||
|
||||
string,
|
||||
T
|
||||
>;
|
||||
type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>>;
|
||||
>LocaleConfig : LocaleConfig<T>
|
||||
|
||||
export interface GetLocalesOptions<T extends LocaleData> {
|
||||
app: unknown;
|
||||
>app : unknown
|
||||
|
||||
default: ConvertLocaleConfig<T>;
|
||||
>default : ConvertLocaleConfig<T>
|
||||
|
||||
config?: LocaleConfig<T> | undefined;
|
||||
>config : LocaleConfig<T>
|
||||
|
||||
name?: string;
|
||||
>name : string
|
||||
}
|
||||
|
||||
export const getLocales = <T extends LocaleData>({
|
||||
>getLocales : <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>
|
||||
><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>
|
||||
|
||||
app,
|
||||
>app : unknown
|
||||
|
||||
name,
|
||||
>name : string
|
||||
|
||||
default: defaultLocalesConfig,
|
||||
>default : any
|
||||
>defaultLocalesConfig : ConvertLocaleConfig<T>
|
||||
|
||||
config: userLocalesConfig = {},
|
||||
>config : any
|
||||
>userLocalesConfig : LocaleConfig<T>
|
||||
>{} : {}
|
||||
|
||||
}: GetLocalesOptions<T>): ConvertLocaleConfig<T> => {
|
||||
return defaultLocalesConfig;
|
||||
>defaultLocalesConfig : ConvertLocaleConfig<T>
|
||||
|
||||
};
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
// Error
|
||||
function a({while}) { }
|
||||
>a : ({ while }: { while: any; }) => void
|
||||
>a : ({ while: }: { while: any; }) => void
|
||||
>while : any
|
||||
> : any
|
||||
|
||||
@ -42,32 +42,32 @@ function a7(...a: string) { }
|
||||
|
||||
a({ while: 1 });
|
||||
>a({ while: 1 }) : void
|
||||
>a : ({ while }: { while: any; }) => void
|
||||
>a : ({ while: }: { while: any; }) => void
|
||||
>{ while: 1 } : { while: number; }
|
||||
>while : number
|
||||
>1 : 1
|
||||
|
||||
// No Error
|
||||
function b1({public: x}) { }
|
||||
>b1 : ({ public }: { public: any; }) => void
|
||||
>b1 : ({ public: x }: { public: any; }) => void
|
||||
>public : any
|
||||
>x : any
|
||||
|
||||
function b2({while: y}) { }
|
||||
>b2 : ({ while }: { while: any; }) => void
|
||||
>b2 : ({ while: y }: { while: any; }) => void
|
||||
>while : any
|
||||
>y : any
|
||||
|
||||
b1({ public: 1 });
|
||||
>b1({ public: 1 }) : void
|
||||
>b1 : ({ public }: { public: any; }) => void
|
||||
>b1 : ({ public: x }: { public: any; }) => void
|
||||
>{ public: 1 } : { public: number; }
|
||||
>public : number
|
||||
>1 : 1
|
||||
|
||||
b2({ while: 1 });
|
||||
>b2({ while: 1 }) : void
|
||||
>b2 : ({ while }: { while: any; }) => void
|
||||
>b2 : ({ while: y }: { while: any; }) => void
|
||||
>{ while: 1 } : { while: number; }
|
||||
>while : number
|
||||
>1 : 1
|
||||
|
||||
@ -13,7 +13,7 @@ import("package").then(({default: foo}) => foo(42));
|
||||
>import("package") : Promise<{ default: (x: number) => string; }>
|
||||
>"package" : "package"
|
||||
>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>
|
||||
>({default: foo}) => foo(42) : ({ default }: { default: (x: number) => string; }) => string
|
||||
>({default: foo}) => foo(42) : ({ default: foo }: { default: (x: number) => string; }) => string
|
||||
>default : any
|
||||
>foo : (x: number) => string
|
||||
>foo(42) : string
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
// @declaration: true
|
||||
type LocaleData = Record<string, never>
|
||||
type ConvertLocaleConfig<T extends LocaleData = LocaleData> = Record<
|
||||
string,
|
||||
T
|
||||
>;
|
||||
type LocaleConfig<T extends LocaleData = LocaleData> = Record<string, Partial<T>>;
|
||||
|
||||
export interface GetLocalesOptions<T extends LocaleData> {
|
||||
app: unknown;
|
||||
default: ConvertLocaleConfig<T>;
|
||||
config?: LocaleConfig<T> | undefined;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export const getLocales = <T extends LocaleData>({
|
||||
app,
|
||||
name,
|
||||
default: defaultLocalesConfig,
|
||||
config: userLocalesConfig = {},
|
||||
}: GetLocalesOptions<T>): ConvertLocaleConfig<T> => {
|
||||
return defaultLocalesConfig;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user