Skip to content

Commit

Permalink
fix(es/typescript): Preserve more comments (#9509)
Browse files Browse the repository at this point in the history
**Related issue:**

- Closes #9505
  • Loading branch information
magic-akari authored Aug 28, 2024
1 parent 3674e7f commit 3e253ec
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-mugs-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
swc_ecma_transforms_typescript: patch
---

fix(es/typescript): Preserve more comments
15 changes: 15 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9505/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"minify": false,
"jsc": {
"parser": {
"syntax": "typescript"
},
"target": "es2022",
"minify": {
"mangle": false,
"format": {
"comments": "all"
}
}
}
}
5 changes: 5 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9505/input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
;// a.ts
const a = 1

;// b.ts
const b = 2
3 changes: 3 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9505/output/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; // a.ts
const a = 1; // b.ts
const b = 2;
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ function* g() {
_ts_decorate([
(yield "")
], C.prototype, "m", null);
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
function* g() {
class C extends (yield) {
}
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ function* g() {
C = _ts_decorate([
(yield 0)
], C);
;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//// [parserDoStatement2.ts]
do {}while (false);
do {
;
}while (false);
false;
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
* @path bestPractice/Sbp_7.9_A9_T3.js
* @description Execute do { \n ; \n }while(false) true
*/ //CHECK#1
do {}while (false);
do {
;
}while (false);
true;
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ C._ = [
_get(_get_prototype_of(C), "w", C).call(C);
})(),
(()=>{
; // no collision
_get(_get_prototype_of(C), "w", C).call(C);
})(),
(()=>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ C._ = [
_get(_get_prototype_of(C), "w", C).call(C);
})(),
(()=>{
; // no collision
_get(_get_prototype_of(C), "w", C).call(C);
})(),
(()=>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class C extends B {
super.w();
})(),
(()=>{
; // no collision
super.w();
})(),
(()=>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ C._ = [
_get(_get_prototype_of(C), "w", C).call(C);
}(),
function() {
; // no collision
_get(_get_prototype_of(C), "w", C).call(C);
}(),
function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class C extends B {
super.w();
})(),
(()=>{
; // no collision
super.w();
})(),
(()=>{
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_transforms_typescript/src/strip_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl VisitMut for StripType {

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

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

0 comments on commit 3e253ec

Please sign in to comment.