diff --git a/packages/commonjs/src/helpers.js b/packages/commonjs/src/helpers.js index 930b709a3..2dbfd6e08 100644 --- a/packages/commonjs/src/helpers.js +++ b/packages/commonjs/src/helpers.js @@ -23,10 +23,6 @@ export const HELPERS_ID = '\0commonjsHelpers.js'; export const HELPERS = ` export var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; -export function unwrapExports (x) { - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; -} - export function createCommonjsModule(fn, basedir, module) { return module = { path: basedir, diff --git a/packages/commonjs/src/transform.js b/packages/commonjs/src/transform.js index 8b882767c..8af4547e2 100644 --- a/packages/commonjs/src/transform.js +++ b/packages/commonjs/src/transform.js @@ -642,9 +642,7 @@ export function transformCommonjs( } } - const defaultExport = /__esModule/.test(code) - ? `export default /*@__PURE__*/${HELPERS_NAME}.unwrapExports(${moduleName});` - : `export default ${moduleName};`; + const defaultExport = `export default ${moduleName};`; const named = namedExportDeclarations .filter((x) => x.name !== 'default' || !hasDefaultExport) diff --git a/packages/commonjs/test/snapshots/function.js.md b/packages/commonjs/test/snapshots/function.js.md index b1d428694..3339cee47 100644 --- a/packages/commonjs/test/snapshots/function.js.md +++ b/packages/commonjs/test/snapshots/function.js.md @@ -11,10 +11,6 @@ Generated by [AVA](https://ava.li). { 'main.js': `'use strict';␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -35,10 +31,8 @@ Generated by [AVA](https://ava.li). exports.answer = 42;␊ });␊ ␊ - var answer$1 = /*@__PURE__*/unwrapExports(answer);␊ - ␊ - var x = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.assign(/*#__PURE__*/Object.create(null), answer$1, {␊ - 'default': answer$1,␊ + var x = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.assign(/*#__PURE__*/Object.create(null), answer, {␊ + 'default': answer,␊ __moduleExports: answer␊ }));␊ ␊ @@ -263,10 +257,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -420,7 +410,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -466,10 +455,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -623,7 +608,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -665,10 +649,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -822,7 +802,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -883,10 +862,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -1040,7 +1015,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -1067,14 +1041,10 @@ Generated by [AVA](https://ava.li). > Snapshot 1 { - 'lib2-07a971d0.js': `'use strict';␊ + 'lib2-f863e9df.js': `'use strict';␊ ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -1228,7 +1198,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -1262,7 +1231,7 @@ Generated by [AVA](https://ava.li). `, 'main.js': `'use strict';␊ ␊ - var lib2 = require('./lib2-07a971d0.js');␊ + var lib2 = require('./lib2-f863e9df.js');␊ ␊ /* eslint-disable import/no-dynamic-require, global-require */␊ ␊ @@ -1279,7 +1248,7 @@ Generated by [AVA](https://ava.li). `, 'main2.js': `'use strict';␊ ␊ - require('./lib2-07a971d0.js');␊ + require('./lib2-f863e9df.js');␊ ␊ `, } @@ -1293,10 +1262,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -1450,7 +1415,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -1483,10 +1447,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -1640,7 +1600,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -1679,10 +1638,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -1836,7 +1791,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -1888,10 +1842,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -2045,7 +1995,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -2095,10 +2044,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -2252,7 +2197,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -2296,10 +2240,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -2453,7 +2393,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -2514,10 +2453,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -2671,7 +2606,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -2718,10 +2652,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -2875,7 +2805,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -2914,10 +2843,6 @@ Generated by [AVA](https://ava.li). ␊ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -3071,7 +2996,6 @@ Generated by [AVA](https://ava.li). var _commonjsHelpers = /*#__PURE__*/Object.freeze({␊ __proto__: null,␊ commonjsGlobal: commonjsGlobal,␊ - unwrapExports: unwrapExports,␊ createCommonjsModule: createCommonjsModule,␊ getCjsExportFromNamespace: getCjsExportFromNamespace,␊ commonjsRegister: commonjsRegister,␊ @@ -3551,10 +3475,6 @@ Generated by [AVA](https://ava.li). { 'main.js': `'use strict';␊ ␊ - function unwrapExports (x) {␊ - return x && !x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;␊ - }␊ - ␊ function createCommonjsModule(fn, basedir, module) {␊ return module = {␊ path: basedir,␊ @@ -3587,9 +3507,7 @@ Generated by [AVA](https://ava.li). exports.Bar = commonjsBar.default;␊ });␊ ␊ - var commonjsFoo$1 = /*@__PURE__*/unwrapExports(commonjsFoo);␊ - ␊ - t.is(new commonjsFoo$1.Bar().x, 42);␊ + t.is(new commonjsFoo.Bar().x, 42);␊ `, } diff --git a/packages/commonjs/test/snapshots/function.js.snap b/packages/commonjs/test/snapshots/function.js.snap index 05cdd2519..3a8b33c2c 100644 Binary files a/packages/commonjs/test/snapshots/function.js.snap and b/packages/commonjs/test/snapshots/function.js.snap differ