Merge pull request #19930 from Microsoft/constEnumWithWatch
Ensure that enum member value is computed before using it
This commit is contained in:
commit
8777962373
|
@ -22415,7 +22415,7 @@ namespace ts {
|
|||
const declaration = memberSymbol.valueDeclaration;
|
||||
if (declaration !== member) {
|
||||
if (isBlockScopedNameDeclaredBeforeUse(declaration, member)) {
|
||||
return getNodeLinks(declaration).enumMemberValue;
|
||||
return getEnumMemberValue(declaration as EnumMember);
|
||||
}
|
||||
error(expr, Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums);
|
||||
return 0;
|
||||
|
|
|
@ -1616,6 +1616,36 @@ namespace ts.tscWatch {
|
|||
return files.slice(0, 2);
|
||||
}
|
||||
});
|
||||
|
||||
it("Elides const enums correctly in incremental compilation", () => {
|
||||
const currentDirectory = "/user/someone/projects/myproject";
|
||||
const file1: FileOrFolder = {
|
||||
path: `${currentDirectory}/file1.ts`,
|
||||
content: "export const enum E1 { V = 1 }"
|
||||
};
|
||||
const file2: FileOrFolder = {
|
||||
path: `${currentDirectory}/file2.ts`,
|
||||
content: `import { E1 } from "./file1"; export const enum E2 { V = E1.V }`
|
||||
};
|
||||
const file3: FileOrFolder = {
|
||||
path: `${currentDirectory}/file3.ts`,
|
||||
content: `import { E2 } from "./file2"; const v: E2 = E2.V;`
|
||||
};
|
||||
const strictAndEsModule = `"use strict";\nexports.__esModule = true;\n`;
|
||||
verifyEmittedFileContents("\n", [file3, file2, file1], [
|
||||
`${strictAndEsModule}var v = 1 /* V */;\n`,
|
||||
strictAndEsModule,
|
||||
strictAndEsModule
|
||||
], modifyFiles);
|
||||
|
||||
function modifyFiles(files: FileOrFolderEmit[], emittedFiles: EmittedFile[]) {
|
||||
files[0].content += `function foo2() { return 2; }`;
|
||||
emittedFiles[0].content += `function foo2() { return 2; }\n`;
|
||||
emittedFiles[1].shouldBeWritten = false;
|
||||
emittedFiles[2].shouldBeWritten = false;
|
||||
return [files[0]];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("tsc-watch module resolution caching", () => {
|
||||
|
|
Loading…
Reference in a new issue