Skip to content

"const" was transformed to "var" when target is "esnext"Β #59877

Open

Description

@Roise-yue

πŸ”Ž Search Terms

transform, const, var, target, ECMA, esnext

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried from Version 5.4 to Version 5.7.0-dev.20240904

⏯ Playground Link

No response

πŸ’» Code

export const cilBlurLinear : string [ ] = [  ,  ] 
const [ ,  ] = cilBlurLinear;

πŸ™ Actual behavior

The JS code generated by tsc is as follows:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cilBlurLinear = void 0;
exports.cilBlurLinear = [,];
var ;

πŸ™‚ Expected behavior

β€œconst” should be translated as "const" instead of "var", as the target in my configuration file is "esnext".

Additional information about the issue

tsconfig.json:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "esnext",
    "moduleResolution": "Node",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "lib": ["es2023","dom"],
    "noEmitOnError":true,
    "force":true,
    "strict":true
  },
  "include": [
    "TScorpus/*"
  ],
  "exclude": [
    "node_modules"
  ]
}

Activity

  1. MartinJohns commented on Sep 6, 2024

    @MartinJohns
    Contributor

    You are using the compiler wrong. You're calling the compiler by passing a list of filenames, in which case your local tsconfig.json is not being used and the compiler uses the default values for the compiler options.

    If you call the compiler correctly, your code would not even compiler due to two errors:

    • force is not a valid value for your tsconfig.json, it can only be used on the CLI together with --build.
    • const cilBlurLinear : string [ ] = [ , ] is not valid with strictNullChecks enabled, because [,] contains undefined.
  2. Roise-yue commented on Sep 6, 2024

    @Roise-yue
    Author

    You are using the compiler wrong. You're calling the compiler by passing a list of filenames, in which case your local tsconfig.json is not being used and the compiler uses the default values for the compiler options.

    If you call the compiler correctly, your code would not even compiler due to two errors:

    • force is not a valid value for your tsconfig.json, it can only be used on the CLI together with --build.
    • const cilBlurLinear : string [ ] = [ , ] is not valid with strictNullChecks enabled, because [,] contains undefined.

    Okay, I understand. I will modify the way I run the program.

  3. RyanCavanaugh commented on Sep 6, 2024

    @RyanCavanaugh
    Member

    We still shouldn't emit var; in ES5 though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JS EmitThe issue relates to the emission of JavaScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions