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

Emitted__exportStar helper has missing ; which causes runtime error #38501

Closed
alan-agius4 opened this issue May 12, 2020 · 6 comments · Fixed by #38502
Closed

Emitted__exportStar helper has missing ; which causes runtime error #38501

alan-agius4 opened this issue May 12, 2020 · 6 comments · Fixed by #38502
Assignees
Labels
Bug A bug in TypeScript

Comments

@alan-agius4
Copy link
Contributor

alan-agius4 commented May 12, 2020

TypeScript Version: 3.9.1-rc

Search Terms:
__exportStar
export star

Code
Input

export *  from './test';

Output

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
} /* There is a missing semi-colon here */
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "./test"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    __exportStar(require("./test"), exports);
});

When module target is configured UMD and helpers are emitted. The __exportStar unnamed function declaration has a missing ;, which causes an error during runtime Uncaught TypeError: (intermediate value)(…) is not a function

Expected behavior:
A semi-colon is added after the unnamed __exportStar function declaration.
Actual behavior:
A semi-colon is missing from the output which cause a runtime error.

Playground Link: https://www.typescriptlang.org/play/?module=3&ts=4.0.0-dev.20200511&ssl=2&ssc=18&pln=2&pc=1#code/KYDwDg9gTgLgBAKjgMyhAtnA5AOgPQzADOMWA3AFBA

alan-agius4 added a commit to alan-agius4/TypeScript that referenced this issue May 12, 2020
alan-agius4 added a commit to alan-agius4/TypeScript that referenced this issue May 12, 2020
alan-agius4 added a commit to alan-agius4/TypeScript that referenced this issue May 12, 2020
alan-agius4 added a commit to alan-agius4/TypeScript that referenced this issue May 12, 2020
alan-agius4 added a commit to petebacondarwin/angular that referenced this issue May 12, 2020
This is a workaround for a TS 3.9 regression microsoft/TypeScript#38501
As good citezens most of our users will be using `importHelpers` anyways, to avoid emitting typescript helpers multiple times
alan-agius4 added a commit to petebacondarwin/angular that referenced this issue May 12, 2020
This is a workaround for a TS 3.9 regression microsoft/TypeScript#38501
As good citizens most of our users will be using `importHelpers` anyways, to avoid emitting typescript helpers multiple times
alan-agius4 added a commit to petebacondarwin/angular that referenced this issue May 12, 2020
This is a workaround for a TS 3.9 regression microsoft/TypeScript#38501 where the emitted `__exportStar` helpers have a missing semi-colon at the end of the unnamed function, when targetting UMD, and causes the following runtime error `Uncaught TypeError: (intermediate value)(…) is not a function`.

This is because the anonymous `__exportStar` function will be invoked with the function on the next like as the parameter which is subsequently invoking whatever was returned.

To get around this TS bug, add `importHelpers: true` in your tsconfig. This also, is recommanded to avoid multiple copies of the same helper being inlined, which might cause increase in bundle size.
petebacondarwin pushed a commit to petebacondarwin/angular that referenced this issue May 12, 2020
This is a workaround for a TS 3.9 regression microsoft/TypeScript#38501 where the emitted `__exportStar` helpers have a missing semi-colon at the end of the unnamed function, when targetting UMD, and causes the following runtime error `Uncaught TypeError: (intermediate value)(…) is not a function`.

This is because the anonymous `__exportStar` function will be invoked with the function on the next like as the parameter which is subsequently invoking whatever was returned.

To get around this TS bug, add `importHelpers: true` in your tsconfig. This also, is recommanded to avoid multiple copies of the same helper being inlined, which might cause increase in bundle size.
@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label May 12, 2020
@DanielRosenwasser
Copy link
Member

Please port the change to tslib

@alan-agius4
Copy link
Contributor Author

On it @DanielRosenwasser

@DanielRosenwasser
Copy link
Member

Sorry, no, I didn't mean to ask you! Though I just made the change as well! 😅

@alan-agius4
Copy link
Contributor Author

alan-agius4 commented May 12, 2020

@DanielRosenwasser, I did the change to tslib microsoft/tslib#101 though that shouldn't have any effect, since it's not followed by immediate function call.

@DanielRosenwasser
Copy link
Member

Thanks @alan-agius4!

petebacondarwin pushed a commit to petebacondarwin/angular that referenced this issue May 13, 2020
This is a workaround for a TS 3.9 regression microsoft/TypeScript#38501 where the emitted `__exportStar` helpers have a missing semi-colon at the end of the unnamed function, when targetting UMD, and causes the following runtime error `Uncaught TypeError: (intermediate value)(…) is not a function`.

This is because the anonymous `__exportStar` function will be invoked with the function on the next like as the parameter which is subsequently invoking whatever was returned.

To get around this TS bug, add `importHelpers: true` in your tsconfig. This also, is recommanded to avoid multiple copies of the same helper being inlined, which might cause increase in bundle size.
petebacondarwin pushed a commit to petebacondarwin/angular that referenced this issue May 13, 2020
This is a workaround for a TS 3.9 regression microsoft/TypeScript#38501 where the emitted `__exportStar` helpers have a missing semi-colon at the end of the unnamed function, when targetting UMD, and causes the following runtime error `Uncaught TypeError: (intermediate value)(…) is not a function`.

This is because the anonymous `__exportStar` function will be invoked with the function on the next like as the parameter which is subsequently invoking whatever was returned.

To get around this TS bug, add `importHelpers: true` in your tsconfig. This also, is recommanded to avoid multiple copies of the same helper being inlined, which might cause increase in bundle size.
IgorMinar pushed a commit to petebacondarwin/angular that referenced this issue May 14, 2020
This is a workaround for a TS 3.9 regression microsoft/TypeScript#38501 where the emitted `__exportStar` helpers have a missing semi-colon at the end of the unnamed function, when targetting UMD, and causes the following runtime error `Uncaught TypeError: (intermediate value)(…) is not a function`.

This is because the anonymous `__exportStar` function will be invoked with the function on the next like as the parameter which is subsequently invoking whatever was returned.

To get around this TS bug, add `importHelpers: true` in your tsconfig. This also, is recommanded to avoid multiple copies of the same helper being inlined, which might cause increase in bundle size.
kara pushed a commit to angular/angular that referenced this issue May 14, 2020
This is a workaround for a TS 3.9 regression microsoft/TypeScript#38501 where the emitted `__exportStar` helpers have a missing semi-colon at the end of the unnamed function, when targetting UMD, and causes the following runtime error `Uncaught TypeError: (intermediate value)(…) is not a function`.

This is because the anonymous `__exportStar` function will be invoked with the function on the next like as the parameter which is subsequently invoking whatever was returned.

To get around this TS bug, add `importHelpers: true` in your tsconfig. This also, is recommanded to avoid multiple copies of the same helper being inlined, which might cause increase in bundle size.

PR Close #36989
@DanielRosenwasser
Copy link
Member

Should be fixed now

profanis pushed a commit to profanis/angular that referenced this issue Sep 5, 2020
This is a workaround for a TS 3.9 regression microsoft/TypeScript#38501 where the emitted `__exportStar` helpers have a missing semi-colon at the end of the unnamed function, when targetting UMD, and causes the following runtime error `Uncaught TypeError: (intermediate value)(…) is not a function`.

This is because the anonymous `__exportStar` function will be invoked with the function on the next like as the parameter which is subsequently invoking whatever was returned.

To get around this TS bug, add `importHelpers: true` in your tsconfig. This also, is recommanded to avoid multiple copies of the same helper being inlined, which might cause increase in bundle size.

PR Close angular#36989
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants