* Wrapper of evalModuleEntryPoint * * This function wraps the compilation of the source code in a try-catch block. * If the source code fails to be compiled, it will retry transpiling the source code * with the TypeScript parser. * @param {string} source The source code to evaluate * @param {b
(source, print)
| 338 | * @returns {Promise} The module evaluation promise |
| 339 | */ |
| 340 | function evalTypeScriptModuleEntryPoint(source, print) { |
| 341 | if (print) { |
| 342 | throw new ERR_EVAL_ESM_CANNOT_PRINT(); |
| 343 | } |
| 344 | |
| 345 | RegExpPrototypeExec(/^/, ''); // Necessary to reset RegExp statics before user code runs. |
| 346 | |
| 347 | return require('internal/modules/run_main').runEntryPointWithESMLoader( |
| 348 | async (loader) => { |
| 349 | const url = getEvalModuleUrl(); |
| 350 | let moduleWrap; |
| 351 | try { |
| 352 | // Compile the module to check for syntax errors. |
| 353 | moduleWrap = loader.createModuleWrap(source, url); |
| 354 | } catch (originalError) { |
| 355 | try { |
| 356 | const strippedSource = stripTypeScriptModuleTypes(source, kEvalTag); |
| 357 | // If the moduleWrap was successfully created, execute the module job. |
| 358 | // outside the try-catch block to avoid catching runtime errors. |
| 359 | moduleWrap = loader.createModuleWrap(strippedSource, url); |
| 360 | } catch (tsError) { |
| 361 | // If it's invalid or unsupported TypeScript syntax, rethrow the original error |
| 362 | // with the TypeScript error message added to the stack. |
| 363 | if (tsError.code === 'ERR_INVALID_TYPESCRIPT_SYNTAX' || |
| 364 | tsError.code === 'ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX') { |
| 365 | originalError.stack = `${tsError.message}\n\n${originalError.stack}`; |
| 366 | throw originalError; |
| 367 | } |
| 368 | |
| 369 | throw tsError; |
| 370 | } |
| 371 | } |
| 372 | // If the moduleWrap was successfully created either with by just compiling |
| 373 | // or after transpilation, execute the module job. |
| 374 | return loader.executeModuleJob(url, moduleWrap, true); |
| 375 | }, |
| 376 | ); |
| 377 | }; |
| 378 | |
| 379 | /** |
| 380 | * |
no test coverage detected
searching dependent graphs…