Skip to content

[backport request] Backport fix of an already-fixed bug of next-swc #66085

@tjx666

Description

@tjx666

Link to the code that reproduces this issue

https://stackblitz.com/edit/nextjs-wzyqzn?file=app%2Fpage.tsx

To Reproduce

just open the stackblize online reproduce

Current vs. Expected behavior

class Father {
  static instance = {};

  static register() {
    return (target) => {
      class Wrapper extends target {
        constructor(props) {
          super({
            ...props,
          });
        }
      }

      this.instance = new Wrapper();
    };
  }

  private _a = 1;

  constructor() {
    this._a = 2;
  }
}

@Father.register()
class Son {}

console.log(Father.instance._a); // 1, but why ???
image image

expect

should compile correct

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: Ubuntu 20.04.0 LTS Wed May 22 2024 23:45:04 GMT+0800 (中国标准时间)
Binaries:
  Node: 18.20.3
  npm: 10.2.3
  Yarn: 1.22.19
  pnpm: 8.15.6
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 13.5.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

SWC

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

The latest canary version fix this issue, but I can find a good way to fix it now.

I want to use canary but it require react19.
I try use yarn1 resolution to lock the next swc version, but yarn1 seems can't correctly deal with resolution with optionalDependencies:

image

So, I thing the best method way to fix this is the nextjs official release a new 14.x version.

I think the compile error is a serious error and cost me one day to locate it.

more context:

  1. https://x.com/YuTengjing/status/1793270230531395826
  2. fix(es/compat): Handle class fields correctly swc-project/swc#8835

Metadata

Metadata

Assignees

No one assigned

    Labels

    SWCRelated to minification/transpilation in Next.js.bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions