Skip to content

Commit 25324fa

Browse files
committed
Merge pull request #1788 from Microsoft/emitConstEnumMembers
make sure that enum values are computed before the emit
2 parents 67476f1 + 05ec43a commit 25324fa

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10001,8 +10001,8 @@ module ts {
1000110001
if (symbol && (symbol.flags & SymbolFlags.EnumMember)) {
1000210002
var declaration = symbol.valueDeclaration;
1000310003
var constantValue: number;
10004-
if (declaration.kind === SyntaxKind.EnumMember && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) {
10005-
return constantValue;
10004+
if (declaration.kind === SyntaxKind.EnumMember) {
10005+
return getEnumMemberValue(<EnumMember>declaration);
1000610006
}
1000710007
}
1000810008

src/harness/fourslash.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,18 @@ module FourSlash {
548548
}
549549
}
550550

551+
public verifyGetEmitOutputForCurrentFile(expected: string): void {
552+
var emit = this.languageService.getEmitOutput(this.activeFile.fileName);
553+
if (emit.outputFiles.length !== 1) {
554+
throw new Error("Expected exactly one output from emit of " + this.activeFile.fileName);
555+
}
556+
this.taoInvalidReason = 'verifyGetEmitOutputForCurrentFile impossible';
557+
var actual = emit.outputFiles[0].text;
558+
if (actual !== expected) {
559+
this.raiseError("Expected emit output to be '" + expected + "', but got '" + actual + "'");
560+
}
561+
}
562+
551563
public verifyMemberListContains(symbol: string, text?: string, documentation?: string, kind?: string) {
552564
this.scenarioActions.push('<ShowCompletionList />');
553565
this.scenarioActions.push('<VerifyCompletionContainsItem ItemName="' + symbol + '"/>');
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @Filename: a.ts
4+
////const enum TestEnum {
5+
//// Foo, Bar
6+
////}
7+
////var testFirstFile = TestEnum.Bar;
8+
9+
// @Filename: b.ts
10+
/////// <reference path="a.ts" />
11+
/////*1*/
12+
////var testInOtherFile = TestEnum.Bar;
13+
14+
goTo.marker("1");
15+
verify.verifyGetEmitOutputForCurrentFile(
16+
"/// <reference path=\"a.ts\" />\r\n\
17+
var testInOtherFile = 1 /* Bar */;\r\n"
18+
)

tests/cases/fourslash/fourslash.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ module FourSlashInterface {
264264
FourSlash.currentTestState.verifyCurrentFileContent(text);
265265
}
266266

267+
public verifyGetEmitOutputForCurrentFile(expected: string): void {
268+
FourSlash.currentTestState.verifyGetEmitOutputForCurrentFile(expected);
269+
}
270+
267271
public currentParameterHelpArgumentNameIs(name: string) {
268272
FourSlash.currentTestState.verifyCurrentParameterHelpName(name);
269273
}

0 commit comments

Comments
 (0)