Rename "babylon" to "@babel/parser" (#7937) 🎉
This commit is contained in:
committed by
Henry Zhu
parent
0200a3e510
commit
daf0ca8680
40
packages/babel-parser/src/parser/location.js
Normal file
40
packages/babel-parser/src/parser/location.js
Normal file
@@ -0,0 +1,40 @@
|
||||
// @flow
|
||||
|
||||
import { getLineInfo, type Position } from "../util/location";
|
||||
import CommentsParser from "./comments";
|
||||
|
||||
// This function is used to raise exceptions on parse errors. It
|
||||
// takes an offset integer (into the current `input`) to indicate
|
||||
// the location of the error, attaches the position to the end
|
||||
// of the error message, and then raises a `SyntaxError` with that
|
||||
// message.
|
||||
|
||||
export default class LocationParser extends CommentsParser {
|
||||
raise(
|
||||
pos: number,
|
||||
message: string,
|
||||
{
|
||||
missingPluginNames,
|
||||
code,
|
||||
}: {
|
||||
missingPluginNames?: Array<string>,
|
||||
code?: string,
|
||||
} = {},
|
||||
): empty {
|
||||
const loc = getLineInfo(this.input, pos);
|
||||
message += ` (${loc.line}:${loc.column})`;
|
||||
// $FlowIgnore
|
||||
const err: SyntaxError & { pos: number, loc: Position } = new SyntaxError(
|
||||
message,
|
||||
);
|
||||
err.pos = pos;
|
||||
err.loc = loc;
|
||||
if (missingPluginNames) {
|
||||
err.missingPlugin = missingPluginNames;
|
||||
}
|
||||
if (code !== undefined) {
|
||||
err.code = code;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user