namespace-unambiguous-if-export-star-as-from.js (4231B)
1 // |reftest| module 2 // Copyright (C) 2025 Igalia, S.L. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 /*--- 5 description: Exporting the same namespace object twice with `export * as foo` produces an unambiguous binding 6 esid: sec-source-text-module-record-initialize-environment 7 info: | 8 [...] 9 7. For each ImportEntry Record in of module.[[ImportEntries]], do 10 a. Let importedModule be GetImportedModule(module, in.[[ModuleRequest]]). 11 b. If in.[[ImportName]] is namespace-object, then 12 i. Let namespace be GetModuleNamespace(importedModule). 13 ii. Perform ! env.CreateImmutableBinding(in.[[LocalName]], true). 14 iii. Perform ! env.InitializeBinding(in.[[LocalName]], namespace). 15 c. Else, 16 i. Let resolution be importedModule.ResolveExport(in.[[ImportName]]). 17 ii. If resolution is either null or ambiguous, throw a SyntaxError exception. 18 19 Table 59 (Informative): Export Forms Mappings to ExportEntry Records 20 21 Export Statement Form [[ExportName]] [[ModuleRequest]] [[ImportName]] [[LocalName]] 22 export {x}; "x" null null "x" 23 export * as ns from "mod"; "ns" "mod" all null 24 25 16.2.1.7.1 ParseModule ( sourceText, realm, hostDefined ) 26 [...] 27 10. For each ExportEntry Record ee of exportEntries, do 28 1. If ee.[[ModuleRequest]] is null, then 29 i. If importedBoundNames does not contain ee.[[LocalName]], then 30 1. Append ee to localExportEntries. 31 ii. Else, 32 1. Let ie be the element of importEntries whose [[LocalName]] is ee.[[LocalName]]. 33 2. If ie.[[ImportName]] is namespace-object, then 34 a. NOTE: This is a re-export of an imported module namespace object. 35 b. Append the ExportEntry Record { [[ModuleRequest]]: ie.[[ModuleRequest]], [[ImportName]]: ~all~, [[LocalName]]: *null*, [[ExportName]]: ee.[[ExportName]] } to indirectExportEntries. 36 3. Else, 37 a. NOTE: This is a re-export of a single name. 38 b. Append the ExportEntry Record { [[ModuleRequest]]: ie.[[ModuleRequest]], 39 [[ImportName]]: ie.[[ImportName]], [[LocalName]]: null, [[ExportName]]: 40 ee.[[ExportName]] } to indirectExportEntries. 41 2. Else if ee.[[ImportName]] is all-but-default, then 42 [...] 43 3. Else, 44 a. Append ee to indirectExportEntries. 45 46 15.2.1.16.3 ResolveExport 47 48 [...] 49 6. For each ExportEntry Record e of module.[[IndirectExportEntries]], do 50 a. If e.[[ExportName]] is exportName, then 51 i. Assert: e.[[ModuleRequest]] is not null. 52 ii. Let importedModule be GetImportedModule(module, e.[[ModuleRequest]]). 53 iii. If e.[[ImportName]] is all, then 54 1. Assert: module does not provide the direct binding for this export. 55 2. Return ResolvedBinding Record { [[Module]]: importedModule, [[BindingName]]: namespace }. 56 [...] 57 9. Let starResolution be null. 58 10. For each ExportEntry Record e in module.[[StarExportEntries]], do 59 a. Let importedModule be GetImportedModule(module, 60 e.[[ModuleRequest]]). 61 b. Let resolution be ? importedModule.ResolveExport(exportName, 62 resolveSet, exportStarSet). 63 c. If resolution is ~ambiguous~, return ~ambiguous~. 64 d. If resolution is not null, then 65 i. If starResolution is null, let starResolution be resolution. 66 ii. Else, 67 1. Assert: there is more than one * import that includes the 68 requested name. 69 2. If _resolution_.[[Module]] and _starResolution_.[[Module]] are 70 not the same Module Record, return ~ambiguous~. 71 3. If _resolution_.[[BindingName]] is not _starResolution_.[[BindingName]], 72 return ~ambiguous~. 73 flags: [module] 74 ---*/ 75 76 export * from "./namespace-export-star-as-from-1_FIXTURE.js"; 77 export * from "./namespace-export-star-as-from-2_FIXTURE.js"; 78 79 import { foo } from './namespace-unambiguous-if-export-star-as-from.js'; 80 81 assert.sameValue(typeof foo, 'object'); 82 83 reportCompare(0, 0);