-
-
Notifications
You must be signed in to change notification settings - Fork 255
Syntax Error: add message with the plugin that should be enabled #658
Conversation
@@ -491,12 +486,13 @@ export default class StatementParser extends ExpressionParser { | |||
if (this.match(tt._catch)) { | |||
const clause = this.startNode(); | |||
this.next(); | |||
if (this.match(tt.parenL) || !this.hasPlugin("optionalCatchBinding")) { | |||
if (this.match(tt.parenL)) { | |||
this.expect(tt.parenL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this became redundant now?
@@ -627,11 +622,11 @@ export default class ExpressionParser extends LValParser { | |||
return this.finishNode(node, "Super"); | |||
|
|||
case tt._import: | |||
if (this.hasPlugin("importMeta") && this.lookahead().type === tt.dot) { | |||
if (this.lookahead().type === tt.dot) { | |||
return this.parseImportMetaProperty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you drop a this.expectPlugin("importMeta")
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's called by the parseImportMetaProperty
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this problem was brought up by @motiz88, @danez in https://github.com/babel/babylon/pull/178/files#r87556780
If we make the error here I guess it's a different error if they just have import.
vs import.asdf
but maybe we shouldn't make a big deal out of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
besides the if(true) {}
looks good
src/parser/expression.js
Outdated
@@ -679,7 +674,9 @@ export default class ExpressionParser extends LValParser { | |||
return id; | |||
|
|||
case tt._do: | |||
if (this.hasPlugin("doExpressions")) { | |||
// TODO | |||
if (true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this ? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a bug somewhere if I don't have it if you want to look into that 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this if
necessary at all? The _do
context can only be legally entered if the plugin is enabled to begin with.
You do need a block here because you have lexical declarations inside the case, but it should just be regular braces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it's not yeah I just need a block if that works
this.expectPlugin("functionSent"); | ||
} else if (!this.hasPlugin("functionSent")) { | ||
// They didn't actually say `function.sent`, just `function.`, so a simple error would be less confusing. | ||
this.unexpected(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uncovered. I add a test.
e0d3d59
to
5f58d89
Compare
I enabled the no-case-declarations. This should prevent this problems. |
Okay I also rebased the branch. |
src/parser/statement.js
Outdated
} | ||
|
||
this.state.inClassProperty = true; | ||
|
||
if (this.match(tt.eq)) { | ||
if (!this.hasPlugin("classProperties")) | ||
this.raise(this.state.start, noPluginMsg); | ||
this.expectOnePlugin(["classProperties"]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you can use
exceptPlugin
Also here
src/parser/statement.js
Outdated
if (!node.typeAnnotation && !this.hasPlugin("classProperties")) { | ||
this.raise(node.start, noPluginMsg); | ||
if (!node.typeAnnotation) { | ||
this.expectOnePlugin(["classProperties"]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you can use exceptPlugin
@@ -0,0 +1,4 @@ | |||
{ | |||
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'classProperties, typescript' (2:6)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this affected by #666?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome 👍
Just a question about the name expectPlugin
sounds like it's part of the lookahead process. What about assertPlugin
? shouldHavePlugin
? checkPlugin
?
Fixes #169
Closes #178
Rebased/rewrite of #178
Add a new method:
this.expectPlugin
instead ofthis.hasPlugin
which throws if the plugin isn't enabled.This also means something better than "unexpected token" when it's a config issue. This also isn't tied to Babel but just babylon's plugins, so other tools can catch the error like Babel will to produce their own specific error messages.
hasPlugin
(can be in later PRs)