feat: use syntax plugin
This commit is contained in:
parent
03d89b6307
commit
51bd87baa8
@ -139,6 +139,7 @@ require("babylon").parse("code", {
|
||||
- `functionSent`
|
||||
- `dynamicImport` ([proposal](https://github.com/tc39/proposal-dynamic-import))
|
||||
- `numericSeparator` ([proposal](https://github.com/samuelgoto/proposal-numeric-separator))
|
||||
- `optionalChaining` ([proposal](https://github.com/tc39/proposal-optional-chaining))
|
||||
|
||||
### FAQ
|
||||
|
||||
|
||||
@ -303,8 +303,13 @@ export default class ExpressionParser extends LValParser {
|
||||
return this.parseSubscripts(this.finishNode(node, "BindExpression"), startPos, startLoc, noCalls);
|
||||
|
||||
} else if (this.eat(tt.questionDot)) {
|
||||
if (this.eat(tt.bracketL)) {
|
||||
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)) {
|
||||
node.object = base;
|
||||
node.optional = true;
|
||||
node.property = this.parseExpression();
|
||||
@ -312,7 +317,6 @@ export default class ExpressionParser extends LValParser {
|
||||
this.expect(tt.bracketR);
|
||||
base = this.finishNode(node, "MemberExpression");
|
||||
} else {
|
||||
const node = this.startNodeAt(startPos, startLoc);
|
||||
node.object = base;
|
||||
node.property = this.parseIdentifier(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