From 62d313e753a17fef76164c7e18493d8c39a92838 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Fri, 7 Jul 2017 23:14:20 -0400 Subject: [PATCH 1/2] Fix function.sent parsing --- src/parser/expression.js | 7 +- src/parser/statement.js | 1 + .../actual.js | 3 + .../options.json | 3 + .../actual.js | 3 + .../options.json | 3 + .../actual.js | 0 .../options.json | 0 .../actual.js | 0 .../disabled-inside-generator/options.json | 3 + .../actual.js | 4 + .../expected.json | 185 ++++++++++++++++++ .../options.json | 0 .../enabled-call-statement/actual.js | 3 + .../enabled-call-statement/expected.json | 168 ++++++++++++++++ .../enabled-call-statement/options.json | 3 + .../function-sent/enabled-call/actual.js | 3 + .../function-sent/enabled-call/expected.json | 172 ++++++++++++++++ .../function-sent/enabled-call/options.json | 3 + .../actual.js | 3 + .../options.json | 4 + .../actual.js | 3 + .../options.json | 4 + .../enabled-inside-function/actual.js | 3 + .../enabled-inside-function/options.json | 4 + .../enabled-inside-generator/actual.js | 3 + .../expected.json | 0 .../enabled-inside-generator/options.json | 3 + .../function-sent/enabled-statement/actual.js | 3 + .../enabled-statement/expected.json | 152 ++++++++++++++ .../enabled-statement/options.json | 3 + 31 files changed, 745 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/experimental/function-sent/disabled-function-keyword-declaration/actual.js create mode 100644 test/fixtures/experimental/function-sent/disabled-function-keyword-declaration/options.json create mode 100644 test/fixtures/experimental/function-sent/disabled-function-keyword-expression/actual.js create mode 100644 test/fixtures/experimental/function-sent/disabled-function-keyword-expression/options.json rename test/fixtures/experimental/function-sent/{inside-function => disabled-inside-function}/actual.js (100%) rename test/fixtures/experimental/function-sent/{inside-function => disabled-inside-function}/options.json (100%) rename test/fixtures/experimental/function-sent/{inside-generator => disabled-inside-generator}/actual.js (100%) create mode 100644 test/fixtures/experimental/function-sent/disabled-inside-generator/options.json create mode 100644 test/fixtures/experimental/function-sent/enabled-asi-funciton-declaration/actual.js create mode 100644 test/fixtures/experimental/function-sent/enabled-asi-funciton-declaration/expected.json rename test/fixtures/experimental/function-sent/{ => enabled-asi-funciton-declaration}/options.json (100%) create mode 100644 test/fixtures/experimental/function-sent/enabled-call-statement/actual.js create mode 100644 test/fixtures/experimental/function-sent/enabled-call-statement/expected.json create mode 100644 test/fixtures/experimental/function-sent/enabled-call-statement/options.json create mode 100644 test/fixtures/experimental/function-sent/enabled-call/actual.js create mode 100644 test/fixtures/experimental/function-sent/enabled-call/expected.json create mode 100644 test/fixtures/experimental/function-sent/enabled-call/options.json create mode 100644 test/fixtures/experimental/function-sent/enabled-function-keyword-declaration/actual.js create mode 100644 test/fixtures/experimental/function-sent/enabled-function-keyword-declaration/options.json create mode 100644 test/fixtures/experimental/function-sent/enabled-function-keyword-expression/actual.js create mode 100644 test/fixtures/experimental/function-sent/enabled-function-keyword-expression/options.json create mode 100644 test/fixtures/experimental/function-sent/enabled-inside-function/actual.js create mode 100644 test/fixtures/experimental/function-sent/enabled-inside-function/options.json create mode 100644 test/fixtures/experimental/function-sent/enabled-inside-generator/actual.js rename test/fixtures/experimental/function-sent/{inside-generator => enabled-inside-generator}/expected.json (100%) create mode 100644 test/fixtures/experimental/function-sent/enabled-inside-generator/options.json create mode 100644 test/fixtures/experimental/function-sent/enabled-statement/actual.js create mode 100644 test/fixtures/experimental/function-sent/enabled-statement/expected.json create mode 100644 test/fixtures/experimental/function-sent/enabled-statement/options.json diff --git a/src/parser/expression.js b/src/parser/expression.js index 1b55fb265d..61d69aa4d5 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -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( diff --git a/src/parser/statement.js b/src/parser/statement.js index d2fd342ca5..0426edda69 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -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); diff --git a/test/fixtures/experimental/function-sent/disabled-function-keyword-declaration/actual.js b/test/fixtures/experimental/function-sent/disabled-function-keyword-declaration/actual.js new file mode 100644 index 0000000000..a268d03ef6 --- /dev/null +++ b/test/fixtures/experimental/function-sent/disabled-function-keyword-declaration/actual.js @@ -0,0 +1,3 @@ +function* foo() { + function.sent() {} +} diff --git a/test/fixtures/experimental/function-sent/disabled-function-keyword-declaration/options.json b/test/fixtures/experimental/function-sent/disabled-function-keyword-declaration/options.json new file mode 100644 index 0000000000..9a9a59331e --- /dev/null +++ b/test/fixtures/experimental/function-sent/disabled-function-keyword-declaration/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ( (2:10)" +} diff --git a/test/fixtures/experimental/function-sent/disabled-function-keyword-expression/actual.js b/test/fixtures/experimental/function-sent/disabled-function-keyword-expression/actual.js new file mode 100644 index 0000000000..3f85ebbee0 --- /dev/null +++ b/test/fixtures/experimental/function-sent/disabled-function-keyword-expression/actual.js @@ -0,0 +1,3 @@ +function* foo() { + (function.sent() {}); +} diff --git a/test/fixtures/experimental/function-sent/disabled-function-keyword-expression/options.json b/test/fixtures/experimental/function-sent/disabled-function-keyword-expression/options.json new file mode 100644 index 0000000000..36c4be02d9 --- /dev/null +++ b/test/fixtures/experimental/function-sent/disabled-function-keyword-expression/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ( (2:11)" +} diff --git a/test/fixtures/experimental/function-sent/inside-function/actual.js b/test/fixtures/experimental/function-sent/disabled-inside-function/actual.js similarity index 100% rename from test/fixtures/experimental/function-sent/inside-function/actual.js rename to test/fixtures/experimental/function-sent/disabled-inside-function/actual.js diff --git a/test/fixtures/experimental/function-sent/inside-function/options.json b/test/fixtures/experimental/function-sent/disabled-inside-function/options.json similarity index 100% rename from test/fixtures/experimental/function-sent/inside-function/options.json rename to test/fixtures/experimental/function-sent/disabled-inside-function/options.json diff --git a/test/fixtures/experimental/function-sent/inside-generator/actual.js b/test/fixtures/experimental/function-sent/disabled-inside-generator/actual.js similarity index 100% rename from test/fixtures/experimental/function-sent/inside-generator/actual.js rename to test/fixtures/experimental/function-sent/disabled-inside-generator/actual.js diff --git a/test/fixtures/experimental/function-sent/disabled-inside-generator/options.json b/test/fixtures/experimental/function-sent/disabled-inside-generator/options.json new file mode 100644 index 0000000000..6127ef0bfb --- /dev/null +++ b/test/fixtures/experimental/function-sent/disabled-inside-generator/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token, expected ( (2:17)" +} diff --git a/test/fixtures/experimental/function-sent/enabled-asi-funciton-declaration/actual.js b/test/fixtures/experimental/function-sent/enabled-asi-funciton-declaration/actual.js new file mode 100644 index 0000000000..850b036cf3 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-asi-funciton-declaration/actual.js @@ -0,0 +1,4 @@ +function* foo() { + function.sent() + {} +} diff --git a/test/fixtures/experimental/function-sent/enabled-asi-funciton-declaration/expected.json b/test/fixtures/experimental/function-sent/enabled-asi-funciton-declaration/expected.json new file mode 100644 index 0000000000..53c4079fde --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-asi-funciton-declaration/expected.json @@ -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": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/function-sent/options.json b/test/fixtures/experimental/function-sent/enabled-asi-funciton-declaration/options.json similarity index 100% rename from test/fixtures/experimental/function-sent/options.json rename to test/fixtures/experimental/function-sent/enabled-asi-funciton-declaration/options.json diff --git a/test/fixtures/experimental/function-sent/enabled-call-statement/actual.js b/test/fixtures/experimental/function-sent/enabled-call-statement/actual.js new file mode 100644 index 0000000000..2bbd798c72 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-call-statement/actual.js @@ -0,0 +1,3 @@ +function* foo() { + function.sent(); +} diff --git a/test/fixtures/experimental/function-sent/enabled-call-statement/expected.json b/test/fixtures/experimental/function-sent/enabled-call-statement/expected.json new file mode 100644 index 0000000000..0edf1696eb --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-call-statement/expected.json @@ -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": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/function-sent/enabled-call-statement/options.json b/test/fixtures/experimental/function-sent/enabled-call-statement/options.json new file mode 100644 index 0000000000..fea46c76c3 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-call-statement/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["functionSent"] +} diff --git a/test/fixtures/experimental/function-sent/enabled-call/actual.js b/test/fixtures/experimental/function-sent/enabled-call/actual.js new file mode 100644 index 0000000000..1903c3caed --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-call/actual.js @@ -0,0 +1,3 @@ +function* foo() { + (function.sent()); +} diff --git a/test/fixtures/experimental/function-sent/enabled-call/expected.json b/test/fixtures/experimental/function-sent/enabled-call/expected.json new file mode 100644 index 0000000000..968f3af3d4 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-call/expected.json @@ -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": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/function-sent/enabled-call/options.json b/test/fixtures/experimental/function-sent/enabled-call/options.json new file mode 100644 index 0000000000..fea46c76c3 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-call/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["functionSent"] +} diff --git a/test/fixtures/experimental/function-sent/enabled-function-keyword-declaration/actual.js b/test/fixtures/experimental/function-sent/enabled-function-keyword-declaration/actual.js new file mode 100644 index 0000000000..a268d03ef6 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-function-keyword-declaration/actual.js @@ -0,0 +1,3 @@ +function* foo() { + function.sent() {} +} diff --git a/test/fixtures/experimental/function-sent/enabled-function-keyword-declaration/options.json b/test/fixtures/experimental/function-sent/enabled-function-keyword-declaration/options.json new file mode 100644 index 0000000000..79cf105e1e --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-function-keyword-declaration/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["functionSent"], + "throws": "Unexpected token, expected ; (2:18)" +} diff --git a/test/fixtures/experimental/function-sent/enabled-function-keyword-expression/actual.js b/test/fixtures/experimental/function-sent/enabled-function-keyword-expression/actual.js new file mode 100644 index 0000000000..3f85ebbee0 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-function-keyword-expression/actual.js @@ -0,0 +1,3 @@ +function* foo() { + (function.sent() {}); +} diff --git a/test/fixtures/experimental/function-sent/enabled-function-keyword-expression/options.json b/test/fixtures/experimental/function-sent/enabled-function-keyword-expression/options.json new file mode 100644 index 0000000000..bb5304a475 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-function-keyword-expression/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["functionSent"], + "throws": "Unexpected token, expected , (2:19)" +} diff --git a/test/fixtures/experimental/function-sent/enabled-inside-function/actual.js b/test/fixtures/experimental/function-sent/enabled-inside-function/actual.js new file mode 100644 index 0000000000..203379b698 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-inside-function/actual.js @@ -0,0 +1,3 @@ +function foo() { + return function.sent; +} diff --git a/test/fixtures/experimental/function-sent/enabled-inside-function/options.json b/test/fixtures/experimental/function-sent/enabled-inside-function/options.json new file mode 100644 index 0000000000..003224f7e0 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-inside-function/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["functionSent"], + "throws": "Unexpected token, expected ( (2:17)" +} diff --git a/test/fixtures/experimental/function-sent/enabled-inside-generator/actual.js b/test/fixtures/experimental/function-sent/enabled-inside-generator/actual.js new file mode 100644 index 0000000000..28760b261b --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-inside-generator/actual.js @@ -0,0 +1,3 @@ +function* foo() { + return function.sent; +} diff --git a/test/fixtures/experimental/function-sent/inside-generator/expected.json b/test/fixtures/experimental/function-sent/enabled-inside-generator/expected.json similarity index 100% rename from test/fixtures/experimental/function-sent/inside-generator/expected.json rename to test/fixtures/experimental/function-sent/enabled-inside-generator/expected.json diff --git a/test/fixtures/experimental/function-sent/enabled-inside-generator/options.json b/test/fixtures/experimental/function-sent/enabled-inside-generator/options.json new file mode 100644 index 0000000000..fea46c76c3 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-inside-generator/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["functionSent"] +} diff --git a/test/fixtures/experimental/function-sent/enabled-statement/actual.js b/test/fixtures/experimental/function-sent/enabled-statement/actual.js new file mode 100644 index 0000000000..343793d055 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-statement/actual.js @@ -0,0 +1,3 @@ +function* foo() { + function.sent; +} diff --git a/test/fixtures/experimental/function-sent/enabled-statement/expected.json b/test/fixtures/experimental/function-sent/enabled-statement/expected.json new file mode 100644 index 0000000000..fd3ef8617b --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-statement/expected.json @@ -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": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/function-sent/enabled-statement/options.json b/test/fixtures/experimental/function-sent/enabled-statement/options.json new file mode 100644 index 0000000000..fea46c76c3 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-statement/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["functionSent"] +} From aa1bad90d12cb29f2f30975d9e64df876f9297fc Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sat, 8 Jul 2017 02:08:46 -0400 Subject: [PATCH 2/2] Test function.sent statement without declarations --- .../enabled-if-statement/actual.js | 3 + .../enabled-if-statement/expected.json | 184 ++++++++++++++++++ .../enabled-if-statement/options.json | 3 + 3 files changed, 190 insertions(+) create mode 100644 test/fixtures/experimental/function-sent/enabled-if-statement/actual.js create mode 100644 test/fixtures/experimental/function-sent/enabled-if-statement/expected.json create mode 100644 test/fixtures/experimental/function-sent/enabled-if-statement/options.json diff --git a/test/fixtures/experimental/function-sent/enabled-if-statement/actual.js b/test/fixtures/experimental/function-sent/enabled-if-statement/actual.js new file mode 100644 index 0000000000..bc34f78278 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-if-statement/actual.js @@ -0,0 +1,3 @@ +function* foo() { + if (true) function.sent; +} diff --git a/test/fixtures/experimental/function-sent/enabled-if-statement/expected.json b/test/fixtures/experimental/function-sent/enabled-if-statement/expected.json new file mode 100644 index 0000000000..7ed356f20a --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-if-statement/expected.json @@ -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": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/function-sent/enabled-if-statement/options.json b/test/fixtures/experimental/function-sent/enabled-if-statement/options.json new file mode 100644 index 0000000000..fea46c76c3 --- /dev/null +++ b/test/fixtures/experimental/function-sent/enabled-if-statement/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["functionSent"] +}