Skip to content

Commit d9ba838

Browse files
authored
fix(es/codegen): Improve comments handling (#10534)
1 parent a72092c commit d9ba838

File tree

126 files changed

+342
-554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+342
-554
lines changed

.changeset/modern-crews-glow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_core: minor
3+
swc_ecma_codegen: minor
4+
---
5+
6+
fix(es/codegen): Improve comments handling

crates/swc/tests/fixture/issues-5xxx/5272/1/output/a.map

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"mappings": ";;;+BACaA;;;eAAAA;;;;;;;oBADQ;AACd,IAAA,AAAMA,oBAAN;;gBAAMA;aAAAA;kCAAAA;eAAN,oBAAMA;;oBAAAA;;YACTC,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,IAAI,CAACC,GAAG;YACvB;;;WAHSF;EAAYG,UAAI",
2+
"mappings": ";;;+BACaA;;;eAAAA;;;;;;;oBADQ;AACd,IAAA,AAAMA,oBAAN;;gBAAMA;aAAAA;kCAAAA;QAAN,OAAA,oBAAMA;;oBAAAA;;YACTC,KAAAA;mBAAAA,SAAAA;gBACI,OAAO,IAAI,IAAI,CAACC,GAAG;YACvB;;;WAHSF;EAAYG,UAAI",
33
"names": [
44
"Foo",
55
"bar",

crates/swc/tests/tsc-references/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.1.normal.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ var Point = /*#__PURE__*/ function() {
1212
x: 0,
1313
y: 0
1414
};
15-
} // unexpected error here bug 840246
16-
;
15+
}; // unexpected error here bug 840246
1716
return Point;
1817
}();
1918
(function(Point) {
@@ -35,8 +34,7 @@ var Point = /*#__PURE__*/ function() {
3534
x: 0,
3635
y: 0
3736
};
38-
} // unexpected error here bug 840246
39-
;
37+
}; // unexpected error here bug 840246
4038
return Point;
4139
}();
4240
A.Point = Point;

crates/swc/tests/tsc-references/ES5SymbolProperty5.1.normal.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ var C = /*#__PURE__*/ function() {
1010
_proto[Symbol.iterator] = function() {};
1111
return C;
1212
}();
13-
(new C)[Symbol.iterator](0) // Should error
14-
;
13+
(new C)[Symbol.iterator](0); // Should error
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//// [types.ts]
22
//// [test.ts]
3-
ohno.a // oh no
4-
;
3+
ohno.a; // oh no
54
export { };

crates/swc/tests/tsc-references/arraySpreadInCall.1.normal.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,4 @@ var x44 = f4.apply(void 0, [
105105
(_action = action).run.apply(_action, [
106106
100,
107107
'foo'
108-
] // error
109-
);
108+
]); // error
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
//// [asiPreventsParsingAsAmbientExternalModule01.ts]
22
var declare;
33
var module;
4-
declare // this is the identifier 'declare'
5-
;
6-
module // this is the identifier 'module'
7-
;
8-
"my external module" // this is just a string
9-
;
4+
declare; // this is the identifier 'declare'
5+
module; // this is the identifier 'module'
6+
"my external module"; // this is just a string
107
{} // this is a block body

crates/swc/tests/tsc-references/asiPreventsParsingAsAmbientExternalModule02.1.normal.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
var declare;
33
var module;
44
(function(container) {
5-
declare // this is the identifier 'declare'
6-
;
7-
module // this is the identifier 'module'
8-
;
9-
"my external module" // this is just a string
10-
;
5+
declare; // this is the identifier 'declare'
6+
module; // this is the identifier 'module'
7+
"my external module"; // this is just a string
118
{}
129
})(container || (container = {}));
1310
var container;
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//// [asiPreventsParsingAsNamespace02.ts]
22
var module;
33
var m;
4-
module // this is the identifier 'namespace'
5-
;
6-
m // this is the identifier 'm'
7-
;
4+
module; // this is the identifier 'namespace'
5+
m; // this is the identifier 'm'
86
{} // this is a block body

crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationES2022.1.normal.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,26 @@ class C {
77
quench;
88
quanch;
99
m1() {
10-
this.foo // ok
11-
;
10+
this.foo; // ok
1211
}
1312
m3;
1413
constructor(foo){
1514
this.foo = foo;
16-
this.qux = this.bar // should error
17-
;
18-
this.bar = this.foo // should error
19-
;
20-
this.quiz = this.bar // ok
21-
;
22-
this.quench = this.m1() // ok
23-
;
24-
this.quanch = this.m3() // should error
25-
;
15+
this.qux = this.bar; // should error
16+
this.bar = this.foo; // should error
17+
this.quiz = this.bar; // ok
18+
this.quench = this.m1(); // ok
19+
this.quanch = this.m3(); // should error
2620
this.m3 = function() {};
27-
this.quim = this.baz // should error
28-
;
29-
this.baz = this.foo;
30-
this.quid = this.baz // ok
31-
;
21+
this.quim = this.baz; // should error
22+
this.baz = this.foo; // should error
23+
this.quid = this.baz; // ok
3224
}
3325
quim;
3426
baz;
3527
quid;
3628
m2() {
37-
this.foo // ok
38-
;
29+
this.foo; // ok
3930
}
4031
}
4132
class D extends C {
@@ -48,7 +39,7 @@ class E {
4839
foo1;
4940
constructor(foo2){
5041
this.foo2 = foo2;
51-
this.bar = ()=>this.foo1 + this.foo2;
42+
this.bar = ()=>this.foo1 + this.foo2; // both ok
5243
this.foo1 = '';
5344
}
5445
}

crates/swc/tests/tsc-references/assignParameterPropertyToPropertyDeclarationESNext.1.normal.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,26 @@ class C {
77
quench;
88
quanch;
99
m1() {
10-
this.foo // ok
11-
;
10+
this.foo; // ok
1211
}
1312
m3;
1413
constructor(foo){
1514
this.foo = foo;
16-
this.qux = this.bar // should error
17-
;
18-
this.bar = this.foo // should error
19-
;
20-
this.quiz = this.bar // ok
21-
;
22-
this.quench = this.m1() // ok
23-
;
24-
this.quanch = this.m3() // should error
25-
;
15+
this.qux = this.bar; // should error
16+
this.bar = this.foo; // should error
17+
this.quiz = this.bar; // ok
18+
this.quench = this.m1(); // ok
19+
this.quanch = this.m3(); // should error
2620
this.m3 = function() {};
27-
this.quim = this.baz // should error
28-
;
29-
this.baz = this.foo;
30-
this.quid = this.baz // ok
31-
;
21+
this.quim = this.baz; // should error
22+
this.baz = this.foo; // should error
23+
this.quid = this.baz; // ok
3224
}
3325
quim;
3426
baz;
3527
quid;
3628
m2() {
37-
this.foo // ok
38-
;
29+
this.foo; // ok
3930
}
4031
}
4132
class D extends C {
@@ -48,7 +39,7 @@ class E {
4839
foo1;
4940
constructor(foo2){
5041
this.foo2 = foo2;
51-
this.bar = ()=>this.foo1 + this.foo2;
42+
this.bar = ()=>this.foo1 + this.foo2; // both ok
5243
this.foo1 = '';
5344
}
5445
}

crates/swc/tests/tsc-references/assignmentCompatWithCallSignaturesWithOptionalParameters.1.normal.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
var b;
44
var a;
55
a = function() {
6-
return 1 // ok, same number of required params
7-
;
8-
};
6+
return 1;
7+
}; // ok, same number of required params
98
a = function(x) {
109
return 1;
1110
}; // ok, same number of required params

crates/swc/tests/tsc-references/assignmentCompatWithGenericCallSignatures3.1.normal.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
// some complex cases of assignment compat of generic signatures that stress contextual signature instantiation
33
var g;
44
var h;
5-
g = h // ok
6-
;
5+
g = h; // ok

crates/swc/tests/tsc-references/callOverload.1.normal.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//// [callOverload.ts]
22
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
33
var n;
4-
fn(1) // no error
5-
;
4+
fn(1); // no error
65
fn(1, 2, 3, 4);
76
takeTwo(1, 2, 3, 4);
87
withRest.apply(void 0, [

crates/swc/tests/tsc-references/callWithMissingVoid.1.normal.js

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,12 @@ var X = /*#__PURE__*/ function() {
1414
};
1515
return X;
1616
}();
17-
x.f() // no error because f expects void
18-
;
19-
xUnion.f(42) // no error because f accepts number
20-
;
21-
xUnion.f() // no error because f accepts void
22-
;
23-
xAny.f() // error, any still expects an argument
24-
;
25-
xUnknown.f() // error, unknown still expects an argument
26-
;
27-
xNever.f() // error, never still expects an argument
28-
;
17+
x.f(); // no error because f expects void
18+
xUnion.f(42); // no error because f accepts number
19+
xUnion.f(); // no error because f accepts void
20+
xAny.f(); // error, any still expects an argument
21+
xUnknown.f(); // error, unknown still expects an argument
22+
xNever.f(); // error, never still expects an argument
2923
// Promise has previously been updated to work without arguments, but to show this fixes the issue too.
3024
var MyPromise = function MyPromise(executor) {
3125
"use strict";
@@ -63,33 +57,25 @@ c(3); // ok
6357
c(); // ok
6458
call(function(x1, y) {
6559
return x1 + y;
66-
}) // error
67-
;
60+
}); // error
6861
call(function(x1, y) {
6962
return x1 + y;
70-
}, 4, 2) // ok
71-
;
63+
}, 4, 2); // ok
7264
call(function(x1, y) {
7365
return x1;
74-
}, 4, void 0) // ok
75-
;
66+
}, 4, void 0); // ok
7667
call(function(x1, y) {
7768
return x1;
78-
}, 4) // ok
79-
;
69+
}, 4); // ok
8070
call(function(x1, y) {
8171
return 42;
82-
}) // ok
83-
;
72+
}); // ok
8473
call(function(x1, y) {
8574
return 42;
86-
}) // ok
87-
;
75+
}); // ok
8876
call(function(x1, y) {
8977
return 42;
90-
}, 4) // ok
91-
;
78+
}, 4); // ok
9279
call(function(x1, y) {
9380
return 42;
94-
}, 4, 2) // ok
95-
;
81+
}, 4, 2); // ok

