@@ -11,6 +11,9 @@ const { getOptionValue } = require('internal/options');
1111
1212const {
1313 evalModuleEntryPoint,
14+ evalTypeScript,
15+ parseAndEvalCommonjsTypeScript,
16+ parseAndEvalModuleTypeScript,
1417 evalScript,
1518 readStdin,
1619} = require ( 'internal/process/execution' ) ;
@@ -25,14 +28,32 @@ readStdin((code) => {
2528
2629 const print = getOptionValue ( '--print' ) ;
2730 const shouldLoadESM = getOptionValue ( '--import' ) . length > 0 ;
28- if ( getOptionValue ( '--input-type' ) === 'module' ||
29- ( getOptionValue ( '--experimental-default-type' ) === 'module' && getOptionValue ( '--input-type' ) !== 'commonjs' ) ) {
31+ const inputType = getOptionValue ( '--input-type' ) ;
32+ const tsEnabled = getOptionValue ( '--experimental-strip-types' ) ;
33+ if ( inputType === 'module' ||
34+ ( getOptionValue ( '--experimental-default-type' ) === 'module' &&
35+ inputType !== 'commonjs' ) ) {
3036 evalModuleEntryPoint ( code , print ) ;
37+ } else if ( inputType === 'module-typescript' && tsEnabled ) {
38+ parseAndEvalModuleTypeScript ( code , print ) ;
3139 } else {
32- evalScript ( '[stdin]' ,
33- code ,
34- getOptionValue ( '--inspect-brk' ) ,
35- print ,
36- shouldLoadESM ) ;
40+
41+ let evalFunction ;
42+ if ( inputType === 'commonjs' ) {
43+ evalFunction = evalScript ;
44+ } else if ( inputType === 'commonjs-typescript' && tsEnabled ) {
45+ evalFunction = parseAndEvalCommonjsTypeScript ;
46+ } else if ( tsEnabled ) {
47+ evalFunction = evalTypeScript ;
48+ } else {
49+ // Default to commonjs.
50+ evalFunction = evalScript ;
51+ }
52+
53+ evalFunction ( '[stdin]' ,
54+ code ,
55+ getOptionValue ( '--inspect-brk' ) ,
56+ print ,
57+ shouldLoadESM ) ;
3758 }
3859} ) ;
0 commit comments