@@ -6,11 +6,10 @@ import { inspect } from 'util'
6
6
import arrify = require ( 'arrify' )
7
7
import Module = require ( 'module' )
8
8
import minimist = require ( 'minimist' )
9
- import chalk from 'chalk'
10
9
import { diffLines } from 'diff'
11
10
import { Script } from 'vm'
12
11
import { readFileSync , statSync } from 'fs'
13
- import { register , VERSION , DEFAULTS , TSError , parse , printError } from './index'
12
+ import { register , VERSION , DEFAULTS , TSError , parse } from './index'
14
13
15
14
interface Argv {
16
15
// Node.js-like options.
@@ -21,6 +20,7 @@ interface Argv {
21
20
help ?: boolean
22
21
version ? : boolean
23
22
// Register options.
23
+ pretty ? : boolean
24
24
typeCheck ? : boolean
25
25
transpileOnly ? : boolean
26
26
cache ? : boolean
@@ -38,7 +38,7 @@ interface Argv {
38
38
const argv = minimist < Argv > ( process . argv . slice ( 2 ) , {
39
39
stopEarly : true ,
40
40
string : [ 'eval' , 'print' , 'compiler' , 'project' , 'ignoreDiagnostics' , 'require' , 'cacheDirectory' , 'ignore' ] ,
41
- boolean : [ 'help' , 'transpileOnly' , 'typeCheck' , 'version' , 'cache' , 'skipProject' , 'skipIgnore' ] ,
41
+ boolean : [ 'help' , 'transpileOnly' , 'typeCheck' , 'version' , 'cache' , 'pretty' , ' skipProject', 'skipIgnore' ] ,
42
42
alias : {
43
43
eval : [ 'e' ] ,
44
44
print : [ 'p' ] ,
@@ -86,6 +86,7 @@ Options:
86
86
-D, --ignoreDiagnostics [code] Ignore TypeScript warnings by diagnostic code
87
87
-O, --compilerOptions [opts] JSON object to merge with compiler options
88
88
89
+ --pretty Use pretty diagnostic formatter
89
90
--no-cache Disable the local TypeScript Node cache
90
91
--skip-project Skip reading \`tsconfig.json\`
91
92
--skip-ignore Skip \`--ignore\` checks
@@ -101,6 +102,7 @@ const isPrinted = argv.print !== undefined
101
102
102
103
// Register the TypeScript compiler instance.
103
104
const service = register ( {
105
+ pretty : argv . pretty ,
104
106
typeCheck : argv . typeCheck ,
105
107
transpileOnly : argv . transpileOnly ,
106
108
cache : argv . cache ,
@@ -175,7 +177,7 @@ function evalAndExit (code: string, isPrinted: boolean) {
175
177
result = _eval ( code )
176
178
} catch ( error ) {
177
179
if ( error instanceof TSError ) {
178
- console . error ( printError ( error ) )
180
+ console . error ( error . diagnosticText )
179
181
process . exit ( 1 )
180
182
}
181
183
@@ -265,7 +267,7 @@ function startRepl () {
265
267
266
268
undo ( )
267
269
268
- repl . outputStream . write ( `${ chalk . bold ( name ) } \n${ comment ? `${ comment } \n` : '' } ` )
270
+ repl . outputStream . write ( `${ name } \n${ comment ? `${ comment } \n` : '' } ` )
269
271
repl . displayPrompt ( )
270
272
}
271
273
} )
@@ -275,7 +277,7 @@ function startRepl () {
275
277
* Eval code from the REPL.
276
278
*/
277
279
function replEval ( code : string , _context : any , _filename : string , callback : ( err ? : Error , result ? : any ) = > any ) {
278
- let err : any
280
+ let err : Error | undefined
279
281
let result : any
280
282
281
283
// TODO: Figure out how to handle completion here.
@@ -292,7 +294,8 @@ function replEval (code: string, _context: any, _filename: string, callback: (er
292
294
if ( Recoverable && isRecoverable ( error ) ) {
293
295
err = new Recoverable ( error )
294
296
} else {
295
- err = printError ( error )
297
+ console . error ( error . diagnosticText )
298
+ err = undefined
296
299
}
297
300
} else {
298
301
err = error
@@ -368,18 +371,18 @@ function fileExistsEval (path: string) {
368
371
}
369
372
}
370
373
371
- const RECOVERY_CODES : number [ ] = [
374
+ const RECOVERY_CODES : Set < number > = new Set( [
372
375
1003, // "Identifier expected."
373
376
1005, // "')' expected."
374
377
1109, // "Expression expected."
375
378
1126, // "Unexpected end of text."
376
379
1160, // "Unterminated template literal."
377
380
1161 // "Unterminated regular expression literal."
378
- ]
381
+ ])
379
382
380
383
/**
381
384
* Check if a function can recover gracefully.
382
385
*/
383
386
function isRecoverable (error: TSError) {
384
- return error . diagnostics . every ( x => RECOVERY_CODES . indexOf ( x . code ) > - 1 )
387
+ return error . diagnosticCodes . every ( code => RECOVERY_CODES . has ( code ) )
385
388
}
0 commit comments