Skip to content

Commit

Permalink
remove unwrapExports entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Jun 23, 2020
1 parent 92166de commit bfc81b4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 95 deletions.
4 changes: 0 additions & 4 deletions packages/commonjs/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions packages/commonjs/src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
94 changes: 6 additions & 88 deletions packages/commonjs/test/snapshots/function.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,␊
Expand All @@ -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␊
}));␊
␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand All @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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 */␊
␊
Expand All @@ -1279,7 +1248,7 @@ Generated by [AVA](https://ava.li).
`,
'main2.js': `'use strict';␊
␊
require('./lib2-07a971d0.js');␊
require('./lib2-f863e9df.js');␊
␊
`,
}
Expand All @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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,␊
Expand Down Expand Up @@ -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);␊
`,
}

Expand Down
Binary file modified packages/commonjs/test/snapshots/function.js.snap
Binary file not shown.

0 comments on commit bfc81b4

Please sign in to comment.