forked from tc39/proposal-import-attributes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspec.emu
More file actions
771 lines (711 loc) · 36.1 KB
/
spec.emu
File metadata and controls
771 lines (711 loc) · 36.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
<!doctype html>
<meta charset="utf8">
<script src="ecmarkup.js"></script>
<link rel="stylesheet" href="ecmarkup.css">
<title>Import Assertions</title>
<pre class="metadata">
title: Import Assertions
status: proposal
stage: 2
location: https://github.com/tc39/proposal-import-assertions
copyright: false
contributors: Sven Sauleau, Myles Borins, Daniel Ehrenberg, Daniel Clark, Nicolò Ribaudo
</pre>
<script>
document.addEventListener("DOMContentLoaded", () => {
// Ecmarkup only supports annotating algorithm steps with a single attribute,
// so we map [normative-optional][legacy] to [normative-optional-legacy].
document.querySelectorAll("[normative-optional-legacy]").forEach(el => {
el.setAttribute("normative-optional", "");
el.setAttribute("legacy", "");
});
// Ecmarkup only injects the clause-attributes-tag header into
// normative-optional/legacy emu-clause elements.
document.querySelectorAll("li[normative-optional][legacy], ins[normative-optional][legacy]").forEach(el => {
el.insertAdjacentHTML("afterbegin", `
<div class="clause-attributes-tag">
<a href="https://tc39.es/ecma262/#sec-conformance">Normative Optional</a>,
<a href="https://tc39.es/ecma262/#sec-conformance">Legacy</a>
</div>
`);
});
})
</script>
<style>
li[normative-optional] {
display: list-item;
}
ins[normative-optional] > emu-rhs {
padding-left: 60px;
}
</style>
<emu-intro id="intro">
<h1>Import Assertions</h1>
<p>See <a href="https://github.com/tc39/proposal-import-assertions/blob/master/README.md">the explainer</a> for information.</p>
<p>The relevant syntax changes are in the <a href="#sec-left-hand-side-expressions">Import Calls</a> and <a href="#sec-imports">Imports</a> sections.</p>
<p>This proposal would ideally use the `with` keyword to denote assertions, but there are existing implementations based on the previous version of the proposal using the `assert` keyword. Due to potential web compatibility risks, the proposal still includes `assert` marked as <emu-xref href="#sec-conformance">normative optional</emu-xref> and <emu-xref href="#sec-conformance">legacy</emu-xref> in sections <emu-xref href="#sec-evaluate-import-call"></emu-xref> and <emu-xref href="#sec-imports"></emu-xref>. Usage of the old syntax is discouraged, and it removal is being investigated.</p>
</emu-intro>
<emu-clause id="sec-ecmascript-language-expressions" number="13">
<h1>ECMAScript Language: Expressions</h1>
<emu-clause id="sec-left-hand-side-expressions" number="3">
<h1>Left-Hand-Side Expressions</h1>
<h2>Syntax</h2>
<emu-grammar type="definition">
ImportCall[Yield, Await] :
`import` `(` AssignmentExpression[+In, ?Yield, ?Await] <ins>`,`?</ins> `)`
<ins>`import` `(` AssignmentExpression[+In, ?Yield, ?Await] `,` AssignmentExpression[+In, ?Yield, ?Await] `,`? `)`</ins>
</emu-grammar>
<emu-clause id="sec-import-calls" number="10">
<h1>Import Calls</h1>
<emu-clause id="sec-import-call-runtime-semantics-evaluation" type="sdo">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar><ins>ImportCall : `import` `(` AssignmentExpression `,`? `)`</ins></emu-grammar>
<emu-alg>
1. <ins>Return ? EvaluateImportCall(|AssignmentExpression|).</ins>
</emu-alg>
<emu-grammar><ins>ImportCall : `import` `(` AssignmentExpression `,` AssignmentExpression `,`? `)`</ins></emu-grammar>
<emu-alg>
1. <ins>Return ? EvaluateImportCall(the first |AssignmentExpression|, the second |AssignmentExpression|).</ins>
</emu-alg>
<emu-grammar><del>ImportCall : `import` `(` AssignmentExpression `)`</del></emu-grammar>
<emu-alg>
1. <del>Let _referrer_ be GetActiveScriptOrModule().</del>
1. <del>If _referrer_ is *null*, set _referrer_ to the current Realm Record.</del>
1. <del>Let _argRef_ be ? Evaluation of |AssignmentExpression|.</del>
1. <del>Let _specifier_ be ? GetValue(_argRef_).</del>
1. <del>Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).</del>
1. <del>Let _specifierString_ be Completion(ToString(_specifier_)).</del>
1. <del>IfAbruptRejectPromise(_specifierString_, _promiseCapability_).</del>
1. <del>Perform HostLoadImportedModule(_referrer_, _specifierString_, ~empty~, _promiseCapability_).</del>
1. <del>Return _promiseCapability_.[[Promise]].</del>
</emu-alg>
</emu-clause>
<emu-clause id="sec-evaluate-import-call" type="abstract operation">
<h1>
<ins>
EvaluateImportCall (
_specifierExpression_: a ParseNode,
optional _optionsExpression_: a ParseNode
): a Promise
</ins>
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _referrer_ be GetActiveScriptOrModule().
1. If _referrer_ is *null*, set _referrer_ to the current Realm Record.
1. Let _specifierRef_ be the result of evaluating _specifierExpression_.
1. Let _specifier_ be ? GetValue(_specifierRef_).
1. If _optionsExpression_ is present, then
1. Let _optionsRef_ be the result of evaluating _optionsExpression_.
1. Let _options_ be ? GetValue(_optionsRef_).
1. Else,
1. Let _options_ be *undefined*.
1. Let _promiseCapability_ be ! NewPromiseCapability(%Promise%).
1. Let _specifierString_ be Completion(ToString(_specifier_)).
1. IfAbruptRejectPromise(_specifierString_, _promiseCapability_).
1. Let _assertions_ be a new empty List.
1. If _options_ is not *undefined*, then
1. If Type(_options_) is not Object,
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
1. Return _promiseCapability_.[[Promise]].
1. Let _assertionsObj_ be Completion(Get(_options_, *"with"*)).
1. IfAbruptRejectPromise(_assertionsObj_, _promiseCapability_).
1. [normative-optional-legacy=""] If _assertionsObj_ is *undefined*, then
1. Let _assertionsObj_ be Completion(Get(_options_, *"assert"*)).
1. IfAbruptRejectPromise(_assertionsObj_, _promiseCapability_).
1. If _assertionsObj_ is not *undefined*,
1. If Type(_assertionsObj_) is not Object,
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
1. Return _promiseCapability_.[[Promise]].
1. Let _keys_ be Completion(EnumerableOwnPropertyNames(_assertionsObj_, ~key~)).
1. IfAbruptRejectPromise(_keys_, _promiseCapability_).
1. For each String _key_ of _keys_,
1. Let _value_ be Completion(Get(_assertionsObj_, _key_)).
1. IfAbruptRejectPromise(_value_, _promiseCapability_).
1. If Type(_value_) is not String, then
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
1. Return _promiseCapability_.[[Promise]].
1. Append the ImportAssertion Record { [[Key]]: _key_, [[Value]]: _value_ } to _assertions_.
1. If AllImportAssertionsSupported(_assertions_) is *false*, then
1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « a newly created *TypeError* object »).
1. Return _promiseCapability_.[[Promise]].
1. Sort _assertions_ by the code point order of the [[Key]] of each element. NOTE: This sorting is observable only in that hosts are prohibited from distinguishing among assertions by the order they occur in.
1. Let _moduleRequest_ be a new ModuleRequest Record { [[Specifier]]: _specifierString_, [[Assertions]]: _assertions_ }.
1. Perform HostLoadImportedModule(_referrer_, _moduleRequest_, ~empty~, _promiseCapability_).
1. Return _promiseCapability_.[[Promise]].
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-ecmascript-language-scripts-and-modules" number="16">
<h1>ECMAScript Language: Scripts and Modules</h1>
<emu-clause id="sec-modules" number="2">
<h1>Modules</h1>
<emu-clause id="sec-module-semantics">
<h1>Module Semantics</h1>
<emu-clause id="sec-modulerequest-record">
<h1><ins>ModuleRequest and ImportAssertion Records</ins></h1>
<p>A <dfn id="modulerequest-record" variants="ModuleRequest Records">ModuleRequest Record</dfn> represents the request to import a module with given import assertions. It consists of the following fields:</p>
<emu-table id="table-modulerequest-fields" caption="ModuleRequest Record fields">
<table>
<tbody>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
<tr>
<td>
[[Specifier]]
</td>
<td>
String
</td>
<td>
The module specifier
</td>
</tr>
<tr>
<td>
[[Assertions]]
</td>
<td>
a List of ImportAssertion Records
</td>
<td>
The import assertions
</td>
</tr>
</tbody>
</table>
</emu-table>
<p>An <dfn id="importassertion-record" variants="ImportAssertion Records">ImportAssertion Record</dfn> consists of the following fields:</p>
<emu-table id="table-importassertion-fields" caption="ImportAssertion Record fields">
<table>
<tbody>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
<tr>
<td>
[[Key]]
</td>
<td>
String
</td>
<td>
The assertion key
</td>
</tr>
<tr>
<td>
[[Value]]
</td>
<td>
String
</td>
<td>
The assertion value
</td>
</tr>
</tbody>
</table>
</emu-table>
<emu-note type="editor">In general, this proposal replaces places where module specifiers are passed around with ModuleRequest Records. For example, several syntax-directed operations, such as ModuleRequests produce Lists of ModuleRequest Records rather than Lists of Strings which are interpreted as module specifiers. Some algorithms like ImportEntries and ImportEntriesForModule pass around ModuleRequest Records rather than Strings, in a way which doesn't require any particular textual change. Additionally, record fields in Cyclic Module Records and Source Text Module Records which contained Lists of Strings are replaced by Lists of ModuleRequest Records, as indicated above.</emu-note>
</emu-clause>
<emu-clause id="sec-static-semantics-modulerequests" type="sdo" number="3">
<h1>
Static Semantics: ModuleRequests ( ): a List of <del>Strings</del><ins>ModuleRequest Records</ins>
</h1>
<dl class="header">
</dl>
<emu-grammar>Module : [empty]</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-grammar>ModuleItemList : ModuleItem</emu-grammar>
<emu-alg>
1. Return ModuleRequests of |ModuleItem|.
</emu-alg>
<emu-grammar>ModuleItemList : ModuleItemList ModuleItem</emu-grammar>
<emu-alg>
1. Let _moduleNames_ be ModuleRequests of |ModuleItemList|.
1. Let _additionalNames_ be ModuleRequests of |ModuleItem|.
1. For each String _name_ of _additionalNames_, do
1. If _moduleNames_ does not contain _name_, then
1. Append _name_ to _moduleNames_.
1. Return _moduleNames_.
</emu-alg>
<emu-grammar>ModuleItem : StatementListItem</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-grammar>
ImportDeclaration : `import` ImportClause FromClause `;`
</emu-grammar>
<emu-alg>
1. <del>Return ModuleRequests of |FromClause|.</del>
1. <ins>Let _specifier_ be SV of the |ModuleSpecifier| contained in |FromClause|.</ins>
1. <ins>Return a ModuleRequest Record { [[Specifer]]: _specifier_, [[Assertions]]: « » }.</ins>
</emu-alg>
<emu-grammar>
<ins>ImportDeclaration : `import` ImportClause FromClause AssertClause `;`</ins>
</emu-grammar>
<emu-alg>
1. <ins>Let _specifier_ be SV of the |ModuleSpecifier| contained in |FromClause|.</ins>
1. <ins>Let _assertions_ be AssertClauseToAssertions of |AssertClause|.</ins>
1. <ins>Return a ModuleRequest Record { [[Specifer]]: _specifier_, [[Assertions]]: _assertions_ }.</ins>
</emu-alg>
<emu-grammar><del>ModuleSpecifier : StringLiteral</del></emu-grammar>
<emu-alg>
1. <del>Return a List whose sole element is the SV of |StringLiteral|.</del>
</emu-alg>
<emu-grammar>
ExportDeclaration : `export` ExportFromClause FromClause `;`
</emu-grammar>
<emu-alg>
1. <del>Return ModuleRequests of |FromClause|.</del>
1. <ins>Let _specifier_ be SV of the |ModuleSpecifier| contained in |FromClause|.</ins>
1. <ins>Return a ModuleRequest Record { [[Specifer]]: _specifier_, [[Assertions]]: « » }.</ins>
</emu-alg>
<emu-grammar>
<ins>ExportDeclaration : `export` ExportFromClause FromClause AssertClause `;`</ins>
</emu-grammar>
<emu-alg>
1. <ins>Let _specifier_ be SV of the |ModuleSpecifier| contained in |FromClause|.</ins>
1. <ins>Let _assertions_ be AssertClauseToAssertions of |AssertClause|.</ins>
1. <ins>Return a ModuleRequest Record { [[Specifer]]: _specifier_, [[Assertions]]: _assertions_ }.</ins>
</emu-alg>
<emu-grammar>
ExportDeclaration :
`export` NamedExports `;`
`export` VariableStatement
`export` Declaration
`export` `default` HoistableDeclaration
`export` `default` ClassDeclaration
`export` `default` AssignmentExpression `;`
</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
</emu-clause>
<emu-clause id="sec-cyclic-module-records" number="5">
<h1>Cyclic Module Records</h1>
<p>A <dfn id="cyclic-module-record" variants="Cyclic Module Records">Cyclic Module Record</dfn> is used to represent information about a module that can participate in dependency cycles with other modules that are subclasses of the Cyclic Module Record type. Module Records that are not subclasses of the Cyclic Module Record type must not participate in dependency cycles with Source Text Module Records.</p>
<p>In addition to the fields defined in <emu-xref href="#table-module-record-fields"></emu-xref> Cyclic Module Records have the additional fields listed in <emu-xref href="#table-cyclic-module-fields"></emu-xref></p>
<emu-table id="table-cyclic-module-fields" caption="Additional Fields of Cyclic Module Records">
<table>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
<tr>
<td>
[[Status]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[EvaluationError]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[DFSIndex]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[DFSAncestorIndex]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[RequestedModules]]
</td>
<td>
a List of <del>Strings</del><ins>ModuleRequest Records</ins>
</td>
<td>
A List of all the |ModuleSpecifier| strings <ins>and import assertions</ins> used by the module represented by this record to request the importation of a module. The List is in source text occurrence order.
</td>
</tr>
<tr>
<td>
[[LoadedModules]]
</td>
<td>
a List of Records with fields [[Specifier]] (a String), <ins>[[Assertions]] (a List of ImportAssertion Records)</ins> and [[Module]] (a Module Record)
</td>
<td>
A map from the specifier strings used by the module represented by this record to request the importation of a module <ins>with the relative assertions</ins> to the resolved Module Record. The list does not contain two different Records with the same <del>[[Specifier]]</del><ins>([[Specifier]], [[Assertions]]) pair</ins>.
</td>
</tr>
<tr>
<td>
[[CycleRoot]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[HasTLA]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[AsyncEvaluation]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[TopLevelCapability]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[AsyncParentModules]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[PendingAsyncDependencies]]
</td>
<td></td>
<td></td>
</tr>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-source-text-module-records" number="6">
<h1>Source Text Module Records</h1>
<p>An <dfn id="importentry-record" variants="ImportEntry Records">ImportEntry Record</dfn> is a Record that digests information about a single declarative import. Each ImportEntry Record has the fields defined in <emu-xref href="#table-importentry-record-fields"></emu-xref>:</p>
<emu-table id="table-importentry-record-fields" caption="ImportEntry Record Fields" oldids="table-39">
<table>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
<tr>
<td>
[[ModuleRequest]]
</td>
<td>
<del>String</del>
<ins>ModuleRequest Record</ins>
</td>
<td>
<del>String value of the |ModuleSpecifier| of the |ImportDeclaration|.</del>
<ins>ModuleRequest Record representing the |ModuleSpecifier| and import assertions of the |ImportDeclaration|.</ins>
</td>
</tr>
<tr>
<td>
[[ImportName]]
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>
[[LocalName]]
</td>
<td></td>
<td></td>
</tr>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-HostLoadImportedModule" type="host-defined abstract operation" number="8">
<h1>
HostLoadImportedModule (
_referrer_: a Script Record, a Cyclic Module Record, or a Realm Record,
<del>_specifier_: a String,</del>
<ins>_moduleRequest_: a ModuleRequest Record,</ins>
_hostDefined_: anything,
_payload_: a GraphLoadingState Record or a PromiseCapability Record,
): ~unused~
</h1>
<dl class="header">
<dt>description</dt>
<dd></dd>
</dl>
<emu-note id="note-HostLoadImportedModule-referrer-Realm-Record">
<p>An example of when _referrer_ can be a Realm Record is in a web browser host. There, if a user clicks on a control given by</p>
<pre><code class="html"><button type="button" onclick="import('./foo.mjs')">Click me</button></code></pre>
<p>there will be no active script or module at the time the <emu-xref href="#sec-import-calls">`import()`</emu-xref> expression runs. More generally, this can happen in any situation where the host pushes execution contexts with *null* ScriptOrModule components onto the execution context stack.</p>
</emu-note>
<p>An implementation of HostLoadImportedModule must conform to the following requirements:</p>
<ul>
<li>
The host environment must perform FinishLoadingImportedModule(_referrer_, <del>_specifier_</del><ins>_moduleRequest_</ins>, _payload_, _result_), where _result_ is either a normal completion containing the loaded Module Record or a throw completion, either synchronously or asynchronously.
</li>
<li>
If this operation is called multiple times with the same <del>(_referrer_, _specifier_) pair</del><ins>(_referrer_, _moduleRequest_.[[Specifer]], _moduleRequest_.[[Assertions]]) triple</ins> and it performs FinishLoadingImportedModule(_referrer_, <del>_specifier_</del><ins>_moduleRequest_</ins>, _payload_, _result_) where _result_ is a normal completion, then it must perform FinishLoadingImportedModule(_referrer_, <del>_specifier_</del><ins>_moduleRequest_</ins>, _payload_, _result_) with the same _result_ each time.
</li>
<li>
The operation must treat _payload_ as an opaque value to be passed through to FinishLoadingImportedModule.
</li>
</ul>
<p>The actual process performed is host-defined, but typically consists of performing whatever I/O operations are necessary to load the appropriate Module Record. Multiple different <del>(_referrer_, _specifier_) pairs</del><ins>(_referrer_, _moduleRequest_.[[Specifer]], _moduleRequest_.[[Assertions]]) triples</ins> may map to the same Module Record instance. The actual mapping semantics is host-defined but typically a normalization process is applied to _specifier_ as part of the mapping process. A typical normalization process would include actions such as expansion of relative and abbreviated path specifiers.</p>
<emu-note>
<p>There are three possible ways to handle multiple imports of the same module with different valid assertions:</p>
<ul>
<li><strong>Race</strong> and use the assertion that was requested by the first import. The second usage is ignored.</li>
<li><strong>Reject</strong> the module graph and don't load if assertions differ. This may be bad for composition: using two unrelated packages together could break, if they load the same module with disagreeing assertions.</li>
<li><strong>Clone</strong> and make two copies of the module, for the different ways it's transformed. These semantics would run counter to the intuition that there is just one copy of a module for each specifier.</li>
</ul>
<p>It's possible that one of these three options may make sense for a module load, on a case-by-case basis by assertion, but it's worth careful thought before making this choice.</p>
</emu-note>
</emu-clause>
<emu-clause id="sec-FinishLoadingImportedModule" type="abstract operation" >
<h1>
FinishLoadingImportedModule (
_referrer_: a Script Record, a Cyclic Module Record, or a Realm Record,
<del>_specifier_: a String,</del>
<ins>_moduleRequest_: a ModuleRequest Record,</ins>
_payload_: a GraphLoadingState Record or a PromiseCapability Record,
_result_: either a normal completion containing a Module Record or a throw completion,
): ~unused~
</h1>
<dl class="header">
<dt>description</dt>
<dd></dd>
</dl>
<emu-alg>
1. If _result_ is a normal completion, then
1. If _referrer_.[[LoadedModules]] contains a Record whose [[Specifier]] is <del>_specifier_</del><ins>_moduleRequest_.[[Specifier]] and AssertionsEqual(_record_.[[Assertions]], _moduleRequest_.[[Assertions]]) is *true*</ins>, then
1. Assert: That Record's [[Module]] is _result_.[[Value]].
1. Else, append the Record { [[Specifier]]: <del>_specifier_</del><ins>_moduleRequest_.[[Specifer]]</ins>, <ins>[[Assertions]]: _moduleRequest_.[[Assertions]]</ins>, [[Module]]: _result_.[[Value]] } to _referrer_.[[LoadedModules]].
1. If _payload_ is a GraphLoadingState Record, then
1. Perform ContinueModuleLoading(_payload_, _result_).
1. Else,
1. Perform ContinueDynamicImport(_payload_, _result_).
1. Return ~unused~.
</emu-alg>
<emu-note type="editor">
<p>The description of the [[LoadedModules]] field of Realm Record, Script Record, and Cyclic Module Record should be updated to include the [[Assertions]] field.</p>
</emu-note>
<emu-clause id="sec-FinishLoadingImportedModule-AssertionsEqual" type="abstract operation">
<h1>
<ins>
AssertionsEqual (
_left_: a List of ImportAssertion Records,
_right_: a List of ImportAssertion Records,
): a Boolean
</ins>
</h1>
<dl class="header">
<dt>description</dt>
<dd></dd>
</dl>
<emu-alg>
1. If the number of elements in _left_ is not the same as the number of elements in _right_, return *false*.
1. For each ImportAssertion Record _r_ of _left_, do
1. Let _found_ be *false*.
1. For each ImportAssertion Record _s_ of _right_, do
1. If _r_.[[Key]] is _s_.[[Key]] and _r_.[[Value]] is _s_.[[Value]], then
1. Set _found_ to *true*.
1. If _found_ is *false*, return *false*.
1. Return *true*.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-AllImportAssertionsSupported" type="abstract operation">
<h1>
<ins>
AllImportAssertionsSupported (
_assertions_: a List of ImportAssertion Records,
): a Boolean
</ins>
</h1>
<dl class="header">
<dt>description</dt>
<dd></dd>
</dl>
<emu-alg>
1. Let _supported_ be HostGetSupportedImportAssertions().
1. For each Record _assertion_ of _assertions_, do
1. If _supported_ does not contain _assertion_.[[Key]], return *false*.
1. Return *true*.
</emu-alg>
<emu-clause id="sec-hostgetsupportedimportassertions" type="host-defined abstract operation">
<h1>
<ins>
HostGetSupportedImportAssertions ( ): a List of Strings
</ins>
</h1>
<dl class="header">
<dt>description</dt>
<dd>It allows host environments to specify which import assertions they support. Only assertions with supported keys will be provided to the host.</dd>
</dl>
<p>An implementation of HostGetSupportedImportAssertions must conform to the following requrements:</p>
<ul>
<li>It must return a List of Strings, each indicating a supported assertion.</li>
<li>Each time this operation is called, it must return the same List with the same contents.</li>
<li>An implementation of HostGetSupportedImportAssertions must always complete normally (i.e., not return an abrupt completion).</li>
</ul>
<p>The default implementation of HostGetSupportedImportAssertions is to return a new empty List.</p>
<emu-note>The purpose of requiring the host to specify its supported import assertions, rather than passing all assertions to the host and letting it then choose which ones it wants to handle, is to ensure that unsupported assertions are handled in a consistent way across different hosts.</emu-note>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-imports">
<h1>Imports</h1>
<emu-grammar type="definition">
ImportDeclaration :
`import` ImportClause FromClause `;`
`import` ModuleSpecifier `;`
<ins>`import` ImportClause FromClause [no LineTerminator here] AssertClause `;`</ins>
<ins>`import` ModuleSpecifier [no LineTerminator here] AssertClause `;`</ins>
<ins>
AssertClause :
`with` `{` `}`
`with` `{` AssertEntries `,`? `}`
<ins normative-optional="" legacy="">
`assert` `{` `}`
`assert` `{` AssertEntries `,`? `}`
</ins>
AssertEntries :
AssertionKey `:` StringLiteral
AssertionKey `:` StringLiteral `,` AssertEntries
AssertionKey:
IdentifierName
StringLiteral
</ins>
</emu-grammar>
<emu-clause id="sec-imports-static-semantics-early-errors">
<h1>Static Semantics: Early Errors</h1>
<emu-grammar>
<ins>
AssertClause :
`with` `{` AssertEntries `,`? `}`
`assert` `{` AssertEntries `,`? `}`
</ins>
</emu-grammar>
<ul>
<li><ins>It is a Syntax Error if AssertClauseToAssertions of |AssertClause| has two entries _a_ and _b_ such that _a_.[[Key]] is _b_.[[Key]].</ins></li>
<li><ins>It is a Syntax Error if AllImportAssertionsSupported(AssertClauseToAssertions of |AssertClause|) is *false*.</ins></li>
</ul>
</emu-clause>
<emu-clause id="sec-assert-clause-to-assertions" type="sdo">
<h1>
<ins>
Static Semantics: AssertClauseToAssertions (
): a List of ImportAssertion Records
</ins>
</h1>
<dl class="header">
</dl>
<emu-grammar>
AssertClause :
`with` `{` `}`
`assert` `{` `}`
</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-grammar>
AssertClause :
`with` `{` AssertEntries `,`? `}`
`assert` `{` AssertEntries `,`? `}`
</emu-grammar>
<emu-alg>
1. Let _assertions_ be AssertClauseToAssertions of |AssertEntries|.
1. Sort _assertions_ by the code point order of the [[Key]] of each element. NOTE: This sorting is observable only in that hosts are prohibited from distinguishing among assertions by the order they occur in.
1. Return _assertions_.
</emu-alg>
<emu-grammar> AssertEntries : AssertionKey `:` StringLiteral </emu-grammar>
<emu-alg>
1. Let _key_ be StringValue of |AssertionKey|.
1. Let _entry_ be the ImportAssertion Record { [[Key]]: _key_, [[Value]]: StringValue of |StringLiteral| }.
1. Return « _entry_ ».
</emu-alg>
<emu-grammar> AssertEntries : AssertionKey `:` StringLiteral `,` AssertEntries </emu-grammar>
<emu-alg>
1. Let _key_ be StringValue of |AssertionKey|.
1. Let _entry_ be the ImportAssertion Record { [[Key]]: _key_, [[Value]]: StringValue of |StringLiteral| }.
1. Let _rest_ be AssertClauseToAssertions of |AssertEntries|.
1. Return the list-concatenation of « _entry_ » and _rest_.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-exports">
<h1>Exports</h1>
<emu-grammar>
ExportDeclaration :
`export` ExportFromClause FromClause `;`
<ins>`export` ExportFromClause FromClause [no LineTerminator here] AssertClause `;`</ins>
`export` NamedExports `;`
`export` VariableStatement[~Yield, ~Await]
`export` Declaration[~Yield, ~Await]
`export` `default` HoistableDeclaration[~Yield, ~Await, +Default]
`export` `default` ClassDeclaration[~Yield, ~Await, +Default]
`export` `default` [lookahead <! {`function`, `async` [no |LineTerminator| here] `function`, `class`}] AssignmentExpression[+In, ~Yield, ~Await] `;`
</emu-grammar>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-annex id="sec-host-integration">
<h1>Sample host integration: The Web embedding</h1>
<p>The import assertions proposal is intended to give key information about how modules are interpreted to hosts. For the Web embedding and environments which aim to be similar to it, the string is interpreted as the "module type". This is not the primary way the module type is determined (which, on the Web, would be the MIME type, and in other environments may be the file extension), but rather a secondary check which is required to pass for the module graph to load.</p>
<p>In the Web embedding, the following changes would be made to the HTML specification for import assertions:</p>
<ul>
<li>The <a href="https://html.spec.whatwg.org/#module-script">module script</a> would have an additional item, which would be the module type, as a string (e.g., *"json"*), or *undefined* for a JavaScript module.</li>
<li>HostLoadImportedModule would take a ModuleRequest Record parameter in place of a specifier string, which would be passed down through several abstract operations to reach the <a href="https://html.spec.whatwg.org/#fetch-a-single-module-script">fetch a single module script</a> algorithm. Somewhere near the entrypoint, if the ModuleRequest Record's [[Assertions]] field has an element _entry_ such that _entry_.[[Key]] is *"type"*, then let _type_ be _entry_.[[Value]]; otherwise let _type_ be *undefined*. If the type is invalid, then an exception is thrown and module loading fails. Otherwise, this will equal the module type, if the module can be successfully fetched with a matching MIME type.</li>
<li>In the <a href="https://html.spec.whatwg.org/#fetch-the-descendants-of-a-module-script">fetch the descendents of a module script</a> algorithm, when iterating over [[RequestedModules]], the elements are ModuleRequest Records rather than just specifier strings; these Records is passed on to the internal module script graph fetching procedure (which sends it to "fetch a single module script". Other usage sites of [[RequestedModules]] ignore the assertion.</li>
<li>"Fetch a single module script" would check the assertion in two places:
<ul>
<li>The module map is keyed with both the absolute URL and the module type, so an existing entry will be found only if its _type_ matches.</li>
<li>When a new module is fetched, before writing it into the module map, the MIME type is checked to ensure that it matches _type_. (Note that the interpretation of the module is still driven by the MIME type, but once the MIME type is established, this is checked against the _type_.) If they differ, then an exception is thrown and module loading fails. The _type_ is written into the module script as the type.</li>
</ul>
</li>
</ul>
<p>The module map is keyed by the absolute URL and the _type_. Initially no other import assertions are supported, so they are not present.</p>
</emu-annex>