From d83064a82e1bf65eb43f5c34f7ed0e51e527bb25 Mon Sep 17 00:00:00 2001 From: Sangboak Lee Date: Tue, 22 Aug 2017 22:48:56 +0900 Subject: [PATCH] add test for do expressions (#688) --- .../conditional-statement/actual.js | 5 + .../conditional-statement/expected.json | 411 +++++++++++++ .../experimental/do-expressions/options.json | 3 + .../do-expressions/scoping-variable/actual.js | 4 + .../scoping-variable/expected.json | 301 ++++++++++ .../do-expressions/with-jsx/actual.js | 16 + .../do-expressions/with-jsx/expected.json | 544 ++++++++++++++++++ .../do-expressions/with-jsx/options.json | 3 + 8 files changed, 1287 insertions(+) create mode 100644 test/fixtures/experimental/do-expressions/conditional-statement/actual.js create mode 100644 test/fixtures/experimental/do-expressions/conditional-statement/expected.json create mode 100644 test/fixtures/experimental/do-expressions/options.json create mode 100644 test/fixtures/experimental/do-expressions/scoping-variable/actual.js create mode 100644 test/fixtures/experimental/do-expressions/scoping-variable/expected.json create mode 100644 test/fixtures/experimental/do-expressions/with-jsx/actual.js create mode 100644 test/fixtures/experimental/do-expressions/with-jsx/expected.json create mode 100644 test/fixtures/experimental/do-expressions/with-jsx/options.json diff --git a/test/fixtures/experimental/do-expressions/conditional-statement/actual.js b/test/fixtures/experimental/do-expressions/conditional-statement/actual.js new file mode 100644 index 0000000000..43a9af6f6a --- /dev/null +++ b/test/fixtures/experimental/do-expressions/conditional-statement/actual.js @@ -0,0 +1,5 @@ +let x = do { + if (foo()) { f() } + else if (bar()) { g() } + else { h() } +}; \ No newline at end of file diff --git a/test/fixtures/experimental/do-expressions/conditional-statement/expected.json b/test/fixtures/experimental/do-expressions/conditional-statement/expected.json new file mode 100644 index 0000000000..5d30dc7436 --- /dev/null +++ b/test/fixtures/experimental/do-expressions/conditional-statement/expected.json @@ -0,0 +1,411 @@ +{ + "type": "File", + "start": 0, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 76, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "DoExpression", + "start": 8, + "end": 76, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "body": { + "type": "BlockStatement", + "start": 11, + "end": 76, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 5, + "column": 1 + } + }, + "body": [ + { + "type": "IfStatement", + "start": 15, + "end": 74, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "test": { + "type": "CallExpression", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "callee": { + "type": "Identifier", + "start": 19, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [] + }, + "consequent": { + "type": "BlockStatement", + "start": 26, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 28, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "expression": { + "type": "CallExpression", + "start": 28, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "callee": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + }, + "identifierName": "f" + }, + "name": "f" + }, + "arguments": [] + } + } + ], + "directives": [] + }, + "alternate": { + "type": "IfStatement", + "start": 41, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "test": { + "type": "CallExpression", + "start": 45, + "end": 50, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "callee": { + "type": "Identifier", + "start": 45, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 14 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "arguments": [] + }, + "consequent": { + "type": "BlockStatement", + "start": 52, + "end": 59, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 54, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "expression": { + "type": "CallExpression", + "start": 54, + "end": 57, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "callee": { + "type": "Identifier", + "start": 54, + "end": 55, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 21 + }, + "identifierName": "g" + }, + "name": "g" + }, + "arguments": [] + } + } + ], + "directives": [] + }, + "alternate": { + "type": "BlockStatement", + "start": 67, + "end": 74, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 69, + "end": 72, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 12 + } + }, + "expression": { + "type": "CallExpression", + "start": 69, + "end": 72, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 12 + } + }, + "callee": { + "type": "Identifier", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + }, + "identifierName": "h" + }, + "name": "h" + }, + "arguments": [] + } + } + ], + "directives": [] + } + } + } + ], + "directives": [] + } + } + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/do-expressions/options.json b/test/fixtures/experimental/do-expressions/options.json new file mode 100644 index 0000000000..294598f215 --- /dev/null +++ b/test/fixtures/experimental/do-expressions/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["doExpressions"] +} \ No newline at end of file diff --git a/test/fixtures/experimental/do-expressions/scoping-variable/actual.js b/test/fixtures/experimental/do-expressions/scoping-variable/actual.js new file mode 100644 index 0000000000..434a3e7862 --- /dev/null +++ b/test/fixtures/experimental/do-expressions/scoping-variable/actual.js @@ -0,0 +1,4 @@ +let x = do { + let tmp = f(); + tmp * tmp + 1 +}; \ No newline at end of file diff --git a/test/fixtures/experimental/do-expressions/scoping-variable/expected.json b/test/fixtures/experimental/do-expressions/scoping-variable/expected.json new file mode 100644 index 0000000000..eb25bd2762 --- /dev/null +++ b/test/fixtures/experimental/do-expressions/scoping-variable/expected.json @@ -0,0 +1,301 @@ +{ + "type": "File", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "DoExpression", + "start": 8, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": { + "type": "BlockStatement", + "start": 11, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 29, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 19, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 19, + "end": 22, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + }, + "identifierName": "tmp" + }, + "name": "tmp" + }, + "init": { + "type": "CallExpression", + "start": 25, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "callee": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + }, + "identifierName": "f" + }, + "name": "f" + }, + "arguments": [] + } + } + ], + "kind": "let" + }, + { + "type": "ExpressionStatement", + "start": 32, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 32, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "left": { + "type": "BinaryExpression", + "start": 32, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "left": { + "type": "Identifier", + "start": 32, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + }, + "identifierName": "tmp" + }, + "name": "tmp" + }, + "operator": "*", + "right": { + "type": "Identifier", + "start": 38, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "tmp" + }, + "name": "tmp" + } + }, + "operator": "+", + "right": { + "type": "NumericLiteral", + "start": 44, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + ], + "directives": [] + } + } + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/do-expressions/with-jsx/actual.js b/test/fixtures/experimental/do-expressions/with-jsx/actual.js new file mode 100644 index 0000000000..11dfe7888e --- /dev/null +++ b/test/fixtures/experimental/do-expressions/with-jsx/actual.js @@ -0,0 +1,16 @@ +function foo() { + return ( + + ); +} \ No newline at end of file diff --git a/test/fixtures/experimental/do-expressions/with-jsx/expected.json b/test/fixtures/experimental/do-expressions/with-jsx/expected.json new file mode 100644 index 0000000000..0096627dd9 --- /dev/null +++ b/test/fixtures/experimental/do-expressions/with-jsx/expected.json @@ -0,0 +1,544 @@ +{ + "type": "File", + "start": 0, + "end": 223, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 16, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 223, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 16, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 223, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 16, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, + "end": 223, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 16, + "column": 1 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 19, + "end": 221, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 15, + "column": 4 + } + }, + "argument": { + "type": "JSXElement", + "start": 32, + "end": 216, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 32, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "attributes": [], + "name": { + "type": "JSXIdentifier", + "start": 33, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "name": "nav" + }, + "selfClosing": false + }, + "closingElement": { + "type": "JSXClosingElement", + "start": 210, + "end": 216, + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "name": { + "type": "JSXIdentifier", + "start": 212, + "end": 215, + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 9 + } + }, + "name": "nav" + } + }, + "children": [ + { + "type": "JSXText", + "start": 37, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 4, + "column": 6 + } + }, + "extra": { + "rawValue": "\n ", + "raw": "\n " + }, + "value": "\n " + }, + { + "type": "JSXElement", + "start": 44, + "end": 52, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 44, + "end": 52, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 14 + } + }, + "attributes": [], + "name": { + "type": "JSXIdentifier", + "start": 45, + "end": 49, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 11 + } + }, + "name": "Home" + }, + "selfClosing": true + }, + "closingElement": null, + "children": [] + }, + { + "type": "JSXText", + "start": 52, + "end": 59, + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "extra": { + "rawValue": "\n ", + "raw": "\n " + }, + "value": "\n " + }, + { + "type": "JSXExpressionContainer", + "start": 59, + "end": 205, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 13, + "column": 7 + } + }, + "expression": { + "type": "DoExpression", + "start": 69, + "end": 197, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 12, + "column": 9 + } + }, + "body": { + "type": "BlockStatement", + "start": 72, + "end": 197, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 12, + "column": 9 + } + }, + "body": [ + { + "type": "IfStatement", + "start": 84, + "end": 187, + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "test": { + "type": "Identifier", + "start": 88, + "end": 96, + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 22 + }, + "identifierName": "loggedIn" + }, + "name": "loggedIn" + }, + "consequent": { + "type": "BlockStatement", + "start": 98, + "end": 140, + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 112, + "end": 128, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 28 + } + }, + "expression": { + "type": "JSXElement", + "start": 112, + "end": 128, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 28 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 112, + "end": 128, + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 28 + } + }, + "attributes": [], + "name": { + "type": "JSXIdentifier", + "start": 113, + "end": 125, + "loc": { + "start": { + "line": 8, + "column": 13 + }, + "end": { + "line": 8, + "column": 25 + } + }, + "name": "LogoutButton" + }, + "selfClosing": true + }, + "closingElement": null, + "children": [] + } + } + ], + "directives": [] + }, + "alternate": { + "type": "BlockStatement", + "start": 146, + "end": 187, + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 160, + "end": 175, + "loc": { + "start": { + "line": 10, + "column": 12 + }, + "end": { + "line": 10, + "column": 27 + } + }, + "expression": { + "type": "JSXElement", + "start": 160, + "end": 175, + "loc": { + "start": { + "line": 10, + "column": 12 + }, + "end": { + "line": 10, + "column": 27 + } + }, + "openingElement": { + "type": "JSXOpeningElement", + "start": 160, + "end": 175, + "loc": { + "start": { + "line": 10, + "column": 12 + }, + "end": { + "line": 10, + "column": 27 + } + }, + "attributes": [], + "name": { + "type": "JSXIdentifier", + "start": 161, + "end": 172, + "loc": { + "start": { + "line": 10, + "column": 13 + }, + "end": { + "line": 10, + "column": 24 + } + }, + "name": "LoginButton" + }, + "selfClosing": true + }, + "closingElement": null, + "children": [] + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } + } + }, + { + "type": "JSXText", + "start": 205, + "end": 210, + "loc": { + "start": { + "line": 13, + "column": 7 + }, + "end": { + "line": 14, + "column": 4 + } + }, + "extra": { + "rawValue": "\n ", + "raw": "\n " + }, + "value": "\n " + } + ], + "extra": { + "parenthesized": true, + "parenStart": 26 + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/do-expressions/with-jsx/options.json b/test/fixtures/experimental/do-expressions/with-jsx/options.json new file mode 100644 index 0000000000..e74b82b101 --- /dev/null +++ b/test/fixtures/experimental/do-expressions/with-jsx/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["jsx", "doExpressions"] +} \ No newline at end of file