feat: use syntax plugin
This commit is contained in:
parent
03d89b6307
commit
51bd87baa8
@ -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
|
||||||
|
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
3
test/fixtures/experimental/optional-chaining/class-contructor-call/options.json
vendored
Normal file
3
test/fixtures/experimental/optional-chaining/class-contructor-call/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["optionalChaining"]
|
||||||
|
}
|
||||||
3
test/fixtures/experimental/optional-chaining/function-call/options.json
vendored
Normal file
3
test/fixtures/experimental/optional-chaining/function-call/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["optionalChaining"]
|
||||||
|
}
|
||||||
3
test/fixtures/experimental/optional-chaining/member-access-bracket/options.json
vendored
Normal file
3
test/fixtures/experimental/optional-chaining/member-access-bracket/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["optionalChaining"]
|
||||||
|
}
|
||||||
3
test/fixtures/experimental/optional-chaining/member-access/options.json
vendored
Normal file
3
test/fixtures/experimental/optional-chaining/member-access/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["optionalChaining"]
|
||||||
|
}
|
||||||
1
test/fixtures/experimental/optional-chaining/missing-plugin/actual.js
vendored
Normal file
1
test/fixtures/experimental/optional-chaining/missing-plugin/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
a?.b
|
||||||
3
test/fixtures/experimental/optional-chaining/missing-plugin/options.json
vendored
Normal file
3
test/fixtures/experimental/optional-chaining/missing-plugin/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "You can only use optional-chaining when the 'optionalChaining' plugin is enabled. (1:0)"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user