diff --git a/src/parser/location.js b/src/parser/location.js index a2a6039762..c506fd0928 100644 --- a/src/parser/location.js +++ b/src/parser/location.js @@ -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; } } diff --git a/src/parser/util.js b/src/parser/util.js index bc789ef993..1300637276 100644 --- a/src/parser/util.js +++ b/src/parser/util.js @@ -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, + ); + } + } }