Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name conflict between JS keywords and generated function names when transpiling classes to ES5 #34831

Closed
robinWongM opened this issue Oct 30, 2019 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@robinWongM
Copy link

TypeScript 3.6.3
Playground link

Compiler Options:

{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "experimentalDecorators": false,
    "emitDecoratorMetadata": false,
    "target": "ES5",
    "module": "ESNext"
  }
}

Input:

let exports: any;
exports.default = class {
    constructor() {
        // do nothing
    }
}

Output:

"use strict";
var exports;
exports.default = /** @class */ (function () {
    function default() {
        // do nothing
    }
    return default;
}());

Expected behavior:
The function name should be replaced when it might be invalid. In the above example, default is not a valid function name and function default() will throw an error in the browser.

@a-tarasyuk
Copy link
Contributor

Duplicate of #26325

@RyanCavanaugh RyanCavanaugh added Duplicate An existing issue was already created and removed Bug A bug in TypeScript labels Jul 20, 2020
@RyanCavanaugh RyanCavanaugh removed this from the TypeScript 4.0.1 milestone Jul 20, 2020
@RyanCavanaugh
Copy link
Member

Thanks @a-tarasyuk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants