diff options
author | 2021-12-15 15:16:24 -0800 | |
---|---|---|
committer | 2021-12-15 15:16:24 -0800 | |
commit | a6ec858750a8a4c19b0bc94ecec00955f8b523c4 (patch) | |
tree | cee71a34d7739ec39a20c78a4852b53a018963b7 /src | |
parent | ba100fa9dcef2404b6186709ad4dbacb54277f22 (diff) | |
download | bun-a6ec858750a8a4c19b0bc94ecec00955f8b523c4.tar.gz bun-a6ec858750a8a4c19b0bc94ecec00955f8b523c4.tar.zst bun-a6ec858750a8a4c19b0bc94ecec00955f8b523c4.zip |
[JS transpiler] Simplify CommonJS interop callback
Diffstat (limited to 'src')
-rw-r--r-- | src/runtime.js | 130 | ||||
-rw-r--r-- | src/runtime.version | 2 |
2 files changed, 65 insertions, 67 deletions
diff --git a/src/runtime.js b/src/runtime.js index 1e86ef3b6..200f178ca 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -54,83 +54,81 @@ export var __toModule = (module) => { var tagSymbol = Symbol("CommonJSTransformed"); var cjsRequireSymbol = Symbol("CommonJS"); export var __commonJS = (cb, name) => { - var mod = {}; + var mod; var has_run = false; const requireFunction = function load() { if (has_run) { return mod.exports; } - has_run = true; - - mod = { exports: {} }; - cb(mod, mod.exports); + has_run = true; + cb(((mod = { exports: {} }), mod), mod.exports); const kind = typeof mod.exports; - if ( - (kind === "function" || kind === "object") && - "__esModule" in mod.exports && - !mod.exports[tagSymbol] - ) { - if (!("default" in mod.exports)) { - Object.defineProperty(mod.exports, "default", { - get() { - return mod.exports; - }, - set(v) { - mod.exports = v; - }, - enumerable: true, - configurable: true, - }); - } - } else if ( - kind === "object" && - "default" in mod.exports && - !mod.exports[tagSymbol] && - Object.keys(mod.exports).length === 1 - ) { - // if mod.exports.default === true this won't work because we can't define a property on a boolean - if ( - typeof mod.exports.default === "object" || - typeof mod.exports.default === "function" - ) { - mod.exports = mod.exports.default; - - Object.defineProperty(mod.exports, "default", { - get() { - return mod.exports; - }, - set(v) { - mod.exports = v; - }, - enumerable: true, - configurable: true, - }); - } - - // If it's a namespace export without .default, pretend .default is the same as mod.exports - } else if ( - (kind === "function" || kind === "object") && - !("default" in mod.exports) && - Object.isExtensible(mod.exports) - ) { - var defaultValue = mod.exports; - Object.defineProperty(mod.exports, "default", { - get() { - return defaultValue; - }, - set(value) { - defaultValue = value; - }, - enumerable: true, - configurable: true, - }); - } + // if ( + // (kind === "function" || kind === "object") && + // "__esModule" in mod.exports && + // !mod.exports[tagSymbol] + // ) { + // if (!("default" in mod.exports)) { + // Object.defineProperty(mod.exports, "default", { + // get() { + // return mod.exports; + // }, + // set(v) { + // mod.exports = v; + // }, + // enumerable: true, + // configurable: true, + // }); + // } + // } else if ( + // kind === "object" && + // "default" in mod.exports && + // !mod.exports[tagSymbol] && + // Object.keys(mod.exports).length === 1 + // ) { + // // if mod.exports.default === true this won't work because we can't define a property on a boolean + // if ( + // typeof mod.exports.default === "object" || + // typeof mod.exports.default === "function" + // ) { + // mod.exports = mod.exports.default; + + // Object.defineProperty(mod.exports, "default", { + // get() { + // return mod.exports; + // }, + // set(v) { + // mod.exports = v; + // }, + // enumerable: true, + // configurable: true, + // }); + // } + + // // If it's a namespace export without .default, pretend .default is the same as mod.exports + // } else if ( + // (kind === "function" || kind === "object") && + // !("default" in mod.exports) && + // Object.isExtensible(mod.exports) + // ) { + // var defaultValue = mod.exports; + // Object.defineProperty(mod.exports, "default", { + // get() { + // return defaultValue; + // }, + // set(value) { + // defaultValue = value; + // }, + // enumerable: true, + // configurable: true, + // }); + // } if ( - kind === "object" && + (kind === "object" || kind === "function") && !mod.exports[tagSymbol] && Object.isExtensible(mod.exports) ) { diff --git a/src/runtime.version b/src/runtime.version index 66b29714a..a2d50cf8a 100644 --- a/src/runtime.version +++ b/src/runtime.version @@ -1 +1 @@ -4decc1484daa0fb4
\ No newline at end of file +b63df695723aa470
\ No newline at end of file |