Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix TypeScript Enum self-references (#14093)
- Loading branch information
1 parent
028cc88
commit bee3e35
Showing
3 changed files
with
118 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/babel-plugin-transform-typescript/test/fixtures/enum/mix-references/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var x = 10; | ||
|
||
enum Foo { | ||
a = 10, | ||
b = a, | ||
c = b + x, | ||
} | ||
|
||
enum Bar { | ||
D = Foo.a, | ||
E = D, | ||
F = Math.E, | ||
G = E + Foo.c, | ||
} | ||
|
||
enum Baz { | ||
a = 0, | ||
b = 1, | ||
// @ts-ignore | ||
x = a.toString(), | ||
} | ||
|
||
enum A { | ||
a = 0, | ||
b = (() => { let a = 1; return a + 1 })(), // a is shadowed | ||
c = (() => { return a + 2 })(), // a refers to A.a | ||
} |
38 changes: 38 additions & 0 deletions
38
packages/babel-plugin-transform-typescript/test/fixtures/enum/mix-references/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var x = 10; | ||
var Foo; | ||
|
||
(function (Foo) { | ||
Foo[Foo["a"] = 10] = "a"; | ||
Foo[Foo["b"] = 10] = "b"; | ||
Foo[Foo["c"] = Foo.b + x] = "c"; | ||
})(Foo || (Foo = {})); | ||
|
||
var Bar; | ||
|
||
(function (Bar) { | ||
Bar[Bar["D"] = Foo.a] = "D"; | ||
Bar[Bar["E"] = Bar.D] = "E"; | ||
Bar[Bar["F"] = Math.E] = "F"; | ||
Bar[Bar["G"] = Bar.E + Foo.c] = "G"; | ||
})(Bar || (Bar = {})); | ||
|
||
var Baz; | ||
|
||
(function (Baz) { | ||
Baz[Baz["a"] = 0] = "a"; | ||
Baz[Baz["b"] = 1] = "b"; | ||
Baz[Baz["x"] = Baz.a.toString()] = "x"; | ||
})(Baz || (Baz = {})); | ||
|
||
var A; | ||
|
||
(function (A) { | ||
A[A["a"] = 0] = "a"; | ||
A[A["b"] = (() => { | ||
let a = 1; | ||
return a + 1; | ||
})()] = "b"; | ||
A[A["c"] = (() => { | ||
return A.a + 2; | ||
})()] = "c"; | ||
})(A || (A = {})); |