From 5999e11501df475cadc6ba31908115f454a622f1 Mon Sep 17 00:00:00 2001 From: Valerie R Young Date: Tue, 17 Apr 2018 17:28:35 -0400 Subject: [PATCH] Update Module Semantics to handle `export * as ns...` --- spec.html | 91 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 37 deletions(-) diff --git a/spec.html b/spec.html index 3237b9fb10f..9d7c0a2d5fe 100644 --- a/spec.html +++ b/spec.html @@ -8814,6 +8814,13 @@

[[Get]] ( _P_, _Receiver_ )

1. Assert: _binding_ is a ResolvedBinding Record. 1. Let _targetModule_ be _binding_.[[Module]]. 1. Assert: _targetModule_ is not *undefined*. + 1. If _binding_.[[BindingName]] is `"*namespace*"`, then + 1. Return ? GetModuleNamespace(_targetModule_). + 1. Else, + 1. Let _targetEnv_ be _targetModule_.[[Environment]]. + 1. If _targetEnv_ is *undefined*, throw a *ReferenceError* exception. + 1. Let _targetEnvRec_ be _targetEnv_'s EnvironmentRecord. + 1. Return ? _targetEnvRec_.GetBindingValue(_binding_.[[BindingName]], *true*). 1. Let _targetEnv_ be _targetModule_.[[Environment]]. 1. If _targetEnv_ is *undefined*, throw a *ReferenceError* exception. 1. Let _targetEnvRec_ be _targetEnv_'s EnvironmentRecord. @@ -22148,7 +22155,7 @@

Abstract Module Records

ResolveExport(_exportName_, _resolveSet_) -

Return the binding of a name exported by this module. Bindings are represented by a ResolvedBinding Record, of the form {[[Module]]: Module Record, [[BindingName]]: String}. Return *null* if the name cannot be resolved, or `"ambiguous"` if multiple bindings were found.

+

Return the binding of a name exported by this module. Bindings are represented by a ResolvedBinding Record, 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.

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.

@@ -22250,7 +22257,7 @@

Source Text Module Records

List of ExportEntry Records - A List of ExportEntry records derived from the code of this module that correspond to reexported imports that occur within the module. + 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. @@ -22261,7 +22268,7 @@

Source Text Module Records

List of ExportEntry Records - A List of ExportEntry records derived from the code of this module that correspond to export * declarations that occur within the module. + 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. @@ -22470,7 +22477,7 @@

Source Text Module Records

[[ExportName]] - String + String | null The name used to export this binding by this module. @@ -22692,7 +22699,7 @@

Source Text Module Records

`export * as ns from "mod";` - *null* + `"ns"` `"mod"` @@ -22700,8 +22707,9 @@

Source Text Module Records

`"*"` + - `"ns"` + *null* @@ -22736,7 +22744,7 @@

ParseModule ( _sourceText_, _realm_, _hostDefined_ )

1. Append _ee_ to _localExportEntries_. 1. Else this is a re-export of a single name, 1. Append the ExportEntry Record {[[ModuleRequest]]: _ie_.[[ModuleRequest]], [[ImportName]]: _ie_.[[ImportName]], [[LocalName]]: *null*, [[ExportName]]: _ee_.[[ExportName]] } to _indirectExportEntries_. - 1. Else if _ee_.[[ImportName]] is `"*"`, then + 1. Else if _ee_.[[ImportName]] is `"*"` and _ee_.[[ExportName]] is *null*, then 1. Append _ee_ to _starExportEntries_. 1. Else, 1. Append _ee_ to _indirectExportEntries_. @@ -22785,7 +22793,7 @@

ResolveExport( _exportName_, _resolveSet_ ) Concrete Method

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_.

-

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.

+

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.

This abstract method performs the following steps:

@@ -22802,13 +22810,17 @@

ResolveExport( _exportName_, _resolveSet_ ) Concrete Method

