Skip to content

Issue in import variable name generation during compilation due to downleveling and hoisting #976

@Indy-rbo

Description

@Indy-rbo

Description

Due to the downleveling of const/let to var, the behavior of the variable declarations change because of Hoisting. This can clash with the generated name of an import:

Image Image

I have attached a reproduction. Sorry if it feels a bit contrived, but we have ran into this error a few times in our large codebase.

Steps to Reproduce

transpilerBugReproduction.zip

  1. Download reproduction
  2. Run mvn test
  3. See error thrown during test execution

Preconditions:

  • There should be an import that generates a VROES.importLazy(...)
  • Define 2 variable names that match the name of an imported file (e.g. import a "Logger" and define 2 variables named "logger" in if statements.
  • The variables should be inside their own scope (e.g. an action importing an exported function)

Expected behavior: To correctly transpile, without scoping issues

Actual behavior: An error is thrown during execution of the code: TypeError: Cannot read properties of undefined (reading '_')

Reproduces how often: 100%

Component/s: typescript/vrotsc or ecmascript(?)

Affects Build/s: 4.15.0 and below (haven't tested all versions)

Environment

Client

  • Build Tools for VMware Aria Version: 4.15.0

Dependencies

✔ Node.js version 22.21.1 is within the required range (22 - 22).
✔ Maven version 3.9.11 meets the minimum requirement (>= 3.9).
✔ Java version 21.0.9 is within the required range (17 - 21).

Failure Logs

[INFO] Installing node modules for the tests completed.
[INFO] Starting unit tests.
[ERROR] Error occurred in unit tests execution:   successful run
[ERROR]     TypeError: Cannot read properties of undefined (reading '_')
[ERROR]         at Object.subAction (C:\Users\johnd\repo\example_codebase\transpilerBugReproduction\target\vro-tests\src\com\example\service\transpilerBugReproduction\mySubAction.js:7:111)
[ERROR]     at module.exports (C:\Users\johnd\repo\example_codebase\transpilerBugReproduction\target\vro-tests\src\com\example\service\transpilerBugReproduction\myLargerAction.js:5:594)
[ERROR]     at s.<computed> (C:\Users\johnd\repo\example_codebase\transpilerBugReproduction\target\vro-tests\helpers\vro-runtime.js:1:34354)
[ERROR]     at UserContext.<anonymous> (C:\Users\johnd\repo\example_codebase\transpilerBugReproduction\target\vro-tests\test\com\example\service\transpilerBugReproduction\tests\myLargerAction.test.js:4:22)
[ERROR]     at <Jasmine>

Additional Context

We can prevent (most of) this issue ourselves by enabling the no-shadow rule in typescript-eslint. But other users might still run into this issue without a clear reason why.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/vrotscRelates to `vrotsc` modulekind/bugSomething isn't workinglang/typescriptRelated to typescript codetriage/neededNeeds to be discussed by project maintainersversion/patchThe change is a non-breaking bugfix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions