Skip to content

Commit a6cbfac

Browse files
author
Valerie R Young
committed
Update Module Semantics to handle export * as ns...
1 parent ba84975 commit a6cbfac

1 file changed

Lines changed: 54 additions & 37 deletions

File tree

spec.html

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8543,6 +8543,13 @@ <h1>[[Get]] ( _P_, _Receiver_ )</h1>
85438543
1. Assert: _binding_ is a ResolvedBinding Record.
85448544
1. Let _targetModule_ be _binding_.[[Module]].
85458545
1. Assert: _targetModule_ is not *undefined*.
8546+
1. If _binding_.[[BindingName]] is `"*namespace*"`, then
8547+
1. Return ? GetModuleNamespace(_targetModule_).
8548+
1. Else,
8549+
1. Let _targetEnv_ be _targetModule_.[[Environment]].
8550+
1. If _targetEnv_ is *undefined*, throw a *ReferenceError* exception.
8551+
1. Let _targetEnvRec_ be _targetEnv_'s EnvironmentRecord.
8552+
1. Return ? _targetEnvRec_.GetBindingValue(_binding_.[[BindingName]], *true*).
85468553
1. Let _targetEnv_ be _targetModule_.[[Environment]].
85478554
1. If _targetEnv_ is *undefined*, throw a *ReferenceError* exception.
85488555
1. Let _targetEnvRec_ be _targetEnv_'s EnvironmentRecord.
@@ -21426,7 +21433,7 @@ <h1>Abstract Module Records</h1>
2142621433
ResolveExport(_exportName_, _resolveSet_)
2142721434
</td>
2142821435
<td>
21429-
<p>Return the binding of a name exported by this module. Bindings are represented by a <dfn id="resolvedbinding-record">ResolvedBinding Record</dfn>, of the form { [[Module]]: Module Record, [[BindingName]]: String }. Return *null* if the name cannot be resolved, or `"ambiguous"` if multiple bindings were found.</p>
21436+
<p>Return the binding of a name exported by this module. Bindings are represented by a <dfn id="resolvedbinding-record">ResolvedBinding Record</dfn>, of the form { [[Module]]: Module Record, [[BindingName]]: String }. If the export is a Module Namespace Object without a direct binding in any module, [[BindingName]] will be set to `"*namespace*"`. Return *null* if the name cannot be resolved, or `"ambiguous"` if multiple bindings were found.</p>
2143021437
<p>This operation must be idempotent if it completes normally. Each time it is called with a specific _exportName_, _resolveSet_ pair as arguments it must return the same result.</p>
2143121438
</td>
2143221439
</tr>
@@ -21527,7 +21534,7 @@ <h1>Source Text Module Records</h1>
2152721534
List of ExportEntry Records
2152821535
</td>
2152921536
<td>
21530-
A List of ExportEntry records derived from the code of this module that correspond to reexported imports that occur within the module.
21537+
A List of ExportEntry records derived from the code of this module that correspond to reexported imports that occur within the module or exports from export * as namespace declarations.
2153121538
</td>
2153221539
</tr>
2153321540
<tr>
@@ -21538,7 +21545,7 @@ <h1>Source Text Module Records</h1>
2153821545
List of ExportEntry Records
2153921546
</td>
2154021547
<td>
21541-
A List of ExportEntry records derived from the code of this module that correspond to export * declarations that occur within the module.
21548+
A List of ExportEntry records derived from the code of this module that correspond to export * declarations that occur within the module, not including export * as namespace declarations.
2154221549
</td>
2154321550
</tr>
2154421551
<tr>
@@ -21747,7 +21754,7 @@ <h1>Source Text Module Records</h1>
2174721754
[[ExportName]]
2174821755
</td>
2174921756
<td>
21750-
String
21757+
String | null
2175121758
</td>
2175221759
<td>
2175321760
The name used to export this binding by this module.
@@ -21969,16 +21976,17 @@ <h1>Source Text Module Records</h1>
2196921976
`export * as ns from "mod";`
2197021977
</td>
2197121978
<td>
21972-
*null*
21979+
`"ns"`
2197321980
</td>
2197421981
<td>
2197521982
`"mod"`
2197621983
</td>
2197721984
<td>
2197821985
`"*"`
2197921986
</td>
21987+
2198021988
<td>
21981-
`"ns"`
21989+
*null*
2198221990
</td>
2198321991
</tr>
2198421992
</tbody>
@@ -22012,7 +22020,7 @@ <h1>ParseModule ( _sourceText_, _realm_, _hostDefined_ )</h1>
2201222020
1. Append _ee_ to _localExportEntries_.
2201322021
1. Else this is a re-export of a single name,
2201422022
1. Append the ExportEntry Record { [[ModuleRequest]]: _ie_.[[ModuleRequest]], [[ImportName]]: _ie_.[[ImportName]], [[LocalName]]: *null*, [[ExportName]]: _ee_.[[ExportName]] } to _indirectExportEntries_.
22015-
1. Else if _ee_.[[ImportName]] is `"*"`, then
22023+
1. Else if _ee_.[[ImportName]] is `"*"` and _ee_.[[ExportName]] is *null*, then
2201622024
1. Append _ee_ to _starExportEntries_.
2201722025
1. Else,
2201822026
1. Append _ee_ to _indirectExportEntries_.
@@ -22060,7 +22068,7 @@ <h1>ResolveExport ( _exportName_, _resolveSet_ ) Concrete Method</h1>
2206022068

