diff --git a/src/index.js b/src/index.js index 5636108c43..996fe5a9d0 100755 --- a/src/index.js +++ b/src/index.js @@ -37,4 +37,8 @@ export function getAvailablePlugins() { return result; } +export function getPluginMetadata() { + return pluginMetadata; +} + export { tokTypes }; diff --git a/src/plugins/lightscript.js b/src/plugins/lightscript.js index df34755a90..9a61cea3b8 100644 --- a/src/plugins/lightscript.js +++ b/src/plugins/lightscript.js @@ -163,6 +163,36 @@ pp.parseObjectWhiteBlock = function(node, blockIndentLevel) { return this.finishNode(node, "BlockStatement"); }; +pp.tryParseObjectWhiteBlock = function(node, blockIndentLevel) { + const state = this.state.clone(); + try { + return [this.parseObjectWhiteBlock(node, blockIndentLevel)]; + } catch (err) { + this.state = state; + return [null, err]; + } +}; + +pp.rethrowObjParseError = function(objParseResult, blockParseError) { + const objParseError = objParseResult ? objParseResult[1] : null; + if (objParseError) { + if (objParseError.message === "WRONG_SPECULATIVE_BRANCH") { + throw blockParseError; + } else { + throw objParseError; + } + } else { + throw blockParseError; + } +}; + +pp.parseNonemptyWhiteBlock = function(node, indentLevel) { + this.parseBlockBody(node, false, false, indentLevel); + if (!node.body.length) { + this.unexpected(node.start, "Expected an Indent or Statement"); + } +}; + pp.parseInlineWhiteBlock = function(node) { if (this.state.type.startsExpr) return this.parseMaybeAssign(); // oneline statement case @@ -179,9 +209,17 @@ pp.parseMultilineWhiteBlock = function(node, indentLevel) { return this.parseObjectWhiteBlock(node, indentLevel); } - this.parseBlockBody(node, false, false, indentLevel); - if (!node.body.length) { - this.unexpected(node.start, "Expected an Indent or Statement"); + if (this.match(tt.braceL) && this.hasPlugin("whiteblockPreferred")) { + const objParseResult = this.tryParseObjectWhiteBlock(node, indentLevel); + if (objParseResult[0]) return objParseResult[0]; + + try { + this.parseNonemptyWhiteBlock(node, indentLevel); + } catch (err) { + this.rethrowObjParseError(objParseResult, err); + } + } else { + this.parseNonemptyWhiteBlock(node, indentLevel); } this.addExtra(node, "curly", false); @@ -198,9 +236,25 @@ pp.parseWhiteBlock = function (isExpression?) { return this.parseInlineWhiteBlock(node); } - if (this.match(tt.braceL) && this.hasPlugin("whiteblockOnly")) { - // Parse as object - return this.parseObjectWhiteBlock(node, indentLevel); + if (this.match(tt.braceL)) { + if (this.hasPlugin("whiteblockOnly")) { + return this.parseObjectWhiteBlock(node, indentLevel); + } + + let objParseResult = null; + if (this.hasPlugin("whiteblockPreferred")) { + objParseResult = this.tryParseObjectWhiteBlock(node, indentLevel); + if (objParseResult[0]) return objParseResult[0]; + + try { + this.state.nestedBlockLevel++; + const stmt = this.parseStatement(false); + this.state.nestedBlockLevel--; + return stmt; + } catch (err) { + this.rethrowObjParseError(objParseResult, err); + } + } } this.state.nestedBlockLevel++; @@ -270,6 +324,35 @@ pp.parseArrowType = function (node) { // largely c/p from parseFunctionBody +pp.parseBraceArrowFunctionBody = function(node, indentLevel) { + // In whiteblock-only mode, `{` must be introducing an object + if (this.hasPlugin("whiteblockOnly")) { + return this.parseObjectWhiteBlock(node, indentLevel); + } + + // In whiteblock-preferred mode, try to parse an object, otherwise fall back on + // a braceblock. + if (this.hasPlugin("whiteblockPreferred")) { + const objParseResult = this.tryParseObjectWhiteBlock(node, indentLevel); + if (objParseResult[0]) return objParseResult[0]; + this.next(); + + try { + this.parseBlockBody(node, true, false, tt.braceR); + } catch (err) { + this.rethrowObjParseError(objParseResult, err); + } + + this.addExtra(node, "curly", true); + return this.finishNode(node, "BlockStatement"); + } + + this.next(); + this.parseBlockBody(node, true, false, tt.braceR); + this.addExtra(node, "curly", true); + return this.finishNode(node, "BlockStatement"); +}; + pp.parseArrowFunctionBody = function (node) { // set and reset state surrounding block const oldInAsync = this.state.inAsync, @@ -286,17 +369,7 @@ pp.parseArrowFunctionBody = function (node) { this.expect(tt.arrow); if (!this.isLineBreak()) { if (this.match(tt.braceL)) { - if (this.hasPlugin("whiteblockOnly")) { - // In whiteblock mode, arrows that start with `{` must be object exprs - node.body = this.parseObjectWhiteBlock(nodeAtArrow, indentLevel); - } else { - // restart node at brace start instead of arrow start - node.body = this.startNode(); - this.next(); - this.parseBlockBody(node.body, true, false, tt.braceR); - this.addExtra(node.body, "curly", true); - node.body = this.finishNode(node.body, "BlockStatement"); - } + node.body = this.parseBraceArrowFunctionBody(this.startNode(), indentLevel); } else { node.body = this.parseInlineWhiteBlock(nodeAtArrow); } diff --git a/src/registerPlugins.js b/src/registerPlugins.js index 49e48c077c..3d9b06dcf7 100644 --- a/src/registerPlugins.js +++ b/src/registerPlugins.js @@ -14,10 +14,18 @@ import { matchCoreSyntax, match } from "./plugins/match"; function noncePlugin() {} export default function registerPlugins(plugins, metadata) { + metadata._reverseDeps = {}; + function registerPlugin(name, plugin, meta) { if (!plugin) plugin = noncePlugin; plugins[name] = plugin; metadata[name] = meta; + if (meta && meta.dependencies) { + meta.dependencies.forEach( (dep) => { + if (!metadata._reverseDeps[dep]) metadata._reverseDeps[dep] = []; + metadata._reverseDeps[dep].push(name); + }); + } } registerPlugin("doExpressions"); @@ -86,4 +94,8 @@ export default function registerPlugins(plugins, metadata) { registerPlugin("whiteblockOnly", noncePlugin, { dependencies: ["lightscript"] }); + + registerPlugin("whiteblockPreferred", noncePlugin, { + dependencies: ["lightscript"] + }); } diff --git a/test/fixtures/comments/options.json b/test/fixtures/comments/options.json index 3b240ce0f5..f3fadc77d4 100644 --- a/test/fixtures/comments/options.json +++ b/test/fixtures/comments/options.json @@ -7,7 +7,7 @@ }, "noLsc": { "allPlugins": true, - "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly"] + "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly", "whiteblockPreferred"] } } } diff --git a/test/fixtures/core/options.json b/test/fixtures/core/options.json index 941a40e7a2..d9661aae66 100644 --- a/test/fixtures/core/options.json +++ b/test/fixtures/core/options.json @@ -8,7 +8,7 @@ }, "noLsc": { "allPlugins": true, - "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly"] + "excludePlugins": ["lightscript"] } } } diff --git a/test/fixtures/core/uncategorised/146/options.json b/test/fixtures/core/uncategorised/146/options.json index e507d5e4d8..fd941b9c3c 100644 --- a/test/fixtures/core/uncategorised/146/options.json +++ b/test/fixtures/core/uncategorised/146/options.json @@ -8,10 +8,7 @@ }, "noTildeCalls": { "allPlugins": true, - "excludePlugins": [ - "lightscript", "match", "splatComprehension", - "whiteblockOnly", "tildeCallExpression" - ], + "excludePlugins": [ "tildeCallExpression" ], "expected": "expected.json" } } diff --git a/test/fixtures/core/uncategorised/19/options.json b/test/fixtures/core/uncategorised/19/options.json index 4a49505418..01df8b776c 100644 --- a/test/fixtures/core/uncategorised/19/options.json +++ b/test/fixtures/core/uncategorised/19/options.json @@ -1,7 +1,10 @@ { "alternatives": { + "all": { + "throws": "Only normal whitespace (ascii-32) is allowed. (1:0)" + }, "noLsc": { - "excludePlugins": ["significantWhitespace", "bangCall", "enforceSubscriptIndentation", "lightscript", "match", "splatComprehension", "whiteblockOnly"] + "excludePlugins": ["significantWhitespace"] } } } diff --git a/test/fixtures/core/uncategorised/19/options.lightscript.json b/test/fixtures/core/uncategorised/19/options.lightscript.json deleted file mode 100644 index b33d18f79b..0000000000 --- a/test/fixtures/core/uncategorised/19/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Only normal whitespace (ascii-32) is allowed. (1:0)" -} \ No newline at end of file diff --git a/test/fixtures/core/uncategorised/321/options.json b/test/fixtures/core/uncategorised/321/options.json index 48635f362f..399414b1e3 100644 --- a/test/fixtures/core/uncategorised/321/options.json +++ b/test/fixtures/core/uncategorised/321/options.json @@ -1,7 +1,10 @@ { "alternatives": { + "all": { + "throws": "Only '\\n' and '\\r\\n' are legal newlines in significant-whitespace mode. (1:0)" + }, "noLsc": { - "excludePlugins": ["significantWhitespace", "bangCall", "enforceSubscriptIndentation", "splatComprehension", "whiteblockOnly"] + "excludePlugins": ["significantWhitespace"] } } } diff --git a/test/fixtures/core/uncategorised/321/options.lightscript.json b/test/fixtures/core/uncategorised/321/options.lightscript.json deleted file mode 100644 index b10071db4d..0000000000 --- a/test/fixtures/core/uncategorised/321/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Only '\\n' and '\\r\\n' are legal newlines in significant-whitespace mode. (1:0)" -} diff --git a/test/fixtures/core/uncategorised/542/options.json b/test/fixtures/core/uncategorised/542/options.json index c410a58884..e970423643 100644 --- a/test/fixtures/core/uncategorised/542/options.json +++ b/test/fixtures/core/uncategorised/542/options.json @@ -1,7 +1,10 @@ { "alternatives": { + "all": { + "throws": "Indentation required. (2:0)" + }, "noLsc": { - "excludePlugins": ["bangCall", "enforceSubscriptIndentation", "significantWhitespace", "splatComprehension", "whiteblockOnly"] + "excludePlugins": ["enforceSubscriptIndentation"] } } } diff --git a/test/fixtures/core/uncategorised/542/options.lightscript.json b/test/fixtures/core/uncategorised/542/options.lightscript.json deleted file mode 100644 index 0d4c46e093..0000000000 --- a/test/fixtures/core/uncategorised/542/options.lightscript.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Indentation required. (2:0)" -} \ No newline at end of file diff --git a/test/fixtures/es2015/arrow-functions/object-rest-spread/expected.lightscript.json b/test/fixtures/es2015/arrow-functions/object-rest-spread/expected.lightscript.json new file mode 100644 index 0000000000..27a3526e16 --- /dev/null +++ b/test/fixtures/es2015/arrow-functions/object-rest-spread/expected.lightscript.json @@ -0,0 +1,262 @@ +{ + "type": "File", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 14, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 14, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "title" + }, + "name": "title" + }, + "value": { + "type": "Identifier", + "start": 14, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "title" + }, + "name": "title" + }, + "extra": { + "shorthand": true + } + }, + { + "type": "RestProperty", + "start": 21, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "argument": { + "type": "Identifier", + "start": 24, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "other" + }, + "name": "other" + } + } + ] + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 37, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 37, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 37, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/options.json b/test/fixtures/es2015/options.json index 941a40e7a2..d9661aae66 100644 --- a/test/fixtures/es2015/options.json +++ b/test/fixtures/es2015/options.json @@ -8,7 +8,7 @@ }, "noLsc": { "allPlugins": true, - "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly"] + "excludePlugins": ["lightscript"] } } } diff --git a/test/fixtures/es2015/uncategorised/158/expected.lightscript.json b/test/fixtures/es2015/uncategorised/158/expected.lightscript.json new file mode 100644 index 0000000000..806e09e094 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/158/expected.lightscript.json @@ -0,0 +1,287 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 1, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 2, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "left": { + "type": "ObjectPattern", + "start": 2, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "Identifier", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + }, + "extra": { + "shorthand": true + } + } + ] + }, + "right": { + "type": "ObjectExpression", + "start": 8, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 9, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "NumericLiteral", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": 10, + "raw": "10" + }, + "value": 10 + } + } + ] + }, + "isNowAssign": false + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 20, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/176/expected.lightscript.json b/test/fixtures/es2015/uncategorised/176/expected.lightscript.json new file mode 100644 index 0000000000..8a29e240d5 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/176/expected.lightscript.json @@ -0,0 +1,155 @@ +{ + "type": "File", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "RestElement", + "start": 1, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "argument": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "a" + }, + "name": "a" + } + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/177/expected.lightscript.json b/test/fixtures/es2015/uncategorised/177/expected.lightscript.json new file mode 100644 index 0000000000..078b8425c9 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/177/expected.lightscript.json @@ -0,0 +1,172 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 1, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "RestElement", + "start": 4, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "argument": { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "b" + }, + "name": "b" + } + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/178/expected.lightscript.json b/test/fixtures/es2015/uncategorised/178/expected.lightscript.json new file mode 100644 index 0000000000..ec293fe994 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/178/expected.lightscript.json @@ -0,0 +1,195 @@ +{ + "type": "File", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 1, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + } + ] + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 11, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 11, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 11, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/179/expected.lightscript.json b/test/fixtures/es2015/uncategorised/179/expected.lightscript.json new file mode 100644 index 0000000000..e75ce0a34d --- /dev/null +++ b/test/fixtures/es2015/uncategorised/179/expected.lightscript.json @@ -0,0 +1,227 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 1, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + } + ] + }, + { + "type": "RestElement", + "start": 8, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "argument": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "b" + }, + "name": "b" + } + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/182/expected.lightscript.json b/test/fixtures/es2015/uncategorised/182/expected.lightscript.json new file mode 100644 index 0000000000..caa0aa2d53 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/182/expected.lightscript.json @@ -0,0 +1,258 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 1, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 3, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "ArrayPattern", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 7, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "a" + }, + "name": "a" + }, + { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "b" + }, + "name": "b" + } + ] + } + } + ] + }, + { + "type": "RestElement", + "start": 16, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "argument": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "c" + }, + "name": "c" + } + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 25, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 25, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 25, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/183/expected.lightscript.json b/test/fixtures/es2015/uncategorised/183/expected.lightscript.json new file mode 100644 index 0000000000..945068c4a3 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/183/expected.lightscript.json @@ -0,0 +1,330 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 1, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 3, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "b" + }, + "name": "b" + } + }, + { + "type": "ObjectProperty", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "c" + }, + "name": "c" + }, + "value": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "c" + }, + "name": "c" + }, + "extra": { + "shorthand": true + } + } + ] + }, + { + "type": "ArrayPattern", + "start": 14, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "elements": [ + { + "type": "Identifier", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "d" + }, + "name": "d" + }, + { + "type": "Identifier", + "start": 18, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "e" + }, + "name": "e" + } + ] + }, + { + "type": "RestElement", + "start": 22, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "argument": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "f" + }, + "name": "f" + } + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/34/expected.lightscript.json b/test/fixtures/es2015/uncategorised/34/expected.lightscript.json new file mode 100644 index 0000000000..a15ce0d905 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/34/expected.lightscript.json @@ -0,0 +1,196 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "e" + }, + "name": "e" + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 5, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 5, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 5, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 7, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 7, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "label" + }, + "name": "label" + }, + "value": { + "type": "NumericLiteral", + "start": 14, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/49/expected.lightscript.json b/test/fixtures/es2015/uncategorised/49/expected.lightscript.json new file mode 100644 index 0000000000..7443388a6e --- /dev/null +++ b/test/fixtures/es2015/uncategorised/49/expected.lightscript.json @@ -0,0 +1,156 @@ +{ + "type": "File", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "callee": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 4, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2015/uncategorised/50/expected.lightscript.json b/test/fixtures/es2015/uncategorised/50/expected.lightscript.json new file mode 100644 index 0000000000..8bfdc94104 --- /dev/null +++ b/test/fixtures/es2015/uncategorised/50/expected.lightscript.json @@ -0,0 +1,191 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "callee": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 4, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + { + "type": "Identifier", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 14, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 14, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 14, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2017/async-functions/1/expected.lightscript.json b/test/fixtures/es2017/async-functions/1/expected.lightscript.json new file mode 100644 index 0000000000..032031a91d --- /dev/null +++ b/test/fixtures/es2017/async-functions/1/expected.lightscript.json @@ -0,0 +1,122 @@ +{ + "type": "File", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": true, + "params": [], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2017/async-functions/27/expected.lightscript.json b/test/fixtures/es2017/async-functions/27/expected.lightscript.json new file mode 100644 index 0000000000..95ecaec42c --- /dev/null +++ b/test/fixtures/es2017/async-functions/27/expected.lightscript.json @@ -0,0 +1,261 @@ +{ + "type": "File", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 12, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 13, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 15, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "method": false, + "shorthand": true, + "key": { + "type": "Identifier", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "async" + }, + "name": "async" + }, + "computed": false, + "value": { + "type": "AssignmentPattern", + "start": 15, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "left": { + "type": "Identifier", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "async" + }, + "name": "async" + }, + "right": { + "type": "BooleanLiteral", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "value": true + } + }, + "extra": { + "shorthand": true + } + } + ] + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2017/async-functions/28/expected.lightscript.json b/test/fixtures/es2017/async-functions/28/expected.lightscript.json new file mode 100644 index 0000000000..746337ba02 --- /dev/null +++ b/test/fixtures/es2017/async-functions/28/expected.lightscript.json @@ -0,0 +1,227 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "sourceType": "script", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 12, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "ObjectPattern", + "start": 13, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 15, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "method": false, + "shorthand": false, + "key": { + "type": "Identifier", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "async" + }, + "name": "async" + }, + "computed": false, + "value": { + "type": "Identifier", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "bar" + }, + "name": "bar" + } + } + ] + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 32, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 32, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 32, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/es2017/options.json b/test/fixtures/es2017/options.json index 941a40e7a2..d9661aae66 100644 --- a/test/fixtures/es2017/options.json +++ b/test/fixtures/es2017/options.json @@ -8,7 +8,7 @@ }, "noLsc": { "allPlugins": true, - "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly"] + "excludePlugins": ["lightscript"] } } } diff --git a/test/fixtures/esprima/es2015-arrow-function/migrated_0006/expected.lightscript.json b/test/fixtures/esprima/es2015-arrow-function/migrated_0006/expected.lightscript.json new file mode 100644 index 0000000000..a15ce0d905 --- /dev/null +++ b/test/fixtures/esprima/es2015-arrow-function/migrated_0006/expected.lightscript.json @@ -0,0 +1,196 @@ +{ + "type": "File", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "e" + }, + "name": "e" + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 5, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 5, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 5, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 7, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 7, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "label" + }, + "name": "label" + }, + "value": { + "type": "NumericLiteral", + "start": 14, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "extra": { + "rawValue": 42, + "raw": "42" + }, + "value": 42 + } + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/esprima/es2015-arrow-function/migrated_0018/expected.lightscript.json b/test/fixtures/esprima/es2015-arrow-function/migrated_0018/expected.lightscript.json new file mode 100644 index 0000000000..7443388a6e --- /dev/null +++ b/test/fixtures/esprima/es2015-arrow-function/migrated_0018/expected.lightscript.json @@ -0,0 +1,156 @@ +{ + "type": "File", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "callee": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 4, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/esprima/es2015-arrow-function/migrated_0019/expected.lightscript.json b/test/fixtures/esprima/es2015-arrow-function/migrated_0019/expected.lightscript.json new file mode 100644 index 0000000000..8bfdc94104 --- /dev/null +++ b/test/fixtures/esprima/es2015-arrow-function/migrated_0019/expected.lightscript.json @@ -0,0 +1,191 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "expression": { + "type": "CallExpression", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "callee": { + "type": "Identifier", + "start": 0, + "end": 3, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 3 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 4, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 5, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + }, + "identifierName": "x" + }, + "name": "x" + }, + { + "type": "Identifier", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "y" + }, + "name": "y" + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 14, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 14, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 14, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/esprima/es2015-yield/yield-arrow-parameter-default/expected.lightscript.json b/test/fixtures/esprima/es2015-yield/yield-arrow-parameter-default/expected.lightscript.json new file mode 100644 index 0000000000..fb4d93dad0 --- /dev/null +++ b/test/fixtures/esprima/es2015-yield/yield-arrow-parameter-default/expected.lightscript.json @@ -0,0 +1,173 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 1, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "left": { + "type": "Identifier", + "start": 1, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 2 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "Identifier", + "start": 5, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "isNowAssign": false + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/esprima/es2015-yield/yield-expression-precedence/options.json b/test/fixtures/esprima/es2015-yield/yield-expression-precedence/options.json index 4a65bfda76..7c1c8fbcf9 100644 --- a/test/fixtures/esprima/es2015-yield/yield-expression-precedence/options.json +++ b/test/fixtures/esprima/es2015-yield/yield-expression-precedence/options.json @@ -8,7 +8,7 @@ }, "noSeqExprParens": { "allPlugins": true, - "excludePlugins": ["seqExprRequiresParen", "splatComprehension", "bangCall", "whiteblockOnly"] + "excludePlugins": ["seqExprRequiresParen", "splatComprehension", "bangCall", "whiteblockOnly", "whiteblockPreferred"] } } } diff --git a/test/fixtures/esprima/es2015-yield/yield-generator-arrow-default/expected.lightscript.json b/test/fixtures/esprima/es2015-yield/yield-generator-arrow-default/expected.lightscript.json new file mode 100644 index 0000000000..49e92c701e --- /dev/null +++ b/test/fixtures/esprima/es2015-yield/yield-generator-arrow-default/expected.lightscript.json @@ -0,0 +1,230 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "sourceType": "script", + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "g" + }, + "name": "g" + }, + "generator": true, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 14, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 16, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 16, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 17, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "left": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "x" + }, + "name": "x" + }, + "right": { + "type": "YieldExpression", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "delegate": false, + "argument": null + }, + "isNowAssign": false + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [], + "extra": { + "curly": true + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/esprima/expression-unary/migrated_0008/options.json b/test/fixtures/esprima/expression-unary/migrated_0008/options.json index e507d5e4d8..6834f00281 100644 --- a/test/fixtures/esprima/expression-unary/migrated_0008/options.json +++ b/test/fixtures/esprima/expression-unary/migrated_0008/options.json @@ -10,7 +10,7 @@ "allPlugins": true, "excludePlugins": [ "lightscript", "match", "splatComprehension", - "whiteblockOnly", "tildeCallExpression" + "whiteblockOnly", "tildeCallExpression", "whiteblockPreferred" ], "expected": "expected.json" } diff --git a/test/fixtures/esprima/options.json b/test/fixtures/esprima/options.json index 941a40e7a2..d9661aae66 100644 --- a/test/fixtures/esprima/options.json +++ b/test/fixtures/esprima/options.json @@ -8,7 +8,7 @@ }, "noLsc": { "allPlugins": true, - "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly"] + "excludePlugins": ["lightscript"] } } } diff --git a/test/fixtures/estree/options.json b/test/fixtures/estree/options.json index 0f0858841d..3bb9493a1a 100644 --- a/test/fixtures/estree/options.json +++ b/test/fixtures/estree/options.json @@ -3,7 +3,7 @@ "all": { "allPlugins": true, "includePlugins": ["estree"], - "excludePlugins": ["whiteblockOnly"], + "excludePlugins": ["whiteblockOnly", "whiteblockPreferred"], "optionsOverride": "options.lightscript.json", "expected": "expected.lightscript.json" } diff --git a/test/fixtures/existential-expression/subscripts/subscript-illegal/options.json b/test/fixtures/existential-expression/subscripts/subscript-illegal/options.json index 274d9eff9d..06758f7c46 100644 --- a/test/fixtures/existential-expression/subscripts/subscript-illegal/options.json +++ b/test/fixtures/existential-expression/subscripts/subscript-illegal/options.json @@ -1,4 +1,4 @@ { - "excludePlugins": ["lightscript", "bangCall", "enforceSubscriptIndentation", "match", "splatComprehension", "whiteblockOnly"], + "excludePlugins": ["lightscript", "bangCall", "enforceSubscriptIndentation", "match", "splatComprehension", "whiteblockOnly", "whiteblockPreferred"], "throws": "Unexpected token, expected ; (1:2)" } diff --git a/test/fixtures/experimental/async-generators/for-await-async-context/options.json b/test/fixtures/experimental/async-generators/for-await-async-context/options.json index 3227688dcd..6046a013c7 100644 --- a/test/fixtures/experimental/async-generators/for-await-async-context/options.json +++ b/test/fixtures/experimental/async-generators/for-await-async-context/options.json @@ -6,7 +6,7 @@ }, "noLsc": { "allPlugins": true, - "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly"] + "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly", "whiteblockPreferred"] } } } diff --git a/test/fixtures/experimental/class-properties/asi-failure-computed/options.json b/test/fixtures/experimental/class-properties/asi-failure-computed/options.json index 15ebb7db7c..7e9de9486d 100644 --- a/test/fixtures/experimental/class-properties/asi-failure-computed/options.json +++ b/test/fixtures/experimental/class-properties/asi-failure-computed/options.json @@ -6,7 +6,7 @@ }, "noLsc": { "allPlugins": true, - "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly"] + "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly", "whiteblockPreferred"] } }, "plugins": ["classProperties"] diff --git a/test/fixtures/experimental/object-rest-spread/5/options.json b/test/fixtures/experimental/object-rest-spread/5/options.json index 38f17b6d33..93b848264d 100644 --- a/test/fixtures/experimental/object-rest-spread/5/options.json +++ b/test/fixtures/experimental/object-rest-spread/5/options.json @@ -5,7 +5,7 @@ }, "noLsc": { "allPlugins": true, - "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly"] + "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly", "whiteblockPreferred"] } } } diff --git a/test/fixtures/experimental/options.json b/test/fixtures/experimental/options.json index 45796bb70b..ae98be3754 100644 --- a/test/fixtures/experimental/options.json +++ b/test/fixtures/experimental/options.json @@ -2,7 +2,7 @@ "alternatives": { "all": { "allPlugins": true, - "excludePlugins": ["whiteblockOnly"] + "excludePlugins": ["whiteblockOnly", "whiteblockPreferred"] } } } diff --git a/test/fixtures/flow/comment/spread/expected.lightscript.json b/test/fixtures/flow/comment/spread/expected.lightscript.json new file mode 100644 index 0000000000..95be9c856b --- /dev/null +++ b/test/fixtures/flow/comment/spread/expected.lightscript.json @@ -0,0 +1,314 @@ +{ + "type": "File", + "start": 0, + "end": 84, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 84, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "module", + "body": [ + { + "type": "FunctionDeclaration", + "start": 9, + "end": 84, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 18, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 37 + }, + "identifierName": "commentsAttachedToIdentifier" + }, + "name": "commentsAttachedToIdentifier", + "leadingComments": null + }, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 49, + "end": 84, + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 53, + "end": 82, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 57, + "end": 81, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 30 + } + }, + "id": { + "type": "Identifier", + "start": 57, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 61, + "end": 81, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 30 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "RestElement", + "start": 62, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "argument": { + "type": "Identifier", + "start": 65, + "end": 69, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 18 + }, + "identifierName": "args" + }, + "name": "args" + }, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 69, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "typeAnnotation": { + "type": "AnyTypeAnnotation", + "start": 71, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 23 + } + } + } + } + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 79, + "end": 81, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 30 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 79, + "end": 81, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 30 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 79, + "end": 81, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 30 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "var" + } + ], + "directives": [], + "extra": { + "curly": true + } + }, + "leadingComments": [ + { + "type": "CommentBlock", + "value": " hi ", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentBlock", + "value": " hi ", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file diff --git a/test/fixtures/flow/optional-type/1/expected.lightscript.json b/test/fixtures/flow/optional-type/1/expected.lightscript.json new file mode 100644 index 0000000000..3a512fec55 --- /dev/null +++ b/test/fixtures/flow/optional-type/1/expected.lightscript.json @@ -0,0 +1,176 @@ +{ + "type": "File", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "f" + }, + "name": "f" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x", + "optional": true + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/optional-type/3/expected.lightscript.json b/test/fixtures/flow/optional-type/3/expected.lightscript.json new file mode 100644 index 0000000000..8a6c16ffa9 --- /dev/null +++ b/test/fixtures/flow/optional-type/3/expected.lightscript.json @@ -0,0 +1,274 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "f" + }, + "name": "f" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x", + "optional": true + }, + { + "type": "AssignmentPattern", + "start": 15, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "left": { + "type": "Identifier", + "start": 15, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 24 + }, + "identifierName": "y" + }, + "name": "y", + "optional": true, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 17, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 18, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 18, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 24 + }, + "identifierName": "Object" + }, + "name": "Object" + } + } + } + }, + "right": { + "type": "ObjectExpression", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "properties": [] + }, + "isNowAssign": false + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/optional-type/4/expected.lightscript.json b/test/fixtures/flow/optional-type/4/expected.lightscript.json new file mode 100644 index 0000000000..789b77e88d --- /dev/null +++ b/test/fixtures/flow/optional-type/4/expected.lightscript.json @@ -0,0 +1,191 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "f" + }, + "name": "f" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "RestElement", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "argument": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + }, + "optional": true + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/options.json b/test/fixtures/flow/options.json index ed98b230f5..7583b320ab 100644 --- a/test/fixtures/flow/options.json +++ b/test/fixtures/flow/options.json @@ -10,7 +10,7 @@ }, "noLsc": { "allPlugins": true, - "excludePlugins": ["lightscript", "match", "splatComprehension", "whiteblockOnly"] + "excludePlugins": ["lightscript"] } } } diff --git a/test/fixtures/flow/regression/issue-336/expected.lightscript.json b/test/fixtures/flow/regression/issue-336/expected.lightscript.json new file mode 100644 index 0000000000..bf8543e9ee --- /dev/null +++ b/test/fixtures/flow/regression/issue-336/expected.lightscript.json @@ -0,0 +1,285 @@ +{ + "type": "File", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 48 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "fn" + }, + "name": "fn" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 11, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "returnType": { + "type": "TypeAnnotation", + "start": 26, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 28, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 35, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "params": [ + { + "type": "VoidTypeAnnotation", + "start": 36, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 40 + } + } + } + ] + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 35 + }, + "identifierName": "Promise" + }, + "name": "Promise" + } + } + }, + "id": null, + "generator": false, + "expression": false, + "async": true, + "params": [ + { + "type": "Identifier", + "start": 18, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "a" + }, + "name": "a", + "optional": true, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 20, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "typeAnnotation": { + "type": "AnyTypeAnnotation", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + } + } + } + } + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 45, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 45, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 45, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/regression/issue-92/expected.lightscript.json b/test/fixtures/flow/regression/issue-92/expected.lightscript.json new file mode 100644 index 0000000000..76a92ee751 --- /dev/null +++ b/test/fixtures/flow/regression/issue-92/expected.lightscript.json @@ -0,0 +1,241 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "a" + }, + "name": "a" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": true, + "params": [ + { + "type": "AssignmentPattern", + "start": 17, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "left": { + "type": "Identifier", + "start": 17, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "foo" + }, + "name": "foo", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 20, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 22, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 28 + } + } + } + } + }, + "right": { + "type": "StringLiteral", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "extra": { + "rawValue": "", + "raw": "\"\"" + }, + "value": "" + }, + "isNowAssign": false + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-annotations/102/expected.lightscript.json b/test/fixtures/flow/type-annotations/102/expected.lightscript.json new file mode 100644 index 0000000000..33203c1f52 --- /dev/null +++ b/test/fixtures/flow/type-annotations/102/expected.lightscript.json @@ -0,0 +1,235 @@ +{ + "type": "File", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 51 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 51 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportDefaultDeclaration", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 51 + } + }, + "declaration": { + "type": "ArrowFunctionExpression", + "start": 15, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "returnType": { + "type": "TypeAnnotation", + "start": 29, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 31, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 36, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "params": [ + { + "type": "StringTypeAnnotation", + "start": 37, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 43 + } + } + } + ] + }, + "id": { + "type": "Identifier", + "start": 31, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 36 + }, + "identifierName": "Array" + }, + "name": "Array" + } + }, + "predicate": null + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "RestElement", + "start": 16, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "argument": { + "type": "Identifier", + "start": 19, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "modifiers" + }, + "name": "modifiers" + } + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 48, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 48 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 48, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 48 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 48, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 48 + }, + "end": { + "line": 1, + "column": 50 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-annotations/103/expected.lightscript.json b/test/fixtures/flow/type-annotations/103/expected.lightscript.json new file mode 100644 index 0000000000..8935b0d164 --- /dev/null +++ b/test/fixtures/flow/type-annotations/103/expected.lightscript.json @@ -0,0 +1,365 @@ +{ + "type": "File", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "parser" + }, + "name": "parser" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 15, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "returnType": { + "type": "TypeAnnotation", + "start": 65, + "end": 67, + "loc": { + "start": { + "line": 1, + "column": 65 + }, + "end": { + "line": 1, + "column": 67 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 66, + "end": 67, + "loc": { + "start": { + "line": 1, + "column": 66 + }, + "end": { + "line": 1, + "column": 67 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 66, + "end": 67, + "loc": { + "start": { + "line": 1, + "column": 66 + }, + "end": { + "line": 1, + "column": 67 + }, + "identifierName": "a" + }, + "name": "a" + } + }, + "predicate": null + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 16, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 32 + }, + "identifierName": "rootPath" + }, + "name": "rootPath", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 24, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 26, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 32 + } + } + } + } + }, + { + "type": "RestElement", + "start": 34, + "end": 64, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 64 + } + }, + "argument": { + "type": "Identifier", + "start": 37, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 49 + }, + "identifierName": "filesToParse" + }, + "name": "filesToParse" + }, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 49, + "end": 64, + "loc": { + "start": { + "line": 1, + "column": 49 + }, + "end": { + "line": 1, + "column": 64 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 51, + "end": 64, + "loc": { + "start": { + "line": 1, + "column": 51 + }, + "end": { + "line": 1, + "column": 64 + } + }, + "typeParameters": { + "type": "TypeParameterInstantiation", + "start": 56, + "end": 64, + "loc": { + "start": { + "line": 1, + "column": 56 + }, + "end": { + "line": 1, + "column": 64 + } + }, + "params": [ + { + "type": "StringTypeAnnotation", + "start": 57, + "end": 63, + "loc": { + "start": { + "line": 1, + "column": 57 + }, + "end": { + "line": 1, + "column": 63 + } + } + } + ] + }, + "id": { + "type": "Identifier", + "start": 51, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 51 + }, + "end": { + "line": 1, + "column": 56 + }, + "identifierName": "Array" + }, + "name": "Array" + } + } + } + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 71, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 71 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 71, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 71 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 71, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 71 + }, + "end": { + "line": 1, + "column": 73 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-annotations/107/expected.lightscript.json b/test/fixtures/flow/type-annotations/107/expected.lightscript.json new file mode 100644 index 0000000000..032dac6b2f --- /dev/null +++ b/test/fixtures/flow/type-annotations/107/expected.lightscript.json @@ -0,0 +1,296 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 8, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 9, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "left": { + "type": "ObjectPattern", + "start": 9, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "extra": { + "shorthand": true + } + } + ], + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "typeAnnotation": { + "type": "AnyTypeAnnotation", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + } + } + } + } + }, + "right": { + "type": "StringLiteral", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "extra": { + "rawValue": "foo", + "raw": "'foo'" + }, + "value": "foo" + }, + "isNowAssign": false + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-annotations/69/expected.lightscript.json b/test/fixtures/flow/type-annotations/69/expected.lightscript.json new file mode 100644 index 0000000000..762f8d1280 --- /dev/null +++ b/test/fixtures/flow/type-annotations/69/expected.lightscript.json @@ -0,0 +1,288 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": true, + "params": [ + { + "type": "Identifier", + "start": 17, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "foo" + }, + "name": "foo", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 20, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "bar" + }, + "name": "bar" + } + } + } + }, + { + "type": "Identifier", + "start": 27, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 35 + }, + "identifierName": "bar" + }, + "name": "bar", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 30, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start": 32, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 35 + } + }, + "typeParameters": null, + "id": { + "type": "Identifier", + "start": 32, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 35 + }, + "identifierName": "foo" + }, + "name": "foo" + } + } + } + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-annotations/79/expected.lightscript.json b/test/fixtures/flow/type-annotations/79/expected.lightscript.json new file mode 100644 index 0000000000..aa9f80a29b --- /dev/null +++ b/test/fixtures/flow/type-annotations/79/expected.lightscript.json @@ -0,0 +1,255 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "init": { + "type": "ConditionalExpression", + "start": 10, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "test": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "bar" + }, + "name": "bar" + }, + "consequent": { + "type": "ArrowFunctionExpression", + "start": 16, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "returnType": { + "type": "TypeAnnotation", + "start": 22, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 30 + } + } + }, + "predicate": null + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 17, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "foo" + }, + "name": "foo" + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + }, + "alternate": { + "type": "Identifier", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 42 + }, + "identifierName": "baz" + }, + "name": "baz" + } + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-annotations/arrow-func-return-newline/expected.lightscript.json b/test/fixtures/flow/type-annotations/arrow-func-return-newline/expected.lightscript.json new file mode 100644 index 0000000000..43034b2881 --- /dev/null +++ b/test/fixtures/flow/type-annotations/arrow-func-return-newline/expected.lightscript.json @@ -0,0 +1,236 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 6, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 10, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "returnType": { + "type": "TypeAnnotation", + "start": 24, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 26, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + "predicate": null + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 11, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 22 + }, + "identifierName": "foo" + }, + "name": "foo", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 14, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 16, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 22 + } + } + } + } + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "const" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-annotations/existential-type-param-2/expected.lightscript.json b/test/fixtures/flow/type-annotations/existential-type-param-2/expected.lightscript.json new file mode 100644 index 0000000000..9c79cd9030 --- /dev/null +++ b/test/fixtures/flow/type-annotations/existential-type-param-2/expected.lightscript.json @@ -0,0 +1,299 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "f" + }, + "name": "f", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "typeAnnotation": { + "type": "ExistentialTypeParam", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + } + } + } + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 12, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "returnType": { + "type": "TypeAnnotation", + "start": 27, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "typeAnnotation": { + "type": "ExistentialTypeParam", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 1, + "column": 31 + } + } + }, + "predicate": null + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 13, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "x" + }, + "name": "x", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 15, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "typeAnnotation": { + "type": "UnionTypeAnnotation", + "start": 17, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "types": [ + { + "type": "NullLiteralTypeAnnotation", + "start": 17, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "value": true + }, + { + "type": "ExistentialTypeParam", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + } + } + ] + } + } + } + ], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 38 + } + }, + "properties": [] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + } + } + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/arrow-expressions/skinny-curly/expected.json b/test/fixtures/lightscript/arrow-expressions/skinny-curly/expected.json index 0505dbb550..7adf40f53d 100644 --- a/test/fixtures/lightscript/arrow-expressions/skinny-curly/expected.json +++ b/test/fixtures/lightscript/arrow-expressions/skinny-curly/expected.json @@ -79,40 +79,95 @@ "body": [ { "type": "ExpressionStatement", - "start": 10, - "end": 11, + "start": 6, + "end": 13, "loc": { "start": { - "line": 2, - "column": 2 + "line": 1, + "column": 6 }, "end": { - "line": 2, - "column": 3 + "line": 3, + "column": 1 } }, "expression": { - "type": "Identifier", - "start": 10, - "end": 11, + "type": "ObjectExpression", + "start": 6, + "end": 13, "loc": { "start": { - "line": 2, - "column": 2 + "line": 1, + "column": 6 }, "end": { - "line": 2, - "column": 3 - }, - "identifierName": "x" + "line": 3, + "column": 1 + } }, - "name": "x" + "properties": [ + { + "type": "ObjectProperty", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "x" + }, + "name": "x" + }, + "extra": { + "shorthand": true + } + } + ] } } ], "directives": [], "extra": { - "curly": true + "curly": false } } } diff --git a/test/fixtures/lightscript/arrow-expressions/skinny-curly/options.json b/test/fixtures/lightscript/arrow-expressions/skinny-curly/options.json index c36a99f661..b223b375f8 100644 --- a/test/fixtures/lightscript/arrow-expressions/skinny-curly/options.json +++ b/test/fixtures/lightscript/arrow-expressions/skinny-curly/options.json @@ -1,7 +1,7 @@ { "alternatives": { "objectBlockAmbiguity": { - "excludePlugins": ["whiteblockOnly"], + "excludePlugins": ["whiteblockOnly", "whiteblockPreferred"], "expected": "expected.objectBlockAmbiguity.json" } } diff --git a/test/fixtures/lightscript/auto-const/not-newline-object-malformed-unfortunate/options.json b/test/fixtures/lightscript/auto-const/not-newline-object-malformed-unfortunate/options.json index 886143b65d..ec40224464 100644 --- a/test/fixtures/lightscript/auto-const/not-newline-object-malformed-unfortunate/options.json +++ b/test/fixtures/lightscript/auto-const/not-newline-object-malformed-unfortunate/options.json @@ -5,11 +5,12 @@ }, "noSeqExprParens": { "allPlugins": true, - "excludePlugins": ["existentialExpression", "safeCallExpression", "splatComprehension", "seqExprRequiresParen", "bangCall", "whiteblockOnly"], + "excludePlugins": ["existentialExpression", "safeCallExpression", "splatComprehension", "seqExprRequiresParen", "bangCall", "whiteblockOnly", "whiteblockPreferred"], "throws": "Unexpected token (1:10)" }, "whiteblock": { "allPlugins": true, + "excludePlugins": ["whiteblockPreferred"], "expected": "expected.whiteblock.json" } } diff --git a/test/fixtures/lightscript/commaless/arrow-expr-params/expected.json b/test/fixtures/lightscript/commaless/arrow-expr-params/expected.json index ca10c8f91f..0ec97cc280 100644 --- a/test/fixtures/lightscript/commaless/arrow-expr-params/expected.json +++ b/test/fixtures/lightscript/commaless/arrow-expr-params/expected.json @@ -111,10 +111,42 @@ "column": 7 } }, - "body": [], + "body": [ + { + "type": "ExpressionStatement", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 15, + "end": 17, + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "properties": [] + } + } + ], "directives": [], "extra": { - "curly": true + "curly": false } } } diff --git a/test/fixtures/lightscript/commaless/arrow-expr-params/options.json b/test/fixtures/lightscript/commaless/arrow-expr-params/options.json index 8e44176f95..b223b375f8 100644 --- a/test/fixtures/lightscript/commaless/arrow-expr-params/options.json +++ b/test/fixtures/lightscript/commaless/arrow-expr-params/options.json @@ -1,7 +1,7 @@ { "alternatives": { "objectBlockAmbiguity": { - "excludePlugins": ["objectBlockAmbiguity_preferObject"], + "excludePlugins": ["whiteblockOnly", "whiteblockPreferred"], "expected": "expected.objectBlockAmbiguity.json" } } diff --git a/test/fixtures/lightscript/for-in/now/expected.whiteblock.json b/test/fixtures/lightscript/for-in/now/expected.braceblock.json similarity index 66% rename from test/fixtures/lightscript/for-in/now/expected.whiteblock.json rename to test/fixtures/lightscript/for-in/now/expected.braceblock.json index aadc64121b..60e6db5e1e 100644 --- a/test/fixtures/lightscript/for-in/now/expected.whiteblock.json +++ b/test/fixtures/lightscript/for-in/now/expected.braceblock.json @@ -79,54 +79,22 @@ }, "body": { "type": "BlockStatement", - "start": 16, + "start": 18, "end": 20, "loc": { "start": { "line": 1, - "column": 16 + "column": 18 }, "end": { "line": 1, "column": 20 } }, - "body": [ - { - "type": "ExpressionStatement", - "start": 18, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "expression": { - "type": "ObjectExpression", - "start": 18, - "end": 20, - "loc": { - "start": { - "line": 1, - "column": 18 - }, - "end": { - "line": 1, - "column": 20 - } - }, - "properties": [] - } - } - ], + "body": [], "directives": [], "extra": { - "curly": false + "curly": true } } } diff --git a/test/fixtures/lightscript/for-in/now/expected.json b/test/fixtures/lightscript/for-in/now/expected.json index 60e6db5e1e..aadc64121b 100644 --- a/test/fixtures/lightscript/for-in/now/expected.json +++ b/test/fixtures/lightscript/for-in/now/expected.json @@ -79,22 +79,54 @@ }, "body": { "type": "BlockStatement", - "start": 18, + "start": 16, "end": 20, "loc": { "start": { "line": 1, - "column": 18 + "column": 16 }, "end": { "line": 1, "column": 20 } }, - "body": [], + "body": [ + { + "type": "ExpressionStatement", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "properties": [] + } + } + ], "directives": [], "extra": { - "curly": true + "curly": false } } } diff --git a/test/fixtures/lightscript/for-in/now/options.json b/test/fixtures/lightscript/for-in/now/options.json index 789ef9baa7..b653bf986f 100644 --- a/test/fixtures/lightscript/for-in/now/options.json +++ b/test/fixtures/lightscript/for-in/now/options.json @@ -1,8 +1,9 @@ { "alternatives": { - "whiteblock": { + "braceblock": { "allPlugins": true, - "expected": "expected.whiteblock.json" + "excludePlugins": ["whiteblockOnly", "whiteblockPreferred"], + "expected": "expected.braceblock.json" } } } diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-curly/expected.braceblock.json b/test/fixtures/lightscript/named-arrow-functions/skinny-curly/expected.braceblock.json new file mode 100644 index 0000000000..84fe23bc04 --- /dev/null +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-curly/expected.braceblock.json @@ -0,0 +1,91 @@ +{ + "type": "File", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "sourceType": "script", + "body": [ + { + "type": "NamedArrowDeclaration", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 2, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 2 + }, + "identifierName": "fn" + }, + "name": "fn" + }, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": true, + "body": { + "type": "BlockStatement", + "start": 8, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "body": [], + "directives": [], + "extra": { + "curly": true + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-curly/expected.json b/test/fixtures/lightscript/named-arrow-functions/skinny-curly/expected.json index 84fe23bc04..12082daac4 100644 --- a/test/fixtures/lightscript/named-arrow-functions/skinny-curly/expected.json +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-curly/expected.json @@ -78,10 +78,42 @@ "column": 10 } }, - "body": [], + "body": [ + { + "type": "ExpressionStatement", + "start": 8, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 8, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "properties": [] + } + } + ], "directives": [], "extra": { - "curly": true + "curly": false } } } diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-curly/options.json b/test/fixtures/lightscript/named-arrow-functions/skinny-curly/options.json index 789ef9baa7..af413d2590 100644 --- a/test/fixtures/lightscript/named-arrow-functions/skinny-curly/options.json +++ b/test/fixtures/lightscript/named-arrow-functions/skinny-curly/options.json @@ -1,8 +1,9 @@ { "alternatives": { - "whiteblock": { + "braceblock": { "allPlugins": true, - "expected": "expected.whiteblock.json" + "excludePlugins": ["whiteblockPreferred", "whiteblockOnly"], + "expected": "expected.braceblock.json" } } } diff --git a/test/fixtures/lightscript/named-arrow-functions/skinny-curly/expected.whiteblock.json b/test/fixtures/lightscript/object-block-ambiguity/basic/expected.braceblock.json similarity index 63% rename from test/fixtures/lightscript/named-arrow-functions/skinny-curly/expected.whiteblock.json rename to test/fixtures/lightscript/object-block-ambiguity/basic/expected.braceblock.json index 41348bfb9f..69b001f468 100644 --- a/test/fixtures/lightscript/named-arrow-functions/skinny-curly/expected.whiteblock.json +++ b/test/fixtures/lightscript/object-block-ambiguity/basic/expected.braceblock.json @@ -1,29 +1,29 @@ { "type": "File", "start": 0, - "end": 10, + "end": 14, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 10 + "line": 3, + "column": 1 } }, "program": { "type": "Program", "start": 0, - "end": 10, + "end": 14, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 10 + "line": 3, + "column": 1 } }, "sourceType": "script", @@ -31,21 +31,21 @@ { "type": "NamedArrowDeclaration", "start": 0, - "end": 10, + "end": 14, "loc": { "start": { "line": 1, "column": 0 }, "end": { - "line": 1, - "column": 10 + "line": 3, + "column": 1 } }, "id": { "type": "Identifier", "start": 0, - "end": 2, + "end": 1, "loc": { "start": { "line": 1, @@ -53,67 +53,68 @@ }, "end": { "line": 1, - "column": 2 + "column": 1 }, - "identifierName": "fn" + "identifierName": "f" }, - "name": "fn" + "name": "f" }, "generator": false, "expression": false, "async": false, "params": [], - "skinny": true, + "skinny": false, "body": { "type": "BlockStatement", - "start": 5, - "end": 10, + "start": 7, + "end": 14, "loc": { "start": { "line": 1, - "column": 5 + "column": 7 }, "end": { - "line": 1, - "column": 10 + "line": 3, + "column": 1 } }, "body": [ { "type": "ExpressionStatement", - "start": 8, - "end": 10, + "start": 11, + "end": 12, "loc": { "start": { - "line": 1, - "column": 8 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 10 + "line": 2, + "column": 3 } }, "expression": { - "type": "ObjectExpression", - "start": 8, - "end": 10, + "type": "Identifier", + "start": 11, + "end": 12, "loc": { "start": { - "line": 1, - "column": 8 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 10 - } + "line": 2, + "column": 3 + }, + "identifierName": "x" }, - "properties": [] + "name": "x" } } ], "directives": [], "extra": { - "curly": false + "curly": true } } } diff --git a/test/fixtures/lightscript/object-block-ambiguity/basic/expected.json b/test/fixtures/lightscript/object-block-ambiguity/basic/expected.json index 69b001f468..59108260c1 100644 --- a/test/fixtures/lightscript/object-block-ambiguity/basic/expected.json +++ b/test/fixtures/lightscript/object-block-ambiguity/basic/expected.json @@ -81,40 +81,95 @@ "body": [ { "type": "ExpressionStatement", - "start": 11, - "end": 12, + "start": 7, + "end": 14, "loc": { "start": { - "line": 2, - "column": 2 + "line": 1, + "column": 7 }, "end": { - "line": 2, - "column": 3 + "line": 3, + "column": 1 } }, "expression": { - "type": "Identifier", - "start": 11, - "end": 12, + "type": "ObjectExpression", + "start": 7, + "end": 14, "loc": { "start": { - "line": 2, - "column": 2 + "line": 1, + "column": 7 }, "end": { - "line": 2, - "column": 3 - }, - "identifierName": "x" + "line": 3, + "column": 1 + } }, - "name": "x" + "properties": [ + { + "type": "ObjectProperty", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "x" + }, + "name": "x" + }, + "extra": { + "shorthand": true + } + } + ] } } ], "directives": [], "extra": { - "curly": true + "curly": false } } } diff --git a/test/fixtures/lightscript/object-block-ambiguity/basic/expected.whiteblock.json b/test/fixtures/lightscript/object-block-ambiguity/basic/expected.whiteblockOnly.json similarity index 98% rename from test/fixtures/lightscript/object-block-ambiguity/basic/expected.whiteblock.json rename to test/fixtures/lightscript/object-block-ambiguity/basic/expected.whiteblockOnly.json index 770e43d7f1..59108260c1 100644 --- a/test/fixtures/lightscript/object-block-ambiguity/basic/expected.whiteblock.json +++ b/test/fixtures/lightscript/object-block-ambiguity/basic/expected.whiteblockOnly.json @@ -66,12 +66,12 @@ "skinny": false, "body": { "type": "BlockStatement", - "start": 4, + "start": 7, "end": 14, "loc": { "start": { "line": 1, - "column": 4 + "column": 7 }, "end": { "line": 3, diff --git a/test/fixtures/lightscript/object-block-ambiguity/error-obj/options.json b/test/fixtures/lightscript/object-block-ambiguity/error-obj/options.json index 0b7c1c9523..775b361f69 100644 --- a/test/fixtures/lightscript/object-block-ambiguity/error-obj/options.json +++ b/test/fixtures/lightscript/object-block-ambiguity/error-obj/options.json @@ -1,9 +1,12 @@ { "alternatives": { - "whiteblock": { + "all": { "throws": "Expected an Indent or Statement (7:6)" }, - "all": { + "whiteblockOnly": { + "throws": "Expected an Indent or Statement (7:6)" + }, + "braceblock": { "throws": "Leading decorators must be attached to a class declaration (7:2)" } } diff --git a/test/fixtures/lightscript/object-block-ambiguity/if/expected.braceblock.json b/test/fixtures/lightscript/object-block-ambiguity/if/expected.braceblock.json new file mode 100644 index 0000000000..5806448ace --- /dev/null +++ b/test/fixtures/lightscript/object-block-ambiguity/if/expected.braceblock.json @@ -0,0 +1,172 @@ +{ + "type": "File", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "test": { + "type": "Identifier", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + }, + "consequent": { + "type": "BlockStatement", + "start": 6, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "expression": { + "type": "Identifier", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "y" + }, + "name": "y" + } + } + ], + "directives": [], + "extra": { + "curly": true + } + }, + "alternate": { + "type": "BlockStatement", + "start": 18, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "expression": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "z" + }, + "name": "z" + } + } + ], + "directives": [], + "extra": { + "curly": true + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/object-block-ambiguity/if/expected.json b/test/fixtures/lightscript/object-block-ambiguity/if/expected.json index 5806448ace..0bac2c4603 100644 --- a/test/fixtures/lightscript/object-block-ambiguity/if/expected.json +++ b/test/fixtures/lightscript/object-block-ambiguity/if/expected.json @@ -61,12 +61,12 @@ }, "consequent": { "type": "BlockStatement", - "start": 6, + "start": 4, "end": 11, "loc": { "start": { "line": 1, - "column": 6 + "column": 4 }, "end": { "line": 1, @@ -76,50 +76,105 @@ "body": [ { "type": "ExpressionStatement", - "start": 8, - "end": 9, + "start": 6, + "end": 11, "loc": { "start": { "line": 1, - "column": 8 + "column": 6 }, "end": { "line": 1, - "column": 9 + "column": 11 } }, "expression": { - "type": "Identifier", - "start": 8, - "end": 9, + "type": "ObjectExpression", + "start": 6, + "end": 11, "loc": { "start": { "line": 1, - "column": 8 + "column": 6 }, "end": { "line": 1, - "column": 9 - }, - "identifierName": "y" + "column": 11 + } }, - "name": "y" + "properties": [ + { + "type": "ObjectProperty", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "y" + }, + "name": "y" + }, + "value": { + "type": "Identifier", + "start": 8, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "y" + }, + "name": "y" + }, + "extra": { + "shorthand": true + } + } + ] } } ], "directives": [], "extra": { - "curly": true + "curly": false } }, "alternate": { "type": "BlockStatement", - "start": 18, + "start": 16, "end": 25, "loc": { "start": { "line": 1, - "column": 18 + "column": 16 }, "end": { "line": 3, @@ -129,40 +184,95 @@ "body": [ { "type": "ExpressionStatement", - "start": 22, - "end": 23, + "start": 18, + "end": 25, "loc": { "start": { - "line": 2, - "column": 2 + "line": 1, + "column": 18 }, "end": { - "line": 2, - "column": 3 + "line": 3, + "column": 1 } }, "expression": { - "type": "Identifier", - "start": 22, - "end": 23, + "type": "ObjectExpression", + "start": 18, + "end": 25, "loc": { "start": { - "line": 2, - "column": 2 + "line": 1, + "column": 18 }, "end": { - "line": 2, - "column": 3 - }, - "identifierName": "z" + "line": 3, + "column": 1 + } }, - "name": "z" + "properties": [ + { + "type": "ObjectProperty", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "z" + }, + "name": "z" + }, + "value": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + }, + "identifierName": "z" + }, + "name": "z" + }, + "extra": { + "shorthand": true + } + } + ] } } ], "directives": [], "extra": { - "curly": true + "curly": false } } } diff --git a/test/fixtures/lightscript/object-block-ambiguity/if/expected.whiteblock.json b/test/fixtures/lightscript/object-block-ambiguity/if/expected.whiteblockOnly.json similarity index 100% rename from test/fixtures/lightscript/object-block-ambiguity/if/expected.whiteblock.json rename to test/fixtures/lightscript/object-block-ambiguity/if/expected.whiteblockOnly.json diff --git a/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/actual.js b/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/actual.js index 497e7c4086..26ad29aeec 100644 --- a/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/actual.js +++ b/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/actual.js @@ -1,3 +1,3 @@ if true: { - for elem e in arr: e + ...for elem e in arr: e } diff --git a/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/expected.json b/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/expected.json index f2b3febedc..46e3fab42f 100644 --- a/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/expected.json +++ b/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 35, + "end": 38, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 35, + "end": 38, "loc": { "start": { "line": 1, @@ -31,7 +31,7 @@ { "type": "IfStatement", "start": 0, - "end": 35, + "end": 38, "loc": { "start": { "line": 1, @@ -60,12 +60,12 @@ }, "consequent": { "type": "BlockStatement", - "start": 9, - "end": 35, + "start": 7, + "end": 38, "loc": { "start": { "line": 1, - "column": 9 + "column": 7 }, "end": { "line": 3, @@ -74,90 +74,137 @@ }, "body": [ { - "type": "ForInArrayStatement", - "start": 13, - "end": 33, + "type": "ExpressionStatement", + "start": 9, + "end": 38, "loc": { "start": { - "line": 2, - "column": 2 + "line": 1, + "column": 9 }, "end": { - "line": 2, - "column": 22 + "line": 3, + "column": 1 } }, - "elem": { - "type": "Identifier", - "start": 22, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 11 - }, - "end": { - "line": 2, - "column": 12 - }, - "identifierName": "e" - }, - "name": "e" - }, - "body": { - "type": "ExpressionStatement", - "start": 32, - "end": 33, + "expression": { + "type": "ObjectComprehension", + "start": 9, + "end": 38, "loc": { "start": { - "line": 2, - "column": 21 + "line": 1, + "column": 9 }, "end": { - "line": 2, - "column": 22 + "line": 3, + "column": 1 } }, - "expression": { - "type": "Identifier", - "start": 32, - "end": 33, - "loc": { - "start": { - "line": 2, - "column": 21 + "properties": [ + { + "type": "LoopComprehension", + "start": 13, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 25 + } }, - "end": { - "line": 2, - "column": 22 - }, - "identifierName": "e" - }, - "name": "e" - } - }, - "array": { - "type": "Identifier", - "start": 27, - "end": 30, - "loc": { - "start": { - "line": 2, - "column": 16 - }, - "end": { - "line": 2, - "column": 19 - }, - "identifierName": "arr" - }, - "name": "arr" + "loop": { + "type": "ForInArrayStatement", + "start": 13, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "elem": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "e" + }, + "name": "e" + }, + "body": { + "type": "ExpressionStatement", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "expression": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + }, + "identifierName": "e" + }, + "name": "e" + } + }, + "array": { + "type": "Identifier", + "start": 30, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 22 + }, + "identifierName": "arr" + }, + "name": "arr" + } + } + } + ] } } ], "directives": [], "extra": { - "curly": true + "curly": false } }, "alternate": null diff --git a/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/expected.whiteblock.json b/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/expected.whiteblock.json deleted file mode 100644 index 814c1eb48e..0000000000 --- a/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/expected.whiteblock.json +++ /dev/null @@ -1,199 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "sourceType": "script", - "body": [ - { - "type": "IfStatement", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "test": { - "type": "BooleanLiteral", - "start": 3, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 7 - } - }, - "value": true - }, - "consequent": { - "type": "BlockStatement", - "start": 7, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "body": [ - { - "type": "ExpressionStatement", - "start": 9, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 9 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "expression": { - "type": "ObjectComprehension", - "start": 9, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 9 - }, - "end": { - "line": 3, - "column": 1 - } - }, - "properties": [], - "loop": { - "type": "ForInArrayStatement", - "start": 13, - "end": 33, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 22 - } - }, - "elem": { - "type": "Identifier", - "start": 22, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 11 - }, - "end": { - "line": 2, - "column": 12 - }, - "identifierName": "e" - }, - "name": "e" - }, - "body": { - "type": "ExpressionStatement", - "start": 32, - "end": 33, - "loc": { - "start": { - "line": 2, - "column": 21 - }, - "end": { - "line": 2, - "column": 22 - } - }, - "expression": { - "type": "Identifier", - "start": 32, - "end": 33, - "loc": { - "start": { - "line": 2, - "column": 21 - }, - "end": { - "line": 2, - "column": 22 - }, - "identifierName": "e" - }, - "name": "e" - } - }, - "array": { - "type": "Identifier", - "start": 27, - "end": 30, - "loc": { - "start": { - "line": 2, - "column": 16 - }, - "end": { - "line": 2, - "column": 19 - }, - "identifierName": "arr" - }, - "name": "arr" - } - } - } - } - ], - "directives": [], - "extra": { - "curly": false - } - }, - "alternate": null - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/expected.whiteblockOnly.json b/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/expected.whiteblockOnly.json new file mode 100644 index 0000000000..46e3fab42f --- /dev/null +++ b/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/expected.whiteblockOnly.json @@ -0,0 +1,215 @@ +{ + "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": "IfStatement", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "test": { + "type": "BooleanLiteral", + "start": 3, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": true + }, + "consequent": { + "type": "BlockStatement", + "start": 7, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "expression": { + "type": "ObjectComprehension", + "start": 9, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "properties": [ + { + "type": "LoopComprehension", + "start": 13, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "loop": { + "type": "ForInArrayStatement", + "start": 13, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "elem": { + "type": "Identifier", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "e" + }, + "name": "e" + }, + "body": { + "type": "ExpressionStatement", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "expression": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + }, + "identifierName": "e" + }, + "name": "e" + } + }, + "array": { + "type": "Identifier", + "start": 30, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 22 + }, + "identifierName": "arr" + }, + "name": "arr" + } + } + } + ] + } + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "alternate": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/options.json b/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/options.json new file mode 100644 index 0000000000..7c6a48606a --- /dev/null +++ b/test/fixtures/lightscript/object-block-ambiguity/object-comprehension/options.json @@ -0,0 +1,7 @@ +{ + "alternatives": { + "braceblock": { + "throws": "Unexpected token (2:2)" + } + } +} diff --git a/test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.braceblock.json b/test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.braceblock.json new file mode 100644 index 0000000000..d97d38bee6 --- /dev/null +++ b/test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.braceblock.json @@ -0,0 +1,171 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "body": [ + { + "type": "NamedArrowDeclaration", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "id": { + "type": "Identifier", + "start": 0, + "end": 1, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + }, + "identifierName": "f" + }, + "name": "f" + }, + "generator": false, + "expression": false, + "async": false, + "params": [], + "skinny": false, + "body": { + "type": "BlockStatement", + "start": 7, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + } + } + ], + "directives": [], + "extra": { + "curly": true + } + } + }, + { + "type": "EmptyStatement", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + } + }, + { + "type": "ExpressionStatement", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "expression": { + "type": "Identifier", + "start": 14, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "y" + }, + "name": "y" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.json b/test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.json index d97d38bee6..efc2ffd412 100644 --- a/test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.json +++ b/test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.json @@ -81,40 +81,95 @@ "body": [ { "type": "ExpressionStatement", - "start": 9, - "end": 10, + "start": 7, + "end": 12, "loc": { "start": { "line": 1, - "column": 9 + "column": 7 }, "end": { "line": 1, - "column": 10 + "column": 12 } }, "expression": { - "type": "Identifier", - "start": 9, - "end": 10, + "type": "ObjectExpression", + "start": 7, + "end": 12, "loc": { "start": { "line": 1, - "column": 9 + "column": 7 }, "end": { "line": 1, - "column": 10 - }, - "identifierName": "x" + "column": 12 + } }, - "name": "x" + "properties": [ + { + "type": "ObjectProperty", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "method": false, + "shorthand": true, + "computed": false, + "key": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "x" + }, + "name": "x" + }, + "extra": { + "shorthand": true + } + } + ] } } ], "directives": [], "extra": { - "curly": true + "curly": false } } }, diff --git a/test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.whiteblock.json b/test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.whiteblockOnly.json similarity index 99% rename from test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.whiteblock.json rename to test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.whiteblockOnly.json index 6d974a9eb9..efc2ffd412 100644 --- a/test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.whiteblock.json +++ b/test/fixtures/lightscript/object-block-ambiguity/oneline-semi/expected.whiteblockOnly.json @@ -66,12 +66,12 @@ "skinny": false, "body": { "type": "BlockStatement", - "start": 4, + "start": 7, "end": 12, "loc": { "start": { "line": 1, - "column": 4 + "column": 7 }, "end": { "line": 1, diff --git a/test/fixtures/lightscript/object-block-ambiguity/options.json b/test/fixtures/lightscript/object-block-ambiguity/options.json index 441a3fef35..a091adfa61 100644 --- a/test/fixtures/lightscript/object-block-ambiguity/options.json +++ b/test/fixtures/lightscript/object-block-ambiguity/options.json @@ -1,9 +1,17 @@ { "alternatives": { - "whiteblock": { + "all": { + "includePlugins": ["splatComprehension"] + }, + "whiteblockOnly": { "allPlugins": true, - "excludePlugins": ["splatComprehension"], - "expected": "expected.whiteblock.json" + "excludePlugins": ["whiteblockPreferred"], + "expected": "expected.whiteblockOnly.json" + }, + "braceblock": { + "allPlugins": true, + "excludePlugins": ["whiteblockPreferred", "whiteblockOnly"], + "expected": "expected.braceblock.json" } } } diff --git a/test/fixtures/lightscript/object-block-ambiguity/tilde-call/expected.whiteblock.json b/test/fixtures/lightscript/object-block-ambiguity/tilde-call/expected.json similarity index 100% rename from test/fixtures/lightscript/object-block-ambiguity/tilde-call/expected.whiteblock.json rename to test/fixtures/lightscript/object-block-ambiguity/tilde-call/expected.json diff --git a/test/fixtures/lightscript/object-block-ambiguity/tilde-call/expected.whiteblockOnly.json b/test/fixtures/lightscript/object-block-ambiguity/tilde-call/expected.whiteblockOnly.json new file mode 100644 index 0000000000..115f7801e7 --- /dev/null +++ b/test/fixtures/lightscript/object-block-ambiguity/tilde-call/expected.whiteblockOnly.json @@ -0,0 +1,154 @@ +{ + "type": "File", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "sourceType": "script", + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "test": { + "type": "Identifier", + "start": 3, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + }, + "consequent": { + "type": "BlockStatement", + "start": 4, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "expression": { + "type": "CallExpression", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "callee": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "y" + }, + "name": "y" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 6, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "properties": [] + } + ], + "tilde": true + } + } + ], + "directives": [], + "extra": { + "curly": false + } + }, + "alternate": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/lightscript/object-block-ambiguity/tilde-call/options.json b/test/fixtures/lightscript/object-block-ambiguity/tilde-call/options.json index 22c1a2e3aa..274e29cbb2 100644 --- a/test/fixtures/lightscript/object-block-ambiguity/tilde-call/options.json +++ b/test/fixtures/lightscript/object-block-ambiguity/tilde-call/options.json @@ -1,6 +1,6 @@ { "alternatives": { - "all": { + "braceblock": { "throws": "Unexpected token (1:8)" } } diff --git a/test/fixtures/match/options.json b/test/fixtures/match/options.json index 2db5769938..9b7d216266 100644 --- a/test/fixtures/match/options.json +++ b/test/fixtures/match/options.json @@ -2,7 +2,7 @@ "alternatives": { "default": { "allPlugins": true, - "excludePlugins": ["whiteblockOnly"] + "excludePlugins": ["whiteblockOnly", "whiteblockPreferred"] } } } diff --git a/test/index.js b/test/index.js index 569865c452..57bae16b6d 100644 --- a/test/index.js +++ b/test/index.js @@ -1,15 +1,13 @@ import path from "path"; import { runFixtureTests } from "./utils/runFixtureTests"; -import { parse, parseExpression, getAvailablePlugins } from "../lib"; +import * as parser from "../lib"; import { TestRun, Test } from "./utils/TestRunner"; import resolve from "try-resolve"; import { readFile } from "babel-helper-fixtures"; -const parser = { parse, parseExpression, getAvailablePlugins }; - // All fixtures with default options -let run = new TestRun(parser); +const run = new TestRun(parser); run.runTopics(path.join(__dirname, "fixtures")); // Holdovers from upstream babylon -runFixtureTests(path.join(__dirname, "expressions"), parseExpression); +runFixtureTests(path.join(__dirname, "expressions"), parser.parseExpression); diff --git a/test/utils/TestRunner.js b/test/utils/TestRunner.js index 18a90bfa85..1e4e6c9180 100644 --- a/test/utils/TestRunner.js +++ b/test/utils/TestRunner.js @@ -251,6 +251,14 @@ exports.Test = class Test { excludePlugins(plugins, list) { if (!list) return plugins; + + // Exclude all plugins that depend on the excluded plugin + const md = this.testRun.parser.getPluginMetadata(); + for (let i = 0; i < list.length; i++) { + const rd = md._reverseDeps[list[i]]; + if (rd) rd.forEach( (x) => list.push(x) ); + } + return plugins.filter((entry) => { return list.indexOf(entry) < 0; }); @@ -323,7 +331,11 @@ exports.Test = class Test { } else { diff = misMatch(JSON.parse(this.expectedCode), ast); if (diff) { - //save(test, ast); + // If expectedFile doesn't exist, we're diffing against a base expected.json + // create the new expectation instead of throwing an error. + if (this.expectedFile && !resolve(this.expectedFile)) { + return this.save(ast, this.expectedFile); + } throw new Error(diff + "\n\nOptions:\n" + JSON.stringify(opts, null, 2)); } }