Skip to content

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

Closed
@millimoose

Description

@millimoose

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions