@@ -13,28 +13,34 @@ const {
1313 prepareMainThreadExecution,
1414 markBootstrapComplete,
1515} = require ( 'internal/process/pre_execution' ) ;
16- const { evalModuleEntryPoint, evalScript } = require ( 'internal/process/execution' ) ;
16+ const {
17+ evalModuleEntryPoint,
18+ evalTypeScript,
19+ parseAndEvalCommonjsTypeScript,
20+ parseAndEvalModuleTypeScript,
21+ evalScript,
22+ } = require ( 'internal/process/execution' ) ;
1723const { addBuiltinLibsToObject } = require ( 'internal/modules/helpers' ) ;
18- const { stripTypeScriptModuleTypes } = require ( 'internal/modules/typescript' ) ;
1924const { getOptionValue } = require ( 'internal/options' ) ;
2025
2126prepareMainThreadExecution ( ) ;
2227addBuiltinLibsToObject ( globalThis , '<eval>' ) ;
2328markBootstrapComplete ( ) ;
2429
2530const code = getOptionValue ( '--eval' ) ;
26- const source = getOptionValue ( '--experimental-strip-types' ) ?
27- stripTypeScriptModuleTypes ( code ) :
28- code ;
2931
3032const print = getOptionValue ( '--print' ) ;
3133const shouldLoadESM = getOptionValue ( '--import' ) . length > 0 || getOptionValue ( '--experimental-loader' ) . length > 0 ;
32- if ( getOptionValue ( '--input-type' ) === 'module' ) {
33- evalModuleEntryPoint ( source , print ) ;
34+ const inputType = getOptionValue ( '--input-type' ) ;
35+ const tsEnabled = getOptionValue ( '--experimental-strip-types' ) ;
36+ if ( inputType === 'module' ) {
37+ evalModuleEntryPoint ( code , print ) ;
38+ } else if ( inputType === 'module-typescript' && tsEnabled ) {
39+ parseAndEvalModuleTypeScript ( code , print ) ;
3440} else {
3541 // For backward compatibility, we want the identifier crypto to be the
3642 // `node:crypto` module rather than WebCrypto.
37- const isUsingCryptoIdentifier = RegExpPrototypeExec ( / \b c r y p t o \b / , source ) !== null ;
43+ const isUsingCryptoIdentifier = RegExpPrototypeExec ( / \b c r y p t o \b / , code ) !== null ;
3844 const shouldDefineCrypto = isUsingCryptoIdentifier && internalBinding ( 'config' ) . hasOpenSSL ;
3945
4046 if ( isUsingCryptoIdentifier && ! shouldDefineCrypto ) {
@@ -49,11 +55,24 @@ if (getOptionValue('--input-type') === 'module') {
4955 } ;
5056 ObjectDefineProperty ( object , name , { __proto__ : null , set : setReal } ) ;
5157 }
52- evalScript ( '[eval]' ,
53- shouldDefineCrypto ? (
54- print ? `let crypto=require("node:crypto");{${ source } }` : `(crypto=>{{${ source } }})(require('node:crypto'))`
55- ) : source ,
56- getOptionValue ( '--inspect-brk' ) ,
57- print ,
58- shouldLoadESM ) ;
58+
59+ let evalFunction ;
60+ if ( inputType === 'commonjs' ) {
61+ evalFunction = evalScript ;
62+ } else if ( inputType === 'commonjs-typescript' && tsEnabled ) {
63+ evalFunction = parseAndEvalCommonjsTypeScript ;
64+ } else if ( tsEnabled ) {
65+ evalFunction = evalTypeScript ;
66+ } else {
67+ // Default to commonjs.
68+ evalFunction = evalScript ;
69+ }
70+
71+ evalFunction ( '[eval]' ,
72+ shouldDefineCrypto ? (
73+ print ? `let crypto=require("node:crypto");{${ code } }` : `(crypto=>{{${ code } }})(require('node:crypto'))`
74+ ) : code ,
75+ getOptionValue ( '--inspect-brk' ) ,
76+ print ,
77+ shouldLoadESM ) ;
5978}
0 commit comments