* Compile a SourceTextModule for the built-in ESM loader. Register it for default * source map and import.meta and dynamic import() handling if cascadedLoader is provided. * @param {string} url URL of the module. * @param {string} source Source code of the module. * @param {string} type Type of
(url, source, type, context = kEmptyObject)
| 335 | * @returns {ModuleWrap} |
| 336 | */ |
| 337 | function compileSourceTextModule(url, source, type, context = kEmptyObject) { |
| 338 | let hostDefinedOptions; |
| 339 | switch (type) { |
| 340 | case SourceTextModuleTypes.kFacade: |
| 341 | case SourceTextModuleTypes.kInternal: |
| 342 | hostDefinedOptions = undefined; |
| 343 | break; |
| 344 | case SourceTextModuleTypes.kEmbedder: |
| 345 | hostDefinedOptions = embedder_module_hdo; |
| 346 | break; |
| 347 | case SourceTextModuleTypes.kUser: |
| 348 | hostDefinedOptions = source_text_module_default_hdo; |
| 349 | break; |
| 350 | default: |
| 351 | assert.fail(`Unknown SourceTextModule type: ${type}`); |
| 352 | } |
| 353 | |
| 354 | const wrap = new ModuleWrap(url, undefined, source, 0, 0, hostDefinedOptions); |
| 355 | |
| 356 | if (type === SourceTextModuleTypes.kFacade) { |
| 357 | return wrap; |
| 358 | } |
| 359 | |
| 360 | const { isMain } = context; |
| 361 | if (isMain) { |
| 362 | wrap.isMain = true; |
| 363 | } |
| 364 | |
| 365 | // Cache the source map for the module if present. |
| 366 | if (wrap.sourceMapURL) { |
| 367 | maybeCacheSourceMap(url, source, wrap, false, wrap.sourceURL, wrap.sourceMapURL); |
| 368 | } |
| 369 | |
| 370 | if (type === SourceTextModuleTypes.kEmbedder) { |
| 371 | // For embedder ESM, we also handle the linking and evaluation. |
| 372 | const requests = wrap.getModuleRequests(); |
| 373 | const modules = requests.map(({ specifier }) => getBuiltinModuleWrapForEmbedder(specifier)); |
| 374 | wrap.link(modules); |
| 375 | wrap.instantiate(); |
| 376 | wrap.evaluate(-1, false); |
| 377 | } |
| 378 | return wrap; |
| 379 | } |
| 380 | |
| 381 | const kImportInImportedESM = Symbol('kImportInImportedESM'); |
| 382 | const kImportInRequiredESM = Symbol('kImportInRequiredESM'); |
no test coverage detected
searching dependent graphs…