forked from code-dot-org/code-dot-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlocklyModeErrorHandler.js
More file actions
31 lines (28 loc) · 975 Bytes
/
Copy pathBlocklyModeErrorHandler.js
File metadata and controls
31 lines (28 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import JavaScriptModeErrorHandler from './JavaScriptModeErrorHandler';
// Number of surrounding context lines to show (before and after). A value of 0
// will only show the line that threw the error.
const context = 2;
export default class BlocklyModeErrorHandler extends JavaScriptModeErrorHandler {
output_(message, logLevel, lineNumber) {
try {
console.groupCollapsed(message);
const interpreter = this.getJsInterpreter_();
if (lineNumber && interpreter) {
const start = Math.max(lineNumber - context - 1, 0);
const count = context * 2 + 1;
const message = interpreter.codeInfo.code
.split(/\n/g)
.splice(start, count)
.map((line, n) => {
return (n === context ? '>>> ' : ' ') + line;
})
.join('\n');
console.log(message);
} else {
console.log('No context available.');
}
} finally {
console.groupEnd();
}
}
}