Skip to content

Commit 8777962

Browse files
authored
Merge pull request microsoft#19930 from Microsoft/constEnumWithWatch
Ensure that enum member value is computed before using it
2 parents f28d236 + c82c6f2 commit 8777962

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22415,7 +22415,7 @@ namespace ts {
2241522415
const declaration = memberSymbol.valueDeclaration;
2241622416
if (declaration !== member) {
2241722417
if (isBlockScopedNameDeclaredBeforeUse(declaration, member)) {
22418-
return getNodeLinks(declaration).enumMemberValue;
22418+
return getEnumMemberValue(declaration as EnumMember);
2241922419
}
2242022420
error(expr, Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums);
2242122421
return 0;

src/harness/unittests/tscWatchMode.ts

+30
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,36 @@ namespace ts.tscWatch {
16161616
return files.slice(0, 2);
16171617
}
16181618
});
1619+
1620+
it("Elides const enums correctly in incremental compilation", () => {
1621+
const currentDirectory = "/user/someone/projects/myproject";
1622+
const file1: FileOrFolder = {
1623+
path: `${currentDirectory}/file1.ts`,
1624+
content: "export const enum E1 { V = 1 }"
1625+
};
1626+
const file2: FileOrFolder = {
1627+
path: `${currentDirectory}/file2.ts`,
1628+
content: `import { E1 } from "./file1"; export const enum E2 { V = E1.V }`
1629+
};
1630+
const file3: FileOrFolder = {
1631+
path: `${currentDirectory}/file3.ts`,
1632+
content: `import { E2 } from "./file2"; const v: E2 = E2.V;`
1633+
};
1634+
const strictAndEsModule = `"use strict";\nexports.__esModule = true;\n`;
1635+
verifyEmittedFileContents("\n", [file3, file2, file1], [
1636+
`${strictAndEsModule}var v = 1 /* V */;\n`,
1637+
strictAndEsModule,
1638+
strictAndEsModule
1639+
], modifyFiles);
1640+
1641+
function modifyFiles(files: FileOrFolderEmit[], emittedFiles: EmittedFile[]) {
1642+
files[0].content += `function foo2() { return 2; }`;
1643+
emittedFiles[0].content += `function foo2() { return 2; }\n`;
1644+
emittedFiles[1].shouldBeWritten = false;
1645+
emittedFiles[2].shouldBeWritten = false;
1646+
return [files[0]];
1647+
}
1648+
});
16191649
});
16201650

16211651
describe("tsc-watch module resolution caching", () => {

0 commit comments

Comments
 (0)