From 151889572851a3179eadb72281e7cdeadc3f4953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 14 May 2024 01:31:36 +0900 Subject: [PATCH] fix(next-swc): Fix SWC env target - include option (#65693) ### What? Enable private properties pass correctly. ### Why? To allow using private properties with brand checking ### How? Closes PACK-3059 --------- Co-authored-by: Jiachi Liu --- .../src/transforms/cjs_optimizer.rs | 2 +- packages/next/src/build/swc/options.ts | 5 +---- .../app-dir/ecmascript-features/webpack/app/page.tsx | 10 ++++------ .../webpack/ecmascript-features-webpack.test.ts | 4 ++-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/packages/next-swc/crates/next-custom-transforms/src/transforms/cjs_optimizer.rs b/packages/next-swc/crates/next-custom-transforms/src/transforms/cjs_optimizer.rs index a94a1f3ed8edf..69f1553c4c34b 100644 --- a/packages/next-swc/crates/next-custom-transforms/src/transforms/cjs_optimizer.rs +++ b/packages/next-swc/crates/next-custom-transforms/src/transforms/cjs_optimizer.rs @@ -131,7 +131,7 @@ impl VisitMut for CjsOptimizer { definite: false, }; - if !self.data.extra_stmts.clone().into_iter().any(|s| { + if !self.data.extra_stmts.iter().any(|s| { if let Stmt::Decl(Decl::Var(v)) = &s { v.decls.iter().any(|d| d.name == var.name) } else { diff --git a/packages/next/src/build/swc/options.ts b/packages/next/src/build/swc/options.ts index a47a55c6de992..aa32bb389f98a 100644 --- a/packages/next/src/build/swc/options.ts +++ b/packages/next/src/build/swc/options.ts @@ -438,10 +438,7 @@ export function getLoaderSWCOptions({ isPageFile, env: { // Workaround acorn issues - include: [ - 'transform-private-methods', - 'transform-private-property-in-object', - ], + include: ['transform-class-properties'], targets: { // Targets the current version of Node.js node: process.versions.node, diff --git a/test/e2e/app-dir/ecmascript-features/webpack/app/page.tsx b/test/e2e/app-dir/ecmascript-features/webpack/app/page.tsx index b624643b3c841..2900b2de8b4d8 100644 --- a/test/e2e/app-dir/ecmascript-features/webpack/app/page.tsx +++ b/test/e2e/app-dir/ecmascript-features/webpack/app/page.tsx @@ -33,10 +33,9 @@ class ClassWithPrivate { getPrivateStaticMethod() { return ClassWithPrivate.#privateStaticMethod() } - // TODO: Not supported in webpack yet. - // isPrivateMethodAvailable() { - // return #privateField in this - // } + isPrivateMethodAvailable() { + return #privateField in this + } } // Not supported in Node.js yet. @@ -57,8 +56,7 @@ export default function Page() { privateStaticFieldWithInitializer: instance.getPrivateStaticFieldWithInitializer(), privateStaticMethod: instance.getPrivateStaticMethod(), - // TODO: Not supported in webpack yet. - // privateMethodInThis: instance.isPrivateMethodAvailable(), + privateMethodInThis: instance.isPrivateMethodAvailable(), exportAs: abc, importWith: json.message, // Not supported in Node.js yet. diff --git a/test/e2e/app-dir/ecmascript-features/webpack/ecmascript-features-webpack.test.ts b/test/e2e/app-dir/ecmascript-features/webpack/ecmascript-features-webpack.test.ts index 10fbb02432f23..0f9000eeaf397 100644 --- a/test/e2e/app-dir/ecmascript-features/webpack/ecmascript-features-webpack.test.ts +++ b/test/e2e/app-dir/ecmascript-features/webpack/ecmascript-features-webpack.test.ts @@ -14,7 +14,7 @@ import { nextTestSetup } from 'e2e-utils' privateFieldWithInitializer: 11, privateStaticFieldWithInitializer: 12, privateStaticMethod: 12, - // privateMethodInThis: true, + privateMethodInThis: true, exportAs: 1, // regex: true, importWith: 'Hello World', @@ -37,7 +37,7 @@ import { nextTestSetup } from 'e2e-utils' privateFieldWithInitializer: 11, privateStaticFieldWithInitializer: 12, privateStaticMethod: 12, - // privateMethodInThis: true, + privateMethodInThis: true, exportAs: 1, // regex: true, importWith: 'Hello World',