diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index 91346429b1774..976a5a1cfddce 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -34722,7 +34722,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return objectType;
}
- if (isConstEnumObjectType(objectType) && !isStringLiteralLike(indexExpression)) {
+ if (isConstEnumObjectType(objectType) && !isStringLiteralLike(indexExpression) && !isUseOfPreservedConstEnum(node, objectType)) {
error(indexExpression, Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal);
return errorType;
}
@@ -40836,7 +40836,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
(node.parent.kind === SyntaxKind.TypeQuery && (node.parent as TypeQueryNode).exprName === node)) ||
(node.parent.kind === SyntaxKind.ExportSpecifier); // We allow reexporting const enums
- if (!ok) {
+ if (!ok && !isUseOfPreservedConstEnum(node, type)) {
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);
}
@@ -40856,15 +40856,27 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
/*excludeGlobals*/ true,
)
) {
- Debug.assert(!!(type.symbol.flags & SymbolFlags.ConstEnum));
- const constEnumDeclaration = type.symbol.valueDeclaration as EnumDeclaration;
- const redirect = host.getRedirectReferenceForResolutionFromSourceOfProject(getSourceFileOfNode(constEnumDeclaration).resolvedPath);
- if (constEnumDeclaration.flags & NodeFlags.Ambient && !isValidTypeOnlyAliasUseSite(node) && (!redirect || !shouldPreserveConstEnums(redirect.commandLine.options))) {
+ if (!isUseOfPreservedConstEnum(node, type)) {
error(node, Diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled, isolatedModulesLikeFlagName);
}
}
}
+ function isUseOfPreservedConstEnum(use: Node, enumType: Type) {
+ Debug.assert(!!(enumType.symbol.flags & SymbolFlags.ConstEnum));
+ const constEnumDeclaration = enumType.symbol.valueDeclaration as EnumDeclaration;
+ if (constEnumDeclaration.flags & NodeFlags.Ambient && isValidTypeOnlyAliasUseSite(use)) {
+ return true;
+ }
+ const otherFile = getSourceFileOfNode(constEnumDeclaration);
+ if (!otherFile.isDeclarationFile) {
+ // This file can only have come from the current project.
+ return shouldPreserveConstEnums(compilerOptions);
+ }
+ const redirect = host.getRedirectReferenceForResolutionFromSourceOfProject(otherFile.resolvedPath);
+ return redirect && shouldPreserveConstEnums(redirect.commandLine.options);
+ }
+
function checkParenthesizedExpression(node: ParenthesizedExpression, checkMode?: CheckMode): Type {
if (hasJSDocNodes(node)) {
if (isJSDocSatisfiesExpression(node)) {
diff --git a/src/testRunner/unittests/tsc/projectReferences.ts b/src/testRunner/unittests/tsc/projectReferences.ts
index 27a575ca02afd..751c6128d7872 100644
--- a/src/testRunner/unittests/tsc/projectReferences.ts
+++ b/src/testRunner/unittests/tsc/projectReferences.ts
@@ -153,4 +153,47 @@ describe("unittests:: tsc:: projectReferences::", () => {
}),
commandLineArgs: ["--p", "src/project", "--pretty", "false"],
});
+
+ verifyTsc({
+ scenario: "projectReferences",
+ subScenario: "referencing ambient const enum as value from referenced project with preserveConstEnums",
+ fs: () =>
+ loadProjectFromFiles({
+ "/src/utils/index.ts": "export const enum E { A = 1 }",
+ "/src/utils/index.d.ts": "export declare const enum E { A = 1 }",
+ "/src/utils/tsconfig.json": jsonToReadableText({
+ compilerOptions: {
+ composite: true,
+ declaration: true,
+ preserveConstEnums: true,
+ },
+ }),
+ "/src/utilsNonPreserved/index.ts": "export const enum E2 { A = 1 }",
+ "/src/utilsNonPreserved/index.d.ts": "export declare const enum E2 { A = 1 }",
+ "/src/utilsNonPreserved/tsconfig.json": jsonToReadableText({
+ compilerOptions: {
+ composite: true,
+ declaration: true,
+ preserveConstEnums: false,
+ },
+ }),
+ "/src/project/index.ts": `
+ import { E } from "../utils";
+ import { E2 } from "../utilsNonPreserved";
+
+ E; declare const x: E; E[x];
+
+ E2; declare const y: E2; E2[y];
+ `,
+ "/src/project/tsconfig.json": jsonToReadableText({
+ compilerOptions: {
+ isolatedModules: true,
+ },
+ references: [
+ { path: "../utils" },
+ ],
+ }),
+ }),
+ commandLineArgs: ["--p", "src/project"],
+ });
});
diff --git a/src/testRunner/unittests/tsserver/projectReferences.ts b/src/testRunner/unittests/tsserver/projectReferences.ts
index 1a775d30f6e90..e246f89f9e5a7 100644
--- a/src/testRunner/unittests/tsserver/projectReferences.ts
+++ b/src/testRunner/unittests/tsserver/projectReferences.ts
@@ -379,6 +379,54 @@ function foo() {
baselineTsserverLogs("projectReferences", `referencing const enum from referenced project with preserveConstEnums`, session);
});
+ it("referencing const enum as value from referenced project with preserveConstEnums", () => {
+ const projectLocation = `/user/username/projects/project`;
+ const utilsIndex: File = {
+ path: `${projectLocation}/src/utils/index.ts`,
+ content: "export const enum E { A = 1 }",
+ };
+ const utilsDeclaration: File = {
+ path: `${projectLocation}/src/utils/index.d.ts`,
+ content: "export declare const enum E { A = 1 }",
+ };
+ const utilsConfig: File = {
+ path: `${projectLocation}/src/utils/tsconfig.json`,
+ content: jsonToReadableText({ compilerOptions: { composite: true, declaration: true, preserveConstEnums: true } }),
+ };
+ const utilsNonPreservedIndex: File = {
+ path: `${projectLocation}/src/utilsNonPreserved/index.ts`,
+ content: "export const enum E2 { A = 1 }",
+ };
+ const utilsNonPreservedDeclaration: File = {
+ path: `${projectLocation}/src/utilsNonPreserved/index.d.ts`,
+ content: "export declare const enum E2 { A = 1 }",
+ };
+ const utilsNonPreservedConfig: File = {
+ path: `${projectLocation}/src/utilsNonPreserved/tsconfig.json`,
+ content: jsonToReadableText({ compilerOptions: { composite: true, declaration: true, preserveConstEnums: false } }),
+ };
+ const projectIndex: File = {
+ path: `${projectLocation}/src/project/index.ts`,
+ content: `
+ import { E } from "../utils";
+ import { E2 } from "../utilsNonPreserved";
+
+ E; declare const x: E; E[x];
+
+ E2; declare const y: E2; E2[y];
+ `,
+ };
+ const projectConfig: File = {
+ path: `${projectLocation}/src/project/tsconfig.json`,
+ content: jsonToReadableText({ compilerOptions: { isolatedModules: true }, references: [{ path: "../utils" }, { path: "../utilsNoPreserved" }] }),
+ };
+ const host = createServerHost([libFile, utilsIndex, utilsDeclaration, utilsConfig, utilsNonPreservedIndex, utilsNonPreservedDeclaration, utilsNonPreservedConfig, projectIndex, projectConfig]);
+ const session = new TestSession(host);
+ openFilesForSession([projectIndex], session);
+ verifyGetErrRequest({ session, files: [projectIndex] });
+ baselineTsserverLogs("projectReferences", `referencing const enum as value from referenced project with preserveConstEnums`, session);
+ });
+
describe("when references are monorepo like with symlinks", () => {
interface Packages {
bPackageJson: File;
diff --git a/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=false).errors.txt b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=false).errors.txt
new file mode 100644
index 0000000000000..e727d635f54d0
--- /dev/null
+++ b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=false).errors.txt
@@ -0,0 +1,19 @@
+constEnumUsedAsValue.ts(9,1): 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.
+constEnumUsedAsValue.ts(10,3): error TS2476: A const enum member can only be accessed using a string literal.
+
+
+==== constEnumUsedAsValue.ts (2 errors) ====
+ const enum E {
+ A,
+ B,
+ C,
+ }
+
+ declare const x: E;
+
+ E;
+ ~
+!!! 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.
+ E[x];
+ ~
+!!! error TS2476: A const enum member can only be accessed using a string literal.
\ No newline at end of file
diff --git a/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=false).js b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=false).js
new file mode 100644
index 0000000000000..bf2881857f99f
--- /dev/null
+++ b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=false).js
@@ -0,0 +1,18 @@
+//// [tests/cases/compiler/constEnumUsedAsValue.ts] ////
+
+//// [constEnumUsedAsValue.ts]
+const enum E {
+ A,
+ B,
+ C,
+}
+
+declare const x: E;
+
+E;
+E[x];
+
+//// [constEnumUsedAsValue.js]
+"use strict";
+E;
+E[x];
diff --git a/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=false).symbols b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=false).symbols
new file mode 100644
index 0000000000000..249efdb4a38a9
--- /dev/null
+++ b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=false).symbols
@@ -0,0 +1,27 @@
+//// [tests/cases/compiler/constEnumUsedAsValue.ts] ////
+
+=== constEnumUsedAsValue.ts ===
+const enum E {
+>E : Symbol(E, Decl(constEnumUsedAsValue.ts, 0, 0))
+
+ A,
+>A : Symbol(E.A, Decl(constEnumUsedAsValue.ts, 0, 14))
+
+ B,
+>B : Symbol(E.B, Decl(constEnumUsedAsValue.ts, 1, 6))
+
+ C,
+>C : Symbol(E.C, Decl(constEnumUsedAsValue.ts, 2, 6))
+}
+
+declare const x: E;
+>x : Symbol(x, Decl(constEnumUsedAsValue.ts, 6, 13))
+>E : Symbol(E, Decl(constEnumUsedAsValue.ts, 0, 0))
+
+E;
+>E : Symbol(E, Decl(constEnumUsedAsValue.ts, 0, 0))
+
+E[x];
+>E : Symbol(E, Decl(constEnumUsedAsValue.ts, 0, 0))
+>x : Symbol(x, Decl(constEnumUsedAsValue.ts, 6, 13))
+
diff --git a/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=false).types b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=false).types
new file mode 100644
index 0000000000000..ab66d8eba35a0
--- /dev/null
+++ b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=false).types
@@ -0,0 +1,36 @@
+//// [tests/cases/compiler/constEnumUsedAsValue.ts] ////
+
+=== constEnumUsedAsValue.ts ===
+const enum E {
+>E : E
+> : ^
+
+ A,
+>A : E.A
+> : ^^^
+
+ B,
+>B : E.B
+> : ^^^
+
+ C,
+>C : E.C
+> : ^^^
+}
+
+declare const x: E;
+>x : E
+> : ^
+
+E;
+>E : typeof E
+> : ^^^^^^^^
+
+E[x];
+>E[x] : any
+> : ^^^
+>E : typeof E
+> : ^^^^^^^^
+>x : E
+> : ^
+
diff --git a/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=true).js b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=true).js
new file mode 100644
index 0000000000000..4bc790c97f36d
--- /dev/null
+++ b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=true).js
@@ -0,0 +1,24 @@
+//// [tests/cases/compiler/constEnumUsedAsValue.ts] ////
+
+//// [constEnumUsedAsValue.ts]
+const enum E {
+ A,
+ B,
+ C,
+}
+
+declare const x: E;
+
+E;
+E[x];
+
+//// [constEnumUsedAsValue.js]
+"use strict";
+var E;
+(function (E) {
+ E[E["A"] = 0] = "A";
+ E[E["B"] = 1] = "B";
+ E[E["C"] = 2] = "C";
+})(E || (E = {}));
+E;
+E[x];
diff --git a/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=true).symbols b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=true).symbols
new file mode 100644
index 0000000000000..249efdb4a38a9
--- /dev/null
+++ b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=true).symbols
@@ -0,0 +1,27 @@
+//// [tests/cases/compiler/constEnumUsedAsValue.ts] ////
+
+=== constEnumUsedAsValue.ts ===
+const enum E {
+>E : Symbol(E, Decl(constEnumUsedAsValue.ts, 0, 0))
+
+ A,
+>A : Symbol(E.A, Decl(constEnumUsedAsValue.ts, 0, 14))
+
+ B,
+>B : Symbol(E.B, Decl(constEnumUsedAsValue.ts, 1, 6))
+
+ C,
+>C : Symbol(E.C, Decl(constEnumUsedAsValue.ts, 2, 6))
+}
+
+declare const x: E;
+>x : Symbol(x, Decl(constEnumUsedAsValue.ts, 6, 13))
+>E : Symbol(E, Decl(constEnumUsedAsValue.ts, 0, 0))
+
+E;
+>E : Symbol(E, Decl(constEnumUsedAsValue.ts, 0, 0))
+
+E[x];
+>E : Symbol(E, Decl(constEnumUsedAsValue.ts, 0, 0))
+>x : Symbol(x, Decl(constEnumUsedAsValue.ts, 6, 13))
+
diff --git a/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=true).types b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=true).types
new file mode 100644
index 0000000000000..f20888f20b4a1
--- /dev/null
+++ b/tests/baselines/reference/constEnumUsedAsValue(preserveconstenums=true).types
@@ -0,0 +1,36 @@
+//// [tests/cases/compiler/constEnumUsedAsValue.ts] ////
+
+=== constEnumUsedAsValue.ts ===
+const enum E {
+>E : E
+> : ^
+
+ A,
+>A : E.A
+> : ^^^
+
+ B,
+>B : E.B
+> : ^^^
+
+ C,
+>C : E.C
+> : ^^^
+}
+
+declare const x: E;
+>x : E
+> : ^
+
+E;
+>E : typeof E
+> : ^^^^^^^^
+
+E[x];
+>E[x] : string
+> : ^^^^^^
+>E : typeof E
+> : ^^^^^^^^
+>x : E
+> : ^
+
diff --git a/tests/baselines/reference/isolatedModulesAmbientConstEnum.errors.txt b/tests/baselines/reference/isolatedModulesAmbientConstEnum.errors.txt
deleted file mode 100644
index 75d30e7f1731d..0000000000000
--- a/tests/baselines/reference/isolatedModulesAmbientConstEnum.errors.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-file1.ts(2,16): error TS2748: Cannot access ambient const enums when 'isolatedModules' is enabled.
-
-
-==== file1.ts (1 errors) ====
- declare const enum E { X = 1}
- export var y = E.X;
- ~
-!!! error TS2748: Cannot access ambient const enums when 'isolatedModules' is enabled.
-
\ No newline at end of file
diff --git a/tests/baselines/reference/tsc/projectReferences/referencing-ambient-const-enum-as-value-from-referenced-project-with-preserveConstEnums.js b/tests/baselines/reference/tsc/projectReferences/referencing-ambient-const-enum-as-value-from-referenced-project-with-preserveConstEnums.js
new file mode 100644
index 0000000000000..91a7c15fca07b
--- /dev/null
+++ b/tests/baselines/reference/tsc/projectReferences/referencing-ambient-const-enum-as-value-from-referenced-project-with-preserveConstEnums.js
@@ -0,0 +1,97 @@
+currentDirectory:: / useCaseSensitiveFileNames: false
+Input::
+//// [/lib/lib.d.ts]
+///
+interface Boolean {}
+interface Function {}
+interface CallableFunction {}
+interface NewableFunction {}
+interface IArguments {}
+interface Number { toExponential: any; }
+interface Object {}
+interface RegExp {}
+interface String { charAt: any; }
+interface Array { length: number; [n: number]: T; }
+interface ReadonlyArray {}
+declare const console: { log(msg: any): void; };
+
+//// [/src/project/index.ts]
+
+ import { E } from "../utils";
+ import { E2 } from "../utilsNonPreserved";
+
+ E; declare const x: E; E[x];
+
+ E2; declare const y: E2; E2[y];
+
+
+//// [/src/project/tsconfig.json]
+{
+ "compilerOptions": {
+ "isolatedModules": true
+ },
+ "references": [
+ {
+ "path": "../utils"
+ }
+ ]
+}
+
+//// [/src/utils/index.d.ts]
+export declare const enum E { A = 1 }
+
+//// [/src/utils/index.ts]
+export const enum E { A = 1 }
+
+//// [/src/utils/tsconfig.json]
+{
+ "compilerOptions": {
+ "composite": true,
+ "declaration": true,
+ "preserveConstEnums": true
+ }
+}
+
+//// [/src/utilsNonPreserved/index.d.ts]
+export declare const enum E2 { A = 1 }
+
+//// [/src/utilsNonPreserved/index.ts]
+export const enum E2 { A = 1 }
+
+//// [/src/utilsNonPreserved/tsconfig.json]
+{
+ "compilerOptions": {
+ "composite": true,
+ "declaration": true,
+ "preserveConstEnums": false
+ }
+}
+
+
+
+Output::
+/lib/tsc --p src/project
+exitCode:: ExitStatus.Success
+
+
+//// [/src/project/index.js]
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+var utils_1 = require("../utils");
+var utilsNonPreserved_1 = require("../utilsNonPreserved");
+utils_1.E;
+utils_1.E[x];
+utilsNonPreserved_1.E2;
+utilsNonPreserved_1.E2[y];
+
+
+//// [/src/utilsNonPreserved/index.js]
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.E2 = void 0;
+var E2;
+(function (E2) {
+ E2[E2["A"] = 1] = "A";
+})(E2 || (exports.E2 = E2 = {}));
+
+
diff --git a/tests/baselines/reference/tsserver/projectReferences/referencing-const-enum-as-value-from-referenced-project-with-preserveConstEnums.js b/tests/baselines/reference/tsserver/projectReferences/referencing-const-enum-as-value-from-referenced-project-with-preserveConstEnums.js
new file mode 100644
index 0000000000000..8f0bcc731a12b
--- /dev/null
+++ b/tests/baselines/reference/tsserver/projectReferences/referencing-const-enum-as-value-from-referenced-project-with-preserveConstEnums.js
@@ -0,0 +1,416 @@
+currentDirectory:: / useCaseSensitiveFileNames: false
+Info seq [hh:mm:ss:mss] Provided types map file "/typesMap.json" doesn't exist
+Before request
+//// [/a/lib/lib.d.ts]
+///
+interface Boolean {}
+interface Function {}
+interface CallableFunction {}
+interface NewableFunction {}
+interface IArguments {}
+interface Number { toExponential: any; }
+interface Object {}
+interface RegExp {}
+interface String { charAt: any; }
+interface Array { length: number; [n: number]: T; }
+
+//// [/user/username/projects/project/src/utils/index.ts]
+export const enum E { A = 1 }
+
+//// [/user/username/projects/project/src/utils/index.d.ts]
+export declare const enum E { A = 1 }
+
+//// [/user/username/projects/project/src/utils/tsconfig.json]
+{
+ "compilerOptions": {
+ "composite": true,
+ "declaration": true,
+ "preserveConstEnums": true
+ }
+}
+
+//// [/user/username/projects/project/src/utilsNonPreserved/index.ts]
+export const enum E2 { A = 1 }
+
+//// [/user/username/projects/project/src/utilsNonPreserved/index.d.ts]
+export declare const enum E2 { A = 1 }
+
+//// [/user/username/projects/project/src/utilsNonPreserved/tsconfig.json]
+{
+ "compilerOptions": {
+ "composite": true,
+ "declaration": true,
+ "preserveConstEnums": false
+ }
+}
+
+//// [/user/username/projects/project/src/project/index.ts]
+
+ import { E } from "../utils";
+ import { E2 } from "../utilsNonPreserved";
+
+ E; declare const x: E; E[x];
+
+ E2; declare const y: E2; E2[y];
+
+
+//// [/user/username/projects/project/src/project/tsconfig.json]
+{
+ "compilerOptions": {
+ "isolatedModules": true
+ },
+ "references": [
+ {
+ "path": "../utils"
+ },
+ {
+ "path": "../utilsNoPreserved"
+ }
+ ]
+}
+
+
+Info seq [hh:mm:ss:mss] request:
+ {
+ "command": "open",
+ "arguments": {
+ "file": "/user/username/projects/project/src/project/index.ts"
+ },
+ "seq": 1,
+ "type": "request"
+ }
+Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /user/username/projects/project/src/project/index.ts ProjectRootPath: undefined:: Result: /user/username/projects/project/src/project/tsconfig.json
+Info seq [hh:mm:ss:mss] Creating configuration project /user/username/projects/project/src/project/tsconfig.json
+Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /user/username/projects/project/src/project/tsconfig.json 2000 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Config file
+Info seq [hh:mm:ss:mss] event:
+ {
+ "seq": 0,
+ "type": "event",
+ "event": "projectLoadingStart",
+ "body": {
+ "projectName": "/user/username/projects/project/src/project/tsconfig.json",
+ "reason": "Creating possible configured project for /user/username/projects/project/src/project/index.ts to open"
+ }
+ }
+Info seq [hh:mm:ss:mss] Config: /user/username/projects/project/src/project/tsconfig.json : {
+ "rootNames": [
+ "/user/username/projects/project/src/project/index.ts"
+ ],
+ "options": {
+ "isolatedModules": true,
+ "configFilePath": "/user/username/projects/project/src/project/tsconfig.json"
+ },
+ "projectReferences": [
+ {
+ "path": "/user/username/projects/project/src/utils",
+ "originalPath": "../utils"
+ },
+ {
+ "path": "/user/username/projects/project/src/utilsNoPreserved",
+ "originalPath": "../utilsNoPreserved"
+ }
+ ]
+}
+Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src/project 1 undefined Config: /user/username/projects/project/src/project/tsconfig.json WatchType: Wild card directory
+Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src/project 1 undefined Config: /user/username/projects/project/src/project/tsconfig.json WatchType: Wild card directory
+Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /user/username/projects/project/src/project/tsconfig.json
+Info seq [hh:mm:ss:mss] Config: /user/username/projects/project/src/utils/tsconfig.json : {
+ "rootNames": [
+ "/user/username/projects/project/src/utils/index.ts"
+ ],
+ "options": {
+ "composite": true,
+ "declaration": true,
+ "preserveConstEnums": true,
+ "configFilePath": "/user/username/projects/project/src/utils/tsconfig.json"
+ }
+}
+Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /user/username/projects/project/src/utils/tsconfig.json 2000 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Config file
+Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src/utils 1 undefined Config: /user/username/projects/project/src/utils/tsconfig.json WatchType: Wild card directory
+Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src/utils 1 undefined Config: /user/username/projects/project/src/utils/tsconfig.json WatchType: Wild card directory
+Info seq [hh:mm:ss:mss] Config: /user/username/projects/project/src/utilsNoPreserved/tsconfig.json : {
+ "rootNames": [],
+ "options": {
+ "configFilePath": "/user/username/projects/project/src/utilsNoPreserved/tsconfig.json"
+ }
+}
+Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /user/username/projects/project/src/utilsNoPreserved/tsconfig.json 2000 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Config file
+Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src 0 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Failed Lookup Locations
+Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src 0 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Failed Lookup Locations
+Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src/utils 1 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Failed Lookup Locations
+Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src/utils 1 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Failed Lookup Locations
+Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src/utilsNonPreserved 1 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Failed Lookup Locations
+Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src/utilsNonPreserved 1 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Failed Lookup Locations
+Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /user/username/projects/project/src/utils/index.ts 500 undefined WatchType: Closed Script info
+Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /user/username/projects/project/src/utilsNonPreserved/index.ts 500 undefined WatchType: Closed Script info
+Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 500 undefined WatchType: Closed Script info
+Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src/project/node_modules/@types 1 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Type roots
+Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src/project/node_modules/@types 1 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Type roots
+Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src/node_modules/@types 1 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Type roots
+Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/src/node_modules/@types 1 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Type roots
+Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/node_modules/@types 1 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Type roots
+Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/project/node_modules/@types 1 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Type roots
+Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules/@types 1 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Type roots
+Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules/@types 1 undefined Project: /user/username/projects/project/src/project/tsconfig.json WatchType: Type roots
+Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /user/username/projects/project/src/project/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms
+Info seq [hh:mm:ss:mss] Project '/user/username/projects/project/src/project/tsconfig.json' (Configured)
+Info seq [hh:mm:ss:mss] Files (4)
+ /a/lib/lib.d.ts Text-1 "/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }"
+ /user/username/projects/project/src/utils/index.ts Text-1 "export const enum E { A = 1 }"
+ /user/username/projects/project/src/utilsNonPreserved/index.ts Text-1 "export const enum E2 { A = 1 }"
+ /user/username/projects/project/src/project/index.ts SVC-1-0 "\n import { E } from \"../utils\";\n import { E2 } from \"../utilsNonPreserved\";\n\n E; declare const x: E; E[x];\n \n E2; declare const y: E2; E2[y];\n "
+
+
+ ../../../../../../a/lib/lib.d.ts
+ Default library for target 'es5'
+ ../utils/index.ts
+ Imported via "../utils" from file 'index.ts'
+ ../utilsNonPreserved/index.ts
+ Imported via "../utilsNonPreserved" from file 'index.ts'
+ index.ts
+ Matched by default include pattern '**/*'
+
+Info seq [hh:mm:ss:mss] -----------------------------------------------
+Info seq [hh:mm:ss:mss] event:
+ {
+ "seq": 0,
+ "type": "event",
+ "event": "projectLoadingFinish",
+ "body": {
+ "projectName": "/user/username/projects/project/src/project/tsconfig.json"
+ }
+ }
+Info seq [hh:mm:ss:mss] event:
+ {
+ "seq": 0,
+ "type": "event",
+ "event": "telemetry",
+ "body": {
+ "telemetryEventName": "projectInfo",
+ "payload": {
+ "projectId": "0ecf3cccdd8e71701ab41fc1852f59ac0c6c0d069aea4eb2fba6867e4bd6f54c",
+ "fileStats": {
+ "js": 0,
+ "jsSize": 0,
+ "jsx": 0,
+ "jsxSize": 0,
+ "ts": 3,
+ "tsSize": 268,
+ "tsx": 0,
+ "tsxSize": 0,
+ "dts": 1,
+ "dtsSize": 334,
+ "deferred": 0,
+ "deferredSize": 0
+ },
+ "compilerOptions": {
+ "isolatedModules": true
+ },
+ "typeAcquisition": {
+ "enable": false,
+ "include": false,
+ "exclude": false
+ },
+ "extends": false,
+ "files": false,
+ "include": false,
+ "exclude": false,
+ "compileOnSave": false,
+ "configFileName": "tsconfig.json",
+ "projectType": "configured",
+ "languageServiceEnabled": true,
+ "version": "FakeVersion"
+ }
+ }
+ }
+Info seq [hh:mm:ss:mss] event:
+ {
+ "seq": 0,
+ "type": "event",
+ "event": "configFileDiag",
+ "body": {
+ "triggerFile": "/user/username/projects/project/src/project/index.ts",
+ "configFile": "/user/username/projects/project/src/project/tsconfig.json",
+ "diagnostics": [
+ {
+ "start": {
+ "line": 9,
+ "offset": 5
+ },
+ "end": {
+ "line": 11,
+ "offset": 6
+ },
+ "text": "File '/user/username/projects/project/src/utilsNoPreserved' not found.",
+ "code": 6053,
+ "category": "error",
+ "fileName": "/user/username/projects/project/src/project/tsconfig.json"
+ }
+ ]
+ }
+ }
+Info seq [hh:mm:ss:mss] Project '/user/username/projects/project/src/project/tsconfig.json' (Configured)
+Info seq [hh:mm:ss:mss] Files (4)
+
+Info seq [hh:mm:ss:mss] -----------------------------------------------
+Info seq [hh:mm:ss:mss] Open files:
+Info seq [hh:mm:ss:mss] FileName: /user/username/projects/project/src/project/index.ts ProjectRootPath: undefined
+Info seq [hh:mm:ss:mss] Projects: /user/username/projects/project/src/project/tsconfig.json
+Info seq [hh:mm:ss:mss] response:
+ {
+ "seq": 0,
+ "type": "response",
+ "command": "open",
+ "request_seq": 1,
+ "success": true,
+ "performanceData": {
+ "updateGraphDurationMs": *
+ }
+ }
+After request
+
+PolledWatches::
+/user/username/projects/node_modules/@types: *new*
+ {"pollingInterval":500}
+/user/username/projects/project/node_modules/@types: *new*
+ {"pollingInterval":500}
+/user/username/projects/project/src/node_modules/@types: *new*
+ {"pollingInterval":500}
+/user/username/projects/project/src/project/node_modules/@types: *new*
+ {"pollingInterval":500}
+/user/username/projects/project/src/utilsNoPreserved/tsconfig.json: *new*
+ {"pollingInterval":2000}
+
+FsWatches::
+/a/lib/lib.d.ts: *new*
+ {}
+/user/username/projects/project/src: *new*
+ {}
+/user/username/projects/project/src/project/tsconfig.json: *new*
+ {}
+/user/username/projects/project/src/utils/index.ts: *new*
+ {}
+/user/username/projects/project/src/utils/tsconfig.json: *new*
+ {}
+/user/username/projects/project/src/utilsNonPreserved/index.ts: *new*
+ {}
+
+FsWatchesRecursive::
+/user/username/projects/project/src/project: *new*
+ {}
+/user/username/projects/project/src/utils: *new*
+ {}
+/user/username/projects/project/src/utilsNonPreserved: *new*
+ {}
+
+Projects::
+/user/username/projects/project/src/project/tsconfig.json (Configured) *new*
+ projectStateVersion: 1
+ projectProgramVersion: 1
+
+ScriptInfos::
+/a/lib/lib.d.ts *new*
+ version: Text-1
+ containingProjects: 1
+ /user/username/projects/project/src/project/tsconfig.json
+/user/username/projects/project/src/project/index.ts (Open) *new*
+ version: SVC-1-0
+ containingProjects: 1
+ /user/username/projects/project/src/project/tsconfig.json *default*
+/user/username/projects/project/src/utils/index.ts *new*
+ version: Text-1
+ containingProjects: 1
+ /user/username/projects/project/src/project/tsconfig.json
+/user/username/projects/project/src/utilsNonPreserved/index.ts *new*
+ version: Text-1
+ containingProjects: 1
+ /user/username/projects/project/src/project/tsconfig.json
+
+Before request
+
+Info seq [hh:mm:ss:mss] request:
+ {
+ "command": "geterr",
+ "arguments": {
+ "delay": 0,
+ "files": [
+ "/user/username/projects/project/src/project/index.ts"
+ ]
+ },
+ "seq": 2,
+ "type": "request"
+ }
+After request
+
+Timeout callback:: count: 1
+1: checkOne *new*
+
+Before running Timeout callback:: count: 1
+1: checkOne
+
+Info seq [hh:mm:ss:mss] event:
+ {
+ "seq": 0,
+ "type": "event",
+ "event": "syntaxDiag",
+ "body": {
+ "file": "/user/username/projects/project/src/project/index.ts",
+ "diagnostics": []
+ }
+ }
+After running Timeout callback:: count: 0
+
+Immedidate callback:: count: 1
+1: semanticCheck *new*
+
+Before running Immedidate callback:: count: 1
+1: semanticCheck
+
+Info seq [hh:mm:ss:mss] event:
+ {
+ "seq": 0,
+ "type": "event",
+ "event": "semanticDiag",
+ "body": {
+ "file": "/user/username/projects/project/src/project/index.ts",
+ "diagnostics": []
+ }
+ }
+After running Immedidate callback:: count: 1
+
+Immedidate callback:: count: 1
+2: suggestionCheck *new*
+
+Before running Immedidate callback:: count: 1
+2: suggestionCheck
+
+Info seq [hh:mm:ss:mss] event:
+ {
+ "seq": 0,
+ "type": "event",
+ "event": "suggestionDiag",
+ "body": {
+ "file": "/user/username/projects/project/src/project/index.ts",
+ "diagnostics": []
+ }
+ }
+Info seq [hh:mm:ss:mss] event:
+ {
+ "seq": 0,
+ "type": "event",
+ "event": "requestCompleted",
+ "body": {
+ "request_seq": 2,
+ "performanceData": {
+ "diagnosticsDuration": [
+ {
+ "syntaxDiag": *,
+ "semanticDiag": *,
+ "suggestionDiag": *,
+ "file": "/user/username/projects/project/src/project/index.ts"
+ }
+ ]
+ }
+ }
+ }
+After running Immedidate callback:: count: 0
diff --git a/tests/cases/compiler/constEnumUsedAsValue.ts b/tests/cases/compiler/constEnumUsedAsValue.ts
new file mode 100644
index 0000000000000..c5dcf6861425d
--- /dev/null
+++ b/tests/cases/compiler/constEnumUsedAsValue.ts
@@ -0,0 +1,13 @@
+// @strict: true
+// @preserveConstEnums: true,false
+
+const enum E {
+ A,
+ B,
+ C,
+}
+
+declare const x: E;
+
+E;
+E[x];
\ No newline at end of file