sourceTextModule.linkRequests(modules)
modules<vm.Module[]> 该模块依赖的vm.Module对象数组。数组中模块的顺序即sourceTextModule.moduleRequests的顺序。- 返回:<undefined>
链接模块依赖。这种方法必须在评估之前调用,并且每个模块只能调用一次。
【Link module dependencies. This method must be called before evaluation, and can only be called once per module.】
modules 数组中模块实例的顺序应对应于 sourceTextModule.moduleRequests 被解析的顺序。如果两个模块请求具有相同的说明符和导入属性,它们必须使用相同的模块实例进行解析,否则将抛出 ERR_MODULE_LINK_MISMATCH 错误。例如,在链接此模块的请求时:
【The order of the module instances in the modules array should correspond to the order of
sourceTextModule.moduleRequests being resolved. If two module requests have the same
specifier and import attributes, they must be resolved with the same module instance or an
ERR_MODULE_LINK_MISMATCH would be thrown. For example, when linking requests for this
module:】
import foo from 'foo';
import source Foo from 'foo'; modules 数组必须包含对同一个实例的两个引用,因为这两个模块请求是相同的,但处于两个不同的阶段。
【The modules array must contain two references to the same instance, because the two
module requests are identical but in two phases.】
如果该模块没有依赖,modules 数组可以为空。
【If the module has no dependencies, the modules array can be empty.】
用户可以使用 sourceTextModule.moduleRequests 来实现 ECMAScript 规范中主机定义的 主机加载导入模块 抽象操作,并使用 sourceTextModule.linkRequests() 调用规范中定义的 完成加载导入的模块,以批量处理包含所有依赖的模块。
【Users can use sourceTextModule.moduleRequests to implement the host-defined
HostLoadImportedModule abstract operation in the ECMAScript specification,
and using sourceTextModule.linkRequests() to invoke specification defined
FinishLoadingImportedModule, on the module with all dependencies in a batch.】
由 SourceTextModule 的创建者决定依赖的解析是同步还是异步。
【It's up to the creator of the SourceTextModule to determine if the resolution
of the dependencies is synchronous or asynchronous.】
在链接 modules 数组中的每个模块后,调用 sourceTextModule.instantiate()。
【After each module in the modules array is linked, call
sourceTextModule.instantiate().】