-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathspec.emu
2518 lines (2392 loc) · 111 KB
/
spec.emu
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
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<meta charset="utf8">
<link rel="stylesheet" href="./spec.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<script src="./spec.js"></script>
<pre class="metadata">
title: Module Declarations
stage: 2
contributors: Daniel Ehrenberg, Nicolò Ribaudo
</pre>
<emu-clause id="sec-module-declarations">
<h1><ins>Module Declarations</ins></h1>
<emu-note type="editor">
<p>This proposal builds on top of <a href="https://tc39.es/proposal-js-module-blocks/">the Module Expressions proposal</a>, which introduces the following production:</p>
<emu-grammar type="definition">
ModuleExpression :
`module` [no LineTerminator here] `{` ModuleBody? `}`
</emu-grammar>
</emu-note>
<h2>Syntax</h2>
<emu-grammar type="definition">
ModuleDeclaration[Default] :
`module` [no LineTerminator here] Identifier `{` ModuleBody? `}`
[+Default] `module` [no LineTerminator here] `{` ModuleBody? `}`
</emu-grammar>
<emu-clause id="sec-module-declarations-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>
ModuleDeclaration :
`module` Identifier `{` ModuleBody? `}`
`module` `{` ModuleBody? `}`
</emu-grammar>
<emu-alg>
1. Return ~empty~.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-syntax-directed-operations" number="8">
<h1>Syntax-Directed Operations</h1>
<emu-clause id="sec-syntax-directed-operations-scope-analysis" number="2">
<h1>Scope Analysis</h1>
<emu-clause id="sec-static-semantics-boundnames" type="sdo" number="1">
<h1>Static Semantics: BoundNames ( ): a List of Strings</h1>
<dl class="header">
</dl>
<emu-grammar>
<ins>ModuleDeclaration : `module` Identifier `{` ModuleBody? `}`</ins>
</emu-grammar>
<emu-alg>
1. Return the BoundNames of Identifier.
</emu-alg>
<emu-grammar>
<ins>ModuleDeclaration : `module` `{` ModuleBody? `}`</ins>
</emu-grammar>
<emu-alg>
1. Return « *"\*default\*"* ».
</emu-alg>
<emu-grammar>
<ins>ExportDeclaration : `export` `default` ModuleDeclaration</ins>
</emu-grammar>
<emu-alg>
1. Let _declarationNames_ be the BoundNames of |ModuleDeclaration|.
1. If _declarationNames_ does not include the element *"\*default\*"*, append *"\*default\*"* to _declarationNames_.
1. Return _declarationNames_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-static-semantics-isconstantdeclaration" type="sdo" number="3">
<h1>Static Semantics: IsConstantDeclaration ( ): a Boolean</h1>
<dl class="header">
</dl>
<emu-grammar>
<ins>
ModuleDeclaration :
`module` Identifier `{` ModuleBody? `}`
`module` `{` ModuleBody? `}`
</ins>
</emu-grammar>
<emu-alg>
1. Return *true*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-static-semantics-lexicallyscopeddeclarations" type="sdo" number="5">
<h1>Static Semantics: LexicallyScopedDeclarations ( ): a List of Parse Nodes</h1>
<dl class="header">
</dl>
<emu-grammar>
<ins>Declaration : ModuleDeclaration</ins>
</emu-grammar>
<emu-alg>
1. Return a List whose sole element is |ModuleDeclaration|.
</emu-alg>
</emu-clause>
<emu-clause id="sec-containsundefinedmodulereference" type="sdo" number="12">
<h1>
<ins>
Static Semantics: ContainsUndefinedModuleReference (
_declaredModules_: a List of Strings,
): a Boolean
</ins>
</h1>
<dl class="header">
</dl>
<p>Unless explicitly specified otherwise, all nonterminals have an implicit definition for ContainsUndefinedModuleReference with argument _declaredModules_.The implicit definition applies ContainsUndefinedModuleReference with argument _declaredModules_ to the nonterminal's inner nonterminals, and returns *true* if it's *true* for any of them. For example, ContainsUndefinedModuleReference of |ExponentiationExpression| is implicitly defined as follows:</p>
<emu-grammar example>
ExponentiationExpression : UpdateExpression `**` ExponentiationExpression
</emu-grammar>
<emu-alg example>
1. Let _hasUndefinedRef_ be ContainsUndefinedModuleReference of |UpdateExpression| with argument _declaredModules_.
1. If _hasUndefinedRef_ is *true*, return *true*.
1. Return ContainsUndefinedModuleReference of |ExponentiationExpression| with argument _declaredModules_.
</emu-alg>
<p>The following productions have a different definition of ContainsUndefinedModuleReference:</p>
<emu-grammar>
ModuleSpecifier : Identifier
</emu-grammar>
<emu-alg>
1. Let _reference_ be the StringValue of |Identifier|.
1. If _reference_ is in _declaredModules_, return *false*.
1. Return *true*.
</emu-alg>
<emu-grammar>
ModuleBody : ModuleItemList
</emu-grammar>
<emu-alg>
1. Let _localDeclaredModules_ be DeclaredModuleNames of |ModuleItemList|.
1. Let _lexNames_ be the LexicallyDeclaredNames of |ModuleItemList|.
1. Let _varNames_ be the VarDeclaredNames of |ModuleItemList|.
1. Let _visibleDeclaredModules_ be a new List containing the elements of _declaredModules_ that are not in _lexNames_ or _varNames_.
1. Append all the elements of _localDeclaredModules_ to _visibleDeclaredModules_.
1. Return ContainsUndefinedModuleReference of |ModuleItemList| with argument _visibleDeclaredModules_.
</emu-alg>
<emu-grammar>
ScriptBody : StatementList
</emu-grammar>
<emu-alg>
1. Assert: _declaredModules_ is an empty List.
1. Let _localDeclaredModules_ be DeclaredModuleNames of |StatementList|.
1. Return ContainsUndefinedModuleReference of |StatementList| with argument _localDeclaredModules_.
</emu-alg>
<emu-grammar>
FunctionStatementList : StatementList
ClassStaticBlockStatementList : StatementList
Block : `{` StatementList `}`
</emu-grammar>
<emu-alg>
1. Let _lexNames_ be the LexicallyDeclaredNames of |StatementList|.
1. Let _varNames_ be the VarDeclaredNames of |StatementList|.
1. Let _localDeclaredModules_ be the DeclaredModuleNames of |StatementList|.
1. Let _visibleDeclaredModules_ be a new List containing the elements of _declaredModules_ that are not in _lexNames_ or _varNames_.
1. Append each element of _localDeclaredModules_ to _visibleDeclaredModules_.
1. Return ContainsUndefinedModuleReference of |StatementList| with argument _visibleDeclaredModules_.
</emu-alg>
<emu-grammar>
FunctionStatementList : [empty]
ClassStaticBlockStatementList : [empty]
Block : `{` `}`
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
<emu-grammar>
FunctionDeclaration :
`function` BindingIdentifier `(` FormalParameters `)` `{` FunctionBody `}`
`function` `(` FormalParameters `)` `{` FunctionBody `}`
FunctionExpression :
`function` BindingIdentifier? `(` FormalParameters `)` `{` FunctionBody `}`
</emu-grammar>
<emu-alg>
1. If |BindingIdentifier| is present, return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, |FormalParameters|, |FunctionBody|, |BindingIdentifier|).
1. Return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, |FormalParameters|, |FunctionBody|).
</emu-alg>
<emu-grammar>
MethodDefinition : ClassElementName `(` UniqueFormalParameters `)` `{` FunctionBody `}`
</emu-grammar>
<emu-alg>
1. Return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, |UniqueFormalParameters|, |FunctionBody|).
</emu-alg>
<emu-grammar>
MethodDefinition : `set` ClassElementName `(` PropertySetParameterList `)` `{` FunctionBody `}`
</emu-grammar>
<emu-alg>
1. Return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, |PropertySetParameterList|, |FunctionBody|).
</emu-alg>
<emu-grammar>
GeneratorDeclaration :
`function` BindingIdentifier `*` `(` UniqueFormalParameters `)` `{` GeneratorBody `}`
`function` `*` `(` UniqueFormalParameters `)` `{` GeneratorBody `}`
GeneratorExpression :
`function` BindingIdentifier? `*` `(` UniqueFormalParameters `)` `{` GeneratorBody `}`
GeneratorMethod :
`*` ClassElementName `(` UniqueFormalParameters `)` `{` GeneratorBody `}`
</emu-grammar>
<emu-alg>
1. If |BindingIdentifier| is present, return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, |UniqueFormalParameters|, |GeneratorBody|, |BindingIdentifier|).
1. Return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, |UniqueFormalParameters|, |GeneratorBody|).
</emu-alg>
<emu-grammar>
AsyncFunctionDeclaration :
`async` `function` BindingIdentifier `(` UniqueFormalParameters `)` `{` AsyncFunctionBody `}`
`async` `function` `(` UniqueFormalParameters `)` `{` AsyncFunctionBody `}`
AsyncFunctionExpression :
`async` `function` BindingIdentifier? `(` UniqueFormalParameters `)` `{` AsyncFunctionBody `}`
AsyncMethod :
`async` ClassElementName `(` UniqueFormalParameters `)` `{` AsyncFunctionBody `}`
</emu-grammar>
<emu-alg>
1. If |BindingIdentifier| is present, return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, |UniqueFormalParameters|, |AsyncFunctionBody|, |BindingIdentifier|).
1. Return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, |UniqueFormalParameters|, |AsyncFunctionBody|).
</emu-alg>
<emu-grammar>
AsyncGeneratorDeclaration :
`async` `function` BindingIdentifier `*` `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}`
`async` `function` `*` `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}`
AsyncGeneratorExpression :
`async` `function` BindingIdentifier? `*` `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}`
AsyncGeneratorMethod :
`async` `*` ClassElementName `(` UniqueFormalParameters `)` `{` AsyncGeneratorBody `}`
</emu-grammar>
<emu-alg>
1. If |BindingIdentifier| is present, return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, |UniqueFormalParameters|, |AsyncGeneratorBody|, |BindingIdentifier|).
1. Return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, |UniqueFormalParameters|, |AsyncGeneratorBody|).
</emu-alg>
<emu-grammar>
ArrowFunction : ArrowParameters `=>` ConciseBody
</emu-grammar>
<emu-alg>
1. If |ArrowParameters| is |BindingIdentifier|, let _params_ be |BindingIdentifier|.
1. Else,
1. Let _cover_ be the |CoverParenthesizedExpressionAndArrowParameterList| of |ArrowParameters|.
1. Let _params_ be the |ArrowFormalParameters| that is covered by _cover_.
1. Return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, _params_, |ConciseBody|).
</emu-alg>
<emu-grammar>
AsyncArrowFunction : `async` AsyncArrowBindingIdentifier `=>` AsyncConciseBody
</emu-grammar>
<emu-alg>
1. Let _params_ be the |BindingIdentifier| of |AsyncArrowBindingIdentifier|.
1. Return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, _params_, |AsyncConciseBody|).
</emu-alg>
<emu-grammar>
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead `=>` AsyncConciseBody
</emu-grammar>
<emu-alg>
1. Let _head_ be the |AsyncArrowHead| that is covered by |CoverCallExpressionAndAsyncArrowHead|.
1. Let _params_ be the |ArrowFormalParameters| of _head_.
1. Return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, _params_, |AsyncConciseBody|).
</emu-alg>
<emu-grammar>
ClassDeclaration :
`class` BindingIdentifier ClassTail
`class` ClassTail
ClassExpression :
`class` BindingIdentifier? ClassTail
</emu-grammar>
<emu-alg>
1. Let _visibleDeclaredModules_ be _declaredModules_.
1. If |BindingIdentifier| is present, then
1. Let _id_ be the StringValue of |BindingIdentifier|.
1. Set _visibleDeclaredModules_ to a new List containing the elements of _declaredModules_ that are not equal to _id_.
1. Return ContainsUndefinedModuleReference of |ClassTail| with argument _visibleDeclaredModules_.
</emu-alg>
<emu-grammar>
Catch : `catch` `(` CatchParameter `)` Block
</emu-grammar>
<emu-alg>
1. Return ContainsUndefinedModuleReferenceInFunction(_declaredModules_, |CatchParameter|, |Block|).
</emu-alg>
<emu-clause id="sec-ContainsUndefinedModuleReferenceInFunction" type="abstract operation">
<h1>
ContainsUndefinedModuleReferenceInFunction (
_declaredModules_: a List of Strings,
_params_: a Parse Node,
_body_: a Parse Node,
optional _binding_: a Parse Node,
): a Boolean
</h1>
<dl class="header"></dl>
<emu-alg>
1. Let _boundNames_ be the BoundNames of _params_.
1. If _binding_ is present, append the StringValue of _binding_ to _boundNames_.
1. Let _visibleDeclaredModules_ be a new List containing the elements of _declaredModules_ that are not in _boundNames_.
1. If ContainsUndefinedModuleReference of _params_ with argument _visibleDeclaredModules_ is *true*, return *true*.
1. Let _localDeclaredModules_ be the DeclaredModuleNames of |StatementList|.
1. Append each element of _localDeclaredModules_ to _visibleDeclaredModules_.
1. Return ContainsUndefinedModuleReference of _body_ with argument _visibleDeclaredModules_ is *true*.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-declaredmodulenames" type="sdo">
<h1>
<ins>
Static Semantics: DeclaredModuleNames ( ): a List of Strings
</ins>
</h1>
<dl class="header">
</dl>
<emu-grammar>
ModuleItemList : ModuleItemList ModuleItem
</emu-grammar>
<emu-alg>
1. Let _names1_ be DeclaredModuleNames of |ModuleItemList|.
1. Let _names2_ be DeclaredModuleNames of |ModuleItem|.
1. Return the list-concatenation of _names1_ and _names2_.
</emu-alg>
<emu-grammar>
StatementList : StatementList StatementListItem
</emu-grammar>
<emu-alg>
1. Let _names1_ be DeclaredModuleNames of |StatementList|.
1. Let _names2_ be DeclaredModuleNames of |StatementListItem|.
1. Return the list-concatenation of _names1_ and _names2_.
</emu-alg>
<emu-grammar>
StatementListItem : Statement
</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-grammar>
Declaration :
HoistableDeclaration
LexicalDeclaration
ClassDeclaration
</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-grammar>
Declaration : ModuleDeclaration
</emu-grammar>
<emu-alg>
1. Return BoundNames of |ModuleDeclaration|.
</emu-alg>
<emu-grammar>
ModuleItem : ImportDeclaration
</emu-grammar>
<emu-alg>
1. Return the BoundNames of |ImportDeclaration|.
</emu-alg>
<emu-note>
DeclaredModuleNames includes all the imported bindings, so that using them as import specifiers doesn't throw when parsing the module. However, they will be validated when linking by LoadInternalModule.
</emu-note>
</emu-clause>
<emu-clause id="sec-toplevelmoduledeclarations" type="sdo">
<h1>
<ins>
Static Semantics: TopLevelModuleDeclarations ( ): a List of |ModuleDeclaration| Parse Node
</ins>
</h1>
<dl class="header">
</dl>
<emu-grammar>
ModuleItemList : ModuleItemList ModuleItem
</emu-grammar>
<emu-alg>
1. Let _decls1_ be TopLevelModuleDeclarations of |ModuleItemList|.
1. Let _decls2_ be TopLevelModuleDeclarations of |ModuleItem|.
1. Return the list-concatenation of _decls1_ and _decls2_.
</emu-alg>
<emu-grammar>
ModuleItem : Statement
ModuleItem : ImportDeclaration
</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-grammar>
Declaration : ModuleDeclaration
</emu-grammar>
<emu-alg>
1. Return a new List whose sole element is |ModuleDeclaration|.
</emu-alg>
<emu-grammar>
Declaration :
HoistableDeclaration
LexicalDeclaration
ClassDeclaration
</emu-grammar>
<emu-alg>
1. Return a new empty List.
</emu-alg>
<emu-grammar>
ExportDeclaration : `export` `default` ModuleDeclaration
</emu-grammar>
<emu-alg>
1. Return a new List whose sole element is |ModuleDeclaration|.
</emu-alg>
<emu-grammar>
ExportDeclaration :
`export` ExportFromClause FromClause `;`
`export` NamedExports `;`
`export` VariableStatement
`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-parseinnermodules" type="sdo">
<h1>
<ins>
Static Semantics: ParseInnerModules (
_declaredModules_: a List of Records,
): ~unused~
</ins>
</h1>
<dl class="header"></dl>
<p>Unless explicitly specified otherwise, all nonterminals have an implicit definition for ParseInnerModules with argument _declaredModules_.The implicit definition applies ParseInnerModules with argument _declaredModules_ to the nonterminal's inner nonterminals. For example, ContainsUndefinedModuleReference of |ExponentiationExpression| is implicitly defined as follows:</p>
<emu-grammar example>
ExponentiationExpression : UpdateExpression `**` ExponentiationExpression
</emu-grammar>
<emu-alg example>
1. Perform ParseInnerModules of |UpdateExpression| with argument _declaredModules_.
1. Perform ParseInnerModules of |ExponentiationExpression| with argument _declaredModules_.
</emu-alg>
<p>The following productions have a different definition of ContainsUndefinedModuleReference:</p>
<emu-grammar>
ModuleSpecifier : Identifier
</emu-grammar>
<emu-alg>
1. Let _reference_ be the StringValue of |Identifier|.
1. If _reference_ is in _declaredModules_, return *false*.
1. Return *true*.
</emu-alg>
<emu-grammar>
ModuleBody : ModuleItemList
</emu-grammar>
<emu-alg>
1. Let _localDeclaredModules_ be DeclaredModuleNames of |ModuleItemList|.
1. Let _lexNames_ be the LexicallyDeclaredNames of |ModuleItemList|.
1. Let _varNames_ be the VarDeclaredNames of |ModuleItemList|.
1. Let _visibleDeclaredModules_ be a new List containing the elements of _declaredModules_ that are not in _lexNames_ or _varNames_.
1. Append all the elements of _localDeclaredModules_ to _visibleDeclaredModules_.
1. Return ContainsUndefinedModuleReference of |ModuleItemList| with argument _visibleDeclaredModules_.
</emu-alg>
<emu-grammar>
ScriptBody : StatementList
</emu-grammar>
<emu-alg>
1. Assert: _declaredModules_ is an empty List.
1. Let _localDeclaredModules_ be DeclaredModuleNames of |StatementList|.
1. Return ContainsUndefinedModuleReference of |StatementList| with argument _localDeclaredModules_.
</emu-alg>
<emu-grammar>
Block : `{` `}`
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
<emu-grammar>
Block : `{` StatementList `}`
</emu-grammar>
<emu-alg>
1. Let _lexNames_ be the LexicallyDeclaredNames of |StatementList|.
1. Let _visibleDeclaredModules_ be a new List containing the elements of _declaredModules_ that are not in _lexNames_.
1. Return ContainsUndefinedModuleReference of |StatementList| with argument _visibleDeclaredModules_.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-executable-code-and-execution-contexts" number="9">
<h1>Executable Code and Execution Contexts</h1>
<emu-clause id="sec-environment-records" oldids="sec-lexical-environments">
<h1>Environment Records</h1>
<p><dfn variants="Environment Records">Environment Record</dfn> is a specification type used to define the association of |Identifier|s to specific variables and functions, based upon the lexical nesting structure of ECMAScript code. Usually an Environment Record is associated with some specific syntactic structure of ECMAScript code such as a |FunctionDeclaration|, a |BlockStatement|, or a |Catch| clause of a |TryStatement|. Each time such code is evaluated, a new Environment Record is created to record the identifier bindings that are created by that code.</p>
<p>Every Environment Record has an [[OuterEnv]] field, which is either *null* or a reference to an outer Environment Record. This is used to model the logical nesting of Environment Record values. The outer reference of an (inner) Environment Record is a reference to the Environment Record that logically surrounds the inner Environment Record. An outer Environment Record may, of course, have its own outer Environment Record. An Environment Record may serve as the outer environment for multiple inner Environment Records. For example, if a |FunctionDeclaration| contains two nested |FunctionDeclaration|s then the Environment Records of each of the nested functions will have as their outer Environment Record the Environment Record of the current evaluation of the surrounding function.</p>
<p>Environment Records are purely specification mechanisms and need not correspond to any specific artefact of an ECMAScript implementation. It is impossible for an ECMAScript program to directly access or manipulate such values.</p>
<p><ins>Each Environment Record has the fields listed in <emu-xref href="#table-fields-of-environment-records"></emu-xref>.</ins></p>
<emu-table id="table-fields-of-environment-records" caption="Fields of Environment Records">
<table>
<tr>
<th>
Field
</th>
<th>
Type
</th>
<th>
Purpose
</th>
</tr>
<tr>
<td>
<ins>[[OuterEnv]]</ins>
</td>
<td>
<ins>an Environment Record or *null*</ins>
</td>
<td>
</td>
</tr>
<tr>
<td>
<ins>[[ModuleDeclarations]]</ins>
</td>
<td>
<ins>a List of Records with fields [[Name]] (a String) and [[Module]] (a Module Record)</ins>
</td>
<td>
</td>
</tr>
</table>
</emu-table>
<emu-clause id="sec-environment-record-operations" oldids="sec-lexical-environment-operations">
<h1>Environment Record Operations</h1>
<p>The following abstract operations are used in this specification to operate upon Environment Records:</p>
<emu-clause id="sec-addmoduledeclaration" type="abstract operation">
<h1>
<ins>
AddModuleDeclaration (
_name_: a String,
_module_: a Module Record,
_env_: an Environment Record
): ~unused~
</ins>
</h1>
<dl class="header">
</dl>
<emu-alg>
1. Append the Record { [[Name]]: _name_, [[Module]]: _module_ } to _env_.[[ModuleDeclarations]].
1. Return ~unused~.
</emu-alg>
</emu-clause>
<emu-clause id="sec-resolvemoduledeclaration" type="abstract operation">
<h1>
<ins>
ResolveModuleDeclaration (
_name_: a String,
_env_: an Environment Record
): either a normal completion containing a Module Record, or a throw completion
</ins>
</h1>
<dl class="header">
</dl>
<emu-alg>
1. Let _moduleDeclarations_ be _env_.[[ModuleDeclarations]].
1. For each Record _m_ in _moduleDeclarations_, do
1. If _m_.[[Name]] is _name_, return _m_.[[Module]].
1. If _env_.HasBinding(_name_), throw a *ReferenceError* exception.
1. If _env_ is a Module Environment Record or a Global Environment Record, throw a *ReferenceError* exception.
1. Assert: _env_.[[OuterEnv]] is not *null*.
1. Return ? ResolveModuleDeclaration(_name_, _env_.[[OuterEnv]]).
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-ordinary-and-exotic-objects-behaviours" number="10">
<h1>Ordinary and Exotic Objects Behaviours</h1>
<emu-clause id="sec-ecmascript-function-objects" number="2">
<h1>ECMAScript Function Objects</h1>
<emu-clause id="sec-functiondeclarationinstantiation" type="abstract operation" number="11">
<h1>
FunctionDeclarationInstantiation (
_func_: a function object,
_argumentsList_: a List of ECMAScript language values,
): either a normal completion containing ~unused~ or an abrupt completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>_func_ is the function object for which the execution context is being established.</dd>
</dl>
<!--
WARNING: If you add, remove, rename, or repurpose any variable names
within this algorithm, you may need to update
#sec-web-compat-functiondeclarationinstantiation accordingly.
-->
<emu-alg>
1. Let _calleeContext_ be the running execution context.
1. Let _code_ be _func_.[[ECMAScriptCode]].
1. Let _strict_ be _func_.[[Strict]].
1. Let _formals_ be _func_.[[FormalParameters]].
1. Let _parameterNames_ be the BoundNames of _formals_.
1. If _parameterNames_ has any duplicate entries, let _hasDuplicates_ be *true*. Otherwise, let _hasDuplicates_ be *false*.
1. Let _simpleParameterList_ be IsSimpleParameterList of _formals_.
1. Let _hasParameterExpressions_ be ContainsExpression of _formals_.
1. Let _varNames_ be the VarDeclaredNames of _code_.
1. Let _varDeclarations_ be the VarScopedDeclarations of _code_.
1. Let _lexicalNames_ be the LexicallyDeclaredNames of _code_.
1. Let _functionNames_ be a new empty List.
1. Let _functionsToInitialize_ be a new empty List.
1. For each element _d_ of _varDeclarations_, in reverse List order, do
1. If _d_ is neither a |VariableDeclaration| nor a |ForBinding| nor a |BindingIdentifier|, then
1. Assert: _d_ is either a |FunctionDeclaration|, a |GeneratorDeclaration|, an |AsyncFunctionDeclaration|, or an |AsyncGeneratorDeclaration|.
1. Let _fn_ be the sole element of the BoundNames of _d_.
1. If _fn_ is not an element of _functionNames_, then
1. Insert _fn_ as the first element of _functionNames_.
1. NOTE: If there are multiple function declarations for the same name, the last declaration is used.
1. Insert _d_ as the first element of _functionsToInitialize_.
1. Let _argumentsObjectNeeded_ be *true*.
1. If _func_.[[ThisMode]] is ~lexical~, then
1. NOTE: Arrow functions never have an arguments object.
1. Set _argumentsObjectNeeded_ to *false*.
1. Else if *"arguments"* is an element of _parameterNames_, then
1. Set _argumentsObjectNeeded_ to *false*.
1. Else if _hasParameterExpressions_ is *false*, then
1. If *"arguments"* is an element of _functionNames_ or if *"arguments"* is an element of _lexicalNames_, then
1. Set _argumentsObjectNeeded_ to *false*.
1. If _strict_ is *true* or if _hasParameterExpressions_ is *false*, then
1. NOTE: Only a single Environment Record is needed for the parameters, since calls to `eval` in strict mode code cannot create new bindings which are visible outside of the `eval`.
1. Let _env_ be the LexicalEnvironment of _calleeContext_.
1. Else,
1. NOTE: A separate Environment Record is needed to ensure that bindings created by direct eval calls in the formal parameter list are outside the environment where parameters are declared.
1. Let _calleeEnv_ be the LexicalEnvironment of _calleeContext_.
1. Let _env_ be NewDeclarativeEnvironment(_calleeEnv_).
1. Assert: The VariableEnvironment of _calleeContext_ is _calleeEnv_.
1. Set the LexicalEnvironment of _calleeContext_ to _env_.
1. For each String _paramName_ of _parameterNames_, do
1. Let _alreadyDeclared_ be ! _env_.HasBinding(_paramName_).
1. NOTE: Early errors ensure that duplicate parameter names can only occur in non-strict functions that do not have parameter default values or rest parameters.
1. If _alreadyDeclared_ is *false*, then
1. Perform ! _env_.CreateMutableBinding(_paramName_, *false*).
1. If _hasDuplicates_ is *true*, then
1. Perform ! _env_.InitializeBinding(_paramName_, *undefined*).
1. If _argumentsObjectNeeded_ is *true*, then
1. If _strict_ is *true* or if _simpleParameterList_ is *false*, then
1. Let _ao_ be CreateUnmappedArgumentsObject(_argumentsList_).
1. Else,
1. NOTE: A mapped argument object is only provided for non-strict functions that don't have a rest parameter, any parameter default value initializers, or any destructured parameters.
1. Let _ao_ be CreateMappedArgumentsObject(_func_, _formals_, _argumentsList_, _env_).
1. If _strict_ is *true*, then
1. Perform ! _env_.CreateImmutableBinding(*"arguments"*, *false*).
1. NOTE: In strict mode code early errors prevent attempting to assign to this binding, so its mutability is not observable.
1. Else,
1. Perform ! _env_.CreateMutableBinding(*"arguments"*, *false*).
1. Perform ! _env_.InitializeBinding(*"arguments"*, _ao_).
1. Let _parameterBindings_ be the list-concatenation of _parameterNames_ and « *"arguments"* ».
1. Else,
1. Let _parameterBindings_ be _parameterNames_.
1. Let _iteratorRecord_ be CreateListIteratorRecord(_argumentsList_).
1. If _hasDuplicates_ is *true*, then
1. Perform ? IteratorBindingInitialization of _formals_ with arguments _iteratorRecord_ and *undefined*.
1. Else,
1. Perform ? IteratorBindingInitialization of _formals_ with arguments _iteratorRecord_ and _env_.
1. If _hasParameterExpressions_ is *false*, then
1. NOTE: Only a single Environment Record is needed for the parameters and top-level vars.
1. Let _instantiatedVarNames_ be a copy of the List _parameterBindings_.
1. For each element _n_ of _varNames_, do
1. If _n_ is not an element of _instantiatedVarNames_, then
1. Append _n_ to _instantiatedVarNames_.
1. Perform ! _env_.CreateMutableBinding(_n_, *false*).
1. Perform ! _env_.InitializeBinding(_n_, *undefined*).
1. Let _varEnv_ be _env_.
1. Else,
1. NOTE: A separate Environment Record is needed to ensure that closures created by expressions in the formal parameter list do not have visibility of declarations in the function body.
1. Let _varEnv_ be NewDeclarativeEnvironment(_env_).
1. Set the VariableEnvironment of _calleeContext_ to _varEnv_.
1. Let _instantiatedVarNames_ be a new empty List.
1. For each element _n_ of _varNames_, do
1. If _n_ is not an element of _instantiatedVarNames_, then
1. Append _n_ to _instantiatedVarNames_.
1. Perform ! _varEnv_.CreateMutableBinding(_n_, *false*).
1. If _n_ is not an element of _parameterBindings_ or if _n_ is an element of _functionNames_, let _initialValue_ be *undefined*.
1. Else,
1. Let _initialValue_ be ! _env_.GetBindingValue(_n_, *false*).
1. Perform ! _varEnv_.InitializeBinding(_n_, _initialValue_).
1. NOTE: A var with the same name as a formal parameter initially has the same value as the corresponding initialized parameter.
1. [id="step-functiondeclarationinstantiation-web-compat-insertion-point"] NOTE: Annex <emu-xref href="#sec-web-compat-functiondeclarationinstantiation"></emu-xref> adds additional steps at this point.
1. If _strict_ is *false*, then
1. Let _lexEnv_ be NewDeclarativeEnvironment(_varEnv_).
1. NOTE: Non-strict functions use a separate Environment Record for top-level lexical declarations so that a direct eval can determine whether any var scoped declarations introduced by the eval code conflict with pre-existing top-level lexically scoped declarations. This is not needed for strict functions because a strict direct eval always places all declarations into a new Environment Record.
1. Else, let _lexEnv_ be _varEnv_.
1. Set the LexicalEnvironment of _calleeContext_ to _lexEnv_.
1. <ins>Let _outerModuleDeclarations_ be the outer module declarations, obtained using ResolveModuleDeclaration (TODO: define how).</ins>
1. <ins>Let _moduleHostDefined_ be *null*.</ins>
1. <ins>Let _currentScriptOrModule_ be GetActiveScriptOrModule().</ins>
1. <ins>If _currentScriptOrModule_ is not *null*, set _moduleHostDefined_ to _currentScriptOrModule_.[[HostDefined]].</ins>
1. <ins>Let _localModuleDeclarations_ be InstantiateModuleDeclarations(_code_, the current Realm Record, _moduleHostDefined_, _outerModuleDeclarations_).</ins>
1. Let _lexDeclarations_ be the LexicallyScopedDeclarations of _code_.
1. For each element _d_ of _lexDeclarations_, do
1. NOTE: A lexically declared name cannot be the same as a function/generator declaration, formal parameter, or a var name. Lexically declared names are only instantiated here but not initialized.
1. For each element _dn_ of the BoundNames of _d_, do
1. If IsConstantDeclaration of _d_ is *true*, then
1. Perform ! _lexEnv_.CreateImmutableBinding(_dn_, *true*).
1. Else,
1. Perform ! _lexEnv_.CreateMutableBinding(_dn_, *false*).
1. Let _privateEnv_ be the PrivateEnvironment of _calleeContext_.
1. <ins>For each Record _m_ in _localModuleDeclarations_, do</ins>
1. <ins>Perform AddModuleDeclaration(_m_.[[Name]], _m.[[Module]], _env_).</ins>
1. <ins>Let _mo_ be GetModuleObject(_m_.[[Module]]).</ins>
1. <ins>Perform ! _env_.InitializeBinding(_m_.[[Name]], _mo_).</ins>
1. For each Parse Node _f_ of _functionsToInitialize_, do
1. Let _fn_ be the sole element of the BoundNames of _f_.
1. Let _fo_ be InstantiateFunctionObject of _f_ with arguments _lexEnv_ and _privateEnv_.
1. Perform ! _varEnv_.SetMutableBinding(_fn_, _fo_, *false*).
1. Return ~unused~.
</emu-alg>
<emu-note>
<p><emu-xref href="#sec-block-level-function-declarations-web-legacy-compatibility-semantics"></emu-xref> provides an extension to the above algorithm that is necessary for backwards compatibility with web browser implementations of ECMAScript that predate ECMAScript 2015.</p>
</emu-note>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="sec-ecmascript-language-statements-and-declarations" number="14">
<h1>ECMAScript Language: Statements and Declarations</h1>
<h2>Syntax</h2>
<emu-grammar type="definition">
Declaration[Yield, Await] :
HoistableDeclaration[?Yield, ?Await, ~Default]
ClassDeclaration[?Yield, ?Await, ~Default]
LexicalDeclaration[+In, ?Yield, ?Await]
<ins>ModuleDeclaration[~Default]</ins>
</emu-grammar>
<emu-clause id="sec-block" number="2">
<h1>Block</h1>
<emu-clause id="sec-blockdeclarationinstantiation" type="abstract operation" number="3">
<h1>
BlockDeclarationInstantiation (
_code_: a Parse Node,
_env_: a Declarative Environment Record,
): ~unused~
</h1>
<dl class="header">
<dt>description</dt>
<dd>_code_ is the Parse Node corresponding to the body of the block. _env_ is the Environment Record in which bindings are to be created.</dd>
</dl>
<p>It performs the following steps when called:</p>
<!--
WARNING: If you add, remove, rename, or repurpose any variable names
within this algorithm, you may need to update
#sec-web-compat-blockdeclarationinstantiation accordingly.
-->
<emu-alg>
1. <ins>Let _outerModuleDeclarations_ be the outer module declarations, obtained using ResolveModuleDeclaration (TODO: define how).</ins>
1. <ins>Let _moduleHostDefined_ be *null*.</ins>
1. <ins>Let _currentScriptOrModule_ be GetActiveScriptOrModule().</ins>
1. <ins>If _currentScriptOrModule_ is not *null*, set _moduleHostDefined_ to _currentScriptOrModule_.[[HostDefined]].</ins>
1. <ins>Let _localModuleDeclarations_ be InstantiateModuleDeclarations(_code_, the current Realm Record, _moduleHostDefined_, _outerModuleDeclarations_).</ins>
1. Let _declarations_ be the LexicallyScopedDeclarations of _code_.
1. Let _privateEnv_ be the running execution context's PrivateEnvironment.
1. For each element _d_ of _declarations_, do
1. For each element _dn_ of the BoundNames of _d_, do
1. If IsConstantDeclaration of _d_ is *true*, then
1. Perform ! _env_.CreateImmutableBinding(_dn_, *true*).
1. Else,
1. [id="step-blockdeclarationinstantiation-createmutablebinding"] Perform ! _env_.CreateMutableBinding(_dn_, *false*). NOTE: This step is replaced in section <emu-xref href="#sec-web-compat-blockdeclarationinstantiation"></emu-xref>.
1. If _d_ is a |FunctionDeclaration|, a |GeneratorDeclaration|, an |AsyncFunctionDeclaration|, or an |AsyncGeneratorDeclaration|, then
1. Let _fn_ be the sole element of the BoundNames of _d_.
1. Let _fo_ be InstantiateFunctionObject of _d_ with arguments _env_ and _privateEnv_.
1. [id="step-blockdeclarationinstantiation-initializebinding"] Perform ! _env_.InitializeBinding(_fn_, _fo_). NOTE: This step is replaced in section <emu-xref href="#sec-web-compat-blockdeclarationinstantiation"></emu-xref>.
1. <ins>For each Record _m_ in _localModuleDeclarations_, do</ins>
1. <ins>Perform AddModuleDeclaration(_m_.[[Name]], _m.[[Module]], _env_).</ins>
1. <ins>Let _mo_ be GetModuleObject(_m_.[[Module]]).</ins>
1. <ins>Perform ! _env_.InitializeBinding(_m_.[[Name]], _mo_).</ins>
1. Return ~unused~.
</emu-alg>
</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-scripts">
<h1>Scripts</h1>
<emu-clause id="sec-scripts-static-semantics-early-errors" number="1">
<h1>Static Semantics: Early Errors</h1>
<emu-grammar>Script : ScriptBody</emu-grammar>
<ul>
<li>
It is a Syntax Error if the LexicallyDeclaredNames of |ScriptBody| contains any duplicate entries.
</li>
<li>
It is a Syntax Error if any element of the LexicallyDeclaredNames of |ScriptBody| also occurs in the VarDeclaredNames of |ScriptBody|.
</li>
<li>
<ins>It is a Syntax Error if ContainsUndefinedModuleReference of |ScriptBody| with argument a new empty List is *true*.</ins>
</li>
</ul>
</emu-clause>
<emu-clause id="sec-script-records" number="4">
<h1>Script Records</h1>
<p>A <dfn id="script-record" variants="Script Records">Script Record</dfn> encapsulates information about a script being evaluated. Each script record contains the fields listed in <emu-xref href="#table-script-records"></emu-xref>.</p>
<emu-table id="table-script-records" caption="Script Record Fields">
<table>
<thead>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
</thead>
<tr>
<td>
[[Realm]]
</td>
<td>
a Realm Record or *undefined*
</td>
<td></td>
</tr>
<tr>
<td>
[[ECMAScriptCode]]
</td>
<td>
a Parse Node
</td>
<td></td>
</tr>
<tr>
<td>
[[LoadedModules]]
</td>
<td>
a List of Records with fields [[Specifier]] (a <del>String</del><ins>ModuleSpecifier Record</ins>) and [[Module]] (a Module Record)
</td>
<td></td>
</tr>
<tr>
<td>
[[HostDefined]]
</td>
<td>
anything (default value is ~empty~)
</td>
<td></td>
</tr>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-globaldeclarationinstantiation" type="abstract operation" number="7">
<h1>
GlobalDeclarationInstantiation (
_script_: a |Script| Parse Node,
_env_: a Global Environment Record,
): either a normal completion containing ~unused~ or a throw completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>_script_ is the |Script| for which the execution context is being established. _env_ is the global environment in which bindings are to be created.</dd>
</dl>
<!--
WARNING: If you add, remove, rename, or repurpose any variable names
within this algorithm, you may need to update
#sec-web-compat-globaldeclarationinstantiation accordingly.
-->
<emu-alg>
1. Let _lexNames_ be the LexicallyDeclaredNames of _script_.
1. Let _varNames_ be the VarDeclaredNames of _script_.
1. For each element _name_ of _lexNames_, do
1. If _env_.HasVarDeclaration(_name_) is *true*, throw a *SyntaxError* exception.
1. If _env_.HasLexicalDeclaration(_name_) is *true*, throw a *SyntaxError* exception.
1. Let _hasRestrictedGlobal_ be ? _env_.HasRestrictedGlobalProperty(_name_).
1. If _hasRestrictedGlobal_ is *true*, throw a *SyntaxError* exception.
1. For each element _name_ of _varNames_, do
1. If _env_.HasLexicalDeclaration(_name_) is *true*, throw a *SyntaxError* exception.
1. Let _varDeclarations_ be the VarScopedDeclarations of _script_.
1. Let _functionsToInitialize_ be a new empty List.
1. Let _declaredFunctionNames_ be a new empty List.
1. For each element _d_ of _varDeclarations_, in reverse List order, do
1. If _d_ is neither a |VariableDeclaration| nor a |ForBinding| nor a |BindingIdentifier|, then
1. Assert: _d_ is either a |FunctionDeclaration|, a |GeneratorDeclaration|, an |AsyncFunctionDeclaration|, or an |AsyncGeneratorDeclaration|.
1. NOTE: If there are multiple function declarations for the same name, the last declaration is used.
1. Let _fn_ be the sole element of the BoundNames of _d_.
1. If _fn_ is not an element of _declaredFunctionNames_, then
1. Let _fnDefinable_ be ? _env_.CanDeclareGlobalFunction(_fn_).
1. If _fnDefinable_ is *false*, throw a *TypeError* exception.
1. Append _fn_ to _declaredFunctionNames_.
1. Insert _d_ as the first element of _functionsToInitialize_.
1. Let _declaredVarNames_ be a new empty List.
1. For each element _d_ of _varDeclarations_, do
1. If _d_ is a |VariableDeclaration|, a |ForBinding|, or a |BindingIdentifier|, then
1. For each String _vn_ of the BoundNames of _d_, do
1. If _vn_ is not an element of _declaredFunctionNames_, then
1. Let _vnDefinable_ be ? _env_.CanDeclareGlobalVar(_vn_).
1. If _vnDefinable_ is *false*, throw a *TypeError* exception.
1. If _vn_ is not an element of _declaredVarNames_, then
1. Append _vn_ to _declaredVarNames_.
1. NOTE: No abnormal terminations occur after this algorithm step if the global object is an ordinary object. However, if the global object is a Proxy exotic object it may exhibit behaviours that cause abnormal terminations in some of the following steps.
1. [id="step-globaldeclarationinstantiation-web-compat-insertion-point"] NOTE: Annex <emu-xref href="#sec-web-compat-globaldeclarationinstantiation"></emu-xref> adds additional steps at this point.
1. <ins>Let _localModuleDeclarations_ be InstantiateModuleDeclarations(_script_, _script_.[[Realm]], _script_.[[HostDefined]], a new empty List).</ins>
1. Let _lexDeclarations_ be the LexicallyScopedDeclarations of _script_.
1. Let _privateEnv_ be *null*.
1. For each element _d_ of _lexDeclarations_, do
1. NOTE: Lexically declared names are only instantiated here but not initialized.
1. For each element _dn_ of the BoundNames of _d_, do
1. If IsConstantDeclaration of _d_ is *true*, then
1. Perform ? <emu-meta effects="user-code">_env_.CreateImmutableBinding</emu-meta>(_dn_, *true*).
1. Else,
1. Perform ? <emu-meta effects="user-code">_env_.CreateMutableBinding</emu-meta>(_dn_, *false*).
1. <ins>For each Record _m_ of _localModuleDeclarations_, do</ins>
1. <ins>Perform AddModuleDeclaration(_m_.[[Name]], _m.[[Module]], _env_).</ins>
1. <ins>Let _mo_ be GetModuleObject(_m_.[[Module]]).</ins>
1. <ins>Perform ! _env_.InitializeBinding(_m_.[[Name]], _mo_).</ins>
1. For each Parse Node _f_ of _functionsToInitialize_, do
1. Let _fn_ be the sole element of the BoundNames of _f_.
1. Let _fo_ be InstantiateFunctionObject of _f_ with arguments _env_ and _privateEnv_.
1. Perform ? <emu-meta effects="user-code">_env_.CreateGlobalFunctionBinding</emu-meta>(_fn_, _fo_, *false*).
1. For each String _vn_ of _declaredVarNames_, do
1. Perform ? <emu-meta effects="user-code">_env_.CreateGlobalVarBinding</emu-meta>(_vn_, *false*).
1. Return ~unused~.
</emu-alg>
<emu-note>
<p>Early errors specified in <emu-xref href="#sec-scripts-static-semantics-early-errors"></emu-xref> prevent name conflicts between function/var declarations and let/const/class<ins>/module</ins> declarations as well as redeclaration of let/const/class<ins>/module</ins> bindings for declaration contained within a single |Script|. However, such conflicts and redeclarations that span more than one |Script| are detected as runtime errors during GlobalDeclarationInstantiation. If any such errors are detected, no bindings are instantiated for the script. However, if the global object is defined using Proxy exotic objects then the runtime tests for conflicting declarations may be unreliable resulting in an abrupt completion and some global declarations not being instantiated. If this occurs, the code for the |Script| is not evaluated.</p>
<p>Unlike explicit var or function declarations, properties that are directly created on the global object result in global bindings that may be shadowed by let/const/class<ins>/module</ins> declarations.</p>
</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-modules">
<h1>Modules</h1>
<emu-clause id="sec-module-semantics">
<h1>Module Semantics</h1>
<emu-clause id="sec-module-semantics-static-semantics-early-errors">
<h1>Static Semantics: Early Errors</h1>
<emu-grammar><ins>Module : ModuleBody</ins></emu-grammar>
<ul>
<li>
1. <ins>It is a Syntax Error if ContainsUndefinedModuleReference of |ModuleBody| with argument a new empty List is *true*.</ins>
</li>
</ul>
</emu-clause>
<emu-clause id="sec-static-semantics-modulerequests" type="sdo" number="3">