Skip to content

Commit 3e253ec

Browse files
authored
fix(es/typescript): Preserve more comments (#9509)
**Related issue:** - Closes #9505
1 parent 3674e7f commit 3e253ec

15 files changed

+43
-3
lines changed

.changeset/silly-mugs-heal.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
swc_ecma_transforms_typescript: patch
3+
---
4+
5+
fix(es/typescript): Preserve more comments
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"minify": false,
3+
"jsc": {
4+
"parser": {
5+
"syntax": "typescript"
6+
},
7+
"target": "es2022",
8+
"minify": {
9+
"mangle": false,
10+
"format": {
11+
"comments": "all"
12+
}
13+
}
14+
}
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
;// a.ts
2+
const a = 1
3+
4+
;// b.ts
5+
const b = 2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
; // a.ts
2+
const a = 1; // b.ts
3+
const b = 2;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ function* g() {
77
_ts_decorate([
88
(yield "")
99
], C.prototype, "m", null);
10+
;
1011
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
function* g() {
33
class C extends (yield) {
44
}
5+
;
56
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ function* g() {
66
C = _ts_decorate([
77
(yield 0)
88
], C);
9+
;
910
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
//// [parserDoStatement2.ts]
2-
do {}while (false);
2+
do {
3+
;
4+
}while (false);
35
false;

crates/swc/tests/tsc-references/parserSbp_7.9_A9_T3.1.normal.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
* @path bestPractice/Sbp_7.9_A9_T3.js
88
* @description Execute do { \n ; \n }while(false) true
99
*/ //CHECK#1
10-
do {}while (false);
10+
do {
11+
;
12+
}while (false);
1113
true;

crates/swc/tests/tsc-references/superInStaticMembers1(target=es2015).1.normal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ C._ = [
5050
_get(_get_prototype_of(C), "w", C).call(C);
5151
})(),
5252
(()=>{
53+
; // no collision
5354
_get(_get_prototype_of(C), "w", C).call(C);
5455
})(),
5556
(()=>{

crates/swc/tests/tsc-references/superInStaticMembers1(target=es2021).1.normal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ C._ = [
5050
_get(_get_prototype_of(C), "w", C).call(C);
5151
})(),
5252
(()=>{
53+
; // no collision
5354
_get(_get_prototype_of(C), "w", C).call(C);
5455
})(),
5556
(()=>{

crates/swc/tests/tsc-references/superInStaticMembers1(target=es2022).1.normal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class C extends B {
4848
super.w();
4949
})(),
5050
(()=>{
51+
; // no collision
5152
super.w();
5253
})(),
5354
(()=>{

crates/swc/tests/tsc-references/superInStaticMembers1(target=es5).1.normal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ C._ = [
6969
_get(_get_prototype_of(C), "w", C).call(C);
7070
}(),
7171
function() {
72+
; // no collision
7273
_get(_get_prototype_of(C), "w", C).call(C);
7374
}(),
7475
function() {

crates/swc/tests/tsc-references/superInStaticMembers1(target=esnext).1.normal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class C extends B {
4848
super.w();
4949
})(),
5050
(()=>{
51+
; // no collision
5152
super.w();
5253
})(),
5354
(()=>{

crates/swc_ecma_transforms_typescript/src/strip_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl VisitMut for StripType {
206206

207207
fn visit_mut_stmts(&mut self, n: &mut Vec<Stmt>) {
208208
n.visit_mut_children_with(self);
209-
n.retain(|s| !s.is_empty());
209+
n.retain(|s| !matches!(s, Stmt::Empty(e) if e.span.is_dummy()));
210210
}
211211

212212
fn visit_mut_stmt(&mut self, n: &mut Stmt) {

0 commit comments

Comments
 (0)