2206122069
<p>ResolveExport attempts to resolve an imported binding to the actual defining module and local binding name. The defining module may be the module represented by the Module Record this method was invoked on or some other module that is imported by that module. The parameter _resolveSet_ is used to detect unresolved circular import/export paths. If a pair consisting of specific Module Record and _exportName_ is reached that is already in _resolveSet_, an import circularity has been encountered. Before recursively calling ResolveExport, a pair consisting of _module_ and _exportName_ is added to _resolveSet_.</p>
2206222070

22063-
<p>If a defining module is found, a ResolvedBinding Record { [[Module]], [[BindingName]] } is returned. This record identifies the resolved binding of the originally requested export. If no definition was found or the request is found to be circular, *null* is returned. If the request is found to be ambiguous, the string `"ambiguous"` is returned.</p>
22071+
<p>If a defining module is found, a ResolvedBinding Record { [[Module]], [[BindingName]] } is returned. This record identifies the resolved binding of the originally requested export, unless this is the export of a namespace with no local binding. In this case, [[BindingName]] will be set to `"*namespace*"`. If no definition was found or the request is found to be circular, *null* is returned. If the request is found to be ambiguous, the string `"ambiguous"` is returned.</p>
2206422072

2206522073
<p>This abstract method performs the following steps:</p>
2206622074

@@ -22077,13 +22085,17 @@ <h1>ResolveExport ( _exportName_, _resolveSet_ ) Concrete Method</h1>
2207722085
1. Return ResolvedBinding Record { [[Module]]: _module_, [[BindingName]]: _e_.[[LocalName]] }.
2207822086
1. For each ExportEntry Record _e_ in _module_.[[IndirectExportEntries]], do
2207922087
1. If SameValue(_exportName_, _e_.[[ExportName]]) is *true*, then
22080-
1. Assert: _module_ imports a specific binding for this export.
22081-
1. Let _importedModule_ be ? HostResolveImportedModule(_module_, _e_.[[ModuleRequest]]).
22082-
1. Return _importedModule_.ResolveExport(_e_.[[ImportName]], _resolveSet_).
22088+
1. If _e_.[[ImportName]] is `"*"`, then
22089+
1. NOTE: _module_ does not provide the direct binding for this export.
22090+
1. Return ResolvedBinding Record {[[Module]]: _e_.[[ModuleRequest]], [[BindingName]]: `"*namespace*"`}.
22091+
1. Else,
22092+
1. Assert: _module_ imports a specific binding for this export.
22093+
1. Let _importedModule_ be ? HostResolveImportedModule(_module_, _e_.[[ModuleRequest]]).
22094+
1. Return _importedModule_.ResolveExport(_e_.[[ImportName]], _resolveSet_)
2208322095
1. If SameValue(_exportName_, `"default"`) is *true*, then
2208422096
1. Assert: A `default` export was not explicitly defined by this module.
2208522097
1. Return *null*.
22086-
1. NOTE: A `default` export cannot be provided by an `export *`.
22098+
1. NOTE: A `default` export cannot be provided by an `export * from "mod"` declaration.
2208722099
1. Let _starResolution_ be *null*.
2208822100
1. For each ExportEntry Record _e_ in _module_.[[StarExportEntries]], do
2208922101
1. Let _importedModule_ be ? HostResolveImportedModule(_module_, _e_.[[ModuleRequest]]).
@@ -22195,7 +22207,12 @@ <h1>ModuleDeclarationEnvironmentSetup ( _module_ )</h1>
2219522207
1. Else,
2219622208
1. Let _resolution_ be ? _importedModule_.ResolveExport(_in_.[[ImportName]], &laquo; &raquo;).
2219722209
1. If _resolution_ is *null* or `"ambiguous"`, throw a *SyntaxError* exception.
22198-
1. Call _envRec_.CreateImportBinding(_in_.[[LocalName]], _resolution_.[[Module]], _resolution_.[[BindingName]]).
22210+
1. If _resolution_.[[BindingName]] is `"*namespace*"`, then
22211+
1. Let _namespace_ be ? GetModuleNamespace(_resolution_.[[Module]]).
22212+
1. Perform ! _envRec_.CreateImmutableBinding(_in_.[[LocalName]], *true*).
22213+
1. Call _envRec_.InitializeBinding(_in_.[[LocalName]], _namespace_).
22214+
1. Else,
22215+
1. Call _envRec_.CreateImportBinding(_in_.[[LocalName]], _resolution_.[[Module]], _resolution_.[[BindingName]]).
2219922216
1. Let _code_ be _module_.[[ECMAScriptCode]].
2220022217
1. Let _varDeclarations_ be the VarScopedDeclarations of _code_.
2220122218
1. Let _declaredVarNames_ be a new empty List.
@@ -22631,7 +22648,7 @@ <h2>Syntax</h2>
2263122648
<emu-grammar type="definition">
2263222649
ExportDeclaration :
2263322650
`export` ExportFromClause FromClause `;`
22634-
`export` ExportClause `;`
22651+
`export` NamedExports `;`
2263522652
`export` VariableStatement[~Yield, ~Await]
2263622653
`export` Declaration[~Yield, ~Await]
2263722654
`export` `default` HoistableDeclaration[~Yield, ~Await, +Default]
@@ -22640,13 +22657,13 @@ <h2>Syntax</h2>
2264022657

2264122658
ExportFromClause :
2264222659
`*`
22643-
ExportClause
22660+
NamedExports
2264422661
NameSpaceExport
2264522662

2264622663
NameSpaceExport:
2264722664
`*` `as` IdentifierName
2264822665

22649-
ExportClause :
22666+
NamedExports :
2265022667
`{` `}`
2265122668
`{` ExportsList `}`
2265222669
`{` ExportsList `,` `}`
@@ -22662,14 +22679,14 @@ <h2>Syntax</h2>
2266222679

2266322680
<emu-clause id="sec-exports-static-semantics-early-errors">
2266422681
<h1>Static Semantics: Early Errors</h1>
22665-
<emu-grammar>ExportDeclaration : `export` ExportClause `;`</emu-grammar>
22682+
<emu-grammar>ExportDeclaration : `export` NamedExports `;`</emu-grammar>
2266622683
<ul>
2266722684
<li>
22668-
For each |IdentifierName| _n_ in ReferencedBindings of |ExportClause|: It is a Syntax Error if StringValue of _n_ is a |ReservedWord| or if the StringValue of _n_ is one of: `"implements"`, `"interface"`, `"let"`, `"package"`, `"private"`, `"protected"`, `"public"`, or `"static"`.
22685+
For each |IdentifierName| _n_ in ReferencedBindings of |NamedExports|: It is a Syntax Error if StringValue of _n_ is a |ReservedWord| or if the StringValue of _n_ is one of: `"implements"`, `"interface"`, `"let"`, `"package"`, `"private"`, `"protected"`, `"public"`, or `"static"`.
2266922686
</li>
2267022687
</ul>
2267122688
<emu-note>
22672-
<p>The above rule means that each ReferencedBindings of |ExportClause| is treated as an |IdentifierReference|.</p>
22689+
<p>The above rule means that each ReferencedBindings of |NamedExports| is treated as an |IdentifierReference|.</p>
2267322690
</emu-note>
2267422691
</emu-clause>
2267522692

