Skip to content

Unnecessary Babel require default interop helpers #10

@jaydenseric

Description

@jaydenseric

When the Babel sourceType is script (CJS), this plugin unessesarily creates _interopRequireDefault in the output.

For example, this input:

Object.assign({});

Results in this output:

var _default = _interopRequireDefault(require("object-assign")).default;

function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

_default({});

When output more like this would be better:

var _default = require("object-assign");

_default({});

The object-assign package (along with others a user might specify using the moduleSpecifier option) doesn't require any default interop:

https://unpkg.com/object-assign@4.1.1/index.js

Perhaps we should add a new noInterop option, that behaves like the same for @babel/plugin-transform-modules-commonjs:

https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs#nointerop

It should default to true, to ensure optimal output when no options are provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions