add expectPlugin which throws an error with the missing plugin
This commit is contained in:
parent
2f76fc88be
commit
cf3ebacf4f
@ -10,7 +10,7 @@ import CommentsParser from "./comments";
|
||||
// message.
|
||||
|
||||
export default class LocationParser extends CommentsParser {
|
||||
raise(pos: number, message: string): empty {
|
||||
raise(pos: number, message: string, missingPluginName: string): empty {
|
||||
const loc = getLineInfo(this.input, pos);
|
||||
message += ` (${loc.line}:${loc.column})`;
|
||||
// $FlowIgnore
|
||||
@ -19,6 +19,9 @@ export default class LocationParser extends CommentsParser {
|
||||
);
|
||||
err.pos = pos;
|
||||
err.loc = loc;
|
||||
if (missingPluginName) {
|
||||
err.missingPlugin = missingPluginName;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,4 +109,14 @@ export default class UtilParser extends Tokenizer {
|
||||
}
|
||||
throw this.raise(pos != null ? pos : this.state.start, messageOrType);
|
||||
}
|
||||
|
||||
expectPlugin(name: string): void {
|
||||
if (!this.hasPlugin(name)) {
|
||||
throw this.raise(
|
||||
this.state.start,
|
||||
`This experimental syntax requires enabling the parser plugin: ${name}`,
|
||||
name,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user