@@ -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' ;
@@ -115,7 +116,6 @@ class Editor extends React.Component {
115
116
styleSelectedText : true ,
116
117
lint : {
117
118
onUpdateLinting : ( annotations ) => {
118
- this . props . hideRuntimeErrorWarning ( ) ;
119
119
this . updateLintingMessageAccessibility ( annotations ) ;
120
120
} ,
121
121
options : {
@@ -159,10 +159,11 @@ class Editor extends React.Component {
159
159
'change' ,
160
160
debounce ( ( ) => {
161
161
this . props . setUnsavedChanges ( true ) ;
162
+ this . props . hideRuntimeErrorWarning ( ) ;
162
163
this . props . updateFileContent ( this . props . file . id , this . _cm . getValue ( ) ) ;
163
164
if ( this . props . autorefresh && this . props . isPlaying ) {
164
165
this . props . clearConsole ( ) ;
165
- this . props . startRefreshSketch ( ) ;
166
+ this . props . startSketch ( ) ;
166
167
}
167
168
} , 1000 )
168
169
) ;
@@ -246,41 +247,45 @@ class Editor extends React.Component {
246
247
) ;
247
248
}
248
249
249
- if ( prevProps . consoleEvents !== this . props . consoleEvents ) {
250
- this . props . showRuntimeErrorWarning ( ) ;
251
- }
252
- for ( let i = 0 ; i < this . _cm . lineCount ( ) ; i += 1 ) {
253
- this . _cm . removeLineClass ( i , 'background' , 'line-runtime-error' ) ;
254
- }
255
250
if ( this . props . runtimeErrorWarningVisible ) {
256
- this . props . consoleEvents . forEach ( ( consoleEvent ) => {
257
- if ( consoleEvent . method === 'error' ) {
258
- if (
259
- consoleEvent . data &&
260
- consoleEvent . data [ 0 ] &&
261
- consoleEvent . data [ 0 ] . indexOf &&
262
- consoleEvent . data [ 0 ] . indexOf ( ')' ) > - 1
263
- ) {
264
- const n = consoleEvent . data [ 0 ] . replace ( ')' , '' ) . split ( ' ' ) ;
265
- const lineNumber = parseInt ( n [ n . length - 1 ] , 10 ) - 1 ;
266
- const { source } = consoleEvent ;
267
- const fileName = this . props . file . name ;
268
- const errorFromJavaScriptFile = ` ${ source } .js` === fileName ;
269
- const errorFromIndexHTML =
270
- source === fileName && fileName === 'index.html' ;
271
- if (
272
- ! Number . isNaN ( lineNumber ) &&
273
- ( errorFromJavaScriptFile || errorFromIndexHTML )
274
- ) {
251
+ if ( this . props . consoleEvents . length !== prevProps . consoleEvents . length ) {
252
+ this . props . consoleEvents . forEach ( ( consoleEvent ) => {
253
+ if ( consoleEvent . method === 'error' ) {
254
+ // It doesn't work if you create a new Error, but this works
255
+ // LOL
256
+ const errorObj = { stack : consoleEvent . data [ 0 ] . toString ( ) } ;
257
+ StackTrace . fromError ( errorObj ) . then ( ( stackLines ) => {
258
+ this . props . expandConsole ( ) ;
259
+ const line = stackLines . find (
260
+ ( l ) => l . fileName && l . fileName . startsWith ( '/' )
261
+ ) ;
262
+ if ( ! line ) return ;
263
+ const fileNameArray = line . fileName . split ( '/' ) ;
264
+ const fileName = fileNameArray . slice ( - 1 ) [ 0 ] ;
265
+ const filePath = fileNameArray . slice ( 0 , - 1 ) . join ( '/' ) ;
266
+ const fileWithError = this . props . files . find (
267
+ ( f ) => f . name === fileName && f . filePath === filePath
268
+ ) ;
269
+ this . props . setSelectedFile ( fileWithError . id ) ;
275
270
this . _cm . addLineClass (
276
- lineNumber ,
271
+ line . lineNumber - 1 ,
277
272
'background' ,
278
273
'line-runtime-error'
279
274
) ;
280
- }
275
+ } ) ;
281
276
}
277
+ } ) ;
278
+ } else {
279
+ for ( let i = 0 ; i < this . _cm . lineCount ( ) ; i += 1 ) {
280
+ this . _cm . removeLineClass ( i , 'background' , 'line-runtime-error' ) ;
282
281
}
283
- } ) ;
282
+ }
283
+ }
284
+
285
+ if ( this . props . file . id !== prevProps . file . id ) {
286
+ for ( let i = 0 ; i < this . _cm . lineCount ( ) ; i += 1 ) {
287
+ this . _cm . removeLineClass ( i , 'background' , 'line-runtime-error' ) ;
288
+ }
284
289
}
285
290
}
286
291
@@ -440,7 +445,7 @@ Editor.propTypes = {
440
445
method : PropTypes . string . isRequired ,
441
446
args : PropTypes . arrayOf ( PropTypes . string )
442
447
} )
443
- ) ,
448
+ ) . isRequired ,
444
449
updateLintMessage : PropTypes . func . isRequired ,
445
450
clearLintMessage : PropTypes . func . isRequired ,
446
451
updateFileContent : PropTypes . func . isRequired ,
@@ -453,7 +458,7 @@ Editor.propTypes = {
453
458
url : PropTypes . string
454
459
} ) . isRequired ,
455
460
setUnsavedChanges : PropTypes . func . isRequired ,
456
- startRefreshSketch : PropTypes . func . isRequired ,
461
+ startSketch : PropTypes . func . isRequired ,
457
462
autorefresh : PropTypes . bool . isRequired ,
458
463
isPlaying : PropTypes . bool . isRequired ,
459
464
theme : PropTypes . string . isRequired ,
@@ -471,15 +476,13 @@ Editor.propTypes = {
471
476
expandSidebar : PropTypes . func . isRequired ,
472
477
isUserOwner : PropTypes . bool . isRequired ,
473
478
clearConsole : PropTypes . func . isRequired ,
474
- showRuntimeErrorWarning : PropTypes . func . isRequired ,
479
+ // showRuntimeErrorWarning: PropTypes.func.isRequired,
475
480
hideRuntimeErrorWarning : PropTypes . func . isRequired ,
476
481
runtimeErrorWarningVisible : PropTypes . bool . isRequired ,
477
482
provideController : PropTypes . func . isRequired ,
478
- t : PropTypes . func . isRequired
479
- } ;
480
-
481
- Editor . defaultProps = {
482
- consoleEvents : [ ]
483
+ t : PropTypes . func . isRequired ,
484
+ setSelectedFile : PropTypes . func . isRequired ,
485
+ expandConsole : PropTypes . func . isRequired
483
486
} ;
484
487
485
488
function mapStateToProps ( state ) {
@@ -496,7 +499,7 @@ function mapStateToProps(state) {
496
499
user : state . user ,
497
500
project : state . project ,
498
501
toast : state . toast ,
499
- console : state . console ,
502
+ consoleEvents : state . console ,
500
503
501
504
...state . preferences ,
502
505
...state . ide ,
0 commit comments