Preserve const enums should keep import refs (#28498)

* Preserve const enums should keep import refs

for exported const enums exported via export default

Move some functionality around, small cleanup

Remove unneeded const enum check

* Only mark const enums as references with preserveConstEnums on in export assignments

* Limit change to declarations and preserveConstEnums mode
This commit is contained in:
Wesley Wigham 2019-08-05 16:47:29 -07:00 committed by GitHub
parent 4df2fc663c
commit 3b54ffcf0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 615 additions and 20 deletions

View File

@ -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 <symbol>
checkExpressionCached((<ExportAssignment>node).expression);
}
else if (node.kind === SyntaxKind.ExportSpecifier) {
// export { <symbol> } or export { <symbol> as foo }
checkExpressionCached((<ExportSpecifier>node).propertyName || (<ExportSpecifier>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 = <symbol>
checkExpressionCached(<Expression>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 && (<PropertyAccessExpression>node.parent).expression === node) ||
(node.parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).expression === node) ||
((node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName) && isInRightSideOfImportOrExportAssignment(<Identifier>node) ||
(node.parent.kind === SyntaxKind.TypeQuery && (<TypeQueryNode>node.parent).exprName === node));
(node.parent.kind === SyntaxKind.TypeQuery && (<TypeQueryNode>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);

View File

@ -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;
});

View File

@ -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))
}
}

View File

@ -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
}
}

View File

@ -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 */;

View File

@ -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))

View File

@ -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

View File

@ -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;

View File

@ -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))

View File

@ -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

View File

@ -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'.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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) {}
}
}

View File

@ -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;

View File

@ -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';