@@ -22679,7 +22696,7 @@ <h1>Static Semantics: BoundNames</h1>
2267922696
<emu-grammar>
2268022697
ExportDeclaration :
2268122698
`export` ExportFromClause FromClause `;`
22682-
`export` ExportClause `;`
22699+
`export` NamedExports `;`
2268322700
</emu-grammar>
2268422701
<emu-alg>
2268522702
1. Return a new empty List.
@@ -22720,9 +22737,9 @@ <h1>Static Semantics: ExportedBindings</h1>
2272022737
<emu-alg>
2272122738
1. Return a new empty List.
2272222739
</emu-alg>
22723-
<emu-grammar>ExportDeclaration : `export` ExportClause `;`</emu-grammar>
22740+
<emu-grammar>ExportDeclaration : `export` NamedExports `;`</emu-grammar>
2272422741
<emu-alg>
22725-
1. Return the ExportedBindings of |ExportClause|.
22742+
1. Return the ExportedBindings of |NamedExports|.
2272622743
</emu-alg>
2272722744
<emu-grammar>ExportDeclaration : `export` VariableStatement</emu-grammar>
2272822745
<emu-alg>
@@ -22742,7 +22759,7 @@ <h1>Static Semantics: ExportedBindings</h1>
2274222759
<emu-alg>
2274322760
1. Return the BoundNames of this |ExportDeclaration|.
2274422761
</emu-alg>
22745-
<emu-grammar>ExportClause : `{` `}`</emu-grammar>
22762+
<emu-grammar>NamedExports : `{` `}`</emu-grammar>
2274622763
<emu-alg>
2274722764
1. Return a new empty List.
2274822765
</emu-alg>
@@ -22773,13 +22790,13 @@ <h1>Static Semantics: ExportedNames</h1>
2277322790
<emu-alg>
2277422791
1. Return a new empty List.
2277522792
</emu-alg>
22776-
<emu-grammar>ExportFromClause : ExportClause</emu-grammar>
22793+
<emu-grammar>ExportFromClause : NamedExports</emu-grammar>
2277722794
<emu-alg>
22778-
1. Return the ExportedNames of ExportClause.
22795+
1. Return the ExportedNames of NamedExports.
2277922796
</emu-alg>
22780-
<emu-grammar>ExportFromClause : NameSpaceExport</emu-grammar>
22797+
<emu-grammar>NameSpaceExport : `*` `as` IdentifierName </emu-grammar>
2278122798
<emu-alg>
22782-
1. Return the ExportedNames of NameSpaceExport.
22799+
1. Return a List containing the StringValue of |IdentifierName|.
2278322800
</emu-alg>
2278422801
<emu-grammar>ExportDeclaration : `export` VariableStatement</emu-grammar>
2278522802
<emu-alg>
@@ -22799,7 +22816,7 @@ <h1>Static Semantics: ExportedNames</h1>
2279922816
<emu-alg>
2280022817
1. Return &laquo; `"default"` &raquo;.
2280122818
</emu-alg>
22802-
<emu-grammar>ExportClause : `{` `}`</emu-grammar>
22819+
<emu-grammar>NamedExports : `{` `}`</emu-grammar>
2280322820
<emu-alg>
2280422821
1. Return a new empty List.
2280522822
</emu-alg>
@@ -22827,9 +22844,9 @@ <h1>Static Semantics: ExportEntries</h1>
2282722844
1. Let _module_ be the sole element of ModuleRequests of |FromClause|.
2282822845
1. Return ExportEntriesForModule of |ExportFromClause| with argument _module_.
2282922846
</emu-alg>
22830-
<emu-grammar>ExportDeclaration : `export` ExportClause `;`</emu-grammar>
22847+
<emu-grammar>ExportDeclaration : `export` NamedExports `;`</emu-grammar>
2283122848
<emu-alg>
22832-
1. Return ExportEntriesForModule of |ExportClause| with argument *null*.
22849+
1. Return ExportEntriesForModule of |NamedExports| with argument *null*.
2283322850
</emu-alg>
2283422851
<emu-grammar>ExportDeclaration : `export` VariableStatement</emu-grammar>
2283522852
<emu-alg>
@@ -22883,7 +22900,7 @@ <h1>Static Semantics: ExportEntriesForModule</h1>
2288322900
1. Let _entry_ be the ExportEntry Record {[[ModuleRequest]]: _module_, [[ImportName]]: `"*"`, [[LocalName]]: *null*, [[ExportName]]: _exportName_ }.
2288422901
1. Return a new List containing _entry_.
2288522902
</emu-alg>
22886-
<emu-grammar>ExportClause : `{` `}`</emu-grammar>
22903+
<emu-grammar>NamedExports : `{` `}`</emu-grammar>
2288722904
<emu-alg>
2288822905
1. Return a new empty List.
2288922906
</emu-alg>
@@ -22924,7 +22941,7 @@ <h1>Static Semantics: IsConstantDeclaration</h1>
2292422941
<emu-grammar>
2292522942
ExportDeclaration :
2292622943
`export` ExportFromClause FromClause `;`
22927-
`export` ExportClause `;`
22944+
`export` NamedExports `;`
2292822945
`export` `default` AssignmentExpression `;`
2292922946
</emu-grammar>
2293022947
<emu-alg>
@@ -22941,7 +22958,7 @@ <h1>Static Semantics: LexicallyScopedDeclarations</h1>
2294122958
<emu-grammar>
2294222959
ExportDeclaration :
2294322960
`export` ExportFromClause FromClause `;`
22944-
`export` ExportClause `;`
22961+
`export` NamedExports `;`
2294522962
`export` VariableStatement
2294622963
</emu-grammar>
2294722964
<emu-alg>
@@ -22976,7 +22993,7 @@ <h1>Static Semantics: ModuleRequests</h1>
2297622993
</emu-alg>
2297722994
<emu-grammar>
2297822995
ExportDeclaration :
22979-
`export` ExportClause `;`
22996+
`export` NamedExports `;`
2298022997
`export` VariableStatement
2298122998
`export` Declaration
2298222999
`export` `default` HoistableDeclaration
@@ -22990,7 +23007,7 @@ <h1>Static Semantics: ModuleRequests</h1>
2299023007

