-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(es/typescript): Inline typescript
enum
s (#3647)
- Loading branch information
1 parent
0bda251
commit 1743302
Showing
60 changed files
with
712 additions
and
348 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
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
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,7 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript" | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
crates/swc/tests/fixture/ts-inline-enum/default/input/index.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,18 @@ | ||
enum Foo { | ||
hello = 42, | ||
} | ||
|
||
enum Foo2 { | ||
hello = "42", | ||
} | ||
|
||
console.log(Foo.hello, Foo2.hello); | ||
|
||
console.log(Hello.en, Hello["ja-JP"], Hello[`ko-KR`], Hello['zh-CN']); | ||
|
||
const enum Hello { | ||
en = "hello", | ||
'ja-JP' = "こんにちは", | ||
"ko-KR" = '안녕하세요', | ||
"zh-CN" = `你好`, | ||
} |
17 changes: 17 additions & 0 deletions
17
crates/swc/tests/fixture/ts-inline-enum/default/output/index.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,17 @@ | ||
var Foo; | ||
(function(Foo) { | ||
Foo[Foo["hello"] = 42] = "hello"; | ||
})(Foo || (Foo = {})); | ||
var Foo2; | ||
(function(Foo2) { | ||
Foo2["hello"] = "42"; | ||
})(Foo2 || (Foo2 = {})); | ||
console.log(Foo.hello, Foo2.hello); | ||
console.log("hello", "こんにちは", '안녕하세요', "你好"); | ||
var Hello; | ||
(function(Hello) { | ||
Hello["en"] = "hello"; | ||
Hello['ja-JP'] = "こんにちは"; | ||
Hello["ko-KR"] = '안녕하세요'; | ||
Hello["zh-CN"] = "你好"; | ||
})(Hello || (Hello = {})); |
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,7 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript" | ||
} | ||
} | ||
} |
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,8 @@ | ||
const enum Foo { | ||
hello = 42, | ||
} | ||
|
||
let x; | ||
[x = Foo.hello] = [,]; | ||
|
||
console.log(x); |
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,8 @@ | ||
var Foo; | ||
(function(Foo) { | ||
Foo[Foo["hello"] = 42] = "hello"; | ||
})(Foo || (Foo = {})); | ||
var x; | ||
var ref; | ||
ref = void 0, x = ref === void 0 ? 42 : ref; | ||
console.log(x); |
10 changes: 10 additions & 0 deletions
10
crates/swc/tests/fixture/ts-inline-enum/treatConstEnumAsEnum-2/input/.swcrc
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,10 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript" | ||
}, | ||
"transform": { | ||
"treatConstEnumAsEnum": false | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
crates/swc/tests/fixture/ts-inline-enum/treatConstEnumAsEnum-2/input/index.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,18 @@ | ||
enum Foo { | ||
hello = 42, | ||
} | ||
|
||
enum Foo2 { | ||
hello = "42", | ||
} | ||
|
||
const enum Bar { | ||
hello = 42, | ||
} | ||
|
||
const enum Bar2 { | ||
hello = "42", | ||
} | ||
|
||
console.log(Foo.hello, Foo2.hello); | ||
console.log(Bar.hello, Bar2.hello); |
18 changes: 18 additions & 0 deletions
18
crates/swc/tests/fixture/ts-inline-enum/treatConstEnumAsEnum-2/output/index.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,18 @@ | ||
var Foo; | ||
(function(Foo) { | ||
Foo[Foo["hello"] = 42] = "hello"; | ||
})(Foo || (Foo = {})); | ||
var Foo2; | ||
(function(Foo2) { | ||
Foo2["hello"] = "42"; | ||
})(Foo2 || (Foo2 = {})); | ||
var Bar; | ||
(function(Bar) { | ||
Bar[Bar["hello"] = 42] = "hello"; | ||
})(Bar || (Bar = {})); | ||
var Bar2; | ||
(function(Bar2) { | ||
Bar2["hello"] = "42"; | ||
})(Bar2 || (Bar2 = {})); | ||
console.log(Foo.hello, Foo2.hello); | ||
console.log(42, "42"); |
10 changes: 10 additions & 0 deletions
10
crates/swc/tests/fixture/ts-inline-enum/treatConstEnumAsEnum/input/.swcrc
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,10 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript" | ||
}, | ||
"transform": { | ||
"treatConstEnumAsEnum": true | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
crates/swc/tests/fixture/ts-inline-enum/treatConstEnumAsEnum/input/index.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,18 @@ | ||
enum Foo { | ||
hello = 42, | ||
} | ||
|
||
enum Foo2 { | ||
hello = "42", | ||
} | ||
|
||
const enum Bar { | ||
hello = 42, | ||
} | ||
|
||
const enum Bar2 { | ||
hello = "42", | ||
} | ||
|
||
console.log(Foo.hello, Foo2.hello); | ||
console.log(Bar.hello, Bar2.hello); |
18 changes: 18 additions & 0 deletions
18
crates/swc/tests/fixture/ts-inline-enum/treatConstEnumAsEnum/output/index.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,18 @@ | ||
var Foo; | ||
(function(Foo) { | ||
Foo[Foo["hello"] = 42] = "hello"; | ||
})(Foo || (Foo = {})); | ||
var Foo2; | ||
(function(Foo2) { | ||
Foo2["hello"] = "42"; | ||
})(Foo2 || (Foo2 = {})); | ||
var Bar; | ||
(function(Bar) { | ||
Bar[Bar["hello"] = 42] = "hello"; | ||
})(Bar || (Bar = {})); | ||
var Bar2; | ||
(function(Bar2) { | ||
Bar2["hello"] = "42"; | ||
})(Bar2 || (Bar2 = {})); | ||
console.log(Foo.hello, Foo2.hello); | ||
console.log(Bar.hello, Bar2.hello); |
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
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
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
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
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
6 changes: 3 additions & 3 deletions
6
crates/swc/tests/tsc-references/constEnumPropertyAccess1_es2015.2.minified.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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
var G; | ||
(function(G) { | ||
!function(G) { | ||
G[G.A = 1] = "A", G[G.B = 2] = "B", G[G.C = 3] = "C", G[G.D = 2] = "D"; | ||
})(G || (G = {})), G.A, G.A, ({ | ||
}(G || (G = {})), ({ | ||
1: !0 | ||
})[G.A], G.A, G.B, G.B; | ||
})[1]; |
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
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
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
2 changes: 1 addition & 1 deletion
2
crates/swc/tests/tsc-references/constEnumPropertyAccess2_es2015.2.minified.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var G; | ||
(function(G) { | ||
G[G.A = 1] = "A", G[G.B = 2] = "B", G[G.C = 3] = "C", G[G.D = 2] = "D"; | ||
})(G || (G = {})), G[G.A], G.B = 3; | ||
})(G || (G = {})), G[1], G.B = 3; |
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
2 changes: 1 addition & 1 deletion
2
crates/swc/tests/tsc-references/constEnumPropertyAccess2_es5.2.minified.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var G; | ||
(function(G) { | ||
G[G.A = 1] = "A", G[G.B = 2] = "B", G[G.C = 3] = "C", G[G.D = 2] = "D"; | ||
})(G || (G = {})), G[G.A], G.B = 3; | ||
})(G || (G = {})), G[1], G.B = 3; |
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
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
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 |
---|---|---|
|
@@ -166,4 +166,4 @@ function foo1() { | |
} | ||
} | ||
foo1(1, 2, 3, E.a); | ||
foo1(1, 2, 3, E1.a, E.b); | ||
foo1(1, 2, 3, 0, E.b); |
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
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
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
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 |
---|---|---|
|
@@ -166,4 +166,4 @@ function foo1() { | |
} | ||
} | ||
foo1(1, 2, 3, E.a); | ||
foo1(1, 2, 3, E1.a, E.b); | ||
foo1(1, 2, 3, 0, E.b); |
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
Oops, something went wrong.
1743302
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
full_es2015
194464632
ns/iter (± 25131345
)172796660
ns/iter (± 5523368
)1.13
full_es2016
209792989
ns/iter (± 22258159
)177884497
ns/iter (± 9630153
)1.18
full_es2017
211067325
ns/iter (± 23599133
)176898710
ns/iter (± 6029938
)1.19
full_es2018
209207663
ns/iter (± 21307513
)175306615
ns/iter (± 5707664
)1.19
full_es2019
207111165
ns/iter (± 27030514
)174867699
ns/iter (± 5929635
)1.18
full_es2020
178077004
ns/iter (± 20117811
)160847944
ns/iter (± 5009194
)1.11
full_es3
253228959
ns/iter (± 24655142
)220222784
ns/iter (± 6855941
)1.15
full_es5
255734069
ns/iter (± 26422005
)216630191
ns/iter (± 9765541
)1.18
parser
825401
ns/iter (± 200602
)698479
ns/iter (± 28796
)1.18
This comment was automatically generated by workflow using github-action-benchmark.