diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f699c08b4db..85f2f84c677 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2380,7 +2380,7 @@ namespace ts { return links.target; } - function markExportAsReferenced(node: ImportEqualsDeclaration | ExportAssignment | ExportSpecifier) { + function markExportAsReferenced(node: ImportEqualsDeclaration | ExportSpecifier) { const symbol = getSymbolOfNode(node); const target = resolveAlias(symbol); if (target) { @@ -2402,15 +2402,10 @@ namespace ts { links.referenced = true; const node = getDeclarationOfAliasSymbol(symbol); if (!node) return Debug.fail(); - if (node.kind === SyntaxKind.ExportAssignment) { - // export default - checkExpressionCached((node).expression); - } - else if (node.kind === SyntaxKind.ExportSpecifier) { - // export { } or export { as foo } - checkExpressionCached((node).propertyName || (node).name); - } - else if (isInternalModuleImportEqualsDeclaration(node)) { + // We defer checking of the reference of an `import =` until the import itself is referenced, + // This way a chain of imports can be elided if ultimately the final input is only used in a type + // position. + if (isInternalModuleImportEqualsDeclaration(node)) { // import foo = checkExpressionCached(node.moduleReference); } @@ -17833,8 +17828,12 @@ namespace ts { return type; } + function isExportOrExportExpression(location: Node) { + return !!findAncestor(location, e => e.parent && isExportAssignment(e.parent) && e.parent.expression === e && isEntityNameExpression(e)); + } + function markAliasReferenced(symbol: Symbol, location: Node) { - if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { + if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(location) && ((compilerOptions.preserveConstEnums && isExportOrExportExpression(location)) || !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol)))) { markAliasSymbolAsReferenced(symbol); } } @@ -20345,8 +20344,8 @@ namespace ts { // if jsx emit was not react as there wont be error being emitted reactSym.isReferenced = SymbolFlags.All; - // If react symbol is alias, mark it as referenced - if (reactSym.flags & SymbolFlags.Alias && !isConstEnumOrConstEnumOnlyModule(resolveAlias(reactSym))) { + // If react symbol is alias, mark it as refereced + if (reactSym.flags & SymbolFlags.Alias) { markAliasSymbolAsReferenced(reactSym); } } @@ -24897,7 +24896,7 @@ namespace ts { return result; } - function checkExpressionCached(node: Expression, checkMode?: CheckMode): Type { + function checkExpressionCached(node: Expression | QualifiedName, checkMode?: CheckMode): Type { const links = getNodeLinks(node); if (!links.resolvedType) { if (checkMode && checkMode !== CheckMode.Normal) { @@ -25225,7 +25224,8 @@ namespace ts { (node.parent.kind === SyntaxKind.PropertyAccessExpression && (node.parent).expression === node) || (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.TypeQuery && (node.parent).exprName === node)) || + (node.parent.kind === SyntaxKind.ExportSpecifier && (compilerOptions.preserveConstEnums || node.flags & NodeFlags.Ambient)); // 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); @@ -30153,6 +30153,10 @@ namespace ts { } else { markExportAsReferenced(node); + const target = symbol && (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol); + if (!target || target === unknownSymbol || target.flags & SymbolFlags.Value) { + checkExpressionCached(node.propertyName || node.name); + } } } } @@ -30179,7 +30183,17 @@ namespace ts { grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers); } if (node.expression.kind === SyntaxKind.Identifier) { - markExportAsReferenced(node); + const id = node.expression as Identifier; + const sym = resolveEntityName(id, SymbolFlags.All, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, node); + if (sym) { + markAliasReferenced(sym, id); + // If not a value, we're interpreting the identifier as a type export, along the lines of (`export { Id as default }`) + const target = sym.flags & SymbolFlags.Alias ? resolveAlias(sym) : sym; + if (target === unknownSymbol || target.flags & SymbolFlags.Value) { + // However if it is a value, we need to check it's being used correctly + checkExpressionCached(node.expression); + } + } if (getEmitDeclarations(compilerOptions)) { collectLinkedAliases(node.expression as Identifier, /*setVisibility*/ true); diff --git a/tests/baselines/reference/amdModuleConstEnumUsage.js b/tests/baselines/reference/amdModuleConstEnumUsage.js new file mode 100644 index 00000000000..a15bdb42ea3 --- /dev/null +++ b/tests/baselines/reference/amdModuleConstEnumUsage.js @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/amdModuleConstEnumUsage.ts] //// + +//// [cc.ts] +export const enum CharCode { + A, + B +} +//// [file.ts] +import { CharCode } from 'defs/cc'; +export class User { + method(input: number) { + if (CharCode.A === input) {} + } +} + + +//// [cc.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + var CharCode; + (function (CharCode) { + CharCode[CharCode["A"] = 0] = "A"; + CharCode[CharCode["B"] = 1] = "B"; + })(CharCode = exports.CharCode || (exports.CharCode = {})); +}); +//// [file.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + var User = /** @class */ (function () { + function User() { + } + User.prototype.method = function (input) { + if (0 /* A */ === input) { } + }; + return User; + }()); + exports.User = User; +}); diff --git a/tests/baselines/reference/amdModuleConstEnumUsage.symbols b/tests/baselines/reference/amdModuleConstEnumUsage.symbols new file mode 100644 index 00000000000..d6831b01814 --- /dev/null +++ b/tests/baselines/reference/amdModuleConstEnumUsage.symbols @@ -0,0 +1,29 @@ +=== /proj/defs/cc.ts === +export const enum CharCode { +>CharCode : Symbol(CharCode, Decl(cc.ts, 0, 0)) + + A, +>A : Symbol(CharCode.A, Decl(cc.ts, 0, 28)) + + B +>B : Symbol(CharCode.B, Decl(cc.ts, 1, 6)) +} +=== /proj/component/file.ts === +import { CharCode } from 'defs/cc'; +>CharCode : Symbol(CharCode, Decl(file.ts, 0, 8)) + +export class User { +>User : Symbol(User, Decl(file.ts, 0, 35)) + + method(input: number) { +>method : Symbol(User.method, Decl(file.ts, 1, 19)) +>input : Symbol(input, Decl(file.ts, 2, 11)) + + if (CharCode.A === input) {} +>CharCode.A : Symbol(CharCode.A, Decl(cc.ts, 0, 28)) +>CharCode : Symbol(CharCode, Decl(file.ts, 0, 8)) +>A : Symbol(CharCode.A, Decl(cc.ts, 0, 28)) +>input : Symbol(input, Decl(file.ts, 2, 11)) + } +} + diff --git a/tests/baselines/reference/amdModuleConstEnumUsage.types b/tests/baselines/reference/amdModuleConstEnumUsage.types new file mode 100644 index 00000000000..2070c5733a0 --- /dev/null +++ b/tests/baselines/reference/amdModuleConstEnumUsage.types @@ -0,0 +1,30 @@ +=== /proj/defs/cc.ts === +export const enum CharCode { +>CharCode : CharCode + + A, +>A : CharCode.A + + B +>B : CharCode.B +} +=== /proj/component/file.ts === +import { CharCode } from 'defs/cc'; +>CharCode : typeof CharCode + +export class User { +>User : User + + method(input: number) { +>method : (input: number) => void +>input : number + + if (CharCode.A === input) {} +>CharCode.A === input : boolean +>CharCode.A : CharCode.A +>CharCode : typeof CharCode +>A : CharCode.A +>input : number + } +} + diff --git a/tests/baselines/reference/constEnumNoPreserveDeclarationReexport.js b/tests/baselines/reference/constEnumNoPreserveDeclarationReexport.js new file mode 100644 index 00000000000..0edacd183ef --- /dev/null +++ b/tests/baselines/reference/constEnumNoPreserveDeclarationReexport.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/constEnumNoPreserveDeclarationReexport.ts] //// + +//// [ConstEnum.d.ts] +export const enum MyConstEnum { + Foo, + Bar +} +//// [ImportExport.d.ts] +import { MyConstEnum } from './ConstEnum'; +export default MyConstEnum; +//// [ReExport.d.ts] +export { MyConstEnum as default } from './ConstEnum'; +//// [usages.ts] +import {MyConstEnum} from "./ConstEnum"; +import AlsoEnum from "./ImportExport"; +import StillEnum from "./ReExport"; + +MyConstEnum.Foo; +AlsoEnum.Foo; +StillEnum.Foo; + + +//// [usages.js] +"use strict"; +exports.__esModule = true; +0 /* Foo */; +0 /* Foo */; +0 /* Foo */; diff --git a/tests/baselines/reference/constEnumNoPreserveDeclarationReexport.symbols b/tests/baselines/reference/constEnumNoPreserveDeclarationReexport.symbols new file mode 100644 index 00000000000..62f839e02dd --- /dev/null +++ b/tests/baselines/reference/constEnumNoPreserveDeclarationReexport.symbols @@ -0,0 +1,47 @@ +=== tests/cases/compiler/ConstEnum.d.ts === +export const enum MyConstEnum { +>MyConstEnum : Symbol(MyConstEnum, Decl(ConstEnum.d.ts, 0, 0)) + + Foo, +>Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.d.ts, 0, 31)) + + Bar +>Bar : Symbol(MyConstEnum.Bar, Decl(ConstEnum.d.ts, 1, 8)) +} +=== tests/cases/compiler/ImportExport.d.ts === +import { MyConstEnum } from './ConstEnum'; +>MyConstEnum : Symbol(MyConstEnum, Decl(ImportExport.d.ts, 0, 8)) + +export default MyConstEnum; +>MyConstEnum : Symbol(MyConstEnum, Decl(ImportExport.d.ts, 0, 8)) + +=== tests/cases/compiler/ReExport.d.ts === +export { MyConstEnum as default } from './ConstEnum'; +>MyConstEnum : Symbol(MyConstEnum, Decl(ConstEnum.d.ts, 0, 0)) +>default : Symbol(default, Decl(ReExport.d.ts, 0, 8)) + +=== tests/cases/compiler/usages.ts === +import {MyConstEnum} from "./ConstEnum"; +>MyConstEnum : Symbol(MyConstEnum, Decl(usages.ts, 0, 8)) + +import AlsoEnum from "./ImportExport"; +>AlsoEnum : Symbol(AlsoEnum, Decl(usages.ts, 1, 6)) + +import StillEnum from "./ReExport"; +>StillEnum : Symbol(StillEnum, Decl(usages.ts, 2, 6)) + +MyConstEnum.Foo; +>MyConstEnum.Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.d.ts, 0, 31)) +>MyConstEnum : Symbol(MyConstEnum, Decl(usages.ts, 0, 8)) +>Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.d.ts, 0, 31)) + +AlsoEnum.Foo; +>AlsoEnum.Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.d.ts, 0, 31)) +>AlsoEnum : Symbol(AlsoEnum, Decl(usages.ts, 1, 6)) +>Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.d.ts, 0, 31)) + +StillEnum.Foo; +>StillEnum.Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.d.ts, 0, 31)) +>StillEnum : Symbol(StillEnum, Decl(usages.ts, 2, 6)) +>Foo : Symbol(MyConstEnum.Foo, Decl(ConstEnum.d.ts, 0, 31)) + diff --git a/tests/baselines/reference/constEnumNoPreserveDeclarationReexport.types b/tests/baselines/reference/constEnumNoPreserveDeclarationReexport.types new file mode 100644 index 00000000000..f68ae116a18 --- /dev/null +++ b/tests/baselines/reference/constEnumNoPreserveDeclarationReexport.types @@ -0,0 +1,47 @@ +=== tests/cases/compiler/ConstEnum.d.ts === +export const enum MyConstEnum { +>MyConstEnum : MyConstEnum + + Foo, +>Foo : MyConstEnum + + Bar +>Bar : MyConstEnum +} +=== tests/cases/compiler/ImportExport.d.ts === +import { MyConstEnum } from './ConstEnum'; +>MyConstEnum : typeof MyConstEnum + +export default MyConstEnum; +>MyConstEnum : MyConstEnum + +=== tests/cases/compiler/ReExport.d.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/usages.ts === +import {MyConstEnum} from "./ConstEnum"; +>MyConstEnum : typeof MyConstEnum + +import AlsoEnum from "./ImportExport"; +>AlsoEnum : typeof MyConstEnum + +import StillEnum from "./ReExport"; +>StillEnum : typeof MyConstEnum + +MyConstEnum.Foo; +>MyConstEnum.Foo : MyConstEnum +>MyConstEnum : typeof MyConstEnum +>Foo : MyConstEnum + +AlsoEnum.Foo; +>AlsoEnum.Foo : MyConstEnum +>AlsoEnum : typeof MyConstEnum +>Foo : MyConstEnum + +StillEnum.Foo; +>StillEnum.Foo : MyConstEnum +>StillEnum : typeof MyConstEnum +>Foo : MyConstEnum + diff --git a/tests/baselines/reference/constEnumPreserveEmitReexport.js b/tests/baselines/reference/constEnumPreserveEmitReexport.js new file mode 100644 index 00000000000..24914ee899b --- /dev/null +++ b/tests/baselines/reference/constEnumPreserveEmitReexport.js @@ -0,0 +1,32 @@ +//// [tests/cases/compiler/constEnumPreserveEmitReexport.ts] //// + +//// [ConstEnum.ts] +export const enum MyConstEnum { + Foo, + Bar +}; +//// [ImportExport.ts] +import { MyConstEnum } from './ConstEnum'; +export default MyConstEnum; +//// [ReExport.ts] +export { MyConstEnum as default } from './ConstEnum'; + +//// [ConstEnum.js] +"use strict"; +exports.__esModule = true; +var MyConstEnum; +(function (MyConstEnum) { + MyConstEnum[MyConstEnum["Foo"] = 0] = "Foo"; + MyConstEnum[MyConstEnum["Bar"] = 1] = "Bar"; +})(MyConstEnum = exports.MyConstEnum || (exports.MyConstEnum = {})); +; +//// [ImportExport.js] +"use strict"; +exports.__esModule = true; +var ConstEnum_1 = require("./ConstEnum"); +exports["default"] = ConstEnum_1.MyConstEnum; +//// [ReExport.js] +"use strict"; +exports.__esModule = true; +var ConstEnum_1 = require("./ConstEnum"); +exports["default"] = ConstEnum_1.MyConstEnum; diff --git a/tests/baselines/reference/constEnumPreserveEmitReexport.symbols b/tests/baselines/reference/constEnumPreserveEmitReexport.symbols new file mode 100644 index 00000000000..0e4e240b4f4 --- /dev/null +++ b/tests/baselines/reference/constEnumPreserveEmitReexport.symbols @@ -0,0 +1,23 @@ +=== 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 default MyConstEnum; +>MyConstEnum : Symbol(MyConstEnum, Decl(ImportExport.ts, 0, 8)) + +=== tests/cases/compiler/ReExport.ts === +export { MyConstEnum as default } from './ConstEnum'; +>MyConstEnum : Symbol(MyConstEnum, Decl(ConstEnum.ts, 0, 0)) +>default : Symbol(default, Decl(ReExport.ts, 0, 8)) + diff --git a/tests/baselines/reference/constEnumPreserveEmitReexport.types b/tests/baselines/reference/constEnumPreserveEmitReexport.types new file mode 100644 index 00000000000..d003cdd878a --- /dev/null +++ b/tests/baselines/reference/constEnumPreserveEmitReexport.types @@ -0,0 +1,23 @@ +=== 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 default MyConstEnum; +>MyConstEnum : MyConstEnum + +=== tests/cases/compiler/ReExport.ts === +export { MyConstEnum as default } from './ConstEnum'; +>MyConstEnum : typeof import("tests/cases/compiler/ConstEnum").MyConstEnum +>default : typeof import("tests/cases/compiler/ConstEnum").MyConstEnum + diff --git a/tests/baselines/reference/exportAsNamespaceConflict.errors.txt b/tests/baselines/reference/exportAsNamespaceConflict.errors.txt index 02d7f859a69..4b08c736069 100644 --- a/tests/baselines/reference/exportAsNamespaceConflict.errors.txt +++ b/tests/baselines/reference/exportAsNamespaceConflict.errors.txt @@ -1,12 +1,9 @@ -/a.d.ts(2,10): error TS2708: Cannot use namespace 'N' as a value. /a.d.ts(3,1): error TS2303: Circular definition of import alias 'N'. -==== /a.d.ts (2 errors) ==== +==== /a.d.ts (1 errors) ==== declare global { namespace N {} } export = N; - ~ -!!! error TS2708: Cannot use namespace 'N' as a value. export as namespace N; ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2303: Circular definition of import alias 'N'. diff --git a/tests/baselines/reference/exportsAndImports1-amd.errors.txt b/tests/baselines/reference/exportsAndImports1-amd.errors.txt new file mode 100644 index 00000000000..713f464a608 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports1-amd.errors.txt @@ -0,0 +1,40 @@ +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 new file mode 100644 index 00000000000..713f464a608 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports1-es6.errors.txt @@ -0,0 +1,40 @@ +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 new file mode 100644 index 00000000000..713f464a608 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports1.errors.txt @@ -0,0 +1,40 @@ +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 new file mode 100644 index 00000000000..b084c1193f4 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports3-amd.errors.txt @@ -0,0 +1,40 @@ +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 new file mode 100644 index 00000000000..b084c1193f4 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports3-es6.errors.txt @@ -0,0 +1,40 @@ +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 new file mode 100644 index 00000000000..b084c1193f4 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports3.errors.txt @@ -0,0 +1,40 @@ +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/amdModuleConstEnumUsage.ts b/tests/cases/compiler/amdModuleConstEnumUsage.ts new file mode 100644 index 00000000000..6778aee0cdd --- /dev/null +++ b/tests/cases/compiler/amdModuleConstEnumUsage.ts @@ -0,0 +1,16 @@ +// @module: amd +// @preserveConstEnums: true +// @baseUrl: /proj +// @filename: /proj/defs/cc.ts +export const enum CharCode { + A, + B +} +// @filename: /proj/component/file.ts + +import { CharCode } from 'defs/cc'; +export class User { + method(input: number) { + if (CharCode.A === input) {} + } +} diff --git a/tests/cases/compiler/constEnumNoPreserveDeclarationReexport.ts b/tests/cases/compiler/constEnumNoPreserveDeclarationReexport.ts new file mode 100644 index 00000000000..293aade8d57 --- /dev/null +++ b/tests/cases/compiler/constEnumNoPreserveDeclarationReexport.ts @@ -0,0 +1,18 @@ +// @filename: ConstEnum.d.ts +export const enum MyConstEnum { + Foo, + Bar +} +// @filename: ImportExport.d.ts +import { MyConstEnum } from './ConstEnum'; +export default MyConstEnum; +// @filename: ReExport.d.ts +export { MyConstEnum as default } from './ConstEnum'; +// @filename: usages.ts +import {MyConstEnum} from "./ConstEnum"; +import AlsoEnum from "./ImportExport"; +import StillEnum from "./ReExport"; + +MyConstEnum.Foo; +AlsoEnum.Foo; +StillEnum.Foo; diff --git a/tests/cases/compiler/constEnumPreserveEmitReexport.ts b/tests/cases/compiler/constEnumPreserveEmitReexport.ts new file mode 100644 index 00000000000..d53345e6380 --- /dev/null +++ b/tests/cases/compiler/constEnumPreserveEmitReexport.ts @@ -0,0 +1,11 @@ +// @preserveConstEnums: true +// @filename: ConstEnum.ts +export const enum MyConstEnum { + Foo, + Bar +}; +// @filename: ImportExport.ts +import { MyConstEnum } from './ConstEnum'; +export default MyConstEnum; +// @filename: ReExport.ts +export { MyConstEnum as default } from './ConstEnum'; \ No newline at end of file