From 349d5f0db49a792111c394b1ee1acc31f82fa267 Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Sun, 11 Aug 2024 18:04:34 +0800 Subject: [PATCH 1/2] Add testcase --- .../tests/normalCases/parsing/asi/index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/rspack-test-tools/tests/normalCases/parsing/asi/index.js b/packages/rspack-test-tools/tests/normalCases/parsing/asi/index.js index 94839ab096e..bba15e9e7b3 100644 --- a/packages/rspack-test-tools/tests/normalCases/parsing/asi/index.js +++ b/packages/rspack-test-tools/tests/normalCases/parsing/asi/index.js @@ -1,7 +1,24 @@ import { foo } from "./a" +foo() + var a = { a: 1 } foo() const b = (function() { throw new Error("do not callme") }) foo() + +export const fooA = foo +foo() + +export { foo as fooB } +foo() + +export default a +foo() + +export * from "./a.js" +foo() + +debugger +foo() \ No newline at end of file From 2bae56476a27ea09c1229978e3df552286baa21d Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Sun, 11 Aug 2024 18:08:19 +0800 Subject: [PATCH 2/2] Fix --- .../src/visitors/semicolon.rs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/crates/rspack_plugin_javascript/src/visitors/semicolon.rs b/crates/rspack_plugin_javascript/src/visitors/semicolon.rs index 2328bd84bc1..e9ca5a73f4f 100644 --- a/crates/rspack_plugin_javascript/src/visitors/semicolon.rs +++ b/crates/rspack_plugin_javascript/src/visitors/semicolon.rs @@ -2,6 +2,7 @@ use rustc_hash::FxHashSet; use swc_core::{ common::{BytePos, Span, Spanned}, ecma::{ + ast::ClassMember, parser::token::{Token, TokenAndSpan}, visit::{Visit, VisitWith}, }, @@ -117,4 +118,48 @@ impl<'a> Visit for InsertedSemicolons<'a> { arg.visit_children_with(self) } } + + fn visit_import_decl(&mut self, n: &swc_core::ecma::ast::ImportDecl) { + self.post_semi(&n.span); + n.visit_children_with(self) + } + + fn visit_export_decl(&mut self, n: &swc_core::ecma::ast::ExportDecl) { + self.post_semi(&n.span); + n.visit_children_with(self) + } + + fn visit_named_export(&mut self, n: &swc_core::ecma::ast::NamedExport) { + self.post_semi(&n.span); + n.visit_children_with(self) + } + + fn visit_export_default_decl(&mut self, n: &swc_core::ecma::ast::ExportDefaultDecl) { + self.post_semi(&n.span); + n.visit_children_with(self) + } + + fn visit_export_default_expr(&mut self, n: &swc_core::ecma::ast::ExportDefaultExpr) { + self.post_semi(&n.span); + n.visit_children_with(self) + } + + fn visit_export_all(&mut self, n: &swc_core::ecma::ast::ExportAll) { + self.post_semi(&n.span); + n.visit_children_with(self) + } + + fn visit_debugger_stmt(&mut self, n: &swc_core::ecma::ast::DebuggerStmt) { + self.post_semi(&n.span); + n.visit_children_with(self); + } + + fn visit_class_member(&mut self, n: &swc_core::ecma::ast::ClassMember) { + match n { + ClassMember::ClassProp(prop) => self.post_semi(&prop.span), + ClassMember::PrivateProp(prop) => self.post_semi(&prop.span), + _ => {} + }; + n.visit_children_with(self); + } }