?um/p1-90`super,则为语法错误,除非包含 super 的源文本是由super 的其他The syntax-directed operation ScriptIsStrict takes no arguments and returns 一个布尔值. It is defined piecewise over the following productions:
Script Record 封装正在求值的脚本相关信息。每个 script record 包含
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[Realm]] |
一个 |
创建此脚本所在的 |
| [[ECMAScriptCode]] |
一个 |
解析此脚本源文本的结果。 |
| [[LoadedModules]] |
|
从此脚本导入的说明符字符串到已解析 Module |
| [[HostDefined]] |
任何值(默认值为 |
保留给需要将额外信息与脚本关联的 |
The abstract operation ParseScript takes arguments sourceText (
实现在对该脚本源文本求值 ParseScript 之前,可以解析脚本源文本并分析其 Early Error 条件。然而,任何错误的报告都必须推迟到本规范实际对该源文本执行 ParseScript 的时刻。
The abstract operation ScriptEvaluation takes argument scriptRecord (一个
The abstract operation GlobalDeclarationInstantiation takes arguments script (一个
当为求值脚本建立
调用时执行以下步骤:
var 和 function 绑定(由非严格与显式 var 或 function 声明不同,直接在
super,则为语法错误。
重复的 export default
The abstract operation ImportedLocalNames takes argument importEntries (ImportEntry
ModuleRequest Record 表示带有给定导入属性的模块导入请求。它由以下字段组成:
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[Specifier]] | 一个 String | 模块说明符 |
| [[Attributes]] |
|
导入属性 |
LoadedModuleRequest Record 表示导入模块的请求以及产生的 Module
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[Specifier]] | 一个 String | 模块说明符 |
| [[Attributes]] |
|
导入属性 |
| [[Module]] |
一个 Module |
与此模块请求对应的已加载模块 |
ImportAttribute Record 由以下字段组成:
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[Key]] | 一个 String |
|
| [[Value]] | 一个 String | 属性值 |
The abstract operation ModuleRequestsEqual takes arguments left (一个
The syntax-directed operation ModuleRequests takes no arguments and returns
模块记录 封装了关于单个模块导入和导出的结构信息。 这些信息用于链接一组关联模块的导入与导出。 模块记录包含四个仅在评估模块时使用的字段。
从规范角度看,模块记录的值是
模块记录定义了
| 方法 | 目的 | 定义 |
|---|---|---|
| LoadRequestedModules ( [ hostDefined ] ) | The abstract method LoadRequestedModules takes optional argument hostDefined (任意值) and returns 一个 Promise. 递归加载所有依赖,为模块链接做准备。 |
在本规范内,此方法在以下类型中有定义; |
| GetExportedNames ( [ exportStarSet ] ) | The abstract method GetExportedNames takes optional argument exportStarSet ( 返回从该模块直接或间接导出的所有名称的列表。 在调用本方法前,必须已经调用并成功完成 |
在本规范内,此方法在以下类型中有定义; |
| ResolveExport ( exportName [ , resolveSet ] ) | The abstract method ResolveExport takes argument exportName (字符串) and optional argument resolveSet (具有字段 [[Module]](
返回该模块导出的某个名称的绑定。绑定由
ResolvedBinding 记录 表示,
形式为 { [[Module]]: 每次使用特定 exportName 和 resolveSet 调用本操作时,必须返回相同结果。 在调用本方法前,必须已成功完成 |
在本规范内,此方法在以下类型中有定义; |
| Link ( ) | The abstract method Link takes no arguments and returns “ 通过传递性地解析所有模块依赖项并创建模块环境记录,为模块求值做准备。 在调用本方法前,必须已成功完成 |
在本规范内,此方法在以下类型中有定义; |
| Evaluate ( ) | The abstract method Evaluate takes no arguments and returns 一个 Promise.
返回一个 promise,其结果为评估该模块及其依赖的过程。
若评估成功或已经成功则 resolve,若失败或之前已失败则 reject。
若 promise 被拒绝, 在调用本方法前,必须已成功完成 |
在本规范内,此方法在以下类型中有定义; |
The abstract operation EvaluateModuleSync takes argument module (一个
循环模块记录用于表示可以与其他
除了在
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[Status]] |
|
初始为 |
| [[EvaluationError]] |
一个 throw completion 或 |
表示在求值过程中发生的异常的 throw completion。如果未发生异常或 [[Status]] 不是 |
| [[DFSAncestorIndex]] |
一个 |
仅在 |
| [[RequestedModules]] |
|
与该模块中 import 相关联的 |
| [[LoadedModules]] |
|
一个从该模块使用的说明符字符串(用于请求导入模块,并带有相对导入属性)映射到已解析的 |
| [[CycleRoot]] |
一个 |
循环中首次访问的模块,即该强连通分量的 DFS 根祖先。对于不在循环中的模块,该值为模块自身。在 |
| [[HasTLA]] | 一个布尔值 |
指示该模块是否本身是异步的(例如,包含顶层 await 的 |
| [[AsyncEvaluationOrder]] |
|
该字段初始为 |
| [[TopLevelCapability]] |
一个 |
如果该模块是某个循环的 [[CycleRoot]],且对该循环中的某个模块调用了 |
| [[AsyncParentModules]] |
|
如果该模块或其依赖的 [[HasTLA]] 为 |
| [[PendingAsyncDependencies]] |
一个 |
如果该模块具有异步依赖,该字段用于跟踪该模块剩余待执行的异步依赖模块数量。当该字段为 0 且没有执行错误时,该模块将被执行。 |
除了在
| 方法 | 目的 | 定义 |
|---|---|---|
| InitializeEnvironment ( ) | The abstract method InitializeEnvironment takes no arguments and returns 返回包含 |
在本规范中,它在以下类型中具有定义; |
| ExecuteModule ( [ capability ] ) | The abstract method ExecuteModule takes optional argument capability (一个 |
在本规范中,它在以下类型中具有定义; |
GraphLoadingState 记录是一个记录,用于包含模块图加载过程的信息。它用于在调用
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[PromiseCapability]] |
一个 |
在加载过程完成时需要解析的 promise。 |
| [[IsLoading]] | 一个布尔值 | 如果加载过程尚未结束(既未成功也未出错),则为 true。 |
| [[PendingModulesCount]] |
一个非负 |
用于跟踪待处理的 |
| [[Visited]] |
|
当前加载过程中已经加载的 |
| [[HostDefined]] |
任意值(默认值为 |
包含由 |
以下是
The
<link rel="preload" as="..."> 标签设置正确的 fetch 目标。
import() 表达式从不会设置 hostDefined 参数。
The abstract operation InnerModuleLoading takes arguments state (一个
The abstract operation ContinueModuleLoading takes arguments state (一个
The
The abstract operation InnerModuleLinking takes arguments module (一个
The
The abstract operation InnerModuleEvaluation takes arguments module (一个
当模块正在被 InnerModuleEvaluation 遍历时,其状态为
当某个异步循环中的模块不处于
The abstract operation ExecuteAsyncModule takes argument module (一个
The abstract operation GatherAvailableAncestors takes arguments module (一个
当某个根模块 module 的异步执行完成时,此函数用于确定可以在该完成点同步执行的一组模块,并将它们填充到 execList 中。
The abstract operation AsyncModuleExecutionFulfilled takes argument module (一个
The abstract operation AsyncModuleExecutionRejected takes arguments module (一个
本非规范性章节给出一系列常见模块图的链接和求值示例,并特别关注错误可能如何发生。
首先考虑以下简单模块图:
我们先假设不存在错误条件。当
接着考虑在成功调用 A.
最后,考虑在成功调用
现在考虑一种不同类型的错误条件:
在此场景中,模块 A 声明依赖另一个模块,但该模块不存在 Module
这里加载、链接和求值错误之间的差异源于以下特性:
现在,考虑一个带有循环的模块图:
这里我们假设入口点是模块 A,因此
随后
在循环模块图的求值阶段,在成功情况下也会发生类似过程。
现在考虑 A 存在链接错误的情况;例如,它试图从 C 导入一个不存在的绑定。在这种情况下,上述步骤仍然发生,包括第二次在 A 上调用
或者,考虑 A 存在求值错误的情况;例如,其源代码抛出异常。在这种情况下,上述步骤在求值时的对应过程仍然发生,包括第二次在 A 上调用 await 的模块形成一条贯穿整个依赖图的链,并通过
最后,考虑一个带有循环的模块图,其中所有模块都异步完成:
加载和链接照常发生,所有模块最终的 [[Status]] 都设置为
调用 A.
|
字段
|
A | B | C | D | E |
|---|---|---|---|---|---|
| [[DFSAncestorIndex]] | 0 | 0 | 0 | 0 | 4 |
| [[Status]] | |||||
| [[AsyncEvaluationOrder]] | 4 | 1 | 3 | 0 | 2 |
| [[AsyncParentModules]] | « » | « A » | « A » | « B, C » | « C » |
| [[PendingAsyncDependencies]] | 2(B 和 C) | 1(D) | 2(D 和 E) | 0 | 0 |
我们假设 E 最先完成执行。当这发生时,调用
|
字段
|
C | E |
|---|---|---|
| [[DFSAncestorIndex]] | 0 | 4 |
| [[Status]] | ||
| [[AsyncEvaluationOrder]] | 3 | |
| [[AsyncParentModules]] | « A » | « C » |
| [[PendingAsyncDependencies]] | 1(D) | 0 |
接下来 D 完成(因为它是唯一仍在执行的模块)。当这发生时,再次调用 await,则可能与 B 并行执行)。更新后的模块字段如
|
字段
|
B | C | D |
|---|---|---|---|
| [[DFSAncestorIndex]] | 0 | 0 | 0 |
| [[Status]] | |||
| [[AsyncEvaluationOrder]] | 1 | 3 | |
| [[AsyncParentModules]] | « A » | « A » | « B, C » |
| [[PendingAsyncDependencies]] | 0 | 0 | 0 |
我们假设 C 接下来完成执行。当这发生时,再次调用
|
字段
|
A | C |
|---|---|---|
| [[DFSAncestorIndex]] | 0 | 0 |
| [[Status]] | ||
| [[AsyncEvaluationOrder]] | 4 | |
| [[AsyncParentModules]] | « » | « A » |
| [[PendingAsyncDependencies]] | 1(B) | 0 |
然后,B 完成执行。当这发生时,再次调用
|
字段
|
A | B |
|---|---|---|
| [[DFSAncestorIndex]] | 0 | 0 |
| [[Status]] | ||
| [[AsyncEvaluationOrder]] | 4 | |
| [[AsyncParentModules]] | « » | « A » |
| [[PendingAsyncDependencies]] | 0 | 0 |
最后,A 完成执行。当这发生时,再次调用
|
字段
|
A |
|---|---|
| [[DFSAncestorIndex]] | 0 |
| [[Status]] | |
| [[AsyncEvaluationOrder]] | |
| [[AsyncParentModules]] | « » |
| [[PendingAsyncDependencies]] | 0 |
或者,考虑一种失败情况:C 在 B 完成执行之前执行失败并返回错误。当这发生时,调用
|
字段
|
A | C |
|---|---|---|
| [[DFSAncestorIndex]] | 0 | 0 |
| [[Status]] | ||
| [[AsyncEvaluationOrder]] | ||
| [[AsyncParentModules]] | « » | « A » |
| [[PendingAsyncDependencies]] | 1(B) | 0 |
| [[EvaluationError]] | C 的求值错误 |
A 将以与 C 相同的错误被拒绝,因为 C 会使用 C 的错误在 A 上调用
|
字段
|
A |
|---|---|
| [[DFSAncestorIndex]] | 0 |
| [[Status]] | |
| [[AsyncEvaluationOrder]] | |
| [[AsyncParentModules]] | « » |
| [[PendingAsyncDependencies]] | 0 |
| [[EvaluationError]] | C 的求值错误 |
然后,B 无错误地完成执行。当这发生时,再次调用
|
字段
|
A | B |
|---|---|---|
| [[DFSAncestorIndex]] | 0 | 0 |
| [[Status]] | ||
| [[AsyncEvaluationOrder]] | 4 | 1 |
| [[AsyncParentModules]] | « » | « A » |
| [[PendingAsyncDependencies]] | 0 | 0 |
| [[EvaluationError]] | C 的求值错误 |
源文本模块记录用于表示从
除了在
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[ECMAScriptCode]] |
一个 |
使用 |
| [[Context]] |
一个 |
与该模块关联的 |
| [[ImportMeta]] |
一个对象或 |
通过 import.meta 元属性暴露的对象。在 ECMAScript 代码访问它之前,它为 |
| [[ImportEntries]] |
|
从该 |
| [[LocalExportEntries]] |
|
从该 |
| [[IndirectExportEntries]] |
|
从该export * as namespace 声明的导出。
|
| [[StarExportEntries]] |
|
从该export * 声明,不包括 export * as namespace 声明。
|
ImportEntry 记录是一个记录,用于摘要关于单个声明式导入的信息。每个
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[ModuleRequest]] | 一个 ModuleRequest 记录 |
表示 |
| [[ImportName]] |
一个字符串或 |
由 [[ModuleRequest]] 标识的模块导出所需绑定所使用的名称。值 |
| [[LocalName]] | 一个字符串 | 在导入模块内部用于本地访问导入值的名称。 |
| 导入语句形式 | [[ModuleRequest]] | [[ImportName]] | [[LocalName]] |
|---|---|---|---|
import v from "mod";
|
|
|
|
import * as ns from "mod";
|
|
|
|
import {x} from "mod";
|
|
|
|
import {x as v} from "mod";
|
|
|
|
import "mod";
|
不会创建 |
||
ExportEntry 记录是一个记录,用于摘要关于单个声明式导出的信息。每个
| 字段名 | 值类型 | 含义 |
|---|---|---|
| [[ExportName]] |
一个字符串或 |
此模块用于导出该绑定的名称。 |
| [[ModuleRequest]] |
一个 ModuleRequest 记录或 |
表示 |
| [[ImportName]] |
一个字符串、 |
由 [[ModuleRequest]] 标识的模块导出所需绑定所使用的名称。如果 export * as ns from "mod" 声明。export * from "mod" 声明。
|
| [[LocalName]] |
一个字符串或 |
在导入模块内部用于本地访问导出值的名称。如果导出的值在模块内部无法本地访问,则为 |
| 导出语句形式 | [[ExportName]] | [[ModuleRequest]] | [[ImportName]] | [[LocalName]] |
|---|---|---|---|---|
export var v;
|
|
|
|
|
export default function f() {}
|
|
|
|
|
export default function () {}
|
|
|
|
|
export default 42;
|
|
|
|
|
export {x};
|
|
|
|
|
export {v as x};
|
|
|
|
|
export {x} from "mod";
|
|
|
|
|
export {v as x} from "mod";
|
|
|
|
|
export * from "mod";
|
|
|
|
|
export * as ns from "mod";
|
|
|
|
|
The abstract operation ParseModule takes arguments sourceText (
export * from 以相同名称导出同一绑定或命名空间两次所产生的冲突被忽略,而不是在await。实现可以在对该模块源文本求值 ParseModule 之前解析模块源文本并分析其 Early Error 条件。然而,任何错误的报告都必须推迟到本规范实际对该源文本执行 ParseModule 的时刻。
以下是
The
export * 循环的起点。The
如果找到定义模块,则返回
It performs the following steps when called:
default 导出。default 导出不能由 export * from "mod" 声明提供。* 导出。以下是
The
The
合成模块记录用于表示由规范定义的模块的信息。其导出名称在创建时静态定义,而其对应值可以随时间通过
除了在
The abstract operation CreateDefaultExportSyntheticModule takes argument defaultExport (一个
The abstract operation ParseJSONModule takes argument source (一个字符串) and returns 返回包含
The abstract operation SetSyntheticModuleExport takes arguments module (一个
以下是
The
The
The
The
The
The abstract operation GetImportedModule takes arguments referrer (一个
The host-defined abstract operation HostLoadImportedModule takes arguments referrer (一个 Script 记录、一个
HostLoadImportedModule 的实现必须符合以下要求:
如果此操作被多次调用,且两个 (referrer, moduleRequest) 对满足:
并且它执行
如果 moduleRequest.[[Attributes]] 有一个条目 entry,使得 entry.[[Key]] 为
实际执行的过程由
The abstract operation FinishLoadingImportedModule takes arguments referrer (一个 Script 记录、一个
The abstract operation AllImportAttributesSupported takes argument attributes (ImportAttribute 记录的列表) and returns 一个布尔值. It performs the following steps when called:
The host-defined abstract operation HostGetSupportedImportAttributes takes no arguments and returns 字符串列表. 允许
HostGetSupportedImportAttributes 的实现必须符合以下要求:
HostGetSupportedImportAttributes 的默认实现是返回一个新的空列表。
The abstract operation GetModuleNamespace takes argument module (
GetModuleNamespace 从不抛出异常。相反,无法解析的名称此时会被简单地从命名空间中排除。它们稍后会导致真正的链接错误,除非它们全都是没有在任何地方被显式请求的歧义星号导出。
The syntax-directed operation ImportEntries takes no arguments and returns
The syntax-directed operation ImportEntriesForModule takes argument module (ModuleRequest 记录) and returns
The syntax-directed operation WithClauseToAttributes takes no arguments and returns ImportAttribute 记录的列表. It is defined piecewise over the following productions:
上述规则意味着
The syntax-directed operation ExportedBindings takes no arguments and returns 字符串列表.
ExportedBindings 是与
It is defined piecewise over the following productions:
The syntax-directed operation ExportedNames takes no arguments and returns 字符串列表.
ExportedNames 是
It is defined piecewise over the following productions:
The syntax-directed operation ExportEntries takes no arguments and returns
The syntax-directed operation ExportEntriesForModule takes argument module (ModuleRequest 记录或
The syntax-directed operation ReferencedBindings takes no arguments and returns