From 5b40a85a50676bb8692d0287cef10cde199c1ab6 Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 3 Feb 2021 02:14:15 +0100 Subject: [PATCH 1/3] test(typescript-estree): add tests for unescape jsx string literals --- .../unicodeCodePointEscapes/ignored.src.js | 9 + .../jsx/escape-patterns-ignored.src.js | 9 + .../jsx/escape-patterns-unknown.src.js | 6 + .../fixtures/jsx/escape-patterns-valid.src.js | 3 + .../fixtures/jsx/escape-patterns.src.js | 1 - .../fixtures/jsx/escape-patters-multi.src.js | 1 + .../jsx/unknown-escape-pattern.src.js | 1 - .../semantic-diagnostics-enabled.test.ts.snap | 12 +- .../ignored.src.js.shot | 1696 ++++++++++++++++ ...ot => escape-patterns-ignored.src.js.shot} | 667 ++++--- .../jsx/escape-patterns-unknown.src.js.shot | 1716 +++++++++++++++++ .../jsx/escape-patterns-valid.src.js.shot | 540 ++++++ ....shot => escape-patters-multi.src.js.shot} | 222 ++- 13 files changed, 4523 insertions(+), 360 deletions(-) create mode 100644 packages/shared-fixtures/fixtures/javascript/unicodeCodePointEscapes/ignored.src.js create mode 100644 packages/shared-fixtures/fixtures/jsx/escape-patterns-ignored.src.js create mode 100644 packages/shared-fixtures/fixtures/jsx/escape-patterns-unknown.src.js create mode 100644 packages/shared-fixtures/fixtures/jsx/escape-patterns-valid.src.js delete mode 100644 packages/shared-fixtures/fixtures/jsx/escape-patterns.src.js create mode 100644 packages/shared-fixtures/fixtures/jsx/escape-patters-multi.src.js delete mode 100644 packages/shared-fixtures/fixtures/jsx/unknown-escape-pattern.src.js create mode 100644 packages/typescript-estree/tests/snapshots/javascript/unicodeCodePointEscapes/ignored.src.js.shot rename packages/typescript-estree/tests/snapshots/jsx/{escape-patterns.src.js.shot => escape-patterns-ignored.src.js.shot} (67%) create mode 100644 packages/typescript-estree/tests/snapshots/jsx/escape-patterns-unknown.src.js.shot create mode 100644 packages/typescript-estree/tests/snapshots/jsx/escape-patterns-valid.src.js.shot rename packages/typescript-estree/tests/snapshots/jsx/{unknown-escape-pattern.src.js.shot => escape-patters-multi.src.js.shot} (57%) diff --git a/packages/shared-fixtures/fixtures/javascript/unicodeCodePointEscapes/ignored.src.js b/packages/shared-fixtures/fixtures/javascript/unicodeCodePointEscapes/ignored.src.js new file mode 100644 index 00000000000..663bc1e5ec2 --- /dev/null +++ b/packages/shared-fixtures/fixtures/javascript/unicodeCodePointEscapes/ignored.src.js @@ -0,0 +1,9 @@ +const b = ' '; +let c = ' '; +let d = '&'; +const e = { + f: 'id=1&group=2', + g(h = '�') {}, + i: (j = '�') => {}, +}; +e.i('&#x;'); diff --git a/packages/shared-fixtures/fixtures/jsx/escape-patterns-ignored.src.js b/packages/shared-fixtures/fixtures/jsx/escape-patterns-ignored.src.js new file mode 100644 index 00000000000..d22bc77844e --- /dev/null +++ b/packages/shared-fixtures/fixtures/jsx/escape-patterns-ignored.src.js @@ -0,0 +1,9 @@ +; diff --git a/packages/shared-fixtures/fixtures/jsx/escape-patterns-unknown.src.js b/packages/shared-fixtures/fixtures/jsx/escape-patterns-unknown.src.js new file mode 100644 index 00000000000..2d8393ff0a7 --- /dev/null +++ b/packages/shared-fixtures/fixtures/jsx/escape-patterns-unknown.src.js @@ -0,0 +1,6 @@ +; +; +; +&abc;; +¬anentity;; +&#x;; diff --git a/packages/shared-fixtures/fixtures/jsx/escape-patterns-valid.src.js b/packages/shared-fixtures/fixtures/jsx/escape-patterns-valid.src.js new file mode 100644 index 00000000000..d6be1e35396 --- /dev/null +++ b/packages/shared-fixtures/fixtures/jsx/escape-patterns-valid.src.js @@ -0,0 +1,3 @@ + +   +; diff --git a/packages/shared-fixtures/fixtures/jsx/escape-patterns.src.js b/packages/shared-fixtures/fixtures/jsx/escape-patterns.src.js deleted file mode 100644 index b218700ab0f..00000000000 --- a/packages/shared-fixtures/fixtures/jsx/escape-patterns.src.js +++ /dev/null @@ -1 +0,0 @@ -; \ No newline at end of file diff --git a/packages/shared-fixtures/fixtures/jsx/escape-patters-multi.src.js b/packages/shared-fixtures/fixtures/jsx/escape-patters-multi.src.js new file mode 100644 index 00000000000..15eb28c92ec --- /dev/null +++ b/packages/shared-fixtures/fixtures/jsx/escape-patters-multi.src.js @@ -0,0 +1 @@ +  test; diff --git a/packages/shared-fixtures/fixtures/jsx/unknown-escape-pattern.src.js b/packages/shared-fixtures/fixtures/jsx/unknown-escape-pattern.src.js deleted file mode 100644 index d300d95f45c..00000000000 --- a/packages/shared-fixtures/fixtures/jsx/unknown-escape-pattern.src.js +++ /dev/null @@ -1 +0,0 @@ -; \ No newline at end of file diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap index 61608bd3595..109716148c4 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap @@ -1285,6 +1285,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/unicodeCodePointEscapes/complex-string-literal.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/unicodeCodePointEscapes/ignored.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/unicodeCodePointEscapes/invalid-empty-escape.src 1`] = ` Object { "column": 4, @@ -1324,7 +1326,13 @@ Object { exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/empty-placeholder.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/escape-patterns.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/escape-patterns-ignored.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/escape-patterns-unknown.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/escape-patterns-valid.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/escape-patters-multi.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-attribute.src 1`] = ` Object { @@ -1639,8 +1647,6 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/trailing-spread-operator-attribute.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/unknown-escape-pattern.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; - exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx-useJSXTextNode/self-closing-tag-inside-tag.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx-useJSXTextNode/test-content.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/snapshots/javascript/unicodeCodePointEscapes/ignored.src.js.shot b/packages/typescript-estree/tests/snapshots/javascript/unicodeCodePointEscapes/ignored.src.js.shot new file mode 100644 index 00000000000..4d8236d2a3c --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/javascript/unicodeCodePointEscapes/ignored.src.js.shot @@ -0,0 +1,1696 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`javascript unicodeCodePointEscapes ignored.src 1`] = ` +Object { + "body": Array [ + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "b", + "range": Array [ + 6, + 7, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 13, + ], + "raw": "' '", + "type": "Literal", + "value": " ", + }, + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 13, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 14, + ], + "type": "VariableDeclaration", + }, + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "name": "c", + "range": Array [ + 19, + 20, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 23, + 26, + ], + "raw": "' '", + "type": "Literal", + "value": " ", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 19, + 26, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "let", + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 15, + 27, + ], + "type": "VariableDeclaration", + }, + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "name": "d", + "range": Array [ + 32, + 33, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 36, + 43, + ], + "raw": "'&'", + "type": "Literal", + "value": "&", + }, + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 32, + 43, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "let", + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 28, + 44, + ], + "type": "VariableDeclaration", + }, + Object { + "declarations": Array [ + Object { + "id": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "name": "e", + "range": Array [ + 51, + 52, + ], + "type": "Identifier", + }, + "init": Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "properties": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "name": "f", + "range": Array [ + 59, + 60, + ], + "type": "Identifier", + }, + "kind": "init", + "loc": Object { + "end": Object { + "column": 19, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "method": false, + "range": Array [ + 59, + 76, + ], + "shorthand": false, + "type": "Property", + "value": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 5, + }, + "start": Object { + "column": 5, + "line": 5, + }, + }, + "range": Array [ + 62, + 76, + ], + "raw": "'id=1&group=2'", + "type": "Literal", + "value": "id=1&group=2", + }, + }, + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "name": "g", + "range": Array [ + 80, + 81, + ], + "type": "Identifier", + }, + "kind": "init", + "loc": Object { + "end": Object { + "column": 25, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "method": true, + "range": Array [ + 80, + 103, + ], + "shorthand": false, + "type": "Property", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 25, + "line": 6, + }, + "start": Object { + "column": 23, + "line": 6, + }, + }, + "range": Array [ + 101, + 103, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 25, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, + }, + "params": Array [ + Object { + "left": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "name": "h", + "range": Array [ + 82, + 83, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 21, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 82, + 99, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 6, + }, + "start": Object { + "column": 8, + "line": 6, + }, + }, + "range": Array [ + 86, + 99, + ], + "raw": "'�'", + "type": "Literal", + "value": "�", + }, + "type": "AssignmentPattern", + }, + ], + "range": Array [ + 81, + 103, + ], + "type": "FunctionExpression", + }, + }, + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 7, + }, + }, + "name": "i", + "range": Array [ + 107, + 108, + ], + "type": "Identifier", + }, + "kind": "init", + "loc": Object { + "end": Object { + "column": 30, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 7, + }, + }, + "method": false, + "range": Array [ + 107, + 135, + ], + "shorthand": false, + "type": "Property", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 30, + "line": 7, + }, + "start": Object { + "column": 28, + "line": 7, + }, + }, + "range": Array [ + 133, + 135, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 30, + "line": 7, + }, + "start": Object { + "column": 5, + "line": 7, + }, + }, + "params": Array [ + Object { + "left": Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 7, + }, + "start": Object { + "column": 6, + "line": 7, + }, + }, + "name": "j", + "range": Array [ + 111, + 112, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 23, + "line": 7, + }, + "start": Object { + "column": 6, + "line": 7, + }, + }, + "range": Array [ + 111, + 128, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 7, + }, + "start": Object { + "column": 10, + "line": 7, + }, + }, + "range": Array [ + 115, + 128, + ], + "raw": "'�'", + "type": "Literal", + "value": "�", + }, + "type": "AssignmentPattern", + }, + ], + "range": Array [ + 110, + 135, + ], + "type": "ArrowFunctionExpression", + }, + }, + ], + "range": Array [ + 55, + 138, + ], + "type": "ObjectExpression", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "range": Array [ + 51, + 138, + ], + "type": "VariableDeclarator", + }, + ], + "kind": "const", + "loc": Object { + "end": Object { + "column": 2, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + "range": Array [ + 45, + 139, + ], + "type": "VariableDeclaration", + }, + Object { + "expression": Object { + "arguments": Array [ + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 9, + }, + "start": Object { + "column": 4, + "line": 9, + }, + }, + "range": Array [ + 144, + 150, + ], + "raw": "'&#x;'", + "type": "Literal", + "value": "&#x;", + }, + ], + "callee": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 3, + "line": 9, + }, + "start": Object { + "column": 0, + "line": 9, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 9, + }, + "start": Object { + "column": 0, + "line": 9, + }, + }, + "name": "e", + "range": Array [ + 140, + 141, + ], + "type": "Identifier", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 9, + }, + "start": Object { + "column": 2, + "line": 9, + }, + }, + "name": "i", + "range": Array [ + 142, + 143, + ], + "type": "Identifier", + }, + "range": Array [ + 140, + 143, + ], + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 9, + }, + "start": Object { + "column": 0, + "line": 9, + }, + }, + "optional": false, + "range": Array [ + 140, + 151, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 12, + "line": 9, + }, + "start": Object { + "column": 0, + "line": 9, + }, + }, + "range": Array [ + 140, + 152, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 10, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 153, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Identifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 9, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 13, + ], + "type": "String", + "value": "' '", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 15, + 18, + ], + "type": "Keyword", + "value": "let", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 19, + 20, + ], + "type": "Identifier", + "value": "c", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 23, + 26, + ], + "type": "String", + "value": "' '", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 28, + 31, + ], + "type": "Keyword", + "value": "let", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 32, + 33, + ], + "type": "Identifier", + "value": "d", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "range": Array [ + 34, + 35, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 36, + 43, + ], + "type": "String", + "value": "'&'", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 43, + 44, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + "range": Array [ + 45, + 50, + ], + "type": "Keyword", + "value": "const", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 4, + }, + "start": Object { + "column": 6, + "line": 4, + }, + }, + "range": Array [ + 51, + 52, + ], + "type": "Identifier", + "value": "e", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "range": Array [ + 53, + 54, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "range": Array [ + 55, + 56, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "range": Array [ + 59, + 60, + ], + "type": "Identifier", + "value": "f", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, + }, + }, + "range": Array [ + 60, + 61, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 5, + }, + "start": Object { + "column": 5, + "line": 5, + }, + }, + "range": Array [ + 62, + 76, + ], + "type": "String", + "value": "'id=1&group=2'", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 5, + }, + "start": Object { + "column": 19, + "line": 5, + }, + }, + "range": Array [ + 76, + 77, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "range": Array [ + 80, + 81, + ], + "type": "Identifier", + "value": "g", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, + }, + "range": Array [ + 81, + 82, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 82, + 83, + ], + "type": "Identifier", + "value": "h", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 6, + }, + "start": Object { + "column": 6, + "line": 6, + }, + }, + "range": Array [ + 84, + 85, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 6, + }, + "start": Object { + "column": 8, + "line": 6, + }, + }, + "range": Array [ + 86, + 99, + ], + "type": "String", + "value": "'�'", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 6, + }, + "start": Object { + "column": 21, + "line": 6, + }, + }, + "range": Array [ + 99, + 100, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 6, + }, + "start": Object { + "column": 23, + "line": 6, + }, + }, + "range": Array [ + 101, + 102, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 6, + }, + "start": Object { + "column": 24, + "line": 6, + }, + }, + "range": Array [ + 102, + 103, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 6, + }, + "start": Object { + "column": 25, + "line": 6, + }, + }, + "range": Array [ + 103, + 104, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 7, + }, + }, + "range": Array [ + 107, + 108, + ], + "type": "Identifier", + "value": "i", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 7, + }, + "start": Object { + "column": 3, + "line": 7, + }, + }, + "range": Array [ + 108, + 109, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 7, + }, + "start": Object { + "column": 5, + "line": 7, + }, + }, + "range": Array [ + 110, + 111, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 7, + }, + "start": Object { + "column": 6, + "line": 7, + }, + }, + "range": Array [ + 111, + 112, + ], + "type": "Identifier", + "value": "j", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 7, + }, + "start": Object { + "column": 8, + "line": 7, + }, + }, + "range": Array [ + 113, + 114, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 7, + }, + "start": Object { + "column": 10, + "line": 7, + }, + }, + "range": Array [ + 115, + 128, + ], + "type": "String", + "value": "'�'", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 7, + }, + "start": Object { + "column": 23, + "line": 7, + }, + }, + "range": Array [ + 128, + 129, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 7, + }, + "start": Object { + "column": 25, + "line": 7, + }, + }, + "range": Array [ + 130, + 132, + ], + "type": "Punctuator", + "value": "=>", + }, + Object { + "loc": Object { + "end": Object { + "column": 29, + "line": 7, + }, + "start": Object { + "column": 28, + "line": 7, + }, + }, + "range": Array [ + 133, + 134, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 30, + "line": 7, + }, + "start": Object { + "column": 29, + "line": 7, + }, + }, + "range": Array [ + 134, + 135, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 31, + "line": 7, + }, + "start": Object { + "column": 30, + "line": 7, + }, + }, + "range": Array [ + 135, + 136, + ], + "type": "Punctuator", + "value": ",", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 8, + }, + }, + "range": Array [ + 137, + 138, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 8, + }, + "start": Object { + "column": 1, + "line": 8, + }, + }, + "range": Array [ + 138, + 139, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 9, + }, + "start": Object { + "column": 0, + "line": 9, + }, + }, + "range": Array [ + 140, + 141, + ], + "type": "Identifier", + "value": "e", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 9, + }, + "start": Object { + "column": 1, + "line": 9, + }, + }, + "range": Array [ + 141, + 142, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 9, + }, + "start": Object { + "column": 2, + "line": 9, + }, + }, + "range": Array [ + 142, + 143, + ], + "type": "Identifier", + "value": "i", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 9, + }, + "start": Object { + "column": 3, + "line": 9, + }, + }, + "range": Array [ + 143, + 144, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 9, + }, + "start": Object { + "column": 4, + "line": 9, + }, + }, + "range": Array [ + 144, + 150, + ], + "type": "String", + "value": "'&#x;'", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 9, + }, + "start": Object { + "column": 10, + "line": 9, + }, + }, + "range": Array [ + 150, + 151, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 9, + }, + "start": Object { + "column": 11, + "line": 9, + }, + }, + "range": Array [ + 151, + 152, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tests/snapshots/jsx/escape-patterns.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-ignored.src.js.shot similarity index 67% rename from packages/typescript-estree/tests/snapshots/jsx/escape-patterns.src.js.shot rename to packages/typescript-estree/tests/snapshots/jsx/escape-patterns-ignored.src.js.shot index 72c7e238c77..ec4eb166c18 100644 --- a/packages/typescript-estree/tests/snapshots/jsx/escape-patterns.src.js.shot +++ b/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-ignored.src.js.shot @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`jsx escape-patterns.src 1`] = ` +exports[`jsx escape-patterns-ignored.src 1`] = ` Object { "body": Array [ Object { @@ -9,8 +9,8 @@ Object { "closingElement": null, "loc": Object { "end": Object { - "column": 83, - "line": 1, + "column": 2, + "line": 9, }, "start": Object { "column": 0, @@ -22,70 +22,70 @@ Object { Object { "loc": Object { "end": Object { - "column": 10, - "line": 1, + "column": 9, + "line": 2, }, "start": Object { - "column": 3, - "line": 1, + "column": 2, + "line": 2, }, }, "name": Object { "loc": Object { "end": Object { - "column": 4, - "line": 1, + "column": 3, + "line": 2, }, "start": Object { - "column": 3, - "line": 1, + "column": 2, + "line": 2, }, }, "name": "b", "range": Array [ - 3, - 4, + 5, + 6, ], "type": "JSXIdentifier", }, "range": Array [ - 3, - 10, + 5, + 12, ], "type": "JSXAttribute", "value": Object { "expression": Object { "loc": Object { "end": Object { - "column": 9, - "line": 1, + "column": 8, + "line": 2, }, "start": Object { - "column": 6, - "line": 1, + "column": 5, + "line": 2, }, }, "range": Array [ - 6, - 9, + 8, + 11, ], - "raw": "\\" \\"", + "raw": "' '", "type": "Literal", "value": " ", }, "loc": Object { "end": Object { - "column": 10, - "line": 1, + "column": 9, + "line": 2, }, "start": Object { - "column": 5, - "line": 1, + "column": 4, + "line": 2, }, }, "range": Array [ - 5, - 10, + 7, + 12, ], "type": "JSXExpressionContainer", }, @@ -93,51 +93,51 @@ Object { Object { "loc": Object { "end": Object { - "column": 16, - "line": 1, + "column": 7, + "line": 3, }, "start": Object { - "column": 11, - "line": 1, + "column": 2, + "line": 3, }, }, "name": Object { "loc": Object { "end": Object { - "column": 12, - "line": 1, + "column": 3, + "line": 3, }, "start": Object { - "column": 11, - "line": 1, + "column": 2, + "line": 3, }, }, "name": "c", "range": Array [ - 11, - 12, + 15, + 16, ], "type": "JSXIdentifier", }, "range": Array [ - 11, - 16, + 15, + 20, ], "type": "JSXAttribute", "value": Object { "loc": Object { "end": Object { - "column": 16, - "line": 1, + "column": 7, + "line": 3, }, "start": Object { - "column": 13, - "line": 1, + "column": 4, + "line": 3, }, }, "range": Array [ - 13, - 16, + 17, + 20, ], "raw": "\\" \\"", "type": "Literal", @@ -147,105 +147,122 @@ Object { Object { "loc": Object { "end": Object { - "column": 26, - "line": 1, + "column": 13, + "line": 4, }, "start": Object { - "column": 17, - "line": 1, + "column": 2, + "line": 4, }, }, "name": Object { "loc": Object { "end": Object { - "column": 18, - "line": 1, + "column": 3, + "line": 4, }, "start": Object { - "column": 17, - "line": 1, + "column": 2, + "line": 4, }, }, "name": "d", "range": Array [ - 17, - 18, + 23, + 24, ], "type": "JSXIdentifier", }, "range": Array [ - 17, - 26, + 23, + 34, ], "type": "JSXAttribute", "value": Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 4, + }, + "start": Object { + "column": 5, + "line": 4, + }, + }, + "range": Array [ + 26, + 33, + ], + "raw": "'&'", + "type": "Literal", + "value": "&", + }, "loc": Object { "end": Object { - "column": 26, - "line": 1, + "column": 13, + "line": 4, }, "start": Object { - "column": 19, - "line": 1, + "column": 4, + "line": 4, }, }, "range": Array [ - 19, - 26, + 25, + 34, ], - "raw": "\\"&\\"", - "type": "Literal", - "value": "&", + "type": "JSXExpressionContainer", }, }, Object { "loc": Object { "end": Object { - "column": 43, - "line": 1, + "column": 18, + "line": 5, }, "start": Object { - "column": 27, - "line": 1, + "column": 2, + "line": 5, }, }, "name": Object { "loc": Object { "end": Object { - "column": 28, - "line": 1, + "column": 3, + "line": 5, }, "start": Object { - "column": 27, - "line": 1, + "column": 2, + "line": 5, }, }, "name": "e", "range": Array [ - 27, - 28, + 37, + 38, ], "type": "JSXIdentifier", }, "range": Array [ - 27, - 43, + 37, + 53, ], "type": "JSXAttribute", "value": Object { "loc": Object { "end": Object { - "column": 43, - "line": 1, + "column": 18, + "line": 5, }, "start": Object { - "column": 29, - "line": 1, + "column": 4, + "line": 5, }, }, "range": Array [ - 29, - 43, + 39, + 53, ], "raw": "\\"id=1&group=2\\"", "type": "Literal", @@ -255,51 +272,51 @@ Object { Object { "loc": Object { "end": Object { - "column": 59, - "line": 1, + "column": 17, + "line": 6, }, "start": Object { - "column": 44, - "line": 1, + "column": 2, + "line": 6, }, }, "name": Object { "loc": Object { "end": Object { - "column": 45, - "line": 1, + "column": 3, + "line": 6, }, "start": Object { - "column": 44, - "line": 1, + "column": 2, + "line": 6, }, }, "name": "f", "range": Array [ - 44, - 45, + 56, + 57, ], "type": "JSXIdentifier", }, "range": Array [ - 44, - 59, + 56, + 71, ], "type": "JSXAttribute", "value": Object { "loc": Object { "end": Object { - "column": 59, - "line": 1, + "column": 17, + "line": 6, }, "start": Object { - "column": 46, - "line": 1, + "column": 4, + "line": 6, }, }, "range": Array [ - 46, - 59, + 58, + 71, ], "raw": "\\"�\\"", "type": "Literal", @@ -309,51 +326,51 @@ Object { Object { "loc": Object { "end": Object { - "column": 71, - "line": 1, + "column": 13, + "line": 7, }, "start": Object { - "column": 60, - "line": 1, + "column": 2, + "line": 7, }, }, "name": Object { "loc": Object { "end": Object { - "column": 61, - "line": 1, + "column": 3, + "line": 7, }, "start": Object { - "column": 60, - "line": 1, + "column": 2, + "line": 7, }, }, "name": "g", "range": Array [ - 60, - 61, + 74, + 75, ], "type": "JSXIdentifier", }, "range": Array [ - 60, - 71, + 74, + 85, ], "type": "JSXAttribute", "value": Object { "loc": Object { "end": Object { - "column": 71, - "line": 1, + "column": 13, + "line": 7, }, "start": Object { - "column": 62, - "line": 1, + "column": 4, + "line": 7, }, }, "range": Array [ - 62, - 71, + 76, + 85, ], "raw": "\\"{*;\\"", "type": "Literal", @@ -363,51 +380,51 @@ Object { Object { "loc": Object { "end": Object { - "column": 80, - "line": 1, + "column": 10, + "line": 8, }, "start": Object { - "column": 72, - "line": 1, + "column": 2, + "line": 8, }, }, "name": Object { "loc": Object { "end": Object { - "column": 73, - "line": 1, + "column": 3, + "line": 8, }, "start": Object { - "column": 72, - "line": 1, + "column": 2, + "line": 8, }, }, "name": "h", "range": Array [ - 72, - 73, + 88, + 89, ], "type": "JSXIdentifier", }, "range": Array [ - 72, - 80, + 88, + 96, ], "type": "JSXAttribute", "value": Object { "loc": Object { "end": Object { - "column": 80, - "line": 1, + "column": 10, + "line": 8, }, "start": Object { - "column": 74, - "line": 1, + "column": 4, + "line": 8, }, }, "range": Array [ - 74, - 80, + 90, + 96, ], "raw": "\\"&#x;\\"", "type": "Literal", @@ -417,8 +434,8 @@ Object { ], "loc": Object { "end": Object { - "column": 83, - "line": 1, + "column": 2, + "line": 9, }, "start": Object { "column": 0, @@ -445,7 +462,7 @@ Object { }, "range": Array [ 0, - 83, + 99, ], "selfClosing": true, "type": "JSXOpeningElement", @@ -453,14 +470,14 @@ Object { }, "range": Array [ 0, - 83, + 99, ], "type": "JSXElement", }, "loc": Object { "end": Object { - "column": 84, - "line": 1, + "column": 3, + "line": 9, }, "start": Object { "column": 0, @@ -469,7 +486,7 @@ Object { }, "range": Array [ 0, - 84, + 100, ], "type": "ExpressionStatement", }, @@ -477,8 +494,8 @@ Object { "comments": Array [], "loc": Object { "end": Object { - "column": 84, - "line": 1, + "column": 0, + "line": 10, }, "start": Object { "column": 0, @@ -487,7 +504,7 @@ Object { }, "range": Array [ 0, - 84, + 101, ], "sourceType": "script", "tokens": Array [ @@ -530,17 +547,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 4, - "line": 1, + "column": 3, + "line": 2, }, "start": Object { - "column": 3, - "line": 1, + "column": 2, + "line": 2, }, }, "range": Array [ - 3, - 4, + 5, + 6, ], "type": "JSXIdentifier", "value": "b", @@ -548,17 +565,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 5, - "line": 1, + "column": 4, + "line": 2, }, "start": Object { - "column": 4, - "line": 1, + "column": 3, + "line": 2, }, }, "range": Array [ - 4, - 5, + 6, + 7, ], "type": "Punctuator", "value": "=", @@ -566,17 +583,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 6, - "line": 1, + "column": 5, + "line": 2, }, "start": Object { - "column": 5, - "line": 1, + "column": 4, + "line": 2, }, }, "range": Array [ - 5, - 6, + 7, + 8, ], "type": "Punctuator", "value": "{", @@ -584,35 +601,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 9, - "line": 1, + "column": 8, + "line": 2, }, "start": Object { - "column": 6, - "line": 1, + "column": 5, + "line": 2, }, }, "range": Array [ - 6, - 9, + 8, + 11, ], "type": "String", - "value": "\\" \\"", + "value": "' '", }, Object { "loc": Object { "end": Object { - "column": 10, - "line": 1, + "column": 9, + "line": 2, }, "start": Object { - "column": 9, - "line": 1, + "column": 8, + "line": 2, }, }, "range": Array [ - 9, - 10, + 11, + 12, ], "type": "Punctuator", "value": "}", @@ -620,17 +637,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 12, - "line": 1, + "column": 3, + "line": 3, }, "start": Object { - "column": 11, - "line": 1, + "column": 2, + "line": 3, }, }, "range": Array [ - 11, - 12, + 15, + 16, ], "type": "JSXIdentifier", "value": "c", @@ -638,17 +655,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 13, - "line": 1, + "column": 4, + "line": 3, }, "start": Object { - "column": 12, - "line": 1, + "column": 3, + "line": 3, }, }, "range": Array [ - 12, - 13, + 16, + 17, ], "type": "Punctuator", "value": "=", @@ -656,17 +673,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 16, - "line": 1, + "column": 7, + "line": 3, }, "start": Object { - "column": 13, - "line": 1, + "column": 4, + "line": 3, }, }, "range": Array [ - 13, - 16, + 17, + 20, ], "type": "JSXText", "value": "\\" \\"", @@ -674,17 +691,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 18, - "line": 1, + "column": 3, + "line": 4, }, "start": Object { - "column": 17, - "line": 1, + "column": 2, + "line": 4, }, }, "range": Array [ - 17, - 18, + 23, + 24, ], "type": "JSXIdentifier", "value": "d", @@ -692,17 +709,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 19, - "line": 1, + "column": 4, + "line": 4, }, "start": Object { - "column": 18, - "line": 1, + "column": 3, + "line": 4, }, }, "range": Array [ - 18, - 19, + 24, + 25, ], "type": "Punctuator", "value": "=", @@ -710,35 +727,71 @@ Object { Object { "loc": Object { "end": Object { - "column": 26, - "line": 1, + "column": 5, + "line": 4, }, "start": Object { - "column": 19, - "line": 1, + "column": 4, + "line": 4, }, }, "range": Array [ - 19, + 25, 26, ], - "type": "JSXText", - "value": "\\"&\\"", + "type": "Punctuator", + "value": "{", }, Object { "loc": Object { "end": Object { - "column": 28, - "line": 1, + "column": 12, + "line": 4, }, "start": Object { - "column": 27, - "line": 1, + "column": 5, + "line": 4, }, }, "range": Array [ - 27, - 28, + 26, + 33, + ], + "type": "String", + "value": "'&'", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 4, + }, + "start": Object { + "column": 12, + "line": 4, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "range": Array [ + 37, + 38, ], "type": "JSXIdentifier", "value": "e", @@ -746,17 +799,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 29, - "line": 1, + "column": 4, + "line": 5, }, "start": Object { - "column": 28, - "line": 1, + "column": 3, + "line": 5, }, }, "range": Array [ - 28, - 29, + 38, + 39, ], "type": "Punctuator", "value": "=", @@ -764,17 +817,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 43, - "line": 1, + "column": 18, + "line": 5, }, "start": Object { - "column": 29, - "line": 1, + "column": 4, + "line": 5, }, }, "range": Array [ - 29, - 43, + 39, + 53, ], "type": "JSXText", "value": "\\"id=1&group=2\\"", @@ -782,17 +835,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 45, - "line": 1, + "column": 3, + "line": 6, }, "start": Object { - "column": 44, - "line": 1, + "column": 2, + "line": 6, }, }, "range": Array [ - 44, - 45, + 56, + 57, ], "type": "JSXIdentifier", "value": "f", @@ -800,17 +853,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 46, - "line": 1, + "column": 4, + "line": 6, }, "start": Object { - "column": 45, - "line": 1, + "column": 3, + "line": 6, }, }, "range": Array [ - 45, - 46, + 57, + 58, ], "type": "Punctuator", "value": "=", @@ -818,17 +871,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 59, - "line": 1, + "column": 17, + "line": 6, }, "start": Object { - "column": 46, - "line": 1, + "column": 4, + "line": 6, }, }, "range": Array [ - 46, - 59, + 58, + 71, ], "type": "JSXText", "value": "\\"�\\"", @@ -836,17 +889,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 61, - "line": 1, + "column": 3, + "line": 7, }, "start": Object { - "column": 60, - "line": 1, + "column": 2, + "line": 7, }, }, "range": Array [ - 60, - 61, + 74, + 75, ], "type": "JSXIdentifier", "value": "g", @@ -854,17 +907,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 62, - "line": 1, + "column": 4, + "line": 7, }, "start": Object { - "column": 61, - "line": 1, + "column": 3, + "line": 7, }, }, "range": Array [ - 61, - 62, + 75, + 76, ], "type": "Punctuator", "value": "=", @@ -872,17 +925,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 71, - "line": 1, + "column": 13, + "line": 7, }, "start": Object { - "column": 62, - "line": 1, + "column": 4, + "line": 7, }, }, "range": Array [ - 62, - 71, + 76, + 85, ], "type": "JSXText", "value": "\\"{*;\\"", @@ -890,17 +943,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 73, - "line": 1, + "column": 3, + "line": 8, }, "start": Object { - "column": 72, - "line": 1, + "column": 2, + "line": 8, }, }, "range": Array [ - 72, - 73, + 88, + 89, ], "type": "JSXIdentifier", "value": "h", @@ -908,17 +961,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 74, - "line": 1, + "column": 4, + "line": 8, }, "start": Object { - "column": 73, - "line": 1, + "column": 3, + "line": 8, }, }, "range": Array [ - 73, - 74, + 89, + 90, ], "type": "Punctuator", "value": "=", @@ -926,17 +979,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 80, - "line": 1, + "column": 10, + "line": 8, }, "start": Object { - "column": 74, - "line": 1, + "column": 4, + "line": 8, }, }, "range": Array [ - 74, - 80, + 90, + 96, ], "type": "JSXText", "value": "\\"&#x;\\"", @@ -944,17 +997,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 82, - "line": 1, + "column": 1, + "line": 9, }, "start": Object { - "column": 81, - "line": 1, + "column": 0, + "line": 9, }, }, "range": Array [ - 81, - 82, + 97, + 98, ], "type": "Punctuator", "value": "/", @@ -962,17 +1015,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 83, - "line": 1, + "column": 2, + "line": 9, }, "start": Object { - "column": 82, - "line": 1, + "column": 1, + "line": 9, }, }, "range": Array [ - 82, - 83, + 98, + 99, ], "type": "Punctuator", "value": ">", @@ -980,17 +1033,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 84, - "line": 1, + "column": 3, + "line": 9, }, "start": Object { - "column": 83, - "line": 1, + "column": 2, + "line": 9, }, }, "range": Array [ - 83, - 84, + 99, + 100, ], "type": "Punctuator", "value": ";", diff --git a/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-unknown.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-unknown.src.js.shot new file mode 100644 index 00000000000..25cd76ed83d --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-unknown.src.js.shot @@ -0,0 +1,1716 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`jsx escape-patterns-unknown.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "children": Array [], + "closingElement": null, + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "openingElement": Object { + "attributes": Array [ + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "name": "b", + "range": Array [ + 3, + 4, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 3, + 20, + ], + "type": "JSXAttribute", + "value": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 20, + ], + "raw": "\\"¬anentity;\\"", + "type": "Literal", + "value": "¬anentity;", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "name": "a", + "range": Array [ + 1, + 2, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 0, + 23, + ], + "selfClosing": true, + "type": "JSXOpeningElement", + "typeParameters": undefined, + }, + "range": Array [ + 0, + 23, + ], + "type": "JSXElement", + }, + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 24, + ], + "type": "ExpressionStatement", + }, + Object { + "expression": Object { + "children": Array [], + "closingElement": null, + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "openingElement": Object { + "attributes": Array [ + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "name": "b", + "range": Array [ + 28, + 29, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 28, + 36, + ], + "type": "JSXAttribute", + "value": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 5, + "line": 2, + }, + }, + "range": Array [ + 30, + 36, + ], + "raw": "\\"&##;\\"", + "type": "Literal", + "value": "&##;", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 2, + }, + "start": Object { + "column": 1, + "line": 2, + }, + }, + "name": "b", + "range": Array [ + 26, + 27, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 25, + 39, + ], + "selfClosing": true, + "type": "JSXOpeningElement", + "typeParameters": undefined, + }, + "range": Array [ + 25, + 39, + ], + "type": "JSXElement", + }, + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 25, + 40, + ], + "type": "ExpressionStatement", + }, + Object { + "expression": Object { + "children": Array [], + "closingElement": null, + "loc": Object { + "end": Object { + "column": 19, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "openingElement": Object { + "attributes": Array [ + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, + }, + "name": "b", + "range": Array [ + 44, + 45, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 44, + 57, + ], + "type": "JSXAttribute", + "value": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 5, + "line": 3, + }, + }, + "range": Array [ + 46, + 57, + ], + "raw": "\\"&x01FZZZ;\\"", + "type": "Literal", + "value": "&x01FZZZ;", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 19, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 3, + }, + "start": Object { + "column": 1, + "line": 3, + }, + }, + "name": "b", + "range": Array [ + 42, + 43, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 41, + 60, + ], + "selfClosing": true, + "type": "JSXOpeningElement", + "typeParameters": undefined, + }, + "range": Array [ + 41, + 60, + ], + "type": "JSXElement", + }, + "loc": Object { + "end": Object { + "column": 20, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 41, + 61, + ], + "type": "ExpressionStatement", + }, + Object { + "expression": Object { + "children": Array [ + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, + }, + "range": Array [ + 65, + 70, + ], + "raw": "&abc;", + "type": "Literal", + "value": "&abc;", + }, + ], + "closingElement": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "name": "c", + "range": Array [ + 72, + 73, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 70, + 74, + ], + "type": "JSXClosingElement", + }, + "loc": Object { + "end": Object { + "column": 12, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + "openingElement": Object { + "attributes": Array [], + "loc": Object { + "end": Object { + "column": 3, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 4, + }, + "start": Object { + "column": 1, + "line": 4, + }, + }, + "name": "c", + "range": Array [ + 63, + 64, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 62, + 65, + ], + "selfClosing": false, + "type": "JSXOpeningElement", + "typeParameters": undefined, + }, + "range": Array [ + 62, + 74, + ], + "type": "JSXElement", + }, + "loc": Object { + "end": Object { + "column": 13, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + "range": Array [ + 62, + 75, + ], + "type": "ExpressionStatement", + }, + Object { + "expression": Object { + "children": Array [ + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, + }, + }, + "range": Array [ + 79, + 92, + ], + "raw": "¬anentity;", + "type": "Literal", + "value": "¬anentity;", + }, + ], + "closingElement": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 5, + }, + "start": Object { + "column": 16, + "line": 5, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 5, + }, + "start": Object { + "column": 18, + "line": 5, + }, + }, + "name": "d", + "range": Array [ + 94, + 95, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 92, + 96, + ], + "type": "JSXClosingElement", + }, + "loc": Object { + "end": Object { + "column": 20, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "openingElement": Object { + "attributes": Array [], + "loc": Object { + "end": Object { + "column": 3, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 5, + }, + "start": Object { + "column": 1, + "line": 5, + }, + }, + "name": "d", + "range": Array [ + 77, + 78, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 76, + 79, + ], + "selfClosing": false, + "type": "JSXOpeningElement", + "typeParameters": undefined, + }, + "range": Array [ + 76, + 96, + ], + "type": "JSXElement", + }, + "loc": Object { + "end": Object { + "column": 21, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "range": Array [ + 76, + 97, + ], + "type": "ExpressionStatement", + }, + Object { + "expression": Object { + "children": Array [ + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, + }, + "range": Array [ + 101, + 105, + ], + "raw": "&#x;", + "type": "Literal", + "value": "&#x;", + }, + ], + "closingElement": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 6, + }, + "start": Object { + "column": 7, + "line": 6, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 6, + }, + "start": Object { + "column": 9, + "line": 6, + }, + }, + "name": "e", + "range": Array [ + 107, + 108, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 105, + 109, + ], + "type": "JSXClosingElement", + }, + "loc": Object { + "end": Object { + "column": 11, + "line": 6, + }, + "start": Object { + "column": 0, + "line": 6, + }, + }, + "openingElement": Object { + "attributes": Array [], + "loc": Object { + "end": Object { + "column": 3, + "line": 6, + }, + "start": Object { + "column": 0, + "line": 6, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 6, + }, + "start": Object { + "column": 1, + "line": 6, + }, + }, + "name": "e", + "range": Array [ + 99, + 100, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 98, + 101, + ], + "selfClosing": false, + "type": "JSXOpeningElement", + "typeParameters": undefined, + }, + "range": Array [ + 98, + 109, + ], + "type": "JSXElement", + }, + "loc": Object { + "end": Object { + "column": 12, + "line": 6, + }, + "start": Object { + "column": 0, + "line": 6, + }, + }, + "range": Array [ + 98, + 110, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 7, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 111, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 1, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 2, + ], + "type": "JSXIdentifier", + "value": "a", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "range": Array [ + 3, + 4, + ], + "type": "JSXIdentifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 20, + ], + "type": "JSXText", + "value": "\\"¬anentity;\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 1, + }, + "start": Object { + "column": 21, + "line": 1, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": "/", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 22, + "line": 1, + }, + }, + "range": Array [ + 22, + 23, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 2, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 2, + }, + "start": Object { + "column": 1, + "line": 2, + }, + }, + "range": Array [ + 26, + 27, + ], + "type": "JSXIdentifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 2, + }, + "start": Object { + "column": 3, + "line": 2, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "JSXIdentifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 4, + "line": 2, + }, + }, + "range": Array [ + 29, + 30, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 5, + "line": 2, + }, + }, + "range": Array [ + 30, + 36, + ], + "type": "JSXText", + "value": "\\"&##;\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "range": Array [ + 37, + 38, + ], + "type": "Punctuator", + "value": "/", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 38, + 39, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 2, + }, + "start": Object { + "column": 14, + "line": 2, + }, + }, + "range": Array [ + 39, + 40, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 41, + 42, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 3, + }, + "start": Object { + "column": 1, + "line": 3, + }, + }, + "range": Array [ + 42, + 43, + ], + "type": "JSXIdentifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, + }, + "range": Array [ + 44, + 45, + ], + "type": "JSXIdentifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 45, + 46, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 5, + "line": 3, + }, + }, + "range": Array [ + 46, + 57, + ], + "type": "JSXText", + "value": "\\"&x01FZZZ;\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 17, + "line": 3, + }, + }, + "range": Array [ + 58, + 59, + ], + "type": "Punctuator", + "value": "/", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 3, + }, + "start": Object { + "column": 18, + "line": 3, + }, + }, + "range": Array [ + 59, + 60, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 3, + }, + "start": Object { + "column": 19, + "line": 3, + }, + }, + "range": Array [ + 60, + 61, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 4, + }, + }, + "range": Array [ + 62, + 63, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 4, + }, + "start": Object { + "column": 1, + "line": 4, + }, + }, + "range": Array [ + 63, + 64, + ], + "type": "JSXIdentifier", + "value": "c", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "range": Array [ + 64, + 65, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 4, + }, + "start": Object { + "column": 3, + "line": 4, + }, + }, + "range": Array [ + 65, + 70, + ], + "type": "JSXText", + "value": "&abc;", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "range": Array [ + 70, + 71, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 4, + }, + "start": Object { + "column": 9, + "line": 4, + }, + }, + "range": Array [ + 71, + 72, + ], + "type": "Punctuator", + "value": "/", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 4, + }, + "start": Object { + "column": 10, + "line": 4, + }, + }, + "range": Array [ + 72, + 73, + ], + "type": "JSXIdentifier", + "value": "c", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 4, + }, + "start": Object { + "column": 11, + "line": 4, + }, + }, + "range": Array [ + 73, + 74, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 4, + }, + "start": Object { + "column": 12, + "line": 4, + }, + }, + "range": Array [ + 74, + 75, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "range": Array [ + 76, + 77, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 5, + }, + "start": Object { + "column": 1, + "line": 5, + }, + }, + "range": Array [ + 77, + 78, + ], + "type": "JSXIdentifier", + "value": "d", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "range": Array [ + 78, + 79, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 5, + }, + "start": Object { + "column": 3, + "line": 5, + }, + }, + "range": Array [ + 79, + 92, + ], + "type": "JSXText", + "value": "¬anentity;", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 5, + }, + "start": Object { + "column": 16, + "line": 5, + }, + }, + "range": Array [ + 92, + 93, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 5, + }, + "start": Object { + "column": 17, + "line": 5, + }, + }, + "range": Array [ + 93, + 94, + ], + "type": "Punctuator", + "value": "/", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 5, + }, + "start": Object { + "column": 18, + "line": 5, + }, + }, + "range": Array [ + 94, + 95, + ], + "type": "JSXIdentifier", + "value": "d", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 5, + }, + "start": Object { + "column": 19, + "line": 5, + }, + }, + "range": Array [ + 95, + 96, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 5, + }, + "start": Object { + "column": 20, + "line": 5, + }, + }, + "range": Array [ + 96, + 97, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 6, + }, + "start": Object { + "column": 0, + "line": 6, + }, + }, + "range": Array [ + 98, + 99, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 6, + }, + "start": Object { + "column": 1, + "line": 6, + }, + }, + "range": Array [ + 99, + 100, + ], + "type": "JSXIdentifier", + "value": "e", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "range": Array [ + 100, + 101, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 6, + }, + "start": Object { + "column": 3, + "line": 6, + }, + }, + "range": Array [ + 101, + 105, + ], + "type": "JSXText", + "value": "&#x;", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 6, + }, + "start": Object { + "column": 7, + "line": 6, + }, + }, + "range": Array [ + 105, + 106, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 6, + }, + "start": Object { + "column": 8, + "line": 6, + }, + }, + "range": Array [ + 106, + 107, + ], + "type": "Punctuator", + "value": "/", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 6, + }, + "start": Object { + "column": 9, + "line": 6, + }, + }, + "range": Array [ + 107, + 108, + ], + "type": "JSXIdentifier", + "value": "e", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 6, + }, + "start": Object { + "column": 10, + "line": 6, + }, + }, + "range": Array [ + 108, + 109, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 6, + }, + "start": Object { + "column": 11, + "line": 6, + }, + }, + "range": Array [ + 109, + 110, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-valid.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-valid.src.js.shot new file mode 100644 index 00000000000..991dba996a8 --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-valid.src.js.shot @@ -0,0 +1,540 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`jsx escape-patterns-valid.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "children": Array [ + Object { + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "range": Array [ + 24, + 34, + ], + "raw": " +   +", + "type": "Literal", + "value": " +   +", + }, + ], + "closingElement": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "name": "a", + "range": Array [ + 36, + 37, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 34, + 38, + ], + "type": "JSXClosingElement", + }, + "loc": Object { + "end": Object { + "column": 4, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "openingElement": Object { + "attributes": Array [ + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "name": "b", + "range": Array [ + 3, + 4, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 3, + 12, + ], + "type": "JSXAttribute", + "value": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 12, + ], + "raw": "\\"&\\"", + "type": "Literal", + "value": "&", + }, + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "name": "c", + "range": Array [ + 13, + 14, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 13, + 23, + ], + "type": "JSXAttribute", + "value": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 23, + ], + "raw": "\\"{\\"", + "type": "Literal", + "value": "{", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "name": "a", + "range": Array [ + 1, + 2, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 0, + 24, + ], + "selfClosing": false, + "type": "JSXOpeningElement", + "typeParameters": undefined, + }, + "range": Array [ + 0, + 38, + ], + "type": "JSXElement", + }, + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 39, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 40, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 1, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 1, + }, + "start": Object { + "column": 1, + "line": 1, + }, + }, + "range": Array [ + 1, + 2, + ], + "type": "JSXIdentifier", + "value": "a", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 1, + }, + "start": Object { + "column": 3, + "line": 1, + }, + }, + "range": Array [ + 3, + 4, + ], + "type": "JSXIdentifier", + "value": "b", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 4, + "line": 1, + }, + }, + "range": Array [ + 4, + 5, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 12, + ], + "type": "JSXText", + "value": "\\"&\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 1, + }, + "start": Object { + "column": 13, + "line": 1, + }, + }, + "range": Array [ + 13, + 14, + ], + "type": "JSXIdentifier", + "value": "c", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 1, + }, + "start": Object { + "column": 14, + "line": 1, + }, + }, + "range": Array [ + 14, + 15, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 1, + }, + "start": Object { + "column": 15, + "line": 1, + }, + }, + "range": Array [ + 15, + 23, + ], + "type": "JSXText", + "value": "\\"{\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 1, + }, + "start": Object { + "column": 23, + "line": 1, + }, + }, + "range": Array [ + 23, + 24, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 0, + "line": 3, + }, + "start": Object { + "column": 24, + "line": 1, + }, + }, + "range": Array [ + 24, + 34, + ], + "type": "JSXText", + "value": " +   +", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 34, + 35, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 2, + "line": 3, + }, + "start": Object { + "column": 1, + "line": 3, + }, + }, + "range": Array [ + 35, + 36, + ], + "type": "Punctuator", + "value": "/", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 36, + 37, + ], + "type": "JSXIdentifier", + "value": "a", + }, + Object { + "loc": Object { + "end": Object { + "column": 4, + "line": 3, + }, + "start": Object { + "column": 3, + "line": 3, + }, + }, + "range": Array [ + 37, + 38, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 4, + "line": 3, + }, + }, + "range": Array [ + 38, + 39, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tests/snapshots/jsx/unknown-escape-pattern.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/escape-patters-multi.src.js.shot similarity index 57% rename from packages/typescript-estree/tests/snapshots/jsx/unknown-escape-pattern.src.js.shot rename to packages/typescript-estree/tests/snapshots/jsx/escape-patters-multi.src.js.shot index c6e3bbe2d36..d4710d1d586 100644 --- a/packages/typescript-estree/tests/snapshots/jsx/unknown-escape-pattern.src.js.shot +++ b/packages/typescript-estree/tests/snapshots/jsx/escape-patters-multi.src.js.shot @@ -1,15 +1,69 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`jsx unknown-escape-pattern.src 1`] = ` +exports[`jsx escape-patters-multi.src 1`] = ` Object { "body": Array [ Object { "expression": Object { - "children": Array [], - "closingElement": null, + "children": Array [ + Object { + "loc": Object { + "end": Object { + "column": 44, + "line": 1, + }, + "start": Object { + "column": 33, + "line": 1, + }, + }, + "range": Array [ + 33, + 44, + ], + "raw": "  test", + "type": "Literal", + "value": "  test", + }, + ], + "closingElement": Object { + "loc": Object { + "end": Object { + "column": 48, + "line": 1, + }, + "start": Object { + "column": 44, + "line": 1, + }, + }, + "name": Object { + "loc": Object { + "end": Object { + "column": 47, + "line": 1, + }, + "start": Object { + "column": 46, + "line": 1, + }, + }, + "name": "a", + "range": Array [ + 46, + 47, + ], + "type": "JSXIdentifier", + }, + "range": Array [ + 44, + 48, + ], + "type": "JSXClosingElement", + }, "loc": Object { "end": Object { - "column": 23, + "column": 48, "line": 1, }, "start": Object { @@ -22,7 +76,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 20, + "column": 32, "line": 1, }, "start": Object { @@ -33,7 +87,7 @@ Object { "name": Object { "loc": Object { "end": Object { - "column": 4, + "column": 7, "line": 1, }, "start": Object { @@ -41,42 +95,42 @@ Object { "line": 1, }, }, - "name": "b", + "name": "href", "range": Array [ 3, - 4, + 7, ], "type": "JSXIdentifier", }, "range": Array [ 3, - 20, + 32, ], "type": "JSXAttribute", "value": Object { "loc": Object { "end": Object { - "column": 20, + "column": 32, "line": 1, }, "start": Object { - "column": 5, + "column": 8, "line": 1, }, }, "range": Array [ - 5, - 20, + 8, + 32, ], - "raw": "\\"¬anentity;\\"", + "raw": "\\"test=1&bar=1{\\"", "type": "Literal", - "value": "¬anentity;", + "value": "test=1&bar=1{", }, }, ], "loc": Object { "end": Object { - "column": 23, + "column": 33, "line": 1, }, "start": Object { @@ -104,21 +158,21 @@ Object { }, "range": Array [ 0, - 23, + 33, ], - "selfClosing": true, + "selfClosing": false, "type": "JSXOpeningElement", "typeParameters": undefined, }, "range": Array [ 0, - 23, + 48, ], "type": "JSXElement", }, "loc": Object { "end": Object { - "column": 24, + "column": 49, "line": 1, }, "start": Object { @@ -128,7 +182,7 @@ Object { }, "range": Array [ 0, - 24, + 49, ], "type": "ExpressionStatement", }, @@ -136,8 +190,8 @@ Object { "comments": Array [], "loc": Object { "end": Object { - "column": 24, - "line": 1, + "column": 0, + "line": 2, }, "start": Object { "column": 0, @@ -146,7 +200,7 @@ Object { }, "range": Array [ 0, - 24, + 50, ], "sourceType": "script", "tokens": Array [ @@ -189,7 +243,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 4, + "column": 7, "line": 1, }, "start": Object { @@ -199,25 +253,25 @@ Object { }, "range": Array [ 3, - 4, + 7, ], "type": "JSXIdentifier", - "value": "b", + "value": "href", }, Object { "loc": Object { "end": Object { - "column": 5, + "column": 8, "line": 1, }, "start": Object { - "column": 4, + "column": 7, "line": 1, }, }, "range": Array [ - 4, - 5, + 7, + 8, ], "type": "Punctuator", "value": "=", @@ -225,35 +279,89 @@ Object { Object { "loc": Object { "end": Object { - "column": 20, + "column": 32, + "line": 1, + }, + "start": Object { + "column": 8, + "line": 1, + }, + }, + "range": Array [ + 8, + 32, + ], + "type": "JSXText", + "value": "\\"test=1&bar=1{\\"", + }, + Object { + "loc": Object { + "end": Object { + "column": 33, + "line": 1, + }, + "start": Object { + "column": 32, + "line": 1, + }, + }, + "range": Array [ + 32, + 33, + ], + "type": "Punctuator", + "value": ">", + }, + Object { + "loc": Object { + "end": Object { + "column": 44, "line": 1, }, "start": Object { - "column": 5, + "column": 33, "line": 1, }, }, "range": Array [ - 5, - 20, + 33, + 44, ], "type": "JSXText", - "value": "\\"¬anentity;\\"", + "value": "  test", }, Object { "loc": Object { "end": Object { - "column": 22, + "column": 45, "line": 1, }, "start": Object { - "column": 21, + "column": 44, "line": 1, }, }, "range": Array [ - 21, - 22, + 44, + 45, + ], + "type": "Punctuator", + "value": "<", + }, + Object { + "loc": Object { + "end": Object { + "column": 46, + "line": 1, + }, + "start": Object { + "column": 45, + "line": 1, + }, + }, + "range": Array [ + 45, + 46, ], "type": "Punctuator", "value": "/", @@ -261,17 +369,35 @@ Object { Object { "loc": Object { "end": Object { - "column": 23, + "column": 47, + "line": 1, + }, + "start": Object { + "column": 46, + "line": 1, + }, + }, + "range": Array [ + 46, + 47, + ], + "type": "JSXIdentifier", + "value": "a", + }, + Object { + "loc": Object { + "end": Object { + "column": 48, "line": 1, }, "start": Object { - "column": 22, + "column": 47, "line": 1, }, }, "range": Array [ - 22, - 23, + 47, + 48, ], "type": "Punctuator", "value": ">", @@ -279,17 +405,17 @@ Object { Object { "loc": Object { "end": Object { - "column": 24, + "column": 49, "line": 1, }, "start": Object { - "column": 23, + "column": 48, "line": 1, }, }, "range": Array [ - 23, - 24, + 48, + 49, ], "type": "Punctuator", "value": ";", From 45e0815a9033b9a9631dab98cec547404ac3ba08 Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 3 Feb 2021 03:03:42 +0100 Subject: [PATCH 2/3] fix(typescript-estree): add proper handling for jsx literal characters --- packages/typescript-estree/package.json | 2 - packages/typescript-estree/src/convert.ts | 29 +- .../src/jsx/xhtml-entities.ts | 255 ++++++++++++++++++ packages/typescript-estree/src/node-utils.ts | 16 +- .../tests/lib/node-utils.test.ts | 46 ++++ .../ignored.src.js.shot | 2 +- .../jsx/escape-patterns-ignored.src.js.shot | 2 +- .../jsx/escape-patterns-valid.src.js.shot | 4 +- .../jsx/escape-patters-multi.src.js.shot | 4 +- 9 files changed, 334 insertions(+), 26 deletions(-) create mode 100644 packages/typescript-estree/src/jsx/xhtml-entities.ts create mode 100644 packages/typescript-estree/tests/lib/node-utils.test.ts diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index 63b5fdcff5c..30c630e85f6 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -46,7 +46,6 @@ "debug": "^4.1.1", "globby": "^11.0.1", "is-glob": "^4.0.1", - "lodash": "^4.17.15", "semver": "^7.3.2", "tsutils": "^3.17.1" }, @@ -58,7 +57,6 @@ "@types/debug": "*", "@types/glob": "*", "@types/is-glob": "^4.0.1", - "@types/lodash": "*", "@types/semver": "^7.1.0", "@types/tmp": "^0.2.0", "@typescript-eslint/shared-fixtures": "4.14.2", diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index a22eae1a5df..f8819a33c9e 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -14,6 +14,7 @@ import { getTextForTokenKind, getTSNodeAccessibility, hasModifier, + isChainExpression, isChildUnwrappableOptionalChain, isComma, isComputedProperty, @@ -21,14 +22,13 @@ import { isOptional, TSError, unescapeStringLiteralText, - isChainExpression, } from './node-utils'; import { ParserWeakMap, ParserWeakMapESTreeToTSNode } from './parser-options'; import { AST_NODE_TYPES, TSESTree, - TSNode, TSESTreeToTSNode, + TSNode, } from './ts-estree'; import { typescriptVersionIsAtLeast } from './version-check'; @@ -1921,18 +1921,14 @@ export class Converter { // Literals case SyntaxKind.StringLiteral: { - const result = this.createNode(node, { + return this.createNode(node, { type: AST_NODE_TYPES.Literal, - raw: '', - value: '', + value: + parent.kind === SyntaxKind.JsxAttribute + ? unescapeStringLiteralText(node.text) + : node.text, + raw: node.getText(), }); - result.raw = this.ast.text.slice(result.range[0], result.range[1]); - if ('name' in parent && parent.name === node) { - result.value = node.text; - } else { - result.value = unescapeStringLiteralText(node.text); - } - return result; } case SyntaxKind.NumericLiteral: { @@ -2141,19 +2137,20 @@ export class Converter { case SyntaxKind.JsxText: { const start = node.getFullStart(); const end = node.getEnd(); + const text = this.ast.text.slice(start, end); if (this.options.useJSXTextNode) { return this.createNode(node, { type: AST_NODE_TYPES.JSXText, - value: this.ast.text.slice(start, end), - raw: this.ast.text.slice(start, end), + value: unescapeStringLiteralText(text), + raw: text, range: [start, end], }); } else { return this.createNode(node, { type: AST_NODE_TYPES.Literal, - value: this.ast.text.slice(start, end), - raw: this.ast.text.slice(start, end), + value: unescapeStringLiteralText(text), + raw: text, range: [start, end], }); } diff --git a/packages/typescript-estree/src/jsx/xhtml-entities.ts b/packages/typescript-estree/src/jsx/xhtml-entities.ts new file mode 100644 index 00000000000..2c3e788f0ed --- /dev/null +++ b/packages/typescript-estree/src/jsx/xhtml-entities.ts @@ -0,0 +1,255 @@ +export const xhtmlEntities: Record = { + quot: '\u0022', + amp: '&', + apos: '\u0027', + lt: '<', + gt: '>', + nbsp: '\u00A0', + iexcl: '\u00A1', + cent: '\u00A2', + pound: '\u00A3', + curren: '\u00A4', + yen: '\u00A5', + brvbar: '\u00A6', + sect: '\u00A7', + uml: '\u00A8', + copy: '\u00A9', + ordf: '\u00AA', + laquo: '\u00AB', + not: '\u00AC', + shy: '\u00AD', + reg: '\u00AE', + macr: '\u00AF', + deg: '\u00B0', + plusmn: '\u00B1', + sup2: '\u00B2', + sup3: '\u00B3', + acute: '\u00B4', + micro: '\u00B5', + para: '\u00B6', + middot: '\u00B7', + cedil: '\u00B8', + sup1: '\u00B9', + ordm: '\u00BA', + raquo: '\u00BB', + frac14: '\u00BC', + frac12: '\u00BD', + frac34: '\u00BE', + iquest: '\u00BF', + Agrave: '\u00C0', + Aacute: '\u00C1', + Acirc: '\u00C2', + Atilde: '\u00C3', + Auml: '\u00C4', + Aring: '\u00C5', + AElig: '\u00C6', + Ccedil: '\u00C7', + Egrave: '\u00C8', + Eacute: '\u00C9', + Ecirc: '\u00CA', + Euml: '\u00CB', + Igrave: '\u00CC', + Iacute: '\u00CD', + Icirc: '\u00CE', + Iuml: '\u00CF', + ETH: '\u00D0', + Ntilde: '\u00D1', + Ograve: '\u00D2', + Oacute: '\u00D3', + Ocirc: '\u00D4', + Otilde: '\u00D5', + Ouml: '\u00D6', + times: '\u00D7', + Oslash: '\u00D8', + Ugrave: '\u00D9', + Uacute: '\u00DA', + Ucirc: '\u00DB', + Uuml: '\u00DC', + Yacute: '\u00DD', + THORN: '\u00DE', + szlig: '\u00DF', + agrave: '\u00E0', + aacute: '\u00E1', + acirc: '\u00E2', + atilde: '\u00E3', + auml: '\u00E4', + aring: '\u00E5', + aelig: '\u00E6', + ccedil: '\u00E7', + egrave: '\u00E8', + eacute: '\u00E9', + ecirc: '\u00EA', + euml: '\u00EB', + igrave: '\u00EC', + iacute: '\u00ED', + icirc: '\u00EE', + iuml: '\u00EF', + eth: '\u00F0', + ntilde: '\u00F1', + ograve: '\u00F2', + oacute: '\u00F3', + ocirc: '\u00F4', + otilde: '\u00F5', + ouml: '\u00F6', + divide: '\u00F7', + oslash: '\u00F8', + ugrave: '\u00F9', + uacute: '\u00FA', + ucirc: '\u00FB', + uuml: '\u00FC', + yacute: '\u00FD', + thorn: '\u00FE', + yuml: '\u00FF', + OElig: '\u0152', + oelig: '\u0153', + Scaron: '\u0160', + scaron: '\u0161', + Yuml: '\u0178', + fnof: '\u0192', + circ: '\u02C6', + tilde: '\u02DC', + Alpha: '\u0391', + Beta: '\u0392', + Gamma: '\u0393', + Delta: '\u0394', + Epsilon: '\u0395', + Zeta: '\u0396', + Eta: '\u0397', + Theta: '\u0398', + Iota: '\u0399', + Kappa: '\u039A', + Lambda: '\u039B', + Mu: '\u039C', + Nu: '\u039D', + Xi: '\u039E', + Omicron: '\u039F', + Pi: '\u03A0', + Rho: '\u03A1', + Sigma: '\u03A3', + Tau: '\u03A4', + Upsilon: '\u03A5', + Phi: '\u03A6', + Chi: '\u03A7', + Psi: '\u03A8', + Omega: '\u03A9', + alpha: '\u03B1', + beta: '\u03B2', + gamma: '\u03B3', + delta: '\u03B4', + epsilon: '\u03B5', + zeta: '\u03B6', + eta: '\u03B7', + theta: '\u03B8', + iota: '\u03B9', + kappa: '\u03BA', + lambda: '\u03BB', + mu: '\u03BC', + nu: '\u03BD', + xi: '\u03BE', + omicron: '\u03BF', + pi: '\u03C0', + rho: '\u03C1', + sigmaf: '\u03C2', + sigma: '\u03C3', + tau: '\u03C4', + upsilon: '\u03C5', + phi: '\u03C6', + chi: '\u03C7', + psi: '\u03C8', + omega: '\u03C9', + thetasym: '\u03D1', + upsih: '\u03D2', + piv: '\u03D6', + ensp: '\u2002', + emsp: '\u2003', + thinsp: '\u2009', + zwnj: '\u200C', + zwj: '\u200D', + lrm: '\u200E', + rlm: '\u200F', + ndash: '\u2013', + mdash: '\u2014', + lsquo: '\u2018', + rsquo: '\u2019', + sbquo: '\u201A', + ldquo: '\u201C', + rdquo: '\u201D', + bdquo: '\u201E', + dagger: '\u2020', + Dagger: '\u2021', + bull: '\u2022', + hellip: '\u2026', + permil: '\u2030', + prime: '\u2032', + Prime: '\u2033', + lsaquo: '\u2039', + rsaquo: '\u203A', + oline: '\u203E', + frasl: '\u2044', + euro: '\u20AC', + image: '\u2111', + weierp: '\u2118', + real: '\u211C', + trade: '\u2122', + alefsym: '\u2135', + larr: '\u2190', + uarr: '\u2191', + rarr: '\u2192', + darr: '\u2193', + harr: '\u2194', + crarr: '\u21B5', + lArr: '\u21D0', + uArr: '\u21D1', + rArr: '\u21D2', + dArr: '\u21D3', + hArr: '\u21D4', + forall: '\u2200', + part: '\u2202', + exist: '\u2203', + empty: '\u2205', + nabla: '\u2207', + isin: '\u2208', + notin: '\u2209', + ni: '\u220B', + prod: '\u220F', + sum: '\u2211', + minus: '\u2212', + lowast: '\u2217', + radic: '\u221A', + prop: '\u221D', + infin: '\u221E', + ang: '\u2220', + and: '\u2227', + or: '\u2228', + cap: '\u2229', + cup: '\u222A', + int: '\u222B', + there4: '\u2234', + sim: '\u223C', + cong: '\u2245', + asymp: '\u2248', + ne: '\u2260', + equiv: '\u2261', + le: '\u2264', + ge: '\u2265', + sub: '\u2282', + sup: '\u2283', + nsub: '\u2284', + sube: '\u2286', + supe: '\u2287', + oplus: '\u2295', + otimes: '\u2297', + perp: '\u22A5', + sdot: '\u22C5', + lceil: '\u2308', + rceil: '\u2309', + lfloor: '\u230A', + rfloor: '\u230B', + lang: '\u2329', + rang: '\u232A', + loz: '\u25CA', + spades: '\u2660', + clubs: '\u2663', + hearts: '\u2665', + diams: '\u2666', +}; diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 74c58666f28..5a93933c771 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -1,6 +1,6 @@ -import unescape from 'lodash/unescape'; import * as ts from 'typescript'; import { AST_NODE_TYPES, AST_TOKEN_TYPES, TSESTree } from './ts-estree'; +import { xhtmlEntities } from './jsx/xhtml-entities'; const SyntaxKind = ts.SyntaxKind; @@ -414,7 +414,19 @@ export function hasJSXAncestor(node: ts.Node): boolean { * @returns The unescaped string literal text. */ export function unescapeStringLiteralText(text: string): string { - return unescape(text); + return text.replace(/&(?:#\d+|#x[\da-fA-F]+|[0-9a-zA-Z]+);/g, entity => { + const item = entity.slice(1, -1); + if (item[0] === '#') { + const codePoint = + item[1] === 'x' + ? parseInt(item.slice(2), 16) + : parseInt(item.slice(1), 10); + return codePoint > 0x10ffff // RangeError: Invalid code point + ? String.fromCharCode(65533) + : String.fromCodePoint(codePoint); + } + return xhtmlEntities[item] || entity; + }); } /** diff --git a/packages/typescript-estree/tests/lib/node-utils.test.ts b/packages/typescript-estree/tests/lib/node-utils.test.ts new file mode 100644 index 00000000000..c0fec80f9f1 --- /dev/null +++ b/packages/typescript-estree/tests/lib/node-utils.test.ts @@ -0,0 +1,46 @@ +import { unescapeStringLiteralText } from '../../src/node-utils'; + +describe('unescapeStringLiteralText()', () => { + it('should not modify content', () => { + let text = 'amp;'; + expect(unescapeStringLiteralText(text)).toEqual(text); + text = 'test'; + expect(unescapeStringLiteralText(text)).toEqual(text); + text = 'foo&bar&baz;'; + expect(unescapeStringLiteralText(text)).toEqual(text); + text = 'foo&bar&baz;'; + expect(unescapeStringLiteralText(text)).toEqual(text); + text = '¬listed;'; + expect(unescapeStringLiteralText(text)).toEqual(text); + text = '\u20ac'; + expect(unescapeStringLiteralText(text)).toEqual(text); + }); + it('should handle empty string', () => { + expect(unescapeStringLiteralText('')).toEqual(''); + }); + it('should handle named entities followed by alphanumeric characters', () => { + expect(unescapeStringLiteralText('über')).toEqual('über'); + }); + it('should handle invalid code point modify content', () => { + expect(unescapeStringLiteralText('�')).toEqual( + String.fromCharCode(65533), + ); + }); + it('should escape correctly', () => { + expect(unescapeStringLiteralText('&=123&lang=en&,&')).toEqual( + '&=123&lang=en&,&', + ); + expect(unescapeStringLiteralText('')).toEqual('\u0001'); + expect(unescapeStringLiteralText('!')).toEqual(`!`); + expect(unescapeStringLiteralText('�')).toEqual('\u0000'); + expect(unescapeStringLiteralText('Œ')).toEqual('\u0152'); + expect(unescapeStringLiteralText('œ')).toEqual('\u0153'); + expect(unescapeStringLiteralText('∴')).toEqual('\u2234'); + expect(unescapeStringLiteralText('😂')).toEqual('😂'); + expect( + unescapeStringLiteralText( + 'a\n<>"'&©∆℞😂�', + ), + ).toEqual(`a\n<>"'&©∆℞😂\u0000\u0001`); + }); +}); diff --git a/packages/typescript-estree/tests/snapshots/javascript/unicodeCodePointEscapes/ignored.src.js.shot b/packages/typescript-estree/tests/snapshots/javascript/unicodeCodePointEscapes/ignored.src.js.shot index 4d8236d2a3c..f893dfa0609 100644 --- a/packages/typescript-estree/tests/snapshots/javascript/unicodeCodePointEscapes/ignored.src.js.shot +++ b/packages/typescript-estree/tests/snapshots/javascript/unicodeCodePointEscapes/ignored.src.js.shot @@ -189,7 +189,7 @@ Object { ], "raw": "'&'", "type": "Literal", - "value": "&", + "value": "&", }, "loc": Object { "end": Object { diff --git a/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-ignored.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-ignored.src.js.shot index ec4eb166c18..3db51530669 100644 --- a/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-ignored.src.js.shot +++ b/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-ignored.src.js.shot @@ -196,7 +196,7 @@ Object { ], "raw": "'&'", "type": "Literal", - "value": "&", + "value": "&", }, "loc": Object { "end": Object { diff --git a/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-valid.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-valid.src.js.shot index 991dba996a8..2cc38d57adb 100644 --- a/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-valid.src.js.shot +++ b/packages/typescript-estree/tests/snapshots/jsx/escape-patterns-valid.src.js.shot @@ -26,7 +26,7 @@ Object { ", "type": "Literal", "value": " -   +   ", }, ], @@ -182,7 +182,7 @@ Object { ], "raw": "\\"{\\"", "type": "Literal", - "value": "{", + "value": "{", }, }, ], diff --git a/packages/typescript-estree/tests/snapshots/jsx/escape-patters-multi.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/escape-patters-multi.src.js.shot index d4710d1d586..d3cff5df9bf 100644 --- a/packages/typescript-estree/tests/snapshots/jsx/escape-patters-multi.src.js.shot +++ b/packages/typescript-estree/tests/snapshots/jsx/escape-patters-multi.src.js.shot @@ -23,7 +23,7 @@ Object { ], "raw": "  test", "type": "Literal", - "value": "  test", + "value": "  test", }, ], "closingElement": Object { @@ -124,7 +124,7 @@ Object { ], "raw": "\\"test=1&bar=1{\\"", "type": "Literal", - "value": "test=1&bar=1{", + "value": "test=1&bar=1{", }, }, ], From 38ff342a246e33106cc7252cdabb1a838455ed35 Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 3 Feb 2021 03:46:21 +0100 Subject: [PATCH 3/3] fix(typescript-estree): do not override codePoints if unparsable --- packages/typescript-estree/src/node-utils.ts | 2 +- packages/typescript-estree/tests/lib/node-utils.test.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 5a93933c771..c9eef0fba76 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -422,7 +422,7 @@ export function unescapeStringLiteralText(text: string): string { ? parseInt(item.slice(2), 16) : parseInt(item.slice(1), 10); return codePoint > 0x10ffff // RangeError: Invalid code point - ? String.fromCharCode(65533) + ? entity : String.fromCodePoint(codePoint); } return xhtmlEntities[item] || entity; diff --git a/packages/typescript-estree/tests/lib/node-utils.test.ts b/packages/typescript-estree/tests/lib/node-utils.test.ts index c0fec80f9f1..04ef46c9f65 100644 --- a/packages/typescript-estree/tests/lib/node-utils.test.ts +++ b/packages/typescript-estree/tests/lib/node-utils.test.ts @@ -22,9 +22,7 @@ describe('unescapeStringLiteralText()', () => { expect(unescapeStringLiteralText('über')).toEqual('über'); }); it('should handle invalid code point modify content', () => { - expect(unescapeStringLiteralText('�')).toEqual( - String.fromCharCode(65533), - ); + expect(unescapeStringLiteralText('�')).toEqual('�'); }); it('should escape correctly', () => { expect(unescapeStringLiteralText('&=123&lang=en&,&')).toEqual(