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

Using export-as emits __importStar and related helpers when importHelpers: true #37113

Closed
millimoose opened this issue Feb 28, 2020 · 3 comments · Fixed by #39490
Closed

Using export-as emits __importStar and related helpers when importHelpers: true #37113

millimoose opened this issue Feb 28, 2020 · 3 comments · Fixed by #39490
Assignees
Labels
Bug A bug in TypeScript Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@millimoose
Copy link

TypeScript Version: Version 3.9.0-dev.20200228

Search Terms:

export as importhelpers
export as importstar
export as helper

Code

export * as _ from 'lodash-es';

compiled with the following configuration:

{
  "compilerOptions": {
    "target": "es2020",
    "module": "commonjs",
    "importHelpers": true,
    "esModuleInterop": true
  }
}

Expected behavior:

The output should be the same as if compiling the equivalent older TS:

import * as _ from 'lodash-es';
export {_}

i.e. the compiled Javascript should be:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
// export * as _ from 'lodash-es';
const _ = tslib_1.__importStar(require("lodash-es"));
exports._ = _;

Actual behavior:

The helper functions are emitted:

"use strict";
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = __importStar(require("lodash-es"));

Playground Link:

The Typescript Playground doesn't support importHelpers, and the analogue noEmitHelpers doesn't cause this behaviour; I don't believe it's possible to reproduce this issue using the Playground.

Related Issues:

The similar issues search pointed me at #21560 and #27415 which also mention import helpers being inlined in different edge cases. Seeing as export-as isn't a dynamic import, and the older issue related to regular imports is closed, this seems to be a different, possibly related issue.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Mar 10, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.9.1 milestone Mar 10, 2020
@lotz
Copy link

lotz commented May 13, 2020

The "__setModuleDefault" helper is causing this error for me:

TypeError: Cannot redefine property: default

I did not encounter this under 3.8.

@KevinGruber
Copy link

@lotz same for me with the module cross-fetch
Started with 3.9.2

I fixed it by named importing fetch as it is also named exported not only default exported.

@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label May 20, 2020
@rbuckton rbuckton added Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Jul 7, 2020
@rbuckton
Copy link
Member

rbuckton commented Jul 7, 2020

We should be treating export * as ns from ... the same as import * as ns from ... in collectExternalModuleInfo. I should have a fix up shortly.

@lotz: I'm not certain whether your issue is related, and may have been fixed by #38808. Can you verify whether that is the case, and if not, can you provide a specific repro for your case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants