Skip to content
Permalink
Browse files
Partially revert #41044, restoring parameter destructurings in d.ts f…
…iles (#50779)
  • Loading branch information
jakebailey committed Sep 15, 2022
1 parent 28232ca commit ec6ae1c4d0f48f15cd01b1502d0b2e5ac387dcf5
Show file tree
Hide file tree
Showing 26 changed files with 190 additions and 129 deletions.
@@ -6116,29 +6116,19 @@ namespace ts {
return parameterNode;

function cloneBindingName(node: BindingName): BindingName {
return elideInitializerAndPropertyRenamingAndSetEmitFlags(node) as BindingName;
function elideInitializerAndPropertyRenamingAndSetEmitFlags(node: Node): Node {
return elideInitializerAndSetEmitFlags(node) as BindingName;
function elideInitializerAndSetEmitFlags(node: Node): Node {
if (context.tracker.trackSymbol && isComputedPropertyName(node) && isLateBindableName(node)) {
trackComputedName(node.expression, context.enclosingDeclaration, context);
}
let visited = visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags)!;
let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!;
if (isBindingElement(visited)) {
if (visited.propertyName && isIdentifier(visited.propertyName) && isIdentifier(visited.name) && !isStringAKeyword(idText(visited.propertyName))) {
visited = factory.updateBindingElement(
visited,
visited.dotDotDotToken,
/* propertyName*/ undefined,
visited.propertyName,
/*initializer*/ undefined);
}
else {
visited = factory.updateBindingElement(
visited,
visited.dotDotDotToken,
visited.propertyName,
visited.name,
/*initializer*/ undefined);
}
visited = factory.updateBindingElement(
visited,
visited.dotDotDotToken,
visited.propertyName,
visited.name,
/*initializer*/ undefined);
}
if (!nodeIsSynthesized(visited)) {
visited = factory.cloneNode(visited);
@@ -5,7 +5,7 @@ interface Show {
>x : number
}
function f({ show: showRename = v => v }: Show) {}
>f : ({ show }: Show) => void
>f : ({ show: showRename }: Show) => void
>show : any
>showRename : (x: number) => string
>v => v : (v: number) => number
@@ -32,7 +32,7 @@ interface Nested {
>nested : Show
}
function ff({ nested: nestedRename = { show: v => v } }: Nested) {}
>ff : ({ nested }: Nested) => void
>ff : ({ nested: nestedRename }: Nested) => void
>nested : any
>nestedRename : Show
>{ show: v => v } : { show: (v: number) => number; }
@@ -44,5 +44,5 @@ export interface GetLocalesOptions<T extends LocaleData> {
config?: LocaleConfig<T> | undefined;
name?: string;
}
export declare const getLocales: <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>;
export declare const getLocales: <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>;
export {};
@@ -26,8 +26,8 @@ export interface GetLocalesOptions<T extends LocaleData> {
}

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>
>getLocales : <T extends LocaleData>({ app, name, default: defaultLocalesConfig, config: userLocalesConfig, }: 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: userLocalesConfig, }: GetLocalesOptions<T>) => ConvertLocaleConfig<T>

app,
>app : unknown
@@ -18,7 +18,7 @@ function f(_a, _b, _c) {


//// [declarationEmitBindingPatterns.d.ts]
declare const k: ({ x }: {
declare const k: ({ x: z }: {
x?: string;
}) => void;
declare var a: any;
@@ -1,7 +1,7 @@
=== tests/cases/compiler/declarationEmitBindingPatterns.ts ===
const k = ({x: z = 'y'}) => { }
>k : ({ x }: { x?: string; }) => void
>({x: z = 'y'}) => { } : ({ x }: { x?: string; }) => void
>k : ({ x: z }: { x?: string; }) => void
>({x: z = 'y'}) => { } : ({ x: z }: { x?: string; }) => void
>x : any
>z : string
>'y' : "y"
@@ -0,0 +1,17 @@
//// [declarationEmitDuplicateParameterDestructuring.ts]
export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b;

export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b;




//// [declarationEmitDuplicateParameterDestructuring.d.ts]
export declare const fn1: ({ prop: a, prop: b }: {
prop: number;
}) => number;
export declare const fn2: ({ prop: a }: {
prop: number;
}, { prop: b }: {
prop: number;
}) => number;
@@ -0,0 +1,22 @@
=== tests/cases/compiler/declarationEmitDuplicateParameterDestructuring.ts ===
export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b;
>fn1 : Symbol(fn1, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 12))
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 43))
>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 21))
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 43))
>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 30))
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 43))
>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 21))
>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 0, 30))

export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b;
>fn2 : Symbol(fn2, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 12))
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 34))
>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 21))
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 34))
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 65))
>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 52))
>prop : Symbol(prop, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 65))
>a : Symbol(a, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 21))
>b : Symbol(b, Decl(declarationEmitDuplicateParameterDestructuring.ts, 2, 52))

@@ -0,0 +1,26 @@
=== tests/cases/compiler/declarationEmitDuplicateParameterDestructuring.ts ===
export const fn1 = ({ prop: a, prop: b }: { prop: number }) => a + b;
>fn1 : ({ prop: a, prop: b }: { prop: number;}) => number
>({ prop: a, prop: b }: { prop: number }) => a + b : ({ prop: a, prop: b }: { prop: number;}) => number
>prop : any
>a : number
>prop : any
>b : number
>prop : number
>a + b : number
>a : number
>b : number

