Merge pull request #613 from jridgewell/function-sent-statement

Fix function.sent parsing
This commit is contained in:
Justin Ridgewell 2017-07-09 08:56:06 -04:00 committed by GitHub
commit cc643668c8
34 changed files with 935 additions and 4 deletions

View File

@ -802,13 +802,12 @@ export default class ExpressionParser extends LValParser {
const meta = this.parseIdentifier(true);
if (
this.state.inGenerator &&
this.eat(tt.dot) &&
this.hasPlugin("functionSent")
this.hasPlugin("functionSent") &&
this.eat(tt.dot)
) {
return this.parseMetaProperty(node, meta, "sent");
} else {
return this.parseFunction(node, false);
}
return this.parseFunction(node, false);
}
parseMetaProperty(

View File

@ -94,6 +94,7 @@ export default class StatementParser extends ExpressionParser {
case tt._for:
return this.parseForStatement(node);
case tt._function:
if (this.lookahead().type === tt.dot) break;
if (!declaration) this.unexpected();
return this.parseFunctionStatement(node);

View File

@ -0,0 +1,3 @@
function* foo() {
function.sent() {}
}

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected ( (2:10)"
}

View File

@ -0,0 +1,3 @@
function* foo() {
(function.sent() {});
}

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected ( (2:11)"
}

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected ( (2:17)"
}

View File

@ -0,0 +1,4 @@
function* foo() {
function.sent()
{}
}

View File

@ -0,0 +1,185 @@
{
"type": "File",
"start": 0,
"end": 42,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 42,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 42,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 4,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 10,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "foo"
},
"name": "foo"
},
"generator": true,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 16,
"end": 42,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 4,
"column": 1
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 20,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 17
}
},
"expression": {
"type": "CallExpression",
"start": 20,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 17
}
},
"callee": {
"type": "MetaProperty",
"start": 20,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 15
}
},
"meta": {
"type": "Identifier",
"start": 20,
"end": 28,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 10
},
"identifierName": "function"
},
"name": "function"
},
"property": {
"type": "Identifier",
"start": 29,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 15
},
"identifierName": "sent"
},
"name": "sent"
}
},
"arguments": []
}
},
{
"type": "BlockStatement",
"start": 38,
"end": 40,
"loc": {
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 4
}
},
"body": [],
"directives": []
}
],
"directives": []
}
}
],
"directives": []
}
}

View File

@ -0,0 +1,3 @@
function* foo() {
function.sent();
}

View File

@ -0,0 +1,168 @@
{
"type": "File",
"start": 0,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 10,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "foo"
},
"name": "foo"
},
"generator": true,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 16,
"end": 38,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 20,
"end": 36,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 18
}
},
"expression": {
"type": "CallExpression",
"start": 20,
"end": 35,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 17
}
},
"callee": {
"type": "MetaProperty",
"start": 20,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 15
}
},
"meta": {
"type": "Identifier",
"start": 20,
"end": 28,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 10
},
"identifierName": "function"
},
"name": "function"
},
"property": {
"type": "Identifier",
"start": 29,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 15
},
"identifierName": "sent"
},
"name": "sent"
}
},
"arguments": []
}
}
],
"directives": []
}
}
],
"directives": []
}
}

View File

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

View File

@ -0,0 +1,3 @@
function* foo() {
(function.sent());
}

View File

@ -0,0 +1,172 @@
{
"type": "File",
"start": 0,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 10,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "foo"
},
"name": "foo"
},
"generator": true,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 16,
"end": 40,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 20,
"end": 38,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 20
}
},
"expression": {
"type": "CallExpression",
"start": 21,
"end": 36,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 18
}
},
"callee": {
"type": "MetaProperty",
"start": 21,
"end": 34,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 16
}
},
"meta": {
"type": "Identifier",
"start": 21,
"end": 29,
"loc": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 11
},
"identifierName": "function"
},
"name": "function"
},
"property": {
"type": "Identifier",
"start": 30,
"end": 34,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 16
},
"identifierName": "sent"
},
"name": "sent"
}
},
"arguments": [],
"extra": {
"parenthesized": true,
"parenStart": 20
}
}
}
],
"directives": []
}
}
],
"directives": []
}
}

View File

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

View File

@ -0,0 +1,3 @@
function* foo() {
function.sent() {}
}

View File

@ -0,0 +1,4 @@
{
"plugins": ["functionSent"],
"throws": "Unexpected token, expected ; (2:18)"
}

View File

@ -0,0 +1,3 @@
function* foo() {
(function.sent() {});
}

View File

@ -0,0 +1,4 @@
{
"plugins": ["functionSent"],
"throws": "Unexpected token, expected , (2:19)"
}

View File

@ -0,0 +1,3 @@
function* foo() {
if (true) function.sent;
}

View File

@ -0,0 +1,184 @@
{
"type": "File",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 10,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "foo"
},
"name": "foo"
},
"generator": true,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 16,
"end": 46,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "IfStatement",
"start": 20,
"end": 44,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 26
}
},
"test": {
"type": "BooleanLiteral",
"start": 24,
"end": 28,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 10
}
},
"value": true
},
"consequent": {
"type": "ExpressionStatement",
"start": 30,
"end": 44,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 26
}
},
"expression": {
"type": "MetaProperty",
"start": 30,
"end": 43,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 25
}
},
"meta": {
"type": "Identifier",
"start": 30,
"end": 38,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 20
},
"identifierName": "function"
},
"name": "function"
},
"property": {
"type": "Identifier",
"start": 39,
"end": 43,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 25
},
"identifierName": "sent"
},
"name": "sent"
}
}
},
"alternate": null
}
],
"directives": []
}
}
],
"directives": []
}
}

View File

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

View File

@ -0,0 +1,3 @@
function foo() {
return function.sent;
}

View File

@ -0,0 +1,4 @@
{
"plugins": ["functionSent"],
"throws": "Unexpected token, expected ( (2:17)"
}

View File

@ -0,0 +1,3 @@
function* foo() {
return function.sent;
}

View File

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

View File

@ -0,0 +1,3 @@
function* foo() {
function.sent;
}

View File

@ -0,0 +1,152 @@
{
"type": "File",
"start": 0,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "FunctionDeclaration",
"start": 0,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 10,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 13
},
"identifierName": "foo"
},
"name": "foo"
},
"generator": true,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 16,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 20,
"end": 34,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 16
}
},
"expression": {
"type": "MetaProperty",
"start": 20,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 15
}
},
"meta": {
"type": "Identifier",
"start": 20,
"end": 28,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 10
},
"identifierName": "function"
},
"name": "function"
},
"property": {
"type": "Identifier",
"start": 29,
"end": 33,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 15
},
"identifierName": "sent"
},
"name": "sent"
}
}
}
],
"directives": []
}
}
],
"directives": []
}
}

View File

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