newoga / babel-plugin-transform-replace-object-assign

Allows you to provide custom implementation of Object.assign in babel builds
MIT License
12 stars 2 forks source link

Unnecessary Babel require default interop helpers #10

Open jaydenseric opened 3 years ago

jaydenseric commented 3 years ago

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.

newoga commented 3 years ago

@jaydenseric That makes sense to me!