Skip to content

Commit d7de54f

Browse files
committed
skip const enums
1 parent 61711e1 commit d7de54f

15 files changed

+14
-72
lines changed

src/harness/typeWriter.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ export class TypeWriterWalker {
233233
return ts.isIntrinsicJsxName(node.getText());
234234
}
235235

236+
private shouldSkipNode(node: ts.Node) {
237+
if (ts.isPartOfTypeNode(node)) {
238+
return true;
239+
}
240+
if (ts.isIdentifier(node)) {
241+
if (ts.getMeaningFromDeclaration(node.parent) & ts.SemanticMeaning.Value) {
242+
return ts.isModuleDeclaration(node.parent) && ts.getModuleInstanceState(node.parent) === ts.ModuleInstanceState.ConstEnumOnly;
243+
}
244+
return !(ts.isTypeAliasDeclaration(node.parent) && node.parent.name === node);
245+
}
246+
return false;
247+
}
248+
236249
private writeTypeOrSymbol(node: ts.Node, isSymbolWalk: boolean): TypeWriterResult | undefined {
237250
const actualPos = ts.skipTrivia(this.currentSourceFile.text, node.pos);
238251
const lineAndCharacter = this.currentSourceFile.getLineAndCharacterOfPosition(actualPos);
@@ -241,9 +254,7 @@ export class TypeWriterWalker {
241254
if (!isSymbolWalk) {
242255
// Don't try to get the type of something that's already a type.
243256
// Exception for `T` in `type T = something` because that may evaluate to some interesting type.
244-
if (ts.isPartOfTypeNode(node) || ts.isIdentifier(node) && !(ts.getMeaningFromDeclaration(node.parent) & ts.SemanticMeaning.Value) && !(ts.isTypeAliasDeclaration(node.parent) && node.parent.name === node)) {
245-
return undefined;
246-
}
257+
if (this.shouldSkipNode(node)) return undefined;
247258

248259
// Workaround to ensure we output 'C' instead of 'typeof C' for base class expressions
249260
// let type = this.checker.getTypeAtLocation(node);

tests/baselines/reference/constEnumMergingWithValues1.types

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ function foo() {}
66
> : ^^^^^^^^^^
77

88
module foo {
9-
>foo : typeof foo
10-
> : ^^^^^^^^^^
11-
129
const enum E { X }
1310
>E : E
1411
> : ^

tests/baselines/reference/constEnumMergingWithValues2.types

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ class foo {}
66
> : ^^^
77

88
module foo {
9-
>foo : typeof foo
10-
> : ^^^^^^^^^^
11-
129
const enum E { X }
1310
>E : E
1411
> : ^

tests/baselines/reference/constEnumMergingWithValues3.types

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ enum foo { A }
88
> : ^^^^^
99

1010
module foo {
11-
>foo : typeof foo
12-
> : ^^^^^^^^^^
13-
1411
const enum E { X }
1512
>E : E
1613
> : ^

tests/baselines/reference/constEnumMergingWithValues4.types

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
=== m1.ts ===
44
module foo {
5-
>foo : typeof foo
6-
> : ^^^^^^^^^^
7-
85
const enum E { X }
96
>E : E
107
> : ^

tests/baselines/reference/constEnumMergingWithValues5.types

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
=== m1.ts ===
44
module foo {
5-
>foo : typeof foo
6-
> : ^^^^^^^^^^
7-
85
const enum E { X }
96
>E : E
107
> : ^

tests/baselines/reference/constEnumOnlyModuleMerging.types

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ module Outer {
1313
}
1414

1515
module Outer {
16-
>Outer : typeof Outer
17-
> : ^^^^^^^^^^^^
18-
1916
export const enum A { X }
2017
>A : A
2118
> : ^

tests/baselines/reference/constEnums.types

-30
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,8 @@ const enum Comments {
329329
}
330330

331331
module A {
332-
>A : typeof A
333-
> : ^^^^^^^^
334-
335332
export module B {
336-
>B : typeof B
337-
> : ^^^^^^^^
338-
339333
export module C {
340-
>C : typeof C
341-
> : ^^^^^^^^
342-
343334
export const enum E {
344335
>E : E
345336
> : ^
@@ -381,17 +372,8 @@ module A {
381372
}
382373

383374
module A {
384-
>A : typeof A
385-
> : ^^^^^^^^
386-
387375
export module B {
388-
>B : typeof B
389-
> : ^^^^^^^^
390-
391376
export module C {
392-
>C : typeof C
393-
> : ^^^^^^^^
394-
395377
export const enum E {
396378
>E : E
397379
> : ^
@@ -453,17 +435,8 @@ module A {
453435
}
454436

455437
module A1 {
456-
>A1 : typeof A1
457-
> : ^^^^^^^^^
458-
459438
export module B {
460-
>B : typeof B
461-
> : ^^^^^^^^
462-
463439
export module C {
464-
>C : typeof C
465-
> : ^^^^^^^^
466-
467440
export const enum E {
468441
>E : E
469442
> : ^
@@ -493,9 +466,6 @@ module A2 {
493466
> : ^^^^^^^^
494467

495468
export module C {
496-
>C : typeof C
497-
> : ^^^^^^^^
498-
499469
export const enum E {
500470
>E : E
501471
> : ^

tests/baselines/reference/emitClassMergedWithConstNamespaceNotElided.types

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
=== enum.d.ts ===
44
export namespace Clone {
5-
>Clone : typeof Clone
6-
> : ^^^^^^^^^^^^
7-
85
const enum LOCAL {
96
>LOCAL : LOCAL
107
> : ^^^^^

tests/baselines/reference/enumAssignmentCompat3.types

-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ namespace Cd {
9797
}
9898
}
9999
namespace Const {
100-
>Const : typeof Const
101-
> : ^^^^^^^^^^^^
102-
103100
export const enum E {
104101
>E : E
105102
> : ^

tests/baselines/reference/intersectionTypeNormalization.types

-3
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,6 @@ function getValueAsString(value: IntersectionFail): string {
201201
// Repro from #12535
202202

203203
namespace enums {
204-
>enums : typeof enums
205-
> : ^^^^^^^^^^^^
206-
207204
export const enum A {
208205
>A : A
209206
> : ^

tests/baselines/reference/reachabilityChecks1.types

-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ module A4 {
7979
> : ^^^^
8080

8181
module A {
82-
>A : typeof A
83-
> : ^^^^^^^^
84-
8582
const enum E { X }
8683
>E : E
8784
> : ^

tests/baselines/reference/reachabilityChecks2.types

-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ module A4 {
2020
> : ^^^^
2121

2222
module A {
23-
>A : typeof A
24-
> : ^^^^^^^^
25-
2623
const enum E { X }
2724
>E : E
2825
> : ^

tests/baselines/reference/systemModuleConstEnums.types

-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ export function foo() {
4444
}
4545

4646
module M {
47-
>M : typeof M
48-
> : ^^^^^^^^
49-
5047
export const enum NonTopLevelConstEnum { X }
5148
>NonTopLevelConstEnum : NonTopLevelConstEnum
5249
> : ^^^^^^^^^^^^^^^^^^^^

tests/baselines/reference/systemModuleConstEnumsSeparateCompilation.types

-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ export function foo() {
4444
}
4545

4646
module M {
47-
>M : typeof M
48-
> : ^^^^^^^^
49-
5047
export const enum NonTopLevelConstEnum { X }
5148
>NonTopLevelConstEnum : NonTopLevelConstEnum
5249
> : ^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)