1
1
// @flow
2
+ import Anser from 'anser' ;
2
3
3
4
export type ErrorLocation = { |
4
5
filePath : string ,
@@ -7,9 +8,16 @@ export type ErrorLocation = {|
7
8
8
9
const filePathRegex = / ^ \. ( \/ [ ^ \/ \n ] + ) + \. [ ^ \/ \n ] + $ / ;
9
10
10
- // Based on syntax error formating of babylon parser
11
- // https://github.com/babel/babylon/blob/v7.0.0-beta.22/src/parser/location.js#L19
12
- const lineNumberRegex = / ^ .* \( ( \d + ) : ( \d + ) \) $ / ;
11
+ const lineNumberRegexes = [
12
+ // Babel syntax errors
13
+ // Based on syntax error formating of babylon parser
14
+ // https://github.com/babel/babylon/blob/v7.0.0-beta.22/src/parser/location.js#L19
15
+ / ^ .* \( ( \d + ) : ( \d + ) \) $ / ,
16
+
17
+ // ESLint errors
18
+ // Based on eslintFormatter in react-dev-utils
19
+ / ^ L i n e ( \d + ) : .+ $ / ,
20
+ ] ;
13
21
14
22
// Based on error formatting of webpack
15
23
// https://github.com/webpack/webpack/blob/v3.5.5/lib/Stats.js#L183-L217
@@ -19,18 +27,21 @@ function parseCompileError(message: string): ?ErrorLocation {
19
27
let lineNumber: number = 0;
20
28
21
29
for (let i = 0; i < lines . length ; i ++ ) {
22
- const line : string = lines [ i ] ;
30
+ const line : string = Anser . ansiToText ( lines [ i ] ) . trim ( ) ;
23
31
if ( ! line ) continue ;
24
32
25
33
if ( ! filePath && line . match ( filePathRegex ) ) {
26
34
filePath = line ;
27
35
}
28
36
29
- if ( ! lineNumber ) {
30
- const match : ?Array < string > = line.match(lineNumberRegex);
37
+ let k = 0 ;
38
+ while ( k < lineNumberRegexes . length ) {
39
+ const match : ?Array < string > = line.match(lineNumberRegexes[k]);
31
40
if (match) {
32
41
lineNumber = parseInt ( match [ 1 ] ) ;
42
+ break ;
33
43
}
44
+ k++;
34
45
}
35
46
36
47
if ( filePath && lineNumber ) break ;
0 commit comments