From 4aec8efd181bc31febd1df8f25a5b7c3253bb3ca Mon Sep 17 00:00:00 2001 From: uhyo Date: Sun, 11 Oct 2020 18:23:11 +0900 Subject: [PATCH 01/31] Forbid renaming a propertyin function type parameters --- src/compiler/checker.ts | 8 ++++++++ src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index be2e6f9d8aba9..257cf98b37566 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37905,6 +37905,14 @@ namespace ts { } if (isBindingElement(node)) { + if (node.propertyName && isIdentifier(node.name) && isParameterDeclaration(node) && nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) { + // type F = ({a: string}) => void; + // ^^^^^^ + // variable renaming in function type notation is confusing, so forbid it + error(node.name, Diagnostics.Renaming_a_property_in_destructuring_assignment_is_only_allowed_in_a_function_or_constructor_implementation); + return; + } + if (isObjectBindingPattern(node.parent) && node.dotDotDotToken && languageVersion < ScriptTarget.ES2018) { checkExternalEmitHelpers(node, ExternalEmitHelpers.Rest); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6078b781250af..6d1df373a2919 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3487,6 +3487,10 @@ "category": "Error", "code": 2841 }, + "Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.": { + "category": "Error", + "code": 2842 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", From a37d6d471b03352a697d74d794d6e855a2ee3df5 Mon Sep 17 00:00:00 2001 From: uhyo Date: Sun, 11 Oct 2020 18:27:17 +0900 Subject: [PATCH 02/31] add tests --- ...ngDestructuredPropertyInFunctionType.errors.txt | 10 ++++++++++ .../renamingDestructuredPropertyInFunctionType.js | 11 +++++++++++ ...amingDestructuredPropertyInFunctionType.symbols | 12 ++++++++++++ ...enamingDestructuredPropertyInFunctionType.types | 13 +++++++++++++ ...gDestructuredPropertyInFunctionType2.errors.txt | 14 ++++++++++++++ .../renamingDestructuredPropertyInFunctionType2.js | 12 ++++++++++++ ...mingDestructuredPropertyInFunctionType2.symbols | 13 +++++++++++++ ...namingDestructuredPropertyInFunctionType2.types | 14 ++++++++++++++ .../renamingDestructuredPropertyInFunctionType.ts | 3 +++ .../renamingDestructuredPropertyInFunctionType2.ts | 5 +++++ 10 files changed, 107 insertions(+) create mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt create mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js create mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols create mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types create mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt create mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.js create mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.symbols create mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types create mode 100644 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts create mode 100644 tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt new file mode 100644 index 0000000000000..d6eaa158e74bc --- /dev/null +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(1,15): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + + +==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (1 errors) ==== + type F = ({a: string}) => void; + ~~~~~~ +!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + + const f = ({a: string}) => string; + \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js new file mode 100644 index 0000000000000..3d3a24d9a2882 --- /dev/null +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js @@ -0,0 +1,11 @@ +//// [renamingDestructuredPropertyInFunctionType.ts] +type F = ({a: string}) => void; + +const f = ({a: string}) => string; + + +//// [renamingDestructuredPropertyInFunctionType.js] +var f = function (_a) { + var string = _a.a; + return string; +}; diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols new file mode 100644 index 0000000000000..c0fc1701b1248 --- /dev/null +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === +type F = ({a: string}) => void; +>F : Symbol(F, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>a : Symbol(a) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 11)) + +const f = ({a: string}) => string; +>f : Symbol(f, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 5)) +>a : Symbol(a) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 12)) + diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types new file mode 100644 index 0000000000000..7ff9138462dd5 --- /dev/null +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === +type F = ({a: string}) => void; +>F : F +>a : any +>string : any + +const f = ({a: string}) => string; +>f : ({ a: string }: { a: any; }) => any +>({a: string}) => string : ({ a: string }: { a: any; }) => any +>a : any +>string : any +>string : any + diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt new file mode 100644 index 0000000000000..9817532b13a03 --- /dev/null +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts(1,15): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts(3,16): error TS7031: Binding element 'string' implicitly has an 'any' type. + + +==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts (2 errors) ==== + type F = ({a: string}) => void; + ~~~~~~ +!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + + const f = ({a: string}) => string; + ~~~~~~ +!!! error TS7031: Binding element 'string' implicitly has an 'any' type. + + \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.js new file mode 100644 index 0000000000000..de4994687621b --- /dev/null +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.js @@ -0,0 +1,12 @@ +//// [renamingDestructuredPropertyInFunctionType2.ts] +type F = ({a: string}) => void; + +const f = ({a: string}) => string; + + + +//// [renamingDestructuredPropertyInFunctionType2.js] +var f = function (_a) { + var string = _a.a; + return string; +}; diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.symbols b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.symbols new file mode 100644 index 0000000000000..0e5dac47a3628 --- /dev/null +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts === +type F = ({a: string}) => void; +>F : Symbol(F, Decl(renamingDestructuredPropertyInFunctionType2.ts, 0, 0)) +>a : Symbol(a) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType2.ts, 0, 11)) + +const f = ({a: string}) => string; +>f : Symbol(f, Decl(renamingDestructuredPropertyInFunctionType2.ts, 2, 5)) +>a : Symbol(a) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType2.ts, 2, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType2.ts, 2, 12)) + + diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types new file mode 100644 index 0000000000000..02b4a3400e241 --- /dev/null +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts === +type F = ({a: string}) => void; +>F : F +>a : any +>string : any + +const f = ({a: string}) => string; +>f : ({ a: string }: { a: any; }) => any +>({a: string}) => string : ({ a: string }: { a: any; }) => any +>a : any +>string : any +>string : any + + diff --git a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts new file mode 100644 index 0000000000000..c61bbe96700dd --- /dev/null +++ b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts @@ -0,0 +1,3 @@ +type F = ({a: string}) => void; + +const f = ({a: string}) => string; diff --git a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts new file mode 100644 index 0000000000000..9f56fe8a11937 --- /dev/null +++ b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts @@ -0,0 +1,5 @@ +// @noImplicitAny: true +type F = ({a: string}) => void; + +const f = ({a: string}) => string; + From 67732d31e1af09523626bc1dc189ee7655048c0e Mon Sep 17 00:00:00 2001 From: uhyo Date: Sun, 11 Oct 2020 20:15:03 +0900 Subject: [PATCH 03/31] Remove renaming from declaration output --- src/compiler/checker.ts | 30 ++++++++---- src/compiler/transformers/declarations.ts | 22 +++++++-- .../declarationEmitBindingPatterns.js | 2 +- .../declarationEmitBindingPatterns.types | 4 +- .../destructuringInFunctionType.errors.txt | 30 ++++++++++++ .../reference/destructuringInFunctionType.js | 2 +- .../excessPropertyCheckWithSpread.errors.txt | 23 +++++++++ ...aramterDestrcuturingDeclaration.errors.txt | 14 ++++++ .../paramterDestrcuturingDeclaration.js | 4 +- ...elessFunctionComponentOverload1.errors.txt | 48 +++++++++++++++++++ 10 files changed, 160 insertions(+), 19 deletions(-) create mode 100644 tests/baselines/reference/destructuringInFunctionType.errors.txt create mode 100644 tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt create mode 100644 tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt create mode 100644 tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 257cf98b37566..6cd04997179c2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5964,19 +5964,29 @@ namespace ts { return parameterNode; function cloneBindingName(node: BindingName): BindingName { - return elideInitializerAndSetEmitFlags(node) as BindingName; - function elideInitializerAndSetEmitFlags(node: Node): Node { + return elideInitializerAndPropertyRenamingAndSetEmitFlags(node) as BindingName; + function elideInitializerAndPropertyRenamingAndSetEmitFlags(node: Node): Node { if (context.tracker.trackSymbol && isComputedPropertyName(node) && isLateBindableName(node)) { trackComputedName(node.expression, context.enclosingDeclaration, context); } - let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!; + let visited = visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags)!; if (isBindingElement(visited)) { - visited = factory.updateBindingElement( - visited, - visited.dotDotDotToken, - visited.propertyName, - visited.name, - /*initializer*/ undefined); + if (visited.propertyName && isIdentifier(visited.propertyName) && isIdentifier(visited.name)) { + 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); + } } if (!nodeIsSynthesized(visited)) { visited = factory.cloneNode(visited); @@ -37905,7 +37915,7 @@ namespace ts { } if (isBindingElement(node)) { - if (node.propertyName && isIdentifier(node.name) && isParameterDeclaration(node) && nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) { + if (node.propertyName && isIdentifier(node.propertyName) && isIdentifier(node.name) && isParameterDeclaration(node) && nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) { // type F = ({a: string}) => void; // ^^^^^^ // variable renaming in function type notation is confusing, so forbid it diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 76db95b260377..3453eae95b210 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -454,7 +454,7 @@ namespace ts { return ret; } - function filterBindingPatternInitializers(name: BindingName) { + function filterBindingPatternInitializersAndRenamings(name: BindingName) { if (name.kind === SyntaxKind.Identifier) { return name; } @@ -472,7 +472,23 @@ namespace ts { if (elem.kind === SyntaxKind.OmittedExpression) { return elem; } - return factory.updateBindingElement(elem, elem.dotDotDotToken, elem.propertyName, filterBindingPatternInitializers(elem.name), shouldPrintWithInitializer(elem) ? elem.initializer : undefined); + if (elem.propertyName && isIdentifier(elem.propertyName) && isIdentifier(elem.name)) { + // Property renaming is forbidden in types, so remove renaming + return factory.updateBindingElement( + elem, + elem.dotDotDotToken, + /* propertyName */ undefined, + elem.propertyName, + shouldPrintWithInitializer(elem) ? elem.initializer : undefined + ); + } + return factory.updateBindingElement( + elem, + elem.dotDotDotToken, + elem.propertyName, + filterBindingPatternInitializersAndRenamings(elem.name), + shouldPrintWithInitializer(elem) ? elem.initializer : undefined + ); } } @@ -487,7 +503,7 @@ namespace ts { /*decorators*/ undefined, maskModifiers(p, modifierMask), p.dotDotDotToken, - filterBindingPatternInitializers(p.name), + filterBindingPatternInitializersAndRenamings(p.name), resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(SyntaxKind.QuestionToken)) : undefined, ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param ensureNoInitializer(p) diff --git a/tests/baselines/reference/declarationEmitBindingPatterns.js b/tests/baselines/reference/declarationEmitBindingPatterns.js index 5581c06ebe67f..31114071a291e 100644 --- a/tests/baselines/reference/declarationEmitBindingPatterns.js +++ b/tests/baselines/reference/declarationEmitBindingPatterns.js @@ -18,7 +18,7 @@ function f(_a, _b, _c) { //// [declarationEmitBindingPatterns.d.ts] -declare const k: ({ x: z }: { +declare const k: ({ x }: { x?: string; }) => void; declare var a: any; diff --git a/tests/baselines/reference/declarationEmitBindingPatterns.types b/tests/baselines/reference/declarationEmitBindingPatterns.types index d49893dad94fa..151991e3039fb 100644 --- a/tests/baselines/reference/declarationEmitBindingPatterns.types +++ b/tests/baselines/reference/declarationEmitBindingPatterns.types @@ -1,7 +1,7 @@ === tests/cases/compiler/declarationEmitBindingPatterns.ts === const k = ({x: z = 'y'}) => { } ->k : ({ x: z }: { x?: string; }) => void ->({x: z = 'y'}) => { } : ({ x: z }: { x?: string; }) => void +>k : ({ x }: { x?: string; }) => void +>({x: z = 'y'}) => { } : ({ x }: { x?: string; }) => void >x : any >z : string >'y' : "y" diff --git a/tests/baselines/reference/destructuringInFunctionType.errors.txt b/tests/baselines/reference/destructuringInFunctionType.errors.txt new file mode 100644 index 0000000000000..da7a2fc32bbf1 --- /dev/null +++ b/tests/baselines/reference/destructuringInFunctionType.errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,18): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,28): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + + +==== tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts (2 errors) ==== + interface a { a } + interface b { b } + interface c { c } + + type T1 = ([a, b, c]); + type F1 = ([a, b, c]) => void; + + type T2 = ({ a }); + type F2 = ({ a }) => void; + + type T3 = ([{ a: b }, { b: a }]); + type F3 = ([{ a: b }, { b: a }]) => void; + ~ +!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + ~ +!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + + type T4 = ([{ a: [b, c] }]); + type F4 = ([{ a: [b, c] }]) => void; + + type C1 = new ([{ a: [b, c] }]) => void; + + var v1 = ([a, b, c]) => "hello"; + var v2: ([a, b, c]) => string; + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringInFunctionType.js b/tests/baselines/reference/destructuringInFunctionType.js index 1844e8e5a8d21..1a38ef067acfc 100644 --- a/tests/baselines/reference/destructuringInFunctionType.js +++ b/tests/baselines/reference/destructuringInFunctionType.js @@ -52,7 +52,7 @@ declare type T3 = ([{ }, { b: a; }]); -declare type F3 = ([{ a: b }, { b: a }]: [{ +declare type F3 = ([{ a }, { b }]: [{ a: any; }, { b: any; diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt new file mode 100644 index 0000000000000..9ae33a275805d --- /dev/null +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt @@ -0,0 +1,23 @@ +tests/cases/compiler/excessPropertyCheckWithSpread.ts(1,25): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + + +==== tests/cases/compiler/excessPropertyCheckWithSpread.ts (1 errors) ==== + declare function f({ a: number }): void + ~~~~~~ +!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + interface I { + readonly n: number; + } + declare let i: I; + f({ a: 1, ...i }); + + interface R { + opt?: number + } + interface L { + opt: string + } + declare let l: L; + declare let r: R; + f({ a: 1, ...l, ...r }); + \ No newline at end of file diff --git a/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt b/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt new file mode 100644 index 0000000000000..69e5d888a1b0c --- /dev/null +++ b/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/paramterDestrcuturingDeclaration.ts(2,10): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/paramterDestrcuturingDeclaration.ts(3,14): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + + +==== tests/cases/compiler/paramterDestrcuturingDeclaration.ts (2 errors) ==== + interface C { + ({p: name}): any; + ~~~~ +!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + new ({p: boolean}): any; + ~~~~~~~ +!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + } + \ No newline at end of file diff --git a/tests/baselines/reference/paramterDestrcuturingDeclaration.js b/tests/baselines/reference/paramterDestrcuturingDeclaration.js index 3ce2527f57226..e0cf710a528da 100644 --- a/tests/baselines/reference/paramterDestrcuturingDeclaration.js +++ b/tests/baselines/reference/paramterDestrcuturingDeclaration.js @@ -10,10 +10,10 @@ interface C { //// [paramterDestrcuturingDeclaration.d.ts] interface C { - ({ p: name }: { + ({ p }: { p: any; }): any; - new ({ p: boolean }: { + new ({ p }: { p: any; }): any; } diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt new file mode 100644 index 0000000000000..69c6d7d79e3c2 --- /dev/null +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt @@ -0,0 +1,48 @@ +tests/cases/conformance/jsx/file.tsx(17,39): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + + +==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== + import React = require('react') + + declare function OneThing(k: {yxx: string}): JSX.Element; + declare function OneThing(k: {yxx1: string, children: string}): JSX.Element; + declare function OneThing(l: {yy: number, yy1: string}): JSX.Element; + declare function OneThing(l: {yy: number, yy1: string, yy2: boolean}): JSX.Element; + declare function OneThing(l1: {data: string, "data-prop": boolean}): JSX.Element; + + // OK + const c1 = + const c2 = + const c3 = + const c4 = + const c5 = Hello + + + declare function TestingOneThing({y1: string}): JSX.Element; + ~~~~~~ +!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element; + declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element; + declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; + + // OK + const d1 = ; + const d2 = ; + const d3 = ; + const d4 = ; + const d5 = ; + + + declare function TestingOptional(a: {y1?: string, y2?: number}): JSX.Element; + declare function TestingOptional(a: {y1: boolean, y2?: number, y3: boolean}): JSX.Element; + + // OK + const e1 = + const e3 = + const e4 = + const e5 = + const e6 = + const e2 = + + + \ No newline at end of file From 1d114e67a216004fcde688f68043faee84507e14 Mon Sep 17 00:00:00 2001 From: uhyo Date: Sun, 11 Oct 2020 20:29:49 +0900 Subject: [PATCH 04/31] accept baseline --- ...tuallyTypedBindingInitializerNegative.types | 4 ++-- .../reference/declarationsAndAssignments.types | 8 ++++---- ...destructuringParameterDeclaration1ES5.types | 2 +- ...uringParameterDeclaration1ES5iterable.types | 2 +- ...destructuringParameterDeclaration1ES6.types | 2 +- .../destructuringParameterDeclaration6.types | 12 ++++++------ .../excessPropertyCheckWithSpread.types | 6 +++--- .../reference/objectRestParameter.types | 2 +- .../reference/objectRestParameterES5.types | 2 +- ...ingDestructuredPropertyInFunctionType.types | 4 ++-- ...ngDestructuredPropertyInFunctionType2.types | 4 ++-- ...ngParameterNestedObjectBindingPattern.types | 12 ++++++------ ...stedObjectBindingPatternDefaultValues.types | 12 ++++++------ ...ucturingParameterObjectBindingPattern.types | 12 ++++++------ ...eterObjectBindingPatternDefaultValues.types | 12 ++++++------ ...heticDefaultExportsWithDynamicImports.types | 2 +- ...sxStatelessFunctionComponentOverload1.types | 18 +++++++++--------- 17 files changed, 58 insertions(+), 58 deletions(-) diff --git a/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types b/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types index 56ad56f21e577..6d64e3b7675cf 100644 --- a/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types +++ b/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types @@ -5,7 +5,7 @@ interface Show { >x : number } function f({ show: showRename = v => v }: Show) {} ->f : ({ show: showRename }: Show) => void +>f : ({ show }: 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: nestedRename }: Nested) => void +>ff : ({ nested }: Nested) => void >nested : any >nestedRename : Show >{ show: v => v } : { show: (v: number) => number; } diff --git a/tests/baselines/reference/declarationsAndAssignments.types b/tests/baselines/reference/declarationsAndAssignments.types index a7b72a6809424..a3caaa9f6bd84 100644 --- a/tests/baselines/reference/declarationsAndAssignments.types +++ b/tests/baselines/reference/declarationsAndAssignments.types @@ -417,7 +417,7 @@ function f13() { } function f14([a = 1, [b = "hello", { x, y: c = false }]]) { ->f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void +>f14 : ([a, [b, { x, y }]]: [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: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void +>f14 : ([a, [b, { x, y }]]: [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: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void +>f14 : ([a, [b, { x, y }]]: [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: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void +>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void >[2, ["abc", { y: false }]] : [number, [string, { y: false; }]] >2 : 2 >["abc", { y: false }] : [string, { y: false; }] diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5.types b/tests/baselines/reference/destructuringParameterDeclaration1ES5.types index cea8e2a231b2c..381c486a5461d 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5.types @@ -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: number }: { x: any; }) => void +>e1 : ({ x }: { x: any; }) => void >x : any >number : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types index 4fee7254d2bfa..aec020bcc2870 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types @@ -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: number }: { x: any; }) => void +>e1 : ({ x }: { x: any; }) => void >x : any >number : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types index cee129da47534..acf5dcffb5ce2 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types @@ -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: number }: { x: any; }) => void +>e1 : ({ x }: { x: any; }) => void >x : any >number : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration6.types b/tests/baselines/reference/destructuringParameterDeclaration6.types index d135f9cb8fdbf..6b5085d21219c 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration6.types @@ -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: x }: { public: any; }) => void +>b1 : ({ public }: { public: any; }) => void >public : any >x : any function b2({while: y}) { } ->b2 : ({ while: y }: { while: any; }) => void +>b2 : ({ while }: { while: any; }) => void >while : any >y : any b1({ public: 1 }); >b1({ public: 1 }) : void ->b1 : ({ public: x }: { public: any; }) => void +>b1 : ({ public }: { public: any; }) => void >{ public: 1 } : { public: number; } >public : number >1 : 1 b2({ while: 1 }); >b2({ while: 1 }) : void ->b2 : ({ while: y }: { while: any; }) => void +>b2 : ({ while }: { while: any; }) => void >{ while: 1 } : { while: number; } >while : number >1 : 1 diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.types b/tests/baselines/reference/excessPropertyCheckWithSpread.types index 460f43d2289f4..de5385d0b33e0 100644 --- a/tests/baselines/reference/excessPropertyCheckWithSpread.types +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.types @@ -1,6 +1,6 @@ === tests/cases/compiler/excessPropertyCheckWithSpread.ts === declare function f({ a: number }): void ->f : ({ a: number }: { a: any; }) => void +>f : ({ a }: { 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: number }: { a: any; }) => void +>f : ({ a }: { 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: number }: { a: any; }) => void +>f : ({ a }: { a: any; }) => void >{ a: 1, ...l, ...r } : { opt: string | number; a: number; } >a : number >1 : 1 diff --git a/tests/baselines/reference/objectRestParameter.types b/tests/baselines/reference/objectRestParameter.types index 71047deea43fe..668214c495f1f 100644 --- a/tests/baselines/reference/objectRestParameter.types +++ b/tests/baselines/reference/objectRestParameter.types @@ -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: a, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string +>({ x: a, ...rest }) => rest.y : ({ x, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string >x : any >a : { z: any; ka: any; } >rest : { y: string; } diff --git a/tests/baselines/reference/objectRestParameterES5.types b/tests/baselines/reference/objectRestParameterES5.types index 74df68093aa45..d88da6a249433 100644 --- a/tests/baselines/reference/objectRestParameterES5.types +++ b/tests/baselines/reference/objectRestParameterES5.types @@ -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: a, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string +>({ x: a, ...rest }) => rest.y : ({ x, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string >x : any >a : { z: any; ka: any; } >rest : { y: string; } diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types index 7ff9138462dd5..7396a7c96a439 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types @@ -5,8 +5,8 @@ type F = ({a: string}) => void; >string : any const f = ({a: string}) => string; ->f : ({ a: string }: { a: any; }) => any ->({a: string}) => string : ({ a: string }: { a: any; }) => any +>f : ({ a }: { a: any; }) => any +>({a: string}) => string : ({ a }: { a: any; }) => any >a : any >string : any >string : any diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types index 02b4a3400e241..0ec5f3a0d133e 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types @@ -5,8 +5,8 @@ type F = ({a: string}) => void; >string : any const f = ({a: string}) => string; ->f : ({ a: string }: { a: any; }) => any ->({a: string}) => string : ({ a: string }: { a: any; }) => any +>f : ({ a }: { a: any; }) => any +>({a: string}) => string : ({ a }: { a: any; }) => any >a : any >string : any >string : any diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types index 287f0c41d2587..dcabaa3bf785d 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types @@ -34,7 +34,7 @@ var robotA: Robot = { name: "mower", skills: { primary: "mowing", secondary: "no >"none" : "none" function foo1({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) { ->foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void +>foo1 : ({ skills: { primary, secondary } }: Robot) => void >skills : any >primary : any >primaryA : string @@ -49,7 +49,7 @@ function foo1({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) { >primaryA : string } function foo2({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) { ->foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void +>foo2 : ({ name, skills: { primary, secondary } }: Robot) => void >name : any >nameC : string >skills : any @@ -81,12 +81,12 @@ function foo3({ skills }: Robot) { foo1(robotA); >foo1(robotA) : void ->foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void +>foo1 : ({ skills: { primary, secondary } }: Robot) => void >robotA : Robot foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void +>foo1 : ({ skills: { primary, secondary } }: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" @@ -99,12 +99,12 @@ foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void +>foo2 : ({ name, skills: { primary, secondary } }: Robot) => void >robotA : Robot foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void +>foo2 : ({ name, skills: { primary, secondary } }: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types index 8bfc93c3db70b..9082abff9dfb4 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types @@ -34,7 +34,7 @@ var robotA: Robot = { name: "mower", skills: { primary: "mowing", secondary: "no >"none" : "none" function foo1( ->foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void +>foo1 : ({ skills: { primary, secondary } }?: Robot) => void { skills: { >skills : any @@ -67,7 +67,7 @@ function foo1( >primaryA : string } function foo2( ->foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void +>foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void { name: nameC = "name", >name : any @@ -126,12 +126,12 @@ function foo3({ skills = { primary: "SomeSkill", secondary: "someSkill" } }: Ro foo1(robotA); >foo1(robotA) : void ->foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void +>foo1 : ({ skills: { primary, secondary } }?: Robot) => void >robotA : Robot foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void +>foo1 : ({ skills: { primary, secondary } }?: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" @@ -144,12 +144,12 @@ foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void +>foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void >robotA : Robot foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void +>foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types index 05a01de79ac9b..a02d95a9939b9 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types @@ -26,7 +26,7 @@ var robotA: Robot = { name: "mower", skill: "mowing" }; >"mowing" : "mowing" function foo1({ name: nameA }: Robot) { ->foo1 : ({ name: nameA }: Robot) => void +>foo1 : ({ name }: Robot) => void >name : any >nameA : string @@ -38,7 +38,7 @@ function foo1({ name: nameA }: Robot) { >nameA : string } function foo2({ name: nameB, skill: skillB }: Robot) { ->foo2 : ({ name: nameB, skill: skillB }: Robot) => void +>foo2 : ({ name, skill }: Robot) => void >name : any >nameB : string >skill : any @@ -65,12 +65,12 @@ function foo3({ name }: Robot) { foo1(robotA); >foo1(robotA) : void ->foo1 : ({ name: nameA }: Robot) => void +>foo1 : ({ name }: Robot) => void >robotA : Robot foo1({ name: "Edger", skill: "cutting edges" }); >foo1({ name: "Edger", skill: "cutting edges" }) : void ->foo1 : ({ name: nameA }: Robot) => void +>foo1 : ({ name }: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" @@ -79,12 +79,12 @@ foo1({ name: "Edger", skill: "cutting edges" }); foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name: nameB, skill: skillB }: Robot) => void +>foo2 : ({ name, skill }: Robot) => void >robotA : Robot foo2({ name: "Edger", skill: "cutting edges" }); >foo2({ name: "Edger", skill: "cutting edges" }) : void ->foo2 : ({ name: nameB, skill: skillB }: Robot) => void +>foo2 : ({ name, skill }: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types index 6f1712d272e25..a7493bcd1dcb0 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types @@ -26,7 +26,7 @@ var robotA: Robot = { name: "mower", skill: "mowing" }; >"mowing" : "mowing" function foo1({ name: nameA = "" }: Robot = { }) { ->foo1 : ({ name: nameA }?: Robot) => void +>foo1 : ({ name }?: Robot) => void >name : any >nameA : string >"" : "" @@ -40,7 +40,7 @@ function foo1({ name: nameA = "" }: Robot = { }) { >nameA : string } function foo2({ name: nameB = "", skill: skillB = "noSkill" }: Robot = {}) { ->foo2 : ({ name: nameB, skill: skillB }?: Robot) => void +>foo2 : ({ name, skill }?: Robot) => void >name : any >nameB : string >"" : "" @@ -72,12 +72,12 @@ function foo3({ name = "" }: Robot = {}) { foo1(robotA); >foo1(robotA) : void ->foo1 : ({ name: nameA }?: Robot) => void +>foo1 : ({ name }?: Robot) => void >robotA : Robot foo1({ name: "Edger", skill: "cutting edges" }); >foo1({ name: "Edger", skill: "cutting edges" }) : void ->foo1 : ({ name: nameA }?: Robot) => void +>foo1 : ({ name }?: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" @@ -86,12 +86,12 @@ foo1({ name: "Edger", skill: "cutting edges" }); foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name: nameB, skill: skillB }?: Robot) => void +>foo2 : ({ name, skill }?: Robot) => void >robotA : Robot foo2({ name: "Edger", skill: "cutting edges" }); >foo2({ name: "Edger", skill: "cutting edges" }) : void ->foo2 : ({ name: nameB, skill: skillB }?: Robot) => void +>foo2 : ({ name, skill }?: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types index 3f1ef83a0ae9c..3dc640792e075 100644 --- a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types +++ b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types @@ -13,7 +13,7 @@ import("package").then(({default: foo}) => foo(42)); >import("package") : Promise<{ default: (x: number) => string; }> >"package" : "package" >then : string; }, TResult2 = never>(onfulfilled?: (value: { default: (x: number) => string; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->({default: foo}) => foo(42) : ({ default: foo }: { default: (x: number) => string; }) => string +>({default: foo}) => foo(42) : ({ default }: { default: (x: number) => string; }) => string >default : any >foo : (x: number) => string >foo(42) : string diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types index d5429be5e488d..2d48ccacf899c 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types @@ -75,27 +75,27 @@ const c5 = Hello declare function TestingOneThing({y1: string}): JSX.Element; ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >y1 : any >string : any >JSX : any declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element; ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string;}): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string;}): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >j : { "extra-data": string; yy?: string; } >"extra-data" : string >yy : string >JSX : any declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element; ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number;}): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number;}): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >n : { yy: number; direction?: number; } >yy : number >direction : number >JSX : any declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string;}): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string;}): JSX.Element; } >n : { yy: string; name: string; } >yy : string >name : string @@ -105,27 +105,27 @@ declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; const d1 = ; >d1 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >y1 : true >extra-data : true const d2 = ; >d2 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string const d3 = ; >d3 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string >yy : string const d4 = ; >d4 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string >yy : number >9 : 9 @@ -135,7 +135,7 @@ const d4 = ; const d5 = ; >d5 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string >yy : string >name : string From 4abcfa173a240f2a3dfc8a0ca9dc1b2057cf2a10 Mon Sep 17 00:00:00 2001 From: uhyo Date: Wed, 8 Jun 2022 21:21:27 +0900 Subject: [PATCH 05/31] accept baseline --- .../renamingDestructuredPropertyInFunctionType.errors.txt | 4 ++-- .../renamingDestructuredPropertyInFunctionType.types | 2 +- .../renamingDestructuredPropertyInFunctionType2.errors.txt | 4 ++-- .../renamingDestructuredPropertyInFunctionType2.types | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index d6eaa158e74bc..d7bcfc4950c06 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(1,15): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(1,15): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. ==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (1 errors) ==== type F = ({a: string}) => void; ~~~~~~ -!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. const f = ({a: string}) => string; \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types index 7396a7c96a439..013797280e345 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types @@ -1,6 +1,6 @@ === tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === type F = ({a: string}) => void; ->F : F +>F : ({ a }: { a: any; }) => void >a : any >string : any diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt index 9817532b13a03..a99d3c2954215 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts(1,15): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts(1,15): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts(3,16): error TS7031: Binding element 'string' implicitly has an 'any' type. ==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts (2 errors) ==== type F = ({a: string}) => void; ~~~~~~ -!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. const f = ({a: string}) => string; ~~~~~~ diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types index 0ec5f3a0d133e..46bae2330b183 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types @@ -1,6 +1,6 @@ === tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts === type F = ({a: string}) => void; ->F : F +>F : ({ a }: { a: any; }) => void >a : any >string : any From 39e90ce1e18b511ff8fe1cf1a0921a32d235a144 Mon Sep 17 00:00:00 2001 From: uhyo Date: Wed, 8 Jun 2022 21:36:18 +0900 Subject: [PATCH 06/31] renew tests (not very right now) --- ...tructuredPropertyInFunctionType.errors.txt | 93 ++++++++++- ...amingDestructuredPropertyInFunctionType.js | 37 ++++- ...DestructuredPropertyInFunctionType.symbols | 153 ++++++++++++++++- ...ngDestructuredPropertyInFunctionType.types | 138 +++++++++++++++- ...ructuredPropertyInFunctionType2.errors.txt | 93 ++++++++++- ...estructuredPropertyInFunctionType2.symbols | 156 +++++++++++++++++- ...gDestructuredPropertyInFunctionType2.types | 141 +++++++++++++++- ...amingDestructuredPropertyInFunctionType.ts | 32 +++- ...mingDestructuredPropertyInFunctionType2.ts | 34 +++- 9 files changed, 826 insertions(+), 51 deletions(-) diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index d7bcfc4950c06..0a04f6fbeeb46 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -1,10 +1,91 @@ -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(1,15): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(3,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(4,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(5,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(6,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(7,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,28): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(9,20): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(13,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(14,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(17,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,28): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(19,20): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,16): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,9): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (1 errors) ==== - type F = ({a: string}) => void; - ~~~~~~ +==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (19 errors) ==== + type O = { a: string; b: number; c: number; }; + type F1 = (arg: number) => any; // OK + type F2 = ({ a: string }: O) => any; // Error + ~~~~~~ !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F3 = ({ a: string, b, c }: O) => any; // Error + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F4 = ({ a: string }: O) => any; // Error + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F5 = ({ a: string, b, c }: O) => any; // Error + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F6 = ({ a: string }) => typeof string; // OK + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F7 = ({ a: string, b: number }) => typeof number; // Error + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F8 = ({ a, b: number }) => typeof number; // OK + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F9 = ([a, b, c]) => void; // Error - const f = ({a: string}) => string; - \ No newline at end of file + type G1 = (arg: number) => any; // OK + type G2 = ({ a: string }: O) => any; // Error + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G3 = ({ a: string, b, c }: O) => any; // Error + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G4 = ({ a: string }: O) => any; // Error + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G5 = ({ a: string, b, c }: O) => any; // Error + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G6 = ({ a: string }) => typeof string; // OK + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G7 = ({ a: string, b: number }) => typeof number; // Error + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G8 = ({ a, b: number }) => typeof number; // OK + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G9 = ([a, b, c]) => void; // Error + + interface I { + method1(arg: number): any; // OK + method2({ a: string }): any; // Error + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + + (arg: number): any; // OK + ({ a: string }): any; // Error + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + + new (arg: number): any; // OK + new ({ a: string }): any; // Error + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + } \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js index 3d3a24d9a2882..634f2fd3512d7 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js @@ -1,11 +1,34 @@ //// [renamingDestructuredPropertyInFunctionType.ts] -type F = ({a: string}) => void; +type O = { a: string; b: number; c: number; }; +type F1 = (arg: number) => any; // OK +type F2 = ({ a: string }: O) => any; // Error +type F3 = ({ a: string, b, c }: O) => any; // Error +type F4 = ({ a: string }: O) => any; // Error +type F5 = ({ a: string, b, c }: O) => any; // Error +type F6 = ({ a: string }) => typeof string; // OK +type F7 = ({ a: string, b: number }) => typeof number; // Error +type F8 = ({ a, b: number }) => typeof number; // OK +type F9 = ([a, b, c]) => void; // Error -const f = ({a: string}) => string; - +type G1 = (arg: number) => any; // OK +type G2 = ({ a: string }: O) => any; // Error +type G3 = ({ a: string, b, c }: O) => any; // Error +type G4 = ({ a: string }: O) => any; // Error +type G5 = ({ a: string, b, c }: O) => any; // Error +type G6 = ({ a: string }) => typeof string; // OK +type G7 = ({ a: string, b: number }) => typeof number; // Error +type G8 = ({ a, b: number }) => typeof number; // OK +type G9 = ([a, b, c]) => void; // Error + +interface I { + method1(arg: number): any; // OK + method2({ a: string }): any; // Error + + (arg: number): any; // OK + ({ a: string }): any; // Error + + new (arg: number): any; // OK + new ({ a: string }): any; // Error +} //// [renamingDestructuredPropertyInFunctionType.js] -var f = function (_a) { - var string = _a.a; - return string; -}; diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols index c0fc1701b1248..0d70bfa20b74a 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols @@ -1,12 +1,151 @@ === tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === -type F = ({a: string}) => void; ->F : Symbol(F, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +type O = { a: string; b: number; c: number; }; +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 21)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 32)) + +type F1 = (arg: number) => any; // OK +>F1 : Symbol(F1, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 46)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 1, 11)) + +type F2 = ({ a: string }: O) => any; // Error +>F2 : Symbol(F2, Decl(renamingDestructuredPropertyInFunctionType.ts, 1, 31)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 12)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +type F3 = ({ a: string, b, c }: O) => any; // Error +>F3 : Symbol(F3, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 36)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 23)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 26)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +type F4 = ({ a: string }: O) => any; // Error +>F4 : Symbol(F4, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 42)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 12)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +type F5 = ({ a: string, b, c }: O) => any; // Error +>F5 : Symbol(F5, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 36)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 23)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 26)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +type F6 = ({ a: string }) => typeof string; // OK +>F6 : Symbol(F6, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 42)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 11)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 12)) -const f = ({a: string}) => string; ->f : Symbol(f, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 5)) +type F7 = ({ a: string, b: number }) => typeof number; // Error +>F7 : Symbol(F7, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 43)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 12)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 12)) +>b : Symbol(b) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 23)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 23)) + +type F8 = ({ a, b: number }) => typeof number; // OK +>F8 : Symbol(F8, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 54)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12)) +>b : Symbol(b) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 15)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 15)) + +type F9 = ([a, b, c]) => void; // Error +>F9 : Symbol(F9, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 46)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 14)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 17)) + +type G1 = (arg: number) => any; // OK +>G1 : Symbol(G1, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 30)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 11)) + +type G2 = ({ a: string }: O) => any; // Error +>G2 : Symbol(G2, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 31)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 12)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +type G3 = ({ a: string, b, c }: O) => any; // Error +>G3 : Symbol(G3, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 36)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 23)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 26)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +type G4 = ({ a: string }: O) => any; // Error +>G4 : Symbol(G4, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 42)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 12)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +type G5 = ({ a: string, b, c }: O) => any; // Error +>G5 : Symbol(G5, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 36)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 23)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 26)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +type G6 = ({ a: string }) => typeof string; // OK +>G6 : Symbol(G6, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 42)) +>a : Symbol(a) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 12)) + +type G7 = ({ a: string, b: number }) => typeof number; // Error +>G7 : Symbol(G7, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 43)) +>a : Symbol(a) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 12)) +>b : Symbol(b) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 23)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 23)) + +type G8 = ({ a, b: number }) => typeof number; // OK +>G8 : Symbol(G8, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 54)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 12)) +>b : Symbol(b) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 15)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 15)) + +type G9 = ([a, b, c]) => void; // Error +>G9 : Symbol(G9, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 46)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 14)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 17)) + +interface I { +>I : Symbol(I, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 30)) + + method1(arg: number): any; // OK +>method1 : Symbol(I.method1, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 13)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 10)) + + method2({ a: string }): any; // Error +>method2 : Symbol(I.method2, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 28)) +>a : Symbol(a) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 11)) + + (arg: number): any; // OK +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 3)) + + ({ a: string }): any; // Error +>a : Symbol(a) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 4)) + + new (arg: number): any; // OK +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 7)) + + new ({ a: string }): any; // Error +>a : Symbol(a) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 8)) +} diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types index 013797280e345..4a4795377a605 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types @@ -1,13 +1,141 @@ === tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === -type F = ({a: string}) => void; ->F : ({ a }: { a: any; }) => void +type O = { a: string; b: number; c: number; }; +>O : { a: string; b: number; c: number; } +>a : string +>b : number +>c : number + +type F1 = (arg: number) => any; // OK +>F1 : (arg: number) => any +>arg : number + +type F2 = ({ a: string }: O) => any; // Error +>F2 : ({ a }: O) => any +>a : any +>string : string + +type F3 = ({ a: string, b, c }: O) => any; // Error +>F3 : ({ a, b, c }: O) => any +>a : any +>string : string +>b : number +>c : number + +type F4 = ({ a: string }: O) => any; // Error +>F4 : ({ a }: O) => any >a : any +>string : string + +type F5 = ({ a: string, b, c }: O) => any; // Error +>F5 : ({ a, b, c }: O) => any +>a : any +>string : string +>b : number +>c : number + +type F6 = ({ a: string }) => typeof string; // OK +>F6 : ({ a }: { a: any; }) => any +>a : any +>string : any >string : any -const f = ({a: string}) => string; ->f : ({ a }: { a: any; }) => any ->({a: string}) => string : ({ a }: { a: any; }) => any +type F7 = ({ a: string, b: number }) => typeof number; // Error +>F7 : ({ a, b }: { a: any; b: any; }) => any >a : any >string : any +>b : any +>number : any +>number : any + +type F8 = ({ a, b: number }) => typeof number; // OK +>F8 : ({ a, b }: { a: any; b: any; }) => any +>a : any +>b : any +>number : any +>number : any + +type F9 = ([a, b, c]) => void; // Error +>F9 : ([a, b, c]: [any, any, any]) => void +>a : any +>b : any +>c : any + +type G1 = (arg: number) => any; // OK +>G1 : (arg: number) => any +>arg : number + +type G2 = ({ a: string }: O) => any; // Error +>G2 : ({ a }: O) => any +>a : any +>string : string + +type G3 = ({ a: string, b, c }: O) => any; // Error +>G3 : ({ a, b, c }: O) => any +>a : any +>string : string +>b : number +>c : number + +type G4 = ({ a: string }: O) => any; // Error +>G4 : ({ a }: O) => any +>a : any +>string : string + +type G5 = ({ a: string, b, c }: O) => any; // Error +>G5 : ({ a, b, c }: O) => any +>a : any +>string : string +>b : number +>c : number + +type G6 = ({ a: string }) => typeof string; // OK +>G6 : ({ a }: { a: any; }) => any +>a : any +>string : any +>string : any + +type G7 = ({ a: string, b: number }) => typeof number; // Error +>G7 : ({ a, b }: { a: any; b: any; }) => any +>a : any +>string : any +>b : any +>number : any +>number : any + +type G8 = ({ a, b: number }) => typeof number; // OK +>G8 : ({ a, b }: { a: any; b: any; }) => any +>a : any +>b : any +>number : any +>number : any + +type G9 = ([a, b, c]) => void; // Error +>G9 : ([a, b, c]: [any, any, any]) => void +>a : any +>b : any +>c : any + +interface I { + method1(arg: number): any; // OK +>method1 : (arg: number) => any +>arg : number + + method2({ a: string }): any; // Error +>method2 : ({ a }: { a: any; }) => any +>a : any >string : any + (arg: number): any; // OK +>arg : number + + ({ a: string }): any; // Error +>a : any +>string : any + + new (arg: number): any; // OK +>arg : number + + new ({ a: string }): any; // Error +>a : any +>string : any +} diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt index a99d3c2954215..c274d106b1aa2 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt @@ -1,14 +1,93 @@ -tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts(1,15): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts(3,16): error TS7031: Binding element 'string' implicitly has an 'any' type. +tests/cases/compiler/a.d.ts(3,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(4,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(5,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(6,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(7,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(8,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(8,28): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(9,20): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(13,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(14,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(15,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(16,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(17,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(18,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(18,28): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(19,20): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(24,16): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(27,9): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/a.d.ts(30,13): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts (2 errors) ==== - type F = ({a: string}) => void; - ~~~~~~ +==== tests/cases/compiler/a.d.ts (19 errors) ==== + type O = { a: string; b: number; c: number; }; + type F1 = (arg: number) => any; + type F2 = ({ a: string }: O) => any; + ~~~~~~ !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F3 = ({ a: string, b, c }: O) => any; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F4 = ({ a: string }: O) => any; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F5 = ({ a: string, b, c }: O) => any; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F6 = ({ a: string }) => typeof string; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F7 = ({ a: string, b: number }) => typeof number; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F8 = ({ a, b: number }) => typeof number; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type F9 = ([a, b, c]) => void; - const f = ({a: string}) => string; + type G1 = (arg: number) => any; + type G2 = ({ a: string }: O) => any; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G3 = ({ a: string, b, c }: O) => any; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G4 = ({ a: string }: O) => any; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G5 = ({ a: string, b, c }: O) => any; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G6 = ({ a: string }) => typeof string; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G7 = ({ a: string, b: number }) => typeof number; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G8 = ({ a, b: number }) => typeof number; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + type G9 = ([a, b, c]) => void; + + interface I { + method1(arg: number): any; + method2({ a: string }): any; ~~~~~~ -!!! error TS7031: Binding element 'string' implicitly has an 'any' type. +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + + (arg: number): any; + ({ a: string }): any; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + + new (arg: number): any; + new ({ a: string }): any; + ~~~~~~ +!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. + } \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.symbols b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.symbols index 0e5dac47a3628..567f4fad62292 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.symbols +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.symbols @@ -1,13 +1,153 @@ -=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts === -type F = ({a: string}) => void; ->F : Symbol(F, Decl(renamingDestructuredPropertyInFunctionType2.ts, 0, 0)) +=== tests/cases/compiler/a.d.ts === +type O = { a: string; b: number; c: number; }; +>O : Symbol(O, Decl(a.d.ts, 0, 0)) +>a : Symbol(a, Decl(a.d.ts, 0, 10)) +>b : Symbol(b, Decl(a.d.ts, 0, 21)) +>c : Symbol(c, Decl(a.d.ts, 0, 32)) + +type F1 = (arg: number) => any; +>F1 : Symbol(F1, Decl(a.d.ts, 0, 46)) +>arg : Symbol(arg, Decl(a.d.ts, 1, 11)) + +type F2 = ({ a: string }: O) => any; +>F2 : Symbol(F2, Decl(a.d.ts, 1, 31)) +>a : Symbol(a, Decl(a.d.ts, 0, 10)) +>string : Symbol(string, Decl(a.d.ts, 2, 12)) +>O : Symbol(O, Decl(a.d.ts, 0, 0)) + +type F3 = ({ a: string, b, c }: O) => any; +>F3 : Symbol(F3, Decl(a.d.ts, 2, 36)) +>a : Symbol(a, Decl(a.d.ts, 0, 10)) +>string : Symbol(string, Decl(a.d.ts, 3, 12)) +>b : Symbol(b, Decl(a.d.ts, 3, 23)) +>c : Symbol(c, Decl(a.d.ts, 3, 26)) +>O : Symbol(O, Decl(a.d.ts, 0, 0)) + +type F4 = ({ a: string }: O) => any; +>F4 : Symbol(F4, Decl(a.d.ts, 3, 42)) +>a : Symbol(a, Decl(a.d.ts, 0, 10)) +>string : Symbol(string, Decl(a.d.ts, 4, 12)) +>O : Symbol(O, Decl(a.d.ts, 0, 0)) + +type F5 = ({ a: string, b, c }: O) => any; +>F5 : Symbol(F5, Decl(a.d.ts, 4, 36)) +>a : Symbol(a, Decl(a.d.ts, 0, 10)) +>string : Symbol(string, Decl(a.d.ts, 5, 12)) +>b : Symbol(b, Decl(a.d.ts, 5, 23)) +>c : Symbol(c, Decl(a.d.ts, 5, 26)) +>O : Symbol(O, Decl(a.d.ts, 0, 0)) + +type F6 = ({ a: string }) => typeof string; +>F6 : Symbol(F6, Decl(a.d.ts, 5, 42)) +>a : Symbol(a) +>string : Symbol(string, Decl(a.d.ts, 6, 12)) +>string : Symbol(string, Decl(a.d.ts, 6, 12)) + +type F7 = ({ a: string, b: number }) => typeof number; +>F7 : Symbol(F7, Decl(a.d.ts, 6, 43)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType2.ts, 0, 11)) +>string : Symbol(string, Decl(a.d.ts, 7, 12)) +>b : Symbol(b) +>number : Symbol(number, Decl(a.d.ts, 7, 23)) +>number : Symbol(number, Decl(a.d.ts, 7, 23)) + +type F8 = ({ a, b: number }) => typeof number; +>F8 : Symbol(F8, Decl(a.d.ts, 7, 54)) +>a : Symbol(a, Decl(a.d.ts, 8, 12)) +>b : Symbol(b) +>number : Symbol(number, Decl(a.d.ts, 8, 15)) +>number : Symbol(number, Decl(a.d.ts, 8, 15)) + +type F9 = ([a, b, c]) => void; +>F9 : Symbol(F9, Decl(a.d.ts, 8, 46)) +>a : Symbol(a, Decl(a.d.ts, 9, 12)) +>b : Symbol(b, Decl(a.d.ts, 9, 14)) +>c : Symbol(c, Decl(a.d.ts, 9, 17)) + +type G1 = (arg: number) => any; +>G1 : Symbol(G1, Decl(a.d.ts, 9, 30)) +>arg : Symbol(arg, Decl(a.d.ts, 11, 11)) + +type G2 = ({ a: string }: O) => any; +>G2 : Symbol(G2, Decl(a.d.ts, 11, 31)) +>a : Symbol(a, Decl(a.d.ts, 0, 10)) +>string : Symbol(string, Decl(a.d.ts, 12, 12)) +>O : Symbol(O, Decl(a.d.ts, 0, 0)) + +type G3 = ({ a: string, b, c }: O) => any; +>G3 : Symbol(G3, Decl(a.d.ts, 12, 36)) +>a : Symbol(a, Decl(a.d.ts, 0, 10)) +>string : Symbol(string, Decl(a.d.ts, 13, 12)) +>b : Symbol(b, Decl(a.d.ts, 13, 23)) +>c : Symbol(c, Decl(a.d.ts, 13, 26)) +>O : Symbol(O, Decl(a.d.ts, 0, 0)) + +type G4 = ({ a: string }: O) => any; +>G4 : Symbol(G4, Decl(a.d.ts, 13, 42)) +>a : Symbol(a, Decl(a.d.ts, 0, 10)) +>string : Symbol(string, Decl(a.d.ts, 14, 12)) +>O : Symbol(O, Decl(a.d.ts, 0, 0)) + +type G5 = ({ a: string, b, c }: O) => any; +>G5 : Symbol(G5, Decl(a.d.ts, 14, 36)) +>a : Symbol(a, Decl(a.d.ts, 0, 10)) +>string : Symbol(string, Decl(a.d.ts, 15, 12)) +>b : Symbol(b, Decl(a.d.ts, 15, 23)) +>c : Symbol(c, Decl(a.d.ts, 15, 26)) +>O : Symbol(O, Decl(a.d.ts, 0, 0)) + +type G6 = ({ a: string }) => typeof string; +>G6 : Symbol(G6, Decl(a.d.ts, 15, 42)) +>a : Symbol(a) +>string : Symbol(string, Decl(a.d.ts, 16, 12)) +>string : Symbol(string, Decl(a.d.ts, 16, 12)) + +type G7 = ({ a: string, b: number }) => typeof number; +>G7 : Symbol(G7, Decl(a.d.ts, 16, 43)) +>a : Symbol(a) +>string : Symbol(string, Decl(a.d.ts, 17, 12)) +>b : Symbol(b) +>number : Symbol(number, Decl(a.d.ts, 17, 23)) +>number : Symbol(number, Decl(a.d.ts, 17, 23)) + +type G8 = ({ a, b: number }) => typeof number; +>G8 : Symbol(G8, Decl(a.d.ts, 17, 54)) +>a : Symbol(a, Decl(a.d.ts, 18, 12)) +>b : Symbol(b) +>number : Symbol(number, Decl(a.d.ts, 18, 15)) +>number : Symbol(number, Decl(a.d.ts, 18, 15)) + +type G9 = ([a, b, c]) => void; +>G9 : Symbol(G9, Decl(a.d.ts, 18, 46)) +>a : Symbol(a, Decl(a.d.ts, 19, 12)) +>b : Symbol(b, Decl(a.d.ts, 19, 14)) +>c : Symbol(c, Decl(a.d.ts, 19, 17)) + +interface I { +>I : Symbol(I, Decl(a.d.ts, 19, 30)) + + method1(arg: number): any; +>method1 : Symbol(I.method1, Decl(a.d.ts, 21, 13)) +>arg : Symbol(arg, Decl(a.d.ts, 22, 10)) + + method2({ a: string }): any; +>method2 : Symbol(I.method2, Decl(a.d.ts, 22, 28)) +>a : Symbol(a) +>string : Symbol(string, Decl(a.d.ts, 23, 11)) + + (arg: number): any; +>arg : Symbol(arg, Decl(a.d.ts, 25, 3)) + + ({ a: string }): any; +>a : Symbol(a) +>string : Symbol(string, Decl(a.d.ts, 26, 4)) + + new (arg: number): any; +>arg : Symbol(arg, Decl(a.d.ts, 28, 7)) -const f = ({a: string}) => string; ->f : Symbol(f, Decl(renamingDestructuredPropertyInFunctionType2.ts, 2, 5)) + new ({ a: string }): any; >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType2.ts, 2, 12)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType2.ts, 2, 12)) +>string : Symbol(string, Decl(a.d.ts, 29, 8)) +} diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types index 46bae2330b183..237a2ac364150 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types @@ -1,14 +1,143 @@ -=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts === -type F = ({a: string}) => void; ->F : ({ a }: { a: any; }) => void +=== tests/cases/compiler/a.d.ts === +type O = { a: string; b: number; c: number; }; +>O : { a: string; b: number; c: number; } +>a : string +>b : number +>c : number + +type F1 = (arg: number) => any; +>F1 : (arg: number) => any +>arg : number + +type F2 = ({ a: string }: O) => any; +>F2 : ({ a }: O) => any +>a : any +>string : string + +type F3 = ({ a: string, b, c }: O) => any; +>F3 : ({ a, b, c }: O) => any +>a : any +>string : string +>b : number +>c : number + +type F4 = ({ a: string }: O) => any; +>F4 : ({ a }: O) => any +>a : any +>string : string + +type F5 = ({ a: string, b, c }: O) => any; +>F5 : ({ a, b, c }: O) => any +>a : any +>string : string +>b : number +>c : number + +type F6 = ({ a: string }) => typeof string; +>F6 : ({ a }: { a: any; }) => any +>a : any +>string : any +>string : any + +type F7 = ({ a: string, b: number }) => typeof number; +>F7 : ({ a, b }: { a: any; b: any; }) => any +>a : any +>string : any +>b : any +>number : any +>number : any + +type F8 = ({ a, b: number }) => typeof number; +>F8 : ({ a, b }: { a: any; b: any; }) => any +>a : any +>b : any +>number : any +>number : any + +type F9 = ([a, b, c]) => void; +>F9 : ([a, b, c]: [any, any, any]) => void +>a : any +>b : any +>c : any + +type G1 = (arg: number) => any; +>G1 : (arg: number) => any +>arg : number + +type G2 = ({ a: string }: O) => any; +>G2 : ({ a }: O) => any +>a : any +>string : string + +type G3 = ({ a: string, b, c }: O) => any; +>G3 : ({ a, b, c }: O) => any +>a : any +>string : string +>b : number +>c : number + +type G4 = ({ a: string }: O) => any; +>G4 : ({ a }: O) => any +>a : any +>string : string + +type G5 = ({ a: string, b, c }: O) => any; +>G5 : ({ a, b, c }: O) => any +>a : any +>string : string +>b : number +>c : number + +type G6 = ({ a: string }) => typeof string; +>G6 : ({ a }: { a: any; }) => any >a : any >string : any +>string : any -const f = ({a: string}) => string; ->f : ({ a }: { a: any; }) => any ->({a: string}) => string : ({ a }: { a: any; }) => any +type G7 = ({ a: string, b: number }) => typeof number; +>G7 : ({ a, b }: { a: any; b: any; }) => any >a : any >string : any +>b : any +>number : any +>number : any + +type G8 = ({ a, b: number }) => typeof number; +>G8 : ({ a, b }: { a: any; b: any; }) => any +>a : any +>b : any +>number : any +>number : any + +type G9 = ([a, b, c]) => void; +>G9 : ([a, b, c]: [any, any, any]) => void +>a : any +>b : any +>c : any + +interface I { + method1(arg: number): any; +>method1 : (arg: number) => any +>arg : number + + method2({ a: string }): any; +>method2 : ({ a }: { a: any; }) => any +>a : any +>string : any + + (arg: number): any; +>arg : number + + ({ a: string }): any; +>a : any +>string : any + + new (arg: number): any; +>arg : number + + new ({ a: string }): any; +>a : any >string : any +} diff --git a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts index c61bbe96700dd..b1aeabb429ace 100644 --- a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts +++ b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts @@ -1,3 +1,31 @@ -type F = ({a: string}) => void; +type O = { a: string; b: number; c: number; }; +type F1 = (arg: number) => any; // OK +type F2 = ({ a: string }: O) => any; // Error +type F3 = ({ a: string, b, c }: O) => any; // Error +type F4 = ({ a: string }: O) => any; // Error +type F5 = ({ a: string, b, c }: O) => any; // Error +type F6 = ({ a: string }) => typeof string; // OK +type F7 = ({ a: string, b: number }) => typeof number; // Error +type F8 = ({ a, b: number }) => typeof number; // OK +type F9 = ([a, b, c]) => void; // Error -const f = ({a: string}) => string; +type G1 = (arg: number) => any; // OK +type G2 = ({ a: string }: O) => any; // Error +type G3 = ({ a: string, b, c }: O) => any; // Error +type G4 = ({ a: string }: O) => any; // Error +type G5 = ({ a: string, b, c }: O) => any; // Error +type G6 = ({ a: string }) => typeof string; // OK +type G7 = ({ a: string, b: number }) => typeof number; // Error +type G8 = ({ a, b: number }) => typeof number; // OK +type G9 = ([a, b, c]) => void; // Error + +interface I { + method1(arg: number): any; // OK + method2({ a: string }): any; // Error + + (arg: number): any; // OK + ({ a: string }): any; // Error + + new (arg: number): any; // OK + new ({ a: string }): any; // Error +} \ No newline at end of file diff --git a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts index 9f56fe8a11937..3653d833b4303 100644 --- a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts +++ b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType2.ts @@ -1,5 +1,33 @@ -// @noImplicitAny: true -type F = ({a: string}) => void; +// @filename: a.d.ts +type O = { a: string; b: number; c: number; }; +type F1 = (arg: number) => any; +type F2 = ({ a: string }: O) => any; +type F3 = ({ a: string, b, c }: O) => any; +type F4 = ({ a: string }: O) => any; +type F5 = ({ a: string, b, c }: O) => any; +type F6 = ({ a: string }) => typeof string; +type F7 = ({ a: string, b: number }) => typeof number; +type F8 = ({ a, b: number }) => typeof number; +type F9 = ([a, b, c]) => void; -const f = ({a: string}) => string; +type G1 = (arg: number) => any; +type G2 = ({ a: string }: O) => any; +type G3 = ({ a: string, b, c }: O) => any; +type G4 = ({ a: string }: O) => any; +type G5 = ({ a: string, b, c }: O) => any; +type G6 = ({ a: string }) => typeof string; +type G7 = ({ a: string, b: number }) => typeof number; +type G8 = ({ a, b: number }) => typeof number; +type G9 = ([a, b, c]) => void; + +interface I { + method1(arg: number): any; + method2({ a: string }): any; + + (arg: number): any; + ({ a: string }): any; + + new (arg: number): any; + new ({ a: string }): any; +} From 79ef4fd0b047fc94742203763846e88d41df61ba Mon Sep 17 00:00:00 2001 From: uhyo Date: Wed, 8 Jun 2022 23:20:11 +0900 Subject: [PATCH 07/31] get correct result --- src/compiler/checker.ts | 29 +++++- ...tructuredPropertyInFunctionType.errors.txt | 20 +--- ...ructuredPropertyInFunctionType2.errors.txt | 93 ------------------- 3 files changed, 27 insertions(+), 115 deletions(-) delete mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6cd04997179c2..78088de0c3d5f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1026,6 +1026,11 @@ namespace ts { const potentialNewTargetCollisions: Node[] = []; const potentialWeakMapSetCollisions: Node[] = []; const potentialReflectCollisions: Node[] = []; + const potentialAlwaysCheckedUnusedTypes: { + node: Node; + name: BindingName; + diagnostic: DiagnosticMessage; + }[] = []; const awaitedTypeStack: number[] = []; const diagnostics = createDiagnosticCollection(); @@ -37915,11 +37920,21 @@ namespace ts { } if (isBindingElement(node)) { - if (node.propertyName && isIdentifier(node.propertyName) && isIdentifier(node.name) && isParameterDeclaration(node) && nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) { + if ( + node.propertyName && + isIdentifier(node.propertyName) && + isIdentifier(node.name) && + isParameterDeclaration(node) && + nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) { // type F = ({a: string}) => void; // ^^^^^^ - // variable renaming in function type notation is confusing, so forbid it - error(node.name, Diagnostics.Renaming_a_property_in_destructuring_assignment_is_only_allowed_in_a_function_or_constructor_implementation); + // variable renaming in function type notation is confusing, + // so we forbid it even if noUnusedLocals is not enabled + potentialAlwaysCheckedUnusedTypes.push({ + node, + name: node.name, + diagnostic: Diagnostics.Renaming_a_property_in_destructuring_assignment_is_only_allowed_in_a_function_or_constructor_implementation + }); return; } @@ -41766,6 +41781,7 @@ namespace ts { clear(potentialNewTargetCollisions); clear(potentialWeakMapSetCollisions); clear(potentialReflectCollisions); + clear(potentialAlwaysCheckedUnusedTypes); forEach(node.statements, checkSourceElement); checkSourceElement(node.endOfFileToken); @@ -41785,6 +41801,13 @@ namespace ts { } }); } + if (!node.isDeclarationFile && potentialAlwaysCheckedUnusedTypes.length) { + for (const { node, name, diagnostic } of potentialAlwaysCheckedUnusedTypes) { + if (!(getSymbolOfNode(node)?.isReferenced! & SymbolFlags.Type)) { + error(name, diagnostic); + } + } + } }); if (compilerOptions.importsNotUsedAsValues === ImportsNotUsedAsValues.Error && diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index 0a04f6fbeeb46..5e6ce63542123 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -2,24 +2,18 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(3,17): error tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(4,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(5,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(6,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(7,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,28): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(9,20): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(13,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(14,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(17,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,28): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(19,20): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,16): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,9): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (19 errors) ==== +==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (13 errors) ==== type O = { a: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error @@ -35,16 +29,10 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error ~~~~~~ !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. type F6 = ({ a: string }) => typeof string; // OK - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. type F7 = ({ a: string, b: number }) => typeof number; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - ~~~~~~ !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. type F8 = ({ a, b: number }) => typeof number; // OK - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. type F9 = ([a, b, c]) => void; // Error type G1 = (arg: number) => any; // OK @@ -61,16 +49,10 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error ~~~~~~ !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. type G6 = ({ a: string }) => typeof string; // OK - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. type G7 = ({ a: string, b: number }) => typeof number; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - ~~~~~~ !!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. type G8 = ({ a, b: number }) => typeof number; // OK - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. type G9 = ([a, b, c]) => void; // Error interface I { diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt deleted file mode 100644 index c274d106b1aa2..0000000000000 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.errors.txt +++ /dev/null @@ -1,93 +0,0 @@ -tests/cases/compiler/a.d.ts(3,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(4,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(5,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(6,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(7,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(8,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(8,28): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(9,20): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(13,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(14,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(15,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(16,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(17,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(18,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(18,28): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(19,20): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(24,16): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(27,9): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/a.d.ts(30,13): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - - -==== tests/cases/compiler/a.d.ts (19 errors) ==== - type O = { a: string; b: number; c: number; }; - type F1 = (arg: number) => any; - type F2 = ({ a: string }: O) => any; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type F3 = ({ a: string, b, c }: O) => any; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type F4 = ({ a: string }: O) => any; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type F5 = ({ a: string, b, c }: O) => any; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type F6 = ({ a: string }) => typeof string; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type F7 = ({ a: string, b: number }) => typeof number; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type F8 = ({ a, b: number }) => typeof number; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type F9 = ([a, b, c]) => void; - - type G1 = (arg: number) => any; - type G2 = ({ a: string }: O) => any; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type G3 = ({ a: string, b, c }: O) => any; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type G4 = ({ a: string }: O) => any; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type G5 = ({ a: string, b, c }: O) => any; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type G6 = ({ a: string }) => typeof string; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type G7 = ({ a: string, b: number }) => typeof number; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type G8 = ({ a, b: number }) => typeof number; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - type G9 = ([a, b, c]) => void; - - interface I { - method1(arg: number): any; - method2({ a: string }): any; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - - (arg: number): any; - ({ a: string }): any; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - - new (arg: number): any; - new ({ a: string }): any; - ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. - } - - \ No newline at end of file From 69b8a58ca1fbd5530cd28949670699c15a7730ab Mon Sep 17 00:00:00 2001 From: uhyo Date: Wed, 8 Jun 2022 23:37:57 +0900 Subject: [PATCH 08/31] update diagnostic text --- src/compiler/checker.ts | 20 ++++--- src/compiler/diagnosticMessages.json | 2 +- ...tructuredPropertyInFunctionType.errors.txt | 52 +++++++++---------- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 78088de0c3d5f..31d5f2da97fdb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1028,7 +1028,7 @@ namespace ts { const potentialReflectCollisions: Node[] = []; const potentialAlwaysCheckedUnusedTypes: { node: Node; - name: BindingName; + name: Identifier; diagnostic: DiagnosticMessage; }[] = []; const awaitedTypeStack: number[] = []; @@ -37579,6 +37579,14 @@ namespace ts { }); } + function checkPotentialAlwaysCheckedUnusedTypes() { + for (const { node, name, diagnostic } of potentialAlwaysCheckedUnusedTypes) { + if (!(getSymbolOfNode(node)?.isReferenced! & SymbolFlags.Type)) { + error(name, diagnostic, declarationNameToString(name)); + } + } + } + function bindingNameText(name: BindingName): string { switch (name.kind) { case SyntaxKind.Identifier: @@ -37933,7 +37941,7 @@ namespace ts { potentialAlwaysCheckedUnusedTypes.push({ node, name: node.name, - diagnostic: Diagnostics.Renaming_a_property_in_destructuring_assignment_is_only_allowed_in_a_function_or_constructor_implementation + diagnostic: Diagnostics.Variable_0_is_not_used_Did_you_mean_to_write_a_type_annotation_for_whole_object }); return; } @@ -41801,12 +41809,8 @@ namespace ts { } }); } - if (!node.isDeclarationFile && potentialAlwaysCheckedUnusedTypes.length) { - for (const { node, name, diagnostic } of potentialAlwaysCheckedUnusedTypes) { - if (!(getSymbolOfNode(node)?.isReferenced! & SymbolFlags.Type)) { - error(name, diagnostic); - } - } + if (!node.isDeclarationFile) { + checkPotentialAlwaysCheckedUnusedTypes(); } }); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6d1df373a2919..1df0c5f12a23a 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3487,7 +3487,7 @@ "category": "Error", "code": 2841 }, - "Renaming a property in destructuring assignment is only allowed in a function or constructor implementation.": { + "Variable '{0}' is not used. Did you mean to write a type annotation for whole object?": { "category": "Error", "code": 2842 }, diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index 5e6ce63542123..dbef15bf69d6c 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -1,16 +1,16 @@ -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(3,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(4,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(5,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(6,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(13,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(14,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,17): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,16): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,9): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(3,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(4,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(5,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(6,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(13,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(14,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,16): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,9): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? ==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (13 errors) ==== @@ -18,40 +18,40 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type F3 = ({ a: string, b, c }: O) => any; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type F4 = ({ a: string }: O) => any; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type F5 = ({ a: string, b, c }: O) => any; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type F6 = ({ a: string }) => typeof string; // OK type F7 = ({ a: string, b: number }) => typeof number; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type F8 = ({ a, b: number }) => typeof number; // OK type F9 = ([a, b, c]) => void; // Error type G1 = (arg: number) => any; // OK type G2 = ({ a: string }: O) => any; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type G3 = ({ a: string, b, c }: O) => any; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type G4 = ({ a: string }: O) => any; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type G5 = ({ a: string, b, c }: O) => any; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type G6 = ({ a: string }) => typeof string; // OK type G7 = ({ a: string, b: number }) => typeof number; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type G8 = ({ a, b: number }) => typeof number; // OK type G9 = ([a, b, c]) => void; // Error @@ -59,15 +59,15 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error method1(arg: number): any; // OK method2({ a: string }): any; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? (arg: number): any; // OK ({ a: string }): any; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? new (arg: number): any; // OK new ({ a: string }): any; // Error ~~~~~~ -!!! error TS2842: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? } \ No newline at end of file From 4ddd9aec8ecd40b671c6c705bf0de9cad801bbd5 Mon Sep 17 00:00:00 2001 From: uhyo Date: Wed, 8 Jun 2022 23:51:13 +0900 Subject: [PATCH 09/31] accept baseline --- .../reference/destructuringInFunctionType.errors.txt | 8 ++++---- .../baselines/reference/destructuringInFunctionType.types | 2 +- .../reference/excessPropertyCheckWithSpread.errors.txt | 4 ++-- .../reference/paramterDestrcuturingDeclaration.errors.txt | 8 ++++---- .../tsxStatelessFunctionComponentOverload1.errors.txt | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/baselines/reference/destructuringInFunctionType.errors.txt b/tests/baselines/reference/destructuringInFunctionType.errors.txt index da7a2fc32bbf1..06b1eeffee422 100644 --- a/tests/baselines/reference/destructuringInFunctionType.errors.txt +++ b/tests/baselines/reference/destructuringInFunctionType.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,18): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,28): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,18): error TS2842: Variable 'b' is not used. Did you mean to write a type annotation for whole object? +tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,28): error TS2842: Variable 'a' is not used. Did you mean to write a type annotation for whole object? ==== tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts (2 errors) ==== @@ -16,9 +16,9 @@ tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,28): type T3 = ([{ a: b }, { b: a }]); type F3 = ([{ a: b }, { b: a }]) => void; ~ -!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'b' is not used. Did you mean to write a type annotation for whole object? ~ -!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'a' is not used. Did you mean to write a type annotation for whole object? type T4 = ([{ a: [b, c] }]); type F4 = ([{ a: [b, c] }]) => void; diff --git a/tests/baselines/reference/destructuringInFunctionType.types b/tests/baselines/reference/destructuringInFunctionType.types index 2b7f0de66ccf7..553fdaa9cf3b0 100644 --- a/tests/baselines/reference/destructuringInFunctionType.types +++ b/tests/baselines/reference/destructuringInFunctionType.types @@ -31,7 +31,7 @@ type T3 = ([{ a: b }, { b: a }]); >b : a type F3 = ([{ a: b }, { b: a }]) => void; ->F3 : ([{ a: b }, { b: a }]: [{ a: any; }, { b: any; }]) => void +>F3 : ([{ a }, { b }]: [{ a: any; }, { b: any; }]) => void >a : any >b : any >b : any diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt index 9ae33a275805d..85975abec2d0c 100644 --- a/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/excessPropertyCheckWithSpread.ts(1,25): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/excessPropertyCheckWithSpread.ts(1,25): error TS2842: Variable 'number' is not used. Did you mean to write a type annotation for whole object? ==== tests/cases/compiler/excessPropertyCheckWithSpread.ts (1 errors) ==== declare function f({ a: number }): void ~~~~~~ -!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'number' is not used. Did you mean to write a type annotation for whole object? interface I { readonly n: number; } diff --git a/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt b/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt index 69e5d888a1b0c..4225815bb0d5d 100644 --- a/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt +++ b/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/paramterDestrcuturingDeclaration.ts(2,10): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. -tests/cases/compiler/paramterDestrcuturingDeclaration.ts(3,14): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/compiler/paramterDestrcuturingDeclaration.ts(2,10): error TS2842: Variable 'name' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/paramterDestrcuturingDeclaration.ts(3,14): error TS2842: Variable 'boolean' is not used. Did you mean to write a type annotation for whole object? ==== tests/cases/compiler/paramterDestrcuturingDeclaration.ts (2 errors) ==== interface C { ({p: name}): any; ~~~~ -!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'name' is not used. Did you mean to write a type annotation for whole object? new ({p: boolean}): any; ~~~~~~~ -!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'boolean' is not used. Did you mean to write a type annotation for whole object? } \ No newline at end of file diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt index 69c6d7d79e3c2..189333949ae82 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/jsx/file.tsx(17,39): error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +tests/cases/conformance/jsx/file.tsx(17,39): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? ==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== @@ -20,7 +20,7 @@ tests/cases/conformance/jsx/file.tsx(17,39): error TS2797: Renaming a property i declare function TestingOneThing({y1: string}): JSX.Element; ~~~~~~ -!!! error TS2797: Renaming a property in destructuring assignment is only allowed in a function or constructor implementation. +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element; declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element; declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; From e21048485c54eb57ac2386bdcb4f94954b6572de Mon Sep 17 00:00:00 2001 From: uhyo Date: Wed, 8 Jun 2022 23:56:44 +0900 Subject: [PATCH 10/31] add declaration emit test --- ...amingDestructuredPropertyInFunctionType.js | 56 +++++++++++++++++++ ...amingDestructuredPropertyInFunctionType.ts | 1 + 2 files changed, 57 insertions(+) diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js index 634f2fd3512d7..445ca0d8c1af0 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js @@ -32,3 +32,59 @@ interface I { } //// [renamingDestructuredPropertyInFunctionType.js] + + +//// [renamingDestructuredPropertyInFunctionType.d.ts] +declare type O = { + a: string; + b: number; + c: number; +}; +declare type F1 = (arg: number) => any; +declare type F2 = ({ a }: O) => any; +declare type F3 = ({ a, b, c }: O) => any; +declare type F4 = ({ a }: O) => any; +declare type F5 = ({ a, b, c }: O) => any; +declare type F6 = ({ a }: { + a: any; +}) => typeof string; +declare type F7 = ({ a, b }: { + a: any; + b: any; +}) => typeof number; +declare type F8 = ({ a, b }: { + a: any; + b: any; +}) => typeof number; +declare type F9 = ([a, b, c]: [any, any, any]) => void; +declare type G1 = (arg: number) => any; +declare type G2 = ({ a }: O) => any; +declare type G3 = ({ a, b, c }: O) => any; +declare type G4 = ({ a }: O) => any; +declare type G5 = ({ a, b, c }: O) => any; +declare type G6 = ({ a }: { + a: any; +}) => typeof string; +declare type G7 = ({ a, b }: { + a: any; + b: any; +}) => typeof number; +declare type G8 = ({ a, b }: { + a: any; + b: any; +}) => typeof number; +declare type G9 = ([a, b, c]: [any, any, any]) => void; +interface I { + method1(arg: number): any; + method2({ a }: { + a: any; + }): any; + (arg: number): any; + ({ a }: { + a: any; + }): any; + new (arg: number): any; + new ({ a }: { + a: any; + }): any; +} diff --git a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts index b1aeabb429ace..1fe6b480c3c9e 100644 --- a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts +++ b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts @@ -1,3 +1,4 @@ +// @declaration: true type O = { a: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error From 2797958ece3fb0044f2d75977ea2ba4c708710ef Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 00:03:29 +0900 Subject: [PATCH 11/31] fix declaration emit --- src/compiler/transformers/declarations.ts | 2445 +++++++++++++---- ...amingDestructuredPropertyInFunctionType.js | 12 +- 2 files changed, 1849 insertions(+), 608 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 3453eae95b210..0a09614535931 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -1,35 +1,82 @@ /*@internal*/ namespace ts { - export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, file: SourceFile | undefined): DiagnosticWithLocation[] | undefined { + export function getDeclarationDiagnostics( + host: EmitHost, + resolver: EmitResolver, + file: SourceFile | undefined + ): DiagnosticWithLocation[] | undefined { const compilerOptions = host.getCompilerOptions(); - const result = transformNodes(resolver, host, factory, compilerOptions, file ? [file] : filter(host.getSourceFiles(), isSourceFileNotJson), [transformDeclarations], /*allowDtsFiles*/ false); + const result = transformNodes( + resolver, + host, + factory, + compilerOptions, + file ? [file] : filter(host.getSourceFiles(), isSourceFileNotJson), + [transformDeclarations], + /*allowDtsFiles*/ false + ); return result.diagnostics; } - function hasInternalAnnotation(range: CommentRange, currentSourceFile: SourceFile) { + function hasInternalAnnotation( + range: CommentRange, + currentSourceFile: SourceFile + ) { const comment = currentSourceFile.text.substring(range.pos, range.end); return stringContains(comment, "@internal"); } - export function isInternalDeclaration(node: Node, currentSourceFile: SourceFile) { + export function isInternalDeclaration( + node: Node, + currentSourceFile: SourceFile + ) { const parseTreeNode = getParseTreeNode(node); if (parseTreeNode && parseTreeNode.kind === SyntaxKind.Parameter) { - const paramIdx = (parseTreeNode.parent as SignatureDeclaration).parameters.indexOf(parseTreeNode as ParameterDeclaration); - const previousSibling = paramIdx > 0 ? (parseTreeNode.parent as SignatureDeclaration).parameters[paramIdx - 1] : undefined; + const paramIdx = ( + parseTreeNode.parent as SignatureDeclaration + ).parameters.indexOf(parseTreeNode as ParameterDeclaration); + const previousSibling = + paramIdx > 0 + ? (parseTreeNode.parent as SignatureDeclaration).parameters[ + paramIdx - 1 + ] + : undefined; const text = currentSourceFile.text; const commentRanges = previousSibling ? concatenate( - // to handle - // ... parameters, /* @internal */ - // public param: string - getTrailingCommentRanges(text, skipTrivia(text, previousSibling.end + 1, /* stopAfterLineBreak */ false, /* stopAtComments */ true)), - getLeadingCommentRanges(text, node.pos) - ) - : getTrailingCommentRanges(text, skipTrivia(text, node.pos, /* stopAfterLineBreak */ false, /* stopAtComments */ true)); - return commentRanges && commentRanges.length && hasInternalAnnotation(last(commentRanges), currentSourceFile); + // to handle + // ... parameters, /* @internal */ + // public param: string + getTrailingCommentRanges( + text, + skipTrivia( + text, + previousSibling.end + 1, + /* stopAfterLineBreak */ false, + /* stopAtComments */ true + ) + ), + getLeadingCommentRanges(text, node.pos) + ) + : getTrailingCommentRanges( + text, + skipTrivia( + text, + node.pos, + /* stopAfterLineBreak */ false, + /* stopAtComments */ true + ) + ); + return ( + commentRanges && + commentRanges.length && + hasInternalAnnotation(last(commentRanges), currentSourceFile) + ); } - const leadingCommentRanges = parseTreeNode && getLeadingCommentRangesOfNode(parseTreeNode, currentSourceFile); - return !!forEach(leadingCommentRanges, range => { + const leadingCommentRanges = + parseTreeNode && + getLeadingCommentRangesOfNode(parseTreeNode, currentSourceFile); + return !!forEach(leadingCommentRanges, (range) => { return hasInternalAnnotation(range, currentSourceFile); }); } @@ -50,17 +97,29 @@ namespace ts { * This means that _no transforms should be allowed to occur before this one_. */ export function transformDeclarations(context: TransformationContext) { - const throwDiagnostic = () => Debug.fail("Diagnostic emitted without context"); - let getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic = throwDiagnostic; + const throwDiagnostic = () => + Debug.fail("Diagnostic emitted without context"); + let getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic = + throwDiagnostic; let needsDeclare = true; let isBundledEmit = false; let resultHasExternalModuleIndicator = false; let needsScopeFixMarker = false; let resultHasScopeMarker = false; let enclosingDeclaration: Node; - let necessaryTypeReferences: Set<[specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined]> | undefined; + let necessaryTypeReferences: + | Set< + [ + specifier: string, + mode: SourceFile["impliedNodeFormat"] | undefined + ] + > + | undefined; let lateMarkedStatements: LateVisibilityPaintedStatement[] | undefined; - let lateStatementReplacementMap: ESMap>; + let lateStatementReplacementMap: ESMap< + NodeId, + VisitResult + >; let suppressNewDiagnosticContexts: boolean; let exportedModulesFromDeclarationEmit: Symbol[] | undefined; @@ -93,7 +152,14 @@ namespace ts { const { noResolve, stripInternal } = options; return transformRoot; - function recordTypeReferenceDirectivesIfNecessary(typeReferenceDirectives: readonly [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined][] | undefined): void { + function recordTypeReferenceDirectivesIfNecessary( + typeReferenceDirectives: + | readonly [ + specifier: string, + mode: SourceFile["impliedNodeFormat"] | undefined + ][] + | undefined + ): void { if (!typeReferenceDirectives) { return; } @@ -103,9 +169,15 @@ namespace ts { } } - function trackReferencedAmbientModule(node: ModuleDeclaration, symbol: Symbol) { + function trackReferencedAmbientModule( + node: ModuleDeclaration, + symbol: Symbol + ) { // If it is visible via `// `, then we should just use that - const directives = resolver.getTypeReferenceDirectivesForSymbol(symbol, SymbolFlags.All); + const directives = resolver.getTypeReferenceDirectivesForSymbol( + symbol, + SymbolFlags.All + ); if (length(directives)) { return recordTypeReferenceDirectivesIfNecessary(directives); } @@ -114,14 +186,22 @@ namespace ts { refs.set(getOriginalNodeId(container), container); } - function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) { - if (symbolAccessibilityResult.accessibility === SymbolAccessibility.Accessible) { + function handleSymbolAccessibilityError( + symbolAccessibilityResult: SymbolAccessibilityResult + ) { + if ( + symbolAccessibilityResult.accessibility === + SymbolAccessibility.Accessible + ) { // Add aliases back onto the possible imports list if they're not there so we can try them again with updated visibility info - if (symbolAccessibilityResult && symbolAccessibilityResult.aliasesToMakeVisible) { + if ( + symbolAccessibilityResult && + symbolAccessibilityResult.aliasesToMakeVisible + ) { if (!lateMarkedStatements) { - lateMarkedStatements = symbolAccessibilityResult.aliasesToMakeVisible; - } - else { + lateMarkedStatements = + symbolAccessibilityResult.aliasesToMakeVisible; + } else { for (const ref of symbolAccessibilityResult.aliasesToMakeVisible) { pushIfUnique(lateMarkedStatements, ref); } @@ -129,23 +209,33 @@ namespace ts { } // TODO: Do all these accessibility checks inside/after the first pass in the checker when declarations are enabled, if possible - } - else { + } else { // Report error - const errorInfo = getSymbolAccessibilityDiagnostic(symbolAccessibilityResult); + const errorInfo = getSymbolAccessibilityDiagnostic( + symbolAccessibilityResult + ); if (errorInfo) { if (errorInfo.typeName) { - context.addDiagnostic(createDiagnosticForNode(symbolAccessibilityResult.errorNode || errorInfo.errorNode, - errorInfo.diagnosticMessage, - getTextOfNode(errorInfo.typeName), - symbolAccessibilityResult.errorSymbolName, - symbolAccessibilityResult.errorModuleName)); - } - else { - context.addDiagnostic(createDiagnosticForNode(symbolAccessibilityResult.errorNode || errorInfo.errorNode, - errorInfo.diagnosticMessage, - symbolAccessibilityResult.errorSymbolName, - symbolAccessibilityResult.errorModuleName)); + context.addDiagnostic( + createDiagnosticForNode( + symbolAccessibilityResult.errorNode || + errorInfo.errorNode, + errorInfo.diagnosticMessage, + getTextOfNode(errorInfo.typeName), + symbolAccessibilityResult.errorSymbolName, + symbolAccessibilityResult.errorModuleName + ) + ); + } else { + context.addDiagnostic( + createDiagnosticForNode( + symbolAccessibilityResult.errorNode || + errorInfo.errorNode, + errorInfo.diagnosticMessage, + symbolAccessibilityResult.errorSymbolName, + symbolAccessibilityResult.errorModuleName + ) + ); } return true; } @@ -155,102 +245,196 @@ namespace ts { function trackExternalModuleSymbolOfImportTypeNode(symbol: Symbol) { if (!isBundledEmit) { - (exportedModulesFromDeclarationEmit || (exportedModulesFromDeclarationEmit = [])).push(symbol); + ( + exportedModulesFromDeclarationEmit || + (exportedModulesFromDeclarationEmit = []) + ).push(symbol); } } - function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { + function trackSymbol( + symbol: Symbol, + enclosingDeclaration?: Node, + meaning?: SymbolFlags + ) { if (symbol.flags & SymbolFlags.TypeParameter) return false; - const issuedDiagnostic = handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ true)); - recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForSymbol(symbol, meaning)); + const issuedDiagnostic = handleSymbolAccessibilityError( + resolver.isSymbolAccessible( + symbol, + enclosingDeclaration, + meaning, + /*shouldComputeAliasesToMakeVisible*/ true + ) + ); + recordTypeReferenceDirectivesIfNecessary( + resolver.getTypeReferenceDirectivesForSymbol(symbol, meaning) + ); return issuedDiagnostic; } function reportPrivateInBaseOfClassExpression(propertyName: string) { if (errorNameNode || errorFallbackNode) { context.addDiagnostic( - createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.Property_0_of_exported_class_expression_may_not_be_private_or_protected, propertyName)); + createDiagnosticForNode( + (errorNameNode || errorFallbackNode)!, + Diagnostics.Property_0_of_exported_class_expression_may_not_be_private_or_protected, + propertyName + ) + ); } } function errorDeclarationNameWithFallback() { - return errorNameNode ? declarationNameToString(errorNameNode) : - errorFallbackNode && getNameOfDeclaration(errorFallbackNode) ? declarationNameToString(getNameOfDeclaration(errorFallbackNode)) : - errorFallbackNode && isExportAssignment(errorFallbackNode) ? errorFallbackNode.isExportEquals ? "export=" : "default" : - "(Missing)"; // same fallback declarationNameToString uses when node is zero-width (ie, nameless) + return errorNameNode + ? declarationNameToString(errorNameNode) + : errorFallbackNode && getNameOfDeclaration(errorFallbackNode) + ? declarationNameToString( + getNameOfDeclaration(errorFallbackNode) + ) + : errorFallbackNode && isExportAssignment(errorFallbackNode) + ? errorFallbackNode.isExportEquals + ? "export=" + : "default" + : "(Missing)"; // same fallback declarationNameToString uses when node is zero-width (ie, nameless) } function reportInaccessibleUniqueSymbolError() { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary, - errorDeclarationNameWithFallback(), - "unique symbol")); + context.addDiagnostic( + createDiagnosticForNode( + (errorNameNode || errorFallbackNode)!, + Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary, + errorDeclarationNameWithFallback(), + "unique symbol" + ) + ); } } function reportCyclicStructureError() { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_references_a_type_with_a_cyclic_structure_which_cannot_be_trivially_serialized_A_type_annotation_is_necessary, - errorDeclarationNameWithFallback())); + context.addDiagnostic( + createDiagnosticForNode( + (errorNameNode || errorFallbackNode)!, + Diagnostics.The_inferred_type_of_0_references_a_type_with_a_cyclic_structure_which_cannot_be_trivially_serialized_A_type_annotation_is_necessary, + errorDeclarationNameWithFallback() + ) + ); } } function reportInaccessibleThisError() { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary, - errorDeclarationNameWithFallback(), - "this")); + context.addDiagnostic( + createDiagnosticForNode( + (errorNameNode || errorFallbackNode)!, + Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary, + errorDeclarationNameWithFallback(), + "this" + ) + ); } } function reportLikelyUnsafeImportRequiredError(specifier: string) { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary, - errorDeclarationNameWithFallback(), - specifier)); + context.addDiagnostic( + createDiagnosticForNode( + (errorNameNode || errorFallbackNode)!, + Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary, + errorDeclarationNameWithFallback(), + specifier + ) + ); } } function reportTruncationError() { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_this_node_exceeds_the_maximum_length_the_compiler_will_serialize_An_explicit_type_annotation_is_needed)); + context.addDiagnostic( + createDiagnosticForNode( + (errorNameNode || errorFallbackNode)!, + Diagnostics.The_inferred_type_of_this_node_exceeds_the_maximum_length_the_compiler_will_serialize_An_explicit_type_annotation_is_needed + ) + ); } } - function reportNonlocalAugmentation(containingFile: SourceFile, parentSymbol: Symbol, symbol: Symbol) { - const primaryDeclaration = parentSymbol.declarations?.find(d => getSourceFileOfNode(d) === containingFile)!; - const augmentingDeclarations = filter(symbol.declarations, d => getSourceFileOfNode(d) !== containingFile); + function reportNonlocalAugmentation( + containingFile: SourceFile, + parentSymbol: Symbol, + symbol: Symbol + ) { + const primaryDeclaration = parentSymbol.declarations?.find( + (d) => getSourceFileOfNode(d) === containingFile + )!; + const augmentingDeclarations = filter( + symbol.declarations, + (d) => getSourceFileOfNode(d) !== containingFile + ); if (augmentingDeclarations) { for (const augmentations of augmentingDeclarations) { - context.addDiagnostic(addRelatedInfo( - createDiagnosticForNode(augmentations, Diagnostics.Declaration_augments_declaration_in_another_file_This_cannot_be_serialized), - createDiagnosticForNode(primaryDeclaration, Diagnostics.This_is_the_declaration_being_augmented_Consider_moving_the_augmenting_declaration_into_the_same_file) - )); + context.addDiagnostic( + addRelatedInfo( + createDiagnosticForNode( + augmentations, + Diagnostics.Declaration_augments_declaration_in_another_file_This_cannot_be_serialized + ), + createDiagnosticForNode( + primaryDeclaration, + Diagnostics.This_is_the_declaration_being_augmented_Consider_moving_the_augmenting_declaration_into_the_same_file + ) + ) + ); } } } function reportNonSerializableProperty(propertyName: string) { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_type_of_this_node_cannot_be_serialized_because_its_property_0_cannot_be_serialized, propertyName)); + context.addDiagnostic( + createDiagnosticForNode( + (errorNameNode || errorFallbackNode)!, + Diagnostics.The_type_of_this_node_cannot_be_serialized_because_its_property_0_cannot_be_serialized, + propertyName + ) + ); } } function reportImportTypeNodeResolutionModeOverride() { if (!isNightly() && (errorNameNode || errorFallbackNode)) { - context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + context.addDiagnostic( + createDiagnosticForNode( + (errorNameNode || errorFallbackNode)!, + Diagnostics.The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next + ) + ); } } - function transformDeclarationsForJS(sourceFile: SourceFile, bundled?: boolean) { + function transformDeclarationsForJS( + sourceFile: SourceFile, + bundled?: boolean + ) { const oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = (s) => (s.errorNode && canProduceDiagnostics(s.errorNode) ? createGetSymbolAccessibilityDiagnosticForNode(s.errorNode)(s) : ({ - diagnosticMessage: s.errorModuleName - ? Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotation_may_unblock_declaration_emit - : Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_An_explicit_type_annotation_may_unblock_declaration_emit, - errorNode: s.errorNode || sourceFile - })); - const result = resolver.getDeclarationStatementsForSourceFile(sourceFile, declarationEmitNodeBuilderFlags, symbolTracker, bundled); + getSymbolAccessibilityDiagnostic = (s) => + s.errorNode && canProduceDiagnostics(s.errorNode) + ? createGetSymbolAccessibilityDiagnosticForNode( + s.errorNode + )(s) + : { + diagnosticMessage: s.errorModuleName + ? Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotation_may_unblock_declaration_emit + : Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_An_explicit_type_annotation_may_unblock_declaration_emit, + errorNode: s.errorNode || sourceFile, + }; + const result = resolver.getDeclarationStatementsForSourceFile( + sourceFile, + declarationEmitNodeBuilderFlags, + symbolTracker, + bundled + ); getSymbolAccessibilityDiagnostic = oldDiag; return result; } @@ -268,10 +452,11 @@ namespace ts { refs = new Map(); libs = new Map(); let hasNoDefaultLib = false; - const bundle = factory.createBundle(map(node.sourceFiles, - sourceFile => { + const bundle = factory.createBundle( + map(node.sourceFiles, (sourceFile) => { if (sourceFile.isDeclarationFile) return undefined!; // Omit declaration files from bundle results, too // TODO: GH#18217 - hasNoDefaultLib = hasNoDefaultLib || sourceFile.hasNoDefaultLib; + hasNoDefaultLib = + hasNoDefaultLib || sourceFile.hasNoDefaultLib; currentSourceFile = sourceFile; enclosingDeclaration = sourceFile; lateMarkedStatements = undefined; @@ -282,39 +467,115 @@ namespace ts { resultHasScopeMarker = false; collectReferences(sourceFile, refs); collectLibs(sourceFile, libs); - if (isExternalOrCommonJsModule(sourceFile) || isJsonSourceFile(sourceFile)) { + if ( + isExternalOrCommonJsModule(sourceFile) || + isJsonSourceFile(sourceFile) + ) { resultHasExternalModuleIndicator = false; // unused in external module bundle emit (all external modules are within module blocks, therefore are known to be modules) needsDeclare = false; - const statements = isSourceFileJS(sourceFile) ? factory.createNodeArray(transformDeclarationsForJS(sourceFile, /*bundled*/ true)) : visitNodes(sourceFile.statements, visitDeclarationStatements); - const newFile = factory.updateSourceFile(sourceFile, [factory.createModuleDeclaration( - [], - [factory.createModifier(SyntaxKind.DeclareKeyword)], - factory.createStringLiteral(getResolvedExternalModuleName(context.getEmitHost(), sourceFile)), - factory.createModuleBlock(setTextRange(factory.createNodeArray(transformAndReplaceLatePaintedStatements(statements)), sourceFile.statements)) - )], /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false, /*libReferences*/ []); + const statements = isSourceFileJS(sourceFile) + ? factory.createNodeArray( + transformDeclarationsForJS( + sourceFile, + /*bundled*/ true + ) + ) + : visitNodes( + sourceFile.statements, + visitDeclarationStatements + ); + const newFile = factory.updateSourceFile( + sourceFile, + [ + factory.createModuleDeclaration( + [], + [ + factory.createModifier( + SyntaxKind.DeclareKeyword + ), + ], + factory.createStringLiteral( + getResolvedExternalModuleName( + context.getEmitHost(), + sourceFile + ) + ), + factory.createModuleBlock( + setTextRange( + factory.createNodeArray( + transformAndReplaceLatePaintedStatements( + statements + ) + ), + sourceFile.statements + ) + ) + ), + ], + /*isDeclarationFile*/ true, + /*referencedFiles*/ [], + /*typeReferences*/ [], + /*hasNoDefaultLib*/ false, + /*libReferences*/ [] + ); return newFile; } needsDeclare = true; - const updated = isSourceFileJS(sourceFile) ? factory.createNodeArray(transformDeclarationsForJS(sourceFile)) : visitNodes(sourceFile.statements, visitDeclarationStatements); - return factory.updateSourceFile(sourceFile, transformAndReplaceLatePaintedStatements(updated), /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false, /*libReferences*/ []); - } - ), mapDefined(node.prepends, prepend => { - if (prepend.kind === SyntaxKind.InputFiles) { - const sourceFile = createUnparsedSourceFile(prepend, "dts", stripInternal); - hasNoDefaultLib = hasNoDefaultLib || !!sourceFile.hasNoDefaultLib; - collectReferences(sourceFile, refs); - recordTypeReferenceDirectivesIfNecessary(map(sourceFile.typeReferenceDirectives, ref => [ref.fileName, ref.resolutionMode])); - collectLibs(sourceFile, libs); - return sourceFile; - } - return prepend; - })); + const updated = isSourceFileJS(sourceFile) + ? factory.createNodeArray( + transformDeclarationsForJS(sourceFile) + ) + : visitNodes( + sourceFile.statements, + visitDeclarationStatements + ); + return factory.updateSourceFile( + sourceFile, + transformAndReplaceLatePaintedStatements(updated), + /*isDeclarationFile*/ true, + /*referencedFiles*/ [], + /*typeReferences*/ [], + /*hasNoDefaultLib*/ false, + /*libReferences*/ [] + ); + }), + mapDefined(node.prepends, (prepend) => { + if (prepend.kind === SyntaxKind.InputFiles) { + const sourceFile = createUnparsedSourceFile( + prepend, + "dts", + stripInternal + ); + hasNoDefaultLib = + hasNoDefaultLib || !!sourceFile.hasNoDefaultLib; + collectReferences(sourceFile, refs); + recordTypeReferenceDirectivesIfNecessary( + map( + sourceFile.typeReferenceDirectives, + (ref) => [ref.fileName, ref.resolutionMode] + ) + ); + collectLibs(sourceFile, libs); + return sourceFile; + } + return prepend; + }) + ); bundle.syntheticFileReferences = []; - bundle.syntheticTypeReferences = getFileReferencesForUsedTypeReferences(); + bundle.syntheticTypeReferences = + getFileReferencesForUsedTypeReferences(); bundle.syntheticLibReferences = getLibReferences(); bundle.hasNoDefaultLib = hasNoDefaultLib; - const outputFilePath = getDirectoryPath(normalizeSlashes(getOutputPathsFor(node, host, /*forceDtsPaths*/ true).declarationFilePath!)); - const referenceVisitor = mapReferencesIntoArray(bundle.syntheticFileReferences as FileReference[], outputFilePath); + const outputFilePath = getDirectoryPath( + normalizeSlashes( + getOutputPathsFor(node, host, /*forceDtsPaths*/ true) + .declarationFilePath! + ) + ); + const referenceVisitor = mapReferencesIntoArray( + bundle.syntheticFileReferences as FileReference[], + outputFilePath + ); refs.forEach(referenceVisitor); return bundle; } @@ -335,78 +596,167 @@ namespace ts { refs = collectReferences(currentSourceFile, new Map()); libs = collectLibs(currentSourceFile, new Map()); const references: FileReference[] = []; - const outputFilePath = getDirectoryPath(normalizeSlashes(getOutputPathsFor(node, host, /*forceDtsPaths*/ true).declarationFilePath!)); - const referenceVisitor = mapReferencesIntoArray(references, outputFilePath); + const outputFilePath = getDirectoryPath( + normalizeSlashes( + getOutputPathsFor(node, host, /*forceDtsPaths*/ true) + .declarationFilePath! + ) + ); + const referenceVisitor = mapReferencesIntoArray( + references, + outputFilePath + ); let combinedStatements: NodeArray; if (isSourceFileJS(currentSourceFile)) { - combinedStatements = factory.createNodeArray(transformDeclarationsForJS(node)); + combinedStatements = factory.createNodeArray( + transformDeclarationsForJS(node) + ); refs.forEach(referenceVisitor); emittedImports = filter(combinedStatements, isAnyImportSyntax); - } - else { - const statements = visitNodes(node.statements, visitDeclarationStatements); - combinedStatements = setTextRange(factory.createNodeArray(transformAndReplaceLatePaintedStatements(statements)), node.statements); + } else { + const statements = visitNodes( + node.statements, + visitDeclarationStatements + ); + combinedStatements = setTextRange( + factory.createNodeArray( + transformAndReplaceLatePaintedStatements(statements) + ), + node.statements + ); refs.forEach(referenceVisitor); emittedImports = filter(combinedStatements, isAnyImportSyntax); - if (isExternalModule(node) && (!resultHasExternalModuleIndicator || (needsScopeFixMarker && !resultHasScopeMarker))) { - combinedStatements = setTextRange(factory.createNodeArray([...combinedStatements, createEmptyExports(factory)]), combinedStatements); + if ( + isExternalModule(node) && + (!resultHasExternalModuleIndicator || + (needsScopeFixMarker && !resultHasScopeMarker)) + ) { + combinedStatements = setTextRange( + factory.createNodeArray([ + ...combinedStatements, + createEmptyExports(factory), + ]), + combinedStatements + ); } } - const updated = factory.updateSourceFile(node, combinedStatements, /*isDeclarationFile*/ true, references, getFileReferencesForUsedTypeReferences(), node.hasNoDefaultLib, getLibReferences()); - updated.exportedModulesFromDeclarationEmit = exportedModulesFromDeclarationEmit; + const updated = factory.updateSourceFile( + node, + combinedStatements, + /*isDeclarationFile*/ true, + references, + getFileReferencesForUsedTypeReferences(), + node.hasNoDefaultLib, + getLibReferences() + ); + updated.exportedModulesFromDeclarationEmit = + exportedModulesFromDeclarationEmit; return updated; function getLibReferences() { - return map(arrayFrom(libs.keys()), lib => ({ fileName: lib, pos: -1, end: -1 })); + return map(arrayFrom(libs.keys()), (lib) => ({ + fileName: lib, + pos: -1, + end: -1, + })); } function getFileReferencesForUsedTypeReferences() { - return necessaryTypeReferences ? mapDefined(arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForSpecifierModeTuple) : []; - } - - function getFileReferenceForSpecifierModeTuple([typeName, mode]: [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined]): FileReference | undefined { + return necessaryTypeReferences + ? mapDefined( + arrayFrom(necessaryTypeReferences.keys()), + getFileReferenceForSpecifierModeTuple + ) + : []; + } + + function getFileReferenceForSpecifierModeTuple([typeName, mode]: [ + specifier: string, + mode: SourceFile["impliedNodeFormat"] | undefined + ]): FileReference | undefined { // Elide type references for which we have imports if (emittedImports) { for (const importStatement of emittedImports) { - if (isImportEqualsDeclaration(importStatement) && isExternalModuleReference(importStatement.moduleReference)) { - const expr = importStatement.moduleReference.expression; - if (isStringLiteralLike(expr) && expr.text === typeName) { + if ( + isImportEqualsDeclaration(importStatement) && + isExternalModuleReference( + importStatement.moduleReference + ) + ) { + const expr = + importStatement.moduleReference.expression; + if ( + isStringLiteralLike(expr) && + expr.text === typeName + ) { return undefined; } - } - else if (isImportDeclaration(importStatement) && isStringLiteral(importStatement.moduleSpecifier) && importStatement.moduleSpecifier.text === typeName) { + } else if ( + isImportDeclaration(importStatement) && + isStringLiteral(importStatement.moduleSpecifier) && + importStatement.moduleSpecifier.text === typeName + ) { return undefined; } } } - return { fileName: typeName, pos: -1, end: -1, ...(mode ? { resolutionMode: mode } : undefined) }; + return { + fileName: typeName, + pos: -1, + end: -1, + ...(mode ? { resolutionMode: mode } : undefined), + }; } - function mapReferencesIntoArray(references: FileReference[], outputFilePath: string): (file: SourceFile) => void { - return file => { + function mapReferencesIntoArray( + references: FileReference[], + outputFilePath: string + ): (file: SourceFile) => void { + return (file) => { let declFileName: string; - if (file.isDeclarationFile) { // Neither decl files or js should have their refs changed + if (file.isDeclarationFile) { + // Neither decl files or js should have their refs changed declFileName = file.fileName; - } - else { - if (isBundledEmit && contains((node as Bundle).sourceFiles, file)) return; // Omit references to files which are being merged - const paths = getOutputPathsFor(file, host, /*forceDtsPaths*/ true); - declFileName = paths.declarationFilePath || paths.jsFilePath || file.fileName; + } else { + if ( + isBundledEmit && + contains((node as Bundle).sourceFiles, file) + ) + return; // Omit references to files which are being merged + const paths = getOutputPathsFor( + file, + host, + /*forceDtsPaths*/ true + ); + declFileName = + paths.declarationFilePath || + paths.jsFilePath || + file.fileName; } if (declFileName) { const specifier = moduleSpecifiers.getModuleSpecifier( options, currentSourceFile, - toPath(outputFilePath, host.getCurrentDirectory(), host.getCanonicalFileName), - toPath(declFileName, host.getCurrentDirectory(), host.getCanonicalFileName), - host, + toPath( + outputFilePath, + host.getCurrentDirectory(), + host.getCanonicalFileName + ), + toPath( + declFileName, + host.getCurrentDirectory(), + host.getCanonicalFileName + ), + host ); if (!pathIsRelative(specifier)) { // If some compiler option/symlink/whatever allows access to the file containing the ambient module declaration // via a non-relative name, emit a type reference directive to that non-relative name, rather than // a relative path to the declaration file - recordTypeReferenceDirectivesIfNecessary([[specifier, /*mode*/ undefined]]); + recordTypeReferenceDirectivesIfNecessary([ + [specifier, /*mode*/ undefined], + ]); return; } @@ -417,13 +767,19 @@ namespace ts { host.getCanonicalFileName, /*isAbsolutePathAnUrl*/ false ); - if (startsWith(fileName, "./") && hasExtension(fileName)) { + if ( + startsWith(fileName, "./") && + hasExtension(fileName) + ) { fileName = fileName.substring(2); } // omit references to files from node_modules (npm may disambiguate module // references when installing this package, making the path is unreliable). - if (startsWith(fileName, "node_modules/") || pathContainsNodeModules(fileName)) { + if ( + startsWith(fileName, "node_modules/") || + pathContainsNodeModules(fileName) + ) { return; } @@ -433,9 +789,16 @@ namespace ts { } } - function collectReferences(sourceFile: SourceFile | UnparsedSource, ret: ESMap) { - if (noResolve || (!isUnparsedSource(sourceFile) && isSourceFileJS(sourceFile))) return ret; - forEach(sourceFile.referencedFiles, f => { + function collectReferences( + sourceFile: SourceFile | UnparsedSource, + ret: ESMap + ) { + if ( + noResolve || + (!isUnparsedSource(sourceFile) && isSourceFileJS(sourceFile)) + ) + return ret; + forEach(sourceFile.referencedFiles, (f) => { const elem = host.getSourceFileFromReference(sourceFile, f); if (elem) { ret.set(getOriginalNodeId(elem), elem); @@ -444,8 +807,11 @@ namespace ts { return ret; } - function collectLibs(sourceFile: SourceFile | UnparsedSource, ret: ESMap) { - forEach(sourceFile.libReferenceDirectives, ref => { + function collectLibs( + sourceFile: SourceFile | UnparsedSource, + ret: ESMap + ) { + forEach(sourceFile.libReferenceDirectives, (ref) => { const lib = host.getLibFileFromReference(ref); if (lib) { ret.set(toFileNameLowerCase(ref.fileName), true); @@ -454,32 +820,49 @@ namespace ts { return ret; } - function filterBindingPatternInitializersAndRenamings(name: BindingName) { + function filterBindingPatternInitializersAndRenamings( + name: BindingName + ) { if (name.kind === SyntaxKind.Identifier) { return name; - } - else { + } else { if (name.kind === SyntaxKind.ArrayBindingPattern) { - return factory.updateArrayBindingPattern(name, visitNodes(name.elements, visitBindingElement)); - } - else { - return factory.updateObjectBindingPattern(name, visitNodes(name.elements, visitBindingElement)); + return factory.updateArrayBindingPattern( + name, + visitNodes(name.elements, visitBindingElement) + ); + } else { + return factory.updateObjectBindingPattern( + name, + visitNodes(name.elements, visitBindingElement) + ); } } - function visitBindingElement(elem: T): T; - function visitBindingElement(elem: ArrayBindingElement): ArrayBindingElement { + function visitBindingElement( + elem: T + ): T; + function visitBindingElement( + elem: ArrayBindingElement + ): ArrayBindingElement { if (elem.kind === SyntaxKind.OmittedExpression) { return elem; } - if (elem.propertyName && isIdentifier(elem.propertyName) && isIdentifier(elem.name)) { - // Property renaming is forbidden in types, so remove renaming + if ( + elem.propertyName && + isIdentifier(elem.propertyName) && + isIdentifier(elem.name) && + !elem.symbol.isReferenced + ) { + // Unnecessary property renaming is forbidden in types, so remove renaming return factory.updateBindingElement( elem, elem.dotDotDotToken, /* propertyName */ undefined, elem.propertyName, - shouldPrintWithInitializer(elem) ? elem.initializer : undefined + shouldPrintWithInitializer(elem) + ? elem.initializer + : undefined ); } return factory.updateBindingElement( @@ -487,16 +870,23 @@ namespace ts { elem.dotDotDotToken, elem.propertyName, filterBindingPatternInitializersAndRenamings(elem.name), - shouldPrintWithInitializer(elem) ? elem.initializer : undefined + shouldPrintWithInitializer(elem) + ? elem.initializer + : undefined ); } } - function ensureParameter(p: ParameterDeclaration, modifierMask?: ModifierFlags, type?: TypeNode): ParameterDeclaration { + function ensureParameter( + p: ParameterDeclaration, + modifierMask?: ModifierFlags, + type?: TypeNode + ): ParameterDeclaration { let oldDiag: typeof getSymbolAccessibilityDiagnostic | undefined; if (!suppressNewDiagnosticContexts) { oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(p); + getSymbolAccessibilityDiagnostic = + createGetSymbolAccessibilityDiagnosticForNode(p); } const newParam = factory.updateParameterDeclaration( p, @@ -504,7 +894,10 @@ namespace ts { maskModifiers(p, modifierMask), p.dotDotDotToken, filterBindingPatternInitializersAndRenamings(p.name), - resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(SyntaxKind.QuestionToken)) : undefined, + resolver.isOptionalParameter(p) + ? p.questionToken || + factory.createToken(SyntaxKind.QuestionToken) + : undefined, ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param ensureNoInitializer(p) ); @@ -515,12 +908,20 @@ namespace ts { } function shouldPrintWithInitializer(node: Node) { - return canHaveLiteralInitializer(node) && resolver.isLiteralConstDeclaration(getParseTreeNode(node) as CanHaveLiteralInitializer); // TODO: Make safe + return ( + canHaveLiteralInitializer(node) && + resolver.isLiteralConstDeclaration( + getParseTreeNode(node) as CanHaveLiteralInitializer + ) + ); // TODO: Make safe } function ensureNoInitializer(node: CanHaveLiteralInitializer) { if (shouldPrintWithInitializer(node)) { - return resolver.createLiteralConstValue(getParseTreeNode(node) as CanHaveLiteralInitializer, symbolTracker); // TODO: Make safe + return resolver.createLiteralConstValue( + getParseTreeNode(node) as CanHaveLiteralInitializer, + symbolTracker + ); // TODO: Make safe } return undefined; } @@ -539,8 +940,15 @@ namespace ts { | PropertyDeclaration | PropertySignature; - function ensureType(node: HasInferredType, type: TypeNode | undefined, ignorePrivate?: boolean): TypeNode | undefined { - if (!ignorePrivate && hasEffectiveModifier(node, ModifierFlags.Private)) { + function ensureType( + node: HasInferredType, + type: TypeNode | undefined, + ignorePrivate?: boolean + ): TypeNode | undefined { + if ( + !ignorePrivate && + hasEffectiveModifier(node, ModifierFlags.Private) + ) { // Private nodes emit no types (except private parameter properties, whose parameter types are actually visible) return; } @@ -548,14 +956,17 @@ namespace ts { // Literal const declarations will have an initializer ensured rather than a type return; } - const shouldUseResolverType = node.kind === SyntaxKind.Parameter && + const shouldUseResolverType = + node.kind === SyntaxKind.Parameter && (resolver.isRequiredInitializedParameter(node) || - resolver.isOptionalUninitializedParameterProperty(node)); + resolver.isOptionalUninitializedParameterProperty(node)); if (type && !shouldUseResolverType) { return visitNode(type, visitDeclarationSubtree); } if (!getParseTreeNode(node)) { - return type ? visitNode(type, visitDeclarationSubtree) : factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); + return type + ? visitNode(type, visitDeclarationSubtree) + : factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); } if (node.kind === SyntaxKind.SetAccessor) { // Set accessors with no associated type node (from it's param or get accessor return) are `any` since they are never contextually typed right now @@ -566,25 +977,71 @@ namespace ts { let oldDiag: typeof getSymbolAccessibilityDiagnostic; if (!suppressNewDiagnosticContexts) { oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(node); - } - if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) { - return cleanup(resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker)); + getSymbolAccessibilityDiagnostic = + createGetSymbolAccessibilityDiagnosticForNode(node); + } + if ( + node.kind === SyntaxKind.VariableDeclaration || + node.kind === SyntaxKind.BindingElement + ) { + return cleanup( + resolver.createTypeOfDeclaration( + node, + enclosingDeclaration, + declarationEmitNodeBuilderFlags, + symbolTracker + ) + ); } - if (node.kind === SyntaxKind.Parameter - || node.kind === SyntaxKind.PropertyDeclaration - || node.kind === SyntaxKind.PropertySignature) { - if (!node.initializer) return cleanup(resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker, shouldUseResolverType)); - return cleanup(resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker, shouldUseResolverType) || resolver.createTypeOfExpression(node.initializer, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker)); + if ( + node.kind === SyntaxKind.Parameter || + node.kind === SyntaxKind.PropertyDeclaration || + node.kind === SyntaxKind.PropertySignature + ) { + if (!node.initializer) + return cleanup( + resolver.createTypeOfDeclaration( + node, + enclosingDeclaration, + declarationEmitNodeBuilderFlags, + symbolTracker, + shouldUseResolverType + ) + ); + return cleanup( + resolver.createTypeOfDeclaration( + node, + enclosingDeclaration, + declarationEmitNodeBuilderFlags, + symbolTracker, + shouldUseResolverType + ) || + resolver.createTypeOfExpression( + node.initializer, + enclosingDeclaration, + declarationEmitNodeBuilderFlags, + symbolTracker + ) + ); } - return cleanup(resolver.createReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker)); + return cleanup( + resolver.createReturnTypeOfSignatureDeclaration( + node, + enclosingDeclaration, + declarationEmitNodeBuilderFlags, + symbolTracker + ) + ); function cleanup(returnValue: TypeNode | undefined) { errorNameNode = undefined; if (!suppressNewDiagnosticContexts) { getSymbolAccessibilityDiagnostic = oldDiag; } - return returnValue || factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); + return ( + returnValue || + factory.createKeywordTypeNode(SyntaxKind.AnyKeyword) + ); } } @@ -618,35 +1075,51 @@ namespace ts { return true; } - const overloadSignatures = input.symbol.declarations?.filter(decl => isFunctionDeclaration(decl) && !decl.body); - return !overloadSignatures || overloadSignatures.indexOf(input) === overloadSignatures.length - 1; + const overloadSignatures = input.symbol.declarations?.filter( + (decl) => isFunctionDeclaration(decl) && !decl.body + ); + return ( + !overloadSignatures || + overloadSignatures.indexOf(input) === + overloadSignatures.length - 1 + ); } - function getBindingNameVisible(elem: BindingElement | VariableDeclaration | OmittedExpression): boolean { + function getBindingNameVisible( + elem: BindingElement | VariableDeclaration | OmittedExpression + ): boolean { if (isOmittedExpression(elem)) { return false; } if (isBindingPattern(elem.name)) { // If any child binding pattern element has been marked visible (usually by collect linked aliases), then this is visible return some(elem.name.elements, getBindingNameVisible); - } - else { + } else { return resolver.isDeclarationVisible(elem); } } - function updateParamsList(node: Node, params: NodeArray, modifierMask?: ModifierFlags) { + function updateParamsList( + node: Node, + params: NodeArray, + modifierMask?: ModifierFlags + ) { if (hasEffectiveModifier(node, ModifierFlags.Private)) { return undefined!; // TODO: GH#18217 } - const newParams = map(params, p => ensureParameter(p, modifierMask)); + const newParams = map(params, (p) => + ensureParameter(p, modifierMask) + ); if (!newParams) { return undefined!; // TODO: GH#18217 } return factory.createNodeArray(newParams, params.hasTrailingComma); } - function updateAccessorParamsList(input: AccessorDeclaration, isPrivate: boolean) { + function updateAccessorParamsList( + input: AccessorDeclaration, + isPrivate: boolean + ) { let newParams: ParameterDeclaration[] | undefined; if (!isPrivate) { const thisParameter = getThisParameter(input); @@ -659,8 +1132,16 @@ namespace ts { if (!isPrivate) { const valueParameter = getSetAccessorValueParameter(input); if (valueParameter) { - const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input, resolver.getAllAccessorDeclarations(input)); - newValueParameter = ensureParameter(valueParameter, /*modifierMask*/ undefined, accessorType); + const accessorType = + getTypeAnnotationFromAllAccessorDeclarations( + input, + resolver.getAllAccessorDeclarations(input) + ); + newValueParameter = ensureParameter( + valueParameter, + /*modifierMask*/ undefined, + accessorType + ); } } if (!newValueParameter) { @@ -676,25 +1157,40 @@ namespace ts { return factory.createNodeArray(newParams || emptyArray); } - function ensureTypeParams(node: Node, params: NodeArray | undefined) { - return hasEffectiveModifier(node, ModifierFlags.Private) ? undefined : visitNodes(params, visitDeclarationSubtree); + function ensureTypeParams( + node: Node, + params: NodeArray | undefined + ) { + return hasEffectiveModifier(node, ModifierFlags.Private) + ? undefined + : visitNodes(params, visitDeclarationSubtree); } function isEnclosingDeclaration(node: Node) { - return isSourceFile(node) - || isTypeAliasDeclaration(node) - || isModuleDeclaration(node) - || isClassDeclaration(node) - || isInterfaceDeclaration(node) - || isFunctionLike(node) - || isIndexSignatureDeclaration(node) - || isMappedTypeNode(node); + return ( + isSourceFile(node) || + isTypeAliasDeclaration(node) || + isModuleDeclaration(node) || + isClassDeclaration(node) || + isInterfaceDeclaration(node) || + isFunctionLike(node) || + isIndexSignatureDeclaration(node) || + isMappedTypeNode(node) + ); } - function checkEntityNameVisibility(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node) { - const visibilityResult = resolver.isEntityNameVisible(entityName, enclosingDeclaration); + function checkEntityNameVisibility( + entityName: EntityNameOrEntityNameExpression, + enclosingDeclaration: Node + ) { + const visibilityResult = resolver.isEntityNameVisible( + entityName, + enclosingDeclaration + ); handleSymbolAccessibilityError(visibilityResult); - recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForEntityName(entityName)); + recordTypeReferenceDirectivesIfNecessary( + resolver.getTypeReferenceDirectivesForEntityName(entityName) + ); } function preserveJsDoc(updated: T, original: Node): T { @@ -704,44 +1200,73 @@ namespace ts { return setCommentRange(updated, getCommentRange(original)); } - function rewriteModuleSpecifier(parent: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode, input: T | undefined): T | StringLiteral { + function rewriteModuleSpecifier( + parent: + | ImportEqualsDeclaration + | ImportDeclaration + | ExportDeclaration + | ModuleDeclaration + | ImportTypeNode, + input: T | undefined + ): T | StringLiteral { if (!input) return undefined!; // TODO: GH#18217 - resultHasExternalModuleIndicator = resultHasExternalModuleIndicator || (parent.kind !== SyntaxKind.ModuleDeclaration && parent.kind !== SyntaxKind.ImportType); + resultHasExternalModuleIndicator = + resultHasExternalModuleIndicator || + (parent.kind !== SyntaxKind.ModuleDeclaration && + parent.kind !== SyntaxKind.ImportType); if (isStringLiteralLike(input)) { if (isBundledEmit) { - const newName = getExternalModuleNameFromDeclaration(context.getEmitHost(), resolver, parent); + const newName = getExternalModuleNameFromDeclaration( + context.getEmitHost(), + resolver, + parent + ); if (newName) { return factory.createStringLiteral(newName); } - } - else { - const symbol = resolver.getSymbolOfExternalModuleSpecifier(input); + } else { + const symbol = + resolver.getSymbolOfExternalModuleSpecifier(input); if (symbol) { - (exportedModulesFromDeclarationEmit || (exportedModulesFromDeclarationEmit = [])).push(symbol); + ( + exportedModulesFromDeclarationEmit || + (exportedModulesFromDeclarationEmit = []) + ).push(symbol); } } } return input; } - function transformImportEqualsDeclaration(decl: ImportEqualsDeclaration) { + function transformImportEqualsDeclaration( + decl: ImportEqualsDeclaration + ) { if (!resolver.isDeclarationVisible(decl)) return; - if (decl.moduleReference.kind === SyntaxKind.ExternalModuleReference) { + if ( + decl.moduleReference.kind === SyntaxKind.ExternalModuleReference + ) { // Rewrite external module names if necessary - const specifier = getExternalModuleImportEqualsDeclarationExpression(decl); + const specifier = + getExternalModuleImportEqualsDeclarationExpression(decl); return factory.updateImportEqualsDeclaration( decl, /*decorators*/ undefined, decl.modifiers, decl.isTypeOnly, decl.name, - factory.updateExternalModuleReference(decl.moduleReference, rewriteModuleSpecifier(decl, specifier)) + factory.updateExternalModuleReference( + decl.moduleReference, + rewriteModuleSpecifier(decl, specifier) + ) ); - } - else { + } else { const oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(decl); - checkEntityNameVisibility(decl.moduleReference, enclosingDeclaration); + getSymbolAccessibilityDiagnostic = + createGetSymbolAccessibilityDiagnosticForNode(decl); + checkEntityNameVisibility( + decl.moduleReference, + enclosingDeclaration + ); getSymbolAccessibilityDiagnostic = oldDiag; return decl; } @@ -756,32 +1281,72 @@ namespace ts { decl.modifiers, decl.importClause, rewriteModuleSpecifier(decl, decl.moduleSpecifier), - getResolutionModeOverrideForClauseInNightly(decl.assertClause) + getResolutionModeOverrideForClauseInNightly( + decl.assertClause + ) ); } // The `importClause` visibility corresponds to the default's visibility. - const visibleDefaultBinding = decl.importClause && decl.importClause.name && resolver.isDeclarationVisible(decl.importClause) ? decl.importClause.name : undefined; + const visibleDefaultBinding = + decl.importClause && + decl.importClause.name && + resolver.isDeclarationVisible(decl.importClause) + ? decl.importClause.name + : undefined; if (!decl.importClause.namedBindings) { // No named bindings (either namespace or list), meaning the import is just default or should be elided - return visibleDefaultBinding && factory.updateImportDeclaration(decl, /*decorators*/ undefined, decl.modifiers, factory.updateImportClause( - decl.importClause, - decl.importClause.isTypeOnly, - visibleDefaultBinding, - /*namedBindings*/ undefined, - ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), getResolutionModeOverrideForClauseInNightly(decl.assertClause)); + return ( + visibleDefaultBinding && + factory.updateImportDeclaration( + decl, + /*decorators*/ undefined, + decl.modifiers, + factory.updateImportClause( + decl.importClause, + decl.importClause.isTypeOnly, + visibleDefaultBinding, + /*namedBindings*/ undefined + ), + rewriteModuleSpecifier(decl, decl.moduleSpecifier), + getResolutionModeOverrideForClauseInNightly( + decl.assertClause + ) + ) + ); } - if (decl.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + if ( + decl.importClause.namedBindings.kind === + SyntaxKind.NamespaceImport + ) { // Namespace import (optionally with visible default) - const namedBindings = resolver.isDeclarationVisible(decl.importClause.namedBindings) ? decl.importClause.namedBindings : /*namedBindings*/ undefined; - return visibleDefaultBinding || namedBindings ? factory.updateImportDeclaration(decl, /*decorators*/ undefined, decl.modifiers, factory.updateImportClause( - decl.importClause, - decl.importClause.isTypeOnly, - visibleDefaultBinding, - namedBindings, - ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), getResolutionModeOverrideForClauseInNightly(decl.assertClause)) : undefined; + const namedBindings = resolver.isDeclarationVisible( + decl.importClause.namedBindings + ) + ? decl.importClause.namedBindings + : /*namedBindings*/ undefined; + return visibleDefaultBinding || namedBindings + ? factory.updateImportDeclaration( + decl, + /*decorators*/ undefined, + decl.modifiers, + factory.updateImportClause( + decl.importClause, + decl.importClause.isTypeOnly, + visibleDefaultBinding, + namedBindings + ), + rewriteModuleSpecifier(decl, decl.moduleSpecifier), + getResolutionModeOverrideForClauseInNightly( + decl.assertClause + ) + ) + : undefined; } // Named imports (optionally with visible default) - const bindingList = mapDefined(decl.importClause.namedBindings.elements, b => resolver.isDeclarationVisible(b) ? b : undefined); + const bindingList = mapDefined( + decl.importClause.namedBindings.elements, + (b) => (resolver.isDeclarationVisible(b) ? b : undefined) + ); if ((bindingList && bindingList.length) || visibleDefaultBinding) { return factory.updateImportDeclaration( decl, @@ -791,10 +1356,17 @@ namespace ts { decl.importClause, decl.importClause.isTypeOnly, visibleDefaultBinding, - bindingList && bindingList.length ? factory.updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined, + bindingList && bindingList.length + ? factory.updateNamedImports( + decl.importClause.namedBindings, + bindingList + ) + : undefined ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), - getResolutionModeOverrideForClauseInNightly(decl.assertClause) + getResolutionModeOverrideForClauseInNightly( + decl.assertClause + ) ); } // Augmentation of export depends on import @@ -805,24 +1377,35 @@ namespace ts { decl.modifiers, /*importClause*/ undefined, rewriteModuleSpecifier(decl, decl.moduleSpecifier), - getResolutionModeOverrideForClauseInNightly(decl.assertClause) + getResolutionModeOverrideForClauseInNightly( + decl.assertClause + ) ); } // Nothing visible } - function getResolutionModeOverrideForClauseInNightly(assertClause: AssertClause | undefined) { + function getResolutionModeOverrideForClauseInNightly( + assertClause: AssertClause | undefined + ) { const mode = getResolutionModeOverrideForClause(assertClause); if (mode !== undefined) { if (!isNightly()) { - context.addDiagnostic(createDiagnosticForNode(assertClause!, Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); + context.addDiagnostic( + createDiagnosticForNode( + assertClause!, + Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next + ) + ); } return assertClause; } return undefined; } - function transformAndReplaceLatePaintedStatements(statements: NodeArray): NodeArray { + function transformAndReplaceLatePaintedStatements( + statements: NodeArray + ): NodeArray { // This is a `while` loop because `handleSymbolAccessibilityError` can see additional import aliases marked as visible during // error handling which must now be included in the output and themselves checked for errors. // For example: @@ -840,10 +1423,19 @@ namespace ts { while (length(lateMarkedStatements)) { const i = lateMarkedStatements!.shift()!; if (!isLateVisibilityPaintedStatement(i)) { - return Debug.fail(`Late replaced statement was found which is not handled by the declaration transformer!: ${(ts as any).SyntaxKind ? (ts as any).SyntaxKind[(i as any).kind] : (i as any).kind}`); + return Debug.fail( + `Late replaced statement was found which is not handled by the declaration transformer!: ${ + (ts as any).SyntaxKind + ? (ts as any).SyntaxKind[(i as any).kind] + : (i as any).kind + }` + ); } const priorNeedsDeclare = needsDeclare; - needsDeclare = i.parent && isSourceFile(i.parent) && !(isExternalModule(i.parent) && isBundledEmit); + needsDeclare = + i.parent && + isSourceFile(i.parent) && + !(isExternalModule(i.parent) && isBundledEmit); const result = transformTopLevelDeclaration(i); needsDeclare = priorNeedsDeclare; lateStatementReplacementMap.set(getOriginalNodeId(i), result); @@ -860,11 +1452,20 @@ namespace ts { const result = lateStatementReplacementMap.get(key); lateStatementReplacementMap.delete(key); if (result) { - if (isArray(result) ? some(result, needsScopeMarker) : needsScopeMarker(result)) { + if ( + isArray(result) + ? some(result, needsScopeMarker) + : needsScopeMarker(result) + ) { // Top-level declarations in .d.ts files are always considered exported even without a modifier unless there's an export assignment or specifier needsScopeFixMarker = true; } - if (isSourceFile(statement.parent) && (isArray(result) ? some(result, isExternalModuleIndicator) : isExternalModuleIndicator(result))) { + if ( + isSourceFile(statement.parent) && + (isArray(result) + ? some(result, isExternalModuleIndicator) + : isExternalModuleIndicator(result)) + ) { resultHasExternalModuleIndicator = true; } } @@ -879,13 +1480,22 @@ namespace ts { if (shouldStripInternal(input)) return; if (isDeclaration(input)) { if (isDeclarationAndNotVisible(input)) return; - if (hasDynamicName(input) && !resolver.isLateBound(getParseTreeNode(input) as Declaration)) { + if ( + hasDynamicName(input) && + !resolver.isLateBound( + getParseTreeNode(input) as Declaration + ) + ) { return; } } // Elide implementation signatures from overload sets - if (isFunctionLike(input) && resolver.isImplementationOfOverload(input)) return; + if ( + isFunctionLike(input) && + resolver.isImplementationOfOverload(input) + ) + return; // Elide semicolon class statements if (isSemicolonClassElement(input)) return; @@ -901,18 +1511,36 @@ namespace ts { // We'd see a TDZ violation at runtime const canProduceDiagnostic = canProduceDiagnostics(input); const oldWithinObjectLiteralType = suppressNewDiagnosticContexts; - let shouldEnterSuppressNewDiagnosticsContextContext = ((input.kind === SyntaxKind.TypeLiteral || input.kind === SyntaxKind.MappedType) && input.parent.kind !== SyntaxKind.TypeAliasDeclaration); + let shouldEnterSuppressNewDiagnosticsContextContext = + (input.kind === SyntaxKind.TypeLiteral || + input.kind === SyntaxKind.MappedType) && + input.parent.kind !== SyntaxKind.TypeAliasDeclaration; // Emit methods which are private as properties with no type information if (isMethodDeclaration(input) || isMethodSignature(input)) { if (hasEffectiveModifier(input, ModifierFlags.Private)) { - if (input.symbol && input.symbol.declarations && input.symbol.declarations[0] !== input) return; // Elide all but the first overload - return cleanup(factory.createPropertyDeclaration(/*decorators*/ undefined, ensureModifiers(input), input.name, /*questionToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined)); + if ( + input.symbol && + input.symbol.declarations && + input.symbol.declarations[0] !== input + ) + return; // Elide all but the first overload + return cleanup( + factory.createPropertyDeclaration( + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + /*questionToken*/ undefined, + /*type*/ undefined, + /*initializer*/ undefined + ) + ); } } if (canProduceDiagnostic && !suppressNewDiagnosticContexts) { - getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(input); + getSymbolAccessibilityDiagnostic = + createGetSymbolAccessibilityDiagnosticForNode(input); } if (isTypeQueryNode(input)) { @@ -927,30 +1555,65 @@ namespace ts { if (isProcessedComponent(input)) { switch (input.kind) { case SyntaxKind.ExpressionWithTypeArguments: { - if ((isEntityName(input.expression) || isEntityNameExpression(input.expression))) { - checkEntityNameVisibility(input.expression, enclosingDeclaration); + if ( + isEntityName(input.expression) || + isEntityNameExpression(input.expression) + ) { + checkEntityNameVisibility( + input.expression, + enclosingDeclaration + ); } - const node = visitEachChild(input, visitDeclarationSubtree, context); - return cleanup(factory.updateExpressionWithTypeArguments(node, node.expression, node.typeArguments)); + const node = visitEachChild( + input, + visitDeclarationSubtree, + context + ); + return cleanup( + factory.updateExpressionWithTypeArguments( + node, + node.expression, + node.typeArguments + ) + ); } case SyntaxKind.TypeReference: { - checkEntityNameVisibility(input.typeName, enclosingDeclaration); - const node = visitEachChild(input, visitDeclarationSubtree, context); - return cleanup(factory.updateTypeReferenceNode(node, node.typeName, node.typeArguments)); + checkEntityNameVisibility( + input.typeName, + enclosingDeclaration + ); + const node = visitEachChild( + input, + visitDeclarationSubtree, + context + ); + return cleanup( + factory.updateTypeReferenceNode( + node, + node.typeName, + node.typeArguments + ) + ); } case SyntaxKind.ConstructSignature: - return cleanup(factory.updateConstructSignature( - input, - ensureTypeParams(input, input.typeParameters), - updateParamsList(input, input.parameters), - ensureType(input, input.type) - )); + return cleanup( + factory.updateConstructSignature( + input, + ensureTypeParams(input, input.typeParameters), + updateParamsList(input, input.parameters), + ensureType(input, input.type) + ) + ); case SyntaxKind.Constructor: { // A constructor declaration may not have a type annotation const ctor = factory.createConstructorDeclaration( /*decorators*/ undefined, /*modifiers*/ ensureModifiers(input), - updateParamsList(input, input.parameters, ModifierFlags.None), + updateParamsList( + input, + input.parameters, + ModifierFlags.None + ), /*body*/ undefined ); return cleanup(ctor); @@ -976,82 +1639,120 @@ namespace ts { if (isPrivateIdentifier(input.name)) { return cleanup(/*returnValue*/ undefined); } - const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input, resolver.getAllAccessorDeclarations(input)); - return cleanup(factory.updateGetAccessorDeclaration( - input, - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - updateAccessorParamsList(input, hasEffectiveModifier(input, ModifierFlags.Private)), - ensureType(input, accessorType), - /*body*/ undefined)); + const accessorType = + getTypeAnnotationFromAllAccessorDeclarations( + input, + resolver.getAllAccessorDeclarations(input) + ); + return cleanup( + factory.updateGetAccessorDeclaration( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + updateAccessorParamsList( + input, + hasEffectiveModifier( + input, + ModifierFlags.Private + ) + ), + ensureType(input, accessorType), + /*body*/ undefined + ) + ); } case SyntaxKind.SetAccessor: { if (isPrivateIdentifier(input.name)) { return cleanup(/*returnValue*/ undefined); } - return cleanup(factory.updateSetAccessorDeclaration( - input, - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - updateAccessorParamsList(input, hasEffectiveModifier(input, ModifierFlags.Private)), - /*body*/ undefined)); + return cleanup( + factory.updateSetAccessorDeclaration( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + updateAccessorParamsList( + input, + hasEffectiveModifier( + input, + ModifierFlags.Private + ) + ), + /*body*/ undefined + ) + ); } case SyntaxKind.PropertyDeclaration: if (isPrivateIdentifier(input.name)) { return cleanup(/*returnValue*/ undefined); } - return cleanup(factory.updatePropertyDeclaration( - input, - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - input.questionToken, - ensureType(input, input.type), - ensureNoInitializer(input) - )); + return cleanup( + factory.updatePropertyDeclaration( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + input.questionToken, + ensureType(input, input.type), + ensureNoInitializer(input) + ) + ); case SyntaxKind.PropertySignature: if (isPrivateIdentifier(input.name)) { return cleanup(/*returnValue*/ undefined); } - return cleanup(factory.updatePropertySignature( - input, - ensureModifiers(input), - input.name, - input.questionToken, - ensureType(input, input.type) - )); + return cleanup( + factory.updatePropertySignature( + input, + ensureModifiers(input), + input.name, + input.questionToken, + ensureType(input, input.type) + ) + ); case SyntaxKind.MethodSignature: { if (isPrivateIdentifier(input.name)) { return cleanup(/*returnValue*/ undefined); } - return cleanup(factory.updateMethodSignature( - input, - ensureModifiers(input), - input.name, - input.questionToken, - ensureTypeParams(input, input.typeParameters), - updateParamsList(input, input.parameters), - ensureType(input, input.type) - )); + return cleanup( + factory.updateMethodSignature( + input, + ensureModifiers(input), + input.name, + input.questionToken, + ensureTypeParams(input, input.typeParameters), + updateParamsList(input, input.parameters), + ensureType(input, input.type) + ) + ); } case SyntaxKind.CallSignature: { - return cleanup(factory.updateCallSignature( - input, - ensureTypeParams(input, input.typeParameters), - updateParamsList(input, input.parameters), - ensureType(input, input.type) - )); + return cleanup( + factory.updateCallSignature( + input, + ensureTypeParams(input, input.typeParameters), + updateParamsList(input, input.parameters), + ensureType(input, input.type) + ) + ); } case SyntaxKind.IndexSignature: { - return cleanup(factory.updateIndexSignature( - input, - /*decorators*/ undefined, - ensureModifiers(input), - updateParamsList(input, input.parameters), - visitNode(input.type, visitDeclarationSubtree) || factory.createKeywordTypeNode(SyntaxKind.AnyKeyword) - )); + return cleanup( + factory.updateIndexSignature( + input, + /*decorators*/ undefined, + ensureModifiers(input), + updateParamsList(input, input.parameters), + visitNode( + input.type, + visitDeclarationSubtree + ) || + factory.createKeywordTypeNode( + SyntaxKind.AnyKeyword + ) + ) + ); } case SyntaxKind.VariableDeclaration: { if (isBindingPattern(input.name)) { @@ -1059,55 +1760,154 @@ namespace ts { } shouldEnterSuppressNewDiagnosticsContextContext = true; suppressNewDiagnosticContexts = true; // Variable declaration types also suppress new diagnostic contexts, provided the contexts wouldn't be made for binding pattern types - return cleanup(factory.updateVariableDeclaration(input, input.name, /*exclamationToken*/ undefined, ensureType(input, input.type), ensureNoInitializer(input))); + return cleanup( + factory.updateVariableDeclaration( + input, + input.name, + /*exclamationToken*/ undefined, + ensureType(input, input.type), + ensureNoInitializer(input) + ) + ); } case SyntaxKind.TypeParameter: { - if (isPrivateMethodTypeParameter(input) && (input.default || input.constraint)) { - return cleanup(factory.updateTypeParameterDeclaration(input, input.modifiers, input.name, /*constraint*/ undefined, /*defaultType*/ undefined)); + if ( + isPrivateMethodTypeParameter(input) && + (input.default || input.constraint) + ) { + return cleanup( + factory.updateTypeParameterDeclaration( + input, + input.modifiers, + input.name, + /*constraint*/ undefined, + /*defaultType*/ undefined + ) + ); } - return cleanup(visitEachChild(input, visitDeclarationSubtree, context)); + return cleanup( + visitEachChild( + input, + visitDeclarationSubtree, + context + ) + ); } case SyntaxKind.ConditionalType: { // We have to process conditional types in a special way because for visibility purposes we need to push a new enclosingDeclaration // just for the `infer` types in the true branch. It's an implicit declaration scope that only applies to _part_ of the type. - const checkType = visitNode(input.checkType, visitDeclarationSubtree); - const extendsType = visitNode(input.extendsType, visitDeclarationSubtree); + const checkType = visitNode( + input.checkType, + visitDeclarationSubtree + ); + const extendsType = visitNode( + input.extendsType, + visitDeclarationSubtree + ); const oldEnclosingDecl = enclosingDeclaration; enclosingDeclaration = input.trueType; - const trueType = visitNode(input.trueType, visitDeclarationSubtree); + const trueType = visitNode( + input.trueType, + visitDeclarationSubtree + ); enclosingDeclaration = oldEnclosingDecl; - const falseType = visitNode(input.falseType, visitDeclarationSubtree); - return cleanup(factory.updateConditionalTypeNode(input, checkType, extendsType, trueType, falseType)); + const falseType = visitNode( + input.falseType, + visitDeclarationSubtree + ); + return cleanup( + factory.updateConditionalTypeNode( + input, + checkType, + extendsType, + trueType, + falseType + ) + ); } case SyntaxKind.FunctionType: { - return cleanup(factory.updateFunctionTypeNode(input, visitNodes(input.typeParameters, visitDeclarationSubtree), updateParamsList(input, input.parameters), visitNode(input.type, visitDeclarationSubtree))); + return cleanup( + factory.updateFunctionTypeNode( + input, + visitNodes( + input.typeParameters, + visitDeclarationSubtree + ), + updateParamsList(input, input.parameters), + visitNode(input.type, visitDeclarationSubtree) + ) + ); } case SyntaxKind.ConstructorType: { - return cleanup(factory.updateConstructorTypeNode(input, ensureModifiers(input), visitNodes(input.typeParameters, visitDeclarationSubtree), updateParamsList(input, input.parameters), visitNode(input.type, visitDeclarationSubtree))); + return cleanup( + factory.updateConstructorTypeNode( + input, + ensureModifiers(input), + visitNodes( + input.typeParameters, + visitDeclarationSubtree + ), + updateParamsList(input, input.parameters), + visitNode(input.type, visitDeclarationSubtree) + ) + ); } case SyntaxKind.ImportType: { - if (!isLiteralImportTypeNode(input)) return cleanup(input); - return cleanup(factory.updateImportTypeNode( - input, - factory.updateLiteralTypeNode(input.argument, rewriteModuleSpecifier(input, input.argument.literal)), - input.assertions, - input.qualifier, - visitNodes(input.typeArguments, visitDeclarationSubtree, isTypeNode), - input.isTypeOf - )); + if (!isLiteralImportTypeNode(input)) + return cleanup(input); + return cleanup( + factory.updateImportTypeNode( + input, + factory.updateLiteralTypeNode( + input.argument, + rewriteModuleSpecifier( + input, + input.argument.literal + ) + ), + input.assertions, + input.qualifier, + visitNodes( + input.typeArguments, + visitDeclarationSubtree, + isTypeNode + ), + input.isTypeOf + ) + ); } - default: Debug.assertNever(input, `Attempted to process unhandled node kind: ${(ts as any).SyntaxKind[(input as any).kind]}`); + default: + Debug.assertNever( + input, + `Attempted to process unhandled node kind: ${ + (ts as any).SyntaxKind[(input as any).kind] + }` + ); } } - if (isTupleTypeNode(input) && (getLineAndCharacterOfPosition(currentSourceFile, input.pos).line === getLineAndCharacterOfPosition(currentSourceFile, input.end).line)) { + if ( + isTupleTypeNode(input) && + getLineAndCharacterOfPosition(currentSourceFile, input.pos) + .line === + getLineAndCharacterOfPosition(currentSourceFile, input.end) + .line + ) { setEmitFlags(input, EmitFlags.SingleLine); } - return cleanup(visitEachChild(input, visitDeclarationSubtree, context)); + return cleanup( + visitEachChild(input, visitDeclarationSubtree, context) + ); - function cleanup(returnValue: T | undefined): T | undefined { - if (returnValue && canProduceDiagnostic && hasDynamicName(input as Declaration)) { + function cleanup( + returnValue: T | undefined + ): T | undefined { + if ( + returnValue && + canProduceDiagnostic && + hasDynamicName(input as Declaration) + ) { checkName(input); } if (isEnclosingDeclaration(input)) { @@ -1122,12 +1922,18 @@ namespace ts { if (returnValue === input) { return returnValue; } - return returnValue && setOriginalNode(preserveJsDoc(returnValue, input), input); + return ( + returnValue && + setOriginalNode(preserveJsDoc(returnValue, input), input) + ); } } function isPrivateMethodTypeParameter(node: TypeParameterDeclaration) { - return node.parent.kind === SyntaxKind.MethodDeclaration && hasEffectiveModifier(node.parent, ModifierFlags.Private); + return ( + node.parent.kind === SyntaxKind.MethodDeclaration && + hasEffectiveModifier(node.parent, ModifierFlags.Private) + ); } function visitDeclarationStatements(input: Node): VisitResult { @@ -1152,7 +1958,9 @@ namespace ts { input.isTypeOnly, input.exportClause, rewriteModuleSpecifier(input, input.moduleSpecifier), - getResolutionModeOverrideForClause(input.assertClause) ? input.assertClause : undefined + getResolutionModeOverrideForClause(input.assertClause) + ? input.assertClause + : undefined ); } case SyntaxKind.ExportAssignment: { @@ -1163,21 +1971,54 @@ namespace ts { resultHasScopeMarker = true; if (input.expression.kind === SyntaxKind.Identifier) { return input; - } - else { - const newId = factory.createUniqueName("_default", GeneratedIdentifierFlags.Optimistic); + } else { + const newId = factory.createUniqueName( + "_default", + GeneratedIdentifierFlags.Optimistic + ); getSymbolAccessibilityDiagnostic = () => ({ - diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, - errorNode: input + diagnosticMessage: + Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, + errorNode: input, }); errorFallbackNode = input; - const varDecl = factory.createVariableDeclaration(newId, /*exclamationToken*/ undefined, resolver.createTypeOfExpression(input.expression, input, declarationEmitNodeBuilderFlags, symbolTracker), /*initializer*/ undefined); + const varDecl = factory.createVariableDeclaration( + newId, + /*exclamationToken*/ undefined, + resolver.createTypeOfExpression( + input.expression, + input, + declarationEmitNodeBuilderFlags, + symbolTracker + ), + /*initializer*/ undefined + ); errorFallbackNode = undefined; - const statement = factory.createVariableStatement(needsDeclare ? [factory.createModifier(SyntaxKind.DeclareKeyword)] : [], factory.createVariableDeclarationList([varDecl], NodeFlags.Const)); + const statement = factory.createVariableStatement( + needsDeclare + ? [ + factory.createModifier( + SyntaxKind.DeclareKeyword + ), + ] + : [], + factory.createVariableDeclarationList( + [varDecl], + NodeFlags.Const + ) + ); preserveJsDoc(statement, input); removeAllComments(input); - return [statement, factory.updateExportAssignment(input, input.decorators, input.modifiers, newId)]; + return [ + statement, + factory.updateExportAssignment( + input, + input.decorators, + input.modifiers, + newId + ), + ]; } } } @@ -1189,17 +2030,26 @@ namespace ts { } function stripExportModifiers(statement: Statement): Statement { - if (isImportEqualsDeclaration(statement) || hasEffectiveModifier(statement, ModifierFlags.Default) || !canHaveModifiers(statement)) { + if ( + isImportEqualsDeclaration(statement) || + hasEffectiveModifier(statement, ModifierFlags.Default) || + !canHaveModifiers(statement) + ) { // `export import` statements should remain as-is, as imports are _not_ implicitly exported in an ambient namespace // Likewise, `export default` classes and the like and just be `default`, so we preserve their `export` modifiers, too return statement; } - const modifiers = factory.createModifiersFromModifierFlags(getEffectiveModifierFlags(statement) & (ModifierFlags.All ^ ModifierFlags.Export)); + const modifiers = factory.createModifiersFromModifierFlags( + getEffectiveModifierFlags(statement) & + (ModifierFlags.All ^ ModifierFlags.Export) + ); return factory.updateModifiers(statement, modifiers); } - function transformTopLevelDeclaration(input: LateVisibilityPaintedStatement) { + function transformTopLevelDeclaration( + input: LateVisibilityPaintedStatement + ) { if (lateMarkedStatements) { while (orderedRemoveItem(lateMarkedStatements, input)); } @@ -1212,10 +2062,15 @@ namespace ts { return transformImportDeclaration(input); } } - if (isDeclaration(input) && isDeclarationAndNotVisible(input)) return; + if (isDeclaration(input) && isDeclarationAndNotVisible(input)) + return; // Elide implementation signatures from overload sets - if (isFunctionLike(input) && resolver.isImplementationOfOverload(input)) return; + if ( + isFunctionLike(input) && + resolver.isImplementationOfOverload(input) + ) + return; let previousEnclosingDeclaration: typeof enclosingDeclaration; if (isEnclosingDeclaration(input)) { @@ -1226,122 +2081,225 @@ namespace ts { const canProdiceDiagnostic = canProduceDiagnostics(input); const oldDiag = getSymbolAccessibilityDiagnostic; if (canProdiceDiagnostic) { - getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(input as DeclarationDiagnosticProducing); + getSymbolAccessibilityDiagnostic = + createGetSymbolAccessibilityDiagnosticForNode( + input as DeclarationDiagnosticProducing + ); } const previousNeedsDeclare = needsDeclare; switch (input.kind) { case SyntaxKind.TypeAliasDeclaration: // Type aliases get `declare`d if need be (for legacy support), but that's all - return cleanup(factory.updateTypeAliasDeclaration( - input, - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - visitNodes(input.typeParameters, visitDeclarationSubtree, isTypeParameterDeclaration), - visitNode(input.type, visitDeclarationSubtree, isTypeNode) - )); + return cleanup( + factory.updateTypeAliasDeclaration( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + visitNodes( + input.typeParameters, + visitDeclarationSubtree, + isTypeParameterDeclaration + ), + visitNode( + input.type, + visitDeclarationSubtree, + isTypeNode + ) + ) + ); case SyntaxKind.InterfaceDeclaration: { - return cleanup(factory.updateInterfaceDeclaration( - input, - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - ensureTypeParams(input, input.typeParameters), - transformHeritageClauses(input.heritageClauses), - visitNodes(input.members, visitDeclarationSubtree) - )); + return cleanup( + factory.updateInterfaceDeclaration( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + ensureTypeParams(input, input.typeParameters), + transformHeritageClauses(input.heritageClauses), + visitNodes(input.members, visitDeclarationSubtree) + ) + ); } case SyntaxKind.FunctionDeclaration: { // Generators lose their generator-ness, excepting their return type - const clean = cleanup(factory.updateFunctionDeclaration( - input, - /*decorators*/ undefined, - ensureModifiers(input), - /*asteriskToken*/ undefined, - input.name, - ensureTypeParams(input, input.typeParameters), - updateParamsList(input, input.parameters), - ensureType(input, input.type), - /*body*/ undefined - )); - if (clean && resolver.isExpandoFunctionDeclaration(input) && shouldEmitFunctionProperties(input)) { - const props = resolver.getPropertiesOfContainerFunction(input); + const clean = cleanup( + factory.updateFunctionDeclaration( + input, + /*decorators*/ undefined, + ensureModifiers(input), + /*asteriskToken*/ undefined, + input.name, + ensureTypeParams(input, input.typeParameters), + updateParamsList(input, input.parameters), + ensureType(input, input.type), + /*body*/ undefined + ) + ); + if ( + clean && + resolver.isExpandoFunctionDeclaration(input) && + shouldEmitFunctionProperties(input) + ) { + const props = + resolver.getPropertiesOfContainerFunction(input); // Use parseNodeFactory so it is usable as an enclosing declaration - const fakespace = parseNodeFactory.createModuleDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, clean.name || factory.createIdentifier("_default"), factory.createModuleBlock([]), NodeFlags.Namespace); - setParent(fakespace, enclosingDeclaration as SourceFile | NamespaceDeclaration); + const fakespace = + parseNodeFactory.createModuleDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + clean.name || + factory.createIdentifier("_default"), + factory.createModuleBlock([]), + NodeFlags.Namespace + ); + setParent( + fakespace, + enclosingDeclaration as + | SourceFile + | NamespaceDeclaration + ); fakespace.locals = createSymbolTable(props); fakespace.symbol = props[0].parent!; const exportMappings: [Identifier, string][] = []; - let declarations: (VariableStatement | ExportDeclaration)[] = mapDefined(props, p => { - if (!p.valueDeclaration || !isPropertyAccessExpression(p.valueDeclaration)) { + let declarations: ( + | VariableStatement + | ExportDeclaration + )[] = mapDefined(props, (p) => { + if ( + !p.valueDeclaration || + !isPropertyAccessExpression(p.valueDeclaration) + ) { return undefined; // TODO GH#33569: Handle element access expressions that created late bound names (rather than silently omitting them) } - getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(p.valueDeclaration); - const type = resolver.createTypeOfDeclaration(p.valueDeclaration, fakespace, declarationEmitNodeBuilderFlags, symbolTracker); + getSymbolAccessibilityDiagnostic = + createGetSymbolAccessibilityDiagnosticForNode( + p.valueDeclaration + ); + const type = resolver.createTypeOfDeclaration( + p.valueDeclaration, + fakespace, + declarationEmitNodeBuilderFlags, + symbolTracker + ); getSymbolAccessibilityDiagnostic = oldDiag; - const nameStr = unescapeLeadingUnderscores(p.escapedName); - const isNonContextualKeywordName = isStringANonContextualKeyword(nameStr); - const name = isNonContextualKeywordName ? factory.getGeneratedNameForNode(p.valueDeclaration) : factory.createIdentifier(nameStr); + const nameStr = unescapeLeadingUnderscores( + p.escapedName + ); + const isNonContextualKeywordName = + isStringANonContextualKeyword(nameStr); + const name = isNonContextualKeywordName + ? factory.getGeneratedNameForNode( + p.valueDeclaration + ) + : factory.createIdentifier(nameStr); if (isNonContextualKeywordName) { exportMappings.push([name, nameStr]); } - const varDecl = factory.createVariableDeclaration(name, /*exclamationToken*/ undefined, type, /*initializer*/ undefined); - return factory.createVariableStatement(isNonContextualKeywordName ? undefined : [factory.createToken(SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([varDecl])); + const varDecl = factory.createVariableDeclaration( + name, + /*exclamationToken*/ undefined, + type, + /*initializer*/ undefined + ); + return factory.createVariableStatement( + isNonContextualKeywordName + ? undefined + : [ + factory.createToken( + SyntaxKind.ExportKeyword + ), + ], + factory.createVariableDeclarationList([varDecl]) + ); }); if (!exportMappings.length) { - declarations = mapDefined(declarations, declaration => factory.updateModifiers(declaration, ModifierFlags.None)); - } - else { - declarations.push(factory.createExportDeclaration( - /*decorators*/ undefined, - /*modifiers*/ undefined, - /*isTypeOnly*/ false, - factory.createNamedExports(map(exportMappings, ([gen, exp]) => { - return factory.createExportSpecifier(/*isTypeOnly*/ false, gen, exp); - })) - )); - } - const namespaceDecl = factory.createModuleDeclaration(/*decorators*/ undefined, ensureModifiers(input), input.name!, factory.createModuleBlock(declarations), NodeFlags.Namespace); - if (!hasEffectiveModifier(clean, ModifierFlags.Default)) { - return [clean, namespaceDecl]; + declarations = mapDefined( + declarations, + (declaration) => + factory.updateModifiers( + declaration, + ModifierFlags.None + ) + ); + } else { + declarations.push( + factory.createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*isTypeOnly*/ false, + factory.createNamedExports( + map(exportMappings, ([gen, exp]) => { + return factory.createExportSpecifier( + /*isTypeOnly*/ false, + gen, + exp + ); + }) + ) + ) + ); } - - const modifiers = factory.createModifiersFromModifierFlags((getEffectiveModifierFlags(clean) & ~ModifierFlags.ExportDefault) | ModifierFlags.Ambient); - const cleanDeclaration = factory.updateFunctionDeclaration( - clean, + const namespaceDecl = factory.createModuleDeclaration( /*decorators*/ undefined, - modifiers, - /*asteriskToken*/ undefined, - clean.name, - clean.typeParameters, - clean.parameters, - clean.type, - /*body*/ undefined + ensureModifiers(input), + input.name!, + factory.createModuleBlock(declarations), + NodeFlags.Namespace ); + if ( + !hasEffectiveModifier(clean, ModifierFlags.Default) + ) { + return [clean, namespaceDecl]; + } - const namespaceDeclaration = factory.updateModuleDeclaration( - namespaceDecl, - /*decorators*/ undefined, - modifiers, - namespaceDecl.name, - namespaceDecl.body - ); + const modifiers = + factory.createModifiersFromModifierFlags( + (getEffectiveModifierFlags(clean) & + ~ModifierFlags.ExportDefault) | + ModifierFlags.Ambient + ); + const cleanDeclaration = + factory.updateFunctionDeclaration( + clean, + /*decorators*/ undefined, + modifiers, + /*asteriskToken*/ undefined, + clean.name, + clean.typeParameters, + clean.parameters, + clean.type, + /*body*/ undefined + ); + + const namespaceDeclaration = + factory.updateModuleDeclaration( + namespaceDecl, + /*decorators*/ undefined, + modifiers, + namespaceDecl.name, + namespaceDecl.body + ); - const exportDefaultDeclaration = factory.createExportAssignment( - /*decorators*/ undefined, - /*modifiers*/ undefined, - /*isExportEquals*/ false, - namespaceDecl.name - ); + const exportDefaultDeclaration = + factory.createExportAssignment( + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*isExportEquals*/ false, + namespaceDecl.name + ); if (isSourceFile(input.parent)) { resultHasExternalModuleIndicator = true; } resultHasScopeMarker = true; - return [cleanDeclaration, namespaceDeclaration, exportDefaultDeclaration]; - } - else { + return [ + cleanDeclaration, + namespaceDeclaration, + exportDefaultDeclaration, + ]; + } else { return clean; } } @@ -1353,8 +2311,14 @@ namespace ts { const oldHasScopeFix = resultHasScopeMarker; resultHasScopeMarker = false; needsScopeFixMarker = false; - const statements = visitNodes(inner.statements, visitDeclarationStatements); - let lateStatements = transformAndReplaceLatePaintedStatements(statements); + const statements = visitNodes( + inner.statements, + visitDeclarationStatements + ); + let lateStatements = + transformAndReplaceLatePaintedStatements( + statements + ); if (input.flags & NodeFlags.Ambient) { needsScopeFixMarker = false; // If it was `declare`'d everything is implicitly exported already, ignore late printed "privates" } @@ -1362,28 +2326,43 @@ namespace ts { // 1. There's an export assignment or export declaration in the namespace - do nothing // 2. Everything is exported and there are no export assignments or export declarations - strip all export modifiers // 3. Some things are exported, some are not, and there's no marker - add an empty marker - if (!isGlobalScopeAugmentation(input) && !hasScopeMarker(lateStatements) && !resultHasScopeMarker) { + if ( + !isGlobalScopeAugmentation(input) && + !hasScopeMarker(lateStatements) && + !resultHasScopeMarker + ) { if (needsScopeFixMarker) { - lateStatements = factory.createNodeArray([...lateStatements, createEmptyExports(factory)]); - } - else { - lateStatements = visitNodes(lateStatements, stripExportModifiers); + lateStatements = factory.createNodeArray([ + ...lateStatements, + createEmptyExports(factory), + ]); + } else { + lateStatements = visitNodes( + lateStatements, + stripExportModifiers + ); } } - const body = factory.updateModuleBlock(inner, lateStatements); + const body = factory.updateModuleBlock( + inner, + lateStatements + ); needsDeclare = previousNeedsDeclare; needsScopeFixMarker = oldNeedsScopeFix; resultHasScopeMarker = oldHasScopeFix; const mods = ensureModifiers(input); - return cleanup(factory.updateModuleDeclaration( - input, - /*decorators*/ undefined, - mods, - isExternalModuleAugmentation(input) ? rewriteModuleSpecifier(input, input.name) : input.name, - body - )); - } - else { + return cleanup( + factory.updateModuleDeclaration( + input, + /*decorators*/ undefined, + mods, + isExternalModuleAugmentation(input) + ? rewriteModuleSpecifier(input, input.name) + : input.name, + body + ) + ); + } else { needsDeclare = previousNeedsDeclare; const mods = ensureModifiers(input); needsDeclare = false; @@ -1392,142 +2371,297 @@ namespace ts { const id = getOriginalNodeId(inner!); // TODO: GH#18217 const body = lateStatementReplacementMap.get(id); lateStatementReplacementMap.delete(id); - return cleanup(factory.updateModuleDeclaration( - input, - /*decorators*/ undefined, - mods, - input.name, - body as ModuleBody - )); + return cleanup( + factory.updateModuleDeclaration( + input, + /*decorators*/ undefined, + mods, + input.name, + body as ModuleBody + ) + ); } } case SyntaxKind.ClassDeclaration: { errorNameNode = input.name; errorFallbackNode = input; - const modifiers = factory.createNodeArray(ensureModifiers(input)); - const typeParameters = ensureTypeParams(input, input.typeParameters); + const modifiers = factory.createNodeArray( + ensureModifiers(input) + ); + const typeParameters = ensureTypeParams( + input, + input.typeParameters + ); const ctor = getFirstConstructorWithBody(input); - let parameterProperties: readonly PropertyDeclaration[] | undefined; + let parameterProperties: + | readonly PropertyDeclaration[] + | undefined; if (ctor) { const oldDiag = getSymbolAccessibilityDiagnostic; - parameterProperties = compact(flatMap(ctor.parameters, (param) => { - if (!hasSyntacticModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param)) return; - getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(param); - if (param.name.kind === SyntaxKind.Identifier) { - return preserveJsDoc(factory.createPropertyDeclaration( - /*decorators*/ undefined, - ensureModifiers(param), - param.name, - param.questionToken, - ensureType(param, param.type), - ensureNoInitializer(param)), param); - } - else { - // Pattern - this is currently an error, but we emit declarations for it somewhat correctly - return walkBindingPattern(param.name); - } + parameterProperties = compact( + flatMap(ctor.parameters, (param) => { + if ( + !hasSyntacticModifier( + param, + ModifierFlags.ParameterPropertyModifier + ) || + shouldStripInternal(param) + ) + return; + getSymbolAccessibilityDiagnostic = + createGetSymbolAccessibilityDiagnosticForNode( + param + ); + if (param.name.kind === SyntaxKind.Identifier) { + return preserveJsDoc( + factory.createPropertyDeclaration( + /*decorators*/ undefined, + ensureModifiers(param), + param.name, + param.questionToken, + ensureType(param, param.type), + ensureNoInitializer(param) + ), + param + ); + } else { + // Pattern - this is currently an error, but we emit declarations for it somewhat correctly + return walkBindingPattern(param.name); + } - function walkBindingPattern(pattern: BindingPattern) { - let elems: PropertyDeclaration[] | undefined; - for (const elem of pattern.elements) { - if (isOmittedExpression(elem)) continue; - if (isBindingPattern(elem.name)) { - elems = concatenate(elems, walkBindingPattern(elem.name)); + function walkBindingPattern( + pattern: BindingPattern + ) { + let elems: + | PropertyDeclaration[] + | undefined; + for (const elem of pattern.elements) { + if (isOmittedExpression(elem)) continue; + if (isBindingPattern(elem.name)) { + elems = concatenate( + elems, + walkBindingPattern(elem.name) + ); + } + elems = elems || []; + elems.push( + factory.createPropertyDeclaration( + /*decorators*/ undefined, + ensureModifiers(param), + elem.name as Identifier, + /*questionToken*/ undefined, + ensureType( + elem, + /*type*/ undefined + ), + /*initializer*/ undefined + ) + ); } - elems = elems || []; - elems.push(factory.createPropertyDeclaration( - /*decorators*/ undefined, - ensureModifiers(param), - elem.name as Identifier, - /*questionToken*/ undefined, - ensureType(elem, /*type*/ undefined), - /*initializer*/ undefined - )); + return elems; } - return elems; - } - })); + }) + ); getSymbolAccessibilityDiagnostic = oldDiag; } - const hasPrivateIdentifier = some(input.members, member => !!member.name && isPrivateIdentifier(member.name)); + const hasPrivateIdentifier = some( + input.members, + (member) => + !!member.name && isPrivateIdentifier(member.name) + ); // When the class has at least one private identifier, create a unique constant identifier to retain the nominal typing behavior // Prevents other classes with the same public members from being used in place of the current class - const privateIdentifier = hasPrivateIdentifier ? [ - factory.createPropertyDeclaration( - /*decorators*/ undefined, - /*modifiers*/ undefined, - factory.createPrivateIdentifier("#private"), - /*questionToken*/ undefined, - /*type*/ undefined, - /*initializer*/ undefined - ) - ] : undefined; - const memberNodes = concatenate(concatenate(privateIdentifier, parameterProperties), visitNodes(input.members, visitDeclarationSubtree)); + const privateIdentifier = hasPrivateIdentifier + ? [ + factory.createPropertyDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + factory.createPrivateIdentifier("#private"), + /*questionToken*/ undefined, + /*type*/ undefined, + /*initializer*/ undefined + ), + ] + : undefined; + const memberNodes = concatenate( + concatenate(privateIdentifier, parameterProperties), + visitNodes(input.members, visitDeclarationSubtree) + ); const members = factory.createNodeArray(memberNodes); const extendsClause = getEffectiveBaseTypeNode(input); - if (extendsClause && !isEntityNameExpression(extendsClause.expression) && extendsClause.expression.kind !== SyntaxKind.NullKeyword) { + if ( + extendsClause && + !isEntityNameExpression(extendsClause.expression) && + extendsClause.expression.kind !== SyntaxKind.NullKeyword + ) { // We must add a temporary declaration for the extends clause expression - const oldId = input.name ? unescapeLeadingUnderscores(input.name.escapedText) : "default"; - const newId = factory.createUniqueName(`${oldId}_base`, GeneratedIdentifierFlags.Optimistic); + const oldId = input.name + ? unescapeLeadingUnderscores(input.name.escapedText) + : "default"; + const newId = factory.createUniqueName( + `${oldId}_base`, + GeneratedIdentifierFlags.Optimistic + ); getSymbolAccessibilityDiagnostic = () => ({ - diagnosticMessage: Diagnostics.extends_clause_of_exported_class_0_has_or_is_using_private_name_1, + diagnosticMessage: + Diagnostics.extends_clause_of_exported_class_0_has_or_is_using_private_name_1, errorNode: extendsClause, - typeName: input.name + typeName: input.name, }); - const varDecl = factory.createVariableDeclaration(newId, /*exclamationToken*/ undefined, resolver.createTypeOfExpression(extendsClause.expression, input, declarationEmitNodeBuilderFlags, symbolTracker), /*initializer*/ undefined); - const statement = factory.createVariableStatement(needsDeclare ? [factory.createModifier(SyntaxKind.DeclareKeyword)] : [], factory.createVariableDeclarationList([varDecl], NodeFlags.Const)); - const heritageClauses = factory.createNodeArray(map(input.heritageClauses, clause => { - if (clause.token === SyntaxKind.ExtendsKeyword) { - const oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(clause.types[0]); - const newClause = factory.updateHeritageClause(clause, map(clause.types, t => factory.updateExpressionWithTypeArguments(t, newId, visitNodes(t.typeArguments, visitDeclarationSubtree)))); - getSymbolAccessibilityDiagnostic = oldDiag; - return newClause; - } - return factory.updateHeritageClause(clause, visitNodes(factory.createNodeArray(filter(clause.types, t => isEntityNameExpression(t.expression) || t.expression.kind === SyntaxKind.NullKeyword)), visitDeclarationSubtree)); - })); - return [statement, cleanup(factory.updateClassDeclaration( - input, - /*decorators*/ undefined, - modifiers, - input.name, - typeParameters, - heritageClauses, - members - ))!]; // TODO: GH#18217 - } - else { - const heritageClauses = transformHeritageClauses(input.heritageClauses); - return cleanup(factory.updateClassDeclaration( - input, - /*decorators*/ undefined, - modifiers, - input.name, - typeParameters, - heritageClauses, - members - )); + const varDecl = factory.createVariableDeclaration( + newId, + /*exclamationToken*/ undefined, + resolver.createTypeOfExpression( + extendsClause.expression, + input, + declarationEmitNodeBuilderFlags, + symbolTracker + ), + /*initializer*/ undefined + ); + const statement = factory.createVariableStatement( + needsDeclare + ? [ + factory.createModifier( + SyntaxKind.DeclareKeyword + ), + ] + : [], + factory.createVariableDeclarationList( + [varDecl], + NodeFlags.Const + ) + ); + const heritageClauses = factory.createNodeArray( + map(input.heritageClauses, (clause) => { + if ( + clause.token === SyntaxKind.ExtendsKeyword + ) { + const oldDiag = + getSymbolAccessibilityDiagnostic; + getSymbolAccessibilityDiagnostic = + createGetSymbolAccessibilityDiagnosticForNode( + clause.types[0] + ); + const newClause = + factory.updateHeritageClause( + clause, + map(clause.types, (t) => + factory.updateExpressionWithTypeArguments( + t, + newId, + visitNodes( + t.typeArguments, + visitDeclarationSubtree + ) + ) + ) + ); + getSymbolAccessibilityDiagnostic = oldDiag; + return newClause; + } + return factory.updateHeritageClause( + clause, + visitNodes( + factory.createNodeArray( + filter( + clause.types, + (t) => + isEntityNameExpression( + t.expression + ) || + t.expression.kind === + SyntaxKind.NullKeyword + ) + ), + visitDeclarationSubtree + ) + ); + }) + ); + return [ + statement, + cleanup( + factory.updateClassDeclaration( + input, + /*decorators*/ undefined, + modifiers, + input.name, + typeParameters, + heritageClauses, + members + ) + )!, + ]; // TODO: GH#18217 + } else { + const heritageClauses = transformHeritageClauses( + input.heritageClauses + ); + return cleanup( + factory.updateClassDeclaration( + input, + /*decorators*/ undefined, + modifiers, + input.name, + typeParameters, + heritageClauses, + members + ) + ); } } case SyntaxKind.VariableStatement: { return cleanup(transformVariableStatement(input)); } case SyntaxKind.EnumDeclaration: { - return cleanup(factory.updateEnumDeclaration(input, /*decorators*/ undefined, factory.createNodeArray(ensureModifiers(input)), input.name, factory.createNodeArray(mapDefined(input.members, m => { - if (shouldStripInternal(m)) return; - // Rewrite enum values to their constants, if available - const constValue = resolver.getConstantValue(m); - return preserveJsDoc(factory.updateEnumMember(m, m.name, constValue !== undefined ? typeof constValue === "string" ? factory.createStringLiteral(constValue) : factory.createNumericLiteral(constValue) : undefined), m); - })))); + return cleanup( + factory.updateEnumDeclaration( + input, + /*decorators*/ undefined, + factory.createNodeArray(ensureModifiers(input)), + input.name, + factory.createNodeArray( + mapDefined(input.members, (m) => { + if (shouldStripInternal(m)) return; + // Rewrite enum values to their constants, if available + const constValue = + resolver.getConstantValue(m); + return preserveJsDoc( + factory.updateEnumMember( + m, + m.name, + constValue !== undefined + ? typeof constValue === "string" + ? factory.createStringLiteral( + constValue + ) + : factory.createNumericLiteral( + constValue + ) + : undefined + ), + m + ); + }) + ) + ) + ); } } // Anything left unhandled is an error, so this should be unreachable - return Debug.assertNever(input, `Unhandled top-level node in declaration emit: ${(ts as any).SyntaxKind[(input as any).kind]}`); + return Debug.assertNever( + input, + `Unhandled top-level node in declaration emit: ${ + (ts as any).SyntaxKind[(input as any).kind] + }` + ); - function cleanup(node: T | undefined): T | undefined { + function cleanup( + node: T | undefined + ): T | undefined { if (isEnclosingDeclaration(input)) { enclosingDeclaration = previousEnclosingDeclaration; } @@ -1537,24 +2671,46 @@ namespace ts { if (input.kind === SyntaxKind.ModuleDeclaration) { needsDeclare = previousNeedsDeclare; } - if (node as Node === input) { + if ((node as Node) === input) { return node; } errorFallbackNode = undefined; errorNameNode = undefined; - return node && setOriginalNode(preserveJsDoc(node, input), input); + return ( + node && setOriginalNode(preserveJsDoc(node, input), input) + ); } } function transformVariableStatement(input: VariableStatement) { - if (!forEach(input.declarationList.declarations, getBindingNameVisible)) return; - const nodes = visitNodes(input.declarationList.declarations, visitDeclarationSubtree); + if ( + !forEach( + input.declarationList.declarations, + getBindingNameVisible + ) + ) + return; + const nodes = visitNodes( + input.declarationList.declarations, + visitDeclarationSubtree + ); if (!length(nodes)) return; - return factory.updateVariableStatement(input, factory.createNodeArray(ensureModifiers(input)), factory.updateVariableDeclarationList(input.declarationList, nodes)); + return factory.updateVariableStatement( + input, + factory.createNodeArray(ensureModifiers(input)), + factory.updateVariableDeclarationList( + input.declarationList, + nodes + ) + ); } - function recreateBindingPattern(d: BindingPattern): VariableDeclaration[] { - return flatten(mapDefined(d.elements, e => recreateBindingElement(e))); + function recreateBindingPattern( + d: BindingPattern + ): VariableDeclaration[] { + return flatten( + mapDefined(d.elements, (e) => recreateBindingElement(e)) + ); } function recreateBindingElement(e: ArrayBindingElement) { @@ -1565,9 +2721,13 @@ namespace ts { if (!getBindingNameVisible(e)) return; if (isBindingPattern(e.name)) { return recreateBindingPattern(e.name); - } - else { - return factory.createVariableDeclaration(e.name, /*exclamationToken*/ undefined, ensureType(e, /*type*/ undefined), /*initializer*/ undefined); + } else { + return factory.createVariableDeclaration( + e.name, + /*exclamationToken*/ undefined, + ensureType(e, /*type*/ undefined), + /*initializer*/ undefined + ); } } } @@ -1576,10 +2736,13 @@ namespace ts { let oldDiag: typeof getSymbolAccessibilityDiagnostic | undefined; if (!suppressNewDiagnosticContexts) { oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNodeName(node); + getSymbolAccessibilityDiagnostic = + createGetSymbolAccessibilityDiagnosticForNodeName(node); } errorNameNode = (node as NamedDeclaration).name; - Debug.assert(resolver.isLateBound(getParseTreeNode(node) as Declaration)); // Should only be called with dynamic names + Debug.assert( + resolver.isLateBound(getParseTreeNode(node) as Declaration) + ); // Should only be called with dynamic names const decl = node as NamedDeclaration as LateBoundDeclaration; const entityName = decl.name.expression; checkEntityNameVisibility(entityName, enclosingDeclaration); @@ -1590,7 +2753,11 @@ namespace ts { } function shouldStripInternal(node: Node) { - return !!stripInternal && !!node && isInternalDeclaration(node, currentSourceFile); + return ( + !!stripInternal && + !!node && + isInternalDeclaration(node, currentSourceFile) + ); } function isScopeMarker(node: Node) { @@ -1611,35 +2778,89 @@ namespace ts { } function ensureModifierFlags(node: Node): ModifierFlags { - let mask = ModifierFlags.All ^ (ModifierFlags.Public | ModifierFlags.Async | ModifierFlags.Override); // No async and override modifiers in declaration files - let additions = (needsDeclare && !isAlwaysType(node)) ? ModifierFlags.Ambient : ModifierFlags.None; + let mask = + ModifierFlags.All ^ + (ModifierFlags.Public | + ModifierFlags.Async | + ModifierFlags.Override); // No async and override modifiers in declaration files + let additions = + needsDeclare && !isAlwaysType(node) + ? ModifierFlags.Ambient + : ModifierFlags.None; const parentIsFile = node.parent.kind === SyntaxKind.SourceFile; - if (!parentIsFile || (isBundledEmit && parentIsFile && isExternalModule(node.parent as SourceFile))) { + if ( + !parentIsFile || + (isBundledEmit && + parentIsFile && + isExternalModule(node.parent as SourceFile)) + ) { mask ^= ModifierFlags.Ambient; additions = ModifierFlags.None; } return maskModifierFlags(node, mask, additions); } - function getTypeAnnotationFromAllAccessorDeclarations(node: AccessorDeclaration, accessors: AllAccessorDeclarations) { + function getTypeAnnotationFromAllAccessorDeclarations( + node: AccessorDeclaration, + accessors: AllAccessorDeclarations + ) { let accessorType = getTypeAnnotationFromAccessor(node); if (!accessorType && node !== accessors.firstAccessor) { - accessorType = getTypeAnnotationFromAccessor(accessors.firstAccessor); + accessorType = getTypeAnnotationFromAccessor( + accessors.firstAccessor + ); // If we end up pulling the type from the second accessor, we also need to change the diagnostic context to get the expected error message - getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(accessors.firstAccessor); + getSymbolAccessibilityDiagnostic = + createGetSymbolAccessibilityDiagnosticForNode( + accessors.firstAccessor + ); } - if (!accessorType && accessors.secondAccessor && node !== accessors.secondAccessor) { - accessorType = getTypeAnnotationFromAccessor(accessors.secondAccessor); + if ( + !accessorType && + accessors.secondAccessor && + node !== accessors.secondAccessor + ) { + accessorType = getTypeAnnotationFromAccessor( + accessors.secondAccessor + ); // If we end up pulling the type from the second accessor, we also need to change the diagnostic context to get the expected error message - getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(accessors.secondAccessor); + getSymbolAccessibilityDiagnostic = + createGetSymbolAccessibilityDiagnosticForNode( + accessors.secondAccessor + ); } return accessorType; } - function transformHeritageClauses(nodes: NodeArray | undefined) { - return factory.createNodeArray(filter(map(nodes, clause => factory.updateHeritageClause(clause, visitNodes(factory.createNodeArray(filter(clause.types, t => { - return isEntityNameExpression(t.expression) || (clause.token === SyntaxKind.ExtendsKeyword && t.expression.kind === SyntaxKind.NullKeyword); - })), visitDeclarationSubtree))), clause => clause.types && !!clause.types.length)); + function transformHeritageClauses( + nodes: NodeArray | undefined + ) { + return factory.createNodeArray( + filter( + map(nodes, (clause) => + factory.updateHeritageClause( + clause, + visitNodes( + factory.createNodeArray( + filter(clause.types, (t) => { + return ( + isEntityNameExpression( + t.expression + ) || + (clause.token === + SyntaxKind.ExtendsKeyword && + t.expression.kind === + SyntaxKind.NullKeyword) + ); + }) + ), + visitDeclarationSubtree + ) + ) + ), + (clause) => clause.types && !!clause.types.length + ) + ); } } @@ -1651,12 +2872,24 @@ namespace ts { } // Elide "public" modifier, as it is the default - function maskModifiers(node: Node, modifierMask?: ModifierFlags, modifierAdditions?: ModifierFlags): Modifier[] | undefined { - return factory.createModifiersFromModifierFlags(maskModifierFlags(node, modifierMask, modifierAdditions)); + function maskModifiers( + node: Node, + modifierMask?: ModifierFlags, + modifierAdditions?: ModifierFlags + ): Modifier[] | undefined { + return factory.createModifiersFromModifierFlags( + maskModifierFlags(node, modifierMask, modifierAdditions) + ); } - function maskModifierFlags(node: Node, modifierMask: ModifierFlags = ModifierFlags.All ^ ModifierFlags.Public, modifierAdditions: ModifierFlags = ModifierFlags.None): ModifierFlags { - let flags = (getEffectiveModifierFlags(node) & modifierMask) | modifierAdditions; + function maskModifierFlags( + node: Node, + modifierMask: ModifierFlags = ModifierFlags.All ^ ModifierFlags.Public, + modifierAdditions: ModifierFlags = ModifierFlags.None + ): ModifierFlags { + let flags = + (getEffectiveModifierFlags(node) & modifierMask) | + modifierAdditions; if (flags & ModifierFlags.Default && !(flags & ModifierFlags.Export)) { // A non-exported default is a nonsequitor - we usually try to remove all export modifiers // from statements in ambient declarations; but a default export must retain its export modifier to be syntactically valid @@ -1668,17 +2901,23 @@ namespace ts { return flags; } - function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | undefined { + function getTypeAnnotationFromAccessor( + accessor: AccessorDeclaration + ): TypeNode | undefined { if (accessor) { return accessor.kind === SyntaxKind.GetAccessor ? accessor.type // Getter - return type : accessor.parameters.length > 0 - ? accessor.parameters[0].type // Setter parameter type - : undefined; + ? accessor.parameters[0].type // Setter parameter type + : undefined; } } - type CanHaveLiteralInitializer = VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration; + type CanHaveLiteralInitializer = + | VariableDeclaration + | PropertyDeclaration + | PropertySignature + | ParameterDeclaration; function canHaveLiteralInitializer(node: Node): boolean { switch (node.kind) { case SyntaxKind.PropertyDeclaration: @@ -1704,7 +2943,9 @@ namespace ts { | ExportDeclaration | ExportAssignment; - function isPreservedDeclarationStatement(node: Node): node is ProcessedDeclarationStatement { + function isPreservedDeclarationStatement( + node: Node + ): node is ProcessedDeclarationStatement { switch (node.kind) { case SyntaxKind.FunctionDeclaration: case SyntaxKind.ModuleDeclaration: diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js index 445ca0d8c1af0..343a3dc49998c 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js @@ -45,14 +45,14 @@ declare type F2 = ({ a }: O) => any; declare type F3 = ({ a, b, c }: O) => any; declare type F4 = ({ a }: O) => any; declare type F5 = ({ a, b, c }: O) => any; -declare type F6 = ({ a }: { +declare type F6 = ({ a: string }: { a: any; }) => typeof string; -declare type F7 = ({ a, b }: { +declare type F7 = ({ a, b: number }: { a: any; b: any; }) => typeof number; -declare type F8 = ({ a, b }: { +declare type F8 = ({ a, b: number }: { a: any; b: any; }) => typeof number; @@ -62,14 +62,14 @@ declare type G2 = ({ a }: O) => any; declare type G3 = ({ a, b, c }: O) => any; declare type G4 = ({ a }: O) => any; declare type G5 = ({ a, b, c }: O) => any; -declare type G6 = ({ a }: { +declare type G6 = ({ a: string }: { a: any; }) => typeof string; -declare type G7 = ({ a, b }: { +declare type G7 = ({ a, b: number }: { a: any; b: any; }) => typeof number; -declare type G8 = ({ a, b }: { +declare type G8 = ({ a, b: number }: { a: any; b: any; }) => typeof number; From cb326d21746462982a2ed8d59eef2b3a1509c48c Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 00:20:32 +0900 Subject: [PATCH 12/31] fix formatting --- src/compiler/transformers/declarations.ts | 2445 +++++---------------- 1 file changed, 602 insertions(+), 1843 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 0a09614535931..0df491537f8eb 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -1,82 +1,35 @@ /*@internal*/ namespace ts { - export function getDeclarationDiagnostics( - host: EmitHost, - resolver: EmitResolver, - file: SourceFile | undefined - ): DiagnosticWithLocation[] | undefined { + export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, file: SourceFile | undefined): DiagnosticWithLocation[] | undefined { const compilerOptions = host.getCompilerOptions(); - const result = transformNodes( - resolver, - host, - factory, - compilerOptions, - file ? [file] : filter(host.getSourceFiles(), isSourceFileNotJson), - [transformDeclarations], - /*allowDtsFiles*/ false - ); + const result = transformNodes(resolver, host, factory, compilerOptions, file ? [file] : filter(host.getSourceFiles(), isSourceFileNotJson), [transformDeclarations], /*allowDtsFiles*/ false); return result.diagnostics; } - function hasInternalAnnotation( - range: CommentRange, - currentSourceFile: SourceFile - ) { + function hasInternalAnnotation(range: CommentRange, currentSourceFile: SourceFile) { const comment = currentSourceFile.text.substring(range.pos, range.end); return stringContains(comment, "@internal"); } - export function isInternalDeclaration( - node: Node, - currentSourceFile: SourceFile - ) { + export function isInternalDeclaration(node: Node, currentSourceFile: SourceFile) { const parseTreeNode = getParseTreeNode(node); if (parseTreeNode && parseTreeNode.kind === SyntaxKind.Parameter) { - const paramIdx = ( - parseTreeNode.parent as SignatureDeclaration - ).parameters.indexOf(parseTreeNode as ParameterDeclaration); - const previousSibling = - paramIdx > 0 - ? (parseTreeNode.parent as SignatureDeclaration).parameters[ - paramIdx - 1 - ] - : undefined; + const paramIdx = (parseTreeNode.parent as SignatureDeclaration).parameters.indexOf(parseTreeNode as ParameterDeclaration); + const previousSibling = paramIdx > 0 ? (parseTreeNode.parent as SignatureDeclaration).parameters[paramIdx - 1] : undefined; const text = currentSourceFile.text; const commentRanges = previousSibling ? concatenate( - // to handle - // ... parameters, /* @internal */ - // public param: string - getTrailingCommentRanges( - text, - skipTrivia( - text, - previousSibling.end + 1, - /* stopAfterLineBreak */ false, - /* stopAtComments */ true - ) - ), - getLeadingCommentRanges(text, node.pos) - ) - : getTrailingCommentRanges( - text, - skipTrivia( - text, - node.pos, - /* stopAfterLineBreak */ false, - /* stopAtComments */ true - ) - ); - return ( - commentRanges && - commentRanges.length && - hasInternalAnnotation(last(commentRanges), currentSourceFile) - ); + // to handle + // ... parameters, /* @internal */ + // public param: string + getTrailingCommentRanges(text, skipTrivia(text, previousSibling.end + 1, /* stopAfterLineBreak */ false, /* stopAtComments */ true)), + getLeadingCommentRanges(text, node.pos) + ) + : getTrailingCommentRanges(text, skipTrivia(text, node.pos, /* stopAfterLineBreak */ false, /* stopAtComments */ true)); + return commentRanges && commentRanges.length && hasInternalAnnotation(last(commentRanges), currentSourceFile); } - const leadingCommentRanges = - parseTreeNode && - getLeadingCommentRangesOfNode(parseTreeNode, currentSourceFile); - return !!forEach(leadingCommentRanges, (range) => { + const leadingCommentRanges = parseTreeNode && getLeadingCommentRangesOfNode(parseTreeNode, currentSourceFile); + return !!forEach(leadingCommentRanges, range => { return hasInternalAnnotation(range, currentSourceFile); }); } @@ -97,29 +50,17 @@ namespace ts { * This means that _no transforms should be allowed to occur before this one_. */ export function transformDeclarations(context: TransformationContext) { - const throwDiagnostic = () => - Debug.fail("Diagnostic emitted without context"); - let getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic = - throwDiagnostic; + const throwDiagnostic = () => Debug.fail("Diagnostic emitted without context"); + let getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic = throwDiagnostic; let needsDeclare = true; let isBundledEmit = false; let resultHasExternalModuleIndicator = false; let needsScopeFixMarker = false; let resultHasScopeMarker = false; let enclosingDeclaration: Node; - let necessaryTypeReferences: - | Set< - [ - specifier: string, - mode: SourceFile["impliedNodeFormat"] | undefined - ] - > - | undefined; + let necessaryTypeReferences: Set<[specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined]> | undefined; let lateMarkedStatements: LateVisibilityPaintedStatement[] | undefined; - let lateStatementReplacementMap: ESMap< - NodeId, - VisitResult - >; + let lateStatementReplacementMap: ESMap>; let suppressNewDiagnosticContexts: boolean; let exportedModulesFromDeclarationEmit: Symbol[] | undefined; @@ -152,14 +93,7 @@ namespace ts { const { noResolve, stripInternal } = options; return transformRoot; - function recordTypeReferenceDirectivesIfNecessary( - typeReferenceDirectives: - | readonly [ - specifier: string, - mode: SourceFile["impliedNodeFormat"] | undefined - ][] - | undefined - ): void { + function recordTypeReferenceDirectivesIfNecessary(typeReferenceDirectives: readonly [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined][] | undefined): void { if (!typeReferenceDirectives) { return; } @@ -169,15 +103,9 @@ namespace ts { } } - function trackReferencedAmbientModule( - node: ModuleDeclaration, - symbol: Symbol - ) { + function trackReferencedAmbientModule(node: ModuleDeclaration, symbol: Symbol) { // If it is visible via `// `, then we should just use that - const directives = resolver.getTypeReferenceDirectivesForSymbol( - symbol, - SymbolFlags.All - ); + const directives = resolver.getTypeReferenceDirectivesForSymbol(symbol, SymbolFlags.All); if (length(directives)) { return recordTypeReferenceDirectivesIfNecessary(directives); } @@ -186,22 +114,14 @@ namespace ts { refs.set(getOriginalNodeId(container), container); } - function handleSymbolAccessibilityError( - symbolAccessibilityResult: SymbolAccessibilityResult - ) { - if ( - symbolAccessibilityResult.accessibility === - SymbolAccessibility.Accessible - ) { + function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) { + if (symbolAccessibilityResult.accessibility === SymbolAccessibility.Accessible) { // Add aliases back onto the possible imports list if they're not there so we can try them again with updated visibility info - if ( - symbolAccessibilityResult && - symbolAccessibilityResult.aliasesToMakeVisible - ) { + if (symbolAccessibilityResult && symbolAccessibilityResult.aliasesToMakeVisible) { if (!lateMarkedStatements) { - lateMarkedStatements = - symbolAccessibilityResult.aliasesToMakeVisible; - } else { + lateMarkedStatements = symbolAccessibilityResult.aliasesToMakeVisible; + } + else { for (const ref of symbolAccessibilityResult.aliasesToMakeVisible) { pushIfUnique(lateMarkedStatements, ref); } @@ -209,33 +129,23 @@ namespace ts { } // TODO: Do all these accessibility checks inside/after the first pass in the checker when declarations are enabled, if possible - } else { + } + else { // Report error - const errorInfo = getSymbolAccessibilityDiagnostic( - symbolAccessibilityResult - ); + const errorInfo = getSymbolAccessibilityDiagnostic(symbolAccessibilityResult); if (errorInfo) { if (errorInfo.typeName) { - context.addDiagnostic( - createDiagnosticForNode( - symbolAccessibilityResult.errorNode || - errorInfo.errorNode, - errorInfo.diagnosticMessage, - getTextOfNode(errorInfo.typeName), - symbolAccessibilityResult.errorSymbolName, - symbolAccessibilityResult.errorModuleName - ) - ); - } else { - context.addDiagnostic( - createDiagnosticForNode( - symbolAccessibilityResult.errorNode || - errorInfo.errorNode, - errorInfo.diagnosticMessage, - symbolAccessibilityResult.errorSymbolName, - symbolAccessibilityResult.errorModuleName - ) - ); + context.addDiagnostic(createDiagnosticForNode(symbolAccessibilityResult.errorNode || errorInfo.errorNode, + errorInfo.diagnosticMessage, + getTextOfNode(errorInfo.typeName), + symbolAccessibilityResult.errorSymbolName, + symbolAccessibilityResult.errorModuleName)); + } + else { + context.addDiagnostic(createDiagnosticForNode(symbolAccessibilityResult.errorNode || errorInfo.errorNode, + errorInfo.diagnosticMessage, + symbolAccessibilityResult.errorSymbolName, + symbolAccessibilityResult.errorModuleName)); } return true; } @@ -245,196 +155,102 @@ namespace ts { function trackExternalModuleSymbolOfImportTypeNode(symbol: Symbol) { if (!isBundledEmit) { - ( - exportedModulesFromDeclarationEmit || - (exportedModulesFromDeclarationEmit = []) - ).push(symbol); + (exportedModulesFromDeclarationEmit || (exportedModulesFromDeclarationEmit = [])).push(symbol); } } - function trackSymbol( - symbol: Symbol, - enclosingDeclaration?: Node, - meaning?: SymbolFlags - ) { + function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { if (symbol.flags & SymbolFlags.TypeParameter) return false; - const issuedDiagnostic = handleSymbolAccessibilityError( - resolver.isSymbolAccessible( - symbol, - enclosingDeclaration, - meaning, - /*shouldComputeAliasesToMakeVisible*/ true - ) - ); - recordTypeReferenceDirectivesIfNecessary( - resolver.getTypeReferenceDirectivesForSymbol(symbol, meaning) - ); + const issuedDiagnostic = handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ true)); + recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForSymbol(symbol, meaning)); return issuedDiagnostic; } function reportPrivateInBaseOfClassExpression(propertyName: string) { if (errorNameNode || errorFallbackNode) { context.addDiagnostic( - createDiagnosticForNode( - (errorNameNode || errorFallbackNode)!, - Diagnostics.Property_0_of_exported_class_expression_may_not_be_private_or_protected, - propertyName - ) - ); + createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.Property_0_of_exported_class_expression_may_not_be_private_or_protected, propertyName)); } } function errorDeclarationNameWithFallback() { - return errorNameNode - ? declarationNameToString(errorNameNode) - : errorFallbackNode && getNameOfDeclaration(errorFallbackNode) - ? declarationNameToString( - getNameOfDeclaration(errorFallbackNode) - ) - : errorFallbackNode && isExportAssignment(errorFallbackNode) - ? errorFallbackNode.isExportEquals - ? "export=" - : "default" - : "(Missing)"; // same fallback declarationNameToString uses when node is zero-width (ie, nameless) + return errorNameNode ? declarationNameToString(errorNameNode) : + errorFallbackNode && getNameOfDeclaration(errorFallbackNode) ? declarationNameToString(getNameOfDeclaration(errorFallbackNode)) : + errorFallbackNode && isExportAssignment(errorFallbackNode) ? errorFallbackNode.isExportEquals ? "export=" : "default" : + "(Missing)"; // same fallback declarationNameToString uses when node is zero-width (ie, nameless) } function reportInaccessibleUniqueSymbolError() { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic( - createDiagnosticForNode( - (errorNameNode || errorFallbackNode)!, - Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary, - errorDeclarationNameWithFallback(), - "unique symbol" - ) - ); + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary, + errorDeclarationNameWithFallback(), + "unique symbol")); } } function reportCyclicStructureError() { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic( - createDiagnosticForNode( - (errorNameNode || errorFallbackNode)!, - Diagnostics.The_inferred_type_of_0_references_a_type_with_a_cyclic_structure_which_cannot_be_trivially_serialized_A_type_annotation_is_necessary, - errorDeclarationNameWithFallback() - ) - ); + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_references_a_type_with_a_cyclic_structure_which_cannot_be_trivially_serialized_A_type_annotation_is_necessary, + errorDeclarationNameWithFallback())); } } function reportInaccessibleThisError() { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic( - createDiagnosticForNode( - (errorNameNode || errorFallbackNode)!, - Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary, - errorDeclarationNameWithFallback(), - "this" - ) - ); + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary, + errorDeclarationNameWithFallback(), + "this")); } } function reportLikelyUnsafeImportRequiredError(specifier: string) { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic( - createDiagnosticForNode( - (errorNameNode || errorFallbackNode)!, - Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary, - errorDeclarationNameWithFallback(), - specifier - ) - ); + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_0_cannot_be_named_without_a_reference_to_1_This_is_likely_not_portable_A_type_annotation_is_necessary, + errorDeclarationNameWithFallback(), + specifier)); } } function reportTruncationError() { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic( - createDiagnosticForNode( - (errorNameNode || errorFallbackNode)!, - Diagnostics.The_inferred_type_of_this_node_exceeds_the_maximum_length_the_compiler_will_serialize_An_explicit_type_annotation_is_needed - ) - ); + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_inferred_type_of_this_node_exceeds_the_maximum_length_the_compiler_will_serialize_An_explicit_type_annotation_is_needed)); } } - function reportNonlocalAugmentation( - containingFile: SourceFile, - parentSymbol: Symbol, - symbol: Symbol - ) { - const primaryDeclaration = parentSymbol.declarations?.find( - (d) => getSourceFileOfNode(d) === containingFile - )!; - const augmentingDeclarations = filter( - symbol.declarations, - (d) => getSourceFileOfNode(d) !== containingFile - ); + function reportNonlocalAugmentation(containingFile: SourceFile, parentSymbol: Symbol, symbol: Symbol) { + const primaryDeclaration = parentSymbol.declarations?.find(d => getSourceFileOfNode(d) === containingFile)!; + const augmentingDeclarations = filter(symbol.declarations, d => getSourceFileOfNode(d) !== containingFile); if (augmentingDeclarations) { for (const augmentations of augmentingDeclarations) { - context.addDiagnostic( - addRelatedInfo( - createDiagnosticForNode( - augmentations, - Diagnostics.Declaration_augments_declaration_in_another_file_This_cannot_be_serialized - ), - createDiagnosticForNode( - primaryDeclaration, - Diagnostics.This_is_the_declaration_being_augmented_Consider_moving_the_augmenting_declaration_into_the_same_file - ) - ) - ); + context.addDiagnostic(addRelatedInfo( + createDiagnosticForNode(augmentations, Diagnostics.Declaration_augments_declaration_in_another_file_This_cannot_be_serialized), + createDiagnosticForNode(primaryDeclaration, Diagnostics.This_is_the_declaration_being_augmented_Consider_moving_the_augmenting_declaration_into_the_same_file) + )); } } } function reportNonSerializableProperty(propertyName: string) { if (errorNameNode || errorFallbackNode) { - context.addDiagnostic( - createDiagnosticForNode( - (errorNameNode || errorFallbackNode)!, - Diagnostics.The_type_of_this_node_cannot_be_serialized_because_its_property_0_cannot_be_serialized, - propertyName - ) - ); + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_type_of_this_node_cannot_be_serialized_because_its_property_0_cannot_be_serialized, propertyName)); } } function reportImportTypeNodeResolutionModeOverride() { if (!isNightly() && (errorNameNode || errorFallbackNode)) { - context.addDiagnostic( - createDiagnosticForNode( - (errorNameNode || errorFallbackNode)!, - Diagnostics.The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next - ) - ); + context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); } } - function transformDeclarationsForJS( - sourceFile: SourceFile, - bundled?: boolean - ) { + function transformDeclarationsForJS(sourceFile: SourceFile, bundled?: boolean) { const oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = (s) => - s.errorNode && canProduceDiagnostics(s.errorNode) - ? createGetSymbolAccessibilityDiagnosticForNode( - s.errorNode - )(s) - : { - diagnosticMessage: s.errorModuleName - ? Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotation_may_unblock_declaration_emit - : Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_An_explicit_type_annotation_may_unblock_declaration_emit, - errorNode: s.errorNode || sourceFile, - }; - const result = resolver.getDeclarationStatementsForSourceFile( - sourceFile, - declarationEmitNodeBuilderFlags, - symbolTracker, - bundled - ); + getSymbolAccessibilityDiagnostic = (s) => (s.errorNode && canProduceDiagnostics(s.errorNode) ? createGetSymbolAccessibilityDiagnosticForNode(s.errorNode)(s) : ({ + diagnosticMessage: s.errorModuleName + ? Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotation_may_unblock_declaration_emit + : Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_An_explicit_type_annotation_may_unblock_declaration_emit, + errorNode: s.errorNode || sourceFile + })); + const result = resolver.getDeclarationStatementsForSourceFile(sourceFile, declarationEmitNodeBuilderFlags, symbolTracker, bundled); getSymbolAccessibilityDiagnostic = oldDiag; return result; } @@ -452,11 +268,10 @@ namespace ts { refs = new Map(); libs = new Map(); let hasNoDefaultLib = false; - const bundle = factory.createBundle( - map(node.sourceFiles, (sourceFile) => { + const bundle = factory.createBundle(map(node.sourceFiles, + sourceFile => { if (sourceFile.isDeclarationFile) return undefined!; // Omit declaration files from bundle results, too // TODO: GH#18217 - hasNoDefaultLib = - hasNoDefaultLib || sourceFile.hasNoDefaultLib; + hasNoDefaultLib = hasNoDefaultLib || sourceFile.hasNoDefaultLib; currentSourceFile = sourceFile; enclosingDeclaration = sourceFile; lateMarkedStatements = undefined; @@ -467,115 +282,39 @@ namespace ts { resultHasScopeMarker = false; collectReferences(sourceFile, refs); collectLibs(sourceFile, libs); - if ( - isExternalOrCommonJsModule(sourceFile) || - isJsonSourceFile(sourceFile) - ) { + if (isExternalOrCommonJsModule(sourceFile) || isJsonSourceFile(sourceFile)) { resultHasExternalModuleIndicator = false; // unused in external module bundle emit (all external modules are within module blocks, therefore are known to be modules) needsDeclare = false; - const statements = isSourceFileJS(sourceFile) - ? factory.createNodeArray( - transformDeclarationsForJS( - sourceFile, - /*bundled*/ true - ) - ) - : visitNodes( - sourceFile.statements, - visitDeclarationStatements - ); - const newFile = factory.updateSourceFile( - sourceFile, - [ - factory.createModuleDeclaration( - [], - [ - factory.createModifier( - SyntaxKind.DeclareKeyword - ), - ], - factory.createStringLiteral( - getResolvedExternalModuleName( - context.getEmitHost(), - sourceFile - ) - ), - factory.createModuleBlock( - setTextRange( - factory.createNodeArray( - transformAndReplaceLatePaintedStatements( - statements - ) - ), - sourceFile.statements - ) - ) - ), - ], - /*isDeclarationFile*/ true, - /*referencedFiles*/ [], - /*typeReferences*/ [], - /*hasNoDefaultLib*/ false, - /*libReferences*/ [] - ); + const statements = isSourceFileJS(sourceFile) ? factory.createNodeArray(transformDeclarationsForJS(sourceFile, /*bundled*/ true)) : visitNodes(sourceFile.statements, visitDeclarationStatements); + const newFile = factory.updateSourceFile(sourceFile, [factory.createModuleDeclaration( + [], + [factory.createModifier(SyntaxKind.DeclareKeyword)], + factory.createStringLiteral(getResolvedExternalModuleName(context.getEmitHost(), sourceFile)), + factory.createModuleBlock(setTextRange(factory.createNodeArray(transformAndReplaceLatePaintedStatements(statements)), sourceFile.statements)) + )], /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false, /*libReferences*/ []); return newFile; } needsDeclare = true; - const updated = isSourceFileJS(sourceFile) - ? factory.createNodeArray( - transformDeclarationsForJS(sourceFile) - ) - : visitNodes( - sourceFile.statements, - visitDeclarationStatements - ); - return factory.updateSourceFile( - sourceFile, - transformAndReplaceLatePaintedStatements(updated), - /*isDeclarationFile*/ true, - /*referencedFiles*/ [], - /*typeReferences*/ [], - /*hasNoDefaultLib*/ false, - /*libReferences*/ [] - ); - }), - mapDefined(node.prepends, (prepend) => { - if (prepend.kind === SyntaxKind.InputFiles) { - const sourceFile = createUnparsedSourceFile( - prepend, - "dts", - stripInternal - ); - hasNoDefaultLib = - hasNoDefaultLib || !!sourceFile.hasNoDefaultLib; - collectReferences(sourceFile, refs); - recordTypeReferenceDirectivesIfNecessary( - map( - sourceFile.typeReferenceDirectives, - (ref) => [ref.fileName, ref.resolutionMode] - ) - ); - collectLibs(sourceFile, libs); - return sourceFile; - } - return prepend; - }) - ); + const updated = isSourceFileJS(sourceFile) ? factory.createNodeArray(transformDeclarationsForJS(sourceFile)) : visitNodes(sourceFile.statements, visitDeclarationStatements); + return factory.updateSourceFile(sourceFile, transformAndReplaceLatePaintedStatements(updated), /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false, /*libReferences*/ []); + } + ), mapDefined(node.prepends, prepend => { + if (prepend.kind === SyntaxKind.InputFiles) { + const sourceFile = createUnparsedSourceFile(prepend, "dts", stripInternal); + hasNoDefaultLib = hasNoDefaultLib || !!sourceFile.hasNoDefaultLib; + collectReferences(sourceFile, refs); + recordTypeReferenceDirectivesIfNecessary(map(sourceFile.typeReferenceDirectives, ref => [ref.fileName, ref.resolutionMode])); + collectLibs(sourceFile, libs); + return sourceFile; + } + return prepend; + })); bundle.syntheticFileReferences = []; - bundle.syntheticTypeReferences = - getFileReferencesForUsedTypeReferences(); + bundle.syntheticTypeReferences = getFileReferencesForUsedTypeReferences(); bundle.syntheticLibReferences = getLibReferences(); bundle.hasNoDefaultLib = hasNoDefaultLib; - const outputFilePath = getDirectoryPath( - normalizeSlashes( - getOutputPathsFor(node, host, /*forceDtsPaths*/ true) - .declarationFilePath! - ) - ); - const referenceVisitor = mapReferencesIntoArray( - bundle.syntheticFileReferences as FileReference[], - outputFilePath - ); + const outputFilePath = getDirectoryPath(normalizeSlashes(getOutputPathsFor(node, host, /*forceDtsPaths*/ true).declarationFilePath!)); + const referenceVisitor = mapReferencesIntoArray(bundle.syntheticFileReferences as FileReference[], outputFilePath); refs.forEach(referenceVisitor); return bundle; } @@ -596,167 +335,78 @@ namespace ts { refs = collectReferences(currentSourceFile, new Map()); libs = collectLibs(currentSourceFile, new Map()); const references: FileReference[] = []; - const outputFilePath = getDirectoryPath( - normalizeSlashes( - getOutputPathsFor(node, host, /*forceDtsPaths*/ true) - .declarationFilePath! - ) - ); - const referenceVisitor = mapReferencesIntoArray( - references, - outputFilePath - ); + const outputFilePath = getDirectoryPath(normalizeSlashes(getOutputPathsFor(node, host, /*forceDtsPaths*/ true).declarationFilePath!)); + const referenceVisitor = mapReferencesIntoArray(references, outputFilePath); let combinedStatements: NodeArray; if (isSourceFileJS(currentSourceFile)) { - combinedStatements = factory.createNodeArray( - transformDeclarationsForJS(node) - ); + combinedStatements = factory.createNodeArray(transformDeclarationsForJS(node)); refs.forEach(referenceVisitor); emittedImports = filter(combinedStatements, isAnyImportSyntax); - } else { - const statements = visitNodes( - node.statements, - visitDeclarationStatements - ); - combinedStatements = setTextRange( - factory.createNodeArray( - transformAndReplaceLatePaintedStatements(statements) - ), - node.statements - ); + } + else { + const statements = visitNodes(node.statements, visitDeclarationStatements); + combinedStatements = setTextRange(factory.createNodeArray(transformAndReplaceLatePaintedStatements(statements)), node.statements); refs.forEach(referenceVisitor); emittedImports = filter(combinedStatements, isAnyImportSyntax); - if ( - isExternalModule(node) && - (!resultHasExternalModuleIndicator || - (needsScopeFixMarker && !resultHasScopeMarker)) - ) { - combinedStatements = setTextRange( - factory.createNodeArray([ - ...combinedStatements, - createEmptyExports(factory), - ]), - combinedStatements - ); + if (isExternalModule(node) && (!resultHasExternalModuleIndicator || (needsScopeFixMarker && !resultHasScopeMarker))) { + combinedStatements = setTextRange(factory.createNodeArray([...combinedStatements, createEmptyExports(factory)]), combinedStatements); } } - const updated = factory.updateSourceFile( - node, - combinedStatements, - /*isDeclarationFile*/ true, - references, - getFileReferencesForUsedTypeReferences(), - node.hasNoDefaultLib, - getLibReferences() - ); - updated.exportedModulesFromDeclarationEmit = - exportedModulesFromDeclarationEmit; + const updated = factory.updateSourceFile(node, combinedStatements, /*isDeclarationFile*/ true, references, getFileReferencesForUsedTypeReferences(), node.hasNoDefaultLib, getLibReferences()); + updated.exportedModulesFromDeclarationEmit = exportedModulesFromDeclarationEmit; return updated; function getLibReferences() { - return map(arrayFrom(libs.keys()), (lib) => ({ - fileName: lib, - pos: -1, - end: -1, - })); + return map(arrayFrom(libs.keys()), lib => ({ fileName: lib, pos: -1, end: -1 })); } function getFileReferencesForUsedTypeReferences() { - return necessaryTypeReferences - ? mapDefined( - arrayFrom(necessaryTypeReferences.keys()), - getFileReferenceForSpecifierModeTuple - ) - : []; - } - - function getFileReferenceForSpecifierModeTuple([typeName, mode]: [ - specifier: string, - mode: SourceFile["impliedNodeFormat"] | undefined - ]): FileReference | undefined { + return necessaryTypeReferences ? mapDefined(arrayFrom(necessaryTypeReferences.keys()), getFileReferenceForSpecifierModeTuple) : []; + } + + function getFileReferenceForSpecifierModeTuple([typeName, mode]: [specifier: string, mode: SourceFile["impliedNodeFormat"] | undefined]): FileReference | undefined { // Elide type references for which we have imports if (emittedImports) { for (const importStatement of emittedImports) { - if ( - isImportEqualsDeclaration(importStatement) && - isExternalModuleReference( - importStatement.moduleReference - ) - ) { - const expr = - importStatement.moduleReference.expression; - if ( - isStringLiteralLike(expr) && - expr.text === typeName - ) { + if (isImportEqualsDeclaration(importStatement) && isExternalModuleReference(importStatement.moduleReference)) { + const expr = importStatement.moduleReference.expression; + if (isStringLiteralLike(expr) && expr.text === typeName) { return undefined; } - } else if ( - isImportDeclaration(importStatement) && - isStringLiteral(importStatement.moduleSpecifier) && - importStatement.moduleSpecifier.text === typeName - ) { + } + else if (isImportDeclaration(importStatement) && isStringLiteral(importStatement.moduleSpecifier) && importStatement.moduleSpecifier.text === typeName) { return undefined; } } } - return { - fileName: typeName, - pos: -1, - end: -1, - ...(mode ? { resolutionMode: mode } : undefined), - }; + return { fileName: typeName, pos: -1, end: -1, ...(mode ? { resolutionMode: mode } : undefined) }; } - function mapReferencesIntoArray( - references: FileReference[], - outputFilePath: string - ): (file: SourceFile) => void { - return (file) => { + function mapReferencesIntoArray(references: FileReference[], outputFilePath: string): (file: SourceFile) => void { + return file => { let declFileName: string; - if (file.isDeclarationFile) { - // Neither decl files or js should have their refs changed + if (file.isDeclarationFile) { // Neither decl files or js should have their refs changed declFileName = file.fileName; - } else { - if ( - isBundledEmit && - contains((node as Bundle).sourceFiles, file) - ) - return; // Omit references to files which are being merged - const paths = getOutputPathsFor( - file, - host, - /*forceDtsPaths*/ true - ); - declFileName = - paths.declarationFilePath || - paths.jsFilePath || - file.fileName; + } + else { + if (isBundledEmit && contains((node as Bundle).sourceFiles, file)) return; // Omit references to files which are being merged + const paths = getOutputPathsFor(file, host, /*forceDtsPaths*/ true); + declFileName = paths.declarationFilePath || paths.jsFilePath || file.fileName; } if (declFileName) { const specifier = moduleSpecifiers.getModuleSpecifier( options, currentSourceFile, - toPath( - outputFilePath, - host.getCurrentDirectory(), - host.getCanonicalFileName - ), - toPath( - declFileName, - host.getCurrentDirectory(), - host.getCanonicalFileName - ), - host + toPath(outputFilePath, host.getCurrentDirectory(), host.getCanonicalFileName), + toPath(declFileName, host.getCurrentDirectory(), host.getCanonicalFileName), + host, ); if (!pathIsRelative(specifier)) { // If some compiler option/symlink/whatever allows access to the file containing the ambient module declaration // via a non-relative name, emit a type reference directive to that non-relative name, rather than // a relative path to the declaration file - recordTypeReferenceDirectivesIfNecessary([ - [specifier, /*mode*/ undefined], - ]); + recordTypeReferenceDirectivesIfNecessary([[specifier, /*mode*/ undefined]]); return; } @@ -767,19 +417,13 @@ namespace ts { host.getCanonicalFileName, /*isAbsolutePathAnUrl*/ false ); - if ( - startsWith(fileName, "./") && - hasExtension(fileName) - ) { + if (startsWith(fileName, "./") && hasExtension(fileName)) { fileName = fileName.substring(2); } // omit references to files from node_modules (npm may disambiguate module // references when installing this package, making the path is unreliable). - if ( - startsWith(fileName, "node_modules/") || - pathContainsNodeModules(fileName) - ) { + if (startsWith(fileName, "node_modules/") || pathContainsNodeModules(fileName)) { return; } @@ -789,16 +433,9 @@ namespace ts { } } - function collectReferences( - sourceFile: SourceFile | UnparsedSource, - ret: ESMap - ) { - if ( - noResolve || - (!isUnparsedSource(sourceFile) && isSourceFileJS(sourceFile)) - ) - return ret; - forEach(sourceFile.referencedFiles, (f) => { + function collectReferences(sourceFile: SourceFile | UnparsedSource, ret: ESMap) { + if (noResolve || (!isUnparsedSource(sourceFile) && isSourceFileJS(sourceFile))) return ret; + forEach(sourceFile.referencedFiles, f => { const elem = host.getSourceFileFromReference(sourceFile, f); if (elem) { ret.set(getOriginalNodeId(elem), elem); @@ -807,11 +444,8 @@ namespace ts { return ret; } - function collectLibs( - sourceFile: SourceFile | UnparsedSource, - ret: ESMap - ) { - forEach(sourceFile.libReferenceDirectives, (ref) => { + function collectLibs(sourceFile: SourceFile | UnparsedSource, ret: ESMap) { + forEach(sourceFile.libReferenceDirectives, ref => { const lib = host.getLibFileFromReference(ref); if (lib) { ret.set(toFileNameLowerCase(ref.fileName), true); @@ -820,49 +454,32 @@ namespace ts { return ret; } - function filterBindingPatternInitializersAndRenamings( - name: BindingName - ) { + function filterBindingPatternInitializersAndRenamings(name: BindingName) { if (name.kind === SyntaxKind.Identifier) { return name; - } else { + } + else { if (name.kind === SyntaxKind.ArrayBindingPattern) { - return factory.updateArrayBindingPattern( - name, - visitNodes(name.elements, visitBindingElement) - ); - } else { - return factory.updateObjectBindingPattern( - name, - visitNodes(name.elements, visitBindingElement) - ); + return factory.updateArrayBindingPattern(name, visitNodes(name.elements, visitBindingElement)); + } + else { + return factory.updateObjectBindingPattern(name, visitNodes(name.elements, visitBindingElement)); } } - function visitBindingElement( - elem: T - ): T; - function visitBindingElement( - elem: ArrayBindingElement - ): ArrayBindingElement { + function visitBindingElement(elem: T): T; + function visitBindingElement(elem: ArrayBindingElement): ArrayBindingElement { if (elem.kind === SyntaxKind.OmittedExpression) { return elem; } - if ( - elem.propertyName && - isIdentifier(elem.propertyName) && - isIdentifier(elem.name) && - !elem.symbol.isReferenced - ) { - // Unnecessary property renaming is forbidden in types, so remove renaming + if (elem.propertyName && isIdentifier(elem.propertyName) && isIdentifier(elem.name) && !elem.symbol.isReferenced) { + // Unnecessary property renaming is forbidden in types, so remove renaming return factory.updateBindingElement( elem, elem.dotDotDotToken, /* propertyName */ undefined, elem.propertyName, - shouldPrintWithInitializer(elem) - ? elem.initializer - : undefined + shouldPrintWithInitializer(elem) ? elem.initializer : undefined ); } return factory.updateBindingElement( @@ -870,23 +487,16 @@ namespace ts { elem.dotDotDotToken, elem.propertyName, filterBindingPatternInitializersAndRenamings(elem.name), - shouldPrintWithInitializer(elem) - ? elem.initializer - : undefined + shouldPrintWithInitializer(elem) ? elem.initializer : undefined ); } } - function ensureParameter( - p: ParameterDeclaration, - modifierMask?: ModifierFlags, - type?: TypeNode - ): ParameterDeclaration { + function ensureParameter(p: ParameterDeclaration, modifierMask?: ModifierFlags, type?: TypeNode): ParameterDeclaration { let oldDiag: typeof getSymbolAccessibilityDiagnostic | undefined; if (!suppressNewDiagnosticContexts) { oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = - createGetSymbolAccessibilityDiagnosticForNode(p); + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(p); } const newParam = factory.updateParameterDeclaration( p, @@ -894,10 +504,7 @@ namespace ts { maskModifiers(p, modifierMask), p.dotDotDotToken, filterBindingPatternInitializersAndRenamings(p.name), - resolver.isOptionalParameter(p) - ? p.questionToken || - factory.createToken(SyntaxKind.QuestionToken) - : undefined, + resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(SyntaxKind.QuestionToken)) : undefined, ensureType(p, type || p.type, /*ignorePrivate*/ true), // Ignore private param props, since this type is going straight back into a param ensureNoInitializer(p) ); @@ -908,20 +515,12 @@ namespace ts { } function shouldPrintWithInitializer(node: Node) { - return ( - canHaveLiteralInitializer(node) && - resolver.isLiteralConstDeclaration( - getParseTreeNode(node) as CanHaveLiteralInitializer - ) - ); // TODO: Make safe + return canHaveLiteralInitializer(node) && resolver.isLiteralConstDeclaration(getParseTreeNode(node) as CanHaveLiteralInitializer); // TODO: Make safe } function ensureNoInitializer(node: CanHaveLiteralInitializer) { if (shouldPrintWithInitializer(node)) { - return resolver.createLiteralConstValue( - getParseTreeNode(node) as CanHaveLiteralInitializer, - symbolTracker - ); // TODO: Make safe + return resolver.createLiteralConstValue(getParseTreeNode(node) as CanHaveLiteralInitializer, symbolTracker); // TODO: Make safe } return undefined; } @@ -940,15 +539,8 @@ namespace ts { | PropertyDeclaration | PropertySignature; - function ensureType( - node: HasInferredType, - type: TypeNode | undefined, - ignorePrivate?: boolean - ): TypeNode | undefined { - if ( - !ignorePrivate && - hasEffectiveModifier(node, ModifierFlags.Private) - ) { + function ensureType(node: HasInferredType, type: TypeNode | undefined, ignorePrivate?: boolean): TypeNode | undefined { + if (!ignorePrivate && hasEffectiveModifier(node, ModifierFlags.Private)) { // Private nodes emit no types (except private parameter properties, whose parameter types are actually visible) return; } @@ -956,17 +548,14 @@ namespace ts { // Literal const declarations will have an initializer ensured rather than a type return; } - const shouldUseResolverType = - node.kind === SyntaxKind.Parameter && + const shouldUseResolverType = node.kind === SyntaxKind.Parameter && (resolver.isRequiredInitializedParameter(node) || - resolver.isOptionalUninitializedParameterProperty(node)); + resolver.isOptionalUninitializedParameterProperty(node)); if (type && !shouldUseResolverType) { return visitNode(type, visitDeclarationSubtree); } if (!getParseTreeNode(node)) { - return type - ? visitNode(type, visitDeclarationSubtree) - : factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); + return type ? visitNode(type, visitDeclarationSubtree) : factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); } if (node.kind === SyntaxKind.SetAccessor) { // Set accessors with no associated type node (from it's param or get accessor return) are `any` since they are never contextually typed right now @@ -977,71 +566,25 @@ namespace ts { let oldDiag: typeof getSymbolAccessibilityDiagnostic; if (!suppressNewDiagnosticContexts) { oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = - createGetSymbolAccessibilityDiagnosticForNode(node); - } - if ( - node.kind === SyntaxKind.VariableDeclaration || - node.kind === SyntaxKind.BindingElement - ) { - return cleanup( - resolver.createTypeOfDeclaration( - node, - enclosingDeclaration, - declarationEmitNodeBuilderFlags, - symbolTracker - ) - ); + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(node); } - if ( - node.kind === SyntaxKind.Parameter || - node.kind === SyntaxKind.PropertyDeclaration || - node.kind === SyntaxKind.PropertySignature - ) { - if (!node.initializer) - return cleanup( - resolver.createTypeOfDeclaration( - node, - enclosingDeclaration, - declarationEmitNodeBuilderFlags, - symbolTracker, - shouldUseResolverType - ) - ); - return cleanup( - resolver.createTypeOfDeclaration( - node, - enclosingDeclaration, - declarationEmitNodeBuilderFlags, - symbolTracker, - shouldUseResolverType - ) || - resolver.createTypeOfExpression( - node.initializer, - enclosingDeclaration, - declarationEmitNodeBuilderFlags, - symbolTracker - ) - ); + if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) { + return cleanup(resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker)); } - return cleanup( - resolver.createReturnTypeOfSignatureDeclaration( - node, - enclosingDeclaration, - declarationEmitNodeBuilderFlags, - symbolTracker - ) - ); + if (node.kind === SyntaxKind.Parameter + || node.kind === SyntaxKind.PropertyDeclaration + || node.kind === SyntaxKind.PropertySignature) { + if (!node.initializer) return cleanup(resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker, shouldUseResolverType)); + return cleanup(resolver.createTypeOfDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker, shouldUseResolverType) || resolver.createTypeOfExpression(node.initializer, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker)); + } + return cleanup(resolver.createReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, declarationEmitNodeBuilderFlags, symbolTracker)); function cleanup(returnValue: TypeNode | undefined) { errorNameNode = undefined; if (!suppressNewDiagnosticContexts) { getSymbolAccessibilityDiagnostic = oldDiag; } - return ( - returnValue || - factory.createKeywordTypeNode(SyntaxKind.AnyKeyword) - ); + return returnValue || factory.createKeywordTypeNode(SyntaxKind.AnyKeyword); } } @@ -1075,51 +618,35 @@ namespace ts { return true; } - const overloadSignatures = input.symbol.declarations?.filter( - (decl) => isFunctionDeclaration(decl) && !decl.body - ); - return ( - !overloadSignatures || - overloadSignatures.indexOf(input) === - overloadSignatures.length - 1 - ); + const overloadSignatures = input.symbol.declarations?.filter(decl => isFunctionDeclaration(decl) && !decl.body); + return !overloadSignatures || overloadSignatures.indexOf(input) === overloadSignatures.length - 1; } - function getBindingNameVisible( - elem: BindingElement | VariableDeclaration | OmittedExpression - ): boolean { + function getBindingNameVisible(elem: BindingElement | VariableDeclaration | OmittedExpression): boolean { if (isOmittedExpression(elem)) { return false; } if (isBindingPattern(elem.name)) { // If any child binding pattern element has been marked visible (usually by collect linked aliases), then this is visible return some(elem.name.elements, getBindingNameVisible); - } else { + } + else { return resolver.isDeclarationVisible(elem); } } - function updateParamsList( - node: Node, - params: NodeArray, - modifierMask?: ModifierFlags - ) { + function updateParamsList(node: Node, params: NodeArray, modifierMask?: ModifierFlags) { if (hasEffectiveModifier(node, ModifierFlags.Private)) { return undefined!; // TODO: GH#18217 } - const newParams = map(params, (p) => - ensureParameter(p, modifierMask) - ); + const newParams = map(params, p => ensureParameter(p, modifierMask)); if (!newParams) { return undefined!; // TODO: GH#18217 } return factory.createNodeArray(newParams, params.hasTrailingComma); } - function updateAccessorParamsList( - input: AccessorDeclaration, - isPrivate: boolean - ) { + function updateAccessorParamsList(input: AccessorDeclaration, isPrivate: boolean) { let newParams: ParameterDeclaration[] | undefined; if (!isPrivate) { const thisParameter = getThisParameter(input); @@ -1132,16 +659,8 @@ namespace ts { if (!isPrivate) { const valueParameter = getSetAccessorValueParameter(input); if (valueParameter) { - const accessorType = - getTypeAnnotationFromAllAccessorDeclarations( - input, - resolver.getAllAccessorDeclarations(input) - ); - newValueParameter = ensureParameter( - valueParameter, - /*modifierMask*/ undefined, - accessorType - ); + const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input, resolver.getAllAccessorDeclarations(input)); + newValueParameter = ensureParameter(valueParameter, /*modifierMask*/ undefined, accessorType); } } if (!newValueParameter) { @@ -1157,40 +676,25 @@ namespace ts { return factory.createNodeArray(newParams || emptyArray); } - function ensureTypeParams( - node: Node, - params: NodeArray | undefined - ) { - return hasEffectiveModifier(node, ModifierFlags.Private) - ? undefined - : visitNodes(params, visitDeclarationSubtree); + function ensureTypeParams(node: Node, params: NodeArray | undefined) { + return hasEffectiveModifier(node, ModifierFlags.Private) ? undefined : visitNodes(params, visitDeclarationSubtree); } function isEnclosingDeclaration(node: Node) { - return ( - isSourceFile(node) || - isTypeAliasDeclaration(node) || - isModuleDeclaration(node) || - isClassDeclaration(node) || - isInterfaceDeclaration(node) || - isFunctionLike(node) || - isIndexSignatureDeclaration(node) || - isMappedTypeNode(node) - ); + return isSourceFile(node) + || isTypeAliasDeclaration(node) + || isModuleDeclaration(node) + || isClassDeclaration(node) + || isInterfaceDeclaration(node) + || isFunctionLike(node) + || isIndexSignatureDeclaration(node) + || isMappedTypeNode(node); } - function checkEntityNameVisibility( - entityName: EntityNameOrEntityNameExpression, - enclosingDeclaration: Node - ) { - const visibilityResult = resolver.isEntityNameVisible( - entityName, - enclosingDeclaration - ); + function checkEntityNameVisibility(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node) { + const visibilityResult = resolver.isEntityNameVisible(entityName, enclosingDeclaration); handleSymbolAccessibilityError(visibilityResult); - recordTypeReferenceDirectivesIfNecessary( - resolver.getTypeReferenceDirectivesForEntityName(entityName) - ); + recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForEntityName(entityName)); } function preserveJsDoc(updated: T, original: Node): T { @@ -1200,73 +704,44 @@ namespace ts { return setCommentRange(updated, getCommentRange(original)); } - function rewriteModuleSpecifier( - parent: - | ImportEqualsDeclaration - | ImportDeclaration - | ExportDeclaration - | ModuleDeclaration - | ImportTypeNode, - input: T | undefined - ): T | StringLiteral { + function rewriteModuleSpecifier(parent: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode, input: T | undefined): T | StringLiteral { if (!input) return undefined!; // TODO: GH#18217 - resultHasExternalModuleIndicator = - resultHasExternalModuleIndicator || - (parent.kind !== SyntaxKind.ModuleDeclaration && - parent.kind !== SyntaxKind.ImportType); + resultHasExternalModuleIndicator = resultHasExternalModuleIndicator || (parent.kind !== SyntaxKind.ModuleDeclaration && parent.kind !== SyntaxKind.ImportType); if (isStringLiteralLike(input)) { if (isBundledEmit) { - const newName = getExternalModuleNameFromDeclaration( - context.getEmitHost(), - resolver, - parent - ); + const newName = getExternalModuleNameFromDeclaration(context.getEmitHost(), resolver, parent); if (newName) { return factory.createStringLiteral(newName); } - } else { - const symbol = - resolver.getSymbolOfExternalModuleSpecifier(input); + } + else { + const symbol = resolver.getSymbolOfExternalModuleSpecifier(input); if (symbol) { - ( - exportedModulesFromDeclarationEmit || - (exportedModulesFromDeclarationEmit = []) - ).push(symbol); + (exportedModulesFromDeclarationEmit || (exportedModulesFromDeclarationEmit = [])).push(symbol); } } } return input; } - function transformImportEqualsDeclaration( - decl: ImportEqualsDeclaration - ) { + function transformImportEqualsDeclaration(decl: ImportEqualsDeclaration) { if (!resolver.isDeclarationVisible(decl)) return; - if ( - decl.moduleReference.kind === SyntaxKind.ExternalModuleReference - ) { + if (decl.moduleReference.kind === SyntaxKind.ExternalModuleReference) { // Rewrite external module names if necessary - const specifier = - getExternalModuleImportEqualsDeclarationExpression(decl); + const specifier = getExternalModuleImportEqualsDeclarationExpression(decl); return factory.updateImportEqualsDeclaration( decl, /*decorators*/ undefined, decl.modifiers, decl.isTypeOnly, decl.name, - factory.updateExternalModuleReference( - decl.moduleReference, - rewriteModuleSpecifier(decl, specifier) - ) + factory.updateExternalModuleReference(decl.moduleReference, rewriteModuleSpecifier(decl, specifier)) ); - } else { + } + else { const oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = - createGetSymbolAccessibilityDiagnosticForNode(decl); - checkEntityNameVisibility( - decl.moduleReference, - enclosingDeclaration - ); + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(decl); + checkEntityNameVisibility(decl.moduleReference, enclosingDeclaration); getSymbolAccessibilityDiagnostic = oldDiag; return decl; } @@ -1281,72 +756,32 @@ namespace ts { decl.modifiers, decl.importClause, rewriteModuleSpecifier(decl, decl.moduleSpecifier), - getResolutionModeOverrideForClauseInNightly( - decl.assertClause - ) + getResolutionModeOverrideForClauseInNightly(decl.assertClause) ); } // The `importClause` visibility corresponds to the default's visibility. - const visibleDefaultBinding = - decl.importClause && - decl.importClause.name && - resolver.isDeclarationVisible(decl.importClause) - ? decl.importClause.name - : undefined; + const visibleDefaultBinding = decl.importClause && decl.importClause.name && resolver.isDeclarationVisible(decl.importClause) ? decl.importClause.name : undefined; if (!decl.importClause.namedBindings) { // No named bindings (either namespace or list), meaning the import is just default or should be elided - return ( - visibleDefaultBinding && - factory.updateImportDeclaration( - decl, - /*decorators*/ undefined, - decl.modifiers, - factory.updateImportClause( - decl.importClause, - decl.importClause.isTypeOnly, - visibleDefaultBinding, - /*namedBindings*/ undefined - ), - rewriteModuleSpecifier(decl, decl.moduleSpecifier), - getResolutionModeOverrideForClauseInNightly( - decl.assertClause - ) - ) - ); + return visibleDefaultBinding && factory.updateImportDeclaration(decl, /*decorators*/ undefined, decl.modifiers, factory.updateImportClause( + decl.importClause, + decl.importClause.isTypeOnly, + visibleDefaultBinding, + /*namedBindings*/ undefined, + ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), getResolutionModeOverrideForClauseInNightly(decl.assertClause)); } - if ( - decl.importClause.namedBindings.kind === - SyntaxKind.NamespaceImport - ) { + if (decl.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { // Namespace import (optionally with visible default) - const namedBindings = resolver.isDeclarationVisible( - decl.importClause.namedBindings - ) - ? decl.importClause.namedBindings - : /*namedBindings*/ undefined; - return visibleDefaultBinding || namedBindings - ? factory.updateImportDeclaration( - decl, - /*decorators*/ undefined, - decl.modifiers, - factory.updateImportClause( - decl.importClause, - decl.importClause.isTypeOnly, - visibleDefaultBinding, - namedBindings - ), - rewriteModuleSpecifier(decl, decl.moduleSpecifier), - getResolutionModeOverrideForClauseInNightly( - decl.assertClause - ) - ) - : undefined; + const namedBindings = resolver.isDeclarationVisible(decl.importClause.namedBindings) ? decl.importClause.namedBindings : /*namedBindings*/ undefined; + return visibleDefaultBinding || namedBindings ? factory.updateImportDeclaration(decl, /*decorators*/ undefined, decl.modifiers, factory.updateImportClause( + decl.importClause, + decl.importClause.isTypeOnly, + visibleDefaultBinding, + namedBindings, + ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), getResolutionModeOverrideForClauseInNightly(decl.assertClause)) : undefined; } // Named imports (optionally with visible default) - const bindingList = mapDefined( - decl.importClause.namedBindings.elements, - (b) => (resolver.isDeclarationVisible(b) ? b : undefined) - ); + const bindingList = mapDefined(decl.importClause.namedBindings.elements, b => resolver.isDeclarationVisible(b) ? b : undefined); if ((bindingList && bindingList.length) || visibleDefaultBinding) { return factory.updateImportDeclaration( decl, @@ -1356,17 +791,10 @@ namespace ts { decl.importClause, decl.importClause.isTypeOnly, visibleDefaultBinding, - bindingList && bindingList.length - ? factory.updateNamedImports( - decl.importClause.namedBindings, - bindingList - ) - : undefined + bindingList && bindingList.length ? factory.updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined, ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), - getResolutionModeOverrideForClauseInNightly( - decl.assertClause - ) + getResolutionModeOverrideForClauseInNightly(decl.assertClause) ); } // Augmentation of export depends on import @@ -1377,35 +805,24 @@ namespace ts { decl.modifiers, /*importClause*/ undefined, rewriteModuleSpecifier(decl, decl.moduleSpecifier), - getResolutionModeOverrideForClauseInNightly( - decl.assertClause - ) + getResolutionModeOverrideForClauseInNightly(decl.assertClause) ); } // Nothing visible } - function getResolutionModeOverrideForClauseInNightly( - assertClause: AssertClause | undefined - ) { + function getResolutionModeOverrideForClauseInNightly(assertClause: AssertClause | undefined) { const mode = getResolutionModeOverrideForClause(assertClause); if (mode !== undefined) { if (!isNightly()) { - context.addDiagnostic( - createDiagnosticForNode( - assertClause!, - Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next - ) - ); + context.addDiagnostic(createDiagnosticForNode(assertClause!, Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next)); } return assertClause; } return undefined; } - function transformAndReplaceLatePaintedStatements( - statements: NodeArray - ): NodeArray { + function transformAndReplaceLatePaintedStatements(statements: NodeArray): NodeArray { // This is a `while` loop because `handleSymbolAccessibilityError` can see additional import aliases marked as visible during // error handling which must now be included in the output and themselves checked for errors. // For example: @@ -1423,19 +840,10 @@ namespace ts { while (length(lateMarkedStatements)) { const i = lateMarkedStatements!.shift()!; if (!isLateVisibilityPaintedStatement(i)) { - return Debug.fail( - `Late replaced statement was found which is not handled by the declaration transformer!: ${ - (ts as any).SyntaxKind - ? (ts as any).SyntaxKind[(i as any).kind] - : (i as any).kind - }` - ); + return Debug.fail(`Late replaced statement was found which is not handled by the declaration transformer!: ${(ts as any).SyntaxKind ? (ts as any).SyntaxKind[(i as any).kind] : (i as any).kind}`); } const priorNeedsDeclare = needsDeclare; - needsDeclare = - i.parent && - isSourceFile(i.parent) && - !(isExternalModule(i.parent) && isBundledEmit); + needsDeclare = i.parent && isSourceFile(i.parent) && !(isExternalModule(i.parent) && isBundledEmit); const result = transformTopLevelDeclaration(i); needsDeclare = priorNeedsDeclare; lateStatementReplacementMap.set(getOriginalNodeId(i), result); @@ -1452,20 +860,11 @@ namespace ts { const result = lateStatementReplacementMap.get(key); lateStatementReplacementMap.delete(key); if (result) { - if ( - isArray(result) - ? some(result, needsScopeMarker) - : needsScopeMarker(result) - ) { + if (isArray(result) ? some(result, needsScopeMarker) : needsScopeMarker(result)) { // Top-level declarations in .d.ts files are always considered exported even without a modifier unless there's an export assignment or specifier needsScopeFixMarker = true; } - if ( - isSourceFile(statement.parent) && - (isArray(result) - ? some(result, isExternalModuleIndicator) - : isExternalModuleIndicator(result)) - ) { + if (isSourceFile(statement.parent) && (isArray(result) ? some(result, isExternalModuleIndicator) : isExternalModuleIndicator(result))) { resultHasExternalModuleIndicator = true; } } @@ -1480,22 +879,13 @@ namespace ts { if (shouldStripInternal(input)) return; if (isDeclaration(input)) { if (isDeclarationAndNotVisible(input)) return; - if ( - hasDynamicName(input) && - !resolver.isLateBound( - getParseTreeNode(input) as Declaration - ) - ) { + if (hasDynamicName(input) && !resolver.isLateBound(getParseTreeNode(input) as Declaration)) { return; } } // Elide implementation signatures from overload sets - if ( - isFunctionLike(input) && - resolver.isImplementationOfOverload(input) - ) - return; + if (isFunctionLike(input) && resolver.isImplementationOfOverload(input)) return; // Elide semicolon class statements if (isSemicolonClassElement(input)) return; @@ -1511,36 +901,18 @@ namespace ts { // We'd see a TDZ violation at runtime const canProduceDiagnostic = canProduceDiagnostics(input); const oldWithinObjectLiteralType = suppressNewDiagnosticContexts; - let shouldEnterSuppressNewDiagnosticsContextContext = - (input.kind === SyntaxKind.TypeLiteral || - input.kind === SyntaxKind.MappedType) && - input.parent.kind !== SyntaxKind.TypeAliasDeclaration; + let shouldEnterSuppressNewDiagnosticsContextContext = ((input.kind === SyntaxKind.TypeLiteral || input.kind === SyntaxKind.MappedType) && input.parent.kind !== SyntaxKind.TypeAliasDeclaration); // Emit methods which are private as properties with no type information if (isMethodDeclaration(input) || isMethodSignature(input)) { if (hasEffectiveModifier(input, ModifierFlags.Private)) { - if ( - input.symbol && - input.symbol.declarations && - input.symbol.declarations[0] !== input - ) - return; // Elide all but the first overload - return cleanup( - factory.createPropertyDeclaration( - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - /*questionToken*/ undefined, - /*type*/ undefined, - /*initializer*/ undefined - ) - ); + if (input.symbol && input.symbol.declarations && input.symbol.declarations[0] !== input) return; // Elide all but the first overload + return cleanup(factory.createPropertyDeclaration(/*decorators*/ undefined, ensureModifiers(input), input.name, /*questionToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined)); } } if (canProduceDiagnostic && !suppressNewDiagnosticContexts) { - getSymbolAccessibilityDiagnostic = - createGetSymbolAccessibilityDiagnosticForNode(input); + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(input); } if (isTypeQueryNode(input)) { @@ -1555,65 +927,30 @@ namespace ts { if (isProcessedComponent(input)) { switch (input.kind) { case SyntaxKind.ExpressionWithTypeArguments: { - if ( - isEntityName(input.expression) || - isEntityNameExpression(input.expression) - ) { - checkEntityNameVisibility( - input.expression, - enclosingDeclaration - ); + if ((isEntityName(input.expression) || isEntityNameExpression(input.expression))) { + checkEntityNameVisibility(input.expression, enclosingDeclaration); } - const node = visitEachChild( - input, - visitDeclarationSubtree, - context - ); - return cleanup( - factory.updateExpressionWithTypeArguments( - node, - node.expression, - node.typeArguments - ) - ); + const node = visitEachChild(input, visitDeclarationSubtree, context); + return cleanup(factory.updateExpressionWithTypeArguments(node, node.expression, node.typeArguments)); } case SyntaxKind.TypeReference: { - checkEntityNameVisibility( - input.typeName, - enclosingDeclaration - ); - const node = visitEachChild( - input, - visitDeclarationSubtree, - context - ); - return cleanup( - factory.updateTypeReferenceNode( - node, - node.typeName, - node.typeArguments - ) - ); + checkEntityNameVisibility(input.typeName, enclosingDeclaration); + const node = visitEachChild(input, visitDeclarationSubtree, context); + return cleanup(factory.updateTypeReferenceNode(node, node.typeName, node.typeArguments)); } case SyntaxKind.ConstructSignature: - return cleanup( - factory.updateConstructSignature( - input, - ensureTypeParams(input, input.typeParameters), - updateParamsList(input, input.parameters), - ensureType(input, input.type) - ) - ); + return cleanup(factory.updateConstructSignature( + input, + ensureTypeParams(input, input.typeParameters), + updateParamsList(input, input.parameters), + ensureType(input, input.type) + )); case SyntaxKind.Constructor: { // A constructor declaration may not have a type annotation const ctor = factory.createConstructorDeclaration( /*decorators*/ undefined, /*modifiers*/ ensureModifiers(input), - updateParamsList( - input, - input.parameters, - ModifierFlags.None - ), + updateParamsList(input, input.parameters, ModifierFlags.None), /*body*/ undefined ); return cleanup(ctor); @@ -1639,120 +976,82 @@ namespace ts { if (isPrivateIdentifier(input.name)) { return cleanup(/*returnValue*/ undefined); } - const accessorType = - getTypeAnnotationFromAllAccessorDeclarations( - input, - resolver.getAllAccessorDeclarations(input) - ); - return cleanup( - factory.updateGetAccessorDeclaration( - input, - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - updateAccessorParamsList( - input, - hasEffectiveModifier( - input, - ModifierFlags.Private - ) - ), - ensureType(input, accessorType), - /*body*/ undefined - ) - ); + const accessorType = getTypeAnnotationFromAllAccessorDeclarations(input, resolver.getAllAccessorDeclarations(input)); + return cleanup(factory.updateGetAccessorDeclaration( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + updateAccessorParamsList(input, hasEffectiveModifier(input, ModifierFlags.Private)), + ensureType(input, accessorType), + /*body*/ undefined)); } case SyntaxKind.SetAccessor: { if (isPrivateIdentifier(input.name)) { return cleanup(/*returnValue*/ undefined); } - return cleanup( - factory.updateSetAccessorDeclaration( - input, - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - updateAccessorParamsList( - input, - hasEffectiveModifier( - input, - ModifierFlags.Private - ) - ), - /*body*/ undefined - ) - ); + return cleanup(factory.updateSetAccessorDeclaration( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + updateAccessorParamsList(input, hasEffectiveModifier(input, ModifierFlags.Private)), + /*body*/ undefined)); } case SyntaxKind.PropertyDeclaration: if (isPrivateIdentifier(input.name)) { return cleanup(/*returnValue*/ undefined); } - return cleanup( - factory.updatePropertyDeclaration( - input, - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - input.questionToken, - ensureType(input, input.type), - ensureNoInitializer(input) - ) - ); + return cleanup(factory.updatePropertyDeclaration( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + input.questionToken, + ensureType(input, input.type), + ensureNoInitializer(input) + )); case SyntaxKind.PropertySignature: if (isPrivateIdentifier(input.name)) { return cleanup(/*returnValue*/ undefined); } - return cleanup( - factory.updatePropertySignature( - input, - ensureModifiers(input), - input.name, - input.questionToken, - ensureType(input, input.type) - ) - ); + return cleanup(factory.updatePropertySignature( + input, + ensureModifiers(input), + input.name, + input.questionToken, + ensureType(input, input.type) + )); case SyntaxKind.MethodSignature: { if (isPrivateIdentifier(input.name)) { return cleanup(/*returnValue*/ undefined); } - return cleanup( - factory.updateMethodSignature( - input, - ensureModifiers(input), - input.name, - input.questionToken, - ensureTypeParams(input, input.typeParameters), - updateParamsList(input, input.parameters), - ensureType(input, input.type) - ) - ); + return cleanup(factory.updateMethodSignature( + input, + ensureModifiers(input), + input.name, + input.questionToken, + ensureTypeParams(input, input.typeParameters), + updateParamsList(input, input.parameters), + ensureType(input, input.type) + )); } case SyntaxKind.CallSignature: { - return cleanup( - factory.updateCallSignature( - input, - ensureTypeParams(input, input.typeParameters), - updateParamsList(input, input.parameters), - ensureType(input, input.type) - ) - ); + return cleanup(factory.updateCallSignature( + input, + ensureTypeParams(input, input.typeParameters), + updateParamsList(input, input.parameters), + ensureType(input, input.type) + )); } case SyntaxKind.IndexSignature: { - return cleanup( - factory.updateIndexSignature( - input, - /*decorators*/ undefined, - ensureModifiers(input), - updateParamsList(input, input.parameters), - visitNode( - input.type, - visitDeclarationSubtree - ) || - factory.createKeywordTypeNode( - SyntaxKind.AnyKeyword - ) - ) - ); + return cleanup(factory.updateIndexSignature( + input, + /*decorators*/ undefined, + ensureModifiers(input), + updateParamsList(input, input.parameters), + visitNode(input.type, visitDeclarationSubtree) || factory.createKeywordTypeNode(SyntaxKind.AnyKeyword) + )); } case SyntaxKind.VariableDeclaration: { if (isBindingPattern(input.name)) { @@ -1760,154 +1059,55 @@ namespace ts { } shouldEnterSuppressNewDiagnosticsContextContext = true; suppressNewDiagnosticContexts = true; // Variable declaration types also suppress new diagnostic contexts, provided the contexts wouldn't be made for binding pattern types - return cleanup( - factory.updateVariableDeclaration( - input, - input.name, - /*exclamationToken*/ undefined, - ensureType(input, input.type), - ensureNoInitializer(input) - ) - ); + return cleanup(factory.updateVariableDeclaration(input, input.name, /*exclamationToken*/ undefined, ensureType(input, input.type), ensureNoInitializer(input))); } case SyntaxKind.TypeParameter: { - if ( - isPrivateMethodTypeParameter(input) && - (input.default || input.constraint) - ) { - return cleanup( - factory.updateTypeParameterDeclaration( - input, - input.modifiers, - input.name, - /*constraint*/ undefined, - /*defaultType*/ undefined - ) - ); + if (isPrivateMethodTypeParameter(input) && (input.default || input.constraint)) { + return cleanup(factory.updateTypeParameterDeclaration(input, input.modifiers, input.name, /*constraint*/ undefined, /*defaultType*/ undefined)); } - return cleanup( - visitEachChild( - input, - visitDeclarationSubtree, - context - ) - ); + return cleanup(visitEachChild(input, visitDeclarationSubtree, context)); } case SyntaxKind.ConditionalType: { // We have to process conditional types in a special way because for visibility purposes we need to push a new enclosingDeclaration // just for the `infer` types in the true branch. It's an implicit declaration scope that only applies to _part_ of the type. - const checkType = visitNode( - input.checkType, - visitDeclarationSubtree - ); - const extendsType = visitNode( - input.extendsType, - visitDeclarationSubtree - ); + const checkType = visitNode(input.checkType, visitDeclarationSubtree); + const extendsType = visitNode(input.extendsType, visitDeclarationSubtree); const oldEnclosingDecl = enclosingDeclaration; enclosingDeclaration = input.trueType; - const trueType = visitNode( - input.trueType, - visitDeclarationSubtree - ); + const trueType = visitNode(input.trueType, visitDeclarationSubtree); enclosingDeclaration = oldEnclosingDecl; - const falseType = visitNode( - input.falseType, - visitDeclarationSubtree - ); - return cleanup( - factory.updateConditionalTypeNode( - input, - checkType, - extendsType, - trueType, - falseType - ) - ); + const falseType = visitNode(input.falseType, visitDeclarationSubtree); + return cleanup(factory.updateConditionalTypeNode(input, checkType, extendsType, trueType, falseType)); } case SyntaxKind.FunctionType: { - return cleanup( - factory.updateFunctionTypeNode( - input, - visitNodes( - input.typeParameters, - visitDeclarationSubtree - ), - updateParamsList(input, input.parameters), - visitNode(input.type, visitDeclarationSubtree) - ) - ); + return cleanup(factory.updateFunctionTypeNode(input, visitNodes(input.typeParameters, visitDeclarationSubtree), updateParamsList(input, input.parameters), visitNode(input.type, visitDeclarationSubtree))); } case SyntaxKind.ConstructorType: { - return cleanup( - factory.updateConstructorTypeNode( - input, - ensureModifiers(input), - visitNodes( - input.typeParameters, - visitDeclarationSubtree - ), - updateParamsList(input, input.parameters), - visitNode(input.type, visitDeclarationSubtree) - ) - ); + return cleanup(factory.updateConstructorTypeNode(input, ensureModifiers(input), visitNodes(input.typeParameters, visitDeclarationSubtree), updateParamsList(input, input.parameters), visitNode(input.type, visitDeclarationSubtree))); } case SyntaxKind.ImportType: { - if (!isLiteralImportTypeNode(input)) - return cleanup(input); - return cleanup( - factory.updateImportTypeNode( - input, - factory.updateLiteralTypeNode( - input.argument, - rewriteModuleSpecifier( - input, - input.argument.literal - ) - ), - input.assertions, - input.qualifier, - visitNodes( - input.typeArguments, - visitDeclarationSubtree, - isTypeNode - ), - input.isTypeOf - ) - ); - } - default: - Debug.assertNever( + if (!isLiteralImportTypeNode(input)) return cleanup(input); + return cleanup(factory.updateImportTypeNode( input, - `Attempted to process unhandled node kind: ${ - (ts as any).SyntaxKind[(input as any).kind] - }` - ); + factory.updateLiteralTypeNode(input.argument, rewriteModuleSpecifier(input, input.argument.literal)), + input.assertions, + input.qualifier, + visitNodes(input.typeArguments, visitDeclarationSubtree, isTypeNode), + input.isTypeOf + )); + } + default: Debug.assertNever(input, `Attempted to process unhandled node kind: ${(ts as any).SyntaxKind[(input as any).kind]}`); } } - if ( - isTupleTypeNode(input) && - getLineAndCharacterOfPosition(currentSourceFile, input.pos) - .line === - getLineAndCharacterOfPosition(currentSourceFile, input.end) - .line - ) { + if (isTupleTypeNode(input) && (getLineAndCharacterOfPosition(currentSourceFile, input.pos).line === getLineAndCharacterOfPosition(currentSourceFile, input.end).line)) { setEmitFlags(input, EmitFlags.SingleLine); } - return cleanup( - visitEachChild(input, visitDeclarationSubtree, context) - ); + return cleanup(visitEachChild(input, visitDeclarationSubtree, context)); - function cleanup( - returnValue: T | undefined - ): T | undefined { - if ( - returnValue && - canProduceDiagnostic && - hasDynamicName(input as Declaration) - ) { + function cleanup(returnValue: T | undefined): T | undefined { + if (returnValue && canProduceDiagnostic && hasDynamicName(input as Declaration)) { checkName(input); } if (isEnclosingDeclaration(input)) { @@ -1922,18 +1122,12 @@ namespace ts { if (returnValue === input) { return returnValue; } - return ( - returnValue && - setOriginalNode(preserveJsDoc(returnValue, input), input) - ); + return returnValue && setOriginalNode(preserveJsDoc(returnValue, input), input); } } function isPrivateMethodTypeParameter(node: TypeParameterDeclaration) { - return ( - node.parent.kind === SyntaxKind.MethodDeclaration && - hasEffectiveModifier(node.parent, ModifierFlags.Private) - ); + return node.parent.kind === SyntaxKind.MethodDeclaration && hasEffectiveModifier(node.parent, ModifierFlags.Private); } function visitDeclarationStatements(input: Node): VisitResult { @@ -1958,9 +1152,7 @@ namespace ts { input.isTypeOnly, input.exportClause, rewriteModuleSpecifier(input, input.moduleSpecifier), - getResolutionModeOverrideForClause(input.assertClause) - ? input.assertClause - : undefined + getResolutionModeOverrideForClause(input.assertClause) ? input.assertClause : undefined ); } case SyntaxKind.ExportAssignment: { @@ -1971,54 +1163,21 @@ namespace ts { resultHasScopeMarker = true; if (input.expression.kind === SyntaxKind.Identifier) { return input; - } else { - const newId = factory.createUniqueName( - "_default", - GeneratedIdentifierFlags.Optimistic - ); + } + else { + const newId = factory.createUniqueName("_default", GeneratedIdentifierFlags.Optimistic); getSymbolAccessibilityDiagnostic = () => ({ - diagnosticMessage: - Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, - errorNode: input, + diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, + errorNode: input }); errorFallbackNode = input; - const varDecl = factory.createVariableDeclaration( - newId, - /*exclamationToken*/ undefined, - resolver.createTypeOfExpression( - input.expression, - input, - declarationEmitNodeBuilderFlags, - symbolTracker - ), - /*initializer*/ undefined - ); + const varDecl = factory.createVariableDeclaration(newId, /*exclamationToken*/ undefined, resolver.createTypeOfExpression(input.expression, input, declarationEmitNodeBuilderFlags, symbolTracker), /*initializer*/ undefined); errorFallbackNode = undefined; - const statement = factory.createVariableStatement( - needsDeclare - ? [ - factory.createModifier( - SyntaxKind.DeclareKeyword - ), - ] - : [], - factory.createVariableDeclarationList( - [varDecl], - NodeFlags.Const - ) - ); + const statement = factory.createVariableStatement(needsDeclare ? [factory.createModifier(SyntaxKind.DeclareKeyword)] : [], factory.createVariableDeclarationList([varDecl], NodeFlags.Const)); preserveJsDoc(statement, input); removeAllComments(input); - return [ - statement, - factory.updateExportAssignment( - input, - input.decorators, - input.modifiers, - newId - ), - ]; + return [statement, factory.updateExportAssignment(input, input.decorators, input.modifiers, newId)]; } } } @@ -2030,26 +1189,17 @@ namespace ts { } function stripExportModifiers(statement: Statement): Statement { - if ( - isImportEqualsDeclaration(statement) || - hasEffectiveModifier(statement, ModifierFlags.Default) || - !canHaveModifiers(statement) - ) { + if (isImportEqualsDeclaration(statement) || hasEffectiveModifier(statement, ModifierFlags.Default) || !canHaveModifiers(statement)) { // `export import` statements should remain as-is, as imports are _not_ implicitly exported in an ambient namespace // Likewise, `export default` classes and the like and just be `default`, so we preserve their `export` modifiers, too return statement; } - const modifiers = factory.createModifiersFromModifierFlags( - getEffectiveModifierFlags(statement) & - (ModifierFlags.All ^ ModifierFlags.Export) - ); + const modifiers = factory.createModifiersFromModifierFlags(getEffectiveModifierFlags(statement) & (ModifierFlags.All ^ ModifierFlags.Export)); return factory.updateModifiers(statement, modifiers); } - function transformTopLevelDeclaration( - input: LateVisibilityPaintedStatement - ) { + function transformTopLevelDeclaration(input: LateVisibilityPaintedStatement) { if (lateMarkedStatements) { while (orderedRemoveItem(lateMarkedStatements, input)); } @@ -2062,15 +1212,10 @@ namespace ts { return transformImportDeclaration(input); } } - if (isDeclaration(input) && isDeclarationAndNotVisible(input)) - return; + if (isDeclaration(input) && isDeclarationAndNotVisible(input)) return; // Elide implementation signatures from overload sets - if ( - isFunctionLike(input) && - resolver.isImplementationOfOverload(input) - ) - return; + if (isFunctionLike(input) && resolver.isImplementationOfOverload(input)) return; let previousEnclosingDeclaration: typeof enclosingDeclaration; if (isEnclosingDeclaration(input)) { @@ -2081,225 +1226,122 @@ namespace ts { const canProdiceDiagnostic = canProduceDiagnostics(input); const oldDiag = getSymbolAccessibilityDiagnostic; if (canProdiceDiagnostic) { - getSymbolAccessibilityDiagnostic = - createGetSymbolAccessibilityDiagnosticForNode( - input as DeclarationDiagnosticProducing - ); + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(input as DeclarationDiagnosticProducing); } const previousNeedsDeclare = needsDeclare; switch (input.kind) { case SyntaxKind.TypeAliasDeclaration: // Type aliases get `declare`d if need be (for legacy support), but that's all - return cleanup( - factory.updateTypeAliasDeclaration( - input, - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - visitNodes( - input.typeParameters, - visitDeclarationSubtree, - isTypeParameterDeclaration - ), - visitNode( - input.type, - visitDeclarationSubtree, - isTypeNode - ) - ) - ); + return cleanup(factory.updateTypeAliasDeclaration( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + visitNodes(input.typeParameters, visitDeclarationSubtree, isTypeParameterDeclaration), + visitNode(input.type, visitDeclarationSubtree, isTypeNode) + )); case SyntaxKind.InterfaceDeclaration: { - return cleanup( - factory.updateInterfaceDeclaration( - input, - /*decorators*/ undefined, - ensureModifiers(input), - input.name, - ensureTypeParams(input, input.typeParameters), - transformHeritageClauses(input.heritageClauses), - visitNodes(input.members, visitDeclarationSubtree) - ) - ); + return cleanup(factory.updateInterfaceDeclaration( + input, + /*decorators*/ undefined, + ensureModifiers(input), + input.name, + ensureTypeParams(input, input.typeParameters), + transformHeritageClauses(input.heritageClauses), + visitNodes(input.members, visitDeclarationSubtree) + )); } case SyntaxKind.FunctionDeclaration: { // Generators lose their generator-ness, excepting their return type - const clean = cleanup( - factory.updateFunctionDeclaration( - input, - /*decorators*/ undefined, - ensureModifiers(input), - /*asteriskToken*/ undefined, - input.name, - ensureTypeParams(input, input.typeParameters), - updateParamsList(input, input.parameters), - ensureType(input, input.type), - /*body*/ undefined - ) - ); - if ( - clean && - resolver.isExpandoFunctionDeclaration(input) && - shouldEmitFunctionProperties(input) - ) { - const props = - resolver.getPropertiesOfContainerFunction(input); + const clean = cleanup(factory.updateFunctionDeclaration( + input, + /*decorators*/ undefined, + ensureModifiers(input), + /*asteriskToken*/ undefined, + input.name, + ensureTypeParams(input, input.typeParameters), + updateParamsList(input, input.parameters), + ensureType(input, input.type), + /*body*/ undefined + )); + if (clean && resolver.isExpandoFunctionDeclaration(input) && shouldEmitFunctionProperties(input)) { + const props = resolver.getPropertiesOfContainerFunction(input); // Use parseNodeFactory so it is usable as an enclosing declaration - const fakespace = - parseNodeFactory.createModuleDeclaration( - /*decorators*/ undefined, - /*modifiers*/ undefined, - clean.name || - factory.createIdentifier("_default"), - factory.createModuleBlock([]), - NodeFlags.Namespace - ); - setParent( - fakespace, - enclosingDeclaration as - | SourceFile - | NamespaceDeclaration - ); + const fakespace = parseNodeFactory.createModuleDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, clean.name || factory.createIdentifier("_default"), factory.createModuleBlock([]), NodeFlags.Namespace); + setParent(fakespace, enclosingDeclaration as SourceFile | NamespaceDeclaration); fakespace.locals = createSymbolTable(props); fakespace.symbol = props[0].parent!; const exportMappings: [Identifier, string][] = []; - let declarations: ( - | VariableStatement - | ExportDeclaration - )[] = mapDefined(props, (p) => { - if ( - !p.valueDeclaration || - !isPropertyAccessExpression(p.valueDeclaration) - ) { + let declarations: (VariableStatement | ExportDeclaration)[] = mapDefined(props, p => { + if (!p.valueDeclaration || !isPropertyAccessExpression(p.valueDeclaration)) { return undefined; // TODO GH#33569: Handle element access expressions that created late bound names (rather than silently omitting them) } - getSymbolAccessibilityDiagnostic = - createGetSymbolAccessibilityDiagnosticForNode( - p.valueDeclaration - ); - const type = resolver.createTypeOfDeclaration( - p.valueDeclaration, - fakespace, - declarationEmitNodeBuilderFlags, - symbolTracker - ); + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(p.valueDeclaration); + const type = resolver.createTypeOfDeclaration(p.valueDeclaration, fakespace, declarationEmitNodeBuilderFlags, symbolTracker); getSymbolAccessibilityDiagnostic = oldDiag; - const nameStr = unescapeLeadingUnderscores( - p.escapedName - ); - const isNonContextualKeywordName = - isStringANonContextualKeyword(nameStr); - const name = isNonContextualKeywordName - ? factory.getGeneratedNameForNode( - p.valueDeclaration - ) - : factory.createIdentifier(nameStr); + const nameStr = unescapeLeadingUnderscores(p.escapedName); + const isNonContextualKeywordName = isStringANonContextualKeyword(nameStr); + const name = isNonContextualKeywordName ? factory.getGeneratedNameForNode(p.valueDeclaration) : factory.createIdentifier(nameStr); if (isNonContextualKeywordName) { exportMappings.push([name, nameStr]); } - const varDecl = factory.createVariableDeclaration( - name, - /*exclamationToken*/ undefined, - type, - /*initializer*/ undefined - ); - return factory.createVariableStatement( - isNonContextualKeywordName - ? undefined - : [ - factory.createToken( - SyntaxKind.ExportKeyword - ), - ], - factory.createVariableDeclarationList([varDecl]) - ); + const varDecl = factory.createVariableDeclaration(name, /*exclamationToken*/ undefined, type, /*initializer*/ undefined); + return factory.createVariableStatement(isNonContextualKeywordName ? undefined : [factory.createToken(SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([varDecl])); }); if (!exportMappings.length) { - declarations = mapDefined( - declarations, - (declaration) => - factory.updateModifiers( - declaration, - ModifierFlags.None - ) - ); - } else { - declarations.push( - factory.createExportDeclaration( - /*decorators*/ undefined, - /*modifiers*/ undefined, - /*isTypeOnly*/ false, - factory.createNamedExports( - map(exportMappings, ([gen, exp]) => { - return factory.createExportSpecifier( - /*isTypeOnly*/ false, - gen, - exp - ); - }) - ) - ) - ); + declarations = mapDefined(declarations, declaration => factory.updateModifiers(declaration, ModifierFlags.None)); } - const namespaceDecl = factory.createModuleDeclaration( - /*decorators*/ undefined, - ensureModifiers(input), - input.name!, - factory.createModuleBlock(declarations), - NodeFlags.Namespace - ); - if ( - !hasEffectiveModifier(clean, ModifierFlags.Default) - ) { + else { + declarations.push(factory.createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*isTypeOnly*/ false, + factory.createNamedExports(map(exportMappings, ([gen, exp]) => { + return factory.createExportSpecifier(/*isTypeOnly*/ false, gen, exp); + })) + )); + } + const namespaceDecl = factory.createModuleDeclaration(/*decorators*/ undefined, ensureModifiers(input), input.name!, factory.createModuleBlock(declarations), NodeFlags.Namespace); + if (!hasEffectiveModifier(clean, ModifierFlags.Default)) { return [clean, namespaceDecl]; } - const modifiers = - factory.createModifiersFromModifierFlags( - (getEffectiveModifierFlags(clean) & - ~ModifierFlags.ExportDefault) | - ModifierFlags.Ambient - ); - const cleanDeclaration = - factory.updateFunctionDeclaration( - clean, - /*decorators*/ undefined, - modifiers, - /*asteriskToken*/ undefined, - clean.name, - clean.typeParameters, - clean.parameters, - clean.type, - /*body*/ undefined - ); - - const namespaceDeclaration = - factory.updateModuleDeclaration( - namespaceDecl, - /*decorators*/ undefined, - modifiers, - namespaceDecl.name, - namespaceDecl.body - ); + const modifiers = factory.createModifiersFromModifierFlags((getEffectiveModifierFlags(clean) & ~ModifierFlags.ExportDefault) | ModifierFlags.Ambient); + const cleanDeclaration = factory.updateFunctionDeclaration( + clean, + /*decorators*/ undefined, + modifiers, + /*asteriskToken*/ undefined, + clean.name, + clean.typeParameters, + clean.parameters, + clean.type, + /*body*/ undefined + ); - const exportDefaultDeclaration = - factory.createExportAssignment( - /*decorators*/ undefined, - /*modifiers*/ undefined, - /*isExportEquals*/ false, - namespaceDecl.name - ); + const namespaceDeclaration = factory.updateModuleDeclaration( + namespaceDecl, + /*decorators*/ undefined, + modifiers, + namespaceDecl.name, + namespaceDecl.body + ); + + const exportDefaultDeclaration = factory.createExportAssignment( + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*isExportEquals*/ false, + namespaceDecl.name + ); if (isSourceFile(input.parent)) { resultHasExternalModuleIndicator = true; } resultHasScopeMarker = true; - return [ - cleanDeclaration, - namespaceDeclaration, - exportDefaultDeclaration, - ]; - } else { + return [cleanDeclaration, namespaceDeclaration, exportDefaultDeclaration]; + } + else { return clean; } } @@ -2311,14 +1353,8 @@ namespace ts { const oldHasScopeFix = resultHasScopeMarker; resultHasScopeMarker = false; needsScopeFixMarker = false; - const statements = visitNodes( - inner.statements, - visitDeclarationStatements - ); - let lateStatements = - transformAndReplaceLatePaintedStatements( - statements - ); + const statements = visitNodes(inner.statements, visitDeclarationStatements); + let lateStatements = transformAndReplaceLatePaintedStatements(statements); if (input.flags & NodeFlags.Ambient) { needsScopeFixMarker = false; // If it was `declare`'d everything is implicitly exported already, ignore late printed "privates" } @@ -2326,43 +1362,28 @@ namespace ts { // 1. There's an export assignment or export declaration in the namespace - do nothing // 2. Everything is exported and there are no export assignments or export declarations - strip all export modifiers // 3. Some things are exported, some are not, and there's no marker - add an empty marker - if ( - !isGlobalScopeAugmentation(input) && - !hasScopeMarker(lateStatements) && - !resultHasScopeMarker - ) { + if (!isGlobalScopeAugmentation(input) && !hasScopeMarker(lateStatements) && !resultHasScopeMarker) { if (needsScopeFixMarker) { - lateStatements = factory.createNodeArray([ - ...lateStatements, - createEmptyExports(factory), - ]); - } else { - lateStatements = visitNodes( - lateStatements, - stripExportModifiers - ); + lateStatements = factory.createNodeArray([...lateStatements, createEmptyExports(factory)]); + } + else { + lateStatements = visitNodes(lateStatements, stripExportModifiers); } } - const body = factory.updateModuleBlock( - inner, - lateStatements - ); + const body = factory.updateModuleBlock(inner, lateStatements); needsDeclare = previousNeedsDeclare; needsScopeFixMarker = oldNeedsScopeFix; resultHasScopeMarker = oldHasScopeFix; const mods = ensureModifiers(input); - return cleanup( - factory.updateModuleDeclaration( - input, - /*decorators*/ undefined, - mods, - isExternalModuleAugmentation(input) - ? rewriteModuleSpecifier(input, input.name) - : input.name, - body - ) - ); - } else { + return cleanup(factory.updateModuleDeclaration( + input, + /*decorators*/ undefined, + mods, + isExternalModuleAugmentation(input) ? rewriteModuleSpecifier(input, input.name) : input.name, + body + )); + } + else { needsDeclare = previousNeedsDeclare; const mods = ensureModifiers(input); needsDeclare = false; @@ -2371,297 +1392,142 @@ namespace ts { const id = getOriginalNodeId(inner!); // TODO: GH#18217 const body = lateStatementReplacementMap.get(id); lateStatementReplacementMap.delete(id); - return cleanup( - factory.updateModuleDeclaration( - input, - /*decorators*/ undefined, - mods, - input.name, - body as ModuleBody - ) - ); + return cleanup(factory.updateModuleDeclaration( + input, + /*decorators*/ undefined, + mods, + input.name, + body as ModuleBody + )); } } case SyntaxKind.ClassDeclaration: { errorNameNode = input.name; errorFallbackNode = input; - const modifiers = factory.createNodeArray( - ensureModifiers(input) - ); - const typeParameters = ensureTypeParams( - input, - input.typeParameters - ); + const modifiers = factory.createNodeArray(ensureModifiers(input)); + const typeParameters = ensureTypeParams(input, input.typeParameters); const ctor = getFirstConstructorWithBody(input); - let parameterProperties: - | readonly PropertyDeclaration[] - | undefined; + let parameterProperties: readonly PropertyDeclaration[] | undefined; if (ctor) { const oldDiag = getSymbolAccessibilityDiagnostic; - parameterProperties = compact( - flatMap(ctor.parameters, (param) => { - if ( - !hasSyntacticModifier( - param, - ModifierFlags.ParameterPropertyModifier - ) || - shouldStripInternal(param) - ) - return; - getSymbolAccessibilityDiagnostic = - createGetSymbolAccessibilityDiagnosticForNode( - param - ); - if (param.name.kind === SyntaxKind.Identifier) { - return preserveJsDoc( - factory.createPropertyDeclaration( - /*decorators*/ undefined, - ensureModifiers(param), - param.name, - param.questionToken, - ensureType(param, param.type), - ensureNoInitializer(param) - ), - param - ); - } else { - // Pattern - this is currently an error, but we emit declarations for it somewhat correctly - return walkBindingPattern(param.name); - } + parameterProperties = compact(flatMap(ctor.parameters, (param) => { + if (!hasSyntacticModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param)) return; + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(param); + if (param.name.kind === SyntaxKind.Identifier) { + return preserveJsDoc(factory.createPropertyDeclaration( + /*decorators*/ undefined, + ensureModifiers(param), + param.name, + param.questionToken, + ensureType(param, param.type), + ensureNoInitializer(param)), param); + } + else { + // Pattern - this is currently an error, but we emit declarations for it somewhat correctly + return walkBindingPattern(param.name); + } - function walkBindingPattern( - pattern: BindingPattern - ) { - let elems: - | PropertyDeclaration[] - | undefined; - for (const elem of pattern.elements) { - if (isOmittedExpression(elem)) continue; - if (isBindingPattern(elem.name)) { - elems = concatenate( - elems, - walkBindingPattern(elem.name) - ); - } - elems = elems || []; - elems.push( - factory.createPropertyDeclaration( - /*decorators*/ undefined, - ensureModifiers(param), - elem.name as Identifier, - /*questionToken*/ undefined, - ensureType( - elem, - /*type*/ undefined - ), - /*initializer*/ undefined - ) - ); + function walkBindingPattern(pattern: BindingPattern) { + let elems: PropertyDeclaration[] | undefined; + for (const elem of pattern.elements) { + if (isOmittedExpression(elem)) continue; + if (isBindingPattern(elem.name)) { + elems = concatenate(elems, walkBindingPattern(elem.name)); } - return elems; + elems = elems || []; + elems.push(factory.createPropertyDeclaration( + /*decorators*/ undefined, + ensureModifiers(param), + elem.name as Identifier, + /*questionToken*/ undefined, + ensureType(elem, /*type*/ undefined), + /*initializer*/ undefined + )); } - }) - ); + return elems; + } + })); getSymbolAccessibilityDiagnostic = oldDiag; } - const hasPrivateIdentifier = some( - input.members, - (member) => - !!member.name && isPrivateIdentifier(member.name) - ); + const hasPrivateIdentifier = some(input.members, member => !!member.name && isPrivateIdentifier(member.name)); // When the class has at least one private identifier, create a unique constant identifier to retain the nominal typing behavior // Prevents other classes with the same public members from being used in place of the current class - const privateIdentifier = hasPrivateIdentifier - ? [ - factory.createPropertyDeclaration( - /*decorators*/ undefined, - /*modifiers*/ undefined, - factory.createPrivateIdentifier("#private"), - /*questionToken*/ undefined, - /*type*/ undefined, - /*initializer*/ undefined - ), - ] - : undefined; - const memberNodes = concatenate( - concatenate(privateIdentifier, parameterProperties), - visitNodes(input.members, visitDeclarationSubtree) - ); + const privateIdentifier = hasPrivateIdentifier ? [ + factory.createPropertyDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + factory.createPrivateIdentifier("#private"), + /*questionToken*/ undefined, + /*type*/ undefined, + /*initializer*/ undefined + ) + ] : undefined; + const memberNodes = concatenate(concatenate(privateIdentifier, parameterProperties), visitNodes(input.members, visitDeclarationSubtree)); const members = factory.createNodeArray(memberNodes); const extendsClause = getEffectiveBaseTypeNode(input); - if ( - extendsClause && - !isEntityNameExpression(extendsClause.expression) && - extendsClause.expression.kind !== SyntaxKind.NullKeyword - ) { + if (extendsClause && !isEntityNameExpression(extendsClause.expression) && extendsClause.expression.kind !== SyntaxKind.NullKeyword) { // We must add a temporary declaration for the extends clause expression - const oldId = input.name - ? unescapeLeadingUnderscores(input.name.escapedText) - : "default"; - const newId = factory.createUniqueName( - `${oldId}_base`, - GeneratedIdentifierFlags.Optimistic - ); + const oldId = input.name ? unescapeLeadingUnderscores(input.name.escapedText) : "default"; + const newId = factory.createUniqueName(`${oldId}_base`, GeneratedIdentifierFlags.Optimistic); getSymbolAccessibilityDiagnostic = () => ({ - diagnosticMessage: - Diagnostics.extends_clause_of_exported_class_0_has_or_is_using_private_name_1, + diagnosticMessage: Diagnostics.extends_clause_of_exported_class_0_has_or_is_using_private_name_1, errorNode: extendsClause, - typeName: input.name, + typeName: input.name }); - const varDecl = factory.createVariableDeclaration( - newId, - /*exclamationToken*/ undefined, - resolver.createTypeOfExpression( - extendsClause.expression, - input, - declarationEmitNodeBuilderFlags, - symbolTracker - ), - /*initializer*/ undefined - ); - const statement = factory.createVariableStatement( - needsDeclare - ? [ - factory.createModifier( - SyntaxKind.DeclareKeyword - ), - ] - : [], - factory.createVariableDeclarationList( - [varDecl], - NodeFlags.Const - ) - ); - const heritageClauses = factory.createNodeArray( - map(input.heritageClauses, (clause) => { - if ( - clause.token === SyntaxKind.ExtendsKeyword - ) { - const oldDiag = - getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = - createGetSymbolAccessibilityDiagnosticForNode( - clause.types[0] - ); - const newClause = - factory.updateHeritageClause( - clause, - map(clause.types, (t) => - factory.updateExpressionWithTypeArguments( - t, - newId, - visitNodes( - t.typeArguments, - visitDeclarationSubtree - ) - ) - ) - ); - getSymbolAccessibilityDiagnostic = oldDiag; - return newClause; - } - return factory.updateHeritageClause( - clause, - visitNodes( - factory.createNodeArray( - filter( - clause.types, - (t) => - isEntityNameExpression( - t.expression - ) || - t.expression.kind === - SyntaxKind.NullKeyword - ) - ), - visitDeclarationSubtree - ) - ); - }) - ); - return [ - statement, - cleanup( - factory.updateClassDeclaration( - input, - /*decorators*/ undefined, - modifiers, - input.name, - typeParameters, - heritageClauses, - members - ) - )!, - ]; // TODO: GH#18217 - } else { - const heritageClauses = transformHeritageClauses( - input.heritageClauses - ); - return cleanup( - factory.updateClassDeclaration( - input, - /*decorators*/ undefined, - modifiers, - input.name, - typeParameters, - heritageClauses, - members - ) - ); + const varDecl = factory.createVariableDeclaration(newId, /*exclamationToken*/ undefined, resolver.createTypeOfExpression(extendsClause.expression, input, declarationEmitNodeBuilderFlags, symbolTracker), /*initializer*/ undefined); + const statement = factory.createVariableStatement(needsDeclare ? [factory.createModifier(SyntaxKind.DeclareKeyword)] : [], factory.createVariableDeclarationList([varDecl], NodeFlags.Const)); + const heritageClauses = factory.createNodeArray(map(input.heritageClauses, clause => { + if (clause.token === SyntaxKind.ExtendsKeyword) { + const oldDiag = getSymbolAccessibilityDiagnostic; + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(clause.types[0]); + const newClause = factory.updateHeritageClause(clause, map(clause.types, t => factory.updateExpressionWithTypeArguments(t, newId, visitNodes(t.typeArguments, visitDeclarationSubtree)))); + getSymbolAccessibilityDiagnostic = oldDiag; + return newClause; + } + return factory.updateHeritageClause(clause, visitNodes(factory.createNodeArray(filter(clause.types, t => isEntityNameExpression(t.expression) || t.expression.kind === SyntaxKind.NullKeyword)), visitDeclarationSubtree)); + })); + return [statement, cleanup(factory.updateClassDeclaration( + input, + /*decorators*/ undefined, + modifiers, + input.name, + typeParameters, + heritageClauses, + members + ))!]; // TODO: GH#18217 + } + else { + const heritageClauses = transformHeritageClauses(input.heritageClauses); + return cleanup(factory.updateClassDeclaration( + input, + /*decorators*/ undefined, + modifiers, + input.name, + typeParameters, + heritageClauses, + members + )); } } case SyntaxKind.VariableStatement: { return cleanup(transformVariableStatement(input)); } case SyntaxKind.EnumDeclaration: { - return cleanup( - factory.updateEnumDeclaration( - input, - /*decorators*/ undefined, - factory.createNodeArray(ensureModifiers(input)), - input.name, - factory.createNodeArray( - mapDefined(input.members, (m) => { - if (shouldStripInternal(m)) return; - // Rewrite enum values to their constants, if available - const constValue = - resolver.getConstantValue(m); - return preserveJsDoc( - factory.updateEnumMember( - m, - m.name, - constValue !== undefined - ? typeof constValue === "string" - ? factory.createStringLiteral( - constValue - ) - : factory.createNumericLiteral( - constValue - ) - : undefined - ), - m - ); - }) - ) - ) - ); + return cleanup(factory.updateEnumDeclaration(input, /*decorators*/ undefined, factory.createNodeArray(ensureModifiers(input)), input.name, factory.createNodeArray(mapDefined(input.members, m => { + if (shouldStripInternal(m)) return; + // Rewrite enum values to their constants, if available + const constValue = resolver.getConstantValue(m); + return preserveJsDoc(factory.updateEnumMember(m, m.name, constValue !== undefined ? typeof constValue === "string" ? factory.createStringLiteral(constValue) : factory.createNumericLiteral(constValue) : undefined), m); + })))); } } // Anything left unhandled is an error, so this should be unreachable - return Debug.assertNever( - input, - `Unhandled top-level node in declaration emit: ${ - (ts as any).SyntaxKind[(input as any).kind] - }` - ); + return Debug.assertNever(input, `Unhandled top-level node in declaration emit: ${(ts as any).SyntaxKind[(input as any).kind]}`); - function cleanup( - node: T | undefined - ): T | undefined { + function cleanup(node: T | undefined): T | undefined { if (isEnclosingDeclaration(input)) { enclosingDeclaration = previousEnclosingDeclaration; } @@ -2671,46 +1537,24 @@ namespace ts { if (input.kind === SyntaxKind.ModuleDeclaration) { needsDeclare = previousNeedsDeclare; } - if ((node as Node) === input) { + if (node as Node === input) { return node; } errorFallbackNode = undefined; errorNameNode = undefined; - return ( - node && setOriginalNode(preserveJsDoc(node, input), input) - ); + return node && setOriginalNode(preserveJsDoc(node, input), input); } } function transformVariableStatement(input: VariableStatement) { - if ( - !forEach( - input.declarationList.declarations, - getBindingNameVisible - ) - ) - return; - const nodes = visitNodes( - input.declarationList.declarations, - visitDeclarationSubtree - ); + if (!forEach(input.declarationList.declarations, getBindingNameVisible)) return; + const nodes = visitNodes(input.declarationList.declarations, visitDeclarationSubtree); if (!length(nodes)) return; - return factory.updateVariableStatement( - input, - factory.createNodeArray(ensureModifiers(input)), - factory.updateVariableDeclarationList( - input.declarationList, - nodes - ) - ); + return factory.updateVariableStatement(input, factory.createNodeArray(ensureModifiers(input)), factory.updateVariableDeclarationList(input.declarationList, nodes)); } - function recreateBindingPattern( - d: BindingPattern - ): VariableDeclaration[] { - return flatten( - mapDefined(d.elements, (e) => recreateBindingElement(e)) - ); + function recreateBindingPattern(d: BindingPattern): VariableDeclaration[] { + return flatten(mapDefined(d.elements, e => recreateBindingElement(e))); } function recreateBindingElement(e: ArrayBindingElement) { @@ -2721,13 +1565,9 @@ namespace ts { if (!getBindingNameVisible(e)) return; if (isBindingPattern(e.name)) { return recreateBindingPattern(e.name); - } else { - return factory.createVariableDeclaration( - e.name, - /*exclamationToken*/ undefined, - ensureType(e, /*type*/ undefined), - /*initializer*/ undefined - ); + } + else { + return factory.createVariableDeclaration(e.name, /*exclamationToken*/ undefined, ensureType(e, /*type*/ undefined), /*initializer*/ undefined); } } } @@ -2736,13 +1576,10 @@ namespace ts { let oldDiag: typeof getSymbolAccessibilityDiagnostic | undefined; if (!suppressNewDiagnosticContexts) { oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = - createGetSymbolAccessibilityDiagnosticForNodeName(node); + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNodeName(node); } errorNameNode = (node as NamedDeclaration).name; - Debug.assert( - resolver.isLateBound(getParseTreeNode(node) as Declaration) - ); // Should only be called with dynamic names + Debug.assert(resolver.isLateBound(getParseTreeNode(node) as Declaration)); // Should only be called with dynamic names const decl = node as NamedDeclaration as LateBoundDeclaration; const entityName = decl.name.expression; checkEntityNameVisibility(entityName, enclosingDeclaration); @@ -2753,11 +1590,7 @@ namespace ts { } function shouldStripInternal(node: Node) { - return ( - !!stripInternal && - !!node && - isInternalDeclaration(node, currentSourceFile) - ); + return !!stripInternal && !!node && isInternalDeclaration(node, currentSourceFile); } function isScopeMarker(node: Node) { @@ -2778,89 +1611,35 @@ namespace ts { } function ensureModifierFlags(node: Node): ModifierFlags { - let mask = - ModifierFlags.All ^ - (ModifierFlags.Public | - ModifierFlags.Async | - ModifierFlags.Override); // No async and override modifiers in declaration files - let additions = - needsDeclare && !isAlwaysType(node) - ? ModifierFlags.Ambient - : ModifierFlags.None; + let mask = ModifierFlags.All ^ (ModifierFlags.Public | ModifierFlags.Async | ModifierFlags.Override); // No async and override modifiers in declaration files + let additions = (needsDeclare && !isAlwaysType(node)) ? ModifierFlags.Ambient : ModifierFlags.None; const parentIsFile = node.parent.kind === SyntaxKind.SourceFile; - if ( - !parentIsFile || - (isBundledEmit && - parentIsFile && - isExternalModule(node.parent as SourceFile)) - ) { + if (!parentIsFile || (isBundledEmit && parentIsFile && isExternalModule(node.parent as SourceFile))) { mask ^= ModifierFlags.Ambient; additions = ModifierFlags.None; } return maskModifierFlags(node, mask, additions); } - function getTypeAnnotationFromAllAccessorDeclarations( - node: AccessorDeclaration, - accessors: AllAccessorDeclarations - ) { + function getTypeAnnotationFromAllAccessorDeclarations(node: AccessorDeclaration, accessors: AllAccessorDeclarations) { let accessorType = getTypeAnnotationFromAccessor(node); if (!accessorType && node !== accessors.firstAccessor) { - accessorType = getTypeAnnotationFromAccessor( - accessors.firstAccessor - ); + accessorType = getTypeAnnotationFromAccessor(accessors.firstAccessor); // If we end up pulling the type from the second accessor, we also need to change the diagnostic context to get the expected error message - getSymbolAccessibilityDiagnostic = - createGetSymbolAccessibilityDiagnosticForNode( - accessors.firstAccessor - ); + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(accessors.firstAccessor); } - if ( - !accessorType && - accessors.secondAccessor && - node !== accessors.secondAccessor - ) { - accessorType = getTypeAnnotationFromAccessor( - accessors.secondAccessor - ); + if (!accessorType && accessors.secondAccessor && node !== accessors.secondAccessor) { + accessorType = getTypeAnnotationFromAccessor(accessors.secondAccessor); // If we end up pulling the type from the second accessor, we also need to change the diagnostic context to get the expected error message - getSymbolAccessibilityDiagnostic = - createGetSymbolAccessibilityDiagnosticForNode( - accessors.secondAccessor - ); + getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(accessors.secondAccessor); } return accessorType; } - function transformHeritageClauses( - nodes: NodeArray | undefined - ) { - return factory.createNodeArray( - filter( - map(nodes, (clause) => - factory.updateHeritageClause( - clause, - visitNodes( - factory.createNodeArray( - filter(clause.types, (t) => { - return ( - isEntityNameExpression( - t.expression - ) || - (clause.token === - SyntaxKind.ExtendsKeyword && - t.expression.kind === - SyntaxKind.NullKeyword) - ); - }) - ), - visitDeclarationSubtree - ) - ) - ), - (clause) => clause.types && !!clause.types.length - ) - ); + function transformHeritageClauses(nodes: NodeArray | undefined) { + return factory.createNodeArray(filter(map(nodes, clause => factory.updateHeritageClause(clause, visitNodes(factory.createNodeArray(filter(clause.types, t => { + return isEntityNameExpression(t.expression) || (clause.token === SyntaxKind.ExtendsKeyword && t.expression.kind === SyntaxKind.NullKeyword); + })), visitDeclarationSubtree))), clause => clause.types && !!clause.types.length)); } } @@ -2872,24 +1651,12 @@ namespace ts { } // Elide "public" modifier, as it is the default - function maskModifiers( - node: Node, - modifierMask?: ModifierFlags, - modifierAdditions?: ModifierFlags - ): Modifier[] | undefined { - return factory.createModifiersFromModifierFlags( - maskModifierFlags(node, modifierMask, modifierAdditions) - ); + function maskModifiers(node: Node, modifierMask?: ModifierFlags, modifierAdditions?: ModifierFlags): Modifier[] | undefined { + return factory.createModifiersFromModifierFlags(maskModifierFlags(node, modifierMask, modifierAdditions)); } - function maskModifierFlags( - node: Node, - modifierMask: ModifierFlags = ModifierFlags.All ^ ModifierFlags.Public, - modifierAdditions: ModifierFlags = ModifierFlags.None - ): ModifierFlags { - let flags = - (getEffectiveModifierFlags(node) & modifierMask) | - modifierAdditions; + function maskModifierFlags(node: Node, modifierMask: ModifierFlags = ModifierFlags.All ^ ModifierFlags.Public, modifierAdditions: ModifierFlags = ModifierFlags.None): ModifierFlags { + let flags = (getEffectiveModifierFlags(node) & modifierMask) | modifierAdditions; if (flags & ModifierFlags.Default && !(flags & ModifierFlags.Export)) { // A non-exported default is a nonsequitor - we usually try to remove all export modifiers // from statements in ambient declarations; but a default export must retain its export modifier to be syntactically valid @@ -2901,23 +1668,17 @@ namespace ts { return flags; } - function getTypeAnnotationFromAccessor( - accessor: AccessorDeclaration - ): TypeNode | undefined { + function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | undefined { if (accessor) { return accessor.kind === SyntaxKind.GetAccessor ? accessor.type // Getter - return type : accessor.parameters.length > 0 - ? accessor.parameters[0].type // Setter parameter type - : undefined; + ? accessor.parameters[0].type // Setter parameter type + : undefined; } } - type CanHaveLiteralInitializer = - | VariableDeclaration - | PropertyDeclaration - | PropertySignature - | ParameterDeclaration; + type CanHaveLiteralInitializer = VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration; function canHaveLiteralInitializer(node: Node): boolean { switch (node.kind) { case SyntaxKind.PropertyDeclaration: @@ -2943,9 +1704,7 @@ namespace ts { | ExportDeclaration | ExportAssignment; - function isPreservedDeclarationStatement( - node: Node - ): node is ProcessedDeclarationStatement { + function isPreservedDeclarationStatement(node: Node): node is ProcessedDeclarationStatement { switch (node.kind) { case SyntaxKind.FunctionDeclaration: case SyntaxKind.ModuleDeclaration: From 17a29fff6c4ce48e9c3f13b55332ce3411c90dc4 Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 00:23:08 +0900 Subject: [PATCH 13/31] revert unnecessary change --- src/compiler/checker.ts | 28 ++++++----------- ...ngDestructuredPropertyInFunctionType.types | 30 +++++++++---------- ...gDestructuredPropertyInFunctionType2.types | 30 +++++++++---------- 3 files changed, 39 insertions(+), 49 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 31d5f2da97fdb..109b1bfecf4a4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5969,29 +5969,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)) { - 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); diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types index 4a4795377a605..8484932a1f109 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types @@ -10,37 +10,37 @@ type F1 = (arg: number) => any; // OK >arg : number type F2 = ({ a: string }: O) => any; // Error ->F2 : ({ a }: O) => any +>F2 : ({ a: string }: O) => any >a : any >string : string type F3 = ({ a: string, b, c }: O) => any; // Error ->F3 : ({ a, b, c }: O) => any +>F3 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type F4 = ({ a: string }: O) => any; // Error ->F4 : ({ a }: O) => any +>F4 : ({ a: string }: O) => any >a : any >string : string type F5 = ({ a: string, b, c }: O) => any; // Error ->F5 : ({ a, b, c }: O) => any +>F5 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type F6 = ({ a: string }) => typeof string; // OK ->F6 : ({ a }: { a: any; }) => any +>F6 : ({ a: string }: { a: any; }) => any >a : any >string : any >string : any type F7 = ({ a: string, b: number }) => typeof number; // Error ->F7 : ({ a, b }: { a: any; b: any; }) => any +>F7 : ({ a: string, b: number }: { a: any; b: any; }) => any >a : any >string : any >b : any @@ -48,7 +48,7 @@ type F7 = ({ a: string, b: number }) => typeof number; // Error >number : any type F8 = ({ a, b: number }) => typeof number; // OK ->F8 : ({ a, b }: { a: any; b: any; }) => any +>F8 : ({ a, b: number }: { a: any; b: any; }) => any >a : any >b : any >number : any @@ -65,37 +65,37 @@ type G1 = (arg: number) => any; // OK >arg : number type G2 = ({ a: string }: O) => any; // Error ->G2 : ({ a }: O) => any +>G2 : ({ a: string }: O) => any >a : any >string : string type G3 = ({ a: string, b, c }: O) => any; // Error ->G3 : ({ a, b, c }: O) => any +>G3 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type G4 = ({ a: string }: O) => any; // Error ->G4 : ({ a }: O) => any +>G4 : ({ a: string }: O) => any >a : any >string : string type G5 = ({ a: string, b, c }: O) => any; // Error ->G5 : ({ a, b, c }: O) => any +>G5 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type G6 = ({ a: string }) => typeof string; // OK ->G6 : ({ a }: { a: any; }) => any +>G6 : ({ a: string }: { a: any; }) => any >a : any >string : any >string : any type G7 = ({ a: string, b: number }) => typeof number; // Error ->G7 : ({ a, b }: { a: any; b: any; }) => any +>G7 : ({ a: string, b: number }: { a: any; b: any; }) => any >a : any >string : any >b : any @@ -103,7 +103,7 @@ type G7 = ({ a: string, b: number }) => typeof number; // Error >number : any type G8 = ({ a, b: number }) => typeof number; // OK ->G8 : ({ a, b }: { a: any; b: any; }) => any +>G8 : ({ a, b: number }: { a: any; b: any; }) => any >a : any >b : any >number : any @@ -121,7 +121,7 @@ interface I { >arg : number method2({ a: string }): any; // Error ->method2 : ({ a }: { a: any; }) => any +>method2 : ({ a: string }: { a: any; }) => any >a : any >string : any diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types index 237a2ac364150..615d9de9145c5 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types @@ -10,37 +10,37 @@ type F1 = (arg: number) => any; >arg : number type F2 = ({ a: string }: O) => any; ->F2 : ({ a }: O) => any +>F2 : ({ a: string }: O) => any >a : any >string : string type F3 = ({ a: string, b, c }: O) => any; ->F3 : ({ a, b, c }: O) => any +>F3 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type F4 = ({ a: string }: O) => any; ->F4 : ({ a }: O) => any +>F4 : ({ a: string }: O) => any >a : any >string : string type F5 = ({ a: string, b, c }: O) => any; ->F5 : ({ a, b, c }: O) => any +>F5 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type F6 = ({ a: string }) => typeof string; ->F6 : ({ a }: { a: any; }) => any +>F6 : ({ a: string }: { a: any; }) => any >a : any >string : any >string : any type F7 = ({ a: string, b: number }) => typeof number; ->F7 : ({ a, b }: { a: any; b: any; }) => any +>F7 : ({ a: string, b: number }: { a: any; b: any; }) => any >a : any >string : any >b : any @@ -48,7 +48,7 @@ type F7 = ({ a: string, b: number }) => typeof number; >number : any type F8 = ({ a, b: number }) => typeof number; ->F8 : ({ a, b }: { a: any; b: any; }) => any +>F8 : ({ a, b: number }: { a: any; b: any; }) => any >a : any >b : any >number : any @@ -65,37 +65,37 @@ type G1 = (arg: number) => any; >arg : number type G2 = ({ a: string }: O) => any; ->G2 : ({ a }: O) => any +>G2 : ({ a: string }: O) => any >a : any >string : string type G3 = ({ a: string, b, c }: O) => any; ->G3 : ({ a, b, c }: O) => any +>G3 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type G4 = ({ a: string }: O) => any; ->G4 : ({ a }: O) => any +>G4 : ({ a: string }: O) => any >a : any >string : string type G5 = ({ a: string, b, c }: O) => any; ->G5 : ({ a, b, c }: O) => any +>G5 : ({ a: string, b, c }: O) => any >a : any >string : string >b : number >c : number type G6 = ({ a: string }) => typeof string; ->G6 : ({ a }: { a: any; }) => any +>G6 : ({ a: string }: { a: any; }) => any >a : any >string : any >string : any type G7 = ({ a: string, b: number }) => typeof number; ->G7 : ({ a, b }: { a: any; b: any; }) => any +>G7 : ({ a: string, b: number }: { a: any; b: any; }) => any >a : any >string : any >b : any @@ -103,7 +103,7 @@ type G7 = ({ a: string, b: number }) => typeof number; >number : any type G8 = ({ a, b: number }) => typeof number; ->G8 : ({ a, b }: { a: any; b: any; }) => any +>G8 : ({ a, b: number }: { a: any; b: any; }) => any >a : any >b : any >number : any @@ -121,7 +121,7 @@ interface I { >arg : number method2({ a: string }): any; ->method2 : ({ a }: { a: any; }) => any +>method2 : ({ a: string }: { a: any; }) => any >a : any >string : any From c4c80db1820ad351a9912c536753687be188b3c7 Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 00:38:15 +0900 Subject: [PATCH 14/31] accept baseline --- ...tuallyTypedBindingInitializerNegative.types | 4 ++-- .../declarationEmitBindingPatterns.js | 2 +- .../declarationEmitBindingPatterns.types | 4 ++-- .../reference/declarationsAndAssignments.types | 8 ++++---- .../destructuringInFunctionType.types | 2 +- ...destructuringParameterDeclaration1ES5.types | 2 +- ...uringParameterDeclaration1ES5iterable.types | 2 +- ...destructuringParameterDeclaration1ES6.types | 2 +- .../destructuringParameterDeclaration6.types | 12 ++++++------ .../excessPropertyCheckWithSpread.types | 6 +++--- .../reference/objectRestParameter.types | 2 +- .../reference/objectRestParameterES5.types | 2 +- ...ngParameterNestedObjectBindingPattern.types | 12 ++++++------ ...stedObjectBindingPatternDefaultValues.types | 12 ++++++------ ...ucturingParameterObjectBindingPattern.types | 12 ++++++------ ...eterObjectBindingPatternDefaultValues.types | 12 ++++++------ ...heticDefaultExportsWithDynamicImports.types | 2 +- ...sxStatelessFunctionComponentOverload1.types | 18 +++++++++--------- 18 files changed, 58 insertions(+), 58 deletions(-) diff --git a/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types b/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types index 6d64e3b7675cf..56ad56f21e577 100644 --- a/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types +++ b/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types @@ -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; } diff --git a/tests/baselines/reference/declarationEmitBindingPatterns.js b/tests/baselines/reference/declarationEmitBindingPatterns.js index 31114071a291e..5581c06ebe67f 100644 --- a/tests/baselines/reference/declarationEmitBindingPatterns.js +++ b/tests/baselines/reference/declarationEmitBindingPatterns.js @@ -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; diff --git a/tests/baselines/reference/declarationEmitBindingPatterns.types b/tests/baselines/reference/declarationEmitBindingPatterns.types index 151991e3039fb..d49893dad94fa 100644 --- a/tests/baselines/reference/declarationEmitBindingPatterns.types +++ b/tests/baselines/reference/declarationEmitBindingPatterns.types @@ -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" diff --git a/tests/baselines/reference/declarationsAndAssignments.types b/tests/baselines/reference/declarationsAndAssignments.types index a3caaa9f6bd84..a7b72a6809424 100644 --- a/tests/baselines/reference/declarationsAndAssignments.types +++ b/tests/baselines/reference/declarationsAndAssignments.types @@ -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; }] diff --git a/tests/baselines/reference/destructuringInFunctionType.types b/tests/baselines/reference/destructuringInFunctionType.types index 553fdaa9cf3b0..2b7f0de66ccf7 100644 --- a/tests/baselines/reference/destructuringInFunctionType.types +++ b/tests/baselines/reference/destructuringInFunctionType.types @@ -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 diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5.types b/tests/baselines/reference/destructuringParameterDeclaration1ES5.types index 381c486a5461d..cea8e2a231b2c 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5.types @@ -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 diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types index aec020bcc2870..4fee7254d2bfa 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types @@ -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 diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types index acf5dcffb5ce2..cee129da47534 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types @@ -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 diff --git a/tests/baselines/reference/destructuringParameterDeclaration6.types b/tests/baselines/reference/destructuringParameterDeclaration6.types index 6b5085d21219c..d135f9cb8fdbf 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration6.types @@ -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 diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.types b/tests/baselines/reference/excessPropertyCheckWithSpread.types index de5385d0b33e0..460f43d2289f4 100644 --- a/tests/baselines/reference/excessPropertyCheckWithSpread.types +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.types @@ -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 diff --git a/tests/baselines/reference/objectRestParameter.types b/tests/baselines/reference/objectRestParameter.types index 668214c495f1f..71047deea43fe 100644 --- a/tests/baselines/reference/objectRestParameter.types +++ b/tests/baselines/reference/objectRestParameter.types @@ -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; } diff --git a/tests/baselines/reference/objectRestParameterES5.types b/tests/baselines/reference/objectRestParameterES5.types index d88da6a249433..74df68093aa45 100644 --- a/tests/baselines/reference/objectRestParameterES5.types +++ b/tests/baselines/reference/objectRestParameterES5.types @@ -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; } diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types index dcabaa3bf785d..287f0c41d2587 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types @@ -34,7 +34,7 @@ var robotA: Robot = { name: "mower", skills: { primary: "mowing", secondary: "no >"none" : "none" function foo1({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) { ->foo1 : ({ skills: { primary, secondary } }: Robot) => void +>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void >skills : any >primary : any >primaryA : string @@ -49,7 +49,7 @@ function foo1({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) { >primaryA : string } function foo2({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) { ->foo2 : ({ name, skills: { primary, secondary } }: Robot) => void +>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void >name : any >nameC : string >skills : any @@ -81,12 +81,12 @@ function foo3({ skills }: Robot) { foo1(robotA); >foo1(robotA) : void ->foo1 : ({ skills: { primary, secondary } }: Robot) => void +>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void >robotA : Robot foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo1 : ({ skills: { primary, secondary } }: Robot) => void +>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" @@ -99,12 +99,12 @@ foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name, skills: { primary, secondary } }: Robot) => void +>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void >robotA : Robot foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo2 : ({ name, skills: { primary, secondary } }: Robot) => void +>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types index 9082abff9dfb4..8bfc93c3db70b 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types @@ -34,7 +34,7 @@ var robotA: Robot = { name: "mower", skills: { primary: "mowing", secondary: "no >"none" : "none" function foo1( ->foo1 : ({ skills: { primary, secondary } }?: Robot) => void +>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void { skills: { >skills : any @@ -67,7 +67,7 @@ function foo1( >primaryA : string } function foo2( ->foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void +>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void { name: nameC = "name", >name : any @@ -126,12 +126,12 @@ function foo3({ skills = { primary: "SomeSkill", secondary: "someSkill" } }: Ro foo1(robotA); >foo1(robotA) : void ->foo1 : ({ skills: { primary, secondary } }?: Robot) => void +>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void >robotA : Robot foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo1 : ({ skills: { primary, secondary } }?: Robot) => void +>foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" @@ -144,12 +144,12 @@ foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void +>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void >robotA : Robot foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void +>foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types index a02d95a9939b9..05a01de79ac9b 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types @@ -26,7 +26,7 @@ var robotA: Robot = { name: "mower", skill: "mowing" }; >"mowing" : "mowing" function foo1({ name: nameA }: Robot) { ->foo1 : ({ name }: Robot) => void +>foo1 : ({ name: nameA }: Robot) => void >name : any >nameA : string @@ -38,7 +38,7 @@ function foo1({ name: nameA }: Robot) { >nameA : string } function foo2({ name: nameB, skill: skillB }: Robot) { ->foo2 : ({ name, skill }: Robot) => void +>foo2 : ({ name: nameB, skill: skillB }: Robot) => void >name : any >nameB : string >skill : any @@ -65,12 +65,12 @@ function foo3({ name }: Robot) { foo1(robotA); >foo1(robotA) : void ->foo1 : ({ name }: Robot) => void +>foo1 : ({ name: nameA }: Robot) => void >robotA : Robot foo1({ name: "Edger", skill: "cutting edges" }); >foo1({ name: "Edger", skill: "cutting edges" }) : void ->foo1 : ({ name }: Robot) => void +>foo1 : ({ name: nameA }: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" @@ -79,12 +79,12 @@ foo1({ name: "Edger", skill: "cutting edges" }); foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name, skill }: Robot) => void +>foo2 : ({ name: nameB, skill: skillB }: Robot) => void >robotA : Robot foo2({ name: "Edger", skill: "cutting edges" }); >foo2({ name: "Edger", skill: "cutting edges" }) : void ->foo2 : ({ name, skill }: Robot) => void +>foo2 : ({ name: nameB, skill: skillB }: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types index a7493bcd1dcb0..6f1712d272e25 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types @@ -26,7 +26,7 @@ var robotA: Robot = { name: "mower", skill: "mowing" }; >"mowing" : "mowing" function foo1({ name: nameA = "" }: Robot = { }) { ->foo1 : ({ name }?: Robot) => void +>foo1 : ({ name: nameA }?: Robot) => void >name : any >nameA : string >"" : "" @@ -40,7 +40,7 @@ function foo1({ name: nameA = "" }: Robot = { }) { >nameA : string } function foo2({ name: nameB = "", skill: skillB = "noSkill" }: Robot = {}) { ->foo2 : ({ name, skill }?: Robot) => void +>foo2 : ({ name: nameB, skill: skillB }?: Robot) => void >name : any >nameB : string >"" : "" @@ -72,12 +72,12 @@ function foo3({ name = "" }: Robot = {}) { foo1(robotA); >foo1(robotA) : void ->foo1 : ({ name }?: Robot) => void +>foo1 : ({ name: nameA }?: Robot) => void >robotA : Robot foo1({ name: "Edger", skill: "cutting edges" }); >foo1({ name: "Edger", skill: "cutting edges" }) : void ->foo1 : ({ name }?: Robot) => void +>foo1 : ({ name: nameA }?: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" @@ -86,12 +86,12 @@ foo1({ name: "Edger", skill: "cutting edges" }); foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name, skill }?: Robot) => void +>foo2 : ({ name: nameB, skill: skillB }?: Robot) => void >robotA : Robot foo2({ name: "Edger", skill: "cutting edges" }); >foo2({ name: "Edger", skill: "cutting edges" }) : void ->foo2 : ({ name, skill }?: Robot) => void +>foo2 : ({ name: nameB, skill: skillB }?: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types index 3dc640792e075..3f1ef83a0ae9c 100644 --- a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types +++ b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types @@ -13,7 +13,7 @@ import("package").then(({default: foo}) => foo(42)); >import("package") : Promise<{ default: (x: number) => string; }> >"package" : "package" >then : string; }, TResult2 = never>(onfulfilled?: (value: { default: (x: number) => string; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->({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 diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types index 2d48ccacf899c..d5429be5e488d 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types @@ -75,27 +75,27 @@ const c5 = Hello declare function TestingOneThing({y1: string}): JSX.Element; ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >y1 : any >string : any >JSX : any declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element; ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string;}): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string;}): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >j : { "extra-data": string; yy?: string; } >"extra-data" : string >yy : string >JSX : any declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element; ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number;}): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number;}): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >n : { yy: number; direction?: number; } >yy : number >direction : number >JSX : any declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string;}): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string;}): JSX.Element; } >n : { yy: string; name: string; } >yy : string >name : string @@ -105,27 +105,27 @@ declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; const d1 = ; >d1 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >y1 : true >extra-data : true const d2 = ; >d2 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string const d3 = ; >d3 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string >yy : string const d4 = ; >d4 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string >yy : number >9 : 9 @@ -135,7 +135,7 @@ const d4 = ; const d5 = ; >d5 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string >yy : string >name : string From 1e3dc2e3d79603cb74f7bb31139624d9e404a3c2 Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 00:50:47 +0900 Subject: [PATCH 15/31] extend tests --- ...tructuredPropertyInFunctionType.errors.txt | 34 ++- ...amingDestructuredPropertyInFunctionType.js | 47 +++- ...DestructuredPropertyInFunctionType.symbols | 228 ++++++++++++------ ...ngDestructuredPropertyInFunctionType.types | 72 ++++++ ...amingDestructuredPropertyInFunctionType.ts | 21 +- 5 files changed, 314 insertions(+), 88 deletions(-) diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index dbef15bf69d6c..3b8ade33b571d 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -1,19 +1,21 @@ -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(3,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(4,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(5,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(6,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(7,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(13,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(14,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(10,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(17,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,16): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,9): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(20,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(26,16): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(29,9): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(32,13): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? ==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (13 errors) ==== + // GH#37454, GH#41044 + type O = { a: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error @@ -70,4 +72,20 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,13): error new ({ a: string }): any; // Error ~~~~~~ !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? - } \ No newline at end of file + } + + // Below are OK but renaming should be removed from declaration emit + function f1({ a: string }: O) { } + const f2 = function({ a: string }: O) { }; + const f3 = ({ a: string, b, c }: O) => { }; + const f4 = function({ a: string }: O): typeof string { return string; }; + const f5 = ({ a: string, b, c }: O): typeof string => ''; + const obj1 = { + method({ a: string }: O) { } + }; + const obj2 = { + method({ a: string }: O): typeof string { return string; } + }; + + // In below case `string` should be kept because it is used + function f6({ a: string }: O): typeof string { return "a"; } \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js index 343a3dc49998c..4046aa54982da 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js @@ -1,4 +1,6 @@ //// [renamingDestructuredPropertyInFunctionType.ts] +// GH#37454, GH#41044 + type O = { a: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error @@ -29,9 +31,40 @@ interface I { new (arg: number): any; // OK new ({ a: string }): any; // Error -} +} + +// Below are OK but renaming should be removed from declaration emit +function f1({ a: string }: O) { } +const f2 = function({ a: string }: O) { }; +const f3 = ({ a: string, b, c }: O) => { }; +const f4 = function({ a: string }: O): typeof string { return string; }; +const f5 = ({ a: string, b, c }: O): typeof string => ''; +const obj1 = { + method({ a: string }: O) { } +}; +const obj2 = { + method({ a: string }: O): typeof string { return string; } +}; + +// In below case `string` should be kept because it is used +function f6({ a: string }: O): typeof string { return "a"; } //// [renamingDestructuredPropertyInFunctionType.js] +// GH#37454, GH#41044 +// Below are OK but renaming should be removed from declaration emit +function f1({ a: string }) { } +const f2 = function ({ a: string }) { }; +const f3 = ({ a: string, b, c }) => { }; +const f4 = function ({ a: string }) { return string; }; +const f5 = ({ a: string, b, c }) => ''; +const obj1 = { + method({ a: string }) { } +}; +const obj2 = { + method({ a: string }) { return string; } +}; +// In below case `string` should be kept because it is used +function f6({ a: string }) { return "a"; } //// [renamingDestructuredPropertyInFunctionType.d.ts] @@ -88,3 +121,15 @@ interface I { a: any; }): any; } +declare function f1({ a }: O): void; +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: string }: O): void; +}; +declare const obj2: { + method({ a: string }: O): string; +}; +declare function f6({ a: string }: O): typeof string; diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols index 0d70bfa20b74a..75fd8a11509bf 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols @@ -1,151 +1,223 @@ === tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === +// GH#37454, GH#41044 + type O = { a: string; b: number; c: number; }; >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 21)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 32)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 32)) type F1 = (arg: number) => any; // OK ->F1 : Symbol(F1, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 46)) ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 1, 11)) +>F1 : Symbol(F1, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 46)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 11)) type F2 = ({ a: string }: O) => any; // Error ->F2 : Symbol(F2, Decl(renamingDestructuredPropertyInFunctionType.ts, 1, 31)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 12)) +>F2 : Symbol(F2, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 31)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 12)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type F3 = ({ a: string, b, c }: O) => any; // Error ->F3 : Symbol(F3, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 36)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 23)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 26)) +>F3 : Symbol(F3, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 36)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 23)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 26)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type F4 = ({ a: string }: O) => any; // Error ->F4 : Symbol(F4, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 42)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 12)) +>F4 : Symbol(F4, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 42)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 12)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type F5 = ({ a: string, b, c }: O) => any; // Error ->F5 : Symbol(F5, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 36)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 23)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 26)) +>F5 : Symbol(F5, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 36)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 23)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 26)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type F6 = ({ a: string }) => typeof string; // OK ->F6 : Symbol(F6, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 42)) +>F6 : Symbol(F6, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 42)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 12)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12)) type F7 = ({ a: string, b: number }) => typeof number; // Error ->F7 : Symbol(F7, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 43)) +>F7 : Symbol(F7, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 43)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 12)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 23)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 23)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 23)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 23)) type F8 = ({ a, b: number }) => typeof number; // OK ->F8 : Symbol(F8, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 54)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12)) +>F8 : Symbol(F8, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 54)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 12)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 15)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 15)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 15)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 15)) type F9 = ([a, b, c]) => void; // Error ->F9 : Symbol(F9, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 46)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 14)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 17)) +>F9 : Symbol(F9, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 46)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 14)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 17)) type G1 = (arg: number) => any; // OK ->G1 : Symbol(G1, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 30)) ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 11)) +>G1 : Symbol(G1, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 30)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 11)) type G2 = ({ a: string }: O) => any; // Error ->G2 : Symbol(G2, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 31)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 12)) +>G2 : Symbol(G2, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 31)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 12)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G3 = ({ a: string, b, c }: O) => any; // Error ->G3 : Symbol(G3, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 36)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 23)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 26)) +>G3 : Symbol(G3, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 36)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 23)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 26)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G4 = ({ a: string }: O) => any; // Error ->G4 : Symbol(G4, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 42)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 12)) +>G4 : Symbol(G4, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 42)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 12)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G5 = ({ a: string, b, c }: O) => any; // Error ->G5 : Symbol(G5, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 36)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 23)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 26)) +>G5 : Symbol(G5, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 36)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 23)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 26)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G6 = ({ a: string }) => typeof string; // OK ->G6 : Symbol(G6, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 42)) +>G6 : Symbol(G6, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 42)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 12)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 12)) type G7 = ({ a: string, b: number }) => typeof number; // Error ->G7 : Symbol(G7, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 43)) +>G7 : Symbol(G7, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 43)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 12)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 23)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 23)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 23)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 23)) type G8 = ({ a, b: number }) => typeof number; // OK ->G8 : Symbol(G8, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 54)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 12)) +>G8 : Symbol(G8, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 54)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 12)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 15)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 15)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 15)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 15)) type G9 = ([a, b, c]) => void; // Error ->G9 : Symbol(G9, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 46)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 14)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 17)) +>G9 : Symbol(G9, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 46)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 14)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 17)) interface I { ->I : Symbol(I, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 30)) +>I : Symbol(I, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 30)) method1(arg: number): any; // OK ->method1 : Symbol(I.method1, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 13)) ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 10)) +>method1 : Symbol(I.method1, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 13)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 10)) method2({ a: string }): any; // Error ->method2 : Symbol(I.method2, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 28)) +>method2 : Symbol(I.method2, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 28)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 11)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 11)) (arg: number): any; // OK ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 3)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 3)) ({ a: string }): any; // Error >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 4)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 4)) new (arg: number): any; // OK ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 7)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 30, 7)) new ({ a: string }): any; // Error >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 8)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 8)) } + +// Below are OK but renaming should be removed from declaration emit +function f1({ a: string }: O) { } +>f1 : Symbol(f1, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 1)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 35, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +const f2 = function({ a: string }: O) { }; +>f2 : Symbol(f2, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 21)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +const f3 = ({ a: string, b, c }: O) => { }; +>f3 : Symbol(f3, Decl(renamingDestructuredPropertyInFunctionType.ts, 37, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 37, 13)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 37, 24)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 37, 27)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +const f4 = function({ a: string }: O): typeof string { return string; }; +>f4 : Symbol(f4, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 21)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 21)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 21)) + +const f5 = ({ a: string, b, c }: O): typeof string => ''; +>f5 : Symbol(f5, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 13)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 24)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 27)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 13)) + +const obj1 = { +>obj1 : Symbol(obj1, Decl(renamingDestructuredPropertyInFunctionType.ts, 40, 5)) + + method({ a: string }: O) { } +>method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 40, 14)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 41, 10)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +}; +const obj2 = { +>obj2 : Symbol(obj2, Decl(renamingDestructuredPropertyInFunctionType.ts, 43, 5)) + + method({ a: string }: O): typeof string { return string; } +>method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 43, 14)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 10)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 10)) + +}; + +// In below case `string` should be kept because it is used +function f6({ a: string }: O): typeof string { return "a"; } +>f6 : Symbol(f6, Decl(renamingDestructuredPropertyInFunctionType.ts, 45, 2)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 13)) + diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types index 8484932a1f109..90979cb5fad32 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types @@ -1,4 +1,6 @@ === tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === +// GH#37454, GH#41044 + type O = { a: string; b: number; c: number; }; >O : { a: string; b: number; c: number; } >a : string @@ -139,3 +141,73 @@ interface I { >a : any >string : any } + +// Below are OK but renaming should be removed from declaration emit +function f1({ a: string }: O) { } +>f1 : ({ a: string }: O) => void +>a : any +>string : string + +const f2 = function({ a: string }: O) { }; +>f2 : ({ a: string }: O) => void +>function({ a: string }: O) { } : ({ a: string }: O) => void +>a : any +>string : string + +const f3 = ({ a: string, b, c }: O) => { }; +>f3 : ({ a: string, b, c }: O) => void +>({ a: string, b, c }: O) => { } : ({ a: string, b, c }: O) => void +>a : any +>string : string +>b : number +>c : number + +const f4 = function({ a: string }: O): typeof string { return string; }; +>f4 : ({ a: string }: O) => string +>function({ a: string }: O): typeof string { return string; } : ({ a: string }: O) => string +>a : any +>string : string +>string : string +>string : string + +const f5 = ({ a: string, b, c }: O): typeof string => ''; +>f5 : ({ a: string, b, c }: O) => string +>({ a: string, b, c }: O): typeof string => '' : ({ a: string, b, c }: O) => string +>a : any +>string : string +>b : number +>c : number +>string : string +>'' : "" + +const obj1 = { +>obj1 : { method({ a: string }: O): void; } +>{ method({ a: string }: O) { }} : { method({ a: string }: O): void; } + + method({ a: string }: O) { } +>method : ({ a: string }: O) => void +>a : any +>string : string + +}; +const obj2 = { +>obj2 : { method({ a: string }: O): string; } +>{ method({ a: string }: O): typeof string { return string; }} : { method({ a: string }: O): string; } + + method({ a: string }: O): typeof string { return string; } +>method : ({ a: string }: O) => string +>a : any +>string : string +>string : string +>string : string + +}; + +// In below case `string` should be kept because it is used +function f6({ a: string }: O): typeof string { return "a"; } +>f6 : ({ a: string }: O) => typeof string +>a : any +>string : string +>string : string +>"a" : "a" + diff --git a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts index 1fe6b480c3c9e..c6a7baf1c1006 100644 --- a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts +++ b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts @@ -1,4 +1,7 @@ +// @target: es2015 // @declaration: true +// GH#37454, GH#41044 + type O = { a: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error @@ -29,4 +32,20 @@ interface I { new (arg: number): any; // OK new ({ a: string }): any; // Error -} \ No newline at end of file +} + +// Below are OK but renaming should be removed from declaration emit +function f1({ a: string }: O) { } +const f2 = function({ a: string }: O) { }; +const f3 = ({ a: string, b, c }: O) => { }; +const f4 = function({ a: string }: O): typeof string { return string; }; +const f5 = ({ a: string, b, c }: O): typeof string => ''; +const obj1 = { + method({ a: string }: O) { } +}; +const obj2 = { + method({ a: string }: O): typeof string { return string; } +}; + +// In below case `string` should be kept because it is used +function f6({ a: string }: O): typeof string { return "a"; } \ No newline at end of file From 32c340ee4d2a48bb536ba642c7586400e83dc94d Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 01:37:35 +0900 Subject: [PATCH 16/31] Revert "revert unnecessary change" This reverts commit 17a29fff6c4ce48e9c3f13b55332ce3411c90dc4. --- src/compiler/checker.ts | 28 +++++++++++------ ...ngDestructuredPropertyInFunctionType.types | 30 +++++++++---------- ...gDestructuredPropertyInFunctionType2.types | 30 +++++++++---------- 3 files changed, 49 insertions(+), 39 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 109b1bfecf4a4..31d5f2da97fdb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5969,19 +5969,29 @@ namespace ts { return parameterNode; function cloneBindingName(node: BindingName): BindingName { - return elideInitializerAndSetEmitFlags(node) as BindingName; - function elideInitializerAndSetEmitFlags(node: Node): Node { + return elideInitializerAndPropertyRenamingAndSetEmitFlags(node) as BindingName; + function elideInitializerAndPropertyRenamingAndSetEmitFlags(node: Node): Node { if (context.tracker.trackSymbol && isComputedPropertyName(node) && isLateBindableName(node)) { trackComputedName(node.expression, context.enclosingDeclaration, context); } - let visited = visitEachChild(node, elideInitializerAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags)!; + let visited = visitEachChild(node, elideInitializerAndPropertyRenamingAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndPropertyRenamingAndSetEmitFlags)!; if (isBindingElement(visited)) { - visited = factory.updateBindingElement( - visited, - visited.dotDotDotToken, - visited.propertyName, - visited.name, - /*initializer*/ undefined); + if (visited.propertyName && isIdentifier(visited.propertyName) && isIdentifier(visited.name)) { + 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); + } } if (!nodeIsSynthesized(visited)) { visited = factory.cloneNode(visited); diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types index 90979cb5fad32..6fdd3af2f9edc 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types @@ -12,37 +12,37 @@ type F1 = (arg: number) => any; // OK >arg : number type F2 = ({ a: string }: O) => any; // Error ->F2 : ({ a: string }: O) => any +>F2 : ({ a }: O) => any >a : any >string : string type F3 = ({ a: string, b, c }: O) => any; // Error ->F3 : ({ a: string, b, c }: O) => any +>F3 : ({ a, b, c }: O) => any >a : any >string : string >b : number >c : number type F4 = ({ a: string }: O) => any; // Error ->F4 : ({ a: string }: O) => any +>F4 : ({ a }: O) => any >a : any >string : string type F5 = ({ a: string, b, c }: O) => any; // Error ->F5 : ({ a: string, b, c }: O) => any +>F5 : ({ a, b, c }: O) => any >a : any >string : string >b : number >c : number type F6 = ({ a: string }) => typeof string; // OK ->F6 : ({ a: string }: { a: any; }) => any +>F6 : ({ a }: { a: any; }) => any >a : any >string : any >string : any type F7 = ({ a: string, b: number }) => typeof number; // Error ->F7 : ({ a: string, b: number }: { a: any; b: any; }) => any +>F7 : ({ a, b }: { a: any; b: any; }) => any >a : any >string : any >b : any @@ -50,7 +50,7 @@ type F7 = ({ a: string, b: number }) => typeof number; // Error >number : any type F8 = ({ a, b: number }) => typeof number; // OK ->F8 : ({ a, b: number }: { a: any; b: any; }) => any +>F8 : ({ a, b }: { a: any; b: any; }) => any >a : any >b : any >number : any @@ -67,37 +67,37 @@ type G1 = (arg: number) => any; // OK >arg : number type G2 = ({ a: string }: O) => any; // Error ->G2 : ({ a: string }: O) => any +>G2 : ({ a }: O) => any >a : any >string : string type G3 = ({ a: string, b, c }: O) => any; // Error ->G3 : ({ a: string, b, c }: O) => any +>G3 : ({ a, b, c }: O) => any >a : any >string : string >b : number >c : number type G4 = ({ a: string }: O) => any; // Error ->G4 : ({ a: string }: O) => any +>G4 : ({ a }: O) => any >a : any >string : string type G5 = ({ a: string, b, c }: O) => any; // Error ->G5 : ({ a: string, b, c }: O) => any +>G5 : ({ a, b, c }: O) => any >a : any >string : string >b : number >c : number type G6 = ({ a: string }) => typeof string; // OK ->G6 : ({ a: string }: { a: any; }) => any +>G6 : ({ a }: { a: any; }) => any >a : any >string : any >string : any type G7 = ({ a: string, b: number }) => typeof number; // Error ->G7 : ({ a: string, b: number }: { a: any; b: any; }) => any +>G7 : ({ a, b }: { a: any; b: any; }) => any >a : any >string : any >b : any @@ -105,7 +105,7 @@ type G7 = ({ a: string, b: number }) => typeof number; // Error >number : any type G8 = ({ a, b: number }) => typeof number; // OK ->G8 : ({ a, b: number }: { a: any; b: any; }) => any +>G8 : ({ a, b }: { a: any; b: any; }) => any >a : any >b : any >number : any @@ -123,7 +123,7 @@ interface I { >arg : number method2({ a: string }): any; // Error ->method2 : ({ a: string }: { a: any; }) => any +>method2 : ({ a }: { a: any; }) => any >a : any >string : any diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types index 615d9de9145c5..237a2ac364150 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType2.types @@ -10,37 +10,37 @@ type F1 = (arg: number) => any; >arg : number type F2 = ({ a: string }: O) => any; ->F2 : ({ a: string }: O) => any +>F2 : ({ a }: O) => any >a : any >string : string type F3 = ({ a: string, b, c }: O) => any; ->F3 : ({ a: string, b, c }: O) => any +>F3 : ({ a, b, c }: O) => any >a : any >string : string >b : number >c : number type F4 = ({ a: string }: O) => any; ->F4 : ({ a: string }: O) => any +>F4 : ({ a }: O) => any >a : any >string : string type F5 = ({ a: string, b, c }: O) => any; ->F5 : ({ a: string, b, c }: O) => any +>F5 : ({ a, b, c }: O) => any >a : any >string : string >b : number >c : number type F6 = ({ a: string }) => typeof string; ->F6 : ({ a: string }: { a: any; }) => any +>F6 : ({ a }: { a: any; }) => any >a : any >string : any >string : any type F7 = ({ a: string, b: number }) => typeof number; ->F7 : ({ a: string, b: number }: { a: any; b: any; }) => any +>F7 : ({ a, b }: { a: any; b: any; }) => any >a : any >string : any >b : any @@ -48,7 +48,7 @@ type F7 = ({ a: string, b: number }) => typeof number; >number : any type F8 = ({ a, b: number }) => typeof number; ->F8 : ({ a, b: number }: { a: any; b: any; }) => any +>F8 : ({ a, b }: { a: any; b: any; }) => any >a : any >b : any >number : any @@ -65,37 +65,37 @@ type G1 = (arg: number) => any; >arg : number type G2 = ({ a: string }: O) => any; ->G2 : ({ a: string }: O) => any +>G2 : ({ a }: O) => any >a : any >string : string type G3 = ({ a: string, b, c }: O) => any; ->G3 : ({ a: string, b, c }: O) => any +>G3 : ({ a, b, c }: O) => any >a : any >string : string >b : number >c : number type G4 = ({ a: string }: O) => any; ->G4 : ({ a: string }: O) => any +>G4 : ({ a }: O) => any >a : any >string : string type G5 = ({ a: string, b, c }: O) => any; ->G5 : ({ a: string, b, c }: O) => any +>G5 : ({ a, b, c }: O) => any >a : any >string : string >b : number >c : number type G6 = ({ a: string }) => typeof string; ->G6 : ({ a: string }: { a: any; }) => any +>G6 : ({ a }: { a: any; }) => any >a : any >string : any >string : any type G7 = ({ a: string, b: number }) => typeof number; ->G7 : ({ a: string, b: number }: { a: any; b: any; }) => any +>G7 : ({ a, b }: { a: any; b: any; }) => any >a : any >string : any >b : any @@ -103,7 +103,7 @@ type G7 = ({ a: string, b: number }) => typeof number; >number : any type G8 = ({ a, b: number }) => typeof number; ->G8 : ({ a, b: number }: { a: any; b: any; }) => any +>G8 : ({ a, b }: { a: any; b: any; }) => any >a : any >b : any >number : any @@ -121,7 +121,7 @@ interface I { >arg : number method2({ a: string }): any; ->method2 : ({ a: string }: { a: any; }) => any +>method2 : ({ a }: { a: any; }) => any >a : any >string : any From 9c9fe5edc5a09f14f1c74c4f0e51a29c0b43ea2f Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 01:56:37 +0900 Subject: [PATCH 17/31] accept baseline --- ...uallyTypedBindingInitializerNegative.types | 4 +- .../declarationEmitBindingPatterns.js | 2 +- .../declarationEmitBindingPatterns.types | 4 +- .../declarationsAndAssignments.types | 8 +-- .../destructuringInFunctionType.types | 2 +- ...estructuringParameterDeclaration1ES5.types | 2 +- ...ringParameterDeclaration1ES5iterable.types | 2 +- ...estructuringParameterDeclaration1ES6.types | 2 +- .../destructuringParameterDeclaration6.types | 12 ++--- .../excessPropertyCheckWithSpread.types | 6 +-- .../reference/objectRestParameter.types | 2 +- .../reference/objectRestParameterES5.types | 2 +- ...tructuredPropertyInFunctionType.errors.txt | 6 ++- ...amingDestructuredPropertyInFunctionType.js | 28 ++++++---- ...DestructuredPropertyInFunctionType.symbols | 29 +++++++--- ...ngDestructuredPropertyInFunctionType.types | 53 ++++++++++++------- ...gParameterNestedObjectBindingPattern.types | 12 ++--- ...tedObjectBindingPatternDefaultValues.types | 12 ++--- ...cturingParameterObjectBindingPattern.types | 12 ++--- ...terObjectBindingPatternDefaultValues.types | 12 ++--- ...eticDefaultExportsWithDynamicImports.types | 2 +- ...xStatelessFunctionComponentOverload1.types | 18 +++---- ...amingDestructuredPropertyInFunctionType.ts | 6 ++- 23 files changed, 138 insertions(+), 100 deletions(-) diff --git a/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types b/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types index 56ad56f21e577..6d64e3b7675cf 100644 --- a/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types +++ b/tests/baselines/reference/contextuallyTypedBindingInitializerNegative.types @@ -5,7 +5,7 @@ interface Show { >x : number } function f({ show: showRename = v => v }: Show) {} ->f : ({ show: showRename }: Show) => void +>f : ({ show }: 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: nestedRename }: Nested) => void +>ff : ({ nested }: Nested) => void >nested : any >nestedRename : Show >{ show: v => v } : { show: (v: number) => number; } diff --git a/tests/baselines/reference/declarationEmitBindingPatterns.js b/tests/baselines/reference/declarationEmitBindingPatterns.js index 5581c06ebe67f..31114071a291e 100644 --- a/tests/baselines/reference/declarationEmitBindingPatterns.js +++ b/tests/baselines/reference/declarationEmitBindingPatterns.js @@ -18,7 +18,7 @@ function f(_a, _b, _c) { //// [declarationEmitBindingPatterns.d.ts] -declare const k: ({ x: z }: { +declare const k: ({ x }: { x?: string; }) => void; declare var a: any; diff --git a/tests/baselines/reference/declarationEmitBindingPatterns.types b/tests/baselines/reference/declarationEmitBindingPatterns.types index d49893dad94fa..151991e3039fb 100644 --- a/tests/baselines/reference/declarationEmitBindingPatterns.types +++ b/tests/baselines/reference/declarationEmitBindingPatterns.types @@ -1,7 +1,7 @@ === tests/cases/compiler/declarationEmitBindingPatterns.ts === const k = ({x: z = 'y'}) => { } ->k : ({ x: z }: { x?: string; }) => void ->({x: z = 'y'}) => { } : ({ x: z }: { x?: string; }) => void +>k : ({ x }: { x?: string; }) => void +>({x: z = 'y'}) => { } : ({ x }: { x?: string; }) => void >x : any >z : string >'y' : "y" diff --git a/tests/baselines/reference/declarationsAndAssignments.types b/tests/baselines/reference/declarationsAndAssignments.types index a7b72a6809424..a3caaa9f6bd84 100644 --- a/tests/baselines/reference/declarationsAndAssignments.types +++ b/tests/baselines/reference/declarationsAndAssignments.types @@ -417,7 +417,7 @@ function f13() { } function f14([a = 1, [b = "hello", { x, y: c = false }]]) { ->f14 : ([a, [b, { x, y: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void +>f14 : ([a, [b, { x, y }]]: [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: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void +>f14 : ([a, [b, { x, y }]]: [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: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void +>f14 : ([a, [b, { x, y }]]: [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: c }]]: [number, [string, { x: any; y?: boolean; }]]) => void +>f14 : ([a, [b, { x, y }]]: [number, [string, { x: any; y?: boolean; }]]) => void >[2, ["abc", { y: false }]] : [number, [string, { y: false; }]] >2 : 2 >["abc", { y: false }] : [string, { y: false; }] diff --git a/tests/baselines/reference/destructuringInFunctionType.types b/tests/baselines/reference/destructuringInFunctionType.types index 2b7f0de66ccf7..553fdaa9cf3b0 100644 --- a/tests/baselines/reference/destructuringInFunctionType.types +++ b/tests/baselines/reference/destructuringInFunctionType.types @@ -31,7 +31,7 @@ type T3 = ([{ a: b }, { b: a }]); >b : a type F3 = ([{ a: b }, { b: a }]) => void; ->F3 : ([{ a: b }, { b: a }]: [{ a: any; }, { b: any; }]) => void +>F3 : ([{ a }, { b }]: [{ a: any; }, { b: any; }]) => void >a : any >b : any >b : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5.types b/tests/baselines/reference/destructuringParameterDeclaration1ES5.types index cea8e2a231b2c..381c486a5461d 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5.types @@ -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: number }: { x: any; }) => void +>e1 : ({ x }: { x: any; }) => void >x : any >number : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types index 4fee7254d2bfa..aec020bcc2870 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5iterable.types @@ -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: number }: { x: any; }) => void +>e1 : ({ x }: { x: any; }) => void >x : any >number : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types index cee129da47534..acf5dcffb5ce2 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types @@ -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: number }: { x: any; }) => void +>e1 : ({ x }: { x: any; }) => void >x : any >number : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration6.types b/tests/baselines/reference/destructuringParameterDeclaration6.types index d135f9cb8fdbf..6b5085d21219c 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration6.types @@ -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: x }: { public: any; }) => void +>b1 : ({ public }: { public: any; }) => void >public : any >x : any function b2({while: y}) { } ->b2 : ({ while: y }: { while: any; }) => void +>b2 : ({ while }: { while: any; }) => void >while : any >y : any b1({ public: 1 }); >b1({ public: 1 }) : void ->b1 : ({ public: x }: { public: any; }) => void +>b1 : ({ public }: { public: any; }) => void >{ public: 1 } : { public: number; } >public : number >1 : 1 b2({ while: 1 }); >b2({ while: 1 }) : void ->b2 : ({ while: y }: { while: any; }) => void +>b2 : ({ while }: { while: any; }) => void >{ while: 1 } : { while: number; } >while : number >1 : 1 diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.types b/tests/baselines/reference/excessPropertyCheckWithSpread.types index 460f43d2289f4..de5385d0b33e0 100644 --- a/tests/baselines/reference/excessPropertyCheckWithSpread.types +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.types @@ -1,6 +1,6 @@ === tests/cases/compiler/excessPropertyCheckWithSpread.ts === declare function f({ a: number }): void ->f : ({ a: number }: { a: any; }) => void +>f : ({ a }: { 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: number }: { a: any; }) => void +>f : ({ a }: { 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: number }: { a: any; }) => void +>f : ({ a }: { a: any; }) => void >{ a: 1, ...l, ...r } : { opt: string | number; a: number; } >a : number >1 : 1 diff --git a/tests/baselines/reference/objectRestParameter.types b/tests/baselines/reference/objectRestParameter.types index 71047deea43fe..668214c495f1f 100644 --- a/tests/baselines/reference/objectRestParameter.types +++ b/tests/baselines/reference/objectRestParameter.types @@ -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: a, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string +>({ x: a, ...rest }) => rest.y : ({ x, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string >x : any >a : { z: any; ka: any; } >rest : { y: string; } diff --git a/tests/baselines/reference/objectRestParameterES5.types b/tests/baselines/reference/objectRestParameterES5.types index 74df68093aa45..d88da6a249433 100644 --- a/tests/baselines/reference/objectRestParameterES5.types +++ b/tests/baselines/reference/objectRestParameterES5.types @@ -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: a, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string +>({ x: a, ...rest }) => rest.y : ({ x, ...rest }: { x: { z: any; ka: any; }; y: string; }) => string >x : any >a : { z: any; ka: any; } >rest : { y: string; } diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index 3b8ade33b571d..087dd06386b4c 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -16,7 +16,7 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(32,13): error ==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (13 errors) ==== // GH#37454, GH#41044 - type O = { a: string; b: number; c: number; }; + type O = { a?: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error ~~~~~~ @@ -86,6 +86,8 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(32,13): error const obj2 = { method({ a: string }: O): typeof string { return string; } }; + function f6({ a: string = "" }: O) { } + const f7 = ({ a: string = "", b, c }: O) => { }; // In below case `string` should be kept because it is used - function f6({ a: string }: O): typeof string { return "a"; } \ No newline at end of file + function f8({ a: string = "" }: O): typeof string { return "a"; } \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js index 4046aa54982da..ed605a856f488 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js @@ -1,7 +1,7 @@ //// [renamingDestructuredPropertyInFunctionType.ts] // GH#37454, GH#41044 -type O = { a: string; b: number; c: number; }; +type O = { a?: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error type F3 = ({ a: string, b, c }: O) => any; // Error @@ -45,9 +45,11 @@ const obj1 = { const obj2 = { method({ a: string }: O): typeof string { return string; } }; +function f6({ a: string = "" }: O) { } +const f7 = ({ a: string = "", b, c }: O) => { }; // In below case `string` should be kept because it is used -function f6({ a: string }: O): typeof string { return "a"; } +function f8({ a: string = "" }: O): typeof string { return "a"; } //// [renamingDestructuredPropertyInFunctionType.js] // GH#37454, GH#41044 @@ -63,13 +65,15 @@ const obj1 = { const obj2 = { method({ a: string }) { return string; } }; +function f6({ a: string = "" }) { } +const f7 = ({ a: string = "", b, c }) => { }; // In below case `string` should be kept because it is used -function f6({ a: string }) { return "a"; } +function f8({ a: string = "" }) { return "a"; } //// [renamingDestructuredPropertyInFunctionType.d.ts] declare type O = { - a: string; + a?: string; b: number; c: number; }; @@ -122,14 +126,16 @@ interface I { }): any; } declare function f1({ a }: O): void; -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 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 obj1: { - method({ a: string }: O): void; + method({ a }: O): void; }; declare const obj2: { - method({ a: string }: O): string; + method({ a }: O): string; }; -declare function f6({ a: string }: O): typeof string; +declare function f6({ a }: O): void; +declare const f7: ({ a, b, c }: O) => void; +declare function f8({ a: string }: O): typeof string; diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols index 75fd8a11509bf..f365b6aa024ee 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols @@ -1,14 +1,14 @@ === tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === // GH#37454, GH#41044 -type O = { a: string; b: number; c: number; }; +type O = { a?: string; b: number; c: number; }; >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 32)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 22)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 33)) type F1 = (arg: number) => any; // OK ->F1 : Symbol(F1, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 46)) +>F1 : Symbol(F1, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 47)) >arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 11)) type F2 = ({ a: string }: O) => any; // Error @@ -212,12 +212,25 @@ const obj2 = { >string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 10)) }; +function f6({ a: string = "" }: O) { } +>f6 : Symbol(f6, Decl(renamingDestructuredPropertyInFunctionType.ts, 45, 2)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +const f7 = ({ a: string = "", b, c }: O) => { }; +>f7 : Symbol(f7, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 13)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 29)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 32)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) // In below case `string` should be kept because it is used -function f6({ a: string }: O): typeof string { return "a"; } ->f6 : Symbol(f6, Decl(renamingDestructuredPropertyInFunctionType.ts, 45, 2)) +function f8({ a: string = "" }: O): typeof string { return "a"; } +>f8 : Symbol(f8, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 48)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 13)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 13)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 13)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 13)) diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types index 6fdd3af2f9edc..331697bf8fadc 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types @@ -1,8 +1,8 @@ === tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === // GH#37454, GH#41044 -type O = { a: string; b: number; c: number; }; ->O : { a: string; b: number; c: number; } +type O = { a?: string; b: number; c: number; }; +>O : { a?: string; b: number; c: number; } >a : string >b : number >c : number @@ -144,35 +144,35 @@ interface I { // Below are OK but renaming should be removed from declaration emit function f1({ a: string }: O) { } ->f1 : ({ a: string }: O) => void +>f1 : ({ a }: O) => void >a : any >string : string const f2 = function({ a: string }: O) { }; ->f2 : ({ a: string }: O) => void ->function({ a: string }: O) { } : ({ a: string }: O) => void +>f2 : ({ a }: O) => void +>function({ a: string }: O) { } : ({ a }: O) => void >a : any >string : string const f3 = ({ a: string, b, c }: O) => { }; ->f3 : ({ a: string, b, c }: O) => void ->({ a: string, b, c }: O) => { } : ({ a: string, b, c }: O) => void +>f3 : ({ a, b, c }: O) => void +>({ a: string, b, c }: O) => { } : ({ a, b, c }: O) => void >a : any >string : string >b : number >c : number const f4 = function({ a: string }: O): typeof string { return string; }; ->f4 : ({ a: string }: O) => string ->function({ a: string }: O): typeof string { return string; } : ({ a: string }: O) => string +>f4 : ({ a }: O) => string +>function({ a: string }: O): typeof string { return string; } : ({ a }: O) => string >a : any >string : string >string : string >string : string const f5 = ({ a: string, b, c }: O): typeof string => ''; ->f5 : ({ a: string, b, c }: O) => string ->({ a: string, b, c }: O): typeof string => '' : ({ a: string, b, c }: O) => string +>f5 : ({ a, b, c }: O) => string +>({ a: string, b, c }: O): typeof string => '' : ({ a, b, c }: O) => string >a : any >string : string >b : number @@ -181,33 +181,48 @@ const f5 = ({ a: string, b, c }: O): typeof string => ''; >'' : "" const obj1 = { ->obj1 : { method({ a: string }: O): void; } ->{ method({ a: string }: O) { }} : { method({ a: string }: O): void; } +>obj1 : { method({ a }: O): void; } +>{ method({ a: string }: O) { }} : { method({ a }: O): void; } method({ a: string }: O) { } ->method : ({ a: string }: O) => void +>method : ({ a }: O) => void >a : any >string : string }; const obj2 = { ->obj2 : { method({ a: string }: O): string; } ->{ method({ a: string }: O): typeof string { return string; }} : { method({ a: string }: O): string; } +>obj2 : { method({ a }: O): string; } +>{ method({ a: string }: O): typeof string { return string; }} : { method({ a }: O): string; } method({ a: string }: O): typeof string { return string; } ->method : ({ a: string }: O) => string +>method : ({ a }: O) => string >a : any >string : string >string : string >string : string }; +function f6({ a: string = "" }: O) { } +>f6 : ({ a }: O) => void +>a : any +>string : string +>"" : "" + +const f7 = ({ a: string = "", b, c }: O) => { }; +>f7 : ({ a, b, c }: O) => void +>({ a: string = "", b, c }: O) => { } : ({ a, b, c }: O) => void +>a : any +>string : string +>"" : "" +>b : number +>c : number // In below case `string` should be kept because it is used -function f6({ a: string }: O): typeof string { return "a"; } ->f6 : ({ a: string }: O) => typeof string +function f8({ a: string = "" }: O): typeof string { return "a"; } +>f8 : ({ a }: O) => typeof string >a : any >string : string +>"" : "" >string : string >"a" : "a" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types index 287f0c41d2587..dcabaa3bf785d 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPattern.types @@ -34,7 +34,7 @@ var robotA: Robot = { name: "mower", skills: { primary: "mowing", secondary: "no >"none" : "none" function foo1({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) { ->foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void +>foo1 : ({ skills: { primary, secondary } }: Robot) => void >skills : any >primary : any >primaryA : string @@ -49,7 +49,7 @@ function foo1({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) { >primaryA : string } function foo2({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) { ->foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void +>foo2 : ({ name, skills: { primary, secondary } }: Robot) => void >name : any >nameC : string >skills : any @@ -81,12 +81,12 @@ function foo3({ skills }: Robot) { foo1(robotA); >foo1(robotA) : void ->foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void +>foo1 : ({ skills: { primary, secondary } }: Robot) => void >robotA : Robot foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }: Robot) => void +>foo1 : ({ skills: { primary, secondary } }: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" @@ -99,12 +99,12 @@ foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void +>foo2 : ({ name, skills: { primary, secondary } }: Robot) => void >robotA : Robot foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }: Robot) => void +>foo2 : ({ name, skills: { primary, secondary } }: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types index 8bfc93c3db70b..9082abff9dfb4 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterNestedObjectBindingPatternDefaultValues.types @@ -34,7 +34,7 @@ var robotA: Robot = { name: "mower", skills: { primary: "mowing", secondary: "no >"none" : "none" function foo1( ->foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void +>foo1 : ({ skills: { primary, secondary } }?: Robot) => void { skills: { >skills : any @@ -67,7 +67,7 @@ function foo1( >primaryA : string } function foo2( ->foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void +>foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void { name: nameC = "name", >name : any @@ -126,12 +126,12 @@ function foo3({ skills = { primary: "SomeSkill", secondary: "someSkill" } }: Ro foo1(robotA); >foo1(robotA) : void ->foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void +>foo1 : ({ skills: { primary, secondary } }?: Robot) => void >robotA : Robot foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo1 : ({ skills: { primary: primaryA, secondary: secondaryA } }?: Robot) => void +>foo1 : ({ skills: { primary, secondary } }?: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" @@ -144,12 +144,12 @@ foo1({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void +>foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void >robotA : Robot foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }); >foo2({ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } }) : void ->foo2 : ({ name: nameC, skills: { primary: primaryB, secondary: secondaryB } }?: Robot) => void +>foo2 : ({ name, skills: { primary, secondary } }?: Robot) => void >{ name: "Edger", skills: { primary: "edging", secondary: "branch trimming" } } : { name: string; skills: { primary: string; secondary: string; }; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types index 05a01de79ac9b..a02d95a9939b9 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPattern.types @@ -26,7 +26,7 @@ var robotA: Robot = { name: "mower", skill: "mowing" }; >"mowing" : "mowing" function foo1({ name: nameA }: Robot) { ->foo1 : ({ name: nameA }: Robot) => void +>foo1 : ({ name }: Robot) => void >name : any >nameA : string @@ -38,7 +38,7 @@ function foo1({ name: nameA }: Robot) { >nameA : string } function foo2({ name: nameB, skill: skillB }: Robot) { ->foo2 : ({ name: nameB, skill: skillB }: Robot) => void +>foo2 : ({ name, skill }: Robot) => void >name : any >nameB : string >skill : any @@ -65,12 +65,12 @@ function foo3({ name }: Robot) { foo1(robotA); >foo1(robotA) : void ->foo1 : ({ name: nameA }: Robot) => void +>foo1 : ({ name }: Robot) => void >robotA : Robot foo1({ name: "Edger", skill: "cutting edges" }); >foo1({ name: "Edger", skill: "cutting edges" }) : void ->foo1 : ({ name: nameA }: Robot) => void +>foo1 : ({ name }: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" @@ -79,12 +79,12 @@ foo1({ name: "Edger", skill: "cutting edges" }); foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name: nameB, skill: skillB }: Robot) => void +>foo2 : ({ name, skill }: Robot) => void >robotA : Robot foo2({ name: "Edger", skill: "cutting edges" }); >foo2({ name: "Edger", skill: "cutting edges" }) : void ->foo2 : ({ name: nameB, skill: skillB }: Robot) => void +>foo2 : ({ name, skill }: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types index 6f1712d272e25..a7493bcd1dcb0 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParameterObjectBindingPatternDefaultValues.types @@ -26,7 +26,7 @@ var robotA: Robot = { name: "mower", skill: "mowing" }; >"mowing" : "mowing" function foo1({ name: nameA = "" }: Robot = { }) { ->foo1 : ({ name: nameA }?: Robot) => void +>foo1 : ({ name }?: Robot) => void >name : any >nameA : string >"" : "" @@ -40,7 +40,7 @@ function foo1({ name: nameA = "" }: Robot = { }) { >nameA : string } function foo2({ name: nameB = "", skill: skillB = "noSkill" }: Robot = {}) { ->foo2 : ({ name: nameB, skill: skillB }?: Robot) => void +>foo2 : ({ name, skill }?: Robot) => void >name : any >nameB : string >"" : "" @@ -72,12 +72,12 @@ function foo3({ name = "" }: Robot = {}) { foo1(robotA); >foo1(robotA) : void ->foo1 : ({ name: nameA }?: Robot) => void +>foo1 : ({ name }?: Robot) => void >robotA : Robot foo1({ name: "Edger", skill: "cutting edges" }); >foo1({ name: "Edger", skill: "cutting edges" }) : void ->foo1 : ({ name: nameA }?: Robot) => void +>foo1 : ({ name }?: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" @@ -86,12 +86,12 @@ foo1({ name: "Edger", skill: "cutting edges" }); foo2(robotA); >foo2(robotA) : void ->foo2 : ({ name: nameB, skill: skillB }?: Robot) => void +>foo2 : ({ name, skill }?: Robot) => void >robotA : Robot foo2({ name: "Edger", skill: "cutting edges" }); >foo2({ name: "Edger", skill: "cutting edges" }) : void ->foo2 : ({ name: nameB, skill: skillB }?: Robot) => void +>foo2 : ({ name, skill }?: Robot) => void >{ name: "Edger", skill: "cutting edges" } : { name: string; skill: string; } >name : string >"Edger" : "Edger" diff --git a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types index 3f1ef83a0ae9c..3dc640792e075 100644 --- a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types +++ b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types @@ -13,7 +13,7 @@ import("package").then(({default: foo}) => foo(42)); >import("package") : Promise<{ default: (x: number) => string; }> >"package" : "package" >then : string; }, TResult2 = never>(onfulfilled?: (value: { default: (x: number) => string; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->({default: foo}) => foo(42) : ({ default: foo }: { default: (x: number) => string; }) => string +>({default: foo}) => foo(42) : ({ default }: { default: (x: number) => string; }) => string >default : any >foo : (x: number) => string >foo(42) : string diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types index d5429be5e488d..2d48ccacf899c 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.types @@ -75,27 +75,27 @@ const c5 = Hello declare function TestingOneThing({y1: string}): JSX.Element; ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >y1 : any >string : any >JSX : any declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element; ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string;}): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string;}): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >j : { "extra-data": string; yy?: string; } >"extra-data" : string >yy : string >JSX : any declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element; ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number;}): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number;}): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >n : { yy: number; direction?: number; } >yy : number >direction : number >JSX : any declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string;}): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string;}): JSX.Element; } >n : { yy: string; name: string; } >yy : string >name : string @@ -105,27 +105,27 @@ declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; const d1 = ; >d1 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >y1 : true >extra-data : true const d2 = ; >d2 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string const d3 = ; >d3 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string >yy : string const d4 = ; >d4 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string >yy : number >9 : 9 @@ -135,7 +135,7 @@ const d4 = ; const d5 = ; >d5 : JSX.Element > : JSX.Element ->TestingOneThing : { ({ y1: string }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } +>TestingOneThing : { ({ y1 }: { y1: any; }): JSX.Element; (j: { "extra-data": string; yy?: string; }): JSX.Element; (n: { yy: number; direction?: number; }): JSX.Element; (n: { yy: string; name: string; }): JSX.Element; } >extra-data : string >yy : string >name : string diff --git a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts index c6a7baf1c1006..c01524f358e6c 100644 --- a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts +++ b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts @@ -2,7 +2,7 @@ // @declaration: true // GH#37454, GH#41044 -type O = { a: string; b: number; c: number; }; +type O = { a?: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error type F3 = ({ a: string, b, c }: O) => any; // Error @@ -46,6 +46,8 @@ const obj1 = { const obj2 = { method({ a: string }: O): typeof string { return string; } }; +function f6({ a: string = "" }: O) { } +const f7 = ({ a: string = "", b, c }: O) => { }; // In below case `string` should be kept because it is used -function f6({ a: string }: O): typeof string { return "a"; } \ No newline at end of file +function f8({ a: string = "" }: O): typeof string { return "a"; } \ No newline at end of file From f0e5112f4d991e63c61a3b332d6da920ce4a354d Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 12:22:22 +0900 Subject: [PATCH 18/31] Rename and refactor potentialAlways... stuff --- src/compiler/checker.ts | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 31d5f2da97fdb..764cc127e2414 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1026,11 +1026,7 @@ namespace ts { const potentialNewTargetCollisions: Node[] = []; const potentialWeakMapSetCollisions: Node[] = []; const potentialReflectCollisions: Node[] = []; - const potentialAlwaysCheckedUnusedTypes: { - node: Node; - name: Identifier; - diagnostic: DiagnosticMessage; - }[] = []; + const potentialUnusedRenamedBindingElementsInTypes: BindingElement[] = []; const awaitedTypeStack: number[] = []; const diagnostics = createDiagnosticCollection(); @@ -37579,10 +37575,10 @@ namespace ts { }); } - function checkPotentialAlwaysCheckedUnusedTypes() { - for (const { node, name, diagnostic } of potentialAlwaysCheckedUnusedTypes) { + function checkPotentialUncheckedRenamedBindingElementsInTypes() { + for (const node of potentialUnusedRenamedBindingElementsInTypes) { if (!(getSymbolOfNode(node)?.isReferenced! & SymbolFlags.Type)) { - error(name, diagnostic, declarationNameToString(name)); + error(node.name, Diagnostics.Variable_0_is_not_used_Did_you_mean_to_write_a_type_annotation_for_whole_object, declarationNameToString(node.name)); } } } @@ -37938,11 +37934,7 @@ namespace ts { // ^^^^^^ // variable renaming in function type notation is confusing, // so we forbid it even if noUnusedLocals is not enabled - potentialAlwaysCheckedUnusedTypes.push({ - node, - name: node.name, - diagnostic: Diagnostics.Variable_0_is_not_used_Did_you_mean_to_write_a_type_annotation_for_whole_object - }); + potentialUnusedRenamedBindingElementsInTypes.push(node); return; } @@ -41789,7 +41781,7 @@ namespace ts { clear(potentialNewTargetCollisions); clear(potentialWeakMapSetCollisions); clear(potentialReflectCollisions); - clear(potentialAlwaysCheckedUnusedTypes); + clear(potentialUnusedRenamedBindingElementsInTypes); forEach(node.statements, checkSourceElement); checkSourceElement(node.endOfFileToken); @@ -41810,7 +41802,7 @@ namespace ts { }); } if (!node.isDeclarationFile) { - checkPotentialAlwaysCheckedUnusedTypes(); + checkPotentialUncheckedRenamedBindingElementsInTypes(); } }); From 7aa2b6e8976c117bbf78da5e1f26a55d41874def Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 12:33:08 +0900 Subject: [PATCH 19/31] add non-identifier names --- ...tructuredPropertyInFunctionType.errors.txt | 67 +-- ...amingDestructuredPropertyInFunctionType.js | 96 ++++- ...DestructuredPropertyInFunctionType.symbols | 382 +++++++++++------- ...ngDestructuredPropertyInFunctionType.types | 107 ++++- ...amingDestructuredPropertyInFunctionType.ts | 37 +- 5 files changed, 456 insertions(+), 233 deletions(-) diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index 087dd06386b4c..1fdf4c76bb041 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -1,21 +1,23 @@ -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(5,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(6,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(7,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(9,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(10,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(17,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(20,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(26,16): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(29,9): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(32,13): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(12,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(22,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(23,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(25,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(38,16): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(41,9): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? ==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (13 errors) ==== // GH#37454, GH#41044 + const sym = Symbol(); + type O = { a?: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error @@ -36,26 +38,36 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(32,13): error !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type F8 = ({ a, b: number }) => typeof number; // OK type F9 = ([a, b, c]) => void; // Error + type F10 = ({ "a": string }) => void; // Error + type F11 = ({ 2: string }) => void; // Error + type F12 = ({ ["a"]: string }: O) => void; // Error + type F13 = ({ [2]: string }) => void; // Error + // type F14 = ({ [sym]: string }) => void; // Error - type G1 = (arg: number) => any; // OK - type G2 = ({ a: string }: O) => any; // Error - ~~~~~~ + type G1 = new (arg: number) => any; // OK + type G2 = new ({ a: string }: O) => any; // Error + ~~~~~~ !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? - type G3 = ({ a: string, b, c }: O) => any; // Error - ~~~~~~ + type G3 = new ({ a: string, b, c }: O) => any; // Error + ~~~~~~ !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? - type G4 = ({ a: string }: O) => any; // Error - ~~~~~~ + type G4 = new ({ a: string }: O) => any; // Error + ~~~~~~ !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? - type G5 = ({ a: string, b, c }: O) => any; // Error - ~~~~~~ + type G5 = new ({ a: string, b, c }: O) => any; // Error + ~~~~~~ !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? - type G6 = ({ a: string }) => typeof string; // OK - type G7 = ({ a: string, b: number }) => typeof number; // Error - ~~~~~~ + type G6 = new ({ a: string }) => typeof string; // OK + type G7 = new ({ a: string, b: number }) => typeof number; // Error + ~~~~~~ !!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? - type G8 = ({ a, b: number }) => typeof number; // OK - type G9 = ([a, b, c]) => void; // Error + type G8 = new ({ a, b: number }) => typeof number; // OK + type G9 = new ([a, b, c]) => void; // Error + type G10 = new ({ "a": string }) => void; // Error + type G11 = new ({ 2: string }) => void; // Error + type G12 = new ({ ["a"]: string }: O) => void; // Error + type G13 = new ({ [2]: string }) => void; // Error + // type G14 = new ({ [sym]: string }) => void; // Error interface I { method1(arg: number): any; // OK @@ -88,6 +100,11 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(32,13): error }; function f6({ a: string = "" }: O) { } const f7 = ({ a: string = "", b, c }: O) => { }; + const f8 = ({ "a": string }: O) => { }; + function f9 ({ 2: string }) { }; + function f10 ({ ["a"]: string }: O) { }; + const f11 = ({ [2]: string }) => { }; + // const f12 = ({ [sym]: string }) => { }; // In below case `string` should be kept because it is used - function f8({ a: string = "" }: O): typeof string { return "a"; } \ No newline at end of file + function f13({ a: string = "" }: O): typeof string { return "a"; } \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js index ed605a856f488..4306d4669533e 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js @@ -1,6 +1,8 @@ //// [renamingDestructuredPropertyInFunctionType.ts] // GH#37454, GH#41044 +const sym = Symbol(); + type O = { a?: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error @@ -11,16 +13,26 @@ type F6 = ({ a: string }) => typeof string; // OK type F7 = ({ a: string, b: number }) => typeof number; // Error type F8 = ({ a, b: number }) => typeof number; // OK type F9 = ([a, b, c]) => void; // Error +type F10 = ({ "a": string }) => void; // Error +type F11 = ({ 2: string }) => void; // Error +type F12 = ({ ["a"]: string }: O) => void; // Error +type F13 = ({ [2]: string }) => void; // Error +// type F14 = ({ [sym]: string }) => void; // Error -type G1 = (arg: number) => any; // OK -type G2 = ({ a: string }: O) => any; // Error -type G3 = ({ a: string, b, c }: O) => any; // Error -type G4 = ({ a: string }: O) => any; // Error -type G5 = ({ a: string, b, c }: O) => any; // Error -type G6 = ({ a: string }) => typeof string; // OK -type G7 = ({ a: string, b: number }) => typeof number; // Error -type G8 = ({ a, b: number }) => typeof number; // OK -type G9 = ([a, b, c]) => void; // Error +type G1 = new (arg: number) => any; // OK +type G2 = new ({ a: string }: O) => any; // Error +type G3 = new ({ a: string, b, c }: O) => any; // Error +type G4 = new ({ a: string }: O) => any; // Error +type G5 = new ({ a: string, b, c }: O) => any; // Error +type G6 = new ({ a: string }) => typeof string; // OK +type G7 = new ({ a: string, b: number }) => typeof number; // Error +type G8 = new ({ a, b: number }) => typeof number; // OK +type G9 = new ([a, b, c]) => void; // Error +type G10 = new ({ "a": string }) => void; // Error +type G11 = new ({ 2: string }) => void; // Error +type G12 = new ({ ["a"]: string }: O) => void; // Error +type G13 = new ({ [2]: string }) => void; // Error +// type G14 = new ({ [sym]: string }) => void; // Error interface I { method1(arg: number): any; // OK @@ -47,12 +59,18 @@ const obj2 = { }; function f6({ a: string = "" }: O) { } const f7 = ({ a: string = "", b, c }: O) => { }; +const f8 = ({ "a": string }: O) => { }; +function f9 ({ 2: string }) { }; +function f10 ({ ["a"]: string }: O) { }; +const f11 = ({ [2]: string }) => { }; +// const f12 = ({ [sym]: string }) => { }; // In below case `string` should be kept because it is used -function f8({ a: string = "" }: O): typeof string { return "a"; } +function f13({ a: string = "" }: O): typeof string { return "a"; } //// [renamingDestructuredPropertyInFunctionType.js] // GH#37454, GH#41044 +const sym = Symbol(); // Below are OK but renaming should be removed from declaration emit function f1({ a: string }) { } const f2 = function ({ a: string }) { }; @@ -67,11 +85,19 @@ const obj2 = { }; function f6({ a: string = "" }) { } const f7 = ({ a: string = "", b, c }) => { }; +const f8 = ({ "a": string }) => { }; +function f9({ 2: string }) { } +; +function f10({ ["a"]: string }) { } +; +const f11 = ({ [2]: string }) => { }; +// const f12 = ({ [sym]: string }) => { }; // In below case `string` should be kept because it is used -function f8({ a: string = "" }) { return "a"; } +function f13({ a: string = "" }) { return "a"; } //// [renamingDestructuredPropertyInFunctionType.d.ts] +declare const sym: unique symbol; declare type O = { a?: string; b: number; @@ -94,23 +120,43 @@ declare type F8 = ({ a, b: number }: { b: any; }) => typeof number; declare type F9 = ([a, b, c]: [any, any, any]) => void; -declare type G1 = (arg: number) => any; -declare type G2 = ({ a }: O) => any; -declare type G3 = ({ a, b, c }: O) => any; -declare type G4 = ({ a }: O) => any; -declare type G5 = ({ a, b, c }: O) => any; -declare type G6 = ({ a: string }: { +declare type F10 = ({ "a": string }: { + a: any; +}) => void; +declare type F11 = ({ 2: string }: { + 2: any; +}) => void; +declare type F12 = ({ ["a"]: string }: O) => void; +declare type F13 = ({ [2]: string }: { + 2: any; +}) => void; +declare type G1 = new (arg: number) => any; +declare type G2 = new ({ a }: O) => any; +declare type G3 = new ({ a, b, c }: O) => any; +declare type G4 = new ({ a }: O) => any; +declare type G5 = new ({ a, b, c }: O) => any; +declare type G6 = new ({ a: string }: { a: any; }) => typeof string; -declare type G7 = ({ a, b: number }: { +declare type G7 = new ({ a, b: number }: { a: any; b: any; }) => typeof number; -declare type G8 = ({ a, b: number }: { +declare type G8 = new ({ a, b: number }: { a: any; b: any; }) => typeof number; -declare type G9 = ([a, b, c]: [any, any, any]) => void; +declare type G9 = new ([a, b, c]: [any, any, any]) => void; +declare type G10 = new ({ "a": string }: { + a: any; +}) => void; +declare type G11 = new ({ 2: string }: { + 2: any; +}) => void; +declare type G12 = new ({ ["a"]: string }: O) => void; +declare type G13 = new ({ [2]: string }: { + 2: any; +}) => void; interface I { method1(arg: number): any; method2({ a }: { @@ -138,4 +184,12 @@ declare const obj2: { }; declare function f6({ a }: O): void; declare const f7: ({ a, b, c }: O) => void; -declare function f8({ a: string }: O): typeof string; +declare const f8: ({ "a": string }: O) => void; +declare function f9({ 2: string }: { + 2: any; +}): void; +declare function f10({ ["a"]: string }: O): void; +declare const f11: ({ [2]: string }: { + 2: any; +}) => void; +declare function f13({ a: string }: O): typeof string; diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols index f365b6aa024ee..e299e57965056 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols @@ -1,236 +1,304 @@ === tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === // GH#37454, GH#41044 +const sym = Symbol(); +>sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + type O = { a?: string; b: number; c: number; }; ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 22)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 33)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 22)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 33)) type F1 = (arg: number) => any; // OK ->F1 : Symbol(F1, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 47)) ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 11)) +>F1 : Symbol(F1, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 47)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 11)) type F2 = ({ a: string }: O) => any; // Error ->F2 : Symbol(F2, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 31)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 12)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>F2 : Symbol(F2, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 31)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 12)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) type F3 = ({ a: string, b, c }: O) => any; // Error ->F3 : Symbol(F3, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 36)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 23)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 26)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>F3 : Symbol(F3, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 36)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 23)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 26)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) type F4 = ({ a: string }: O) => any; // Error ->F4 : Symbol(F4, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 42)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 12)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>F4 : Symbol(F4, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 42)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) type F5 = ({ a: string, b, c }: O) => any; // Error ->F5 : Symbol(F5, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 36)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 23)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 26)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>F5 : Symbol(F5, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 36)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 23)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 26)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) type F6 = ({ a: string }) => typeof string; // OK ->F6 : Symbol(F6, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 42)) +>F6 : Symbol(F6, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 42)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 12)) type F7 = ({ a: string, b: number }) => typeof number; // Error ->F7 : Symbol(F7, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 43)) +>F7 : Symbol(F7, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 43)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 12)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 23)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 23)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 23)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 23)) type F8 = ({ a, b: number }) => typeof number; // OK ->F8 : Symbol(F8, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 54)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 12)) +>F8 : Symbol(F8, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 54)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 12)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 15)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 15)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 15)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 15)) type F9 = ([a, b, c]) => void; // Error ->F9 : Symbol(F9, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 46)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 14)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 17)) - -type G1 = (arg: number) => any; // OK ->G1 : Symbol(G1, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 30)) ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 11)) - -type G2 = ({ a: string }: O) => any; // Error ->G2 : Symbol(G2, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 31)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 12)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) - -type G3 = ({ a: string, b, c }: O) => any; // Error ->G3 : Symbol(G3, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 36)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 23)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 26)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) - -type G4 = ({ a: string }: O) => any; // Error ->G4 : Symbol(G4, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 42)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 12)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) - -type G5 = ({ a: string, b, c }: O) => any; // Error ->G5 : Symbol(G5, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 36)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 23)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 26)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) - -type G6 = ({ a: string }) => typeof string; // OK ->G6 : Symbol(G6, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 42)) +>F9 : Symbol(F9, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 46)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 14)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 17)) + +type F10 = ({ "a": string }) => void; // Error +>F10 : Symbol(F10, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 30)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 13)) + +type F11 = ({ 2: string }) => void; // Error +>F11 : Symbol(F11, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 37)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 13)) + +type F12 = ({ ["a"]: string }: O) => void; // Error +>F12 : Symbol(F12, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 35)) +>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 13)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) + +type F13 = ({ [2]: string }) => void; // Error +>F13 : Symbol(F13, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 42)) +>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 13)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 13)) + +// type F14 = ({ [sym]: string }) => void; // Error + +type G1 = new (arg: number) => any; // OK +>G1 : Symbol(G1, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 37)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 15)) + +type G2 = new ({ a: string }: O) => any; // Error +>G2 : Symbol(G2, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 35)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 16)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) + +type G3 = new ({ a: string, b, c }: O) => any; // Error +>G3 : Symbol(G3, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 40)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 16)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 27)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 30)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) + +type G4 = new ({ a: string }: O) => any; // Error +>G4 : Symbol(G4, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 46)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 16)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) + +type G5 = new ({ a: string, b, c }: O) => any; // Error +>G5 : Symbol(G5, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 40)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 16)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 27)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 30)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) + +type G6 = new ({ a: string }) => typeof string; // OK +>G6 : Symbol(G6, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 46)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 12)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 16)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 16)) -type G7 = ({ a: string, b: number }) => typeof number; // Error ->G7 : Symbol(G7, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 43)) +type G7 = new ({ a: string, b: number }) => typeof number; // Error +>G7 : Symbol(G7, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 47)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 16)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 23)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 23)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 27)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 27)) -type G8 = ({ a, b: number }) => typeof number; // OK ->G8 : Symbol(G8, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 54)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 12)) +type G8 = new ({ a, b: number }) => typeof number; // OK +>G8 : Symbol(G8, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 58)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 16)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 15)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 15)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 19)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 19)) + +type G9 = new ([a, b, c]) => void; // Error +>G9 : Symbol(G9, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 50)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 16)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 18)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 21)) + +type G10 = new ({ "a": string }) => void; // Error +>G10 : Symbol(G10, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 34)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 17)) -type G9 = ([a, b, c]) => void; // Error ->G9 : Symbol(G9, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 46)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 14)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 17)) +type G11 = new ({ 2: string }) => void; // Error +>G11 : Symbol(G11, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 41)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 30, 17)) + +type G12 = new ({ ["a"]: string }: O) => void; // Error +>G12 : Symbol(G12, Decl(renamingDestructuredPropertyInFunctionType.ts, 30, 39)) +>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 17)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 17)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) + +type G13 = new ({ [2]: string }) => void; // Error +>G13 : Symbol(G13, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 46)) +>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 17)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 17)) + +// type G14 = new ({ [sym]: string }) => void; // Error interface I { ->I : Symbol(I, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 30)) +>I : Symbol(I, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 41)) method1(arg: number): any; // OK ->method1 : Symbol(I.method1, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 13)) ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 10)) +>method1 : Symbol(I.method1, Decl(renamingDestructuredPropertyInFunctionType.ts, 35, 13)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 10)) method2({ a: string }): any; // Error ->method2 : Symbol(I.method2, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 28)) +>method2 : Symbol(I.method2, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 28)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 11)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 37, 11)) (arg: number): any; // OK ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 3)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 3)) ({ a: string }): any; // Error >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 4)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 40, 4)) new (arg: number): any; // OK ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 30, 7)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 42, 7)) new ({ a: string }): any; // Error >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 8)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 43, 8)) } // Below are OK but renaming should be removed from declaration emit function f1({ a: string }: O) { } ->f1 : Symbol(f1, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 1)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 35, 13)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>f1 : Symbol(f1, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 1)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) const f2 = function({ a: string }: O) { }; ->f2 : Symbol(f2, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 5)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 21)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>f2 : Symbol(f2, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 21)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) const f3 = ({ a: string, b, c }: O) => { }; ->f3 : Symbol(f3, Decl(renamingDestructuredPropertyInFunctionType.ts, 37, 5)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 37, 13)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 37, 24)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 37, 27)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>f3 : Symbol(f3, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 13)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 24)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 27)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) const f4 = function({ a: string }: O): typeof string { return string; }; ->f4 : Symbol(f4, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 5)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 21)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 21)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 21)) +>f4 : Symbol(f4, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 21)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 21)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 21)) const f5 = ({ a: string, b, c }: O): typeof string => ''; ->f5 : Symbol(f5, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 5)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 13)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 24)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 27)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 13)) +>f5 : Symbol(f5, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 13)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 24)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 27)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 13)) const obj1 = { ->obj1 : Symbol(obj1, Decl(renamingDestructuredPropertyInFunctionType.ts, 40, 5)) +>obj1 : Symbol(obj1, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 5)) method({ a: string }: O) { } ->method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 40, 14)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 41, 10)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 14)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 53, 10)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) }; const obj2 = { ->obj2 : Symbol(obj2, Decl(renamingDestructuredPropertyInFunctionType.ts, 43, 5)) +>obj2 : Symbol(obj2, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 5)) method({ a: string }: O): typeof string { return string; } ->method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 43, 14)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 10)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 10)) +>method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 14)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 10)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 10)) }; function f6({ a: string = "" }: O) { } ->f6 : Symbol(f6, Decl(renamingDestructuredPropertyInFunctionType.ts, 45, 2)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 13)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>f6 : Symbol(f6, Decl(renamingDestructuredPropertyInFunctionType.ts, 57, 2)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) const f7 = ({ a: string = "", b, c }: O) => { }; ->f7 : Symbol(f7, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 5)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 13)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 29)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 32)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>f7 : Symbol(f7, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 13)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 29)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 32)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) + +const f8 = ({ "a": string }: O) => { }; +>f8 : Symbol(f8, Decl(renamingDestructuredPropertyInFunctionType.ts, 60, 5)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 60, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) + +function f9 ({ 2: string }) { }; +>f9 : Symbol(f9, Decl(renamingDestructuredPropertyInFunctionType.ts, 60, 39)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 61, 14)) + +function f10 ({ ["a"]: string }: O) { }; +>f10 : Symbol(f10, Decl(renamingDestructuredPropertyInFunctionType.ts, 61, 32)) +>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 15)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 15)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) + +const f11 = ({ [2]: string }) => { }; +>f11 : Symbol(f11, Decl(renamingDestructuredPropertyInFunctionType.ts, 63, 5)) +>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 63, 15)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 63, 15)) + +// const f12 = ({ [sym]: string }) => { }; // In below case `string` should be kept because it is used -function f8({ a: string = "" }: O): typeof string { return "a"; } ->f8 : Symbol(f8, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 48)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 13)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 13)) +function f13({ a: string = "" }: O): typeof string { return "a"; } +>f13 : Symbol(f13, Decl(renamingDestructuredPropertyInFunctionType.ts, 63, 38)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 67, 14)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 67, 14)) diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types index 331697bf8fadc..d01ff5ab21111 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types @@ -1,6 +1,11 @@ === tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === // GH#37454, GH#41044 +const sym = Symbol(); +>sym : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + type O = { a?: string; b: number; c: number; }; >O : { a?: string; b: number; c: number; } >a : string @@ -62,61 +67,101 @@ type F9 = ([a, b, c]) => void; // Error >b : any >c : any -type G1 = (arg: number) => any; // OK ->G1 : (arg: number) => any +type F10 = ({ "a": string }) => void; // Error +>F10 : ({ "a": string }: { a: any; }) => void +>string : any + +type F11 = ({ 2: string }) => void; // Error +>F11 : ({ 2: string }: { 2: any; }) => void +>string : any + +type F12 = ({ ["a"]: string }: O) => void; // Error +>F12 : ({ ["a"]: string }: O) => void +>"a" : "a" +>string : string + +type F13 = ({ [2]: string }) => void; // Error +>F13 : ({ [2]: string }: { 2: any; }) => void +>2 : 2 +>string : any + +// type F14 = ({ [sym]: string }) => void; // Error + +type G1 = new (arg: number) => any; // OK +>G1 : new (arg: number) => any >arg : number -type G2 = ({ a: string }: O) => any; // Error ->G2 : ({ a }: O) => any +type G2 = new ({ a: string }: O) => any; // Error +>G2 : new ({ a }: O) => any >a : any >string : string -type G3 = ({ a: string, b, c }: O) => any; // Error ->G3 : ({ a, b, c }: O) => any +type G3 = new ({ a: string, b, c }: O) => any; // Error +>G3 : new ({ a, b, c }: O) => any >a : any >string : string >b : number >c : number -type G4 = ({ a: string }: O) => any; // Error ->G4 : ({ a }: O) => any +type G4 = new ({ a: string }: O) => any; // Error +>G4 : new ({ a }: O) => any >a : any >string : string -type G5 = ({ a: string, b, c }: O) => any; // Error ->G5 : ({ a, b, c }: O) => any +type G5 = new ({ a: string, b, c }: O) => any; // Error +>G5 : new ({ a, b, c }: O) => any >a : any >string : string >b : number >c : number -type G6 = ({ a: string }) => typeof string; // OK ->G6 : ({ a }: { a: any; }) => any +type G6 = new ({ a: string }) => typeof string; // OK +>G6 : new ({ a }: { a: any; }) => any >a : any >string : any >string : any -type G7 = ({ a: string, b: number }) => typeof number; // Error ->G7 : ({ a, b }: { a: any; b: any; }) => any +type G7 = new ({ a: string, b: number }) => typeof number; // Error +>G7 : new ({ a, b }: { a: any; b: any; }) => any >a : any >string : any >b : any >number : any >number : any -type G8 = ({ a, b: number }) => typeof number; // OK ->G8 : ({ a, b }: { a: any; b: any; }) => any +type G8 = new ({ a, b: number }) => typeof number; // OK +>G8 : new ({ a, b }: { a: any; b: any; }) => any >a : any >b : any >number : any >number : any -type G9 = ([a, b, c]) => void; // Error ->G9 : ([a, b, c]: [any, any, any]) => void +type G9 = new ([a, b, c]) => void; // Error +>G9 : new ([a, b, c]: [any, any, any]) => void >a : any >b : any >c : any +type G10 = new ({ "a": string }) => void; // Error +>G10 : new ({ "a": string }: { a: any; }) => void +>string : any + +type G11 = new ({ 2: string }) => void; // Error +>G11 : new ({ 2: string }: { 2: any; }) => void +>string : any + +type G12 = new ({ ["a"]: string }: O) => void; // Error +>G12 : new ({ ["a"]: string }: O) => void +>"a" : "a" +>string : string + +type G13 = new ({ [2]: string }) => void; // Error +>G13 : new ({ [2]: string }: { 2: any; }) => void +>2 : 2 +>string : any + +// type G14 = new ({ [sym]: string }) => void; // Error + interface I { method1(arg: number): any; // OK >method1 : (arg: number) => any @@ -217,9 +262,31 @@ const f7 = ({ a: string = "", b, c }: O) => { }; >b : number >c : number +const f8 = ({ "a": string }: O) => { }; +>f8 : ({ "a": string }: O) => void +>({ "a": string }: O) => { } : ({ "a": string }: O) => void +>string : string + +function f9 ({ 2: string }) { }; +>f9 : ({ 2: string }: { 2: any; }) => void +>string : any + +function f10 ({ ["a"]: string }: O) { }; +>f10 : ({ ["a"]: string }: O) => void +>"a" : "a" +>string : string + +const f11 = ({ [2]: string }) => { }; +>f11 : ({ [2]: string }: { 2: any; }) => void +>({ [2]: string }) => { } : ({ [2]: string }: { 2: any; }) => void +>2 : 2 +>string : any + +// const f12 = ({ [sym]: string }) => { }; + // In below case `string` should be kept because it is used -function f8({ a: string = "" }: O): typeof string { return "a"; } ->f8 : ({ a }: O) => typeof string +function f13({ a: string = "" }: O): typeof string { return "a"; } +>f13 : ({ a }: O) => typeof string >a : any >string : string >"" : "" diff --git a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts index c01524f358e6c..ce3228a37743f 100644 --- a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts +++ b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts @@ -2,6 +2,8 @@ // @declaration: true // GH#37454, GH#41044 +const sym = Symbol(); + type O = { a?: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error @@ -12,16 +14,26 @@ type F6 = ({ a: string }) => typeof string; // OK type F7 = ({ a: string, b: number }) => typeof number; // Error type F8 = ({ a, b: number }) => typeof number; // OK type F9 = ([a, b, c]) => void; // Error +type F10 = ({ "a": string }) => void; // Error +type F11 = ({ 2: string }) => void; // Error +type F12 = ({ ["a"]: string }: O) => void; // Error +type F13 = ({ [2]: string }) => void; // Error +// type F14 = ({ [sym]: string }) => void; // Error -type G1 = (arg: number) => any; // OK -type G2 = ({ a: string }: O) => any; // Error -type G3 = ({ a: string, b, c }: O) => any; // Error -type G4 = ({ a: string }: O) => any; // Error -type G5 = ({ a: string, b, c }: O) => any; // Error -type G6 = ({ a: string }) => typeof string; // OK -type G7 = ({ a: string, b: number }) => typeof number; // Error -type G8 = ({ a, b: number }) => typeof number; // OK -type G9 = ([a, b, c]) => void; // Error +type G1 = new (arg: number) => any; // OK +type G2 = new ({ a: string }: O) => any; // Error +type G3 = new ({ a: string, b, c }: O) => any; // Error +type G4 = new ({ a: string }: O) => any; // Error +type G5 = new ({ a: string, b, c }: O) => any; // Error +type G6 = new ({ a: string }) => typeof string; // OK +type G7 = new ({ a: string, b: number }) => typeof number; // Error +type G8 = new ({ a, b: number }) => typeof number; // OK +type G9 = new ([a, b, c]) => void; // Error +type G10 = new ({ "a": string }) => void; // Error +type G11 = new ({ 2: string }) => void; // Error +type G12 = new ({ ["a"]: string }: O) => void; // Error +type G13 = new ({ [2]: string }) => void; // Error +// type G14 = new ({ [sym]: string }) => void; // Error interface I { method1(arg: number): any; // OK @@ -48,6 +60,11 @@ const obj2 = { }; function f6({ a: string = "" }: O) { } const f7 = ({ a: string = "", b, c }: O) => { }; +const f8 = ({ "a": string }: O) => { }; +function f9 ({ 2: string }) { }; +function f10 ({ ["a"]: string }: O) { }; +const f11 = ({ [2]: string }) => { }; +// const f12 = ({ [sym]: string }) => { }; // In below case `string` should be kept because it is used -function f8({ a: string = "" }: O): typeof string { return "a"; } \ No newline at end of file +function f13({ a: string = "" }: O): typeof string { return "a"; } \ No newline at end of file From 755c7c4dabc4fb58287f0fc522e9611abb67781a Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 12:36:03 +0900 Subject: [PATCH 20/31] extend check to non-identifier original property names --- src/compiler/checker.ts | 1 - ...tructuredPropertyInFunctionType.errors.txt | 26 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 764cc127e2414..d66c38739273d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37926,7 +37926,6 @@ namespace ts { if (isBindingElement(node)) { if ( node.propertyName && - isIdentifier(node.propertyName) && isIdentifier(node.name) && isParameterDeclaration(node) && nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) { diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index 1fdf4c76bb041..5a02329a2af6a 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -3,17 +3,25 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(9,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(10,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(12,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,20): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,18): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(17,22): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,20): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(22,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(23,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(25,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,24): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(31,22): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(32,26): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(33,24): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(38,16): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(41,9): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (13 errors) ==== +==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (21 errors) ==== // GH#37454, GH#41044 const sym = Symbol(); @@ -39,9 +47,17 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error type F8 = ({ a, b: number }) => typeof number; // OK type F9 = ([a, b, c]) => void; // Error type F10 = ({ "a": string }) => void; // Error + ~~~~~~ +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type F11 = ({ 2: string }) => void; // Error + ~~~~~~ +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type F12 = ({ ["a"]: string }: O) => void; // Error + ~~~~~~ +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type F13 = ({ [2]: string }) => void; // Error + ~~~~~~ +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? // type F14 = ({ [sym]: string }) => void; // Error type G1 = new (arg: number) => any; // OK @@ -64,9 +80,17 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error type G8 = new ({ a, b: number }) => typeof number; // OK type G9 = new ([a, b, c]) => void; // Error type G10 = new ({ "a": string }) => void; // Error + ~~~~~~ +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type G11 = new ({ 2: string }) => void; // Error + ~~~~~~ +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type G12 = new ({ ["a"]: string }: O) => void; // Error + ~~~~~~ +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? type G13 = new ({ [2]: string }) => void; // Error + ~~~~~~ +!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? // type G14 = new ({ [sym]: string }) => void; // Error interface I { From c7768cfda10ec8c03327ce05b178f56ea4bb9687 Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 12:40:29 +0900 Subject: [PATCH 21/31] update diagnostic message --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- ...tructuredPropertyInFunctionType.errors.txt | 84 +++++++++---------- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d66c38739273d..58c84ceb7ad15 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37578,7 +37578,7 @@ namespace ts { function checkPotentialUncheckedRenamedBindingElementsInTypes() { for (const node of potentialUnusedRenamedBindingElementsInTypes) { if (!(getSymbolOfNode(node)?.isReferenced! & SymbolFlags.Type)) { - error(node.name, Diagnostics.Variable_0_is_not_used_Did_you_mean_to_write_a_type_annotation_for_whole_object, declarationNameToString(node.name)); + error(node.name, Diagnostics._0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation, declarationNameToString(node.name), declarationNameToString(node.propertyName)); } } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 1df0c5f12a23a..26601478be5b2 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3487,7 +3487,7 @@ "category": "Error", "code": 2841 }, - "Variable '{0}' is not used. Did you mean to write a type annotation for whole object?": { + "'{0}' is an unused renaming of '{1}'. Did you intend to use it as a type annotation?": { "category": "Error", "code": 2842 }, diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index 5a02329a2af6a..8495c911cd9b9 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -1,24 +1,24 @@ -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(7,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(9,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(10,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(12,17): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,20): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,18): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(17,22): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,20): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(22,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(23,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(25,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,21): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,24): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(31,22): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(32,26): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(33,24): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(38,16): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(41,9): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(7,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(9,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(10,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(12,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,20): error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,18): error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(17,22): error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,20): error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(22,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(23,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(25,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,24): error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(31,22): error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(32,26): error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(33,24): error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(38,16): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(41,9): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? ==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (21 errors) ==== @@ -30,84 +30,84 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? type F3 = ({ a: string, b, c }: O) => any; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? type F4 = ({ a: string }: O) => any; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? type F5 = ({ a: string, b, c }: O) => any; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? type F6 = ({ a: string }) => typeof string; // OK type F7 = ({ a: string, b: number }) => typeof number; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? type F8 = ({ a, b: number }) => typeof number; // OK type F9 = ([a, b, c]) => void; // Error type F10 = ({ "a": string }) => void; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? type F11 = ({ 2: string }) => void; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? type F12 = ({ ["a"]: string }: O) => void; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? type F13 = ({ [2]: string }) => void; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? // type F14 = ({ [sym]: string }) => void; // Error type G1 = new (arg: number) => any; // OK type G2 = new ({ a: string }: O) => any; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? type G3 = new ({ a: string, b, c }: O) => any; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? type G4 = new ({ a: string }: O) => any; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? type G5 = new ({ a: string, b, c }: O) => any; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? type G6 = new ({ a: string }) => typeof string; // OK type G7 = new ({ a: string, b: number }) => typeof number; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? type G8 = new ({ a, b: number }) => typeof number; // OK type G9 = new ([a, b, c]) => void; // Error type G10 = new ({ "a": string }) => void; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? type G11 = new ({ 2: string }) => void; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? type G12 = new ({ ["a"]: string }: O) => void; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? type G13 = new ({ [2]: string }) => void; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? // type G14 = new ({ [sym]: string }) => void; // Error interface I { method1(arg: number): any; // OK method2({ a: string }): any; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? (arg: number): any; // OK ({ a: string }): any; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? new (arg: number): any; // OK new ({ a: string }): any; // Error ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? } // Below are OK but renaming should be removed from declaration emit From bdb42e196f57afe803f5954e18f58fbcc0d765c8 Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 13:06:54 +0900 Subject: [PATCH 22/31] add related span --- src/compiler/checker.ts | 12 +++++++++++- src/compiler/diagnosticMessages.json | 4 ++++ ...mingDestructuredPropertyInFunctionType.errors.txt | 11 +++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 58c84ceb7ad15..4f1a86fabc44b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37578,7 +37578,17 @@ namespace ts { function checkPotentialUncheckedRenamedBindingElementsInTypes() { for (const node of potentialUnusedRenamedBindingElementsInTypes) { if (!(getSymbolOfNode(node)?.isReferenced! & SymbolFlags.Type)) { - error(node.name, Diagnostics._0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation, declarationNameToString(node.name), declarationNameToString(node.propertyName)); + const wrappingDeclaration = walkUpBindingElementsAndPatterns(node); + Debug.assert(isParameterDeclaration(wrappingDeclaration), "Only parameter declaration should be checked here"); + const diagnostic = createDiagnosticForNode(node.name, Diagnostics._0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation, declarationNameToString(node.name), declarationNameToString(node.propertyName)); + if (!wrappingDeclaration.type) { + // entire parameter does not have type annotation, suggest adding an annotation + addRelatedInfo( + diagnostic, + createFileDiagnostic(getSourceFileOfNode(wrappingDeclaration), wrappingDeclaration.end - 1, 1,Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here, declarationNameToString(wrappingDeclaration.name)) + ); + } + diagnostics.add(diagnostic); } } } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 26601478be5b2..cda1a050cb927 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3491,6 +3491,10 @@ "category": "Error", "code": 2842 }, + "We can only write a type for '{0}' by adding a type for the entire parameter here.": { + "category": "Error", + "code": 2843 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index 8495c911cd9b9..61260d9c84927 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -44,20 +44,24 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error type F7 = ({ a: string, b: number }) => typeof number; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:12:35: We can only write a type for '{ a: string, b: number }' by adding a type for the entire parameter here. type F8 = ({ a, b: number }) => typeof number; // OK type F9 = ([a, b, c]) => void; // Error type F10 = ({ "a": string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:15:27: We can only write a type for '{ "a": string }' by adding a type for the entire parameter here. type F11 = ({ 2: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:16:25: We can only write a type for '{ 2: string }' by adding a type for the entire parameter here. type F12 = ({ ["a"]: string }: O) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? type F13 = ({ [2]: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:18:27: We can only write a type for '{ [2]: string }' by adding a type for the entire parameter here. // type F14 = ({ [sym]: string }) => void; // Error type G1 = new (arg: number) => any; // OK @@ -77,20 +81,24 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error type G7 = new ({ a: string, b: number }) => typeof number; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:27:39: We can only write a type for '{ a: string, b: number }' by adding a type for the entire parameter here. type G8 = new ({ a, b: number }) => typeof number; // OK type G9 = new ([a, b, c]) => void; // Error type G10 = new ({ "a": string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:30:31: We can only write a type for '{ "a": string }' by adding a type for the entire parameter here. type G11 = new ({ 2: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:31:29: We can only write a type for '{ 2: string }' by adding a type for the entire parameter here. type G12 = new ({ ["a"]: string }: O) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? type G13 = new ({ [2]: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:33:31: We can only write a type for '{ [2]: string }' by adding a type for the entire parameter here. // type G14 = new ({ [sym]: string }) => void; // Error interface I { @@ -98,16 +106,19 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error method2({ a: string }): any; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:38:23: We can only write a type for '{ a: string }' by adding a type for the entire parameter here. (arg: number): any; // OK ({ a: string }): any; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:41:16: We can only write a type for '{ a: string }' by adding a type for the entire parameter here. new (arg: number): any; // OK new ({ a: string }): any; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:44:20: We can only write a type for '{ a: string }' by adding a type for the entire parameter here. } // Below are OK but renaming should be removed from declaration emit From 6d4d1476c4f788b4118f4b77a5137f54b430de6f Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 14:16:46 +0900 Subject: [PATCH 23/31] accept baseline --- .../reference/destructuringInFunctionType.errors.txt | 10 ++++++---- .../reference/excessPropertyCheckWithSpread.errors.txt | 5 +++-- .../paramterDestrcuturingDeclaration.errors.txt | 10 ++++++---- .../tsxStatelessFunctionComponentOverload1.errors.txt | 5 +++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/tests/baselines/reference/destructuringInFunctionType.errors.txt b/tests/baselines/reference/destructuringInFunctionType.errors.txt index 06b1eeffee422..718d76678600d 100644 --- a/tests/baselines/reference/destructuringInFunctionType.errors.txt +++ b/tests/baselines/reference/destructuringInFunctionType.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,18): error TS2842: Variable 'b' is not used. Did you mean to write a type annotation for whole object? -tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,28): error TS2842: Variable 'a' is not used. Did you mean to write a type annotation for whole object? +tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,18): error TS2842: 'b' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,28): error TS2842: 'a' is an unused renaming of 'b'. Did you intend to use it as a type annotation? ==== tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts (2 errors) ==== @@ -16,9 +16,11 @@ tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,28): type T3 = ([{ a: b }, { b: a }]); type F3 = ([{ a: b }, { b: a }]) => void; ~ -!!! error TS2842: Variable 'b' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'b' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:31: We can only write a type for '[{ a: b }, { b: a }]' by adding a type for the entire parameter here. ~ -!!! error TS2842: Variable 'a' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'a' is an unused renaming of 'b'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:31: We can only write a type for '[{ a: b }, { b: a }]' by adding a type for the entire parameter here. type T4 = ([{ a: [b, c] }]); type F4 = ([{ a: [b, c] }]) => void; diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt index 85975abec2d0c..8c36a9512093f 100644 --- a/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt @@ -1,10 +1,11 @@ -tests/cases/compiler/excessPropertyCheckWithSpread.ts(1,25): error TS2842: Variable 'number' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/excessPropertyCheckWithSpread.ts(1,25): error TS2842: 'number' is an unused renaming of 'a'. Did you intend to use it as a type annotation? ==== tests/cases/compiler/excessPropertyCheckWithSpread.ts (1 errors) ==== declare function f({ a: number }): void ~~~~~~ -!!! error TS2842: Variable 'number' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'number' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/excessPropertyCheckWithSpread.ts:1:32: We can only write a type for '{ a: number }' by adding a type for the entire parameter here. interface I { readonly n: number; } diff --git a/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt b/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt index 4225815bb0d5d..fab67b5b42522 100644 --- a/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt +++ b/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt @@ -1,14 +1,16 @@ -tests/cases/compiler/paramterDestrcuturingDeclaration.ts(2,10): error TS2842: Variable 'name' is not used. Did you mean to write a type annotation for whole object? -tests/cases/compiler/paramterDestrcuturingDeclaration.ts(3,14): error TS2842: Variable 'boolean' is not used. Did you mean to write a type annotation for whole object? +tests/cases/compiler/paramterDestrcuturingDeclaration.ts(2,10): error TS2842: 'name' is an unused renaming of 'p'. Did you intend to use it as a type annotation? +tests/cases/compiler/paramterDestrcuturingDeclaration.ts(3,14): error TS2842: 'boolean' is an unused renaming of 'p'. Did you intend to use it as a type annotation? ==== tests/cases/compiler/paramterDestrcuturingDeclaration.ts (2 errors) ==== interface C { ({p: name}): any; ~~~~ -!!! error TS2842: Variable 'name' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'name' is an unused renaming of 'p'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/paramterDestrcuturingDeclaration.ts:2:14: We can only write a type for '{p: name}' by adding a type for the entire parameter here. new ({p: boolean}): any; ~~~~~~~ -!!! error TS2842: Variable 'boolean' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'boolean' is an unused renaming of 'p'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/paramterDestrcuturingDeclaration.ts:3:21: We can only write a type for '{p: boolean}' by adding a type for the entire parameter here. } \ No newline at end of file diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt index 189333949ae82..0de9080e6368a 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/jsx/file.tsx(17,39): error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +tests/cases/conformance/jsx/file.tsx(17,39): error TS2842: 'string' is an unused renaming of 'y1'. Did you intend to use it as a type annotation? ==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== @@ -20,7 +20,8 @@ tests/cases/conformance/jsx/file.tsx(17,39): error TS2842: Variable 'string' is declare function TestingOneThing({y1: string}): JSX.Element; ~~~~~~ -!!! error TS2842: Variable 'string' is not used. Did you mean to write a type annotation for whole object? +!!! error TS2842: 'string' is an unused renaming of 'y1'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/conformance/jsx/file.tsx:17:45: We can only write a type for '{y1: string}' by adding a type for the entire parameter here. declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element; declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element; declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; From bc92945b132509ad2d572ee2cc31cf1a1a991bb3 Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 14:24:59 +0900 Subject: [PATCH 24/31] add symbol-keyed test case --- ...tructuredPropertyInFunctionType.errors.txt | 61 ++- ...amingDestructuredPropertyInFunctionType.js | 14 +- ...DestructuredPropertyInFunctionType.symbols | 362 +++++++++--------- ...ngDestructuredPropertyInFunctionType.types | 15 +- ...ructuredPropertyInFunctionType3.errors.txt | 18 + ...mingDestructuredPropertyInFunctionType3.js | 14 + ...estructuredPropertyInFunctionType3.symbols | 25 ++ ...gDestructuredPropertyInFunctionType3.types | 27 ++ ...amingDestructuredPropertyInFunctionType.ts | 7 +- ...mingDestructuredPropertyInFunctionType3.ts | 7 + 10 files changed, 301 insertions(+), 249 deletions(-) create mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.errors.txt create mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.js create mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.symbols create mode 100644 tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.types create mode 100644 tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index 61260d9c84927..7975294f6ac62 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -1,31 +1,29 @@ +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(5,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(6,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(7,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(9,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(10,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(12,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,20): error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,18): error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(17,22): error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,20): error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(13,20): error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(14,18): error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,22): error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,20): error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(19,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(20,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(21,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(22,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(23,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(25,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,24): error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(31,22): error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(32,26): error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(33,24): error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(38,16): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(41,9): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,24): error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(28,22): error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(29,26): error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,24): error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(34,16): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(37,9): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(40,13): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? ==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (21 errors) ==== // GH#37454, GH#41044 - const sym = Symbol(); - type O = { a?: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error @@ -44,25 +42,24 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error type F7 = ({ a: string, b: number }) => typeof number; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:12:35: We can only write a type for '{ a: string, b: number }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:10:35: We can only write a type for '{ a: string, b: number }' by adding a type for the entire parameter here. type F8 = ({ a, b: number }) => typeof number; // OK type F9 = ([a, b, c]) => void; // Error type F10 = ({ "a": string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:15:27: We can only write a type for '{ "a": string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:13:27: We can only write a type for '{ "a": string }' by adding a type for the entire parameter here. type F11 = ({ 2: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:16:25: We can only write a type for '{ 2: string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:14:25: We can only write a type for '{ 2: string }' by adding a type for the entire parameter here. type F12 = ({ ["a"]: string }: O) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? type F13 = ({ [2]: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:18:27: We can only write a type for '{ [2]: string }' by adding a type for the entire parameter here. - // type F14 = ({ [sym]: string }) => void; // Error +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:16:27: We can only write a type for '{ [2]: string }' by adding a type for the entire parameter here. type G1 = new (arg: number) => any; // OK type G2 = new ({ a: string }: O) => any; // Error @@ -81,44 +78,43 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error type G7 = new ({ a: string, b: number }) => typeof number; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:27:39: We can only write a type for '{ a: string, b: number }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:24:39: We can only write a type for '{ a: string, b: number }' by adding a type for the entire parameter here. type G8 = new ({ a, b: number }) => typeof number; // OK type G9 = new ([a, b, c]) => void; // Error type G10 = new ({ "a": string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:30:31: We can only write a type for '{ "a": string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:27:31: We can only write a type for '{ "a": string }' by adding a type for the entire parameter here. type G11 = new ({ 2: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:31:29: We can only write a type for '{ 2: string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:28:29: We can only write a type for '{ 2: string }' by adding a type for the entire parameter here. type G12 = new ({ ["a"]: string }: O) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? type G13 = new ({ [2]: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:33:31: We can only write a type for '{ [2]: string }' by adding a type for the entire parameter here. - // type G14 = new ({ [sym]: string }) => void; // Error +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:30:31: We can only write a type for '{ [2]: string }' by adding a type for the entire parameter here. interface I { method1(arg: number): any; // OK method2({ a: string }): any; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:38:23: We can only write a type for '{ a: string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:34:23: We can only write a type for '{ a: string }' by adding a type for the entire parameter here. (arg: number): any; // OK ({ a: string }): any; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:41:16: We can only write a type for '{ a: string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:37:16: We can only write a type for '{ a: string }' by adding a type for the entire parameter here. new (arg: number): any; // OK new ({ a: string }): any; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:44:20: We can only write a type for '{ a: string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:40:20: We can only write a type for '{ a: string }' by adding a type for the entire parameter here. } // Below are OK but renaming should be removed from declaration emit @@ -139,7 +135,6 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(44,13): error function f9 ({ 2: string }) { }; function f10 ({ ["a"]: string }: O) { }; const f11 = ({ [2]: string }) => { }; - // const f12 = ({ [sym]: string }) => { }; // In below case `string` should be kept because it is used - function f13({ a: string = "" }: O): typeof string { return "a"; } \ No newline at end of file + function f12({ a: string = "" }: O): typeof string { return "a"; } \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js index 4306d4669533e..c7b5339584240 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js @@ -1,8 +1,6 @@ //// [renamingDestructuredPropertyInFunctionType.ts] // GH#37454, GH#41044 -const sym = Symbol(); - type O = { a?: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error @@ -17,7 +15,6 @@ type F10 = ({ "a": string }) => void; // Error type F11 = ({ 2: string }) => void; // Error type F12 = ({ ["a"]: string }: O) => void; // Error type F13 = ({ [2]: string }) => void; // Error -// type F14 = ({ [sym]: string }) => void; // Error type G1 = new (arg: number) => any; // OK type G2 = new ({ a: string }: O) => any; // Error @@ -32,7 +29,6 @@ type G10 = new ({ "a": string }) => void; // Error type G11 = new ({ 2: string }) => void; // Error type G12 = new ({ ["a"]: string }: O) => void; // Error type G13 = new ({ [2]: string }) => void; // Error -// type G14 = new ({ [sym]: string }) => void; // Error interface I { method1(arg: number): any; // OK @@ -63,14 +59,12 @@ const f8 = ({ "a": string }: O) => { }; function f9 ({ 2: string }) { }; function f10 ({ ["a"]: string }: O) { }; const f11 = ({ [2]: string }) => { }; -// const f12 = ({ [sym]: string }) => { }; // In below case `string` should be kept because it is used -function f13({ a: string = "" }: O): typeof string { return "a"; } +function f12({ a: string = "" }: O): typeof string { return "a"; } //// [renamingDestructuredPropertyInFunctionType.js] // GH#37454, GH#41044 -const sym = Symbol(); // Below are OK but renaming should be removed from declaration emit function f1({ a: string }) { } const f2 = function ({ a: string }) { }; @@ -91,13 +85,11 @@ function f9({ 2: string }) { } function f10({ ["a"]: string }) { } ; const f11 = ({ [2]: string }) => { }; -// const f12 = ({ [sym]: string }) => { }; // In below case `string` should be kept because it is used -function f13({ a: string = "" }) { return "a"; } +function f12({ a: string = "" }) { return "a"; } //// [renamingDestructuredPropertyInFunctionType.d.ts] -declare const sym: unique symbol; declare type O = { a?: string; b: number; @@ -192,4 +184,4 @@ declare function f10({ ["a"]: string }: O): void; declare const f11: ({ [2]: string }: { 2: any; }) => void; -declare function f13({ a: string }: O): typeof string; +declare function f12({ a: string }: O): typeof string; diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols index e299e57965056..0e55d8c000b81 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols @@ -1,304 +1,294 @@ === tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === // GH#37454, GH#41044 -const sym = Symbol(); ->sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 5)) ->Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) - type O = { a?: string; b: number; c: number; }; ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 22)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 33)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 22)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 33)) type F1 = (arg: number) => any; // OK ->F1 : Symbol(F1, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 47)) ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 11)) +>F1 : Symbol(F1, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 47)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 11)) type F2 = ({ a: string }: O) => any; // Error ->F2 : Symbol(F2, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 31)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 12)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>F2 : Symbol(F2, Decl(renamingDestructuredPropertyInFunctionType.ts, 3, 31)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 12)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type F3 = ({ a: string, b, c }: O) => any; // Error ->F3 : Symbol(F3, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 36)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 23)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 26)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>F3 : Symbol(F3, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 36)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 23)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 26)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type F4 = ({ a: string }: O) => any; // Error ->F4 : Symbol(F4, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 42)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>F4 : Symbol(F4, Decl(renamingDestructuredPropertyInFunctionType.ts, 5, 42)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 12)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type F5 = ({ a: string, b, c }: O) => any; // Error ->F5 : Symbol(F5, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 36)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 23)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 26)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>F5 : Symbol(F5, Decl(renamingDestructuredPropertyInFunctionType.ts, 6, 36)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 23)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 26)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type F6 = ({ a: string }) => typeof string; // OK ->F6 : Symbol(F6, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 42)) +>F6 : Symbol(F6, Decl(renamingDestructuredPropertyInFunctionType.ts, 7, 42)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 12)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 12)) type F7 = ({ a: string, b: number }) => typeof number; // Error ->F7 : Symbol(F7, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 43)) +>F7 : Symbol(F7, Decl(renamingDestructuredPropertyInFunctionType.ts, 8, 43)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 12)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 12)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 23)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 23)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 23)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 23)) type F8 = ({ a, b: number }) => typeof number; // OK ->F8 : Symbol(F8, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 54)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 12)) +>F8 : Symbol(F8, Decl(renamingDestructuredPropertyInFunctionType.ts, 9, 54)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 12)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 15)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 15)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 15)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 15)) type F9 = ([a, b, c]) => void; // Error ->F9 : Symbol(F9, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 46)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 12)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 14)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 17)) +>F9 : Symbol(F9, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 46)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 12)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 14)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 17)) type F10 = ({ "a": string }) => void; // Error ->F10 : Symbol(F10, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 30)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 13)) +>F10 : Symbol(F10, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 30)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 13)) type F11 = ({ 2: string }) => void; // Error ->F11 : Symbol(F11, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 37)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 13)) +>F11 : Symbol(F11, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 37)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 13)) type F12 = ({ ["a"]: string }: O) => void; // Error ->F12 : Symbol(F12, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 35)) ->"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 13)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 13)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>F12 : Symbol(F12, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 35)) +>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 13)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type F13 = ({ [2]: string }) => void; // Error ->F13 : Symbol(F13, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 42)) ->2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 13)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 13)) - -// type F14 = ({ [sym]: string }) => void; // Error +>F13 : Symbol(F13, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 42)) +>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 13)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 13)) type G1 = new (arg: number) => any; // OK ->G1 : Symbol(G1, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 37)) ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 15)) +>G1 : Symbol(G1, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 37)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 15)) type G2 = new ({ a: string }: O) => any; // Error ->G2 : Symbol(G2, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 35)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 16)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>G2 : Symbol(G2, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 35)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 16)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G3 = new ({ a: string, b, c }: O) => any; // Error ->G3 : Symbol(G3, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 40)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 16)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 27)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 30)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>G3 : Symbol(G3, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 40)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 16)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 27)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 30)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G4 = new ({ a: string }: O) => any; // Error ->G4 : Symbol(G4, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 46)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 16)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>G4 : Symbol(G4, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 46)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 16)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G5 = new ({ a: string, b, c }: O) => any; // Error ->G5 : Symbol(G5, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 40)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 16)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 27)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 30)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>G5 : Symbol(G5, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 40)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 16)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 27)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 30)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G6 = new ({ a: string }) => typeof string; // OK ->G6 : Symbol(G6, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 46)) +>G6 : Symbol(G6, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 46)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 16)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 16)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 16)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 16)) type G7 = new ({ a: string, b: number }) => typeof number; // Error ->G7 : Symbol(G7, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 47)) +>G7 : Symbol(G7, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 47)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 16)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 16)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 27)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 27)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 27)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 27)) type G8 = new ({ a, b: number }) => typeof number; // OK ->G8 : Symbol(G8, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 58)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 16)) +>G8 : Symbol(G8, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 58)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 16)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 19)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 19)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 19)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 19)) type G9 = new ([a, b, c]) => void; // Error ->G9 : Symbol(G9, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 50)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 16)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 18)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 21)) +>G9 : Symbol(G9, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 50)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 16)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 18)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 21)) type G10 = new ({ "a": string }) => void; // Error ->G10 : Symbol(G10, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 34)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 17)) +>G10 : Symbol(G10, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 34)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 17)) type G11 = new ({ 2: string }) => void; // Error ->G11 : Symbol(G11, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 41)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 30, 17)) +>G11 : Symbol(G11, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 41)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 17)) type G12 = new ({ ["a"]: string }: O) => void; // Error ->G12 : Symbol(G12, Decl(renamingDestructuredPropertyInFunctionType.ts, 30, 39)) ->"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 17)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 17)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>G12 : Symbol(G12, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 39)) +>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 17)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 17)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G13 = new ({ [2]: string }) => void; // Error ->G13 : Symbol(G13, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 46)) ->2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 17)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 17)) - -// type G14 = new ({ [sym]: string }) => void; // Error +>G13 : Symbol(G13, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 46)) +>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 17)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 17)) interface I { ->I : Symbol(I, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 41)) +>I : Symbol(I, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 41)) method1(arg: number): any; // OK ->method1 : Symbol(I.method1, Decl(renamingDestructuredPropertyInFunctionType.ts, 35, 13)) ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 10)) +>method1 : Symbol(I.method1, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 13)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 10)) method2({ a: string }): any; // Error ->method2 : Symbol(I.method2, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 28)) +>method2 : Symbol(I.method2, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 28)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 37, 11)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 33, 11)) (arg: number): any; // OK ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 3)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 35, 3)) ({ a: string }): any; // Error >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 40, 4)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 4)) new (arg: number): any; // OK ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 42, 7)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 7)) new ({ a: string }): any; // Error >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 43, 8)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 8)) } // Below are OK but renaming should be removed from declaration emit function f1({ a: string }: O) { } ->f1 : Symbol(f1, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 1)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 13)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>f1 : Symbol(f1, Decl(renamingDestructuredPropertyInFunctionType.ts, 40, 1)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 43, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) const f2 = function({ a: string }: O) { }; ->f2 : Symbol(f2, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 5)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 21)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>f2 : Symbol(f2, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 21)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) const f3 = ({ a: string, b, c }: O) => { }; ->f3 : Symbol(f3, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 5)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 13)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 24)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 27)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>f3 : Symbol(f3, Decl(renamingDestructuredPropertyInFunctionType.ts, 45, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 45, 13)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 45, 24)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 45, 27)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) const f4 = function({ a: string }: O): typeof string { return string; }; ->f4 : Symbol(f4, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 5)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 21)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 21)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 21)) +>f4 : Symbol(f4, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 21)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 21)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 21)) const f5 = ({ a: string, b, c }: O): typeof string => ''; ->f5 : Symbol(f5, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 5)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 13)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 24)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 27)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 13)) +>f5 : Symbol(f5, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 13)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 24)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 27)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 13)) const obj1 = { ->obj1 : Symbol(obj1, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 5)) +>obj1 : Symbol(obj1, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 5)) method({ a: string }: O) { } ->method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 14)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 53, 10)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 14)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 10)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) }; const obj2 = { ->obj2 : Symbol(obj2, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 5)) +>obj2 : Symbol(obj2, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 5)) method({ a: string }: O): typeof string { return string; } ->method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 14)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 10)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 10)) +>method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 14)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 10)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 10)) }; function f6({ a: string = "" }: O) { } ->f6 : Symbol(f6, Decl(renamingDestructuredPropertyInFunctionType.ts, 57, 2)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 13)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>f6 : Symbol(f6, Decl(renamingDestructuredPropertyInFunctionType.ts, 53, 2)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 54, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) const f7 = ({ a: string = "", b, c }: O) => { }; ->f7 : Symbol(f7, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 5)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 13)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 29)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 32)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>f7 : Symbol(f7, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 5)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 13)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 29)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 32)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) const f8 = ({ "a": string }: O) => { }; ->f8 : Symbol(f8, Decl(renamingDestructuredPropertyInFunctionType.ts, 60, 5)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 60, 13)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>f8 : Symbol(f8, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 5)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) function f9 ({ 2: string }) { }; ->f9 : Symbol(f9, Decl(renamingDestructuredPropertyInFunctionType.ts, 60, 39)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 61, 14)) +>f9 : Symbol(f9, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 39)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 57, 14)) function f10 ({ ["a"]: string }: O) { }; ->f10 : Symbol(f10, Decl(renamingDestructuredPropertyInFunctionType.ts, 61, 32)) ->"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 15)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 15)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) +>f10 : Symbol(f10, Decl(renamingDestructuredPropertyInFunctionType.ts, 57, 32)) +>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 15)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 15)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) const f11 = ({ [2]: string }) => { }; ->f11 : Symbol(f11, Decl(renamingDestructuredPropertyInFunctionType.ts, 63, 5)) ->2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 63, 15)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 63, 15)) - -// const f12 = ({ [sym]: string }) => { }; +>f11 : Symbol(f11, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 5)) +>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 15)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 15)) // In below case `string` should be kept because it is used -function f13({ a: string = "" }: O): typeof string { return "a"; } ->f13 : Symbol(f13, Decl(renamingDestructuredPropertyInFunctionType.ts, 63, 38)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 4, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 67, 14)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 21)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 67, 14)) +function f12({ a: string = "" }: O): typeof string { return "a"; } +>f12 : Symbol(f12, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 38)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 14)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 14)) diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types index d01ff5ab21111..f950dd1685d6f 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types @@ -1,11 +1,6 @@ === tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts === // GH#37454, GH#41044 -const sym = Symbol(); ->sym : unique symbol ->Symbol() : unique symbol ->Symbol : SymbolConstructor - type O = { a?: string; b: number; c: number; }; >O : { a?: string; b: number; c: number; } >a : string @@ -85,8 +80,6 @@ type F13 = ({ [2]: string }) => void; // Error >2 : 2 >string : any -// type F14 = ({ [sym]: string }) => void; // Error - type G1 = new (arg: number) => any; // OK >G1 : new (arg: number) => any >arg : number @@ -160,8 +153,6 @@ type G13 = new ({ [2]: string }) => void; // Error >2 : 2 >string : any -// type G14 = new ({ [sym]: string }) => void; // Error - interface I { method1(arg: number): any; // OK >method1 : (arg: number) => any @@ -282,11 +273,9 @@ const f11 = ({ [2]: string }) => { }; >2 : 2 >string : any -// const f12 = ({ [sym]: string }) => { }; - // In below case `string` should be kept because it is used -function f13({ a: string = "" }: O): typeof string { return "a"; } ->f13 : ({ a }: O) => typeof string +function f12({ a: string = "" }: O): typeof string { return "a"; } +>f12 : ({ a }: O) => typeof string >a : any >string : string >"" : "" diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.errors.txt new file mode 100644 index 0000000000000..46df84d2e4579 --- /dev/null +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts(2,22): error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts(3,26): error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation? + + +==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts (2 errors) ==== + const sym = Symbol(); + type F14 = ({ [sym]: string }) => void; // Error + ~~~~~~ +!!! error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts:2:29: We can only write a type for '{ [sym]: string }' by adding a type for the entire parameter here. + type G14 = new ({ [sym]: string }) => void; // Error + ~~~~~~ +!!! error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts:3:33: We can only write a type for '{ [sym]: string }' by adding a type for the entire parameter here. + + const f13 = ({ [sym]: string }) => { }; + function f14 ({ [sym]: string }) { }; + \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.js new file mode 100644 index 0000000000000..2a38852c88c69 --- /dev/null +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.js @@ -0,0 +1,14 @@ +//// [renamingDestructuredPropertyInFunctionType3.ts] +const sym = Symbol(); +type F14 = ({ [sym]: string }) => void; // Error +type G14 = new ({ [sym]: string }) => void; // Error + +const f13 = ({ [sym]: string }) => { }; +function f14 ({ [sym]: string }) { }; + + +//// [renamingDestructuredPropertyInFunctionType3.js] +const sym = Symbol(); +const f13 = ({ [sym]: string }) => { }; +function f14({ [sym]: string }) { } +; diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.symbols b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.symbols new file mode 100644 index 0000000000000..02b4d415ebb65 --- /dev/null +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.symbols @@ -0,0 +1,25 @@ +=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts === +const sym = Symbol(); +>sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +type F14 = ({ [sym]: string }) => void; // Error +>F14 : Symbol(F14, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 21)) +>sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 1, 13)) + +type G14 = new ({ [sym]: string }) => void; // Error +>G14 : Symbol(G14, Decl(renamingDestructuredPropertyInFunctionType3.ts, 1, 39)) +>sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 2, 17)) + +const f13 = ({ [sym]: string }) => { }; +>f13 : Symbol(f13, Decl(renamingDestructuredPropertyInFunctionType3.ts, 4, 5)) +>sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 4, 15)) + +function f14 ({ [sym]: string }) { }; +>f14 : Symbol(f14, Decl(renamingDestructuredPropertyInFunctionType3.ts, 4, 40)) +>sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 5, 15)) + diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.types new file mode 100644 index 0000000000000..d50f7b6155ef3 --- /dev/null +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts === +const sym = Symbol(); +>sym : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +type F14 = ({ [sym]: string }) => void; // Error +>F14 : ({ [sym]: string }: { "__@sym@420": any; }) => void +>sym : unique symbol +>string : any + +type G14 = new ({ [sym]: string }) => void; // Error +>G14 : new ({ [sym]: string }: { "__@sym@420": any; }) => void +>sym : unique symbol +>string : any + +const f13 = ({ [sym]: string }) => { }; +>f13 : ({ [sym]: string }: { "__@sym@420": any; }) => void +>({ [sym]: string }) => { } : ({ [sym]: string }: { "__@sym@420": any; }) => void +>sym : unique symbol +>string : any + +function f14 ({ [sym]: string }) { }; +>f14 : ({ [sym]: string }: { "__@sym@420": any; }) => void +>sym : unique symbol +>string : any + diff --git a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts index ce3228a37743f..f128e18e3d723 100644 --- a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts +++ b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts @@ -2,8 +2,6 @@ // @declaration: true // GH#37454, GH#41044 -const sym = Symbol(); - type O = { a?: string; b: number; c: number; }; type F1 = (arg: number) => any; // OK type F2 = ({ a: string }: O) => any; // Error @@ -18,7 +16,6 @@ type F10 = ({ "a": string }) => void; // Error type F11 = ({ 2: string }) => void; // Error type F12 = ({ ["a"]: string }: O) => void; // Error type F13 = ({ [2]: string }) => void; // Error -// type F14 = ({ [sym]: string }) => void; // Error type G1 = new (arg: number) => any; // OK type G2 = new ({ a: string }: O) => any; // Error @@ -33,7 +30,6 @@ type G10 = new ({ "a": string }) => void; // Error type G11 = new ({ 2: string }) => void; // Error type G12 = new ({ ["a"]: string }: O) => void; // Error type G13 = new ({ [2]: string }) => void; // Error -// type G14 = new ({ [sym]: string }) => void; // Error interface I { method1(arg: number): any; // OK @@ -64,7 +60,6 @@ const f8 = ({ "a": string }: O) => { }; function f9 ({ 2: string }) { }; function f10 ({ ["a"]: string }: O) { }; const f11 = ({ [2]: string }) => { }; -// const f12 = ({ [sym]: string }) => { }; // In below case `string` should be kept because it is used -function f13({ a: string = "" }: O): typeof string { return "a"; } \ No newline at end of file +function f12({ a: string = "" }: O): typeof string { return "a"; } \ No newline at end of file diff --git a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts new file mode 100644 index 0000000000000..e2e3bc8f45ea0 --- /dev/null +++ b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts @@ -0,0 +1,7 @@ +// @target: es2015 +const sym = Symbol(); +type F14 = ({ [sym]: string }) => void; // Error +type G14 = new ({ [sym]: string }) => void; // Error + +const f13 = ({ [sym]: string }) => { }; +function f14 ({ [sym]: string }) { }; From e2710b75098b7e3952f77be40cac3808695a21e7 Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 14:47:07 +0900 Subject: [PATCH 25/31] oops? --- .../renamingDestructuredPropertyInFunctionType3.types | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.types index d50f7b6155ef3..53efd33aed62e 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.types @@ -5,23 +5,23 @@ const sym = Symbol(); >Symbol : SymbolConstructor type F14 = ({ [sym]: string }) => void; // Error ->F14 : ({ [sym]: string }: { "__@sym@420": any; }) => void +>F14 : ({ [sym]: string }: { "__@sym@6": any; }) => void >sym : unique symbol >string : any type G14 = new ({ [sym]: string }) => void; // Error ->G14 : new ({ [sym]: string }: { "__@sym@420": any; }) => void +>G14 : new ({ [sym]: string }: { "__@sym@6": any; }) => void >sym : unique symbol >string : any const f13 = ({ [sym]: string }) => { }; ->f13 : ({ [sym]: string }: { "__@sym@420": any; }) => void ->({ [sym]: string }) => { } : ({ [sym]: string }: { "__@sym@420": any; }) => void +>f13 : ({ [sym]: string }: { "__@sym@6": any; }) => void +>({ [sym]: string }) => { } : ({ [sym]: string }: { "__@sym@6": any; }) => void >sym : unique symbol >string : any function f14 ({ [sym]: string }) { }; ->f14 : ({ [sym]: string }: { "__@sym@420": any; }) => void +>f14 : ({ [sym]: string }: { "__@sym@6": any; }) => void >sym : unique symbol >string : any From 1e4c14bdb64ab3e308a2f9ca12b48a11c8446534 Mon Sep 17 00:00:00 2001 From: uhyo Date: Thu, 9 Jun 2022 15:11:00 +0900 Subject: [PATCH 26/31] workaround for unstable test --- ...ructuredPropertyInFunctionType3.errors.txt | 15 ++++----- ...mingDestructuredPropertyInFunctionType3.js | 9 +++--- ...estructuredPropertyInFunctionType3.symbols | 32 ++++++++++++------- ...gDestructuredPropertyInFunctionType3.types | 29 +++++++++-------- ...mingDestructuredPropertyInFunctionType3.ts | 9 +++--- 5 files changed, 53 insertions(+), 41 deletions(-) diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.errors.txt index 46df84d2e4579..c109b35de7713 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.errors.txt @@ -1,18 +1,17 @@ -tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts(2,22): error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts(3,26): error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts(3,22): error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts(4,26): error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation? ==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts (2 errors) ==== const sym = Symbol(); - type F14 = ({ [sym]: string }) => void; // Error + type O = Record + type F14 = ({ [sym]: string }: O) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts:2:29: We can only write a type for '{ [sym]: string }' by adding a type for the entire parameter here. - type G14 = new ({ [sym]: string }) => void; // Error + type G14 = new ({ [sym]: string }: O) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '[sym]'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts:3:33: We can only write a type for '{ [sym]: string }' by adding a type for the entire parameter here. - const f13 = ({ [sym]: string }) => { }; - function f14 ({ [sym]: string }) { }; + const f13 = ({ [sym]: string }: O) => { }; + function f14 ({ [sym]: string }: O) { }; \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.js index 2a38852c88c69..ec06977c4f77d 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.js +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.js @@ -1,10 +1,11 @@ //// [renamingDestructuredPropertyInFunctionType3.ts] const sym = Symbol(); -type F14 = ({ [sym]: string }) => void; // Error -type G14 = new ({ [sym]: string }) => void; // Error +type O = Record +type F14 = ({ [sym]: string }: O) => void; // Error +type G14 = new ({ [sym]: string }: O) => void; // Error -const f13 = ({ [sym]: string }) => { }; -function f14 ({ [sym]: string }) { }; +const f13 = ({ [sym]: string }: O) => { }; +function f14 ({ [sym]: string }: O) { }; //// [renamingDestructuredPropertyInFunctionType3.js] diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.symbols b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.symbols index 02b4d415ebb65..6a645a13b5c80 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.symbols +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.symbols @@ -3,23 +3,31 @@ const sym = Symbol(); >sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5)) >Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) -type F14 = ({ [sym]: string }) => void; // Error ->F14 : Symbol(F14, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 21)) ->sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 1, 13)) +type O = Record +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 21)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) -type G14 = new ({ [sym]: string }) => void; // Error ->G14 : Symbol(G14, Decl(renamingDestructuredPropertyInFunctionType3.ts, 1, 39)) +type F14 = ({ [sym]: string }: O) => void; // Error +>F14 : Symbol(F14, Decl(renamingDestructuredPropertyInFunctionType3.ts, 1, 32)) >sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 2, 17)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 2, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 21)) -const f13 = ({ [sym]: string }) => { }; ->f13 : Symbol(f13, Decl(renamingDestructuredPropertyInFunctionType3.ts, 4, 5)) +type G14 = new ({ [sym]: string }: O) => void; // Error +>G14 : Symbol(G14, Decl(renamingDestructuredPropertyInFunctionType3.ts, 2, 42)) >sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 4, 15)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 3, 17)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 21)) -function f14 ({ [sym]: string }) { }; ->f14 : Symbol(f14, Decl(renamingDestructuredPropertyInFunctionType3.ts, 4, 40)) +const f13 = ({ [sym]: string }: O) => { }; +>f13 : Symbol(f13, Decl(renamingDestructuredPropertyInFunctionType3.ts, 5, 5)) >sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5)) >string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 5, 15)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 21)) + +function f14 ({ [sym]: string }: O) { }; +>f14 : Symbol(f14, Decl(renamingDestructuredPropertyInFunctionType3.ts, 5, 43)) +>sym : Symbol(sym, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 5)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType3.ts, 6, 15)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType3.ts, 0, 21)) diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.types index 53efd33aed62e..b195de75dce27 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType3.types @@ -4,24 +4,27 @@ const sym = Symbol(); >Symbol() : unique symbol >Symbol : SymbolConstructor -type F14 = ({ [sym]: string }) => void; // Error ->F14 : ({ [sym]: string }: { "__@sym@6": any; }) => void +type O = Record +>O : { [x: symbol]: unknown; } + +type F14 = ({ [sym]: string }: O) => void; // Error +>F14 : ({ [sym]: string }: O) => void >sym : unique symbol ->string : any +>string : unknown -type G14 = new ({ [sym]: string }) => void; // Error ->G14 : new ({ [sym]: string }: { "__@sym@6": any; }) => void +type G14 = new ({ [sym]: string }: O) => void; // Error +>G14 : new ({ [sym]: string }: O) => void >sym : unique symbol ->string : any +>string : unknown -const f13 = ({ [sym]: string }) => { }; ->f13 : ({ [sym]: string }: { "__@sym@6": any; }) => void ->({ [sym]: string }) => { } : ({ [sym]: string }: { "__@sym@6": any; }) => void +const f13 = ({ [sym]: string }: O) => { }; +>f13 : ({ [sym]: string }: O) => void +>({ [sym]: string }: O) => { } : ({ [sym]: string }: O) => void >sym : unique symbol ->string : any +>string : unknown -function f14 ({ [sym]: string }) { }; ->f14 : ({ [sym]: string }: { "__@sym@6": any; }) => void +function f14 ({ [sym]: string }: O) { }; +>f14 : ({ [sym]: string }: O) => void >sym : unique symbol ->string : any +>string : unknown diff --git a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts index e2e3bc8f45ea0..4b90494734855 100644 --- a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts +++ b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType3.ts @@ -1,7 +1,8 @@ // @target: es2015 const sym = Symbol(); -type F14 = ({ [sym]: string }) => void; // Error -type G14 = new ({ [sym]: string }) => void; // Error +type O = Record +type F14 = ({ [sym]: string }: O) => void; // Error +type G14 = new ({ [sym]: string }: O) => void; // Error -const f13 = ({ [sym]: string }) => { }; -function f14 ({ [sym]: string }) { }; +const f13 = ({ [sym]: string }: O) => { }; +function f14 ({ [sym]: string }: O) { }; From 4e519ff49c1a849cc21cff318d3ce91a380d7c82 Mon Sep 17 00:00:00 2001 From: uhyo Date: Fri, 10 Jun 2022 10:25:30 +0900 Subject: [PATCH 27/31] fix suggested name --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4f1a86fabc44b..23230031dce3e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37585,7 +37585,7 @@ namespace ts { // entire parameter does not have type annotation, suggest adding an annotation addRelatedInfo( diagnostic, - createFileDiagnostic(getSourceFileOfNode(wrappingDeclaration), wrappingDeclaration.end - 1, 1,Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here, declarationNameToString(wrappingDeclaration.name)) + createFileDiagnostic(getSourceFileOfNode(wrappingDeclaration), wrappingDeclaration.end - 1, 1, Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here, declarationNameToString(node.propertyName)) ); } diagnostics.add(diagnostic); From 07f162f3b196f1ad7ea3fcb38c1186feb333756f Mon Sep 17 00:00:00 2001 From: uhyo Date: Fri, 10 Jun 2022 10:27:58 +0900 Subject: [PATCH 28/31] add comment about non-identifier property names --- .../renamingDestructuredPropertyInFunctionType.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts index f128e18e3d723..5714dcb887e02 100644 --- a/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts +++ b/tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts @@ -11,11 +11,7 @@ type F5 = ({ a: string, b, c }: O) => any; // Error type F6 = ({ a: string }) => typeof string; // OK type F7 = ({ a: string, b: number }) => typeof number; // Error type F8 = ({ a, b: number }) => typeof number; // OK -type F9 = ([a, b, c]) => void; // Error -type F10 = ({ "a": string }) => void; // Error -type F11 = ({ 2: string }) => void; // Error -type F12 = ({ ["a"]: string }: O) => void; // Error -type F13 = ({ [2]: string }) => void; // Error +type F9 = ([a, b, c]) => void; // OK type G1 = new (arg: number) => any; // OK type G2 = new ({ a: string }: O) => any; // Error @@ -25,7 +21,14 @@ type G5 = new ({ a: string, b, c }: O) => any; // Error type G6 = new ({ a: string }) => typeof string; // OK type G7 = new ({ a: string, b: number }) => typeof number; // Error type G8 = new ({ a, b: number }) => typeof number; // OK -type G9 = new ([a, b, c]) => void; // Error +type G9 = new ([a, b, c]) => void; // OK + +// Below are Error but renaming is retained in declaration emit, +// since elinding it would leave invalid syntax. +type F10 = ({ "a": string }) => void; // Error +type F11 = ({ 2: string }) => void; // Error +type F12 = ({ ["a"]: string }: O) => void; // Error +type F13 = ({ [2]: string }) => void; // Error type G10 = new ({ "a": string }) => void; // Error type G11 = new ({ 2: string }) => void; // Error type G12 = new ({ ["a"]: string }: O) => void; // Error From 6c8a95ba6126ee18197e75f6498baac5ee41e1bf Mon Sep 17 00:00:00 2001 From: uhyo Date: Fri, 10 Jun 2022 10:28:07 +0900 Subject: [PATCH 29/31] simplify isReferenced check --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 23230031dce3e..a18017e4a07da 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37577,7 +37577,7 @@ namespace ts { function checkPotentialUncheckedRenamedBindingElementsInTypes() { for (const node of potentialUnusedRenamedBindingElementsInTypes) { - if (!(getSymbolOfNode(node)?.isReferenced! & SymbolFlags.Type)) { + if (!getSymbolOfNode(node)?.isReferenced) { const wrappingDeclaration = walkUpBindingElementsAndPatterns(node); Debug.assert(isParameterDeclaration(wrappingDeclaration), "Only parameter declaration should be checked here"); const diagnostic = createDiagnosticForNode(node.name, Diagnostics._0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation, declarationNameToString(node.name), declarationNameToString(node.propertyName)); From bd0da300ea2bbaf1ddd14566d9f059b217d9650b Mon Sep 17 00:00:00 2001 From: uhyo Date: Fri, 10 Jun 2022 10:46:55 +0900 Subject: [PATCH 30/31] accept baseline --- .../destructuringInFunctionType.errors.txt | 4 +- .../excessPropertyCheckWithSpread.errors.txt | 2 +- ...aramterDestrcuturingDeclaration.errors.txt | 4 +- ...tructuredPropertyInFunctionType.errors.txt | 83 ++++--- ...amingDestructuredPropertyInFunctionType.js | 35 +-- ...DestructuredPropertyInFunctionType.symbols | 228 +++++++++--------- ...ngDestructuredPropertyInFunctionType.types | 42 ++-- ...elessFunctionComponentOverload1.errors.txt | 2 +- 8 files changed, 205 insertions(+), 195 deletions(-) diff --git a/tests/baselines/reference/destructuringInFunctionType.errors.txt b/tests/baselines/reference/destructuringInFunctionType.errors.txt index 718d76678600d..19751a3511c4a 100644 --- a/tests/baselines/reference/destructuringInFunctionType.errors.txt +++ b/tests/baselines/reference/destructuringInFunctionType.errors.txt @@ -17,10 +17,10 @@ tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,28): type F3 = ([{ a: b }, { b: a }]) => void; ~ !!! error TS2842: 'b' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:31: We can only write a type for '[{ a: b }, { b: a }]' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:31: We can only write a type for 'a' by adding a type for the entire parameter here. ~ !!! error TS2842: 'a' is an unused renaming of 'b'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:31: We can only write a type for '[{ a: b }, { b: a }]' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:31: We can only write a type for 'b' by adding a type for the entire parameter here. type T4 = ([{ a: [b, c] }]); type F4 = ([{ a: [b, c] }]) => void; diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt index 8c36a9512093f..182cb9ca3add1 100644 --- a/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/excessPropertyCheckWithSpread.ts(1,25): error TS2842: 'numb declare function f({ a: number }): void ~~~~~~ !!! error TS2842: 'number' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/excessPropertyCheckWithSpread.ts:1:32: We can only write a type for '{ a: number }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/excessPropertyCheckWithSpread.ts:1:32: We can only write a type for 'a' by adding a type for the entire parameter here. interface I { readonly n: number; } diff --git a/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt b/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt index fab67b5b42522..e760900375241 100644 --- a/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt +++ b/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt @@ -7,10 +7,10 @@ tests/cases/compiler/paramterDestrcuturingDeclaration.ts(3,14): error TS2842: 'b ({p: name}): any; ~~~~ !!! error TS2842: 'name' is an unused renaming of 'p'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/paramterDestrcuturingDeclaration.ts:2:14: We can only write a type for '{p: name}' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/paramterDestrcuturingDeclaration.ts:2:14: We can only write a type for 'p' by adding a type for the entire parameter here. new ({p: boolean}): any; ~~~~~~~ !!! error TS2842: 'boolean' is an unused renaming of 'p'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/paramterDestrcuturingDeclaration.ts:3:21: We can only write a type for '{p: boolean}' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/paramterDestrcuturingDeclaration.ts:3:21: We can only write a type for 'p' by adding a type for the entire parameter here. } \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index 7975294f6ac62..3575dfcea9d83 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -3,22 +3,22 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(6,17): error tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(7,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(8,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(10,17): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(13,20): error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(14,18): error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,22): error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,20): error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(19,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(15,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(16,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(17,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(18,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(20,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(21,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(22,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(24,21): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,24): error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(28,22): error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(29,26): error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,24): error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(34,16): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(37,9): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(40,13): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(26,20): error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(27,18): error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(28,22): error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(29,20): error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(30,24): error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(31,22): error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(32,26): error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(33,24): error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(37,16): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(40,9): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? +tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(43,13): error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? ==== tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts (21 errors) ==== @@ -42,24 +42,9 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(40,13): error type F7 = ({ a: string, b: number }) => typeof number; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:10:35: We can only write a type for '{ a: string, b: number }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:10:35: We can only write a type for 'a' by adding a type for the entire parameter here. type F8 = ({ a, b: number }) => typeof number; // OK - type F9 = ([a, b, c]) => void; // Error - type F10 = ({ "a": string }) => void; // Error - ~~~~~~ -!!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:13:27: We can only write a type for '{ "a": string }' by adding a type for the entire parameter here. - type F11 = ({ 2: string }) => void; // Error - ~~~~~~ -!!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:14:25: We can only write a type for '{ 2: string }' by adding a type for the entire parameter here. - type F12 = ({ ["a"]: string }: O) => void; // Error - ~~~~~~ -!!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? - type F13 = ({ [2]: string }) => void; // Error - ~~~~~~ -!!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:16:27: We can only write a type for '{ [2]: string }' by adding a type for the entire parameter here. + type F9 = ([a, b, c]) => void; // OK type G1 = new (arg: number) => any; // OK type G2 = new ({ a: string }: O) => any; // Error @@ -78,43 +63,61 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(40,13): error type G7 = new ({ a: string, b: number }) => typeof number; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:24:39: We can only write a type for '{ a: string, b: number }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:20:39: We can only write a type for 'a' by adding a type for the entire parameter here. type G8 = new ({ a, b: number }) => typeof number; // OK - type G9 = new ([a, b, c]) => void; // Error + type G9 = new ([a, b, c]) => void; // OK + + // Below are Error but renaming is retained in declaration emit, + // since elinding it would leave invalid syntax. + type F10 = ({ "a": string }) => void; // Error + ~~~~~~ +!!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:26:27: We can only write a type for '"a"' by adding a type for the entire parameter here. + type F11 = ({ 2: string }) => void; // Error + ~~~~~~ +!!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:27:25: We can only write a type for '2' by adding a type for the entire parameter here. + type F12 = ({ ["a"]: string }: O) => void; // Error + ~~~~~~ +!!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? + type F13 = ({ [2]: string }) => void; // Error + ~~~~~~ +!!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:29:27: We can only write a type for '[2]' by adding a type for the entire parameter here. type G10 = new ({ "a": string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:27:31: We can only write a type for '{ "a": string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:30:31: We can only write a type for '"a"' by adding a type for the entire parameter here. type G11 = new ({ 2: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:28:29: We can only write a type for '{ 2: string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:31:29: We can only write a type for '2' by adding a type for the entire parameter here. type G12 = new ({ ["a"]: string }: O) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? type G13 = new ({ [2]: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:30:31: We can only write a type for '{ [2]: string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:33:31: We can only write a type for '[2]' by adding a type for the entire parameter here. interface I { method1(arg: number): any; // OK method2({ a: string }): any; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:34:23: We can only write a type for '{ a: string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:37:23: We can only write a type for 'a' by adding a type for the entire parameter here. (arg: number): any; // OK ({ a: string }): any; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:37:16: We can only write a type for '{ a: string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:40:16: We can only write a type for 'a' by adding a type for the entire parameter here. new (arg: number): any; // OK new ({ a: string }): any; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:40:20: We can only write a type for '{ a: string }' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:43:20: We can only write a type for 'a' by adding a type for the entire parameter here. } // Below are OK but renaming should be removed from declaration emit diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js index c7b5339584240..ac5fe3b3c35e0 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js @@ -10,11 +10,7 @@ type F5 = ({ a: string, b, c }: O) => any; // Error type F6 = ({ a: string }) => typeof string; // OK type F7 = ({ a: string, b: number }) => typeof number; // Error type F8 = ({ a, b: number }) => typeof number; // OK -type F9 = ([a, b, c]) => void; // Error -type F10 = ({ "a": string }) => void; // Error -type F11 = ({ 2: string }) => void; // Error -type F12 = ({ ["a"]: string }: O) => void; // Error -type F13 = ({ [2]: string }) => void; // Error +type F9 = ([a, b, c]) => void; // OK type G1 = new (arg: number) => any; // OK type G2 = new ({ a: string }: O) => any; // Error @@ -24,7 +20,14 @@ type G5 = new ({ a: string, b, c }: O) => any; // Error type G6 = new ({ a: string }) => typeof string; // OK type G7 = new ({ a: string, b: number }) => typeof number; // Error type G8 = new ({ a, b: number }) => typeof number; // OK -type G9 = new ([a, b, c]) => void; // Error +type G9 = new ([a, b, c]) => void; // OK + +// Below are Error but renaming is retained in declaration emit, +// since elinding it would leave invalid syntax. +type F10 = ({ "a": string }) => void; // Error +type F11 = ({ 2: string }) => void; // Error +type F12 = ({ ["a"]: string }: O) => void; // Error +type F13 = ({ [2]: string }) => void; // Error type G10 = new ({ "a": string }) => void; // Error type G11 = new ({ 2: string }) => void; // Error type G12 = new ({ ["a"]: string }: O) => void; // Error @@ -112,16 +115,6 @@ declare type F8 = ({ a, b: number }: { b: any; }) => typeof number; declare type F9 = ([a, b, c]: [any, any, any]) => void; -declare type F10 = ({ "a": string }: { - a: any; -}) => void; -declare type F11 = ({ 2: string }: { - 2: any; -}) => void; -declare type F12 = ({ ["a"]: string }: O) => void; -declare type F13 = ({ [2]: string }: { - 2: any; -}) => void; declare type G1 = new (arg: number) => any; declare type G2 = new ({ a }: O) => any; declare type G3 = new ({ a, b, c }: O) => any; @@ -139,6 +132,16 @@ declare type G8 = new ({ a, b: number }: { b: any; }) => typeof number; declare type G9 = new ([a, b, c]: [any, any, any]) => void; +declare type F10 = ({ "a": string }: { + a: any; +}) => void; +declare type F11 = ({ 2: string }: { + 2: any; +}) => void; +declare type F12 = ({ ["a"]: string }: O) => void; +declare type F13 = ({ [2]: string }: { + 2: any; +}) => void; declare type G10 = new ({ "a": string }: { a: any; }) => void; diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols index 0e55d8c000b81..abb839d485716 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.symbols @@ -60,235 +60,237 @@ type F8 = ({ a, b: number }) => typeof number; // OK >number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 15)) >number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 15)) -type F9 = ([a, b, c]) => void; // Error +type F9 = ([a, b, c]) => void; // OK >F9 : Symbol(F9, Decl(renamingDestructuredPropertyInFunctionType.ts, 10, 46)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 12)) >b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 14)) >c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 17)) -type F10 = ({ "a": string }) => void; // Error ->F10 : Symbol(F10, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 30)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 13)) - -type F11 = ({ 2: string }) => void; // Error ->F11 : Symbol(F11, Decl(renamingDestructuredPropertyInFunctionType.ts, 12, 37)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 13)) - -type F12 = ({ ["a"]: string }: O) => void; // Error ->F12 : Symbol(F12, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 35)) ->"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 13)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 13)) ->O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) - -type F13 = ({ [2]: string }) => void; // Error ->F13 : Symbol(F13, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 42)) ->2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 13)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 13)) - type G1 = new (arg: number) => any; // OK ->G1 : Symbol(G1, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 37)) ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 15)) +>G1 : Symbol(G1, Decl(renamingDestructuredPropertyInFunctionType.ts, 11, 30)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 15)) type G2 = new ({ a: string }: O) => any; // Error ->G2 : Symbol(G2, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 35)) +>G2 : Symbol(G2, Decl(renamingDestructuredPropertyInFunctionType.ts, 13, 35)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 16)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 16)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G3 = new ({ a: string, b, c }: O) => any; // Error ->G3 : Symbol(G3, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 40)) +>G3 : Symbol(G3, Decl(renamingDestructuredPropertyInFunctionType.ts, 14, 40)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 16)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 27)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 30)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 16)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 27)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 30)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G4 = new ({ a: string }: O) => any; // Error ->G4 : Symbol(G4, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 46)) +>G4 : Symbol(G4, Decl(renamingDestructuredPropertyInFunctionType.ts, 15, 46)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 16)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 16)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G5 = new ({ a: string, b, c }: O) => any; // Error ->G5 : Symbol(G5, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 40)) +>G5 : Symbol(G5, Decl(renamingDestructuredPropertyInFunctionType.ts, 16, 40)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 16)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 27)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 30)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 16)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 27)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 30)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G6 = new ({ a: string }) => typeof string; // OK ->G6 : Symbol(G6, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 46)) +>G6 : Symbol(G6, Decl(renamingDestructuredPropertyInFunctionType.ts, 17, 46)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 16)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 16)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 16)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 16)) type G7 = new ({ a: string, b: number }) => typeof number; // Error ->G7 : Symbol(G7, Decl(renamingDestructuredPropertyInFunctionType.ts, 22, 47)) +>G7 : Symbol(G7, Decl(renamingDestructuredPropertyInFunctionType.ts, 18, 47)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 16)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 16)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 27)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 27)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 27)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 27)) type G8 = new ({ a, b: number }) => typeof number; // OK ->G8 : Symbol(G8, Decl(renamingDestructuredPropertyInFunctionType.ts, 23, 58)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 16)) +>G8 : Symbol(G8, Decl(renamingDestructuredPropertyInFunctionType.ts, 19, 58)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 16)) >b : Symbol(b) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 19)) ->number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 19)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 19)) +>number : Symbol(number, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 19)) -type G9 = new ([a, b, c]) => void; // Error ->G9 : Symbol(G9, Decl(renamingDestructuredPropertyInFunctionType.ts, 24, 50)) ->a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 16)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 18)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 21)) +type G9 = new ([a, b, c]) => void; // OK +>G9 : Symbol(G9, Decl(renamingDestructuredPropertyInFunctionType.ts, 20, 50)) +>a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 16)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 18)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 21)) + +// Below are Error but renaming is retained in declaration emit, +// since elinding it would leave invalid syntax. +type F10 = ({ "a": string }) => void; // Error +>F10 : Symbol(F10, Decl(renamingDestructuredPropertyInFunctionType.ts, 21, 34)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 13)) + +type F11 = ({ 2: string }) => void; // Error +>F11 : Symbol(F11, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 37)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 13)) + +type F12 = ({ ["a"]: string }: O) => void; // Error +>F12 : Symbol(F12, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 35)) +>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 13)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 13)) +>O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) + +type F13 = ({ [2]: string }) => void; // Error +>F13 : Symbol(F13, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 42)) +>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 13)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 13)) type G10 = new ({ "a": string }) => void; // Error ->G10 : Symbol(G10, Decl(renamingDestructuredPropertyInFunctionType.ts, 25, 34)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 17)) +>G10 : Symbol(G10, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 37)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 17)) type G11 = new ({ 2: string }) => void; // Error ->G11 : Symbol(G11, Decl(renamingDestructuredPropertyInFunctionType.ts, 26, 41)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 17)) +>G11 : Symbol(G11, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 41)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 30, 17)) type G12 = new ({ ["a"]: string }: O) => void; // Error ->G12 : Symbol(G12, Decl(renamingDestructuredPropertyInFunctionType.ts, 27, 39)) ->"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 17)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 17)) +>G12 : Symbol(G12, Decl(renamingDestructuredPropertyInFunctionType.ts, 30, 39)) +>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 17)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 17)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) type G13 = new ({ [2]: string }) => void; // Error ->G13 : Symbol(G13, Decl(renamingDestructuredPropertyInFunctionType.ts, 28, 46)) ->2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 17)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 17)) +>G13 : Symbol(G13, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 46)) +>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 17)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 17)) interface I { ->I : Symbol(I, Decl(renamingDestructuredPropertyInFunctionType.ts, 29, 41)) +>I : Symbol(I, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 41)) method1(arg: number): any; // OK ->method1 : Symbol(I.method1, Decl(renamingDestructuredPropertyInFunctionType.ts, 31, 13)) ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 10)) +>method1 : Symbol(I.method1, Decl(renamingDestructuredPropertyInFunctionType.ts, 34, 13)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 35, 10)) method2({ a: string }): any; // Error ->method2 : Symbol(I.method2, Decl(renamingDestructuredPropertyInFunctionType.ts, 32, 28)) +>method2 : Symbol(I.method2, Decl(renamingDestructuredPropertyInFunctionType.ts, 35, 28)) >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 33, 11)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 11)) (arg: number): any; // OK ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 35, 3)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 3)) ({ a: string }): any; // Error >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 36, 4)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 4)) new (arg: number): any; // OK ->arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 38, 7)) +>arg : Symbol(arg, Decl(renamingDestructuredPropertyInFunctionType.ts, 41, 7)) new ({ a: string }): any; // Error >a : Symbol(a) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 39, 8)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 42, 8)) } // Below are OK but renaming should be removed from declaration emit function f1({ a: string }: O) { } ->f1 : Symbol(f1, Decl(renamingDestructuredPropertyInFunctionType.ts, 40, 1)) +>f1 : Symbol(f1, Decl(renamingDestructuredPropertyInFunctionType.ts, 43, 1)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 43, 13)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 13)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) const f2 = function({ a: string }: O) { }; ->f2 : Symbol(f2, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 5)) +>f2 : Symbol(f2, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 5)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 44, 21)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 21)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) const f3 = ({ a: string, b, c }: O) => { }; ->f3 : Symbol(f3, Decl(renamingDestructuredPropertyInFunctionType.ts, 45, 5)) +>f3 : Symbol(f3, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 5)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 45, 13)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 45, 24)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 45, 27)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 13)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 24)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 27)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) const f4 = function({ a: string }: O): typeof string { return string; }; ->f4 : Symbol(f4, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 5)) +>f4 : Symbol(f4, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 5)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 21)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 21)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 21)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 46, 21)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 21)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 21)) const f5 = ({ a: string, b, c }: O): typeof string => ''; ->f5 : Symbol(f5, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 5)) +>f5 : Symbol(f5, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 5)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 13)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 24)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 27)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 13)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 24)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 27)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 47, 13)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 50, 13)) const obj1 = { ->obj1 : Symbol(obj1, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 5)) +>obj1 : Symbol(obj1, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 5)) method({ a: string }: O) { } ->method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 48, 14)) +>method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 14)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 49, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 10)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) }; const obj2 = { ->obj2 : Symbol(obj2, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 5)) +>obj2 : Symbol(obj2, Decl(renamingDestructuredPropertyInFunctionType.ts, 54, 5)) method({ a: string }: O): typeof string { return string; } ->method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 51, 14)) +>method : Symbol(method, Decl(renamingDestructuredPropertyInFunctionType.ts, 54, 14)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 10)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 52, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 10)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 10)) }; function f6({ a: string = "" }: O) { } ->f6 : Symbol(f6, Decl(renamingDestructuredPropertyInFunctionType.ts, 53, 2)) +>f6 : Symbol(f6, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 2)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 54, 13)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 57, 13)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) const f7 = ({ a: string = "", b, c }: O) => { }; ->f7 : Symbol(f7, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 5)) +>f7 : Symbol(f7, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 5)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 13)) ->b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 29)) ->c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 55, 32)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 13)) +>b : Symbol(b, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 29)) +>c : Symbol(c, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 32)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) const f8 = ({ "a": string }: O) => { }; ->f8 : Symbol(f8, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 5)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 13)) +>f8 : Symbol(f8, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 5)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 13)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) function f9 ({ 2: string }) { }; ->f9 : Symbol(f9, Decl(renamingDestructuredPropertyInFunctionType.ts, 56, 39)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 57, 14)) +>f9 : Symbol(f9, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 39)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 60, 14)) function f10 ({ ["a"]: string }: O) { }; ->f10 : Symbol(f10, Decl(renamingDestructuredPropertyInFunctionType.ts, 57, 32)) ->"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 15)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 58, 15)) +>f10 : Symbol(f10, Decl(renamingDestructuredPropertyInFunctionType.ts, 60, 32)) +>"a" : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 61, 15)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 61, 15)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) const f11 = ({ [2]: string }) => { }; ->f11 : Symbol(f11, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 5)) ->2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 15)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 15)) +>f11 : Symbol(f11, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 5)) +>2 : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 15)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 15)) // In below case `string` should be kept because it is used function f12({ a: string = "" }: O): typeof string { return "a"; } ->f12 : Symbol(f12, Decl(renamingDestructuredPropertyInFunctionType.ts, 59, 38)) +>f12 : Symbol(f12, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 38)) >a : Symbol(a, Decl(renamingDestructuredPropertyInFunctionType.ts, 2, 10)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 14)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 65, 14)) >O : Symbol(O, Decl(renamingDestructuredPropertyInFunctionType.ts, 0, 0)) ->string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 62, 14)) +>string : Symbol(string, Decl(renamingDestructuredPropertyInFunctionType.ts, 65, 14)) diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types index f950dd1685d6f..9fc0a27a46282 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types @@ -56,30 +56,12 @@ type F8 = ({ a, b: number }) => typeof number; // OK >number : any >number : any -type F9 = ([a, b, c]) => void; // Error +type F9 = ([a, b, c]) => void; // OK >F9 : ([a, b, c]: [any, any, any]) => void >a : any >b : any >c : any -type F10 = ({ "a": string }) => void; // Error ->F10 : ({ "a": string }: { a: any; }) => void ->string : any - -type F11 = ({ 2: string }) => void; // Error ->F11 : ({ 2: string }: { 2: any; }) => void ->string : any - -type F12 = ({ ["a"]: string }: O) => void; // Error ->F12 : ({ ["a"]: string }: O) => void ->"a" : "a" ->string : string - -type F13 = ({ [2]: string }) => void; // Error ->F13 : ({ [2]: string }: { 2: any; }) => void ->2 : 2 ->string : any - type G1 = new (arg: number) => any; // OK >G1 : new (arg: number) => any >arg : number @@ -129,12 +111,32 @@ type G8 = new ({ a, b: number }) => typeof number; // OK >number : any >number : any -type G9 = new ([a, b, c]) => void; // Error +type G9 = new ([a, b, c]) => void; // OK >G9 : new ([a, b, c]: [any, any, any]) => void >a : any >b : any >c : any +// Below are Error but renaming is retained in declaration emit, +// since elinding it would leave invalid syntax. +type F10 = ({ "a": string }) => void; // Error +>F10 : ({ "a": string }: { a: any; }) => void +>string : any + +type F11 = ({ 2: string }) => void; // Error +>F11 : ({ 2: string }: { 2: any; }) => void +>string : any + +type F12 = ({ ["a"]: string }: O) => void; // Error +>F12 : ({ ["a"]: string }: O) => void +>"a" : "a" +>string : string + +type F13 = ({ [2]: string }) => void; // Error +>F13 : ({ [2]: string }: { 2: any; }) => void +>2 : 2 +>string : any + type G10 = new ({ "a": string }) => void; // Error >G10 : new ({ "a": string }: { a: any; }) => void >string : any diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt index 0de9080e6368a..70a0224c89a91 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt @@ -21,7 +21,7 @@ tests/cases/conformance/jsx/file.tsx(17,39): error TS2842: 'string' is an unused declare function TestingOneThing({y1: string}): JSX.Element; ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'y1'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/conformance/jsx/file.tsx:17:45: We can only write a type for '{y1: string}' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/conformance/jsx/file.tsx:17:45: We can only write a type for 'y1' by adding a type for the entire parameter here. declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element; declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element; declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element; From 600b614d7e921efbaecebd0203896b50ca71fc05 Mon Sep 17 00:00:00 2001 From: uhyo Date: Fri, 10 Jun 2022 11:08:17 +0900 Subject: [PATCH 31/31] move it one step further --- src/compiler/checker.ts | 2 +- .../destructuringInFunctionType.errors.txt | 4 ++-- .../excessPropertyCheckWithSpread.errors.txt | 2 +- ...aramterDestrcuturingDeclaration.errors.txt | 4 ++-- ...tructuredPropertyInFunctionType.errors.txt | 22 +++++++++---------- ...elessFunctionComponentOverload1.errors.txt | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a18017e4a07da..faeab2b7b370a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37585,7 +37585,7 @@ namespace ts { // entire parameter does not have type annotation, suggest adding an annotation addRelatedInfo( diagnostic, - createFileDiagnostic(getSourceFileOfNode(wrappingDeclaration), wrappingDeclaration.end - 1, 1, Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here, declarationNameToString(node.propertyName)) + createFileDiagnostic(getSourceFileOfNode(wrappingDeclaration), wrappingDeclaration.end, 1, Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here, declarationNameToString(node.propertyName)) ); } diagnostics.add(diagnostic); diff --git a/tests/baselines/reference/destructuringInFunctionType.errors.txt b/tests/baselines/reference/destructuringInFunctionType.errors.txt index 19751a3511c4a..a6ba91ddee799 100644 --- a/tests/baselines/reference/destructuringInFunctionType.errors.txt +++ b/tests/baselines/reference/destructuringInFunctionType.errors.txt @@ -17,10 +17,10 @@ tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts(12,28): type F3 = ([{ a: b }, { b: a }]) => void; ~ !!! error TS2842: 'b' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:31: We can only write a type for 'a' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:32: We can only write a type for 'a' by adding a type for the entire parameter here. ~ !!! error TS2842: 'a' is an unused renaming of 'b'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:31: We can only write a type for 'b' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts:12:32: We can only write a type for 'b' by adding a type for the entire parameter here. type T4 = ([{ a: [b, c] }]); type F4 = ([{ a: [b, c] }]) => void; diff --git a/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt index 182cb9ca3add1..5c4f8427e3972 100644 --- a/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt +++ b/tests/baselines/reference/excessPropertyCheckWithSpread.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/excessPropertyCheckWithSpread.ts(1,25): error TS2842: 'numb declare function f({ a: number }): void ~~~~~~ !!! error TS2842: 'number' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/excessPropertyCheckWithSpread.ts:1:32: We can only write a type for 'a' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/excessPropertyCheckWithSpread.ts:1:33: We can only write a type for 'a' by adding a type for the entire parameter here. interface I { readonly n: number; } diff --git a/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt b/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt index e760900375241..80d793e3124b6 100644 --- a/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt +++ b/tests/baselines/reference/paramterDestrcuturingDeclaration.errors.txt @@ -7,10 +7,10 @@ tests/cases/compiler/paramterDestrcuturingDeclaration.ts(3,14): error TS2842: 'b ({p: name}): any; ~~~~ !!! error TS2842: 'name' is an unused renaming of 'p'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/paramterDestrcuturingDeclaration.ts:2:14: We can only write a type for 'p' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/paramterDestrcuturingDeclaration.ts:2:15: We can only write a type for 'p' by adding a type for the entire parameter here. new ({p: boolean}): any; ~~~~~~~ !!! error TS2842: 'boolean' is an unused renaming of 'p'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/paramterDestrcuturingDeclaration.ts:3:21: We can only write a type for 'p' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/paramterDestrcuturingDeclaration.ts:3:22: We can only write a type for 'p' by adding a type for the entire parameter here. } \ No newline at end of file diff --git a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt index 3575dfcea9d83..d725c027450f6 100644 --- a/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt +++ b/tests/baselines/reference/renamingDestructuredPropertyInFunctionType.errors.txt @@ -42,7 +42,7 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(43,13): error type F7 = ({ a: string, b: number }) => typeof number; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:10:35: We can only write a type for 'a' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:10:36: We can only write a type for 'a' by adding a type for the entire parameter here. type F8 = ({ a, b: number }) => typeof number; // OK type F9 = ([a, b, c]) => void; // OK @@ -63,7 +63,7 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(43,13): error type G7 = new ({ a: string, b: number }) => typeof number; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:20:39: We can only write a type for 'a' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:20:40: We can only write a type for 'a' by adding a type for the entire parameter here. type G8 = new ({ a, b: number }) => typeof number; // OK type G9 = new ([a, b, c]) => void; // OK @@ -72,52 +72,52 @@ tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts(43,13): error type F10 = ({ "a": string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:26:27: We can only write a type for '"a"' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:26:28: We can only write a type for '"a"' by adding a type for the entire parameter here. type F11 = ({ 2: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:27:25: We can only write a type for '2' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:27:26: We can only write a type for '2' by adding a type for the entire parameter here. type F12 = ({ ["a"]: string }: O) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? type F13 = ({ [2]: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:29:27: We can only write a type for '[2]' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:29:28: We can only write a type for '[2]' by adding a type for the entire parameter here. type G10 = new ({ "a": string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '"a"'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:30:31: We can only write a type for '"a"' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:30:32: We can only write a type for '"a"' by adding a type for the entire parameter here. type G11 = new ({ 2: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '2'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:31:29: We can only write a type for '2' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:31:30: We can only write a type for '2' by adding a type for the entire parameter here. type G12 = new ({ ["a"]: string }: O) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '["a"]'. Did you intend to use it as a type annotation? type G13 = new ({ [2]: string }) => void; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of '[2]'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:33:31: We can only write a type for '[2]' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:33:32: We can only write a type for '[2]' by adding a type for the entire parameter here. interface I { method1(arg: number): any; // OK method2({ a: string }): any; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:37:23: We can only write a type for 'a' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:37:24: We can only write a type for 'a' by adding a type for the entire parameter here. (arg: number): any; // OK ({ a: string }): any; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:40:16: We can only write a type for 'a' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:40:17: We can only write a type for 'a' by adding a type for the entire parameter here. new (arg: number): any; // OK new ({ a: string }): any; // Error ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'a'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:43:20: We can only write a type for 'a' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/compiler/renamingDestructuredPropertyInFunctionType.ts:43:21: We can only write a type for 'a' by adding a type for the entire parameter here. } // Below are OK but renaming should be removed from declaration emit diff --git a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt index 70a0224c89a91..ae1532b986895 100644 --- a/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt +++ b/tests/baselines/reference/tsxStatelessFunctionComponentOverload1.errors.txt @@ -21,7 +21,7 @@ tests/cases/conformance/jsx/file.tsx(17,39): error TS2842: 'string' is an unused declare function TestingOneThing({y1: string}): JSX.Element; ~~~~~~ !!! error TS2842: 'string' is an unused renaming of 'y1'. Did you intend to use it as a type annotation? -!!! related TS2843 tests/cases/conformance/jsx/file.tsx:17:45: We can only write a type for 'y1' by adding a type for the entire parameter here. +!!! related TS2843 tests/cases/conformance/jsx/file.tsx:17:46: We can only write a type for 'y1' by adding a type for the entire parameter here. declare function TestingOneThing(j: {"extra-data": string, yy?: string}): JSX.Element; declare function TestingOneThing(n: {yy: number, direction?: number}): JSX.Element; declare function TestingOneThing(n: {yy: string, name: string}): JSX.Element;