feat: use syntax plugin

This commit is contained in:
Sven SAULEAU 2017-05-30 18:35:29 +02:00
parent 03d89b6307
commit 51bd87baa8
No known key found for this signature in database
GPG Key ID: 7C3212582FBA1BA2
8 changed files with 23 additions and 2 deletions

View File

@ -139,6 +139,7 @@ require("babylon").parse("code", {
- `functionSent` - `functionSent`
- `dynamicImport` ([proposal](https://github.com/tc39/proposal-dynamic-import)) - `dynamicImport` ([proposal](https://github.com/tc39/proposal-dynamic-import))
- `numericSeparator` ([proposal](https://github.com/samuelgoto/proposal-numeric-separator)) - `numericSeparator` ([proposal](https://github.com/samuelgoto/proposal-numeric-separator))
- `optionalChaining` ([proposal](https://github.com/tc39/proposal-optional-chaining))
### FAQ ### FAQ

View File

@ -303,8 +303,13 @@ export default class ExpressionParser extends LValParser {
return this.parseSubscripts(this.finishNode(node, "BindExpression"), startPos, startLoc, noCalls); return this.parseSubscripts(this.finishNode(node, "BindExpression"), startPos, startLoc, noCalls);
} else if (this.eat(tt.questionDot)) { } else if (this.eat(tt.questionDot)) {
const node = this.startNodeAt(startPos, startLoc);
if (!this.hasPlugin("optionalChaining")) {
this.raise(node.start, "You can only use optional-chaining when the 'optionalChaining' plugin is enabled.");
}
if (this.eat(tt.bracketL)) { if (this.eat(tt.bracketL)) {
const node = this.startNodeAt(startPos, startLoc);
node.object = base; node.object = base;
node.optional = true; node.optional = true;
node.property = this.parseExpression(); node.property = this.parseExpression();
@ -312,7 +317,6 @@ export default class ExpressionParser extends LValParser {
this.expect(tt.bracketR); this.expect(tt.bracketR);
base = this.finishNode(node, "MemberExpression"); base = this.finishNode(node, "MemberExpression");
} else { } else {
const node = this.startNodeAt(startPos, startLoc);
node.object = base; node.object = base;
node.property = this.parseIdentifier(true); node.property = this.parseIdentifier(true);
node.optional = true; node.optional = true;

View File

@ -0,0 +1,3 @@
{
"plugins": ["optionalChaining"]
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["optionalChaining"]
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["optionalChaining"]
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["optionalChaining"]
}

View File

@ -0,0 +1 @@
a?.b

View File

@ -0,0 +1,3 @@
{
"throws": "You can only use optional-chaining when the 'optionalChaining' plugin is enabled. (1:0)"
}