fix buildCodeFrameError empty code frames

This commit is contained in:
Tim Seckinger
2018-01-03 02:38:04 +01:00
committed by James Kyle
parent 49775e2f12
commit c3f6f7fe28
4 changed files with 25 additions and 6 deletions

View File

@@ -179,8 +179,8 @@ export default class File {
buildCodeFrameError(
node: ?{
loc?: { line: number, column: number },
_loc?: { line: number, column: number },
loc?: { start: { line: number, column: number } },
_loc?: { start: { line: number, column: number } },
},
msg: string,
Error: typeof Error = SyntaxError,
@@ -212,8 +212,8 @@ export default class File {
this.code,
{
start: {
line: loc.line,
column: loc.column + 1,
line: loc.start.line,
column: loc.start.column + 1,
},
},
{ highlightCode },

View File

@@ -39,8 +39,8 @@ export default class PluginPass {
buildCodeFrameError(
node: ?{
loc?: { line: number, column: number },
_loc?: { line: number, column: number },
loc?: { start: { line: number, column: number } },
_loc?: { start: { line: number, column: number } },
},
msg: string,
Error?: typeof Error,

View File

@@ -0,0 +1,16 @@
var code = "function f() {}";
transform(code, {
plugins: [
function() {
return {
visitor: {
FunctionDeclaration: function(path) {
throw path.buildCodeFrameError("someMsg");
},
},
};
},
],
// hard to assert on ANSI escape codes
highlightCode: false,
});

View File

@@ -0,0 +1,3 @@
{
"throws": "undefined: someMsg\n> 1 | function f() {}"
}