From a59a0f17a23de0ad093f989b2b1f4b7e84605097 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 22 Aug 2023 17:50:10 +0200 Subject: [PATCH 1/6] Fix swc compiling --- .../next-swc/crates/core/src/react_server_components.rs | 4 ++++ .../server-graph/fake-client-entry/input.js | 5 +++++ .../server-graph/fake-client-entry/output.js | 3 +++ .../server-graph/fake-client-entry/output.stderr | 7 +++++++ 4 files changed, 19 insertions(+) create mode 100644 packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js create mode 100644 packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js create mode 100644 packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr diff --git a/packages/next-swc/crates/core/src/react_server_components.rs b/packages/next-swc/crates/core/src/react_server_components.rs index 1c483a1ab3311..1435e38eafa3c 100644 --- a/packages/next-swc/crates/core/src/react_server_components.rs +++ b/packages/next-swc/crates/core/src/react_server_components.rs @@ -222,6 +222,7 @@ impl ReactServerComponents { }, }) } + finished_directives = true; } ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { decl, .. })) => { match decl { @@ -240,18 +241,21 @@ impl ReactServerComponents { } _ => {} } + finished_directives = true; } ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { decl: _, .. })) => { self.export_names.push("default".to_string()); + finished_directives = true; } ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultExpr(ExportDefaultExpr { expr: _, .. })) => { self.export_names.push("default".to_string()); + finished_directives = true; } ModuleItem::ModuleDecl(ModuleDecl::ExportAll(_)) => { self.export_names.push("*".to_string()); diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js new file mode 100644 index 0000000000000..decc3848b224d --- /dev/null +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js @@ -0,0 +1,5 @@ +export default function () { + return null +} + +'use client' \ No newline at end of file diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js new file mode 100644 index 0000000000000..33997bb6e2495 --- /dev/null +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js @@ -0,0 +1,3 @@ +export default function() { + return null; +} diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr new file mode 100644 index 0000000000000..8da2c69a3b137 --- /dev/null +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr @@ -0,0 +1,7 @@ + + x NEXT_RSC_ERR_CLIENT_DIRECTIVE + ,-[input.js:4:1] + 4 | + 5 | 'use client' + : ^^^^^^^^^^^^ + `---- From 46bdcef5282f3931312577530c2850b1975fa68b Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 22 Aug 2023 18:25:54 +0200 Subject: [PATCH 2/6] fix test --- .../server-graph/fake-client-entry/input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js index decc3848b224d..cb1e0dcca1450 100644 --- a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js @@ -2,4 +2,4 @@ export default function () { return null } -'use client' \ No newline at end of file +;('use client') From d52106ee935021a8d03ad52d2a097eaeb5db9358 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 22 Aug 2023 18:57:51 +0200 Subject: [PATCH 3/6] fix test --- .../next-swc/crates/core/src/react_server_components.rs | 1 + .../server-graph/fake-client-entry/input.js | 4 +++- .../server-graph/fake-client-entry/output.js | 1 + .../server-graph/fake-client-entry/output.stderr | 8 ++++---- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/next-swc/crates/core/src/react_server_components.rs b/packages/next-swc/crates/core/src/react_server_components.rs index 1435e38eafa3c..5cee5f7506af2 100644 --- a/packages/next-swc/crates/core/src/react_server_components.rs +++ b/packages/next-swc/crates/core/src/react_server_components.rs @@ -70,6 +70,7 @@ impl VisitMut for ReactServerComponents { self.assert_server_graph(&imports, module); } else { self.to_module_ref(module, is_cjs); + print!(""); return; } } else { diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js index cb1e0dcca1450..d7c578a3fd313 100644 --- a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js @@ -2,4 +2,6 @@ export default function () { return null } -;('use client') +export const runtime = 'edge' + +;'use client' diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js index 33997bb6e2495..59f77e82e957a 100644 --- a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js @@ -1,3 +1,4 @@ export default function() { return null; } +export const runtime = 'edge'; diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr index 8da2c69a3b137..86dcf13f25942 100644 --- a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr @@ -1,7 +1,7 @@ x NEXT_RSC_ERR_CLIENT_DIRECTIVE - ,-[input.js:4:1] - 4 | - 5 | 'use client' - : ^^^^^^^^^^^^ + ,-[input.js:6:1] + 6 | + 7 | ;'use client' + : ^^^^^^^^^^^^ `---- From 74b446ac0462079459d0bad024e6f22cd41f2a65 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 22 Aug 2023 19:06:49 +0200 Subject: [PATCH 4/6] prettier ignore --- .../server-graph/fake-client-entry/input.js | 3 +-- .../server-graph/fake-client-entry/output.js | 3 ++- .../server-graph/fake-client-entry/output.stderr | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js index d7c578a3fd313..7a23e34fac54b 100644 --- a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js @@ -2,6 +2,5 @@ export default function () { return null } -export const runtime = 'edge' - +// prettier-ignore ;'use client' diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js index 59f77e82e957a..837ce96b60db0 100644 --- a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js @@ -1,4 +1,5 @@ export default function() { return null; } -export const runtime = 'edge'; +// prettier-ignore +; diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr index 86dcf13f25942..1130328acd681 100644 --- a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr @@ -1,7 +1,7 @@ x NEXT_RSC_ERR_CLIENT_DIRECTIVE - ,-[input.js:6:1] - 6 | - 7 | ;'use client' + ,-[input.js:5:1] + 5 | // prettier-ignore + 6 | ;'use client' : ^^^^^^^^^^^^ `---- From b79e4d8684452d7142119eb6fc59761bd388164f Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 22 Aug 2023 19:14:45 +0200 Subject: [PATCH 5/6] fix lint --- .../server-graph/fake-client-entry/input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js index 7a23e34fac54b..43efcd92752b6 100644 --- a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/input.js @@ -3,4 +3,4 @@ export default function () { } // prettier-ignore -;'use client' +'use client' From 5c077205e9b003ba0fd6929a2d9108cf579640c6 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 22 Aug 2023 19:25:48 +0200 Subject: [PATCH 6/6] fix lint --- packages/next-swc/crates/core/src/react_server_components.rs | 1 - .../server-graph/fake-client-entry/output.js | 2 -- .../server-graph/fake-client-entry/output.stderr | 4 ++-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/next-swc/crates/core/src/react_server_components.rs b/packages/next-swc/crates/core/src/react_server_components.rs index 5cee5f7506af2..1435e38eafa3c 100644 --- a/packages/next-swc/crates/core/src/react_server_components.rs +++ b/packages/next-swc/crates/core/src/react_server_components.rs @@ -70,7 +70,6 @@ impl VisitMut for ReactServerComponents { self.assert_server_graph(&imports, module); } else { self.to_module_ref(module, is_cjs); - print!(""); return; } } else { diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js index 837ce96b60db0..33997bb6e2495 100644 --- a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.js @@ -1,5 +1,3 @@ export default function() { return null; } -// prettier-ignore -; diff --git a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr index 1130328acd681..4c7a3a110b70a 100644 --- a/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr +++ b/packages/next-swc/crates/core/tests/errors/react-server-components/server-graph/fake-client-entry/output.stderr @@ -2,6 +2,6 @@ x NEXT_RSC_ERR_CLIENT_DIRECTIVE ,-[input.js:5:1] 5 | // prettier-ignore - 6 | ;'use client' - : ^^^^^^^^^^^^ + 6 | 'use client' + : ^^^^^^^^^^^^ `----