Skip to content

Commit

Permalink
fix(es/codegen): Emit semicolon after using declarations (#9816)
Browse files Browse the repository at this point in the history
**Related issue:**

 - nodejs/amaro#138
  • Loading branch information
kdy1 authored Dec 27, 2024
1 parent 4e2dae5 commit 556d924
Show file tree
Hide file tree
Showing 30 changed files with 40 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .changeset/chilly-zoos-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc_ecma_codegen: patch
---

fix(es/codegen): Emit semicolon after using declarations
9 changes: 9 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9816/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"jsc": {
"target": "esnext",
"parser": {
"syntax": "ecmascript",
"explicitResourceManagement": true
}
},
}
1 change: 1 addition & 0 deletions crates/swc/tests/fixture/issues-9xxx/9816/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using r = 0;
15 changes: 15 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9816/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var _ts_add_disposable_resource = require("@swc/helpers/_/_ts_add_disposable_resource");
var _ts_dispose_resources = require("@swc/helpers/_/_ts_dispose_resources");
const env = {
stack: [],
error: void 0,
hasError: false
};
try {
const r = _ts_add_disposable_resource._(env, 0, false);
} catch (e) {
env.error = e;
env.hasError = true;
} finally{
_ts_dispose_resources._(env);
}
4 changes: 4 additions & 0 deletions crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,10 @@ where
emit!(e);
semi!();
}
Stmt::Decl(e @ Decl::Using(..)) => {
emit!(e);
semi!();
}
Stmt::Decl(ref e) => emit!(e),
}
if self.comments.is_some() {
Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_codegen/tests/fixture/node-erm/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using r = 0;
1 change: 1 addition & 0 deletions crates/swc_ecma_codegen/tests/fixture/node-erm/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using r = 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using r=0;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
using foo__3 = null
using foo__3 = null;
}{
using foo__4 = null
using foo__4 = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ async function fn() {
};
try {
const x = _ts_add_disposable_resource(env, y, true);
;
await 1;
} catch (e) {
env.error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
};
try {
const x = _ts_add_disposable_resource(env, fn(), false);
;
doSomethingWith(x);
} catch (e) {
env.error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function f() {
};
try {
const x = _ts_add_disposable_resource(env, 0, false);
;
break;
} catch (e) {
env.error = e;
Expand All @@ -24,7 +23,6 @@ function f() {
};
try {
const y = _ts_add_disposable_resource(env1, 1, false);
;
break;
} catch (e) {
env1.error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const env = {
try {
before;
const x = _ts_add_disposable_resource(env, fn(), false);
;
doSomethingWith(x);
after;
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
};
try {
const a = _ts_add_disposable_resource(env, 1, false);
;
const b = _ts_add_disposable_resource(env, 2, true);
;
const c = _ts_add_disposable_resource(env, 3, false);
;
} catch (e) {
env.error = e;
env.hasError = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
};
try {
const x = _ts_add_disposable_resource(env, obj, true);
;
stmt;
const y = _ts_add_disposable_resource(env, obj, true), z = _ts_add_disposable_resource(env, obj, true);
;
doSomethingWith(x, y);
} catch (e) {
env.error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ async function f() {
};
try {
const x = _ts_add_disposable_resource(env, 0, true);
;
break;
} catch (e) {
env.error = e;
Expand All @@ -25,7 +24,6 @@ async function f() {
};
try {
const y = _ts_add_disposable_resource(env1, 1, true);
;
break;
} catch (e) {
env1.error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
};
try {
const x = _ts_add_disposable_resource(env, obj, false);
;
doSomethingWith(x);
} catch (e) {
env.error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ function fn() {
};
try {
const x = _ts_add_disposable_resource(env, obj, false);
;
return doSomethingWith(x);
} catch (e) {
env.error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ if (test) {
};
try {
const x = _ts_add_disposable_resource(env, obj, false);
;
doSomethingWith(x);
} catch (e) {
env.error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
};
try {
const x = _ts_add_disposable_resource(env, obj, false);
;
{
const env = {
stack: [],
Expand All @@ -22,7 +21,6 @@
};
try {
const z = _ts_add_disposable_resource(env, obj, false);
;
return z;
} catch (e) {
env.error = e;
Expand All @@ -31,7 +29,6 @@
_ts_dispose_resources(env);
}
}), false);
;
stmt;
} catch (e) {
env.error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
try {
stmt;
const x = _ts_add_disposable_resource(env, obj, false);
;
stmt;
const y = _ts_add_disposable_resource(env, obj, false), z = _ts_add_disposable_resource(env, obj, false);
;
stmt;
const w = _ts_add_disposable_resource(env, obj, false);
;
doSomethingWith(x, z);
} catch (e) {
env.error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class A {
};
try {
const x = _ts_add_disposable_resource(env, y, false);
;
doSomethingWith(x);
} catch (e) {
env.error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function f() {
};
try {
const x = _ts_add_disposable_resource(env, 0, false);
;
break;
} catch (e) {
env.error = e;
Expand All @@ -24,7 +23,6 @@ function f() {
};
try {
const y = _ts_add_disposable_resource(env1, 1, false);
;
break;
} catch (e) {
env1.error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const env = {
};
try {
const x = _ts_add_disposable_resource(env, A, false);
;
const y = _ts_add_disposable_resource(env, B, true);
;
} catch (e) {
env.error = e;
env.hasError = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const env = {
};
try {
const x = _ts_add_disposable_resource(env, null, false);
;
} catch (e) {
env.error = e;
env.hasError = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const env = {
};
try {
const x = _ts_add_disposable_resource(env, null, false);
;
} catch (e) {
env.error = e;
env.hasError = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const env = {
};
try {
const x = _ts_add_disposable_resource(env, null, false);
;
} catch (e) {
env.error = e;
env.hasError = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const env = {
};
try {
const x = _ts_add_disposable_resource(env, null, false);
;
} catch (e) {
env.error = e;
env.hasError = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const env = {
};
try {
const x = _ts_add_disposable_resource(env, null, false);
;
} catch (e) {
env.error = e;
env.hasError = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ try {
class A {
}
const x = _ts_add_disposable_resource(env, null, false);
;
} catch (e) {
env.error = e;
env.hasError = true;
Expand Down

0 comments on commit 556d924

Please sign in to comment.