Skip to content

Commit

Permalink
fix(next-swc): Fix SWC env target - include option (#65693)
Browse files Browse the repository at this point in the history
### What?

Enable private properties pass correctly.

### Why?

To allow using private properties with brand checking

### How?

Closes PACK-3059

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
  • Loading branch information
kdy1 and huozhi authored May 13, 2024
1 parent c1f8d93 commit 1518895
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions packages/next/src/build/swc/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions test/e2e/app-dir/ecmascript-features/webpack/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit 1518895

Please sign in to comment.