├── .gitignore
├── LICENSE
├── README.md
├── index.html
├── package.json
├── spec.css
├── spec.emu
└── spec.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Caridy Patiño
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Dynamic Module Reform (REJECTED)
2 |
3 | ECMAScript Proposal specs for the reform to preserve the order of execution for dynamic modules.
4 |
5 | ## Champions
6 |
7 | * [@caridy](https://github.com/caridy).
8 | * [@dherman](https://github.com/dherman).
9 |
10 | This proposal was rejected in favor of preserving the current semantics. You can read more about this decision in the [tc39-notes](https://github.com/rwaldron/tc39-notes/blob/master/es8/2017-03/mar-23.md#10iia-dynamic-module-reform-for-stage-2). The last slide from [Update 2 - March 2017](https://docs.google.com/presentation/d/1EYOysPhgjXtgmuNoZ_wUCMElZ8GKLxJmCLeF0EvUXkc/edit#slide=id.g1f1f22a6f5_1_31) shows why this proposal is faulty.
11 |
12 | ## Slides
13 |
14 | * [Update 1 - Nov 2016](https://docs.google.com/presentation/d/1EYOysPhgjXtgmuNoZ_wUCMElZ8GKLxJmCLeF0EvUXkc/edit#slide=id.p)
15 | * [Update 2 - March 2017](https://docs.google.com/presentation/d/1EYOysPhgjXtgmuNoZ_wUCMElZ8GKLxJmCLeF0EvUXkc/edit#slide=id.g1f19d52d1f_0_0)
16 |
17 | ## Rationale
18 |
19 | ES module spec requires all Module Records to know all the exports during `ModuleDeclarationInstantiation()`. This is needed to guarantee that the linking process (bindings from one module environment record to another) can be accomplish, and works very well for Source Text Module Records, but forces other dynamic modules (like Node CJS modules) to be evaluated during the `ModuleDeclarationInstantiation()` phase. As a result, it is impossible to preserve the order of evaluation.
20 |
21 | ## Preserving the order of evaluation for Dynamic Module Records
22 |
23 | This proposal introduces the `"pending"` resolution value when calling `ResolveExport()` for a Dynamic Module Record. Additionally, this proposal introduces a new internal slot `[[PendingImportEntries]]` on Source Text Module Records that is used to track the import entries that are coming from Dynamic Module Records that hasn't been evaluated yet. As a result, calling `ResolveExport()` on the Dynamic Module Record during the `ModuleDeclarationInstantiation()` phase can resolve to `"pending"` to signal that the validation or assertion about the bindings should be deferred to the `ModuleEvaluation()` phase for the Source Text Module Record importing from a Dynamic Module Record.
24 |
25 | These changes allow us to identify, during the linking phase, an import binding that cannot be created yet and does not require explicit assertion during this phase. As a result, we can defer the evaluation of a Dynamic Module Record to preserve the execution order, and we do so under the assumption that the imported bindings from the Dynamic Module Record will gets populated after it is evaluated.
26 |
27 | ## Enabling Circular Dependencies with Dynamic Module Records
28 |
29 | This change also enable us to match the semantics of NCJS when it comes to circular dependencies. The following example illustrates this:
30 |
31 | ```js
32 | // even.js
33 | module.exports = function even(n) {
34 | ...
35 | require('odd')(n - 1)
36 | ...
37 | }
38 |
39 | // odd.js
40 | module.exports = function odd(n) {
41 | ...
42 | require('even')(n - 1)
43 | ...
44 | }
45 | ```
46 |
47 | These CJS modules will work in Node independently of which one is imported first, the same applies if both are written as ESM. But if one of them is ESM and the other is CJS, based on the currenct spec, we might get a static error depending on which one is imported first. E.g.:
48 |
49 | ```js
50 | // even.js (ESM):
51 | import odd from "odd";
52 | export default function even() {
53 | ...
54 | odd(n - 1)
55 | ...
56 | }
57 |
58 | // odd.js (DM)
59 | module.exports = function odd(n) {
60 | ...
61 | require('even')(n - 1)
62 | ...
63 | }
64 | ```
65 |
66 | If the binding for `odd` in `even.js` is not created until after `odd.js` is evaluated, the NCJS semantics are preserved, and this example works independently of which one is imported first.
67 |
68 | ## SyntaxError in Source Text Module Records
69 |
70 | * Throw during `ModuleDeclarationInstantiation` if the indirect import entry resolves to *null* or *ambiguous*.
71 | * Throw during `ModuleEvaluation` if a pending import entry resolves to *null* or *ambiguous* or *pending* after evaluating all dependencies, and before evaluating the source text.
72 |
73 | ## Compromises
74 |
75 | With this proposal, the statically verifiable mechanism introduced by ESM can only be enforced in a ES Module that is importing from another ES Module, and any interaction with Dynamic Module Records will be deferred to the `ModuleEvaluation()` phase for Dynamic Module Records that were not previously evaluated.
76 |
77 | ## Additional Information
78 |
79 | Most of the discussion around this topic is condenced in the meetings notes from TC39 Sept 2016 Meeting:
80 |
81 | * [Meeting Notes](https://esdiscuss.org/notes/2016-09-28)
82 | * [ES Modules Slides](https://esdiscuss.org/notes/2016-09/ES-Modules-Compat.pdf)
83 |
84 | ## Spec
85 |
86 | You can view the spec rendered as [HTML](https://rawgit.com/tc39/proposal-dynamic-modules/master/index.html).
87 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
2164 | A
2165 | List of ExportEntry records derived from the code of this module that correspond to declarations that occur within the module.
2166 |
2167 |
2168 |
2169 |
2170 |
2171 |
2172 |
2173 |
2174 |
2175 |
2176 |
1[[Get]] (P, Receiver)
2177 |
When the [[Get]] internal method of a module namespace exotic object O is called with property key P and
2178 | ECMAScript language valueReceiver, the following steps are taken:
ResolveExport is idempotent and side-effect free. An implementation might choose to pre-compute or cache the ResolveExport results for the [[Exports]] of each module namespace exotic object.
The ResolveExport concrete method of a
2223 | Source Text Module Record with arguments exportName, resolveSet, and exportStarSet performs the following steps:
Let resolution be ? importedModule.ResolveExport(exportName, resolveSet, exportStarSet).
2295 |
If resolution is "ambiguous", return "ambiguous".
2296 |
If resolution is "pending", return "pending".
2297 |
If resolution is not
2298 | null, then
2299 |
2300 |
If starResolution is
2301 | null, let starResolution be resolution.
2302 |
Else,
2303 |
2304 |
Assert: There is more than one * import that includes the requested name.
2305 |
If resolution.[[Module]] and starResolution.[[Module]] are not the same
2306 | Module Record or
2307 | SameValue(resolution.[[BindingName]], starResolution.[[BindingName]]) is
2308 | false, return "ambiguous".
2309 |
2310 |
2311 |
2312 |
2313 |
2314 |
2315 |
Return starResolution.
2316 |
2317 |
2318 |
2319 | Note
2320 |
2321 |
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
2322 | Module Record this method was invoked on or some other module that is imported by that module. The parameter resolveSet is use to detect unresolved circular import/export paths. If a pair consisting of specific
2323 | 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.
2324 |
If a defining module is found a
2325 | 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,
2326 | null is returned. If the request is found to be ambiguous, the string "ambiguous" is returned. If the request is found to be pending, the string "pending" is returned.
For each String required that is an element of module.[[RequestedModules]] do,
2353 |
2354 |
NOTE: Before instantiating a module, all of the modules it requested must be available. An implementation may perform this test at any time prior to this point.
NOTE: The above call cannot fail because imported module requests are a subset of module.[[RequestedModules]], and these have been resolved earlier in this algorithm.
The abstract operation ParseModule with arguments sourceText, realm, and hostDefined creates a
2526 | Source Text Module Record based upon the result of parsing sourceText as a
2527 | Module. ParseModule performs the following steps:
2528 |
2529 |
2530 |
Assert: sourceText is an ECMAScript source text (see clause
2531 | 10).
2532 |
Parse sourceText using
2533 | Module as the
2534 | goal symbol and analyze the parse result for any Early Error conditions. If the parse was successful and no early errors were found, let body be the resulting parse tree. Otherwise, let body be a
2535 | List of one or more
2536 | SyntaxError or
2537 | ReferenceError objects representing the parsing errors and/or early errors. Parsing and
2538 | early error detection may be interweaved in an implementation dependent manner. If more than one parsing error or
2539 | early error is present, the number and ordering of error objects in the list is implementation dependent, but at least one must be present.
2540 |
If body is a
2541 | List of errors, then return body.
2542 |
Let requestedModules be the ModuleRequests of body.
2543 |
Let importEntries be ImportEntries of body.
2544 |
Let pendingImportEntries be a new empty List.
2545 |
An implementation may parse module source text and analyze it for Early Error conditions prior to the evaluation of ParseModule for that module source text. However, the reporting of any errors must be deferred until the point where this specification actually performs ParseModule upon that source text.
All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT http://www.ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.
2619 |
2620 |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
2621 |
2622 |
2623 |
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2624 |
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
2625 |
Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.
2626 |
2627 |
2628 |
THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 | A List of ImportEntry records derived from the code of this module.
36 |
37 |
38 |
39 |
40 | [[PendingImportEntries]]
41 |
42 |
43 | List of ImportEntry Records
44 |
45 |
46 | A List of ImportEntry records that are pending to be validated.
47 |
48 |
49 |
50 |
51 | [[LocalExportEntries]]
52 |
53 |
54 | List of ExportEntry Records
55 |
56 |
57 | A List of ExportEntry records derived from the code of this module that correspond to declarations that occur within the module.
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
[[Get]] (_P_, _Receiver_)
67 |
When the [[Get]] internal method of a module namespace exotic object _O_ is called with property key _P_ and ECMAScript language value _Receiver_, the following steps are taken:
68 |
69 | 1. Assert: IsPropertyKey(_P_) is *true*.
70 | 1. If Type(_P_) is Symbol, then
71 | 1. Return ? OrdinaryGet(_O_, _P_, _Receiver_).
72 | 1. Let _exports_ be _O_.[[Exports]].
73 | 1. If _P_ is not an element of _exports_, return *undefined*.
74 | 1. Let _m_ be _O_.[[Module]].
75 | 1. Let _binding_ be ! _m_.ResolveExport(_P_, « », « »).
76 | 1. Assert: _binding_ is neither *null* nor `"ambiguous"`.
77 | 1. If _binding_ is `"pending"` or _binding_ is *null* or resolution is `"ambiguous"`, throw a *SyntaxError* exception.
78 | 1. Let _targetModule_ be _binding_.[[Module]].
79 | 1. Assert: _targetModule_ is not *undefined*.
80 | 1. Let _targetEnv_ be _targetModule_.[[Environment]].
81 | 1. If _targetEnv_ is *undefined*, throw a *ReferenceError* exception.
82 | 1. Let _targetEnvRec_ be _targetEnv_'s EnvironmentRecord.
83 | 1. Return ? _targetEnvRec_.GetBindingValue(_binding_.[[BindingName]], *true*).
84 |
85 |
86 |
ResolveExport is idempotent and side-effect free. An implementation might choose to pre-compute or cache the ResolveExport results for the [[Exports]] of each module namespace exotic object.
The ResolveExport concrete method of a Source Text Module Record with arguments _exportName_, _resolveSet_, and _exportStarSet_ performs the following steps:
94 |
95 | 1. Let _module_ be this Source Text Module Record.
96 | 1. For each Record {[[Module]], [[ExportName]]} _r_ in _resolveSet_, do:
97 | 1. If _module_ and _r_.[[Module]] are the same Module Record and SameValue(_exportName_, _r_.[[ExportName]]) is *true*, then
98 | 1. Assert: This is a circular import request.
99 | 1. Return *null*.
100 | 1. Append the Record {[[Module]]: _module_, [[ExportName]]: _exportName_} to _resolveSet_.
101 | 1. For each ExportEntry Record _e_ in _module_.[[LocalExportEntries]], do
102 | 1. If SameValue(_exportName_, _e_.[[ExportName]]) is *true*, then
103 | 1. Assert: _module_ provides the direct binding for this export.
104 | 1. Return Record{[[Module]]: _module_, [[BindingName]]: _e_.[[LocalName]]}.
105 | 1. For each ExportEntry Record _e_ in _module_.[[IndirectExportEntries]], do
106 | 1. If SameValue(_exportName_, _e_.[[ExportName]]) is *true*, then
107 | 1. Assert: _module_ imports a specific binding for this export.
108 | 1. Let _importedModule_ be ? HostResolveImportedModule(_module_, _e_.[[ModuleRequest]]).
109 | 1. Return ? _importedModule_.ResolveExport(_e_.[[ImportName]], _resolveSet_, _exportStarSet_).
110 | 1. If SameValue(_exportName_, `"default"`) is *true*, then
111 | 1. Assert: A `default` export was not explicitly defined by this module.
112 | 1. Return *null*.
113 | 1. NOTE A `default` export cannot be provided by an `export *`.
114 | 1. If _exportStarSet_ contains _module_, return *null*.
115 | 1. Append _module_ to _exportStarSet_.
116 | 1. Let _starResolution_ be *null*.
117 | 1. For each ExportEntry Record _e_ in _module_.[[StarExportEntries]], do
118 | 1. Let _importedModule_ be ? HostResolveImportedModule(_module_, _e_.[[ModuleRequest]]).
119 | 1. Let _resolution_ be ? _importedModule_.ResolveExport(_exportName_, _resolveSet_, _exportStarSet_).
120 | 1. If _resolution_ is `"ambiguous"`, return `"ambiguous"`.
121 | 1. If _resolution_ is `"pending"`, return `"pending"`.
122 | 1. If _resolution_ is not *null*, then
123 | 1. If _starResolution_ is *null*, let _starResolution_ be _resolution_.
124 | 1. Else,
125 | 1. Assert: There is more than one `*` import that includes the requested name.
126 | 1. If _resolution_.[[Module]] and _starResolution_.[[Module]] are not the same Module Record or SameValue(_resolution_.[[BindingName]], _starResolution_.[[BindingName]]) is *false*, return `"ambiguous"`.
127 | 1. Return _starResolution_.
128 |
129 |
130 |
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 use 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_.
131 |
If a defining module is found a 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 the request is found to be pending, the string `"pending"` is returned.
132 |
133 |
134 |
135 |
136 |
137 |
138 |
ModuleDeclarationInstantiation( ) Concrete Method
139 |
The ModuleDeclarationInstantiation concrete method of a Source Text Module Record performs the following steps:
140 |
141 | 1. Let _module_ be this Source Text Module Record.
142 | 1. Let _realm_ be _module_.[[Realm]].
143 | 1. Assert: _realm_ is not *undefined*.
144 | 1. Let _code_ be _module_.[[ECMAScriptCode]].
145 | 1. If _module_.[[Environment]] is not *undefined*, return NormalCompletion(~empty~).
146 | 1. Let _env_ be NewModuleEnvironment(_realm_.[[GlobalEnv]]).
147 | 1. Set _module_.[[Environment]] to _env_.
148 | 1. For each String _required_ that is an element of _module_.[[RequestedModules]] do,
149 | 1. NOTE: Before instantiating a module, all of the modules it requested must be available. An implementation may perform this test at any time prior to this point.
150 | 1. Let _requiredModule_ be ? HostResolveImportedModule(_module_, _required_).
151 | 1. Perform ? _requiredModule_.ModuleDeclarationInstantiation().
152 | 1. For each ExportEntry Record _e_ in _module_.[[IndirectExportEntries]], do
153 | 1. Let _resolution_ be ? _module_.ResolveExport(_e_.[[ExportName]], « », « »).
154 | 1. If _resolution_ is *null* or _resolution_ is `"ambiguous"`, throw a *SyntaxError* exception.
155 | 1. Assert: All named exports from _module_ are resolvable.
156 | 1. Let _envRec_ be _env_'s EnvironmentRecord.
157 | 1. For each ImportEntry Record _in_ in _module_.[[ImportEntries]], do
158 | 1. Let _importedModule_ be ! HostResolveImportedModule(_module_, _in_.[[ModuleRequest]]).
159 | 1. NOTE: The above call cannot fail because imported module requests are a subset of _module_.[[RequestedModules]], and these have been resolved earlier in this algorithm.
160 | 1. If _in_.[[ImportName]] is `"*"`, then
161 | 1. Let _namespace_ be ? GetModuleNamespace(_importedModule_).
162 | 1. Perform ! _envRec_.CreateImmutableBinding(_in_.[[LocalName]], *true*).
163 | 1. Call _envRec_.InitializeBinding(_in_.[[LocalName]], _namespace_).
164 | 1. Else,
165 | 1. Let _resolution_ be ? _importedModule_.ResolveExport(_in_.[[ImportName]], « », « »).
166 | 1. If _resolution_ is *null* or _resolution_ is `"ambiguous"`, throw a *SyntaxError* exception.
167 | 1. If _resolution_ is `"pending"`, then append _in_ to _module_.[[PendingImportEntries]].
168 | 1. Else, call _envRec_.CreateImportBinding(_in_.[[LocalName]], _resolution_.[[Module]], _resolution_.[[BindingName]]).
169 | 1. Let _varDeclarations_ be the VarScopedDeclarations of _code_.
170 | 1. Let _declaredVarNames_ be a new empty List.
171 | 1. For each element _d_ in _varDeclarations_ do
172 | 1. For each element _dn_ of the BoundNames of _d_ do
173 | 1. If _dn_ is not an element of _declaredVarNames_, then
174 | 1. Perform ! _envRec_.CreateMutableBinding(_dn_, *false*).
175 | 1. Call _envRec_.InitializeBinding(_dn_, *undefined*).
176 | 1. Append _dn_ to _declaredVarNames_.
177 | 1. Let _lexDeclarations_ be the LexicallyScopedDeclarations of _code_.
178 | 1. For each element _d_ in _lexDeclarations_ do
179 | 1. For each element _dn_ of the BoundNames of _d_ do
180 | 1. If IsConstantDeclaration of _d_ is *true*, then
181 | 1. Perform ! _envRec_.CreateImmutableBinding(_dn_, *true*).
182 | 1. Else,
183 | 1. Perform ! _envRec_.CreateMutableBinding(_dn_, *false*).
184 | 1. If _d_ is a |GeneratorDeclaration| production or a |FunctionDeclaration| production, then
185 | 1. Let _fo_ be the result of performing InstantiateFunctionObject for _d_ with argument _env_.
186 | 1. Call _envRec_.InitializeBinding(_dn_, _fo_).
187 | 1. Return NormalCompletion(~empty~).
188 |
189 |
190 |
191 |
192 |
193 |
ModuleEvaluation() Concrete Method
194 |
The ModuleEvaluation concrete method of a Source Text Module Record performs the following steps:
195 |
196 | 1. Let _module_ be this Source Text Module Record.
197 | 1. Assert: ModuleDeclarationInstantiation has already been invoked on _module_ and successfully completed.
198 | 1. Assert: _module_.[[Realm]] is not *undefined*.
199 | 1. If _module_.[[Evaluated]] is *true*, return *undefined*.
200 | 1. Set _module_.[[Evaluated]] to *true*.
201 | 1. For each String _required_ that is an element of _module_.[[RequestedModules]] do,
202 | 1. Let _requiredModule_ be ! HostResolveImportedModule(_module_, _required_).
203 | 1. NOTE: ModuleDeclarationInstantiation must be completed prior to invoking this method, so every requested module is guaranteed to resolve successfully.
204 | 1. Perform ? _requiredModule_.ModuleEvaluation().
205 | 1. Let _env_ be _module_.[[Environment]].
206 | 1. Let _envRec_ be _env_'s EnvironmentRecord.
207 | 1. For each ImportEntry Record _in_ in _module_.[[PendingImportEntries]], do
208 | 1. Let _resolution_ be ? _importedModule_.ResolveExport(_in_.[[ImportName]], « », « »).
209 | 1. If _resolution_ is *null* or _resolution_ is `"ambiguous"` or _resultion_ is `"pending"`, throw a *SyntaxError* exception.
210 | 1. Remove ImportEntry Record _in_ from _module_.[[PendingImportEntries]].
211 | 1. Call _envRec_.CreateImportBinding(_in_.[[LocalName]], _resolution_.[[Module].
212 | 1. Let _moduleCxt_ be a new ECMAScript code execution context.
213 | 1. Set the Function of _moduleCxt_ to *null*.
214 | 1. Set the Realm of _moduleCxt_ to _module_.[[Realm]].
215 | 1. Set the ScriptOrModule of _moduleCxt_ to _module_.
216 | 1. Assert: _module_ has been linked and declarations in its module environment have been instantiated.
217 | 1. Set the VariableEnvironment of _moduleCxt_ to _module_.[[Environment]].
218 | 1. Set the LexicalEnvironment of _moduleCxt_ to _module_.[[Environment]].
219 | 1. Suspend the currently running execution context.
220 | 1. Push _moduleCxt_ on to the execution context stack; _moduleCxt_ is now the running execution context.
221 | 1. Let _result_ be the result of evaluating _module_.[[ECMAScriptCode]].
222 | 1. Suspend _moduleCxt_ and remove it from the execution context stack.
223 | 1. Resume the context that is now on the top of the execution context stack as the running execution context.
224 | 1. Return Completion(_result_).
225 |
226 |
227 |
228 |
229 |
230 |
The abstract operation ParseModule with arguments _sourceText_, _realm_, and _hostDefined_ creates a Source Text Module Record based upon the result of parsing _sourceText_ as a |Module|. ParseModule performs the following steps:
232 |
233 | 1. Assert: _sourceText_ is an ECMAScript source text (see clause ).
234 | 1. Parse _sourceText_ using |Module| as the goal symbol and analyze the parse result for any Early Error conditions. If the parse was successful and no early errors were found, let _body_ be the resulting parse tree. Otherwise, let _body_ be a List of one or more *SyntaxError* or *ReferenceError* objects representing the parsing errors and/or early errors. Parsing and early error detection may be interweaved in an implementation dependent manner. If more than one parsing error or early error is present, the number and ordering of error objects in the list is implementation dependent, but at least one must be present.
235 | 1. If _body_ is a List of errors, then return _body_.
236 | 1. Let _requestedModules_ be the ModuleRequests of _body_.
237 | 1. Let _importEntries_ be ImportEntries of _body_.
238 | 1. Let _pendingImportEntries_ be a new empty List.
239 | 1. Let _importedBoundNames_ be ImportedLocalNames(_importEntries_).
240 | 1. Let _indirectExportEntries_ be a new empty List.
241 | 1. Let _localExportEntries_ be a new empty List.
242 | 1. Let _starExportEntries_ be a new empty List.
243 | 1. Let _exportEntries_ be ExportEntries of _body_.
244 | 1. For each record _ee_ in _exportEntries_, do
245 | 1. If _ee_.[[ModuleRequest]] is *null*, then
246 | 1. If _ee_.[[LocalName]] is not an element of _importedBoundNames_, then
247 | 1. Append _ee_ to _localExportEntries_.
248 | 1. Else,
249 | 1. Let _ie_ be the element of _importEntries_ whose [[LocalName]] is the same as _ee_.[[LocalName]].
250 | 1. If _ie_.[[ImportName]] is `"*"`, then
251 | 1. Assert: This is a re-export of an imported module namespace object.
252 | 1. Append _ee_ to _localExportEntries_.
253 | 1. Else this is a re-export of a single name,
254 | 1. Append to _indirectExportEntries_ the Record {[[ModuleRequest]]: _ie_.[[ModuleRequest]], [[ImportName]]: _ie_.[[ImportName]], [[LocalName]]: *null*, [[ExportName]]: _ee_.[[ExportName]] }.
255 | 1. Else if _ee_.[[ImportName]] is `"*"`, then
256 | 1. Append _ee_ to _starExportEntries_.
257 | 1. Else,
258 | 1. Append _ee_ to _indirectExportEntries_.
259 | 1. Return Source Text Module Record {[[Realm]]: _realm_, [[Environment]]: *undefined*, [[HostDefined]]: _hostDefined_, [[Namespace]]: *undefined*, [[Evaluated]]: *false*, [[ECMAScriptCode]]: _body_, [[RequestedModules]]: _requestedModules_, [[ImportEntries]]: _importEntries_, [[PendingImportEntries]]: _pendingImportEntries_, [[LocalExportEntries]]: _localExportEntries_, [[StarExportEntries]]: _starExportEntries_, [[IndirectExportEntries]]: _indirectExportEntries_}.
260 |
261 |
262 |
An implementation may parse module source text and analyze it for Early Error conditions prior to the evaluation of ParseModule for that module source text. However, the reporting of any errors must be deferred until the point where this specification actually performs ParseModule upon that source text.