diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ed3057895fae8..057ac1e0d49e1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27464,7 +27464,7 @@ namespace ts { (node.parent.kind === SyntaxKind.ElementAccessExpression && (node.parent).expression === node) || ((node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName) && isInRightSideOfImportOrExportAssignment(node) || (node.parent.kind === SyntaxKind.TypeQuery && (node.parent).exprName === node)) || - (node.parent.kind === SyntaxKind.ExportSpecifier && (compilerOptions.preserveConstEnums || node.flags & NodeFlags.Ambient)); // We allow reexporting const enums + (node.parent.kind === SyntaxKind.ExportSpecifier); // We allow reexporting const enums if (!ok) { error(node, Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment_or_type_query); diff --git a/tests/baselines/reference/constEnumNoEmitReexport.js b/tests/baselines/reference/constEnumNoEmitReexport.js new file mode 100644 index 0000000000000..de1ed1ff03275 --- /dev/null +++ b/tests/baselines/reference/constEnumNoEmitReexport.js @@ -0,0 +1,59 @@ +//// [tests/cases/compiler/constEnumNoEmitReexport.ts] //// + +//// [ConstEnum.ts] +export const enum MyConstEnum { + Foo, + Bar +}; +//// [ImportExport.ts] +import { MyConstEnum } from './ConstEnum'; +export { MyConstEnum }; +//// [ImportExportDefault.ts] +import { MyConstEnum } from './ConstEnum'; +export default MyConstEnum; +//// [ReExportDefault.ts] +export { MyConstEnum as default } from './ConstEnum'; +//// [ReExport.ts] +export { MyConstEnum } from './ConstEnum'; +//// [Usage1.ts] +import MyConstEnum1 from './ImportExportDefault'; +import MyConstEnum2 from './ReExportDefault'; +MyConstEnum1.Foo; +MyConstEnum2.Foo; +//// [Usage2.ts] +import { MyConstEnum } from './ImportExport'; +MyConstEnum.Foo; +//// [Usage3.ts] +import { MyConstEnum } from './ReExport'; +MyConstEnum.Foo; + + +//// [ConstEnum.js] +"use strict"; +exports.__esModule = true; +; +//// [ImportExport.js] +"use strict"; +exports.__esModule = true; +//// [ImportExportDefault.js] +"use strict"; +exports.__esModule = true; +//// [ReExportDefault.js] +"use strict"; +exports.__esModule = true; +//// [ReExport.js] +"use strict"; +exports.__esModule = true; +//// [Usage1.js] +"use strict"; +exports.__esModule = true; +0 /* Foo */; +0 /* Foo */; +//// [Usage2.js] +"use strict"; +exports.__esModule = true; +0 /* Foo */; +//// [Usage3.js] +"use strict"; +exports.__esModule = true; +0 /* Foo */; diff --git a/tests/baselines/reference/constEnumNoEmitReexport.symbols b/tests/baselines/reference/constEnumNoEmitReexport.symbols new file mode 100644 index 0000000000000..894da1c6705cf --- /dev/null +++ b/tests/baselines/reference/constEnumNoEmitReexport.symbols @@ -0,0 +1,69 @@ +=== tests/cases/compiler/ConstEnum.ts === +export const enum MyConstEnum { +>MyConstEnum : Symbol(MyConstEnum, Decl(ConstEnum.ts, 0, 0)) + + Foo, +>Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.ts, 0, 31)) + + Bar +>Bar : Symbol(MyConstEnum.Bar, Decl(ConstEnum.ts, 1, 8)) + +}; +=== tests/cases/compiler/ImportExport.ts === +import { MyConstEnum } from './ConstEnum'; +>MyConstEnum : Symbol(MyConstEnum, Decl(ImportExport.ts, 0, 8)) + +export { MyConstEnum }; +>MyConstEnum : Symbol(MyConstEnum, Decl(ImportExport.ts, 1, 8)) + +=== tests/cases/compiler/ImportExportDefault.ts === +import { MyConstEnum } from './ConstEnum'; +>MyConstEnum : Symbol(MyConstEnum, Decl(ImportExportDefault.ts, 0, 8)) + +export default MyConstEnum; +>MyConstEnum : Symbol(MyConstEnum, Decl(ImportExportDefault.ts, 0, 8)) + +=== tests/cases/compiler/ReExportDefault.ts === +export { MyConstEnum as default } from './ConstEnum'; +>MyConstEnum : Symbol(MyConstEnum, Decl(ConstEnum.ts, 0, 0)) +>default : Symbol(default, Decl(ReExportDefault.ts, 0, 8)) + +=== tests/cases/compiler/ReExport.ts === +export { MyConstEnum } from './ConstEnum'; +>MyConstEnum : Symbol(MyConstEnum, Decl(ReExport.ts, 0, 8)) + +=== tests/cases/compiler/Usage1.ts === +import MyConstEnum1 from './ImportExportDefault'; +>MyConstEnum1 : Symbol(MyConstEnum1, Decl(Usage1.ts, 0, 6)) + +import MyConstEnum2 from './ReExportDefault'; +>MyConstEnum2 : Symbol(MyConstEnum2, Decl(Usage1.ts, 1, 6)) + +MyConstEnum1.Foo; +>MyConstEnum1.Foo : Symbol(MyConstEnum1.Foo, Decl(ConstEnum.ts, 0, 31)) +>MyConstEnum1 : Symbol(MyConstEnum1, Decl(Usage1.ts, 0, 6)) +>Foo : Symbol(MyConstEnum1.Foo, Decl(ConstEnum.ts, 0, 31)) + +MyConstEnum2.Foo; +>MyConstEnum2.Foo : Symbol(MyConstEnum1.Foo, Decl(ConstEnum.ts, 0, 31)) +>MyConstEnum2 : Symbol(MyConstEnum2, Decl(Usage1.ts, 1, 6)) +>Foo : Symbol(MyConstEnum1.Foo, Decl(ConstEnum.ts, 0, 31)) + +=== tests/cases/compiler/Usage2.ts === +import { MyConstEnum } from './ImportExport'; +>MyConstEnum : Symbol(MyConstEnum, Decl(Usage2.ts, 0, 8)) + +MyConstEnum.Foo; +>MyConstEnum.Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.ts, 0, 31)) +>MyConstEnum : Symbol(MyConstEnum, Decl(Usage2.ts, 0, 8)) +>Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.ts, 0, 31)) + +=== tests/cases/compiler/Usage3.ts === +import { MyConstEnum } from './ReExport'; +>MyConstEnum : Symbol(MyConstEnum, Decl(Usage3.ts, 0, 8)) + +MyConstEnum.Foo; +>MyConstEnum.Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.ts, 0, 31)) +>MyConstEnum : Symbol(MyConstEnum, Decl(Usage3.ts, 0, 8)) +>Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.ts, 0, 31)) + diff --git a/tests/baselines/reference/constEnumNoEmitReexport.types b/tests/baselines/reference/constEnumNoEmitReexport.types new file mode 100644 index 0000000000000..cec0dfeb03ff6 --- /dev/null +++ b/tests/baselines/reference/constEnumNoEmitReexport.types @@ -0,0 +1,69 @@ +=== tests/cases/compiler/ConstEnum.ts === +export const enum MyConstEnum { +>MyConstEnum : MyConstEnum + + Foo, +>Foo : MyConstEnum.Foo + + Bar +>Bar : MyConstEnum.Bar + +}; +=== tests/cases/compiler/ImportExport.ts === +import { MyConstEnum } from './ConstEnum'; +>MyConstEnum : typeof MyConstEnum + +export { MyConstEnum }; +>MyConstEnum : typeof MyConstEnum + +=== tests/cases/compiler/ImportExportDefault.ts === +import { MyConstEnum } from './ConstEnum'; +>MyConstEnum : typeof MyConstEnum + +export default MyConstEnum; +>MyConstEnum : MyConstEnum + +=== tests/cases/compiler/ReExportDefault.ts === +export { MyConstEnum as default } from './ConstEnum'; +>MyConstEnum : typeof import("tests/cases/compiler/ConstEnum").MyConstEnum +>default : typeof import("tests/cases/compiler/ConstEnum").MyConstEnum + +=== tests/cases/compiler/ReExport.ts === +export { MyConstEnum } from './ConstEnum'; +>MyConstEnum : typeof import("tests/cases/compiler/ConstEnum").MyConstEnum + +=== tests/cases/compiler/Usage1.ts === +import MyConstEnum1 from './ImportExportDefault'; +>MyConstEnum1 : typeof MyConstEnum1 + +import MyConstEnum2 from './ReExportDefault'; +>MyConstEnum2 : typeof MyConstEnum1 + +MyConstEnum1.Foo; +>MyConstEnum1.Foo : MyConstEnum1.Foo +>MyConstEnum1 : typeof MyConstEnum1 +>Foo : MyConstEnum1.Foo + +MyConstEnum2.Foo; +>MyConstEnum2.Foo : MyConstEnum1.Foo +>MyConstEnum2 : typeof MyConstEnum1 +>Foo : MyConstEnum1.Foo + +=== tests/cases/compiler/Usage2.ts === +import { MyConstEnum } from './ImportExport'; +>MyConstEnum : typeof MyConstEnum + +MyConstEnum.Foo; +>MyConstEnum.Foo : MyConstEnum.Foo +>MyConstEnum : typeof MyConstEnum +>Foo : MyConstEnum.Foo + +=== tests/cases/compiler/Usage3.ts === +import { MyConstEnum } from './ReExport'; +>MyConstEnum : typeof MyConstEnum + +MyConstEnum.Foo; +>MyConstEnum.Foo : MyConstEnum.Foo +>MyConstEnum : typeof MyConstEnum +>Foo : MyConstEnum.Foo + diff --git a/tests/baselines/reference/exportsAndImports1-amd.errors.txt b/tests/baselines/reference/exportsAndImports1-amd.errors.txt deleted file mode 100644 index 713f464a60805..0000000000000 --- a/tests/baselines/reference/exportsAndImports1-amd.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/conformance/es6/modules/t1.ts(23,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/conformance/es6/modules/t3.ts(2,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - - -==== tests/cases/conformance/es6/modules/t1.ts (1 errors) ==== - var v = 1; - function f() { } - class C { - } - interface I { - } - enum E { - A, B, C - } - const enum D { - A, B, C - } - module M { - export var x; - } - module N { - export interface I { - } - } - type T = number; - import a = M.x; - - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - -==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== - export { v, f, C, I, E, D, M, N, T, a } from "./t1"; - -==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ==== - import { v, f, C, I, E, D, M, N, T, a } from "./t1"; - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImports1-es6.errors.txt b/tests/baselines/reference/exportsAndImports1-es6.errors.txt deleted file mode 100644 index 713f464a60805..0000000000000 --- a/tests/baselines/reference/exportsAndImports1-es6.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/conformance/es6/modules/t1.ts(23,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/conformance/es6/modules/t3.ts(2,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - - -==== tests/cases/conformance/es6/modules/t1.ts (1 errors) ==== - var v = 1; - function f() { } - class C { - } - interface I { - } - enum E { - A, B, C - } - const enum D { - A, B, C - } - module M { - export var x; - } - module N { - export interface I { - } - } - type T = number; - import a = M.x; - - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - -==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== - export { v, f, C, I, E, D, M, N, T, a } from "./t1"; - -==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ==== - import { v, f, C, I, E, D, M, N, T, a } from "./t1"; - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImports1.errors.txt b/tests/baselines/reference/exportsAndImports1.errors.txt deleted file mode 100644 index 713f464a60805..0000000000000 --- a/tests/baselines/reference/exportsAndImports1.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/conformance/es6/modules/t1.ts(23,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/conformance/es6/modules/t3.ts(2,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - - -==== tests/cases/conformance/es6/modules/t1.ts (1 errors) ==== - var v = 1; - function f() { } - class C { - } - interface I { - } - enum E { - A, B, C - } - const enum D { - A, B, C - } - module M { - export var x; - } - module N { - export interface I { - } - } - type T = number; - import a = M.x; - - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - -==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== - export { v, f, C, I, E, D, M, N, T, a } from "./t1"; - -==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ==== - import { v, f, C, I, E, D, M, N, T, a } from "./t1"; - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImports3-amd.errors.txt b/tests/baselines/reference/exportsAndImports3-amd.errors.txt deleted file mode 100644 index b084c1193f47d..0000000000000 --- a/tests/baselines/reference/exportsAndImports3-amd.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/conformance/es6/modules/t1.ts(23,55): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/conformance/es6/modules/t3.ts(2,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - - -==== tests/cases/conformance/es6/modules/t1.ts (1 errors) ==== - export var v = 1; - export function f() { } - export class C { - } - export interface I { - } - export enum E { - A, B, C - } - export const enum D { - A, B, C - } - export module M { - export var x; - } - export module N { - export interface I { - } - } - export type T = number; - export import a = M.x; - - export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - -==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== - export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; - -==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ==== - import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImports3-es6.errors.txt b/tests/baselines/reference/exportsAndImports3-es6.errors.txt deleted file mode 100644 index b084c1193f47d..0000000000000 --- a/tests/baselines/reference/exportsAndImports3-es6.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/conformance/es6/modules/t1.ts(23,55): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/conformance/es6/modules/t3.ts(2,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - - -==== tests/cases/conformance/es6/modules/t1.ts (1 errors) ==== - export var v = 1; - export function f() { } - export class C { - } - export interface I { - } - export enum E { - A, B, C - } - export const enum D { - A, B, C - } - export module M { - export var x; - } - export module N { - export interface I { - } - } - export type T = number; - export import a = M.x; - - export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - -==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== - export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; - -==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ==== - import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImports3.errors.txt b/tests/baselines/reference/exportsAndImports3.errors.txt deleted file mode 100644 index b084c1193f47d..0000000000000 --- a/tests/baselines/reference/exportsAndImports3.errors.txt +++ /dev/null @@ -1,40 +0,0 @@ -tests/cases/conformance/es6/modules/t1.ts(23,55): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. -tests/cases/conformance/es6/modules/t3.ts(2,25): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - - -==== tests/cases/conformance/es6/modules/t1.ts (1 errors) ==== - export var v = 1; - export function f() { } - export class C { - } - export interface I { - } - export enum E { - A, B, C - } - export const enum D { - A, B, C - } - export module M { - export var x; - } - export module N { - export interface I { - } - } - export type T = number; - export import a = M.x; - - export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - -==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== - export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; - -==== tests/cases/conformance/es6/modules/t3.ts (1 errors) ==== - import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; - export { v, f, C, I, E, D, M, N, T, a }; - ~ -!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment or type query. - \ No newline at end of file diff --git a/tests/cases/compiler/constEnumNoEmitReexport.ts b/tests/cases/compiler/constEnumNoEmitReexport.ts new file mode 100644 index 0000000000000..9ef57f1255061 --- /dev/null +++ b/tests/cases/compiler/constEnumNoEmitReexport.ts @@ -0,0 +1,26 @@ +// @filename: ConstEnum.ts +export const enum MyConstEnum { + Foo, + Bar +}; +// @filename: ImportExport.ts +import { MyConstEnum } from './ConstEnum'; +export { MyConstEnum }; +// @filename: ImportExportDefault.ts +import { MyConstEnum } from './ConstEnum'; +export default MyConstEnum; +// @filename: ReExportDefault.ts +export { MyConstEnum as default } from './ConstEnum'; +// @filename: ReExport.ts +export { MyConstEnum } from './ConstEnum'; +// @filename: Usage1.ts +import MyConstEnum1 from './ImportExportDefault'; +import MyConstEnum2 from './ReExportDefault'; +MyConstEnum1.Foo; +MyConstEnum2.Foo; +// @filename: Usage2.ts +import { MyConstEnum } from './ImportExport'; +MyConstEnum.Foo; +// @filename: Usage3.ts +import { MyConstEnum } from './ReExport'; +MyConstEnum.Foo;