forked from tc39/proposal-import-meta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.html
324 lines (280 loc) · 10.9 KB
/
spec.html
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
<pre class="metadata">
title: import.meta
status: proposal
stage: 4
location: https://tc39.github.io/proposal-import-meta/
copyright: false
contributors: Domenic Denicola
</pre>
<script src="ecmarkup.js" defer></script>
<link rel="stylesheet" href="ecmarkup.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/solarized_light.min.css">
<emu-intro id="introduction">
<h1>Introduction</h1>
<p>Background explanatory material for this specification can be found in the <a
href="https://github.com/tc39/proposal-import-meta">tc39/proposal-import-meta</a>
repository. See also the <a
href="https://github.com/tc39/proposal-import-meta/issues">issues</a> list and the <a
href="https://github.com/tc39/proposal-import-meta/blob/master/HTML%20Integration.md">HTML
integration spec</a> that builds on top of the below JavaScript specification.</p>
</emu-intro>
<emu-clause id="sec-modules">
<h1>Modules</h1>
<emu-clause id="sec-module-semantics">
<h1>Module Semantics</h1>
<emu-clause id="sec-abstract-module-records">
<h1>Abstract Module Records</h1>
<emu-table id="table-36" caption="Module Record Fields">
<table>
<thead>
<tr>
<th>
Field Name
</th>
<th>
Value Type
</th>
<th>
Meaning
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
[[Realm]]
</td>
<td>
Realm Record | *undefined*
</td>
<td>
The Realm within which this module was created. *undefined* if not yet assigned.
</td>
</tr>
<tr>
<td>
[[Environment]]
</td>
<td>
Lexical Environment | *undefined*
</td>
<td>
The Lexical Environment containing the top level bindings for this module. This field is set when the module is instantiated.
</td>
</tr>
<tr>
<td>
[[Namespace]]
</td>
<td>
Object | *undefined*
</td>
<td>
The Module Namespace Object (<emu-xref href="#sec-module-namespace-objects"></emu-xref>) if one has been created for this module. Otherwise *undefined*.
</td>
</tr>
<tr>
<td>
[[Status]]
</td>
<td>
String
</td>
<td>
Initially `"uninstantiated"`. Can become `"instantiating"`, `"instantiated"`, `"evaluating"`, `"evaluated"`, or `"errored"` as the module progresses throughout its lifecycle.
</td>
</tr>
<tr>
<td>
[[ErrorCompletion]]
</td>
<td>
An abrupt completion | *undefined*
</td>
<td>
A completion of type ~throw~ representing the exception that occurred during instantiation or evaluation, if [[Status]] is `"errored"`. Otherwise *undefined*.
</td>
</tr>
<tr>
<td><ins>[[Meta]]</ins></td>
<td><ins>Object | *undefined*</ins></td>
<td>
<ins>An object exposed through the `import.meta` meta property. It is *undefined* by
default, but will become an Object before it is ever accessed by ECMAScript
code.</ins>
</td>
</tr>
<tr>
<td>
[[HostDefined]]
</td>
<td>
Any, default value is *undefined*.
</td>
<td>
Field reserved for use by host environments that need to associate additional information with a module.
</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
</emu-clause>
<emu-clause id="sec-left-hand-side-expressions">
<h1>Left-Hand-Side Expressions</h1>
<h2>Syntax</h2>
<emu-grammar>
MemberExpression[Yield, Await] :
PrimaryExpression[?Yield, ?Await]
MemberExpression[?Yield, ?Await] `[` Expression[+In, ?Yield, ?Await] `]`
MemberExpression[?Yield, ?Await] `.` IdentifierName
MemberExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await]
SuperProperty[?Yield, ?Await]
MetaProperty
`new` MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]
SuperProperty[Yield, Await] :
`super` `[` Expression[+In, ?Yield, ?Await] `]`
`super` `.` IdentifierName
MetaProperty :
NewTarget
<ins>ImportMeta</ins>
NewTarget :
`new` `.` `target`
<ins>
ImportMeta :
`import` `.` `meta`
</ins>
NewExpression[Yield, Await] :
MemberExpression[?Yield, ?Await]
`new` NewExpression[?Yield, ?Await]
CallExpression[Yield, Await] :
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] #callcover
SuperCall[?Yield, ?Await]
CallExpression[?Yield, ?Await] Arguments[?Yield, ?Await]
CallExpression[?Yield, ?Await] `[` Expression[+In, ?Yield, ?Await] `]`
CallExpression[?Yield, ?Await] `.` IdentifierName
CallExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await]
SuperCall[Yield, Await] :
`super` Arguments[?Yield, ?Await]
Arguments[Yield, Await] :
`(` `)`
`(` ArgumentList[?Yield, ?Await] `)`
`(` ArgumentList[?Yield, ?Await] `,` `)`
ArgumentList[Yield, Await] :
AssignmentExpression[+In, ?Yield, ?Await]
`...` AssignmentExpression[+In, ?Yield, ?Await]
ArgumentList[?Yield, ?Await] `,` AssignmentExpression[+In, ?Yield, ?Await]
ArgumentList[?Yield, ?Await] `,` `...` AssignmentExpression[+In, ?Yield, ?Await]
LeftHandSideExpression[Yield, Await] :
NewExpression[?Yield, ?Await]
CallExpression[?Yield, ?Await]
</emu-grammar>
<emu-clause id="sec-static-semantics">
<h1>Static Semantics</h1>
<emu-clause id="sec-left-hand-side-expressions-static-semantics-early-errors">
<h1><ins>Static Semantics: Early Errors</ins></h1>
<emu-grammar>
ImportMeta :
`import` `.` `meta`
</emu-grammar>
<ul>
<li>It is an early Syntax Error if |Module| is not the syntactic goal symbol.</li>
</ul>
</emu-clause>
<emu-clause id="sec-static-semantics-static-semantics-isvalidsimpleassignmenttarget">
<h1>Static Semantics: IsValidSimpleAssignmentTarget</h1>
<emu-see-also-para op="IsValidSimpleAssignmentTarget"></emu-see-also-para>
<emu-grammar>
CallExpression :
CallExpression `[` Expression `]`
CallExpression `.` IdentifierName
MemberExpression :
MemberExpression `[` Expression `]`
MemberExpression `.` IdentifierName
SuperProperty
</emu-grammar>
<emu-alg>
1. Return *true*.
</emu-alg>
<emu-grammar>
CallExpression :
CoverCallExpressionAndAsyncArrowHead
SuperCall
CallExpression Arguments
CallExpression TemplateLiteral
NewExpression :
`new` NewExpression
MemberExpression :
MemberExpression TemplateLiteral
`new` MemberExpression Arguments
NewTarget :
`new` `.` `target`
<ins>ImportMeta :
`import` `.` `meta`</ins>
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-meta-properties">
<h1>Meta Properties</h1>
<emu-clause id="sec-meta-properties-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>NewTarget : `new` `.` `target`</emu-grammar>
<emu-alg>
1. Return GetNewTarget().
</emu-alg>
</emu-clause>
<emu-grammar><ins>ImportMeta : `import` `.` `meta`</ins></emu-grammar>
<emu-alg>
1. <ins>Let _module_ be GetActiveScriptOrModule().</ins>
1. <ins>Assert: _module_ is a Module Record (not a Script Record).</ins>
1. <ins>Let _importMeta_ be _module_.[[ImportMeta]].</ins>
1. <ins>If _importMeta_ is *undefined*.
1. <ins>Set _importMeta_ to ObjectCreate(*null*).</ins>
1. <ins>Let _importMetaValues_ be ! HostGetImportMetaProperties(_module_).</ins>
1. <ins>For each Record {[[Key]], [[Value]]} _p_ that is an element of _importMetaValues_,</ins>
1. <ins>Perform ! CreateDataProperty(_importMeta_, _p_.[[Key]], _p_.[[Value]]).</ins>
1. <ins>Perform ! HostFinalizeImportMeta(_importMeta_, _module_).</ins>
1. <ins>Set _module_.[[ImportMeta]] to _importMeta_.</ins>
1. <ins>Return _importMeta_.</ins>
1. <ins>Else,
1. <ins>Assert: Type(_importMeta_) is Object.</ins>
1. <ins>Return _importMeta_.</ins>
</emu-alg>
<emu-clause id="sec-hostgetimportmetaproperties" aoid="HostGetImportMetaProperties">
<h1><ins>Runtime Semantics: HostGetImportMetaProperties ( _moduleRecord_ )</ins></h1>
<p>HostGetImportMetaProperties is an implementation-defined abstract operation that allows
hosts to provide property keys and values for the object returned from `import.meta`.</p>
<p>The implementation of HostGetImportMetaProperties must conform to the following
requirements:</p>
<ul>
<li>It must return a List, whose values are all Records with the two fields [[Key]] and
[[Value]].</li>
<li>Each such Record's [[Key]] field must be a property key, i.e., IsPropertyKey must
return true when applied to it.</li>
<li>Each such Record's [[Value]] field must be an ECMAScript value.</li>
<li>It must always complete normally (i.e., not return an abrupt completion).</li>
</ul>
<p>The default implementation of HostGetImportMetaProperties is to return a new empty
List.</p>
</emu-clause>
<emu-clause id="sec-hostfinalizeimportmeta" aoid="HostFinalizeImportMeta">
<h1><ins>Runtime Semantics: HostFinalizeImportMeta ( _importMeta_, _moduleRecord_ )</ins></h1>
<p>HostFinalizeImportMeta is an implementation-defined abstract operation that allows
hosts to perform any extraordinary operations to prepare the object returned from
`import.meta`.</p>
<p>Most hosts will be able to simply define HostGetImportMetaProperties, and leave
HostFinalizeImportMeta with its default behavior. However, HostFinalizeImportMeta provides an
"escape hatch" for hosts which need to directly manipulate the object before it is exposed
to ECMAScript code.</p>
<p>The implementation of HostFinalizeImportMeta must conform to the following
requirements:</p>
<ul>
<li>It must always complete normally (i.e., not return an abrupt completion).</li>
</ul>
<p>The default implementation of HostFinalizeImportMeta is to do nothing.</p>
</emu-clause>
</emu-clause>
</emu-clause>