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

Inlined helpers generate undeclarated references #35108

Closed
manucorporat opened this issue Nov 14, 2019 · 2 comments
Closed

Inlined helpers generate undeclarated references #35108

manucorporat opened this issue Nov 14, 2019 · 2 comments
Assignees
Labels
Duplicate An existing issue was already created

Comments

@manucorporat
Copy link

manucorporat commented Nov 14, 2019

Seems like this issue was introduced at some point in 3.6.x, since it was working fine in 3.5.3.

TypeScript Version: 3.6.3 and Nightly

Search Terms: helpers name conflict

Code

// Helpers come from a bundled dependency
function __awaiter() { }

// The generated code, references a non-existing __awaiter_1
async function func() {
}

Expected behavior:

The generated helpers declarations include an "id" to prevent the name conflict, and the references to the helpers point to the new name.

var __awaiter_1 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    // ...
};
function __awaiter() { }
function func() {
    return __awaiter_1(this, void 0, void 0, function* () {
    });
}

Actual behavior:

Typescript emits the helper with the same name (__awaiter) causing a name conflict with existing declarations, but the emitted references point to __awaiter_1, generating in fact, JS that errors at runtime, with "__awaiter_1 is undeclarated".

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    // ...
};
function __awaiter() { }
function func() {
    return __awaiter_1(this, void 0, void 0, function* () {
    });
}

Playground Link: https://www.typescriptlang.org/play/index.html?target=3&ts=3.6.3#code/PTAEBUAsEsGdQMYHsC2BTeAzATq0BDUAIwFcA7AEwBs0LQK0AHNSlhATwChNyEAXaEjKgA+iPwB3fND5psACgCUoAN6gAvp04gIkNKADmLOfll1kDADShsaTHLYYCoMkIC0aAB5wBZA6PEpGTkRAEZOfFh2MgRQHhiBITjeJVVOTSA

@manucorporat
Copy link
Author

manucorporat commented Nov 14, 2019

I want to point out that the conflict with inlined ts helpers comes after bundling dependencies that already have the helpers inlined, so it's not really up to the user to prevent the conflict by choosing a different function name.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: JS Emit The issue relates to the emission of JavaScript labels Nov 14, 2019
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.8.0 milestone Nov 14, 2019
@RyanCavanaugh RyanCavanaugh added Duplicate An existing issue was already created and removed Bug A bug in TypeScript Domain: JS Emit The issue relates to the emission of JavaScript labels Jan 24, 2020
@RyanCavanaugh
Copy link
Member

Duplicate #33547

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