tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

namespace-unambiguous-if-import-star-as-and-export.js (4165B)


      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 `import * as foo; export { 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 * as ns from "mod"; 	"ns" 	               "mod"                   all                  null
     23 
     24   16.2.1.7.1 ParseModule ( sourceText, realm, hostDefined )
     25      [...]
     26      10. For each ExportEntry Record ee of exportEntries, do
     27         1. If ee.[[ModuleRequest]] is null, then
     28            i. If importedBoundNames does not contain ee.[[LocalName]], then
     29              1. Append ee to localExportEntries.
     30            ii. Else,
     31              1. Let ie be the element of importEntries whose [[LocalName]] is ee.[[LocalName]].
     32              2. If ie.[[ImportName]] is namespace-object, then
     33                a. NOTE: This is a re-export of an imported module namespace object.
     34                b. Append the ExportEntry Record { [[ModuleRequest]]: ie.[[ModuleRequest]], [[ImportName]]: ~all~, [[LocalName]]: *null*, [[ExportName]]: ee.[[ExportName]] } to indirectExportEntries.
     35              3. Else,
     36                a. NOTE: This is a re-export of a single name.
     37                b. Append the ExportEntry Record { [[ModuleRequest]]: ie.[[ModuleRequest]],
     38                [[ImportName]]: ie.[[ImportName]], [[LocalName]]: null, [[ExportName]]:
     39                ee.[[ExportName]] } to indirectExportEntries.
     40         2. Else if ee.[[ImportName]] is all-but-default, then
     41            [...]
     42         3. Else,
     43            a. Append ee to indirectExportEntries.
     44 
     45   15.2.1.16.3 ResolveExport
     46 
     47   [...]
     48   6. For each ExportEntry Record e of module.[[IndirectExportEntries]], do
     49   a. If e.[[ExportName]] is exportName, then
     50      i. Assert: e.[[ModuleRequest]] is not null.
     51      ii. Let importedModule be GetImportedModule(module, e.[[ModuleRequest]]).
     52      iii. If e.[[ImportName]] is all, then
     53         1. Assert: module does not provide the direct binding for this export.
     54         2. Return ResolvedBinding Record { [[Module]]: importedModule, [[BindingName]]: namespace }.
     55   [...]
     56   9. Let starResolution be null.
     57   10. For each ExportEntry Record e in module.[[StarExportEntries]], do
     58      a. Let importedModule be GetImportedModule(module,
     59         e.[[ModuleRequest]]).
     60      b. Let resolution be ? importedModule.ResolveExport(exportName,
     61         resolveSet, exportStarSet).
     62      c. If resolution is ~ambiguous~, return ~ambiguous~.
     63      d. If resolution is not null, then
     64         i. If starResolution is null, let starResolution be resolution.
     65         ii. Else,
     66            1. Assert: there is more than one * import that includes the
     67               requested name.
     68            2. If _resolution_.[[Module]] and _starResolution_.[[Module]] are
     69               not the same Module Record, return ~ambiguous~.
     70            3. If _resolution_.[[BindingName]] is not _starResolution_.[[BindingName]],
     71               return ~ambiguous~.
     72 flags: [module]
     73 ---*/
     74 
     75 export * from "./namespace-import-star-as-and-export-1_FIXTURE.js";
     76 export * from "./namespace-import-star-as-and-export-2_FIXTURE.js";
     77 
     78 import { foo } from './namespace-unambiguous-if-import-star-as-and-export.js';
     79 
     80 assert.sameValue(typeof foo, 'object');
     81 
     82 reportCompare(0, 0);