This repository was archived by the owner on May 19, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 255
Syntax Error: add message with the plugin that should be enabled #658
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cf3ebac
add expectPlugin which throws an error with the missing plugin
motiz88 2dbba25
change some things to expectPlugin
hzoo de47b04
rename folders, add more
hzoo dfb279f
Add test for function.
danez aec1bdb
Enable no-case-declarations to prevent bugs and remove if (true)
danez 96bd271
Fix tests
danez 19c099d
Use expectPlugin
danez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -433,12 +433,7 @@ export default class ExpressionParser extends LValParser { | |
noCalls, | ||
); | ||
} else if (this.match(tt.questionDot)) { | ||
if (!this.hasPlugin("optionalChaining")) { | ||
this.raise( | ||
startPos, | ||
"You can only use optional-chaining when the 'optionalChaining' plugin is enabled.", | ||
); | ||
} | ||
this.expectPlugin("optionalChaining"); | ||
|
||
if (noCalls && this.lookahead().type == tt.parenL) { | ||
state.stop = true; | ||
|
@@ -660,11 +655,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(); | ||
} | ||
|
||
if (!this.hasPlugin("dynamicImport")) this.unexpected(); | ||
this.expectPlugin("dynamicImport"); | ||
|
||
node = this.startNode(); | ||
this.next(); | ||
|
@@ -681,7 +676,7 @@ export default class ExpressionParser extends LValParser { | |
case tt._yield: | ||
if (this.state.inGenerator) this.unexpected(); | ||
|
||
case tt.name: | ||
case tt.name: { | ||
node = this.startNode(); | ||
const allowAwait = this.state.value === "await" && this.state.inAsync; | ||
const allowYield = this.shouldAllowYieldIdentifier(); | ||
|
@@ -710,27 +705,29 @@ export default class ExpressionParser extends LValParser { | |
} | ||
|
||
return id; | ||
} | ||
|
||
case tt._do: | ||
if (this.hasPlugin("doExpressions")) { | ||
const node = this.startNode(); | ||
this.next(); | ||
const oldInFunction = this.state.inFunction; | ||
const oldLabels = this.state.labels; | ||
this.state.labels = []; | ||
this.state.inFunction = false; | ||
node.body = this.parseBlock(false); | ||
this.state.inFunction = oldInFunction; | ||
this.state.labels = oldLabels; | ||
return this.finishNode(node, "DoExpression"); | ||
} | ||
case tt._do: { | ||
this.expectPlugin("doExpressions"); | ||
const node = this.startNode(); | ||
this.next(); | ||
const oldInFunction = this.state.inFunction; | ||
const oldLabels = this.state.labels; | ||
this.state.labels = []; | ||
this.state.inFunction = false; | ||
node.body = this.parseBlock(false); | ||
this.state.inFunction = oldInFunction; | ||
this.state.labels = oldLabels; | ||
return this.finishNode(node, "DoExpression"); | ||
} | ||
|
||
case tt.regexp: | ||
case tt.regexp: { | ||
const value = this.state.value; | ||
node = this.parseLiteral(value.value, "RegExpLiteral"); | ||
node.pattern = value.pattern; | ||
node.flags = value.flags; | ||
return node; | ||
} | ||
|
||
case tt.num: | ||
return this.parseLiteral(this.state.value, "NumericLiteral"); | ||
|
@@ -784,7 +781,7 @@ export default class ExpressionParser extends LValParser { | |
case tt.backQuote: | ||
return this.parseTemplate(false); | ||
|
||
case tt.doubleColon: | ||
case tt.doubleColon: { | ||
node = this.startNode(); | ||
this.next(); | ||
node.object = null; | ||
|
@@ -797,6 +794,7 @@ export default class ExpressionParser extends LValParser { | |
"Binding should be performed on object property.", | ||
); | ||
} | ||
} | ||
|
||
default: | ||
throw this.unexpected(); | ||
|
@@ -825,11 +823,7 @@ export default class ExpressionParser extends LValParser { | |
parseFunctionExpression(): N.FunctionExpression | N.MetaProperty { | ||
const node = this.startNode(); | ||
const meta = this.parseIdentifier(true); | ||
if ( | ||
this.state.inGenerator && | ||
this.hasPlugin("functionSent") && | ||
this.eat(tt.dot) | ||
) { | ||
if (this.state.inGenerator && this.eat(tt.dot)) { | ||
return this.parseMetaProperty(node, meta, "sent"); | ||
} | ||
return this.parseFunction(node, false); | ||
|
@@ -841,6 +835,16 @@ export default class ExpressionParser extends LValParser { | |
propertyName: string, | ||
): N.MetaProperty { | ||
node.meta = meta; | ||
|
||
if (meta.name === "function" && propertyName === "sent") { | ||
if (this.isContextual(propertyName)) { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Uncovered. I add a test. |
||
} | ||
} | ||
|
||
node.property = this.parseIdentifier(true); | ||
|
||
if (node.property.name !== propertyName) { | ||
|
@@ -857,6 +861,18 @@ export default class ExpressionParser extends LValParser { | |
const node = this.startNode(); | ||
const id = this.parseIdentifier(true); | ||
this.expect(tt.dot); | ||
|
||
if (id.name === "import") { | ||
if (this.isContextual("meta")) { | ||
this.expectPlugin("importMeta"); | ||
} else if (!this.hasPlugin("importMeta")) { | ||
this.raise( | ||
id.start, | ||
`Dynamic imports require a parameter: import('a.js').then`, | ||
); | ||
} | ||
} | ||
|
||
if (!this.inModule) { | ||
this.raise( | ||
id.start, | ||
|
@@ -1141,7 +1157,8 @@ export default class ExpressionParser extends LValParser { | |
decorators = []; | ||
} | ||
|
||
if (this.hasPlugin("objectRestSpread") && this.match(tt.ellipsis)) { | ||
if (this.match(tt.ellipsis)) { | ||
this.expectPlugin("objectRestSpread"); | ||
prop = this.parseSpread(isPattern ? { start: 0 } : undefined); | ||
if (isPattern) { | ||
this.toAssignable(prop, true, "object pattern"); | ||
|
@@ -1199,8 +1216,11 @@ export default class ExpressionParser extends LValParser { | |
prop.computed = false; | ||
} else { | ||
isAsync = true; | ||
if (this.hasPlugin("asyncGenerators")) | ||
isGenerator = this.eat(tt.star); | ||
if (this.match(tt.star)) { | ||
this.expectPlugin("asyncGenerators"); | ||
this.next(); | ||
isGenerator = true; | ||
} | ||
this.parsePropertyName(prop); | ||
} | ||
} else { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,9 +237,7 @@ export default class StatementParser extends ExpressionParser { | |
} | ||
|
||
parseDecorator(): N.Decorator { | ||
if (!(this.hasPlugin("decorators") || this.hasPlugin("decorators2"))) { | ||
this.unexpected(); | ||
} | ||
this.expectOnePlugin(["decorators", "decorators2"]); | ||
|
||
const node = this.startNode(); | ||
this.next(); | ||
|
@@ -340,11 +338,8 @@ export default class StatementParser extends ExpressionParser { | |
this.state.labels.push(loopLabel); | ||
|
||
let forAwait = false; | ||
if ( | ||
this.hasPlugin("asyncGenerators") && | ||
this.state.inAsync && | ||
this.isContextual("await") | ||
) { | ||
if (this.state.inAsync && this.isContextual("await")) { | ||
this.expectPlugin("asyncGenerators"); | ||
forAwait = true; | ||
this.next(); | ||
} | ||
|
@@ -489,12 +484,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 commentThe reason will be displayed to describe this comment to others. Learn more. I guess this became redundant now? |
||
clause.param = this.parseBindingAtom(); | ||
this.checkLVal(clause.param, true, Object.create(null), "catch clause"); | ||
this.expect(tt.parenR); | ||
} else { | ||
this.expectPlugin("optionalCatchBinding"); | ||
clause.param = null; | ||
} | ||
clause.body = this.parseBlock(); | ||
|
@@ -782,12 +778,11 @@ export default class StatementParser extends ExpressionParser { | |
this.initFunction(node, isAsync); | ||
|
||
if (this.match(tt.star)) { | ||
if (node.async && !this.hasPlugin("asyncGenerators")) { | ||
this.unexpected(); | ||
} else { | ||
node.generator = true; | ||
this.next(); | ||
if (node.async) { | ||
this.expectPlugin("asyncGenerators"); | ||
} | ||
node.generator = true; | ||
this.next(); | ||
} | ||
|
||
if ( | ||
|
@@ -960,8 +955,9 @@ export default class StatementParser extends ExpressionParser { | |
isStatic = true; | ||
} | ||
|
||
if (this.hasPlugin("classPrivateProperties") && this.match(tt.hash)) { | ||
if (this.match(tt.hash)) { | ||
// Private property | ||
this.expectPlugin("classPrivateProperties"); | ||
this.next(); | ||
const privateProp: N.ClassPrivateProperty = memberAny; | ||
privateProp.key = this.parseIdentifier(true); | ||
|
@@ -1047,8 +1043,12 @@ export default class StatementParser extends ExpressionParser { | |
this.pushClassProperty(classBody, prop); | ||
} else if (isSimple && key.name === "async" && !this.isLineTerminator()) { | ||
// an async method | ||
const isGenerator = | ||
this.hasPlugin("asyncGenerators") && this.eat(tt.star); | ||
let isGenerator = false; | ||
if (this.match(tt.star)) { | ||
this.expectPlugin("asyncGenerators"); | ||
this.next(); | ||
isGenerator = true; | ||
} | ||
method.kind = "method"; | ||
this.parsePropertyName(method); | ||
if (this.isNonstaticConstructor(method)) { | ||
|
@@ -1151,24 +1151,22 @@ export default class StatementParser extends ExpressionParser { | |
} | ||
|
||
parseClassProperty(node: N.ClassProperty): N.ClassProperty { | ||
const noPluginMsg = | ||
"You can only use Class Properties when the 'classProperties' plugin is enabled."; | ||
if (!node.typeAnnotation && !this.hasPlugin("classProperties")) { | ||
this.raise(node.start, noPluginMsg); | ||
if (!node.typeAnnotation) { | ||
this.expectPlugin("classProperties"); | ||
} | ||
|
||
this.state.inClassProperty = true; | ||
|
||
if (this.match(tt.eq)) { | ||
if (!this.hasPlugin("classProperties")) | ||
this.raise(this.state.start, noPluginMsg); | ||
this.expectPlugin("classProperties"); | ||
this.next(); | ||
node.value = this.parseMaybeAssign(); | ||
} else { | ||
node.value = null; | ||
} | ||
this.semicolon(); | ||
this.state.inClassProperty = false; | ||
|
||
return this.finishNode(node, "ClassProperty"); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
vsimport.asdf
but maybe we shouldn't make a big deal out of it?