diff --git a/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_0d348e.js b/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_0d348e.js index 916a1d88f0ba8..db9733134e271 100644 --- a/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_0d348e.js +++ b/crates/turbopack-tests/tests/snapshot/basic/async_chunk/output/crates_turbopack-tests_tests_snapshot_basic_async_chunk_input_index_0d348e.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/basic/chunked/output/crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_e77e9f.js b/crates/turbopack-tests/tests/snapshot/basic/chunked/output/crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_e77e9f.js index 394e9cd6a3c92..173fbd8a0df4e 100644 --- a/crates/turbopack-tests/tests/snapshot/basic/chunked/output/crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_e77e9f.js +++ b/crates/turbopack-tests/tests/snapshot/basic/chunked/output/crates_turbopack-tests_tests_snapshot_basic_chunked_input_index_e77e9f.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/basic/shebang/output/crates_turbopack-tests_tests_snapshot_basic_shebang_input_index_b1f0c2.js b/crates/turbopack-tests/tests/snapshot/basic/shebang/output/crates_turbopack-tests_tests_snapshot_basic_shebang_input_index_b1f0c2.js index c55960299665a..d264bfff485ec 100644 --- a/crates/turbopack-tests/tests/snapshot/basic/shebang/output/crates_turbopack-tests_tests_snapshot_basic_shebang_input_index_b1f0c2.js +++ b/crates/turbopack-tests/tests/snapshot/basic/shebang/output/crates_turbopack-tests_tests_snapshot_basic_shebang_input_index_b1f0c2.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/comptime/define/output/crates_turbopack-tests_tests_snapshot_comptime_define_input_index_6b0d2b.js b/crates/turbopack-tests/tests/snapshot/comptime/define/output/crates_turbopack-tests_tests_snapshot_comptime_define_input_index_6b0d2b.js index f9b9835708da4..8817feac25cd2 100644 --- a/crates/turbopack-tests/tests/snapshot/comptime/define/output/crates_turbopack-tests_tests_snapshot_comptime_define_input_index_6b0d2b.js +++ b/crates/turbopack-tests/tests/snapshot/comptime/define/output/crates_turbopack-tests_tests_snapshot_comptime_define_input_index_6b0d2b.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_fa9a30.js b/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_fa9a30.js index 037ed496da0c3..531535b77b56d 100644 --- a/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_fa9a30.js +++ b/crates/turbopack-tests/tests/snapshot/css/absolute-uri-import/output/crates_turbopack-tests_tests_snapshot_css_absolute-uri-import_input_index_fa9a30.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/css/css/output/crates_turbopack-tests_tests_snapshot_css_css_input_index_37a138.js b/crates/turbopack-tests/tests/snapshot/css/css/output/crates_turbopack-tests_tests_snapshot_css_css_input_index_37a138.js index 459bca8b742d4..32fa5a5a28427 100644 --- a/crates/turbopack-tests/tests/snapshot/css/css/output/crates_turbopack-tests_tests_snapshot_css_css_input_index_37a138.js +++ b/crates/turbopack-tests/tests/snapshot/css/css/output/crates_turbopack-tests_tests_snapshot_css_css_input_index_37a138.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/crates_turbopack-tests_tests_snapshot_emotion_emotion_input_index_b080c4.js b/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/crates_turbopack-tests_tests_snapshot_emotion_emotion_input_index_b080c4.js index b0c60112d28e8..b71f5dee25f96 100644 --- a/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/crates_turbopack-tests_tests_snapshot_emotion_emotion_input_index_b080c4.js +++ b/crates/turbopack-tests/tests/snapshot/emotion/emotion/output/crates_turbopack-tests_tests_snapshot_emotion_emotion_input_index_b080c4.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/env/env/output/crates_turbopack-tests_tests_snapshot_env_env_input_index_29a23f.js b/crates/turbopack-tests/tests/snapshot/env/env/output/crates_turbopack-tests_tests_snapshot_env_env_input_index_29a23f.js index f84168548fed5..c468aeed626e9 100644 --- a/crates/turbopack-tests/tests/snapshot/env/env/output/crates_turbopack-tests_tests_snapshot_env_env_input_index_29a23f.js +++ b/crates/turbopack-tests/tests/snapshot/env/env/output/crates_turbopack-tests_tests_snapshot_env_env_input_index_29a23f.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/evaluated_entrry/runtime_entry/output/a587c_tests_snapshot_evaluated_entrry_runtime_entry_input_index_f59cc7.js b/crates/turbopack-tests/tests/snapshot/evaluated_entrry/runtime_entry/output/a587c_tests_snapshot_evaluated_entrry_runtime_entry_input_index_f59cc7.js index 19fc0ee7a0d55..cb989e9281277 100644 --- a/crates/turbopack-tests/tests/snapshot/evaluated_entrry/runtime_entry/output/a587c_tests_snapshot_evaluated_entrry_runtime_entry_input_index_f59cc7.js +++ b/crates/turbopack-tests/tests/snapshot/evaluated_entrry/runtime_entry/output/a587c_tests_snapshot_evaluated_entrry_runtime_entry_input_index_f59cc7.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/example/example/output/crates_turbopack-tests_tests_snapshot_example_example_input_index_78b6bf.js b/crates/turbopack-tests/tests/snapshot/example/example/output/crates_turbopack-tests_tests_snapshot_example_example_input_index_78b6bf.js index 5ac6d84e68a2c..dafd2e36cb45a 100644 --- a/crates/turbopack-tests/tests/snapshot/example/example/output/crates_turbopack-tests_tests_snapshot_example_example_input_index_78b6bf.js +++ b/crates/turbopack-tests/tests/snapshot/example/example/output/crates_turbopack-tests_tests_snapshot_example_example_input_index_78b6bf.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_289ae7.js b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_289ae7.js index a239cceb94779..075dd39093cea 100644 --- a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_289ae7.js +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-2_input_index_289ae7.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_3e96b7.js b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_3e96b7.js index 9dd5ebbea4a14..13ca4d8c4c09e 100644 --- a/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_3e96b7.js +++ b/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/output/crates_turbopack-tests_tests_snapshot_export-alls_cjs-script_input_index_3e96b7.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/import-meta/cjs/output/crates_turbopack-tests_tests_snapshot_import-meta_cjs_input_index_537553.js b/crates/turbopack-tests/tests/snapshot/import-meta/cjs/output/crates_turbopack-tests_tests_snapshot_import-meta_cjs_input_index_537553.js index d83741d860569..5a03e655e0a4c 100644 --- a/crates/turbopack-tests/tests/snapshot/import-meta/cjs/output/crates_turbopack-tests_tests_snapshot_import-meta_cjs_input_index_537553.js +++ b/crates/turbopack-tests/tests/snapshot/import-meta/cjs/output/crates_turbopack-tests_tests_snapshot_import-meta_cjs_input_index_537553.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/output/79fb1_turbopack-tests_tests_snapshot_import-meta_esm-multiple_input_index_c00392.js b/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/output/79fb1_turbopack-tests_tests_snapshot_import-meta_esm-multiple_input_index_c00392.js index 80b721710ea0d..e294815d25980 100644 --- a/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/output/79fb1_turbopack-tests_tests_snapshot_import-meta_esm-multiple_input_index_c00392.js +++ b/crates/turbopack-tests/tests/snapshot/import-meta/esm-multiple/output/79fb1_turbopack-tests_tests_snapshot_import-meta_esm-multiple_input_index_c00392.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-mutable_input_index_6c9201.js b/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-mutable_input_index_6c9201.js index b36c24f7a6e56..e3779a398a985 100644 --- a/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-mutable_input_index_6c9201.js +++ b/crates/turbopack-tests/tests/snapshot/import-meta/esm-mutable/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-mutable_input_index_6c9201.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-object_input_index_6fcf7d.js b/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-object_input_index_6fcf7d.js index 8233e4814a106..0b065108c8544 100644 --- a/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-object_input_index_6fcf7d.js +++ b/crates/turbopack-tests/tests/snapshot/import-meta/esm-object/output/crates_turbopack-tests_tests_snapshot_import-meta_esm-object_input_index_6fcf7d.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/import-meta/esm/output/crates_turbopack-tests_tests_snapshot_import-meta_esm_input_index_c4c88a.js b/crates/turbopack-tests/tests/snapshot/import-meta/esm/output/crates_turbopack-tests_tests_snapshot_import-meta_esm_input_index_c4c88a.js index e03c2cdfaa464..113115928b8d8 100644 --- a/crates/turbopack-tests/tests/snapshot/import-meta/esm/output/crates_turbopack-tests_tests_snapshot_import-meta_esm_input_index_c4c88a.js +++ b/crates/turbopack-tests/tests/snapshot/import-meta/esm/output/crates_turbopack-tests_tests_snapshot_import-meta_esm_input_index_c4c88a.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/import-meta/url/output/crates_turbopack-tests_tests_snapshot_import-meta_url_input_index_988b57.js b/crates/turbopack-tests/tests/snapshot/import-meta/url/output/crates_turbopack-tests_tests_snapshot_import-meta_url_input_index_988b57.js index d431f339aa76f..4189b0df5380f 100644 --- a/crates/turbopack-tests/tests/snapshot/import-meta/url/output/crates_turbopack-tests_tests_snapshot_import-meta_url_input_index_988b57.js +++ b/crates/turbopack-tests/tests/snapshot/import-meta/url/output/crates_turbopack-tests_tests_snapshot_import-meta_url_input_index_988b57.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_index_45c162.js b/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_index_45c162.js index 39bda445e7700..1bd1bde9a1f0e 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_index_45c162.js +++ b/crates/turbopack-tests/tests/snapshot/imports/dynamic/output/crates_turbopack-tests_tests_snapshot_imports_dynamic_input_index_45c162.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_961ae2.js b/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_961ae2.js index febedb7a1671e..4d8909a4fa16c 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_961ae2.js +++ b/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_961ae2.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/imports/resolve_error_cjs/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_cjs_input_index_f8412b.js b/crates/turbopack-tests/tests/snapshot/imports/resolve_error_cjs/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_cjs_input_index_f8412b.js index 6861d2799df12..63a94d903f6ea 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/resolve_error_cjs/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_cjs_input_index_f8412b.js +++ b/crates/turbopack-tests/tests/snapshot/imports/resolve_error_cjs/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_cjs_input_index_f8412b.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/imports/resolve_error_esm/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_esm_input_index_0b3e45.js b/crates/turbopack-tests/tests/snapshot/imports/resolve_error_esm/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_esm_input_index_0b3e45.js index fe54717fd9086..b8d9a79092d06 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/resolve_error_esm/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_esm_input_index_0b3e45.js +++ b/crates/turbopack-tests/tests/snapshot/imports/resolve_error_esm/output/79fb1_turbopack-tests_tests_snapshot_imports_resolve_error_esm_input_index_0b3e45.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_index_ec8693.js b/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_index_ec8693.js index 97fc24e0ca1e7..2df87366b807d 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_index_ec8693.js +++ b/crates/turbopack-tests/tests/snapshot/imports/static-and-dynamic/output/79fb1_turbopack-tests_tests_snapshot_imports_static-and-dynamic_input_index_ec8693.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/imports/static/output/crates_turbopack-tests_tests_snapshot_imports_static_input_index_885269.js b/crates/turbopack-tests/tests/snapshot/imports/static/output/crates_turbopack-tests_tests_snapshot_imports_static_input_index_885269.js index 4e1484114ea43..b1493a776ef18 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/static/output/crates_turbopack-tests_tests_snapshot_imports_static_input_index_885269.js +++ b/crates/turbopack-tests/tests/snapshot/imports/static/output/crates_turbopack-tests_tests_snapshot_imports_static_input_index_885269.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/node/node_protocol_external/output/79fb1_turbopack-tests_tests_snapshot_node_node_protocol_external_input_index_667edf.js b/crates/turbopack-tests/tests/snapshot/node/node_protocol_external/output/79fb1_turbopack-tests_tests_snapshot_node_node_protocol_external_input_index_667edf.js index 9f4355661c02c..b829c5dc52e16 100644 --- a/crates/turbopack-tests/tests/snapshot/node/node_protocol_external/output/79fb1_turbopack-tests_tests_snapshot_node_node_protocol_external_input_index_667edf.js +++ b/crates/turbopack-tests/tests/snapshot/node/node_protocol_external/output/79fb1_turbopack-tests_tests_snapshot_node_node_protocol_external_input_index_667edf.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/output/a587c_tests_snapshot_styled_components_styled_components_input_index_afc482.js b/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/output/a587c_tests_snapshot_styled_components_styled_components_input_index_afc482.js index e85ea61e354b1..5a97786eaf754 100644 --- a/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/output/a587c_tests_snapshot_styled_components_styled_components_input_index_afc482.js +++ b/crates/turbopack-tests/tests/snapshot/styled_components/styled_components/output/a587c_tests_snapshot_styled_components_styled_components_input_index_afc482.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_app_index_4a3d65.js b/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_app_index_4a3d65.js index ca6fc450172f9..d402c7064d002 100644 --- a/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_app_index_4a3d65.js +++ b/crates/turbopack-tests/tests/snapshot/swc_transforms/mono_transforms/output/a587c_tests_snapshot_swc_transforms_mono_transforms_input_packages_app_index_4a3d65.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/79fb1_turbopack-tests_tests_snapshot_swc_transforms_preset_env_input_index_9dcfd0.js b/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/79fb1_turbopack-tests_tests_snapshot_swc_transforms_preset_env_input_index_9dcfd0.js index 677fa284349d5..70c6924f0c0b1 100644 --- a/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/79fb1_turbopack-tests_tests_snapshot_swc_transforms_preset_env_input_index_9dcfd0.js +++ b/crates/turbopack-tests/tests/snapshot/swc_transforms/preset_env/output/79fb1_turbopack-tests_tests_snapshot_swc_transforms_preset_env_input_index_9dcfd0.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/typescript/jsconfig-baseurl/output/79fb1_turbopack-tests_tests_snapshot_typescript_jsconfig-baseurl_input_index_8f1e58.js b/crates/turbopack-tests/tests/snapshot/typescript/jsconfig-baseurl/output/79fb1_turbopack-tests_tests_snapshot_typescript_jsconfig-baseurl_input_index_8f1e58.js index b28a4079e33e8..aaa42f08ebe8a 100644 --- a/crates/turbopack-tests/tests/snapshot/typescript/jsconfig-baseurl/output/79fb1_turbopack-tests_tests_snapshot_typescript_jsconfig-baseurl_input_index_8f1e58.js +++ b/crates/turbopack-tests/tests/snapshot/typescript/jsconfig-baseurl/output/79fb1_turbopack-tests_tests_snapshot_typescript_jsconfig-baseurl_input_index_8f1e58.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-baseurl/output/a587c_tests_snapshot_typescript_tsconfig-baseurl_input_index.ts_0aa04e._.js b/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-baseurl/output/a587c_tests_snapshot_typescript_tsconfig-baseurl_input_index.ts_0aa04e._.js index 3e6d3de2d0757..112d7f1b6742f 100644 --- a/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-baseurl/output/a587c_tests_snapshot_typescript_tsconfig-baseurl_input_index.ts_0aa04e._.js +++ b/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-baseurl/output/a587c_tests_snapshot_typescript_tsconfig-baseurl_input_index.ts_0aa04e._.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-module-full-path/output/8562f_snapshot_typescript_tsconfig-extends-module-full-path_input_index.ts_a751eb._.js b/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-module-full-path/output/8562f_snapshot_typescript_tsconfig-extends-module-full-path_input_index.ts_a751eb._.js index 450b0baadb759..85c9f0da20a4b 100644 --- a/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-module-full-path/output/8562f_snapshot_typescript_tsconfig-extends-module-full-path_input_index.ts_a751eb._.js +++ b/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-module-full-path/output/8562f_snapshot_typescript_tsconfig-extends-module-full-path_input_index.ts_a751eb._.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-module/output/a587c_tests_snapshot_typescript_tsconfig-extends-module_input_index.ts_a662d4._.js b/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-module/output/a587c_tests_snapshot_typescript_tsconfig-extends-module_input_index.ts_a662d4._.js index 4ebbfc0ed72b8..a78e01cdd362f 100644 --- a/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-module/output/a587c_tests_snapshot_typescript_tsconfig-extends-module_input_index.ts_a662d4._.js +++ b/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-module/output/a587c_tests_snapshot_typescript_tsconfig-extends-module_input_index.ts_a662d4._.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-relative-dir/output/a587c_tests_snapshot_typescript_tsconfig-extends-relative-dir_input_index.ts_be3d7b._.js b/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-relative-dir/output/a587c_tests_snapshot_typescript_tsconfig-extends-relative-dir_input_index.ts_be3d7b._.js index c1bdb70a703e0..208512f913284 100644 --- a/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-relative-dir/output/a587c_tests_snapshot_typescript_tsconfig-extends-relative-dir_input_index.ts_be3d7b._.js +++ b/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-relative-dir/output/a587c_tests_snapshot_typescript_tsconfig-extends-relative-dir_input_index.ts_be3d7b._.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-without-ext/output/a587c_tests_snapshot_typescript_tsconfig-extends-without-ext_input_index.ts_38aae8._.js b/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-without-ext/output/a587c_tests_snapshot_typescript_tsconfig-extends-without-ext_input_index.ts_38aae8._.js index 94019fce80e3e..ecaeaece1f7ea 100644 --- a/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-without-ext/output/a587c_tests_snapshot_typescript_tsconfig-extends-without-ext_input_index.ts_38aae8._.js +++ b/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends-without-ext/output/a587c_tests_snapshot_typescript_tsconfig-extends-without-ext_input_index.ts_38aae8._.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => { diff --git a/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends/output/a587c_tests_snapshot_typescript_tsconfig-extends_input_index.ts_18c083._.js b/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends/output/a587c_tests_snapshot_typescript_tsconfig-extends_input_index.ts_18c083._.js index 1887f627829bf..9beec3e43f705 100644 --- a/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends/output/a587c_tests_snapshot_typescript_tsconfig-extends_input_index.ts_18c083._.js +++ b/crates/turbopack-tests/tests/snapshot/typescript/tsconfig-extends/output/a587c_tests_snapshot_typescript_tsconfig-extends_input_index.ts_18c083._.js @@ -173,6 +173,17 @@ function createGetter(obj, key) { return () => obj[key]; } +/** + * @param {any} obj + * @returns {any} prototype of the object + */ +const getProto = Object.getPrototypeOf + ? (obj) => Object.getPrototypeOf(obj) + : (obj) => obj.__proto__; + +/** Prototypes that are not expanded for exports */ +const LEAF_PROTOTYPES = [null, getProto({}), getProto([]), getProto(getProto)]; + /** * @param {Exports} raw * @param {EsmNamespaceObject} ns @@ -181,8 +192,15 @@ function createGetter(obj, key) { function interopEsm(raw, ns, allowExportDefault) { /** @type {Object. any>} */ const getters = { __proto__: null }; - for (const key in raw) { - getters[key] = createGetter(raw, key); + for ( + let current = raw; + (typeof current === "object" || typeof current === "function") && + !LEAF_PROTOTYPES.includes(current); + current = getProto(current) + ) { + for (const key of Object.getOwnPropertyNames(current)) { + getters[key] = createGetter(raw, key); + } } if (!(allowExportDefault && "default" in getters)) { getters["default"] = () => raw; @@ -282,11 +300,11 @@ function externalRequire(id, esm) { // compilation error. throw new Error(`Failed to load external module ${id}: ${err}`); } - if (!esm || raw.__esModule) { + if (!esm) { return raw; } const ns = {}; - interopEsm(raw, ns, true); + interopEsm(raw, ns, raw.__esModule); return ns; } externalRequire.resolve = (name, opt) => {