From 3ed2e8ed34419890228935f0cd59df80e7a10f1f Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Wed, 14 Aug 2024 22:34:03 -0700 Subject: [PATCH] Report unreachable on enums (#58380) Co-authored-by: Daniel Rosenwasser --- src/compiler/binder.ts | 52 ++- .../reference/reachabilityChecks1.errors.txt | 12 +- ...tions(preserveconstenums=false).errors.txt | 137 ++++++ ...eDeclarations(preserveconstenums=false).js | 169 +++++++ ...arations(preserveconstenums=false).symbols | 245 ++++++++++ ...clarations(preserveconstenums=false).types | 442 ++++++++++++++++++ ...ations(preserveconstenums=true).errors.txt | 141 ++++++ ...leDeclarations(preserveconstenums=true).js | 177 +++++++ ...larations(preserveconstenums=true).symbols | 245 ++++++++++ ...eclarations(preserveconstenums=true).types | 442 ++++++++++++++++++ .../cases/compiler/unreachableDeclarations.ts | 89 ++++ .../cases/fourslash/codeFixUnreachableCode.ts | 3 +- 12 files changed, 2128 insertions(+), 26 deletions(-) create mode 100644 tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).errors.txt create mode 100644 tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).js create mode 100644 tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).symbols create mode 100644 tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).types create mode 100644 tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).errors.txt create mode 100644 tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).js create mode 100644 tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).symbols create mode 100644 tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).types create mode 100644 tests/cases/compiler/unreachableDeclarations.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 96c6e08f0f5..1666c90883e 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -154,7 +154,6 @@ import { isEmptyObjectLiteral, isEntityNameExpression, isEnumConst, - isEnumDeclaration, isExportAssignment, isExportDeclaration, isExportsIdentifier, @@ -3789,7 +3788,9 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { (isStatementButNotDeclaration(node) && node.kind !== SyntaxKind.EmptyStatement) || // report error on class declarations node.kind === SyntaxKind.ClassDeclaration || - // report error on instantiated modules or const-enums only modules if preserveConstEnums is set + // report errors on enums with preserved emit + isEnumDeclarationWithPreservedEmit(node, options) || + // report error on instantiated modules (node.kind === SyntaxKind.ModuleDeclaration && shouldReportErrorOnModuleDeclaration(node as ModuleDeclaration)); if (reportError) { @@ -3813,7 +3814,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { node.declarationList.declarations.some(d => !!d.initializer) ); - eachUnreachableRange(node, (start, end) => errorOrSuggestionOnRange(isError, start, end, Diagnostics.Unreachable_code_detected)); + eachUnreachableRange(node, options, (start, end) => errorOrSuggestionOnRange(isError, start, end, Diagnostics.Unreachable_code_detected)); } } } @@ -3821,7 +3822,11 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { } } -function eachUnreachableRange(node: Node, cb: (start: Node, last: Node) => void): void { +function isEnumDeclarationWithPreservedEmit(node: Node, options: CompilerOptions): boolean { + return node.kind === SyntaxKind.EnumDeclaration && (!isEnumConst(node as EnumDeclaration) || shouldPreserveConstEnums(options)); +} + +function eachUnreachableRange(node: Node, options: CompilerOptions, cb: (start: Node, last: Node) => void): void { if (isStatement(node) && isExecutableStatement(node) && isBlock(node.parent)) { const { statements } = node.parent; const slice = sliceAfter(statements, node); @@ -3830,26 +3835,27 @@ function eachUnreachableRange(node: Node, cb: (start: Node, last: Node) => void) else { cb(node, node); } -} -// As opposed to a pure declaration like an `interface` -function isExecutableStatement(s: Statement): boolean { - // Don't remove statements that can validly be used before they appear. - return !isFunctionDeclaration(s) && !isPurelyTypeDeclaration(s) && !isEnumDeclaration(s) && - // `var x;` may declare a variable used above - !(isVariableStatement(s) && !(getCombinedNodeFlags(s) & (NodeFlags.BlockScoped)) && s.declarationList.declarations.some(d => !d.initializer)); -} -function isPurelyTypeDeclaration(s: Statement): boolean { - switch (s.kind) { - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.TypeAliasDeclaration: - return true; - case SyntaxKind.ModuleDeclaration: - return getModuleInstanceState(s as ModuleDeclaration) !== ModuleInstanceState.Instantiated; - case SyntaxKind.EnumDeclaration: - return hasSyntacticModifier(s, ModifierFlags.Const); - default: - return false; + // As opposed to a pure declaration like an `interface` + function isExecutableStatement(s: Statement): boolean { + // Don't remove statements that can validly be used before they appear. + return !isFunctionDeclaration(s) && !isPurelyTypeDeclaration(s) && + // `var x;` may declare a variable used above + !(isVariableStatement(s) && !(getCombinedNodeFlags(s) & (NodeFlags.BlockScoped)) && s.declarationList.declarations.some(d => !d.initializer)); + } + + function isPurelyTypeDeclaration(s: Statement): boolean { + switch (s.kind) { + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.TypeAliasDeclaration: + return true; + case SyntaxKind.ModuleDeclaration: + return getModuleInstanceState(s as ModuleDeclaration) !== ModuleInstanceState.Instantiated; + case SyntaxKind.EnumDeclaration: + return !isEnumDeclarationWithPreservedEmit(s, options); + default: + return false; + } } } diff --git a/tests/baselines/reference/reachabilityChecks1.errors.txt b/tests/baselines/reference/reachabilityChecks1.errors.txt index 72736526094..d25977a05b7 100644 --- a/tests/baselines/reference/reachabilityChecks1.errors.txt +++ b/tests/baselines/reference/reachabilityChecks1.errors.txt @@ -3,9 +3,11 @@ reachabilityChecks1.ts(6,5): error TS7027: Unreachable code detected. reachabilityChecks1.ts(18,5): error TS7027: Unreachable code detected. reachabilityChecks1.ts(30,5): error TS7027: Unreachable code detected. reachabilityChecks1.ts(47,5): error TS7027: Unreachable code detected. +reachabilityChecks1.ts(60,5): error TS7027: Unreachable code detected. +reachabilityChecks1.ts(69,5): error TS7027: Unreachable code detected. -==== reachabilityChecks1.ts (5 errors) ==== +==== reachabilityChecks1.ts (7 errors) ==== while (true); var x = 1; ~~~~~~~~~~ @@ -81,8 +83,12 @@ reachabilityChecks1.ts(47,5): error TS7027: Unreachable code detected. do { } while (true); enum E { + ~~~~~~~~ X = 1 + ~~~~~~~~~~~~~ } + ~~~~~ +!!! error TS7027: Unreachable code detected. } function f4() { @@ -90,8 +96,12 @@ reachabilityChecks1.ts(47,5): error TS7027: Unreachable code detected. throw new Error(); } const enum E { + ~~~~~~~~~~~~~~ X = 1 + ~~~~~~~~~~~~~ } + ~~~~~ +!!! error TS7027: Unreachable code detected. } \ No newline at end of file diff --git a/tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).errors.txt b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).errors.txt new file mode 100644 index 00000000000..fd7f5d66b9f --- /dev/null +++ b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).errors.txt @@ -0,0 +1,137 @@ +unreachableDeclarations.ts(4,17): error TS2450: Enum 'EnumA' used before its declaration. +unreachableDeclarations.ts(14,5): error TS7027: Unreachable code detected. +unreachableDeclarations.ts(21,17): error TS2450: Enum 'EnumA' used before its declaration. +unreachableDeclarations.ts(29,5): error TS7027: Unreachable code detected. +unreachableDeclarations.ts(49,17): error TS2449: Class 'ClassA' used before its declaration. +unreachableDeclarations.ts(57,5): error TS7027: Unreachable code detected. +unreachableDeclarations.ts(63,14): error TS2450: Enum 'Bar' used before its declaration. +unreachableDeclarations.ts(64,14): error TS2448: Block-scoped variable 'blah' used before its declaration. +unreachableDeclarations.ts(64,14): error TS2454: Variable 'blah' is used before being assigned. +unreachableDeclarations.ts(65,18): error TS2449: Class 'Foo' used before its declaration. +unreachableDeclarations.ts(78,2): error TS7027: Unreachable code detected. +unreachableDeclarations.ts(84,2): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. + + +==== unreachableDeclarations.ts (12 errors) ==== + function func1() { + aFunc(); + + console.log(EnumA.Value); + ~~~~~ +!!! error TS2450: Enum 'EnumA' used before its declaration. +!!! related TS2728 unreachableDeclarations.ts:14:10: 'EnumA' is declared here. + console.log(EnumB.Value); + + return; + + function aFunc() { + console.log(EnumA.Value); + console.log(EnumB.Value); + } + + enum EnumA { Value } + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS7027: Unreachable code detected. + const enum EnumB { Value } + } + + function func2() { + aFunc(); + + console.log(EnumA.Value); + ~~~~~ +!!! error TS2450: Enum 'EnumA' used before its declaration. +!!! related TS2728 unreachableDeclarations.ts:29:10: 'EnumA' is declared here. + + return; + + function aFunc() { + console.log(EnumA.Value); + } + + enum EnumA { Value } + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS7027: Unreachable code detected. + } + + function func3() { + aFunc(); + + console.log(EnumB.Value); + + return; + + function aFunc() { + console.log(EnumB.Value); + } + + const enum EnumB { Value } + } + + function func4() { + aFunc(); + + console.log(ClassA.Value); + ~~~~~~ +!!! error TS2449: Class 'ClassA' used before its declaration. +!!! related TS2728 unreachableDeclarations.ts:57:11: 'ClassA' is declared here. + + return; + + function aFunc() { + console.log(ClassA.Value); + } + + class ClassA { static Value = 1234; } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7027: Unreachable code detected. + } + + function func5() { + aFunc(); + + console.log(Bar.A); + ~~~ +!!! error TS2450: Enum 'Bar' used before its declaration. +!!! related TS2728 unreachableDeclarations.ts:80:7: 'Bar' is declared here. + console.log(blah.prop); + ~~~~ +!!! error TS2448: Block-scoped variable 'blah' used before its declaration. +!!! related TS2728 unreachableDeclarations.ts:78:8: 'blah' is declared here. + ~~~~ +!!! error TS2454: Variable 'blah' is used before being assigned. + console.log(new Foo()) + ~~~ +!!! error TS2449: Class 'Foo' used before its declaration. +!!! related TS2728 unreachableDeclarations.ts:82:8: 'Foo' is declared here. + console.log(Baz.value); + + + return; + + function aFunc() { + console.log(Bar.A); + console.log(blah.prop); + console.log(new Foo()) + console.log(Baz.value); + } + + const blah = { prop: 1234 }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + enum Bar { A } + ~~~~~~~~~~~~~~~ + + + class Foo { x = 1234 } + ~~~~~~~~~~~~~~~~~~~~~~~ + + + namespace Baz { export const value = 1234 } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7027: Unreachable code detected. + ~~~~~~~~~ +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. + } + \ No newline at end of file diff --git a/tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).js b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).js new file mode 100644 index 00000000000..945f427dae8 --- /dev/null +++ b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).js @@ -0,0 +1,169 @@ +//// [tests/cases/compiler/unreachableDeclarations.ts] //// + +//// [unreachableDeclarations.ts] +function func1() { + aFunc(); + + console.log(EnumA.Value); + console.log(EnumB.Value); + + return; + + function aFunc() { + console.log(EnumA.Value); + console.log(EnumB.Value); + } + + enum EnumA { Value } + const enum EnumB { Value } +} + +function func2() { + aFunc(); + + console.log(EnumA.Value); + + return; + + function aFunc() { + console.log(EnumA.Value); + } + + enum EnumA { Value } +} + +function func3() { + aFunc(); + + console.log(EnumB.Value); + + return; + + function aFunc() { + console.log(EnumB.Value); + } + + const enum EnumB { Value } +} + +function func4() { + aFunc(); + + console.log(ClassA.Value); + + return; + + function aFunc() { + console.log(ClassA.Value); + } + + class ClassA { static Value = 1234; } +} + +function func5() { + aFunc(); + + console.log(Bar.A); + console.log(blah.prop); + console.log(new Foo()) + console.log(Baz.value); + + + return; + + function aFunc() { + console.log(Bar.A); + console.log(blah.prop); + console.log(new Foo()) + console.log(Baz.value); + } + + const blah = { prop: 1234 }; + + enum Bar { A } + + class Foo { x = 1234 } + + namespace Baz { export const value = 1234 } +} + + +//// [unreachableDeclarations.js] +"use strict"; +function func1() { + aFunc(); + console.log(EnumA.Value); + console.log(0 /* EnumB.Value */); + return; + function aFunc() { + console.log(EnumA.Value); + console.log(0 /* EnumB.Value */); + } + var EnumA; + (function (EnumA) { + EnumA[EnumA["Value"] = 0] = "Value"; + })(EnumA || (EnumA = {})); +} +function func2() { + aFunc(); + console.log(EnumA.Value); + return; + function aFunc() { + console.log(EnumA.Value); + } + var EnumA; + (function (EnumA) { + EnumA[EnumA["Value"] = 0] = "Value"; + })(EnumA || (EnumA = {})); +} +function func3() { + aFunc(); + console.log(0 /* EnumB.Value */); + return; + function aFunc() { + console.log(0 /* EnumB.Value */); + } +} +function func4() { + aFunc(); + console.log(ClassA.Value); + return; + function aFunc() { + console.log(ClassA.Value); + } + var ClassA = /** @class */ (function () { + function ClassA() { + } + ClassA.Value = 1234; + return ClassA; + }()); +} +function func5() { + aFunc(); + console.log(Bar.A); + console.log(blah.prop); + console.log(new Foo()); + console.log(Baz.value); + return; + function aFunc() { + console.log(Bar.A); + console.log(blah.prop); + console.log(new Foo()); + console.log(Baz.value); + } + var blah = { prop: 1234 }; + var Bar; + (function (Bar) { + Bar[Bar["A"] = 0] = "A"; + })(Bar || (Bar = {})); + var Foo = /** @class */ (function () { + function Foo() { + this.x = 1234; + } + return Foo; + }()); + var Baz; + (function (Baz) { + Baz.value = 1234; + })(Baz || (Baz = {})); +} diff --git a/tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).symbols b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).symbols new file mode 100644 index 00000000000..20cadc7d774 --- /dev/null +++ b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).symbols @@ -0,0 +1,245 @@ +//// [tests/cases/compiler/unreachableDeclarations.ts] //// + +=== unreachableDeclarations.ts === +function func1() { +>func1 : Symbol(func1, Decl(unreachableDeclarations.ts, 0, 0)) + + aFunc(); +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 6, 11)) + + console.log(EnumA.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumA.Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 13, 16)) +>EnumA : Symbol(EnumA, Decl(unreachableDeclarations.ts, 11, 5)) +>Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 13, 16)) + + console.log(EnumB.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumB.Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 14, 22)) +>EnumB : Symbol(EnumB, Decl(unreachableDeclarations.ts, 13, 24)) +>Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 14, 22)) + + return; + + function aFunc() { +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 6, 11)) + + console.log(EnumA.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumA.Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 13, 16)) +>EnumA : Symbol(EnumA, Decl(unreachableDeclarations.ts, 11, 5)) +>Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 13, 16)) + + console.log(EnumB.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumB.Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 14, 22)) +>EnumB : Symbol(EnumB, Decl(unreachableDeclarations.ts, 13, 24)) +>Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 14, 22)) + } + + enum EnumA { Value } +>EnumA : Symbol(EnumA, Decl(unreachableDeclarations.ts, 11, 5)) +>Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 13, 16)) + + const enum EnumB { Value } +>EnumB : Symbol(EnumB, Decl(unreachableDeclarations.ts, 13, 24)) +>Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 14, 22)) +} + +function func2() { +>func2 : Symbol(func2, Decl(unreachableDeclarations.ts, 15, 1)) + + aFunc(); +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 22, 11)) + + console.log(EnumA.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumA.Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 28, 16)) +>EnumA : Symbol(EnumA, Decl(unreachableDeclarations.ts, 26, 5)) +>Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 28, 16)) + + return; + + function aFunc() { +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 22, 11)) + + console.log(EnumA.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumA.Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 28, 16)) +>EnumA : Symbol(EnumA, Decl(unreachableDeclarations.ts, 26, 5)) +>Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 28, 16)) + } + + enum EnumA { Value } +>EnumA : Symbol(EnumA, Decl(unreachableDeclarations.ts, 26, 5)) +>Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 28, 16)) +} + +function func3() { +>func3 : Symbol(func3, Decl(unreachableDeclarations.ts, 29, 1)) + + aFunc(); +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 36, 11)) + + console.log(EnumB.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumB.Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 42, 22)) +>EnumB : Symbol(EnumB, Decl(unreachableDeclarations.ts, 40, 5)) +>Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 42, 22)) + + return; + + function aFunc() { +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 36, 11)) + + console.log(EnumB.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumB.Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 42, 22)) +>EnumB : Symbol(EnumB, Decl(unreachableDeclarations.ts, 40, 5)) +>Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 42, 22)) + } + + const enum EnumB { Value } +>EnumB : Symbol(EnumB, Decl(unreachableDeclarations.ts, 40, 5)) +>Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 42, 22)) +} + +function func4() { +>func4 : Symbol(func4, Decl(unreachableDeclarations.ts, 43, 1)) + + aFunc(); +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 50, 11)) + + console.log(ClassA.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>ClassA.Value : Symbol(ClassA.Value, Decl(unreachableDeclarations.ts, 56, 18)) +>ClassA : Symbol(ClassA, Decl(unreachableDeclarations.ts, 54, 5)) +>Value : Symbol(ClassA.Value, Decl(unreachableDeclarations.ts, 56, 18)) + + return; + + function aFunc() { +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 50, 11)) + + console.log(ClassA.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>ClassA.Value : Symbol(ClassA.Value, Decl(unreachableDeclarations.ts, 56, 18)) +>ClassA : Symbol(ClassA, Decl(unreachableDeclarations.ts, 54, 5)) +>Value : Symbol(ClassA.Value, Decl(unreachableDeclarations.ts, 56, 18)) + } + + class ClassA { static Value = 1234; } +>ClassA : Symbol(ClassA, Decl(unreachableDeclarations.ts, 54, 5)) +>Value : Symbol(ClassA.Value, Decl(unreachableDeclarations.ts, 56, 18)) +} + +function func5() { +>func5 : Symbol(func5, Decl(unreachableDeclarations.ts, 57, 1)) + + aFunc(); +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 68, 8)) + + console.log(Bar.A); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Bar.A : Symbol(Bar.A, Decl(unreachableDeclarations.ts, 79, 11)) +>Bar : Symbol(Bar, Decl(unreachableDeclarations.ts, 77, 29)) +>A : Symbol(Bar.A, Decl(unreachableDeclarations.ts, 79, 11)) + + console.log(blah.prop); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>blah.prop : Symbol(prop, Decl(unreachableDeclarations.ts, 77, 15)) +>blah : Symbol(blah, Decl(unreachableDeclarations.ts, 77, 6)) +>prop : Symbol(prop, Decl(unreachableDeclarations.ts, 77, 15)) + + console.log(new Foo()) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(unreachableDeclarations.ts, 79, 15)) + + console.log(Baz.value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Baz.value : Symbol(Baz.value, Decl(unreachableDeclarations.ts, 83, 29)) +>Baz : Symbol(Baz, Decl(unreachableDeclarations.ts, 81, 23)) +>value : Symbol(Baz.value, Decl(unreachableDeclarations.ts, 83, 29)) + + + return; + + function aFunc() { +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 68, 8)) + + console.log(Bar.A); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Bar.A : Symbol(Bar.A, Decl(unreachableDeclarations.ts, 79, 11)) +>Bar : Symbol(Bar, Decl(unreachableDeclarations.ts, 77, 29)) +>A : Symbol(Bar.A, Decl(unreachableDeclarations.ts, 79, 11)) + + console.log(blah.prop); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>blah.prop : Symbol(prop, Decl(unreachableDeclarations.ts, 77, 15)) +>blah : Symbol(blah, Decl(unreachableDeclarations.ts, 77, 6)) +>prop : Symbol(prop, Decl(unreachableDeclarations.ts, 77, 15)) + + console.log(new Foo()) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(unreachableDeclarations.ts, 79, 15)) + + console.log(Baz.value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Baz.value : Symbol(Baz.value, Decl(unreachableDeclarations.ts, 83, 29)) +>Baz : Symbol(Baz, Decl(unreachableDeclarations.ts, 81, 23)) +>value : Symbol(Baz.value, Decl(unreachableDeclarations.ts, 83, 29)) + } + + const blah = { prop: 1234 }; +>blah : Symbol(blah, Decl(unreachableDeclarations.ts, 77, 6)) +>prop : Symbol(prop, Decl(unreachableDeclarations.ts, 77, 15)) + + enum Bar { A } +>Bar : Symbol(Bar, Decl(unreachableDeclarations.ts, 77, 29)) +>A : Symbol(Bar.A, Decl(unreachableDeclarations.ts, 79, 11)) + + class Foo { x = 1234 } +>Foo : Symbol(Foo, Decl(unreachableDeclarations.ts, 79, 15)) +>x : Symbol(Foo.x, Decl(unreachableDeclarations.ts, 81, 12)) + + namespace Baz { export const value = 1234 } +>Baz : Symbol(Baz, Decl(unreachableDeclarations.ts, 81, 23)) +>value : Symbol(value, Decl(unreachableDeclarations.ts, 83, 29)) +} + diff --git a/tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).types b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).types new file mode 100644 index 00000000000..9a54857c8d2 --- /dev/null +++ b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=false).types @@ -0,0 +1,442 @@ +//// [tests/cases/compiler/unreachableDeclarations.ts] //// + +=== unreachableDeclarations.ts === +function func1() { +>func1 : () => void +> : ^^^^^^^^^^ + + aFunc(); +>aFunc() : void +> : ^^^^ +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(EnumA.Value); +>console.log(EnumA.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumA.Value : EnumA +> : ^^^^^ +>EnumA : typeof EnumA +> : ^^^^^^^^^^^^ +>Value : EnumA +> : ^^^^^ + + console.log(EnumB.Value); +>console.log(EnumB.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumB.Value : EnumB +> : ^^^^^ +>EnumB : typeof EnumB +> : ^^^^^^^^^^^^ +>Value : EnumB +> : ^^^^^ + + return; + + function aFunc() { +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(EnumA.Value); +>console.log(EnumA.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumA.Value : EnumA +> : ^^^^^ +>EnumA : typeof EnumA +> : ^^^^^^^^^^^^ +>Value : EnumA +> : ^^^^^ + + console.log(EnumB.Value); +>console.log(EnumB.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumB.Value : EnumB +> : ^^^^^ +>EnumB : typeof EnumB +> : ^^^^^^^^^^^^ +>Value : EnumB +> : ^^^^^ + } + + enum EnumA { Value } +>EnumA : EnumA +> : ^^^^^ +>Value : EnumA.Value +> : ^^^^^^^^^^^ + + const enum EnumB { Value } +>EnumB : EnumB +> : ^^^^^ +>Value : EnumB.Value +> : ^^^^^^^^^^^ +} + +function func2() { +>func2 : () => void +> : ^^^^^^^^^^ + + aFunc(); +>aFunc() : void +> : ^^^^ +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(EnumA.Value); +>console.log(EnumA.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumA.Value : EnumA +> : ^^^^^ +>EnumA : typeof EnumA +> : ^^^^^^^^^^^^ +>Value : EnumA +> : ^^^^^ + + return; + + function aFunc() { +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(EnumA.Value); +>console.log(EnumA.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumA.Value : EnumA +> : ^^^^^ +>EnumA : typeof EnumA +> : ^^^^^^^^^^^^ +>Value : EnumA +> : ^^^^^ + } + + enum EnumA { Value } +>EnumA : EnumA +> : ^^^^^ +>Value : EnumA.Value +> : ^^^^^^^^^^^ +} + +function func3() { +>func3 : () => void +> : ^^^^^^^^^^ + + aFunc(); +>aFunc() : void +> : ^^^^ +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(EnumB.Value); +>console.log(EnumB.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumB.Value : EnumB +> : ^^^^^ +>EnumB : typeof EnumB +> : ^^^^^^^^^^^^ +>Value : EnumB +> : ^^^^^ + + return; + + function aFunc() { +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(EnumB.Value); +>console.log(EnumB.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumB.Value : EnumB +> : ^^^^^ +>EnumB : typeof EnumB +> : ^^^^^^^^^^^^ +>Value : EnumB +> : ^^^^^ + } + + const enum EnumB { Value } +>EnumB : EnumB +> : ^^^^^ +>Value : EnumB.Value +> : ^^^^^^^^^^^ +} + +function func4() { +>func4 : () => void +> : ^^^^^^^^^^ + + aFunc(); +>aFunc() : void +> : ^^^^ +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(ClassA.Value); +>console.log(ClassA.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>ClassA.Value : number +> : ^^^^^^ +>ClassA : typeof ClassA +> : ^^^^^^^^^^^^^ +>Value : number +> : ^^^^^^ + + return; + + function aFunc() { +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(ClassA.Value); +>console.log(ClassA.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>ClassA.Value : number +> : ^^^^^^ +>ClassA : typeof ClassA +> : ^^^^^^^^^^^^^ +>Value : number +> : ^^^^^^ + } + + class ClassA { static Value = 1234; } +>ClassA : ClassA +> : ^^^^^^ +>Value : number +> : ^^^^^^ +>1234 : 1234 +> : ^^^^ +} + +function func5() { +>func5 : () => void +> : ^^^^^^^^^^ + + aFunc(); +>aFunc() : void +> : ^^^^ +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(Bar.A); +>console.log(Bar.A) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>Bar.A : Bar +> : ^^^ +>Bar : typeof Bar +> : ^^^^^^^^^^ +>A : Bar +> : ^^^ + + console.log(blah.prop); +>console.log(blah.prop) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>blah.prop : number +> : ^^^^^^ +>blah : { prop: number; } +> : ^^^^^^^^^^^^^^^^^ +>prop : number +> : ^^^^^^ + + console.log(new Foo()) +>console.log(new Foo()) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>new Foo() : Foo +> : ^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ + + console.log(Baz.value); +>console.log(Baz.value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>Baz.value : 1234 +> : ^^^^ +>Baz : typeof Baz +> : ^^^^^^^^^^ +>value : 1234 +> : ^^^^ + + + return; + + function aFunc() { +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(Bar.A); +>console.log(Bar.A) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>Bar.A : Bar +> : ^^^ +>Bar : typeof Bar +> : ^^^^^^^^^^ +>A : Bar +> : ^^^ + + console.log(blah.prop); +>console.log(blah.prop) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>blah.prop : number +> : ^^^^^^ +>blah : { prop: number; } +> : ^^^^^^^^^^^^^^^^^ +>prop : number +> : ^^^^^^ + + console.log(new Foo()) +>console.log(new Foo()) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>new Foo() : Foo +> : ^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ + + console.log(Baz.value); +>console.log(Baz.value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>Baz.value : 1234 +> : ^^^^ +>Baz : typeof Baz +> : ^^^^^^^^^^ +>value : 1234 +> : ^^^^ + } + + const blah = { prop: 1234 }; +>blah : { prop: number; } +> : ^^^^^^^^^^^^^^^^^ +>{ prop: 1234 } : { prop: number; } +> : ^^^^^^^^^^^^^^^^^ +>prop : number +> : ^^^^^^ +>1234 : 1234 +> : ^^^^ + + enum Bar { A } +>Bar : Bar +> : ^^^ +>A : Bar.A +> : ^^^^^ + + class Foo { x = 1234 } +>Foo : Foo +> : ^^^ +>x : number +> : ^^^^^^ +>1234 : 1234 +> : ^^^^ + + namespace Baz { export const value = 1234 } +>Baz : typeof Baz +> : ^^^^^^^^^^ +>value : 1234 +> : ^^^^ +>1234 : 1234 +> : ^^^^ +} + diff --git a/tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).errors.txt b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).errors.txt new file mode 100644 index 00000000000..a648a0d7665 --- /dev/null +++ b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).errors.txt @@ -0,0 +1,141 @@ +unreachableDeclarations.ts(4,17): error TS2450: Enum 'EnumA' used before its declaration. +unreachableDeclarations.ts(14,5): error TS7027: Unreachable code detected. +unreachableDeclarations.ts(21,17): error TS2450: Enum 'EnumA' used before its declaration. +unreachableDeclarations.ts(29,5): error TS7027: Unreachable code detected. +unreachableDeclarations.ts(43,5): error TS7027: Unreachable code detected. +unreachableDeclarations.ts(49,17): error TS2449: Class 'ClassA' used before its declaration. +unreachableDeclarations.ts(57,5): error TS7027: Unreachable code detected. +unreachableDeclarations.ts(63,14): error TS2450: Enum 'Bar' used before its declaration. +unreachableDeclarations.ts(64,14): error TS2448: Block-scoped variable 'blah' used before its declaration. +unreachableDeclarations.ts(64,14): error TS2454: Variable 'blah' is used before being assigned. +unreachableDeclarations.ts(65,18): error TS2449: Class 'Foo' used before its declaration. +unreachableDeclarations.ts(78,2): error TS7027: Unreachable code detected. +unreachableDeclarations.ts(84,2): error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. + + +==== unreachableDeclarations.ts (13 errors) ==== + function func1() { + aFunc(); + + console.log(EnumA.Value); + ~~~~~ +!!! error TS2450: Enum 'EnumA' used before its declaration. +!!! related TS2728 unreachableDeclarations.ts:14:10: 'EnumA' is declared here. + console.log(EnumB.Value); + + return; + + function aFunc() { + console.log(EnumA.Value); + console.log(EnumB.Value); + } + + enum EnumA { Value } + ~~~~~~~~~~~~~~~~~~~~ + const enum EnumB { Value } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7027: Unreachable code detected. + } + + function func2() { + aFunc(); + + console.log(EnumA.Value); + ~~~~~ +!!! error TS2450: Enum 'EnumA' used before its declaration. +!!! related TS2728 unreachableDeclarations.ts:29:10: 'EnumA' is declared here. + + return; + + function aFunc() { + console.log(EnumA.Value); + } + + enum EnumA { Value } + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS7027: Unreachable code detected. + } + + function func3() { + aFunc(); + + console.log(EnumB.Value); + + return; + + function aFunc() { + console.log(EnumB.Value); + } + + const enum EnumB { Value } + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7027: Unreachable code detected. + } + + function func4() { + aFunc(); + + console.log(ClassA.Value); + ~~~~~~ +!!! error TS2449: Class 'ClassA' used before its declaration. +!!! related TS2728 unreachableDeclarations.ts:57:11: 'ClassA' is declared here. + + return; + + function aFunc() { + console.log(ClassA.Value); + } + + class ClassA { static Value = 1234; } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7027: Unreachable code detected. + } + + function func5() { + aFunc(); + + console.log(Bar.A); + ~~~ +!!! error TS2450: Enum 'Bar' used before its declaration. +!!! related TS2728 unreachableDeclarations.ts:80:7: 'Bar' is declared here. + console.log(blah.prop); + ~~~~ +!!! error TS2448: Block-scoped variable 'blah' used before its declaration. +!!! related TS2728 unreachableDeclarations.ts:78:8: 'blah' is declared here. + ~~~~ +!!! error TS2454: Variable 'blah' is used before being assigned. + console.log(new Foo()) + ~~~ +!!! error TS2449: Class 'Foo' used before its declaration. +!!! related TS2728 unreachableDeclarations.ts:82:8: 'Foo' is declared here. + console.log(Baz.value); + + + return; + + function aFunc() { + console.log(Bar.A); + console.log(blah.prop); + console.log(new Foo()) + console.log(Baz.value); + } + + const blah = { prop: 1234 }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + enum Bar { A } + ~~~~~~~~~~~~~~~ + + + class Foo { x = 1234 } + ~~~~~~~~~~~~~~~~~~~~~~~ + + + namespace Baz { export const value = 1234 } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7027: Unreachable code detected. + ~~~~~~~~~ +!!! error TS1235: A namespace declaration is only allowed at the top level of a namespace or module. + } + \ No newline at end of file diff --git a/tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).js b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).js new file mode 100644 index 00000000000..1433be8a790 --- /dev/null +++ b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).js @@ -0,0 +1,177 @@ +//// [tests/cases/compiler/unreachableDeclarations.ts] //// + +//// [unreachableDeclarations.ts] +function func1() { + aFunc(); + + console.log(EnumA.Value); + console.log(EnumB.Value); + + return; + + function aFunc() { + console.log(EnumA.Value); + console.log(EnumB.Value); + } + + enum EnumA { Value } + const enum EnumB { Value } +} + +function func2() { + aFunc(); + + console.log(EnumA.Value); + + return; + + function aFunc() { + console.log(EnumA.Value); + } + + enum EnumA { Value } +} + +function func3() { + aFunc(); + + console.log(EnumB.Value); + + return; + + function aFunc() { + console.log(EnumB.Value); + } + + const enum EnumB { Value } +} + +function func4() { + aFunc(); + + console.log(ClassA.Value); + + return; + + function aFunc() { + console.log(ClassA.Value); + } + + class ClassA { static Value = 1234; } +} + +function func5() { + aFunc(); + + console.log(Bar.A); + console.log(blah.prop); + console.log(new Foo()) + console.log(Baz.value); + + + return; + + function aFunc() { + console.log(Bar.A); + console.log(blah.prop); + console.log(new Foo()) + console.log(Baz.value); + } + + const blah = { prop: 1234 }; + + enum Bar { A } + + class Foo { x = 1234 } + + namespace Baz { export const value = 1234 } +} + + +//// [unreachableDeclarations.js] +"use strict"; +function func1() { + aFunc(); + console.log(EnumA.Value); + console.log(0 /* EnumB.Value */); + return; + function aFunc() { + console.log(EnumA.Value); + console.log(0 /* EnumB.Value */); + } + var EnumA; + (function (EnumA) { + EnumA[EnumA["Value"] = 0] = "Value"; + })(EnumA || (EnumA = {})); + var EnumB; + (function (EnumB) { + EnumB[EnumB["Value"] = 0] = "Value"; + })(EnumB || (EnumB = {})); +} +function func2() { + aFunc(); + console.log(EnumA.Value); + return; + function aFunc() { + console.log(EnumA.Value); + } + var EnumA; + (function (EnumA) { + EnumA[EnumA["Value"] = 0] = "Value"; + })(EnumA || (EnumA = {})); +} +function func3() { + aFunc(); + console.log(0 /* EnumB.Value */); + return; + function aFunc() { + console.log(0 /* EnumB.Value */); + } + var EnumB; + (function (EnumB) { + EnumB[EnumB["Value"] = 0] = "Value"; + })(EnumB || (EnumB = {})); +} +function func4() { + aFunc(); + console.log(ClassA.Value); + return; + function aFunc() { + console.log(ClassA.Value); + } + var ClassA = /** @class */ (function () { + function ClassA() { + } + ClassA.Value = 1234; + return ClassA; + }()); +} +function func5() { + aFunc(); + console.log(Bar.A); + console.log(blah.prop); + console.log(new Foo()); + console.log(Baz.value); + return; + function aFunc() { + console.log(Bar.A); + console.log(blah.prop); + console.log(new Foo()); + console.log(Baz.value); + } + var blah = { prop: 1234 }; + var Bar; + (function (Bar) { + Bar[Bar["A"] = 0] = "A"; + })(Bar || (Bar = {})); + var Foo = /** @class */ (function () { + function Foo() { + this.x = 1234; + } + return Foo; + }()); + var Baz; + (function (Baz) { + Baz.value = 1234; + })(Baz || (Baz = {})); +} diff --git a/tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).symbols b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).symbols new file mode 100644 index 00000000000..20cadc7d774 --- /dev/null +++ b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).symbols @@ -0,0 +1,245 @@ +//// [tests/cases/compiler/unreachableDeclarations.ts] //// + +=== unreachableDeclarations.ts === +function func1() { +>func1 : Symbol(func1, Decl(unreachableDeclarations.ts, 0, 0)) + + aFunc(); +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 6, 11)) + + console.log(EnumA.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumA.Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 13, 16)) +>EnumA : Symbol(EnumA, Decl(unreachableDeclarations.ts, 11, 5)) +>Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 13, 16)) + + console.log(EnumB.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumB.Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 14, 22)) +>EnumB : Symbol(EnumB, Decl(unreachableDeclarations.ts, 13, 24)) +>Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 14, 22)) + + return; + + function aFunc() { +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 6, 11)) + + console.log(EnumA.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumA.Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 13, 16)) +>EnumA : Symbol(EnumA, Decl(unreachableDeclarations.ts, 11, 5)) +>Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 13, 16)) + + console.log(EnumB.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumB.Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 14, 22)) +>EnumB : Symbol(EnumB, Decl(unreachableDeclarations.ts, 13, 24)) +>Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 14, 22)) + } + + enum EnumA { Value } +>EnumA : Symbol(EnumA, Decl(unreachableDeclarations.ts, 11, 5)) +>Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 13, 16)) + + const enum EnumB { Value } +>EnumB : Symbol(EnumB, Decl(unreachableDeclarations.ts, 13, 24)) +>Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 14, 22)) +} + +function func2() { +>func2 : Symbol(func2, Decl(unreachableDeclarations.ts, 15, 1)) + + aFunc(); +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 22, 11)) + + console.log(EnumA.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumA.Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 28, 16)) +>EnumA : Symbol(EnumA, Decl(unreachableDeclarations.ts, 26, 5)) +>Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 28, 16)) + + return; + + function aFunc() { +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 22, 11)) + + console.log(EnumA.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumA.Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 28, 16)) +>EnumA : Symbol(EnumA, Decl(unreachableDeclarations.ts, 26, 5)) +>Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 28, 16)) + } + + enum EnumA { Value } +>EnumA : Symbol(EnumA, Decl(unreachableDeclarations.ts, 26, 5)) +>Value : Symbol(EnumA.Value, Decl(unreachableDeclarations.ts, 28, 16)) +} + +function func3() { +>func3 : Symbol(func3, Decl(unreachableDeclarations.ts, 29, 1)) + + aFunc(); +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 36, 11)) + + console.log(EnumB.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumB.Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 42, 22)) +>EnumB : Symbol(EnumB, Decl(unreachableDeclarations.ts, 40, 5)) +>Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 42, 22)) + + return; + + function aFunc() { +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 36, 11)) + + console.log(EnumB.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>EnumB.Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 42, 22)) +>EnumB : Symbol(EnumB, Decl(unreachableDeclarations.ts, 40, 5)) +>Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 42, 22)) + } + + const enum EnumB { Value } +>EnumB : Symbol(EnumB, Decl(unreachableDeclarations.ts, 40, 5)) +>Value : Symbol(EnumB.Value, Decl(unreachableDeclarations.ts, 42, 22)) +} + +function func4() { +>func4 : Symbol(func4, Decl(unreachableDeclarations.ts, 43, 1)) + + aFunc(); +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 50, 11)) + + console.log(ClassA.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>ClassA.Value : Symbol(ClassA.Value, Decl(unreachableDeclarations.ts, 56, 18)) +>ClassA : Symbol(ClassA, Decl(unreachableDeclarations.ts, 54, 5)) +>Value : Symbol(ClassA.Value, Decl(unreachableDeclarations.ts, 56, 18)) + + return; + + function aFunc() { +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 50, 11)) + + console.log(ClassA.Value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>ClassA.Value : Symbol(ClassA.Value, Decl(unreachableDeclarations.ts, 56, 18)) +>ClassA : Symbol(ClassA, Decl(unreachableDeclarations.ts, 54, 5)) +>Value : Symbol(ClassA.Value, Decl(unreachableDeclarations.ts, 56, 18)) + } + + class ClassA { static Value = 1234; } +>ClassA : Symbol(ClassA, Decl(unreachableDeclarations.ts, 54, 5)) +>Value : Symbol(ClassA.Value, Decl(unreachableDeclarations.ts, 56, 18)) +} + +function func5() { +>func5 : Symbol(func5, Decl(unreachableDeclarations.ts, 57, 1)) + + aFunc(); +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 68, 8)) + + console.log(Bar.A); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Bar.A : Symbol(Bar.A, Decl(unreachableDeclarations.ts, 79, 11)) +>Bar : Symbol(Bar, Decl(unreachableDeclarations.ts, 77, 29)) +>A : Symbol(Bar.A, Decl(unreachableDeclarations.ts, 79, 11)) + + console.log(blah.prop); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>blah.prop : Symbol(prop, Decl(unreachableDeclarations.ts, 77, 15)) +>blah : Symbol(blah, Decl(unreachableDeclarations.ts, 77, 6)) +>prop : Symbol(prop, Decl(unreachableDeclarations.ts, 77, 15)) + + console.log(new Foo()) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(unreachableDeclarations.ts, 79, 15)) + + console.log(Baz.value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Baz.value : Symbol(Baz.value, Decl(unreachableDeclarations.ts, 83, 29)) +>Baz : Symbol(Baz, Decl(unreachableDeclarations.ts, 81, 23)) +>value : Symbol(Baz.value, Decl(unreachableDeclarations.ts, 83, 29)) + + + return; + + function aFunc() { +>aFunc : Symbol(aFunc, Decl(unreachableDeclarations.ts, 68, 8)) + + console.log(Bar.A); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Bar.A : Symbol(Bar.A, Decl(unreachableDeclarations.ts, 79, 11)) +>Bar : Symbol(Bar, Decl(unreachableDeclarations.ts, 77, 29)) +>A : Symbol(Bar.A, Decl(unreachableDeclarations.ts, 79, 11)) + + console.log(blah.prop); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>blah.prop : Symbol(prop, Decl(unreachableDeclarations.ts, 77, 15)) +>blah : Symbol(blah, Decl(unreachableDeclarations.ts, 77, 6)) +>prop : Symbol(prop, Decl(unreachableDeclarations.ts, 77, 15)) + + console.log(new Foo()) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(unreachableDeclarations.ts, 79, 15)) + + console.log(Baz.value); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>Baz.value : Symbol(Baz.value, Decl(unreachableDeclarations.ts, 83, 29)) +>Baz : Symbol(Baz, Decl(unreachableDeclarations.ts, 81, 23)) +>value : Symbol(Baz.value, Decl(unreachableDeclarations.ts, 83, 29)) + } + + const blah = { prop: 1234 }; +>blah : Symbol(blah, Decl(unreachableDeclarations.ts, 77, 6)) +>prop : Symbol(prop, Decl(unreachableDeclarations.ts, 77, 15)) + + enum Bar { A } +>Bar : Symbol(Bar, Decl(unreachableDeclarations.ts, 77, 29)) +>A : Symbol(Bar.A, Decl(unreachableDeclarations.ts, 79, 11)) + + class Foo { x = 1234 } +>Foo : Symbol(Foo, Decl(unreachableDeclarations.ts, 79, 15)) +>x : Symbol(Foo.x, Decl(unreachableDeclarations.ts, 81, 12)) + + namespace Baz { export const value = 1234 } +>Baz : Symbol(Baz, Decl(unreachableDeclarations.ts, 81, 23)) +>value : Symbol(value, Decl(unreachableDeclarations.ts, 83, 29)) +} + diff --git a/tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).types b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).types new file mode 100644 index 00000000000..9a54857c8d2 --- /dev/null +++ b/tests/baselines/reference/unreachableDeclarations(preserveconstenums=true).types @@ -0,0 +1,442 @@ +//// [tests/cases/compiler/unreachableDeclarations.ts] //// + +=== unreachableDeclarations.ts === +function func1() { +>func1 : () => void +> : ^^^^^^^^^^ + + aFunc(); +>aFunc() : void +> : ^^^^ +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(EnumA.Value); +>console.log(EnumA.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumA.Value : EnumA +> : ^^^^^ +>EnumA : typeof EnumA +> : ^^^^^^^^^^^^ +>Value : EnumA +> : ^^^^^ + + console.log(EnumB.Value); +>console.log(EnumB.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumB.Value : EnumB +> : ^^^^^ +>EnumB : typeof EnumB +> : ^^^^^^^^^^^^ +>Value : EnumB +> : ^^^^^ + + return; + + function aFunc() { +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(EnumA.Value); +>console.log(EnumA.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumA.Value : EnumA +> : ^^^^^ +>EnumA : typeof EnumA +> : ^^^^^^^^^^^^ +>Value : EnumA +> : ^^^^^ + + console.log(EnumB.Value); +>console.log(EnumB.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumB.Value : EnumB +> : ^^^^^ +>EnumB : typeof EnumB +> : ^^^^^^^^^^^^ +>Value : EnumB +> : ^^^^^ + } + + enum EnumA { Value } +>EnumA : EnumA +> : ^^^^^ +>Value : EnumA.Value +> : ^^^^^^^^^^^ + + const enum EnumB { Value } +>EnumB : EnumB +> : ^^^^^ +>Value : EnumB.Value +> : ^^^^^^^^^^^ +} + +function func2() { +>func2 : () => void +> : ^^^^^^^^^^ + + aFunc(); +>aFunc() : void +> : ^^^^ +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(EnumA.Value); +>console.log(EnumA.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumA.Value : EnumA +> : ^^^^^ +>EnumA : typeof EnumA +> : ^^^^^^^^^^^^ +>Value : EnumA +> : ^^^^^ + + return; + + function aFunc() { +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(EnumA.Value); +>console.log(EnumA.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumA.Value : EnumA +> : ^^^^^ +>EnumA : typeof EnumA +> : ^^^^^^^^^^^^ +>Value : EnumA +> : ^^^^^ + } + + enum EnumA { Value } +>EnumA : EnumA +> : ^^^^^ +>Value : EnumA.Value +> : ^^^^^^^^^^^ +} + +function func3() { +>func3 : () => void +> : ^^^^^^^^^^ + + aFunc(); +>aFunc() : void +> : ^^^^ +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(EnumB.Value); +>console.log(EnumB.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumB.Value : EnumB +> : ^^^^^ +>EnumB : typeof EnumB +> : ^^^^^^^^^^^^ +>Value : EnumB +> : ^^^^^ + + return; + + function aFunc() { +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(EnumB.Value); +>console.log(EnumB.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>EnumB.Value : EnumB +> : ^^^^^ +>EnumB : typeof EnumB +> : ^^^^^^^^^^^^ +>Value : EnumB +> : ^^^^^ + } + + const enum EnumB { Value } +>EnumB : EnumB +> : ^^^^^ +>Value : EnumB.Value +> : ^^^^^^^^^^^ +} + +function func4() { +>func4 : () => void +> : ^^^^^^^^^^ + + aFunc(); +>aFunc() : void +> : ^^^^ +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(ClassA.Value); +>console.log(ClassA.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>ClassA.Value : number +> : ^^^^^^ +>ClassA : typeof ClassA +> : ^^^^^^^^^^^^^ +>Value : number +> : ^^^^^^ + + return; + + function aFunc() { +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(ClassA.Value); +>console.log(ClassA.Value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>ClassA.Value : number +> : ^^^^^^ +>ClassA : typeof ClassA +> : ^^^^^^^^^^^^^ +>Value : number +> : ^^^^^^ + } + + class ClassA { static Value = 1234; } +>ClassA : ClassA +> : ^^^^^^ +>Value : number +> : ^^^^^^ +>1234 : 1234 +> : ^^^^ +} + +function func5() { +>func5 : () => void +> : ^^^^^^^^^^ + + aFunc(); +>aFunc() : void +> : ^^^^ +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(Bar.A); +>console.log(Bar.A) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>Bar.A : Bar +> : ^^^ +>Bar : typeof Bar +> : ^^^^^^^^^^ +>A : Bar +> : ^^^ + + console.log(blah.prop); +>console.log(blah.prop) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>blah.prop : number +> : ^^^^^^ +>blah : { prop: number; } +> : ^^^^^^^^^^^^^^^^^ +>prop : number +> : ^^^^^^ + + console.log(new Foo()) +>console.log(new Foo()) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>new Foo() : Foo +> : ^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ + + console.log(Baz.value); +>console.log(Baz.value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>Baz.value : 1234 +> : ^^^^ +>Baz : typeof Baz +> : ^^^^^^^^^^ +>value : 1234 +> : ^^^^ + + + return; + + function aFunc() { +>aFunc : () => void +> : ^^^^^^^^^^ + + console.log(Bar.A); +>console.log(Bar.A) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>Bar.A : Bar +> : ^^^ +>Bar : typeof Bar +> : ^^^^^^^^^^ +>A : Bar +> : ^^^ + + console.log(blah.prop); +>console.log(blah.prop) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>blah.prop : number +> : ^^^^^^ +>blah : { prop: number; } +> : ^^^^^^^^^^^^^^^^^ +>prop : number +> : ^^^^^^ + + console.log(new Foo()) +>console.log(new Foo()) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>new Foo() : Foo +> : ^^^ +>Foo : typeof Foo +> : ^^^^^^^^^^ + + console.log(Baz.value); +>console.log(Baz.value) : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>Baz.value : 1234 +> : ^^^^ +>Baz : typeof Baz +> : ^^^^^^^^^^ +>value : 1234 +> : ^^^^ + } + + const blah = { prop: 1234 }; +>blah : { prop: number; } +> : ^^^^^^^^^^^^^^^^^ +>{ prop: 1234 } : { prop: number; } +> : ^^^^^^^^^^^^^^^^^ +>prop : number +> : ^^^^^^ +>1234 : 1234 +> : ^^^^ + + enum Bar { A } +>Bar : Bar +> : ^^^ +>A : Bar.A +> : ^^^^^ + + class Foo { x = 1234 } +>Foo : Foo +> : ^^^ +>x : number +> : ^^^^^^ +>1234 : 1234 +> : ^^^^ + + namespace Baz { export const value = 1234 } +>Baz : typeof Baz +> : ^^^^^^^^^^ +>value : 1234 +> : ^^^^ +>1234 : 1234 +> : ^^^^ +} + diff --git a/tests/cases/compiler/unreachableDeclarations.ts b/tests/cases/compiler/unreachableDeclarations.ts new file mode 100644 index 00000000000..71c30e8995c --- /dev/null +++ b/tests/cases/compiler/unreachableDeclarations.ts @@ -0,0 +1,89 @@ +// @strict: true +// @preserveConstEnums: true, false +// @allowUnreachableCode: false + +function func1() { + aFunc(); + + console.log(EnumA.Value); + console.log(EnumB.Value); + + return; + + function aFunc() { + console.log(EnumA.Value); + console.log(EnumB.Value); + } + + enum EnumA { Value } + const enum EnumB { Value } +} + +function func2() { + aFunc(); + + console.log(EnumA.Value); + + return; + + function aFunc() { + console.log(EnumA.Value); + } + + enum EnumA { Value } +} + +function func3() { + aFunc(); + + console.log(EnumB.Value); + + return; + + function aFunc() { + console.log(EnumB.Value); + } + + const enum EnumB { Value } +} + +function func4() { + aFunc(); + + console.log(ClassA.Value); + + return; + + function aFunc() { + console.log(ClassA.Value); + } + + class ClassA { static Value = 1234; } +} + +function func5() { + aFunc(); + + console.log(Bar.A); + console.log(blah.prop); + console.log(new Foo()) + console.log(Baz.value); + + + return; + + function aFunc() { + console.log(Bar.A); + console.log(blah.prop); + console.log(new Foo()) + console.log(Baz.value); + } + + const blah = { prop: 1234 }; + + enum Bar { A } + + class Foo { x = 1234 } + + namespace Baz { export const value = 1234 } +} diff --git a/tests/cases/fourslash/codeFixUnreachableCode.ts b/tests/cases/fourslash/codeFixUnreachableCode.ts index 3940fbd9163..b5ad96e775b 100644 --- a/tests/cases/fourslash/codeFixUnreachableCode.ts +++ b/tests/cases/fourslash/codeFixUnreachableCode.ts @@ -8,7 +8,7 @@ //// type T = number; //// interface I {} //// const enum E {} -//// enum EE {} +//// [|enum EE {}|] //// namespace N { export type T = number; } //// [|namespace N { export const x: T = 0; }|] //// var x: I; @@ -33,7 +33,6 @@ verify.codeFixAll({ type T = number; interface I {} const enum E {} - enum EE {} namespace N { export type T = number; } var x: I; }`,