2299123008
<emu-clause id="sec-static-semantics-referencedbindings">
2299223009
<h1>Static Semantics: ReferencedBindings</h1>
22993-
<emu-grammar>ExportClause : `{` `}`</emu-grammar>
23010+
<emu-grammar>NamedExports : `{` `}`</emu-grammar>
2299423011
<emu-alg>
2299523012
1. Return a new empty List.
2299623013
</emu-alg>
@@ -23015,7 +23032,7 @@ <h1>Runtime Semantics: Evaluation</h1>
2301523032
<emu-grammar>
2301623033
ExportDeclaration :
2301723034
`export` ExportFromClause FromClause `;`
23018-
`export` ExportClause `;`
23035+
`export` NamedExports `;`
2301923036
</emu-grammar>
2302023037
<emu-alg>
2302123038
1. Return NormalCompletion(~empty~).
@@ -39486,7 +39503,7 @@ <h1>Scripts and Modules</h1>
3948639503
<emu-prodref name=ModuleSpecifier></emu-prodref>
3948739504
<emu-prodref name=ImportedBinding></emu-prodref>
3948839505
<emu-prodref name=ExportDeclaration></emu-prodref>
39489-
<emu-prodref name=ExportClause></emu-prodref>
39506+
<emu-prodref name=NamedExports></emu-prodref>
3949039507
<emu-prodref name=ExportsList></emu-prodref>
3949139508
<emu-prodref name=ExportSpecifier></emu-prodref>
3949239509
</emu-annex>

0 commit comments

Comments
 (0)