@@ -7,6 +7,7 @@ import babelParser from 'prettier/parser-babel';
7
7
import htmlParser from 'prettier/parser-html' ;
8
8
import cssParser from 'prettier/parser-postcss' ;
9
9
import { withTranslation } from 'react-i18next' ;
10
+ import StackTrace from 'stacktrace-js' ;
10
11
import 'codemirror/mode/css/css' ;
11
12
import 'codemirror/addon/selection/active-line' ;
12
13
import 'codemirror/addon/lint/lint' ;
@@ -252,42 +253,25 @@ class Editor extends React.Component {
252
253
253
254
this . props . consoleEvents . forEach ( ( consoleEvent ) => {
254
255
if ( consoleEvent . method === 'error' ) {
255
- if ( consoleEvent . data && consoleEvent . data [ 0 ] ) {
256
- let sourceAndLoc ;
257
- if (
258
- consoleEvent . data [ 0 ] . indexOf &&
259
- consoleEvent . data [ 0 ] . indexOf ( ')' ) > - 1
260
- ) {
261
- sourceAndLoc = consoleEvent . data [ 0 ] // eslint-disable-line
262
- . split ( '\n' ) [ 1 ]
263
- . split ( '(' ) [ 1 ]
264
- . split ( ')' ) [ 0 ] ;
265
- } else if ( consoleEvent . data [ 0 ] . indexOf ( 'at ' ) > - 1 ) {
266
- sourceAndLoc = consoleEvent . data [ 0 ] // eslint-disable-line
267
- . split ( '\n' ) [ 1 ]
268
- . split ( 'at ' ) [ 1 ] ;
269
- } else {
256
+ StackTrace . fromError ( new Error ( consoleEvent . data [ 0 ] ) ) . then (
257
+ ( stackLines ) => {
270
258
this . props . expandConsole ( ) ;
271
- return ;
259
+ const line = stackLines . find ( ( l ) => l . fileName . startsWith ( '/' ) ) ;
260
+ if ( ! line ) return ;
261
+ const fileNameArray = line . fileName . split ( '/' ) ;
262
+ const fileName = fileNameArray . slice ( - 1 ) [ 0 ] ;
263
+ const filePath = fileNameArray . slice ( 0 , - 1 ) . join ( '/' ) ;
264
+ const fileWithError = this . props . files . find (
265
+ ( f ) => f . name === fileName && f . filePath === filePath
266
+ ) ;
267
+ this . props . setSelectedFile ( fileWithError . id ) ;
268
+ this . _cm . addLineClass (
269
+ line . lineNumber - 1 ,
270
+ 'background' ,
271
+ 'line-runtime-error'
272
+ ) ;
272
273
}
273
- const [ source , line ] = sourceAndLoc . split ( ':' ) ;
274
-
275
- // get the file that this message is coming from, and then select it
276
- const sourceArray = source . split ( '/' ) ;
277
- const fileName = sourceArray . slice ( - 1 ) [ 0 ] ;
278
- const filePath = sourceArray . slice ( 0 , - 1 ) . join ( '/' ) ;
279
- const fileWithError = this . props . files . find (
280
- ( f ) => f . name === fileName && f . filePath === filePath
281
- ) ;
282
- this . props . setSelectedFile ( fileWithError . id ) ;
283
- this . props . expandConsole ( ) ;
284
- const lineNumber = parseInt ( line , 10 ) - 1 ;
285
- this . _cm . addLineClass (
286
- lineNumber ,
287
- 'background' ,
288
- 'line-runtime-error'
289
- ) ;
290
- }
274
+ ) ;
291
275
}
292
276
} ) ;
293
277
} else {
0 commit comments