diff --git a/.changeset/chilly-zoos-applaud.md b/.changeset/chilly-zoos-applaud.md new file mode 100644 index 000000000000..3429ad20c411 --- /dev/null +++ b/.changeset/chilly-zoos-applaud.md @@ -0,0 +1,6 @@ +--- +swc_core: patch +swc_ecma_codegen: patch +--- + +fix(es/codegen): Emit semicolon after using declarations diff --git a/crates/swc/tests/fixture/issues-9xxx/9816/input/.swcrc b/crates/swc/tests/fixture/issues-9xxx/9816/input/.swcrc new file mode 100644 index 000000000000..7d776342ec49 --- /dev/null +++ b/crates/swc/tests/fixture/issues-9xxx/9816/input/.swcrc @@ -0,0 +1,9 @@ +{ + "jsc": { + "target": "esnext", + "parser": { + "syntax": "ecmascript", + "explicitResourceManagement": true + } + }, +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-9xxx/9816/input/1.js b/crates/swc/tests/fixture/issues-9xxx/9816/input/1.js new file mode 100644 index 000000000000..2ca3bab25b1d --- /dev/null +++ b/crates/swc/tests/fixture/issues-9xxx/9816/input/1.js @@ -0,0 +1 @@ +using r = 0; \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-9xxx/9816/output/1.js b/crates/swc/tests/fixture/issues-9xxx/9816/output/1.js new file mode 100644 index 000000000000..e88e4e429581 --- /dev/null +++ b/crates/swc/tests/fixture/issues-9xxx/9816/output/1.js @@ -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); +} diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index dad7714d6aff..c78527cca5ea 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -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() { diff --git a/crates/swc_ecma_codegen/tests/fixture/node-erm/input.js b/crates/swc_ecma_codegen/tests/fixture/node-erm/input.js new file mode 100644 index 000000000000..2ca3bab25b1d --- /dev/null +++ b/crates/swc_ecma_codegen/tests/fixture/node-erm/input.js @@ -0,0 +1 @@ +using r = 0; \ No newline at end of file diff --git a/crates/swc_ecma_codegen/tests/fixture/node-erm/output.js b/crates/swc_ecma_codegen/tests/fixture/node-erm/output.js new file mode 100644 index 000000000000..458657f9ed9b --- /dev/null +++ b/crates/swc_ecma_codegen/tests/fixture/node-erm/output.js @@ -0,0 +1 @@ +using r = 0; diff --git a/crates/swc_ecma_codegen/tests/fixture/node-erm/output.min.js b/crates/swc_ecma_codegen/tests/fixture/node-erm/output.min.js new file mode 100644 index 000000000000..e324adaf583f --- /dev/null +++ b/crates/swc_ecma_codegen/tests/fixture/node-erm/output.min.js @@ -0,0 +1 @@ +using r=0; diff --git a/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/2/output.ts b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/2/output.ts index 38f986f77eb9..b49ce7d56e20 100644 --- a/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/2/output.ts +++ b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/2/output.ts @@ -1,5 +1,5 @@ { - using foo__3 = null + using foo__3 = null; }{ - using foo__4 = null + using foo__4 = null; } diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/output.js index 7ea4e7afe729..d32fa8aa6f74 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/integration/async-to-generator/output.js @@ -8,7 +8,6 @@ async function fn() { }; try { const x = _ts_add_disposable_resource(env, y, true); - ; await 1; } catch (e) { env.error = e; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/output.js index a2524db313bb..abf31f5ccc7b 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/block/output.js @@ -6,7 +6,6 @@ }; try { const x = _ts_add_disposable_resource(env, fn(), false); - ; doSomethingWith(x); } catch (e) { env.error = e; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/output.js index 8129924e0ee2..974acd562f42 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/switch/output.js @@ -8,7 +8,6 @@ function f() { }; try { const x = _ts_add_disposable_resource(env, 0, false); - ; break; } catch (e) { env.error = e; @@ -24,7 +23,6 @@ function f() { }; try { const y = _ts_add_disposable_resource(env1, 1, false); - ; break; } catch (e) { env1.error = e; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/output.mjs index 605b85deb577..be24a5cbc81e 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/source-maps/top-level/output.mjs @@ -6,7 +6,6 @@ const env = { try { before; const x = _ts_add_disposable_resource(env, fn(), false); - ; doSomethingWith(x); after; } catch (e) { diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/output.js index afbfd33fd0bf..6a6c8f482086 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/mixed/output.js @@ -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; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/output.js index 2f5441a4e83a..3e21c43bfa7c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/only-using-await/output.js @@ -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; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/output.js index b9d99eae1372..94dfa01847e2 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-await/switch/output.js @@ -8,7 +8,6 @@ async function f() { }; try { const x = _ts_add_disposable_resource(env, 0, true); - ; break; } catch (e) { env.error = e; @@ -25,7 +24,6 @@ async function f() { }; try { const y = _ts_add_disposable_resource(env1, 1, true); - ; break; } catch (e) { env1.error = e; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/bare-block/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/bare-block/output.js index cf9feb07ec12..a5cf6ad40b3c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/bare-block/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/bare-block/output.js @@ -6,7 +6,6 @@ }; try { const x = _ts_add_disposable_resource(env, obj, false); - ; doSomethingWith(x); } catch (e) { env.error = e; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/function-body/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/function-body/output.js index 6f0533a0174c..d91233001761 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/function-body/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/function-body/output.js @@ -6,7 +6,6 @@ function fn() { }; try { const x = _ts_add_disposable_resource(env, obj, false); - ; return doSomethingWith(x); } catch (e) { env.error = e; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/if-body/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/if-body/output.js index 0cc69839bee6..81c69ee81ac7 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/if-body/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/if-body/output.js @@ -6,7 +6,6 @@ if (test) { }; try { const x = _ts_add_disposable_resource(env, obj, false); - ; doSomethingWith(x); } catch (e) { env.error = e; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-nested/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-nested/output.js index 6d0283026a4d..8cb88fa4fb7a 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-nested/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-nested/output.js @@ -6,7 +6,6 @@ }; try { const x = _ts_add_disposable_resource(env, obj, false); - ; { const env = { stack: [], @@ -22,7 +21,6 @@ }; try { const z = _ts_add_disposable_resource(env, obj, false); - ; return z; } catch (e) { env.error = e; @@ -31,7 +29,6 @@ _ts_dispose_resources(env); } }), false); - ; stmt; } catch (e) { env.error = e; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-same-level/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-same-level/output.js index b665392b9b36..2af1a480aebb 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-same-level/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/multiple-same-level/output.js @@ -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; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/static-block/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/static-block/output.js index c36e33bfe7b7..498f53d5b0f2 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/static-block/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/static-block/output.js @@ -7,7 +7,6 @@ class A { }; try { const x = _ts_add_disposable_resource(env, y, false); - ; doSomethingWith(x); } catch (e) { env.error = e; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/output.js b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/output.js index 8129924e0ee2..974acd562f42 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-sync/switch/output.js @@ -8,7 +8,6 @@ function f() { }; try { const x = _ts_add_disposable_resource(env, 0, false); - ; break; } catch (e) { env.error = e; @@ -24,7 +23,6 @@ function f() { }; try { const y = _ts_add_disposable_resource(env1, 1, false); - ; break; } catch (e) { env1.error = e; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/await-or-not-preserved/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/await-or-not-preserved/output.mjs index e020f64d1ad7..e6728520148b 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/await-or-not-preserved/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/await-or-not-preserved/output.mjs @@ -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; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-clas-anon/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-clas-anon/output.mjs index 38ecd583ef88..32c068181126 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-clas-anon/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-clas-anon/output.mjs @@ -5,7 +5,6 @@ const env = { }; try { const x = _ts_add_disposable_resource(env, null, false); - ; } catch (e) { env.error = e; env.hasError = true; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-class/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-class/output.mjs index b50ee59781f7..6a3bcf09b09e 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-class/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-class/output.mjs @@ -5,7 +5,6 @@ const env = { }; try { const x = _ts_add_disposable_resource(env, null, false); - ; } catch (e) { env.error = e; env.hasError = true; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-expr/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-expr/output.mjs index 80815fe04151..804cff5ea28f 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-expr/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-expr/output.mjs @@ -5,7 +5,6 @@ const env = { }; try { const x = _ts_add_disposable_resource(env, null, false); - ; } catch (e) { env.error = e; env.hasError = true; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn-anon/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn-anon/output.mjs index 1bac2b983899..ae339597cfc2 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn-anon/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn-anon/output.mjs @@ -5,7 +5,6 @@ const env = { }; try { const x = _ts_add_disposable_resource(env, null, false); - ; } catch (e) { env.error = e; env.hasError = true; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn/output.mjs index 1bac2b983899..ae339597cfc2 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting-default-fn/output.mjs @@ -5,7 +5,6 @@ const env = { }; try { const x = _ts_add_disposable_resource(env, null, false); - ; } catch (e) { env.error = e; env.hasError = true; diff --git a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting/output.mjs b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting/output.mjs index e3878d4f3ccf..042d0e1a582a 100644 --- a/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting/output.mjs +++ b/crates/swc_ecma_transforms_proposal/tests/explicit-resource-management/transform-top-level/hoisting/output.mjs @@ -17,7 +17,6 @@ try { class A { } const x = _ts_add_disposable_resource(env, null, false); - ; } catch (e) { env.error = e; env.hasError = true;