Skip to content

Compiler inlines arrow function definition #81898

@stefan-schubert-sbb

Description

@stefan-schubert-sbb

Link to the code that reproduces this issue

https://github.com/stefan-schubert-sbb/compiles-wrong

To Reproduce

This code:

  const o = {
    func() {
      console.log('This is a function');
    },
    func2() {
      const bound = () => this.func();
      return {
        hu() {
          console.log('This is a nested function');
          bound();
        },
      };
    },
  };

is compiled wrong in export mode.

Current vs. Expected behavior

This code:

  const o = {
    func() {
      console.log('This is a function');
    },
    func2() {
      const bound = () => this.func();
      return {
        hu() {
          console.log('This is a nested function');
          bound();
        },
      };
    },
  };

is compiled to in version 15.4.2:

        let e = {
          func() {
            console.log('This is a function');
          },
          func2: () => ({
            hu() {
              console.log('This is a nested function'), this.func();
            },
          }),
        };

which is wrong.

Version 15.3.5 compiles:

        let e = {
          func() {
            console.log('This is a function');
          },
          func2() {
            let e = () => this.func();
            return {
              hu() {
                console.log('This is a nested function'), e();
              },
            };
          },
        };

which is correct.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:29 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6030
  Available memory (MB): 36864
  Available CPU cores: 11
Binaries:
  Node: 22.15.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.11.1
Relevant Packages:
  next: 15.4.2-canary.10 // Latest available version is detected (15.4.2-canary.10).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: export

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

SWC

swc-project/swc#10825 fixes this issue

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

next build (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    SWCRelated to minification/transpilation in Next.js.locked

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions