@@ -35,7 +35,7 @@ const { getOptionValue } = require('internal/options');
35
35
const {
36
36
makeContextifyScript, runScriptInThisContext,
37
37
} = require ( 'internal/vm' ) ;
38
- const { emitExperimentalWarning, isError } = require ( 'internal/util' ) ;
38
+ const { emitExperimentalWarning } = require ( 'internal/util' ) ;
39
39
// shouldAbortOnUncaughtToggle is a typed array for faster
40
40
// communication with JS.
41
41
const { shouldAbortOnUncaughtToggle } = internalBinding ( 'util' ) ;
@@ -254,10 +254,6 @@ function evalTypeScript(name, source, breakFirstLine, print, shouldLoadESM = fal
254
254
try {
255
255
compiledScript = compileScript ( name , source , baseUrl ) ;
256
256
} catch ( originalError ) {
257
- // If it's not a SyntaxError, rethrow it.
258
- if ( ! isError ( originalError ) || originalError . name !== 'SyntaxError' ) {
259
- throw originalError ;
260
- }
261
257
try {
262
258
sourceToRun = stripTypeScriptModuleTypes ( source , name , false ) ;
263
259
// Retry the CJS/ESM syntax detection after stripping the types.
@@ -272,12 +268,8 @@ function evalTypeScript(name, source, breakFirstLine, print, shouldLoadESM = fal
272
268
} catch ( tsError ) {
273
269
// If it's invalid or unsupported TypeScript syntax, rethrow the original error
274
270
// with the TypeScript error message added to the stack.
275
- const isInvalidTS = tsError ?. code === 'ERR_INVALID_TYPESCRIPT_SYNTAX' ;
276
- const isUnsupportedTS = tsError ?. code === 'ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX' ;
277
- if ( ( isInvalidTS || isUnsupportedTS ) && isError ( tsError ) ) {
278
- try {
279
- originalError . stack = decorateCJSErrorWithTSMessage ( originalError . stack , tsError . message ) ;
280
- } catch { /* Ignore potential errors coming from `stack` getter/setter */ }
271
+ if ( tsError . code === 'ERR_INVALID_TYPESCRIPT_SYNTAX' || tsError . code === 'ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX' ) {
272
+ originalError . stack = decorateCJSErrorWithTSMessage ( originalError . stack , tsError . message ) ;
281
273
throw originalError ;
282
274
}
283
275
@@ -325,13 +317,8 @@ function evalTypeScriptModuleEntryPoint(source, print) {
325
317
// Compile the module to check for syntax errors.
326
318
moduleWrap = loader . createModuleWrap ( source , url ) ;
327
319
} catch ( originalError ) {
328
- // If it's not a SyntaxError, rethrow it.
329
- if ( ! isError ( originalError ) || originalError . name !== 'SyntaxError' ) {
330
- throw originalError ;
331
- }
332
- let strippedSource ;
333
320
try {
334
- strippedSource = stripTypeScriptModuleTypes ( source , url , false ) ;
321
+ const strippedSource = stripTypeScriptModuleTypes ( source , url , false ) ;
335
322
// If the moduleWrap was successfully created, execute the module job.
336
323
// outside the try-catch block to avoid catching runtime errors.
337
324
moduleWrap = loader . createModuleWrap ( strippedSource , url ) ;
@@ -340,12 +327,9 @@ function evalTypeScriptModuleEntryPoint(source, print) {
340
327
} catch ( tsError ) {
341
328
// If it's invalid or unsupported TypeScript syntax, rethrow the original error
342
329
// with the TypeScript error message added to the stack.
343
- const isInvalidTS = tsError ?. code === 'ERR_INVALID_TYPESCRIPT_SYNTAX' ;
344
- const isUnsupportedTS = tsError ?. code === 'ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX' ;
345
- if ( ( isInvalidTS || isUnsupportedTS ) && isError ( tsError ) ) {
346
- try {
347
- originalError . stack = `${ tsError . message } \n\n${ originalError . stack } ` ;
348
- } catch { /* Ignore potential errors coming from `stack` getter/setter */ }
330
+ if ( tsError . code === 'ERR_INVALID_TYPESCRIPT_SYNTAX' ||
331
+ tsError . code === 'ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX' ) {
332
+ originalError . stack = `${ tsError . message } \n\n${ originalError . stack } ` ;
349
333
throw originalError ;
350
334
}
351
335
0 commit comments