export const fn2 = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b;
>fn2 : ({ prop: a }: { prop: number;}, { prop: b }: { prop: number;}) => number
>({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b : ({ prop: a }: { prop: number;}, { prop: b }: { prop: number;}) => number
>prop : any
>a : number
>prop : number
>prop : any
>b : number
>prop : number
>a + b : number
>a : number
>b : number

@@ -417,7 +417,7 @@ function f13() {
}

function f14([a = 1, [b = "hello", { x, y: c = false }]]) {
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
>a : number
>1 : 1
>b : string
@@ -438,7 +438,7 @@ function f14([a = 1, [b = "hello", { x, y: c = false }]]) {
}
f14([2, ["abc", { x: 0, y: true }]]);
>f14([2, ["abc", { x: 0, y: true }]]) : void
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
>[2, ["abc", { x: 0, y: true }]] : [number, [string, { x: number; y: true; }]]
>2 : 2
>["abc", { x: 0, y: true }] : [string, { x: number; y: true; }]
@@ -451,7 +451,7 @@ f14([2, ["abc", { x: 0, y: true }]]);

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

f14([2, ["abc", { y: false }]]); // Error, no x
>f14([2, ["abc", { y: false }]]) : void
>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void
>f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void
>[2, ["abc", { y: false }]] : [number, [string, { y: false; }]]
>2 : 2
>["abc", { y: false }] : [string, { y: false; }]
@@ -31,7 +31,7 @@ type T3 = ([{ a: b }, { b: a }]);
>b : a

type F3 = ([{ a: b }, { b: a }]) => void;
>F3 : ([{ a }, { b }]: [{ a: any; }, { b: any; }]) => void
>F3 : ([{ a: b }, { b: a }]: [{ a: any; }, { b: any; }]) => void
>a : any
>b : any
>b : any
@@ -402,7 +402,7 @@ d5(); // Parameter is optional as its declaration included an initializer
// Type annotations must instead be written on the top- level parameter declaration

function e1({x: number}) { } // x has type any NOT number
>e1 : ({ x }: { x: any; }) => void
>e1 : ({ x: number }: { x: any; }) => void
>x : any
>number : any

@@ -402,7 +402,7 @@ d5(); // Parameter is optional as its declaration included an initializer
// Type annotations must instead be written on the top- level parameter declaration

function e1({x: number}) { } // x has type any NOT number
>e1 : ({ x }: { x: any; }) => void
>e1 : ({ x: number }: { x: any; }) => void
>x : any
>number : any

@@ -376,7 +376,7 @@ d5(); // Parameter is optional as its declaration included an initializer
// Type annotations must instead be written on the top- level parameter declaration

function e1({x: number}) { } // x has type any NOT number
>e1 : ({ x }: { x: any; }) => void
>e1 : ({ x: number }: { x: any; }) => void
>x : any
>number : any

@@ -1,6 +1,6 @@
=== tests/cases/compiler/excessPropertyCheckWithSpread.ts ===
declare function f({ a: number }): void
>f : ({ a }: { a: any; }) => void
>f : ({ a: number }: { a: any; }) => void
>a : any
>number : any

@@ -13,7 +13,7 @@ declare let i: I;

f({ a: 1, ...i });
>f({ a: 1, ...i }) : void
>f : ({ a }: { a: any; }) => void
>f : ({ a: number }: { a: any; }) => void
>{ a: 1, ...i } : { n: number; a: number; }
>a : number
>1 : 1
@@ -35,7 +35,7 @@ declare let r: R;

f({ a: 1, ...l, ...r });
>f({ a: 1, ...l, ...r }) : void
>f : ({ a }: { a: any; }) => void
>f : ({ a: number }: { a: any; }) => void
>{ a: 1, ...l, ...r } : { opt: string | number; a: number; }
>a : number
>1 : 1
@@ -19,7 +19,7 @@ declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void);
suddenly(({ x: a, ...rest }) => rest.y);
>suddenly(({ x: a, ...rest }) => rest.y) : any
>suddenly : (f: (a: { x: { z: any; ka: any; }; y: string; }) => void) => any
>({ x: a, ...rest }) => rest.y : ({ x, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string
>({ x: a, ...rest }) => rest.y : ({ x: a, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string
>x : any
>a : { z: any; ka: any; }
>rest : { y: string; }
@@ -19,7 +19,7 @@ declare function suddenly(f: (a: { x: { z, ka }, y: string }) => void);
suddenly(({ x: a, ...rest }) => rest.y);
>suddenly(({ x: a, ...rest }) => rest.y) : any
>suddenly : (f: (a: { x: { z: any; ka: any; }; y: string; }) => void) => any
>({ x: a, ...rest }) => rest.y : ({ x, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string
>({ x: a, ...rest }) => rest.y : ({ x: a, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string
>x : any
>a : { z: any; ka: any; }
>rest : { y: string; }
@@ -167,18 +167,18 @@ interface I {
}): any;
}
declare function f1({ a }: O): void;
declare const f2: ({ a }: O) => void;
declare const f3: ({ a, b, c }: O) => void;
declare const f4: ({ a }: O) => string;
declare const f5: ({ a, b, c }: O) => string;
declare const f2: ({ a: string }: O) => void;
declare const f3: ({ a: string, b, c }: O) => void;
declare const f4: ({ a: string }: O) => string;
declare const f5: ({ a: string, b, c }: O) => string;
declare const obj1: {
method({ a }: O): void;
method({ a: string }: O): void;
};
declare const obj2: {
method({ a }: O): string;
method({ a: string }: O): string;
};
declare function f6({ a }: O): void;
declare const f7: ({ a, b, c }: O) => void;
declare const f7: ({ a: string, b, c }: O) => void;
declare const f8: ({ "a": string }: O) => void;
declare function f9({ 2: string }: {
2: any;

0 comments on commit ec6ae1c

Please sign in to comment.