Skip to content

[Compiler Bug]: Not handling named functions calling named functions when defined in a weird order #33689

@amcsi

Description

@amcsi

What kind of issue is this?

  • React Compiler core (the JS output is incorrect, or your app works incorrectly after optimization)
  • babel-plugin-react-compiler (build issue installing or using the Babel plugin)
  • eslint-plugin-react-compiler (build issue installing or using the eslint plugin)
  • react-compiler-healthcheck (build issue installing or using the healthcheck script)

Link to repro

https://playground.react.dev/#N4Igzg9grgTgxgUxALhAgHgBwjALgAgBMEAzAQygBsCSoA7OXASwjvwFkBPAQU0wAoAlPmAAdNvhgJcsNgB4AMkzoIAakzBQylJgC8yzVvjgALMngC8wYIQNlk+ANoBaAIwAafAAZPH-ACZPAGYAXQBfMPwAegA+AG5xMPFxOFYwAiUVdU1tPQMWNgt8fkwYCEwwYQsYkXF8YzSCYGMzPHxIotLysAS6Ooa6dJEiO3b8ItNzXF7+1MGCW1wEQnH8EiZqBBgAeShcAHUhGYlaBkM2dc2YADkEAHN8gDcEMH4mJYBbYTEJeqkZGBsd4ID69epJPoneiMAprDZLHZ7Q7ffp-aSyEa4MgAOkuCP4eK2twezGelTB7WSEn+GLkhCYjxiNgMy2xACsIMp+KIQJ4eYIwnIovTGb0wnEQGEgA

Repro steps

In a component assign to a variable the result of a named function call that's defined lower down in the code, that named function calling another named function that's defined higher up than it.
As per the above example, you would get this error (ignore the line numbers):

LineVisualization.js:15 Uncaught ReferenceError: Cannot access 'filterNegatives' before initialization
at filterOutW (LineVisualization.js:15:24)
at LineVisualization (LineVisualization.js:8:17)

How often does this bug happen?

Every time

What version of React are you using?

18.2.0

What version of React Compiler are you using?

19.1.0-rc.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions