Skip to content

Commit 31fe3b6

Browse files
authored
chore(es/typescript): Improve enum comments and sourcemap (#9652)
1 parent abffc07 commit 31fe3b6

8 files changed

+39
-32
lines changed

Diff for: .changeset/wild-glasses-buy.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: patch
3+
swc_ecma_transforms_typescript: patch
4+
---
5+
6+
chore(es/typescript): Improve enum comments and sourcemap

Diff for: crates/swc/tests/tsc-references/enumBasics.1.normal.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,29 @@ var e;
1515
// Reverse mapping of enum returns string name of property
1616
var s = E1[e.A];
1717
var s;
18-
var // Enum with only constant members
19-
E2 = /*#__PURE__*/ function(E2) {
18+
// Enum with only constant members
19+
var E2 = /*#__PURE__*/ function(E2) {
2020
E2[E2["A"] = 1] = "A";
2121
E2[E2["B"] = 2] = "B";
2222
E2[E2["C"] = 3] = "C";
2323
return E2;
2424
}(E2 || {});
25-
var // Enum with only computed members
26-
E3 = /*#__PURE__*/ function(E3) {
25+
// Enum with only computed members
26+
var E3 = /*#__PURE__*/ function(E3) {
2727
E3[E3["X"] = 'foo'.length] = "X";
2828
E3[E3["Y"] = 7] = "Y";
2929
E3[E3["Z"] = +"foo"] = "Z";
3030
return E3;
3131
}(E3 || {});
32-
var // Enum with constant members followed by computed members
33-
E4 = /*#__PURE__*/ function(E4) {
32+
// Enum with constant members followed by computed members
33+
var E4 = /*#__PURE__*/ function(E4) {
3434
E4[E4["X"] = 0] = "X";
3535
E4[E4["Y"] = 1] = "Y";
3636
E4[E4["Z"] = 'foo'.length] = "Z";
3737
return E4;
3838
}(E4 || {});
39-
var // Enum with > 2 constant members with no initializer for first member, non zero initializer for second element
40-
E5 = /*#__PURE__*/ function(E5) {
39+
// Enum with > 2 constant members with no initializer for first member, non zero initializer for second element
40+
var E5 = /*#__PURE__*/ function(E5) {
4141
E5[E5["A"] = 0] = "A";
4242
E5[E5["B"] = 3] = "B";
4343
E5[E5["C"] = 4] = "C"; // 4
@@ -49,18 +49,18 @@ var E6 = /*#__PURE__*/ function(E6) {
4949
E6[E6["C"] = 1] = "C"; // 1
5050
return E6;
5151
}(E6 || {});
52-
var // Enum with computed member initializer of type 'any'
53-
E7 = /*#__PURE__*/ function(E7) {
52+
// Enum with computed member initializer of type 'any'
53+
var E7 = /*#__PURE__*/ function(E7) {
5454
E7[E7["A"] = 'foo'['foo']] = "A";
5555
return E7;
5656
}(E7 || {});
57-
var // Enum with computed member initializer of type number
58-
E8 = /*#__PURE__*/ function(E8) {
57+
// Enum with computed member initializer of type number
58+
var E8 = /*#__PURE__*/ function(E8) {
5959
E8[E8["B"] = 'foo'['foo']] = "B";
6060
return E8;
6161
}(E8 || {});
62-
var //Enum with computed member intializer of same enum type
63-
E9 = /*#__PURE__*/ function(E9) {
62+
//Enum with computed member intializer of same enum type
63+
var E9 = /*#__PURE__*/ function(E9) {
6464
E9[E9["A"] = 0] = "A";
6565
E9[E9["B"] = 0] = "B";
6666
return E9;

Diff for: crates/swc/tests/tsc-references/enumClassification.1.normal.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ var E08 = /*#__PURE__*/ function(E08) {
5151
E08[E08["E"] = 10] = "E";
5252
return E08;
5353
}(E08 || {});
54-
var // Examples of numeric enum types with only constant members
55-
E10 = /*#__PURE__*/ function(E10) {
54+
// Examples of numeric enum types with only constant members
55+
var E10 = /*#__PURE__*/ function(E10) {
5656
return E10;
5757
}(E10 || {});
5858
var E11 = /*#__PURE__*/ function(E11) {
@@ -67,8 +67,8 @@ var E12 = /*#__PURE__*/ function(E12) {
6767
E12[E12["C"] = 4] = "C";
6868
return E12;
6969
}(E12 || {});
70-
var // Examples of numeric enum types with constant and computed members
71-
E20 = /*#__PURE__*/ function(E20) {
70+
// Examples of numeric enum types with constant and computed members
71+
var E20 = /*#__PURE__*/ function(E20) {
7272
E20[E20["A"] = "foo".length] = "A";
7373
E20[E20["B"] = E20.A + 1] = "B";
7474
E20[E20["C"] = +"123"] = "C";

Diff for: crates/swc/tests/tsc-references/equalityWithEnumTypes.1.normal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var E1 = /*#__PURE__*/ function(E1) {
55
E1[E1["b"] = 2] = "b";
66
return E1;
77
}(E1 || {});
8-
var // Numeric enum type
9-
E2 = /*#__PURE__*/ function(E2) {
8+
// Numeric enum type
9+
var E2 = /*#__PURE__*/ function(E2) {
1010
E2[E2["a"] = 1] = "a";
1111
E2[E2["b"] = 2] = "b";
1212
return E2;

Diff for: crates/swc/tests/tsc-references/exhaustiveSwitchStatements1.1.normal.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ function f3(x) {
3535
throw new Error("Bad input");
3636
}
3737
}
38-
var // Repro from #11572
39-
E = /*#__PURE__*/ function(E) {
38+
// Repro from #11572
39+
var E = /*#__PURE__*/ function(E) {
4040
E[E["A"] = 0] = "A";
4141
E[E["B"] = 1] = "B";
4242
return E;
@@ -92,8 +92,8 @@ function areaWrapped(s) {
9292
}();
9393
return area;
9494
}
95-
var // Repro from #13241
96-
MyEnum = /*#__PURE__*/ function(MyEnum) {
95+
// Repro from #13241
96+
var MyEnum = /*#__PURE__*/ function(MyEnum) {
9797
MyEnum[MyEnum["A"] = 0] = "A";
9898
MyEnum[MyEnum["B"] = 1] = "B";
9999
return MyEnum;
@@ -133,8 +133,8 @@ function good2(e) {
133133
return "it was B";
134134
}
135135
}
136-
var // Repro from #18362
137-
Level = /*#__PURE__*/ function(Level) {
136+
// Repro from #18362
137+
var Level = /*#__PURE__*/ function(Level) {
138138
Level[Level["One"] = 0] = "One";
139139
Level[Level["Two"] = 1] = "Two";
140140
return Level;
@@ -192,8 +192,8 @@ function test4(value) {
192192
}
193193
return x;
194194
}
195-
var // Repro from #34661
196-
Animal = /*#__PURE__*/ function(Animal) {
195+
// Repro from #34661
196+
var Animal = /*#__PURE__*/ function(Animal) {
197197
Animal[Animal["DOG"] = 0] = "DOG";
198198
Animal[Animal["CAT"] = 1] = "CAT";
199199
return Animal;

Diff for: crates/swc/tests/tsc-references/generatorYieldContextualType.1.normal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ f2(async function*() {
77
const a = yield 0;
88
return 0;
99
});
10-
var // repro from #41428
11-
Directive = /*#__PURE__*/ function(Directive) {
10+
// repro from #41428
11+
var Directive = /*#__PURE__*/ function(Directive) {
1212
Directive[Directive["Back"] = 0] = "Back";
1313
Directive[Directive["Cancel"] = 1] = "Cancel";
1414
Directive[Directive["LoadMore"] = 2] = "LoadMore";

Diff for: crates/swc/tests/tsc-references/typeofOperatorWithEnumType.1.normal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ typeof ENUM === "undefined" ? "undefined" : _type_of(ENUM);
2424
typeof ENUM1 === "undefined" ? "undefined" : _type_of(ENUM1);
2525
_type_of(1);
2626
typeof ENUM === "undefined" ? "undefined" : _type_of(ENUM), ENUM1;
27-
var // use typeof in type query
28-
z = /*#__PURE__*/ function(z) {
27+
// use typeof in type query
28+
var z = /*#__PURE__*/ function(z) {
2929
return z;
3030
}(z || {});
3131
z: typeof ENUM === "undefined" ? "undefined" : _type_of(ENUM);

Diff for: crates/swc_ecma_transforms_typescript/src/transform.rs

+1
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ impl Transform {
781781

782782
FoldedDecl::Decl(
783783
VarDecl {
784+
span,
784785
kind: var_kind,
785786
decls: vec![var_declarator],
786787
..Default::default()

0 commit comments

Comments
 (0)