diff --git a/test/Esprima.Tests/Fixtures.cs b/test/Esprima.Tests/Fixtures.cs index cb3e9c4c..aab84788 100644 --- a/test/Esprima.Tests/Fixtures.cs +++ b/test/Esprima.Tests/Fixtures.cs @@ -186,9 +186,27 @@ public void ExecuteTestCase(string fixture) expected = File.ReadAllText(failureFilePath); if (WriteBackExpectedTree && conversionOptions.TestCompatibilityMode == AstToJsonTestCompatibilityMode.None) { - var actual = ParseAndFormat(sourceType, script, parserOptions, parserFactory, conversionOptions); - if (!CompareTrees(actual, expected, metadata)) - File.WriteAllText(failureFilePath, actual); + try + { + ParseAndFormat(sourceType, script, parserOptions, parserFactory, conversionOptions); + } + catch (ParserException ex) + { + var expectedJsonObject = JObject.Parse(expected); + + var parseError = ex.Error!; + var actualJsonObject = new JObject + { + ["index"] = parseError.Index, + ["lineNumber"] = parseError.LineNumber, + ["column"] = parseError.Column, + ["message"] = ex.Message, + ["description"] = parseError.Description, + }; + + if (!JToken.DeepEquals(expectedJsonObject, actualJsonObject)) + File.WriteAllText(failureFilePath, actualJsonObject.ToString(Formatting.None)); + } } } else @@ -292,6 +310,7 @@ private static FixtureMetadata CreateFrom(HashSet flags) IncludesLocation = flags.Contains("IncludesLocation"), IncludesRange = flags.Contains("IncludesRange"), IncludesLocationSource = flags.Contains("IncludesLocationSource"), + IncludesTokens = flags.Contains("IncludesTokens"), IgnoresRegex = flags.Contains("IgnoresRegex"), Skip = flags.Contains("Skip"), }; @@ -303,6 +322,7 @@ private FixtureMetadata() { } public bool IncludesLocation { get; init; } public bool IncludesRange { get; init; } public bool IncludesLocationSource { get; init; } + public bool IncludesTokens { get; init; } public bool IgnoresRegex { get; init; } public bool Skip { get; init; } @@ -311,6 +331,7 @@ public AstToJsonOptions CreateConversionOptions(AstToJsonOptions defaultOptions) TestCompatibilityMode = TestCompatibilityMode, IncludeLineColumn = IncludesLocation, IncludeRange = IncludesRange, + IncludeTokens = IncludesTokens, }; } } diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-callee-with-args.failure.json b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-callee-with-args.failure.json new file mode 100644 index 00000000..add070a1 --- /dev/null +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-callee-with-args.failure.json @@ -0,0 +1 @@ +{"index":8,"lineNumber":1,"column":9,"message":"Line 1: Invalid optional chain from new expression","description":"Invalid optional chain from new expression"} \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-callee-with-args.js b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-callee-with-args.js new file mode 100644 index 00000000..f52814d6 --- /dev/null +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-callee-with-args.js @@ -0,0 +1 @@ +new a?.b() \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-callee-without-args.failure.json b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-callee-without-args.failure.json new file mode 100644 index 00000000..add070a1 --- /dev/null +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-callee-without-args.failure.json @@ -0,0 +1 @@ +{"index":8,"lineNumber":1,"column":9,"message":"Line 1: Invalid optional chain from new expression","description":"Invalid optional chain from new expression"} \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-callee-without-args.js b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-callee-without-args.js new file mode 100644 index 00000000..1c237ec5 --- /dev/null +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-callee-without-args.js @@ -0,0 +1 @@ +new a?.b \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-construction.failure.json b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-construction.failure.json new file mode 100644 index 00000000..f2ea92c9 --- /dev/null +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-construction.failure.json @@ -0,0 +1 @@ +{"index":7,"lineNumber":1,"column":8,"message":"Line 1: Unexpected token (","description":"Unexpected token ("} \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-construction.js b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-construction.js new file mode 100644 index 00000000..62d32f62 --- /dev/null +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-construction.js @@ -0,0 +1 @@ +new a?.() \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-leading-paren.failure.json b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-leading-paren.failure.json new file mode 100644 index 00000000..b0040d66 --- /dev/null +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-leading-paren.failure.json @@ -0,0 +1 @@ +{"index":14,"lineNumber":1,"column":15,"message":"Line 1: Invalid optional chain from new expression","description":"Invalid optional chain from new expression"} \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-leading-paren.js b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-leading-paren.js new file mode 100644 index 00000000..22393ae6 --- /dev/null +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-new-leading-paren.js @@ -0,0 +1 @@ +new (a?.b)?.c \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-super-call.failure.json b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-super-call.failure.json new file mode 100644 index 00000000..49ec7bf8 --- /dev/null +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-super-call.failure.json @@ -0,0 +1 @@ +{"index":46,"lineNumber":2,"column":26,"message":"Line 2: 'super' keyword unexpected here","description":"'super' keyword unexpected here"} \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-super-call.js b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-super-call.js new file mode 100644 index 00000000..1b2c06bf --- /dev/null +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-super-call.js @@ -0,0 +1,3 @@ +class B extends A { + constructor() { super?.(); } +} \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-super-member-access.failure.json b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-super-member-access.failure.json new file mode 100644 index 00000000..75ae735b --- /dev/null +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-super-member-access.failure.json @@ -0,0 +1 @@ +{"index":50,"lineNumber":2,"column":30,"message":"Line 2: 'super' keyword unexpected here","description":"'super' keyword unexpected here"} \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-super-member-access.js b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-super-member-access.js new file mode 100644 index 00000000..ea04c2fe --- /dev/null +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/invalid-optional-chaining-super-member-access.js @@ -0,0 +1,3 @@ +class B extends A { + get prop() { return super?.a; } +} \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-computed-property.js b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-computed-property.js index d7df54bd..1f8f7753 100644 --- a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-computed-property.js +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-computed-property.js @@ -1,4 +1,5 @@ a?.['b'].c a.b?.['c'] -new a?.['b'].c -new a.b?.['c'] \ No newline at end of file +new (a?.['b'].c) +new (a?.['b']).c +new (a.b?.['c']) diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-computed-property.tree.json b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-computed-property.tree.json index 00e45471..38b0f7fd 100644 --- a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-computed-property.tree.json +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-computed-property.tree.json @@ -1,1050 +1,1504 @@ { - "type": "Program", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "ChainExpression", - "expression": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "MemberExpression", - "computed": true, - "object": { - "type": "Identifier", - "name": "a", - "range": [ - 0, - 1 - ], - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "property": { - "type": "Literal", - "value": "b", - "raw": "'b'", - "range": [ - 4, - 7 - ], - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 7 - } - } - }, - "optional": true, - "range": [ - 0, - 8 - ], - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 8 - } - } - }, - "property": { - "type": "Identifier", - "name": "c", - "range": [ - 9, - 10 - ], - "loc": { - "start": { - "line": 1, - "column": 9 - }, - "end": { - "line": 1, - "column": 10 - } - } - }, - "optional": false, - "range": [ - 0, - 10 - ], - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 10 - } - } - } - }, - "range": [ + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ChainExpression", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "MemberExpression", + "computed": true, + "object": { + "type": "Identifier", + "name": "a", + "range": [ 0, - 10 - ], - "loc": { + 1 + ], + "loc": { "start": { - "line": 1, - "column": 0 + "line": 1, + "column": 0 }, "end": { - "line": 1, - "column": 10 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "ChainExpression", - "expression": { - "type": "MemberExpression", - "computed": true, - "object": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "Identifier", - "name": "a", - "range": [ - 11, - 12 - ], - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 1 - } - } - }, - "property": { - "type": "Identifier", - "name": "b", - "range": [ - 13, - 14 - ], - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 3 - } - } - }, - "optional": false, - "range": [ - 11, - 14 - ], - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 3 - } - } - }, - "property": { - "type": "Literal", - "value": "c", - "raw": "'c'", - "range": [ - 17, - 20 - ], - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 9 - } - } - }, - "optional": true, - "range": [ - 11, - 21 - ], - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 10 - } - } + "line": 1, + "column": 1 } + } }, - "range": [ - 11, - 21 - ], - "loc": { + "property": { + "type": "Literal", + "value": "b", + "raw": "'b'", + "range": [ + 4, + 7 + ], + "loc": { "start": { - "line": 2, - "column": 0 + "line": 1, + "column": 4 }, "end": { - "line": 2, - "column": 10 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "NewExpression", - "callee": { - "type": "ChainExpression", - "expression": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "MemberExpression", - "computed": true, - "object": { - "type": "Identifier", - "name": "a", - "range": [ - 26, - 27 - ], - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 5 - } - } - }, - "property": { - "type": "Literal", - "value": "b", - "raw": "'b'", - "range": [ - 30, - 33 - ], - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 11 - } - } - }, - "optional": true, - "range": [ - 26, - 34 - ], - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 12 - } - } - }, - "property": { - "type": "Identifier", - "name": "c", - "range": [ - 35, - 36 - ], - "loc": { - "start": { - "line": 3, - "column": 13 - }, - "end": { - "line": 3, - "column": 14 - } - } - }, - "optional": false, - "range": [ - 26, - 36 - ], - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 14 - } - } - } - }, - "arguments": [], - "range": [ - 22, - 36 - ], - "loc": { - "start": { - "line": 3, - "column": 0 - }, - "end": { - "line": 3, - "column": 14 - } + "line": 1, + "column": 7 } + } }, + "optional": true, "range": [ - 22, - 36 + 0, + 8 ], "loc": { - "start": { - "line": 3, - "column": 0 - }, - "end": { - "line": 3, - "column": 14 - } + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "NewExpression", - "callee": { - "type": "ChainExpression", - "expression": { - "type": "MemberExpression", - "computed": true, - "object": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "Identifier", - "name": "a", - "range": [ - 41, - 42 - ], - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 5 - } - } - }, - "property": { - "type": "Identifier", - "name": "b", - "range": [ - 43, - 44 - ], - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 4, - "column": 7 - } - } - }, - "optional": false, - "range": [ - 41, - 44 - ], - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 7 - } - } - }, - "property": { - "type": "Literal", - "value": "c", - "raw": "'c'", - "range": [ - 47, - 50 - ], - "loc": { - "start": { - "line": 4, - "column": 10 - }, - "end": { - "line": 4, - "column": 13 - } - } - }, - "optional": true, - "range": [ - 41, - 51 - ], - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 14 - } - } - } - }, - "arguments": [], - "range": [ - 37, - 51 - ], - "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 4, - "column": 14 - } - } - }, + }, + "property": { + "type": "Identifier", + "name": "c", "range": [ - 37, - 51 + 9, + 10 ], "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 4, - "column": 14 - } + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + "optional": false, + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 } + } + }, + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } } - ], - "sourceType": "script", - "range": [ + }, + "range": [ 0, - 51 - ], - "loc": { + 10 + ], + "loc": { "start": { - "line": 1, - "column": 0 + "line": 1, + "column": 0 }, "end": { - "line": 4, - "column": 14 + "line": 1, + "column": 10 } + } }, - "tokens": [ - { - "type": "Identifier", - "value": "a", - "range": [ - 0, - 1 - ], - "loc": { + { + "type": "ExpressionStatement", + "expression": { + "type": "ChainExpression", + "expression": { + "type": "MemberExpression", + "computed": true, + "object": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "a", + "range": [ + 11, + 12 + ], + "loc": { "start": { - "line": 1, - "column": 0 + "line": 2, + "column": 0 }, "end": { - "line": 1, - "column": 1 + "line": 2, + "column": 1 } - } - }, - { - "type": "Punctuator", - "value": "?.", - "range": [ - 1, - 3 - ], - "loc": { + } + }, + "property": { + "type": "Identifier", + "name": "b", + "range": [ + 13, + 14 + ], + "loc": { "start": { - "line": 1, - "column": 1 + "line": 2, + "column": 2 }, "end": { - "line": 1, - "column": 3 + "line": 2, + "column": 3 } - } - }, - { - "type": "Punctuator", - "value": "[", + } + }, + "optional": false, "range": [ - 3, - 4 + 11, + 14 ], "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 4 - } + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } } - }, - { - "type": "String", - "value": "'b'", + }, + "property": { + "type": "Literal", + "value": "c", + "raw": "'c'", "range": [ - 4, - 7 + 17, + 20 ], "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 7 - } + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } } + }, + "optional": true, + "range": [ + 11, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + } }, - { - "type": "Punctuator", - "value": "]", - "range": [ - 7, - 8 - ], - "loc": { + "range": [ + 11, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + "range": [ + 11, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "NewExpression", + "callee": { + "type": "ChainExpression", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "MemberExpression", + "computed": true, + "object": { + "type": "Identifier", + "name": "a", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + "property": { + "type": "Literal", + "value": "b", + "raw": "'b'", + "range": [ + 31, + 34 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "optional": true, + "range": [ + 27, + 35 + ], + "loc": { "start": { - "line": 1, - "column": 7 + "line": 3, + "column": 5 }, "end": { - "line": 1, - "column": 8 + "line": 3, + "column": 13 } - } - }, - { - "type": "Punctuator", - "value": ".", - "range": [ - 8, - 9 - ], - "loc": { + } + }, + "property": { + "type": "Identifier", + "name": "c", + "range": [ + 36, + 37 + ], + "loc": { "start": { - "line": 1, - "column": 8 + "line": 3, + "column": 14 }, "end": { - "line": 1, - "column": 9 + "line": 3, + "column": 15 } - } - }, - { - "type": "Identifier", - "value": "c", + } + }, + "optional": false, "range": [ - 9, - 10 + 27, + 37 ], "loc": { - "start": { - "line": 1, - "column": 9 - }, - "end": { - "line": 1, - "column": 10 - } + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + "range": [ + 27, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 15 } + } }, - { - "type": "Identifier", - "value": "a", - "range": [ - 11, - 12 - ], - "loc": { + "arguments": [], + "range": [ + 22, + 38 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 16 + } + } + }, + "range": [ + 22, + 38 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 16 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "NewExpression", + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "ChainExpression", + "expression": { + "type": "MemberExpression", + "computed": true, + "object": { + "type": "Identifier", + "name": "a", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 6 + } + } + }, + "property": { + "type": "Literal", + "value": "b", + "raw": "'b'", + "range": [ + 48, + 51 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + "optional": true, + "range": [ + 44, + 52 + ], + "loc": { "start": { - "line": 2, - "column": 0 + "line": 4, + "column": 5 }, "end": { - "line": 2, - "column": 1 + "line": 4, + "column": 13 } - } - }, - { - "type": "Punctuator", - "value": ".", + } + }, "range": [ - 12, - 13 + 44, + 52 ], "loc": { - "start": { - "line": 2, - "column": 1 - }, - "end": { - "line": 2, - "column": 2 - } + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 13 + } } - }, - { + }, + "property": { "type": "Identifier", - "value": "b", + "name": "c", "range": [ - 13, - 14 + 54, + 55 ], "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 3 - } + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 16 + } } - }, - { - "type": "Punctuator", - "value": "?.", - "range": [ - 14, - 16 - ], - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 5 - } + }, + "optional": false, + "range": [ + 43, + 55 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 16 } + } }, - { - "type": "Punctuator", - "value": "[", - "range": [ - 16, - 17 - ], - "loc": { - "start": { - "line": 2, + "arguments": [], + "range": [ + 39, + 55 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + "range": [ + 39, + 55 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "NewExpression", + "callee": { + "type": "ChainExpression", + "expression": { + "type": "MemberExpression", + "computed": true, + "object": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "a", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 5, "column": 5 - }, - "end": { - "line": 2, + }, + "end": { + "line": 5, "column": 6 + } } - } - }, - { - "type": "String", - "value": "'c'", - "range": [ - 17, - 20 - ], - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 9 + }, + "property": { + "type": "Identifier", + "name": "b", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + } } - } - }, - { - "type": "Punctuator", - "value": "]", - "range": [ - 20, - 21 - ], - "loc": { + }, + "optional": false, + "range": [ + 61, + 64 + ], + "loc": { "start": { - "line": 2, - "column": 9 + "line": 5, + "column": 5 }, "end": { - "line": 2, - "column": 10 + "line": 5, + "column": 8 } - } - }, - { - "type": "Keyword", - "value": "new", - "range": [ - 22, - 25 - ], - "loc": { + } + }, + "property": { + "type": "Literal", + "value": "c", + "raw": "'c'", + "range": [ + 67, + 70 + ], + "loc": { "start": { - "line": 3, - "column": 0 + "line": 5, + "column": 11 }, "end": { - "line": 3, - "column": 3 + "line": 5, + "column": 14 } - } - }, - { - "type": "Identifier", - "value": "a", + } + }, + "optional": true, "range": [ - 26, - 27 + 61, + 71 ], "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 5 - } + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 15 + } + } + }, + "range": [ + 61, + 71 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 15 } + } }, - { - "type": "Punctuator", - "value": "?.", - "range": [ - 27, - 29 - ], - "loc": { - "start": { - "line": 3, - "column": 5 - }, - "end": { - "line": 3, - "column": 7 - } - } + "arguments": [], + "range": [ + 56, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 16 + } + } + }, + "range": [ + 56, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 0 }, - { - "type": "Punctuator", - "value": "[", - "range": [ - 29, - 30 - ], - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 8 - } - } + "end": { + "line": 5, + "column": 16 + } + } + } + ], + "sourceType": "script", + "strict": false, + "tokens": [ + { + "type": "Identifier", + "value": "a", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 }, - { - "type": "String", - "value": "'b'", - "range": [ - 30, - 33 - ], - "loc": { - "start": { - "line": 3, - "column": 8 - }, - "end": { - "line": 3, - "column": 11 - } - } + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "?.", + "range": [ + 1, + 3 + ], + "loc": { + "start": { + "line": 1, + "column": 1 }, - { - "type": "Punctuator", - "value": "]", - "range": [ - 33, - 34 - ], - "loc": { - "start": { - "line": 3, - "column": 11 - }, - "end": { - "line": 3, - "column": 12 - } - } + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "[", + "range": [ + 3, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 3 }, - { - "type": "Punctuator", - "value": ".", - "range": [ - 34, - 35 - ], - "loc": { - "start": { - "line": 3, - "column": 12 - }, - "end": { - "line": 3, - "column": 13 - } - } + "end": { + "line": 1, + "column": 4 + } + } + }, + { + "type": "StringLiteral", + "value": "'b'", + "range": [ + 4, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 4 }, - { - "type": "Identifier", - "value": "c", - "range": [ - 35, - 36 - ], - "loc": { - "start": { - "line": 3, - "column": 13 - }, - "end": { - "line": 3, - "column": 14 - } - } + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": "]", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 }, - { - "type": "Keyword", - "value": "new", - "range": [ - 37, - 40 - ], - "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 4, - "column": 3 - } - } + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 }, - { - "type": "Identifier", - "value": "a", - "range": [ - 41, - 42 - ], - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 5 - } - } + "end": { + "line": 1, + "column": 9 + } + } + }, + { + "type": "Identifier", + "value": "c", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 }, - { - "type": "Punctuator", - "value": ".", - "range": [ - 42, - 43 - ], - "loc": { - "start": { - "line": 4, - "column": 5 - }, - "end": { - "line": 4, - "column": 6 - } - } + "end": { + "line": 1, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 11, + 12 + ], + "loc": { + "start": { + "line": 2, + "column": 0 }, - { - "type": "Identifier", - "value": "b", - "range": [ - 43, - 44 - ], - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 4, - "column": 7 - } - } + "end": { + "line": 2, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 2, + "column": 1 }, - { - "type": "Punctuator", - "value": "?.", - "range": [ - 44, - 46 - ], - "loc": { - "start": { - "line": 4, - "column": 7 - }, - "end": { - "line": 4, - "column": 9 - } - } + "end": { + "line": 2, + "column": 2 + } + } + }, + { + "type": "Identifier", + "value": "b", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 2, + "column": 2 }, - { - "type": "Punctuator", - "value": "[", - "range": [ - 46, - 47 - ], - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 4, - "column": 10 - } - } + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "?.", + "range": [ + 14, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 3 }, - { - "type": "String", - "value": "'c'", - "range": [ - 47, - 50 - ], - "loc": { - "start": { - "line": 4, - "column": 10 - }, - "end": { - "line": 4, - "column": 13 - } - } + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "[", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 5 }, - { - "type": "Punctuator", - "value": "]", - "range": [ - 50, - 51 - ], - "loc": { - "start": { - "line": 4, - "column": 13 - }, - "end": { - "line": 4, - "column": 14 - } - } + "end": { + "line": 2, + "column": 6 + } + } + }, + { + "type": "StringLiteral", + "value": "'c'", + "range": [ + 17, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "]", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Keyword", + "value": "new", + "range": [ + 22, + 25 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": "?.", + "range": [ + 28, + 30 + ], + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "[", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "StringLiteral", + "value": "'b'", + "range": [ + 31, + 34 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 12 } - ] + } + }, + { + "type": "Punctuator", + "value": "]", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "c", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 16 + } + } + }, + { + "type": "Keyword", + "value": "new", + "range": [ + 39, + 42 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": "?.", + "range": [ + 45, + 47 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "[", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "StringLiteral", + "value": "'b'", + "range": [ + 48, + 51 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "]", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Identifier", + "value": "c", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + { + "type": "Keyword", + "value": "new", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "b", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "?.", + "range": [ + 64, + 66 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "[", + "range": [ + 66, + 67 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 11 + } + } + }, + { + "type": "StringLiteral", + "value": "'c'", + "range": [ + 67, + 70 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "]", + "range": [ + 70, + 71 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 71, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 16 + } + } + } + ], + "range": [ + 0, + 72 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 16 + } + } } \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-static-property.js b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-static-property.js index 9efbe64a..b7ac8dc9 100644 --- a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-static-property.js +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-static-property.js @@ -1,4 +1,5 @@ a?.b.c a.b?.c -new a?.b.c -new a.b?.c \ No newline at end of file +new (a?.b.c) +new (a?.b).c +new (a.b?.c) diff --git a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-static-property.tree.json b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-static-property.tree.json index 1fcf0c48..fc2be798 100644 --- a/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-static-property.tree.json +++ b/test/Esprima.Tests/Fixtures/es2020/optional-chaining/optional-chaining-static-property.tree.json @@ -1,902 +1,1319 @@ { - "type": "Program", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "ChainExpression", - "expression": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "Identifier", - "name": "a", - "range": [ - 0, - 1 - ], - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "property": { - "type": "Identifier", - "name": "b", - "range": [ - 3, - 4 - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 4 - } - } - }, - "optional": true, - "range": [ - 0, - 4 - ], - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 4 - } - } - }, - "property": { - "type": "Identifier", - "name": "c", - "range": [ - 5, - 6 - ], - "loc": { - "start": { - "line": 1, - "column": 5 - }, - "end": { - "line": 1, - "column": 6 - } - } - }, - "optional": false, - "range": [ - 0, - 6 - ], - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 6 - } - } - } - }, - "range": [ + "type": "Program", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ChainExpression", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "a", + "range": [ 0, - 6 - ], - "loc": { + 1 + ], + "loc": { "start": { - "line": 1, - "column": 0 + "line": 1, + "column": 0 }, "end": { - "line": 1, - "column": 6 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "ChainExpression", - "expression": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "Identifier", - "name": "a", - "range": [ - 7, - 8 - ], - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 1 - } - } - }, - "property": { - "type": "Identifier", - "name": "b", - "range": [ - 9, - 10 - ], - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 3 - } - } - }, - "optional": false, - "range": [ - 7, - 10 - ], - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 3 - } - } - }, - "property": { - "type": "Identifier", - "name": "c", - "range": [ - 12, - 13 - ], - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - } - } - }, - "optional": true, - "range": [ - 7, - 13 - ], - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 6 - } - } + "line": 1, + "column": 1 } + } }, - "range": [ - 7, - 13 - ], - "loc": { + "property": { + "type": "Identifier", + "name": "b", + "range": [ + 3, + 4 + ], + "loc": { "start": { - "line": 2, - "column": 0 + "line": 1, + "column": 3 }, "end": { - "line": 2, - "column": 6 - } - } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "NewExpression", - "callee": { - "type": "ChainExpression", - "expression": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "Identifier", - "name": "a", - "range": [ - 18, - 19 - ], - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 5 - } - } - }, - "property": { - "type": "Identifier", - "name": "b", - "range": [ - 21, - 22 - ], - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 8 - } - } - }, - "optional": true, - "range": [ - 18, - 22 - ], - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 8 - } - } - }, - "property": { - "type": "Identifier", - "name": "c", - "range": [ - 23, - 24 - ], - "loc": { - "start": { - "line": 3, - "column": 9 - }, - "end": { - "line": 3, - "column": 10 - } - } - }, - "optional": false, - "range": [ - 18, - 24 - ], - "loc": { - "start": { - "line": 3, - "column": 4 - }, - "end": { - "line": 3, - "column": 10 - } - } - } - }, - "arguments": [], - "range": [ - 14, - 24 - ], - "loc": { - "start": { - "line": 3, - "column": 0 - }, - "end": { - "line": 3, - "column": 10 - } + "line": 1, + "column": 4 } + } }, + "optional": true, "range": [ - 14, - 24 + 0, + 4 ], "loc": { - "start": { - "line": 3, - "column": 0 - }, - "end": { - "line": 3, - "column": 10 - } + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "NewExpression", - "callee": { - "type": "ChainExpression", - "expression": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "MemberExpression", - "computed": false, - "object": { - "type": "Identifier", - "name": "a", - "range": [ - 29, - 30 - ], - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 5 - } - } - }, - "property": { - "type": "Identifier", - "name": "b", - "range": [ - 31, - 32 - ], - "loc": { - "start": { - "line": 4, - "column": 6 - }, - "end": { - "line": 4, - "column": 7 - } - } - }, - "optional": false, - "range": [ - 29, - 32 - ], - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 7 - } - } - }, - "property": { - "type": "Identifier", - "name": "c", - "range": [ - 34, - 35 - ], - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 4, - "column": 10 - } - } - }, - "optional": true, - "range": [ - 29, - 35 - ], - "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 10 - } - } - } - }, - "arguments": [], - "range": [ - 25, - 35 - ], - "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 4, - "column": 10 - } - } - }, + }, + "property": { + "type": "Identifier", + "name": "c", "range": [ - 25, - 35 + 5, + 6 ], "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 4, - "column": 10 - } + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } } + }, + "optional": false, + "range": [ + 0, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + } + }, + "range": [ + 0, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } } - ], - "sourceType": "script", - "range": [ + }, + "range": [ 0, - 35 - ], - "loc": { + 6 + ], + "loc": { "start": { - "line": 1, - "column": 0 + "line": 1, + "column": 0 }, "end": { - "line": 4, - "column": 10 + "line": 1, + "column": 6 } + } }, - "tokens": [ - { - "type": "Identifier", - "value": "a", - "range": [ - 0, - 1 - ], - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - { - "type": "Punctuator", - "value": "?.", - "range": [ - 1, - 3 - ], - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 3 - } - } - }, - { - "type": "Identifier", - "value": "b", - "range": [ - 3, - 4 - ], - "loc": { - "start": { - "line": 1, - "column": 3 - }, - "end": { - "line": 1, - "column": 4 - } - } - }, - { - "type": "Punctuator", - "value": ".", - "range": [ - 4, - 5 - ], - "loc": { - "start": { - "line": 1, - "column": 4 - }, - "end": { - "line": 1, - "column": 5 - } - } - }, - { - "type": "Identifier", - "value": "c", - "range": [ - 5, - 6 - ], - "loc": { - "start": { - "line": 1, - "column": 5 - }, - "end": { - "line": 1, - "column": 6 - } - } - }, - { - "type": "Identifier", - "value": "a", - "range": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "ChainExpression", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "a", + "range": [ 7, 8 - ], - "loc": { + ], + "loc": { "start": { - "line": 2, - "column": 0 + "line": 2, + "column": 0 }, "end": { - "line": 2, - "column": 1 + "line": 2, + "column": 1 } - } - }, - { - "type": "Punctuator", - "value": ".", - "range": [ - 8, - 9 - ], - "loc": { - "start": { - "line": 2, - "column": 1 - }, - "end": { - "line": 2, - "column": 2 - } - } - }, - { - "type": "Identifier", - "value": "b", - "range": [ + } + }, + "property": { + "type": "Identifier", + "name": "b", + "range": [ 9, 10 - ], - "loc": { + ], + "loc": { "start": { - "line": 2, - "column": 2 + "line": 2, + "column": 2 }, "end": { - "line": 2, - "column": 3 + "line": 2, + "column": 3 } - } - }, - { - "type": "Punctuator", - "value": "?.", + } + }, + "optional": false, "range": [ - 10, - 12 + 7, + 10 ], "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 5 - } + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } } - }, - { + }, + "property": { "type": "Identifier", - "value": "c", + "name": "c", "range": [ - 12, - 13 + 12, + 13 ], "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 6 - } + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + } + }, + "optional": true, + "range": [ + 7, + 13 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 } + } }, - { - "type": "Keyword", - "value": "new", - "range": [ - 14, - 17 - ], - "loc": { - "start": { + "range": [ + 7, + 13 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + } + }, + "range": [ + 7, + 13 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "NewExpression", + "callee": { + "type": "ChainExpression", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "a", + "range": [ + 19, + 20 + ], + "loc": { + "start": { "line": 3, - "column": 0 - }, - "end": { + "column": 5 + }, + "end": { "line": 3, - "column": 3 + "column": 6 + } } - } - }, - { - "type": "Identifier", - "value": "a", - "range": [ - 18, - 19 - ], - "loc": { - "start": { + }, + "property": { + "type": "Identifier", + "name": "b", + "range": [ + 22, + 23 + ], + "loc": { + "start": { "line": 3, - "column": 4 - }, - "end": { + "column": 8 + }, + "end": { "line": 3, - "column": 5 + "column": 9 + } } - } - }, - { - "type": "Punctuator", - "value": "?.", - "range": [ + }, + "optional": true, + "range": [ 19, - 21 - ], - "loc": { + 23 + ], + "loc": { "start": { - "line": 3, - "column": 5 + "line": 3, + "column": 5 }, "end": { - "line": 3, - "column": 7 + "line": 3, + "column": 9 } - } - }, - { - "type": "Identifier", - "value": "b", - "range": [ - 21, - 22 - ], - "loc": { + } + }, + "property": { + "type": "Identifier", + "name": "c", + "range": [ + 24, + 25 + ], + "loc": { "start": { - "line": 3, - "column": 7 + "line": 3, + "column": 10 }, "end": { - "line": 3, - "column": 8 + "line": 3, + "column": 11 } - } - }, - { - "type": "Punctuator", - "value": ".", + } + }, + "optional": false, "range": [ - 22, - 23 + 19, + 25 ], "loc": { - "start": { - "line": 3, + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "range": [ + 19, + 25 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "arguments": [], + "range": [ + 14, + 26 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + "range": [ + 14, + 26 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "NewExpression", + "callee": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "ChainExpression", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "a", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 6 + } + } + }, + "property": { + "type": "Identifier", + "name": "b", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 4, "column": 8 - }, - "end": { - "line": 3, + }, + "end": { + "line": 4, "column": 9 + } } - } - }, - { - "type": "Identifier", - "value": "c", - "range": [ - 23, - 24 - ], - "loc": { + }, + "optional": true, + "range": [ + 32, + 36 + ], + "loc": { "start": { - "line": 3, - "column": 9 + "line": 4, + "column": 5 }, "end": { - "line": 3, - "column": 10 + "line": 4, + "column": 9 } - } - }, - { - "type": "Keyword", - "value": "new", + } + }, "range": [ - 25, - 28 + 32, + 36 ], "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 4, - "column": 3 - } + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 9 + } } - }, - { + }, + "property": { "type": "Identifier", - "value": "a", + "name": "c", "range": [ - 29, - 30 + 38, + 39 ], "loc": { - "start": { - "line": 4, - "column": 4 - }, - "end": { - "line": 4, - "column": 5 - } + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + } } + }, + "optional": false, + "range": [ + 31, + 39 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 12 + } + } }, - { - "type": "Punctuator", - "value": ".", - "range": [ - 30, - 31 - ], - "loc": { - "start": { - "line": 4, + "arguments": [], + "range": [ + 27, + 39 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + "range": [ + 27, + 39 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "NewExpression", + "callee": { + "type": "ChainExpression", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "a", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 5, "column": 5 - }, - "end": { - "line": 4, + }, + "end": { + "line": 5, "column": 6 + } } - } - }, - { - "type": "Identifier", - "value": "b", - "range": [ - 31, - 32 - ], - "loc": { + }, + "property": { + "type": "Identifier", + "name": "b", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + } + } + }, + "optional": false, + "range": [ + 45, + 48 + ], + "loc": { "start": { - "line": 4, - "column": 6 + "line": 5, + "column": 5 }, "end": { - "line": 4, - "column": 7 + "line": 5, + "column": 8 } - } - }, - { - "type": "Punctuator", - "value": "?.", - "range": [ - 32, - 34 - ], - "loc": { + } + }, + "property": { + "type": "Identifier", + "name": "c", + "range": [ + 50, + 51 + ], + "loc": { "start": { - "line": 4, - "column": 7 + "line": 5, + "column": 10 }, "end": { - "line": 4, - "column": 9 + "line": 5, + "column": 11 } - } - }, - { - "type": "Identifier", - "value": "c", + } + }, + "optional": true, "range": [ - 34, - 35 + 45, + 51 ], "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 4, - "column": 10 - } + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 11 + } + } + }, + "range": [ + 45, + 51 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 11 } + } + }, + "arguments": [], + "range": [ + 40, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "range": [ + 40, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 12 + } + } + } + ], + "sourceType": "script", + "strict": false, + "tokens": [ + { + "type": "Identifier", + "value": "a", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "?.", + "range": [ + 1, + 3 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Identifier", + "value": "b", + "range": [ + 3, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 4, + 5 + ], + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "c", + "range": [ + 5, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 2 + } + } + }, + { + "type": "Identifier", + "value": "b", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "?.", + "range": [ + 10, + 12 + ], + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "c", + "range": [ + 12, + 13 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + } + }, + { + "type": "Keyword", + "value": "new", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": "?.", + "range": [ + 20, + 22 + ], + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "b", + "range": [ + 22, + 23 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "c", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + { + "type": "Keyword", + "value": "new", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": "?.", + "range": [ + 33, + 35 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + { + "type": "Identifier", + "value": "b", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 4, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "c", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + { + "type": "Keyword", + "value": "new", + "range": [ + 40, + 43 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 } - ] + } + }, + { + "type": "Identifier", + "value": "a", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "b", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "?.", + "range": [ + 48, + 50 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "c", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 12 + } + } + } + ], + "range": [ + 0, + 52 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 12 + } + } } \ No newline at end of file diff --git a/test/Esprima.Tests/Fixtures/fixtures-metadata.json b/test/Esprima.Tests/Fixtures/fixtures-metadata.json index 51cf7470..ad6a284a 100644 --- a/test/Esprima.Tests/Fixtures/fixtures-metadata.json +++ b/test/Esprima.Tests/Fixtures/fixtures-metadata.json @@ -378,8 +378,6 @@ "es2020/optional-chaining/invalid-optional-chaining-new-template-string.js", "es2020/optional-chaining/invalid-optional-chaining-template-string.js", "es2020/optional-chaining/optional-chaining-call.js", - "es2020/optional-chaining/optional-chaining-computed-property.js", - "es2020/optional-chaining/optional-chaining-static-property.js", "ES6/arrow-function/arrow-rest-forgetting-comma.js", "ES6/arrow-function/arrow-with-multiple-arg-and-rest.js", @@ -1715,5 +1713,12 @@ "ES6/identifier/module_await.js", "expression/primary/literal/regular-expression/migrated_0006.source.js" // false negative ] + }, + { + "flags": [ "IncludesLocation", "IncludesRange", "IncludesTokens" ], + "files": [ + "es2020/optional-chaining/optional-chaining-computed-property.js", + "es2020/optional-chaining/optional-chaining-static-property.js" + ] } ]