diff --git a/ext/node/analyze.rs b/ext/node/analyze.rs index 0a02266254..ad38a511bb 100644 --- a/ext/node/analyze.rs +++ b/ext/node/analyze.rs @@ -86,7 +86,7 @@ impl NodeCodeTranslator { permissions: &dyn NodePermissions, ) -> Result { let mut temp_var_count = 0; - let mut handled_reexports: HashSet = HashSet::default(); + let mut handled_reexports: HashSet = HashSet::default(); let analysis = self.cjs_code_analyzer.analyze_cjs(specifier, source)?; @@ -114,12 +114,6 @@ impl NodeCodeTranslator { } while let Some((reexport, referrer)) = reexports_to_handle.pop_front() { - if handled_reexports.contains(&reexport) { - continue; - } - - handled_reexports.insert(reexport.to_string()); - // First, resolve the reexport specifier let reexport_specifier = self.resolve( &reexport, @@ -131,6 +125,10 @@ impl NodeCodeTranslator { permissions, )?; + if !handled_reexports.insert(reexport_specifier.clone()) { + continue; + } + // Second, resolve its exports and re-exports let analysis = self .cjs_code_analyzer diff --git a/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/api.js b/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/api.js new file mode 100644 index 0000000000..831428ef73 --- /dev/null +++ b/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/api.js @@ -0,0 +1 @@ +module.exports.main = 1; diff --git a/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/index.js b/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/index.js new file mode 100644 index 0000000000..9e9b27a0a8 --- /dev/null +++ b/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/index.js @@ -0,0 +1,14 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +// specifier here is the same as in sub/index.js +__exportStar(require("./api"), exports); +__exportStar(require("./sub"), exports); \ No newline at end of file diff --git a/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/package.json b/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/package.json new file mode 100644 index 0000000000..0264413a3e --- /dev/null +++ b/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/package.json @@ -0,0 +1,4 @@ +{ + "name": "@denotest/cjs-reexport-same-specifier-in-sub-folder", + "version": "1.0.0" +} \ No newline at end of file diff --git a/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/sub/api.js b/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/sub/api.js new file mode 100644 index 0000000000..bba5ee087f --- /dev/null +++ b/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/sub/api.js @@ -0,0 +1 @@ +module.exports.sub = 2; diff --git a/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/sub/index.js b/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/sub/index.js new file mode 100644 index 0000000000..48f78249e0 --- /dev/null +++ b/tests/registry/npm/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0/sub/index.js @@ -0,0 +1,12 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +__exportStar(require("./api"), exports); \ No newline at end of file diff --git a/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/__test__.jsonc b/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/__test__.jsonc new file mode 100644 index 0000000000..5517e693d6 --- /dev/null +++ b/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "run main.ts", + "output": "main.out" +} diff --git a/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.out b/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.out new file mode 100644 index 0000000000..321d995b8a --- /dev/null +++ b/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.out @@ -0,0 +1,7 @@ +Download http://localhost:4260/@denotest/cjs-reexport-same-specifier-in-sub-folder +Download http://localhost:4260/@denotest/cjs-reexport-same-specifier-in-sub-folder/1.0.0.tgz +[Module: null prototype] { + default: { main: [Getter], sub: [Getter] }, + main: 1, + sub: 2 +} diff --git a/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.ts b/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.ts new file mode 100644 index 0000000000..fd0bf7ebac --- /dev/null +++ b/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.ts @@ -0,0 +1,3 @@ +import * as module from "npm:@denotest/cjs-reexport-same-specifier-in-sub-folder"; + +console.log(module);