crates/swc/tests/tsc-references/callWithSpread2.1.normal.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ rest.apply(void 0, [
3131
rest.apply(void 0, [
3232
"f"
3333
].concat(_to_consumable_array(tuple)));
34-
prefix.apply(void 0, _to_consumable_array(ns)) // required parameters are required
35-
;
34+
prefix.apply(void 0, _to_consumable_array(ns)); // required parameters are required
3635
prefix.apply(void 0, _to_consumable_array(mixed));
3736
prefix.apply(void 0, _to_consumable_array(tuple));
3837
prefix2.apply(void 0, [

crates/swc/tests/tsc-references/classAbstractSuperCalls.1.normal.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ var C = /*#__PURE__*/ function(B) {
4444
};
4545
_proto.qux = function qux() {
4646
return _get(_get_prototype_of(C.prototype), "foo", this).call(this) || _get(_get_prototype_of(C.prototype), "foo", this);
47-
} // 2 errors, foo is abstract
48-
;
47+
}; // 2 errors, foo is abstract
4948
_proto.norf = function norf() {
5049
return _get(_get_prototype_of(C.prototype), "bar", this).call(this);
5150
};

crates/swc/tests/tsc-references/classConstructorAccessibility2.1.normal.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,10 @@ var DerivedB = /*#__PURE__*/ function(BaseB1) {
8181
};
8282
_proto.createBaseInstance = function createBaseInstance() {
8383
new BaseB(8);
84-
} // ok
85-
;
84+
}; // ok
8685
DerivedB.staticBaseInstance = function staticBaseInstance() {
8786
new BaseB(9);
88-
} // ok
89-
;
87+
}; // ok
9088
return DerivedB;
9189
}(BaseB);
9290
var DerivedC = /*#__PURE__*/ function(BaseC1) {
@@ -106,12 +104,10 @@ var DerivedC = /*#__PURE__*/ function(BaseC1) {
106104
};
107105
_proto.createBaseInstance = function createBaseInstance() {
108106
new BaseC(10);
109-
} // error
110-
;
107+
}; // error
111108
DerivedC.staticBaseInstance = function staticBaseInstance() {
112109
new BaseC(11);
113-
} // error
114-
;
110+
}; // error
115111
return DerivedC;
116112
}(BaseC);
117113
var ba = new BaseA(1);

crates/swc/tests/tsc-references/classConstructorAccessibility5.1.normal.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ var Derived = /*#__PURE__*/ function(Base1) {
1515
}
1616
Derived.make = function make() {
1717
new Base();
18-
} // ok
19-
;
18+
}; // ok
2019
return Derived;
2120
}(Base);
2221
var Unrelated = /*#__PURE__*/ function() {
@@ -26,7 +25,6 @@ var Unrelated = /*#__PURE__*/ function() {
2625
}
2726
Unrelated.fake = function fake() {
2827
new Base();
29-
} // error
30-
;
28+
}; // error
3129
return Unrelated;
3230
}();

crates/swc/tests/tsc-references/classConstructorParametersAccessibility.1.normal.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,21 @@ var C1 = function C1(x) {
88
this.x = x;
99
};
1010
var c1;
11-
c1.x // OK
12-
;
11+
c1.x; // OK
1312
var C2 = function C2(p) {
1413
"use strict";
1514
_class_call_check(this, C2);
1615
this.p = p;
1716
};
1817
var c2;
19-
c2.p // private, error
20-
;
18+
c2.p; // private, error
2119
var C3 = function C3(p) {
2220
"use strict";
2321
_class_call_check(this, C3);
2422
this.p = p;
2523
};
2624
var c3;
27-
c3.p // protected, error
28-
;
25+
c3.p; // protected, error
2926
var Derived = /*#__PURE__*/ function(C3) {
3027
"use strict";
3128
_inherits(Derived, C3);

0 commit comments

Comments
 (0)