1. Return ResolvedBinding Record {[[Module]]: _module_, [[BindingName]]: _e_.[[LocalName]]}. 1. For each ExportEntry Record _e_ in _module_.[[IndirectExportEntries]], do 1. If SameValue(_exportName_, _e_.[[ExportName]]) is *true*, then - 1. Assert: _module_ imports a specific binding for this export. - 1. Let _importedModule_ be ? HostResolveImportedModule(_module_, _e_.[[ModuleRequest]]). - 1. Return _importedModule_.ResolveExport(_e_.[[ImportName]], _resolveSet_). + 1. If _e_.[[ImportName]] is `"*"`, then + 1. NOTE: _module_ does not provide the direct binding for this export. + 1. Return ResolvedBinding Record {[[Module]]: _e_.[[ModuleRequest]], [[BindingName]]: `"*namespace*"`}. + 1. Else, + 1. Assert: _module_ imports a specific binding for this export. + 1. Let _importedModule_ be ? HostResolveImportedModule(_module_, _e_.[[ModuleRequest]]). + 1. Return _importedModule_.ResolveExport(_e_.[[ImportName]], _resolveSet_) 1. If SameValue(_exportName_, `"default"`) is *true*, then 1. Assert: A `default` export was not explicitly defined by this module. 1. Return *null*. - 1. NOTE: A `default` export cannot be provided by an `export *`. + 1. NOTE: A `default` export cannot be provided by an `export * from "mod"` declaration. 1. Let _starResolution_ be *null*. 1. For each ExportEntry Record _e_ in _module_.[[StarExportEntries]], do 1. Let _importedModule_ be ? HostResolveImportedModule(_module_, _e_.[[ModuleRequest]]). @@ -22921,7 +22933,12 @@

ModuleDeclarationEnvironmentSetup( _module_ )

1. Else, 1. Let _resolution_ be ? _importedModule_.ResolveExport(_in_.[[ImportName]], « »). 1. If _resolution_ is *null* or `"ambiguous"`, throw a *SyntaxError* exception. - 1. Call _envRec_.CreateImportBinding(_in_.[[LocalName]], _resolution_.[[Module]], _resolution_.[[BindingName]]). + 1. If _resolution_.[[BindingName]] is `"*namespace*"`, then + 1. Let _namespace_ be ? GetModuleNamespace(_resolution_.[[Module]]). + 1. Perform ! _envRec_.CreateImmutableBinding(_in_.[[LocalName]], *true*). + 1. Call _envRec_.InitializeBinding(_in_.[[LocalName]], _namespace_). + 1. Else, + 1. Call _envRec_.CreateImportBinding(_in_.[[LocalName]], _resolution_.[[Module]], _resolution_.[[BindingName]]). 1. Let _code_ be _module_.[[ECMAScriptCode]]. 1. Let _varDeclarations_ be the VarScopedDeclarations of _code_. 1. Let _declaredVarNames_ be a new empty List. @@ -23368,7 +23385,7 @@

Syntax

ExportDeclaration : `export` ExportFromClause FromClause `;` - `export` ExportClause `;` + `export` NamedExports `;` `export` VariableStatement[~Yield, ~Await] `export` Declaration[~Yield, ~Await] `export` `default` HoistableDeclaration[~Yield, ~Await, +Default] @@ -23377,13 +23394,13 @@

Syntax

ExportFromClause : `*` - ExportClause + NamedExports NameSpaceExport NameSpaceExport: `*` `as` IdentifierName - ExportClause : + NamedExports : `{` `}` `{` ExportsList `}` `{` ExportsList `,` `}` @@ -23400,14 +23417,14 @@

Syntax

Static Semantics: Early Errors

- ExportDeclaration : `export` ExportClause `;` + ExportDeclaration : `export` NamedExports `;`
  • - 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"`. + 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"`.
-

The above rule means that each ReferencedBindings of |ExportClause| is treated as an |IdentifierReference|.

+

The above rule means that each ReferencedBindings of |NamedExports| is treated as an |IdentifierReference|.

@@ -23418,7 +23435,7 @@

Static Semantics: BoundNames

ExportDeclaration : `export` ExportFromClause FromClause `;` - `export` ExportClause `;` + `export` NamedExports `;` 1. Return a new empty List. @@ -23460,9 +23477,9 @@

Static Semantics: ExportedBindings

1. Return a new empty List. - ExportDeclaration : `export` ExportClause `;` + ExportDeclaration : `export` NamedExports `;` - 1. Return the ExportedBindings of |ExportClause|. + 1. Return the ExportedBindings of |NamedExports|. ExportDeclaration : `export` VariableStatement @@ -23482,7 +23499,7 @@

Static Semantics: ExportedBindings

1. Return the BoundNames of this |ExportDeclaration|. - ExportClause : `{` `}` + NamedExports : `{` `}` 1. Return a new empty List. @@ -23514,13 +23531,13 @@

Static Semantics: ExportedNames

1. Return a new empty List. - ExportFromClause : ExportClause + ExportFromClause : NamedExports - 1. Return the ExportedNames of ExportClause. + 1. Return the ExportedNames of NamedExports. - ExportFromClause : NameSpaceExport + NameSpaceExport : `*` `as` IdentifierName - 1. Return the ExportedNames of NameSpaceExport. + 1. Return a List containing the StringValue of |IdentifierName|. ExportDeclaration : `export` VariableStatement @@ -23540,7 +23557,7 @@

Static Semantics: ExportedNames

1. Return « `"default"` ». - ExportClause : `{` `}` + NamedExports : `{` `}` 1. Return a new empty List. @@ -23569,9 +23586,9 @@

Static Semantics: ExportEntries

1. Let _module_ be the sole element of ModuleRequests of |FromClause|. 1. Return ExportEntriesForModule of |ExportFromClause| with argument _module_.
- ExportDeclaration : `export` ExportClause `;` + ExportDeclaration : `export` NamedExports `;` - 1. Return ExportEntriesForModule of |ExportClause| with argument *null*. + 1. Return ExportEntriesForModule of |NamedExports| with argument *null*. ExportDeclaration : `export` VariableStatement @@ -23626,7 +23643,7 @@

Static Semantics: ExportEntriesForModule

1. Let _entry_ be the ExportEntry Record {[[ModuleRequest]]: _module_, [[ImportName]]: `"*"`, [[LocalName]]: *null*, [[ExportName]]: _exportName_ }. 1. Return a new List containing _entry_.
- ExportClause : `{` `}` + NamedExports : `{` `}` 1. Return a new empty List. @@ -23668,7 +23685,7 @@

Static Semantics: IsConstantDeclaration

ExportDeclaration : `export` ExportFromClause FromClause `;` - `export` ExportClause `;` + `export` NamedExports `;` `export` `default` AssignmentExpression `;` @@ -23686,7 +23703,7 @@

Static Semantics: LexicallyScopedDeclarations

ExportDeclaration : `export` ExportFromClause FromClause `;` - `export` ExportClause `;` + `export` NamedExports `;` `export` VariableStatement @@ -23722,7 +23739,7 @@

Static Semantics: ModuleRequests

ExportDeclaration : - `export` ExportClause `;` + `export` NamedExports `;` `export` VariableStatement `export` Declaration `export` `default` HoistableDeclaration @@ -23737,7 +23754,7 @@

Static Semantics: ModuleRequests

Static Semantics: ReferencedBindings

- ExportClause : `{` `}` + NamedExports : `{` `}` 1. Return a new empty List. @@ -23763,7 +23780,7 @@

Runtime Semantics: Evaluation

ExportDeclaration : `export` ExportFromClause FromClause `;` - `export` ExportClause `;` + `export` NamedExports `;` 1. Return NormalCompletion(~empty~). @@ -40504,7 +40521,7 @@

Scripts and Modules

- +