feat: if code frame error is on a single line, highlight the w… (#10361)
* feat: if code frame error is on a single line, highlight the whole path * flow
This commit is contained in:
parent
b6ef9689b2
commit
f1bc6c4e18
@ -19,6 +19,17 @@ const errorVisitor = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type NodeLocation = {
|
||||||
|
loc?: {
|
||||||
|
end?: { line: number, column: number },
|
||||||
|
start: { line: number, column: number },
|
||||||
|
},
|
||||||
|
_loc?: {
|
||||||
|
end?: { line: number, column: number },
|
||||||
|
start: { line: number, column: number },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export default class File {
|
export default class File {
|
||||||
_map: Map<any, any> = new Map();
|
_map: Map<any, any> = new Map();
|
||||||
opts: Object;
|
opts: Object;
|
||||||
@ -250,10 +261,7 @@ export default class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildCodeFrameError(
|
buildCodeFrameError(
|
||||||
node: ?{
|
node: ?NodeLocation,
|
||||||
loc?: { start: { line: number, column: number } },
|
|
||||||
_loc?: { start: { line: number, column: number } },
|
|
||||||
},
|
|
||||||
msg: string,
|
msg: string,
|
||||||
Error: typeof Error = SyntaxError,
|
Error: typeof Error = SyntaxError,
|
||||||
): Error {
|
): Error {
|
||||||
@ -285,6 +293,13 @@ export default class File {
|
|||||||
line: loc.start.line,
|
line: loc.start.line,
|
||||||
column: loc.start.column + 1,
|
column: loc.start.column + 1,
|
||||||
},
|
},
|
||||||
|
end:
|
||||||
|
loc.end && loc.start.line === loc.end.line
|
||||||
|
? {
|
||||||
|
line: loc.end.line,
|
||||||
|
column: loc.end.column + 1,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
},
|
},
|
||||||
{ highlightCode },
|
{ highlightCode },
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import type File from "./file/file";
|
import type File from "./file/file";
|
||||||
|
import type NodeLocation from "./file/file";
|
||||||
|
|
||||||
export default class PluginPass {
|
export default class PluginPass {
|
||||||
_map: Map<mixed, mixed> = new Map();
|
_map: Map<mixed, mixed> = new Map();
|
||||||
@ -47,14 +48,7 @@ export default class PluginPass {
|
|||||||
return this.file.getModuleName();
|
return this.file.getModuleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
buildCodeFrameError(
|
buildCodeFrameError(node: ?NodeLocation, msg: string, Error?: typeof Error) {
|
||||||
node: ?{
|
|
||||||
loc?: { start: { line: number, column: number } },
|
|
||||||
_loc?: { start: { line: number, column: number } },
|
|
||||||
},
|
|
||||||
msg: string,
|
|
||||||
Error?: typeof Error,
|
|
||||||
) {
|
|
||||||
return this.file.buildCodeFrameError(node, msg, Error);
|
return this.file.buildCodeFrameError(node, msg, Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user