feat: CallExpression support

This commit is contained in:
Sven SAULEAU 2017-05-30 20:12:43 +02:00
parent 26096d6a3d
commit 9bcd85acf3
No known key found for this signature in database
GPG Key ID: 7C3212582FBA1BA2
4 changed files with 146 additions and 0 deletions

View File

@ -897,6 +897,7 @@ interface CallExpression <: Expression {
type: "CallExpression";
callee: Expression | Super | Import;
arguments: [ Expression | SpreadElement ];
optional: boolean | null;
}
```

View File

@ -316,6 +316,16 @@ export default class ExpressionParser extends LValParser {
node.computed = true;
this.expect(tt.bracketR);
base = this.finishNode(node, "MemberExpression");
} if (this.eat(tt.parenL)) {
const possibleAsync = this.state.potentialArrowAt === base.start &&
base.type === "Identifier" &&
base.name === "async" &&
!this.canInsertSemicolon();
node.arguments = this.parseCallExpressionArguments(tt.parenR, possibleAsync);
node.optional = true;
base = this.finishNode(node, "CallExpression");
} else {
node.object = base;
node.property = this.parseIdentifier(true);

View File

@ -1 +1,3 @@
func?.()
func?.(a, b)

View File

@ -0,0 +1,133 @@
{
"type": "File",
"start": 0,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 12
}
},
"program": {
"type": "Program",
"start": 0,
"end": 22,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 12
}
},
"sourceType": "script",
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
}
},
"expression": {
"type": "CallExpression",
"start": 0,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
}
},
"arguments": [],
"optional": true
}
},
{
"type": "ExpressionStatement",
"start": 10,
"end": 22,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 12
}
},
"expression": {
"type": "CallExpression",
"start": 10,
"end": 22,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 12
}
},
"arguments": [
{
"type": "Identifier",
"start": 17,
"end": 18,
"loc": {
"start": {
"line": 3,
"column": 7
},
"end": {
"line": 3,
"column": 8
},
"identifierName": "a"
},
"name": "a"
},
{
"type": "Identifier",
"start": 20,
"end": 21,
"loc": {
"start": {
"line": 3,
"column": 10
},
"end": {
"line": 3,
"column": 11
},
"identifierName": "b"
},
"name": "b"
}
],
"optional": true
}
}
],
"directives": []
}
}