From 6c34578145ae87927baf6903f632f39d7cdbafa2 Mon Sep 17 00:00:00 2001 From: Armano Date: Mon, 14 Jan 2019 05:10:47 +0100 Subject: [PATCH 1/4] fix(estree): fix parsing legacy octal number value and add tests --- .../javascript/hexLiterals/invalid.src.js | 1 + .../javascript/hexLiterals/lowercase.src.js | 1 + .../javascript/hexLiterals/uppercase.src.js | 1 + .../javascript/octalLiterals/legacy.src.js | 1 + packages/typescript-estree/src/convert.ts | 17 +- .../tests/ast-alignment/fixtures-to-test.ts | 1 + .../lib/__snapshots__/javascript.ts.snap | 293 ++++++++++++++++++ .../semantic-diagnostics-enabled.ts.snap | 15 + 8 files changed, 327 insertions(+), 3 deletions(-) create mode 100644 packages/typescript-eslint-shared-fixtures/fixtures/javascript/hexLiterals/invalid.src.js create mode 100644 packages/typescript-eslint-shared-fixtures/fixtures/javascript/hexLiterals/lowercase.src.js create mode 100644 packages/typescript-eslint-shared-fixtures/fixtures/javascript/hexLiterals/uppercase.src.js create mode 100644 packages/typescript-eslint-shared-fixtures/fixtures/javascript/octalLiterals/legacy.src.js diff --git a/packages/typescript-eslint-shared-fixtures/fixtures/javascript/hexLiterals/invalid.src.js b/packages/typescript-eslint-shared-fixtures/fixtures/javascript/hexLiterals/invalid.src.js new file mode 100644 index 000000000000..52cc359c1b9e --- /dev/null +++ b/packages/typescript-eslint-shared-fixtures/fixtures/javascript/hexLiterals/invalid.src.js @@ -0,0 +1 @@ +0x12z; diff --git a/packages/typescript-eslint-shared-fixtures/fixtures/javascript/hexLiterals/lowercase.src.js b/packages/typescript-eslint-shared-fixtures/fixtures/javascript/hexLiterals/lowercase.src.js new file mode 100644 index 000000000000..ebb8a6d300ae --- /dev/null +++ b/packages/typescript-eslint-shared-fixtures/fixtures/javascript/hexLiterals/lowercase.src.js @@ -0,0 +1 @@ +0x2343; diff --git a/packages/typescript-eslint-shared-fixtures/fixtures/javascript/hexLiterals/uppercase.src.js b/packages/typescript-eslint-shared-fixtures/fixtures/javascript/hexLiterals/uppercase.src.js new file mode 100644 index 000000000000..4cd84c3772d9 --- /dev/null +++ b/packages/typescript-eslint-shared-fixtures/fixtures/javascript/hexLiterals/uppercase.src.js @@ -0,0 +1 @@ +0X2343; diff --git a/packages/typescript-eslint-shared-fixtures/fixtures/javascript/octalLiterals/legacy.src.js b/packages/typescript-eslint-shared-fixtures/fixtures/javascript/octalLiterals/legacy.src.js new file mode 100644 index 000000000000..531316639580 --- /dev/null +++ b/packages/typescript-eslint-shared-fixtures/fixtures/javascript/octalLiterals/legacy.src.js @@ -0,0 +1 @@ +02343; diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 17ef919099f6..f665a2dc3622 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1779,13 +1779,24 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { } break; - case SyntaxKind.NumericLiteral: + case SyntaxKind.NumericLiteral: { + const rawValue = node.getText(); + let value = Number(node.text); + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal + // http://www.ecma-international.org/ecma-262/6.0/#sec-additional-syntax-numeric-literals + if (/^(-?)0([0-7]+)$/i.test(rawValue)) { + value = parseInt( + node.text.replace(/^(-?)0([0-7]+)$/i, (match, p0, p1) => p0 + p1), + 8 + ); + } Object.assign(result, { type: AST_NODE_TYPES.Literal, - value: Number(node.text), - raw: ast.text.slice(result.range[0], result.range[1]) + value: value, + raw: rawValue }); break; + } case SyntaxKind.BigIntLiteral: { const raw = ast.text.slice(result.range[0], result.range[1]); diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index c8556789e1f6..2960127aecdc 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -225,6 +225,7 @@ tester.addFixturePatternConfig('javascript/forIn', { tester.addFixturePatternConfig('javascript/forOf'); tester.addFixturePatternConfig('javascript/generators'); tester.addFixturePatternConfig('javascript/globalReturn'); +tester.addFixturePatternConfig('javascript/hexLiterals'); tester.addFixturePatternConfig('javascript/importMeta'); tester.addFixturePatternConfig('javascript/labels'); diff --git a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap index 44ce6eaf9987..25148b5f226c 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap @@ -102893,6 +102893,202 @@ Object { } `; +exports[`javascript fixtures/hexLiterals/invalid.src 1`] = `"';' expected."`; + +exports[`javascript fixtures/hexLiterals/lowercase.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "raw": "0x2343", + "type": "Literal", + "value": 9027, + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Numeric", + "value": "0x2343", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + +exports[`javascript fixtures/hexLiterals/uppercase.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "raw": "0X2343", + "type": "Literal", + "value": 9027, + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Numeric", + "value": "0X2343", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`javascript fixtures/importMeta/simple-import-meta.src 1`] = ` Object { "body": Array [ @@ -126899,6 +127095,103 @@ Object { exports[`javascript fixtures/octalLiterals/invalid.src 1`] = `"';' expected."`; +exports[`javascript fixtures/octalLiterals/legacy.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "raw": "02343", + "type": "Literal", + "value": 1251, + }, + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Numeric", + "value": "02343", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 6, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`javascript fixtures/octalLiterals/lowercase.src 1`] = ` Object { "body": Array [ diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index c4739a193999..1150e2b2ba06 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -742,6 +742,19 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/globalReturn/return-true.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/hexLiterals/invalid.src 1`] = ` +Object { + "column": 4, + "index": 4, + "lineNumber": 1, + "message": "';' expected.", +} +`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/hexLiterals/lowercase.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/hexLiterals/uppercase.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/importMeta/simple-import-meta.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/labels/label-break.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; @@ -1145,6 +1158,8 @@ Object { } `; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/octalLiterals/legacy.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/octalLiterals/lowercase.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/octalLiterals/strict-uppercase.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; From 14d63d905498ec94a64d4416c1c66b50cc034d2c Mon Sep 17 00:00:00 2001 From: Armano Date: Mon, 14 Jan 2019 05:21:06 +0100 Subject: [PATCH 2/4] fix(estree): remove unneeded regexp --- packages/typescript-estree/src/convert.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index f665a2dc3622..6040a4dbfcaa 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1785,10 +1785,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal // http://www.ecma-international.org/ecma-262/6.0/#sec-additional-syntax-numeric-literals if (/^(-?)0([0-7]+)$/i.test(rawValue)) { - value = parseInt( - node.text.replace(/^(-?)0([0-7]+)$/i, (match, p0, p1) => p0 + p1), - 8 - ); + value = parseInt(node.text, 8); } Object.assign(result, { type: AST_NODE_TYPES.Literal, From d462195a8b80248148120cf96d267544c00c82f5 Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 16 Jan 2019 03:38:12 +0100 Subject: [PATCH 3/4] test(eslint-parser): add snapshots for new tests --- .../lib/__snapshots__/javascript.js.snap | 296 ++++++++++++++++++ 1 file changed, 296 insertions(+) diff --git a/packages/typescript-eslint-parser/tests/lib/__snapshots__/javascript.js.snap b/packages/typescript-eslint-parser/tests/lib/__snapshots__/javascript.js.snap index e9c04f72d828..337817c6fe2e 100644 --- a/packages/typescript-eslint-parser/tests/lib/__snapshots__/javascript.js.snap +++ b/packages/typescript-eslint-parser/tests/lib/__snapshots__/javascript.js.snap @@ -103210,6 +103210,204 @@ Object { } `; +exports[`javascript fixtures/hexLiterals/invalid.src 1`] = `"';' expected."`; + +exports[`javascript fixtures/hexLiterals/lowercase.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "raw": "0x2343", + "type": "Literal", + "value": 9027, + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Numeric", + "value": "0x2343", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + +exports[`javascript fixtures/hexLiterals/uppercase.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "raw": "0X2343", + "type": "Literal", + "value": 9027, + }, + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 8, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "Numeric", + "value": "0X2343", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 7, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`javascript fixtures/importMeta/simple-import-meta.src 1`] = ` Object { "body": Array [ @@ -127293,6 +127491,104 @@ Object { exports[`javascript fixtures/octalLiterals/invalid.src 1`] = `"';' expected."`; +exports[`javascript fixtures/octalLiterals/legacy.src 1`] = ` +Object { + "body": Array [ + Object { + "expression": Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "raw": "02343", + "type": "Literal", + "value": 2343, + }, + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 6, + ], + "type": "ExpressionStatement", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 2, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 7, + ], + "sourceType": "module", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Numeric", + "value": "02343", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 1, + }, + "start": Object { + "column": 5, + "line": 1, + }, + }, + "range": Array [ + 5, + 6, + ], + "type": "Punctuator", + "value": ";", + }, + ], + "type": "Program", +} +`; + exports[`javascript fixtures/octalLiterals/lowercase.src 1`] = ` Object { "body": Array [ From 1faf80fd1e68eceb4c2be18a7aa0b67e8745a4bc Mon Sep 17 00:00:00 2001 From: Armano Date: Wed, 16 Jan 2019 21:27:02 +0100 Subject: [PATCH 4/4] test(typescript-estree): enable TS1085 and TS8017 error codes --- .../lib/__snapshots__/javascript.ts.snap | 32 ++++++++--------- .../arrowFunctions/not-strict-octal.src.js | 2 +- packages/typescript-estree/src/convert.ts | 11 ++---- .../typescript-estree/src/semantic-errors.ts | 2 ++ .../tests/ast-alignment/fixtures-to-test.ts | 14 +++++--- .../lib/__snapshots__/javascript.ts.snap | 34 +++++++++---------- .../semantic-diagnostics-enabled.ts.snap | 9 ++++- 7 files changed, 56 insertions(+), 48 deletions(-) diff --git a/packages/typescript-eslint-parser/tests/lib/__snapshots__/javascript.ts.snap b/packages/typescript-eslint-parser/tests/lib/__snapshots__/javascript.ts.snap index 337817c6fe2e..bb1a15c2bdb6 100644 --- a/packages/typescript-eslint-parser/tests/lib/__snapshots__/javascript.ts.snap +++ b/packages/typescript-eslint-parser/tests/lib/__snapshots__/javascript.ts.snap @@ -8081,7 +8081,7 @@ Object { "body": Object { "loc": Object { "end": Object { - "column": 9, + "column": 10, "line": 1, }, "start": Object { @@ -8091,9 +8091,9 @@ Object { }, "range": Array [ 7, - 9, + 10, ], - "raw": "00", + "raw": "0o0", "type": "Literal", "value": 0, }, @@ -8102,7 +8102,7 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 9, + "column": 10, "line": 1, }, "start": Object { @@ -8132,13 +8132,13 @@ Object { ], "range": Array [ 0, - 9, + 10, ], "type": "ArrowFunctionExpression", }, "loc": Object { "end": Object { - "column": 10, + "column": 11, "line": 1, }, "start": Object { @@ -8148,7 +8148,7 @@ Object { }, "range": Array [ 0, - 10, + 11, ], "type": "ExpressionStatement", }, @@ -8156,8 +8156,8 @@ Object { "comments": Array [], "loc": Object { "end": Object { - "column": 10, - "line": 1, + "column": 0, + "line": 2, }, "start": Object { "column": 0, @@ -8166,7 +8166,7 @@ Object { }, "range": Array [ 0, - 10, + 12, ], "sourceType": "module", "tokens": Array [ @@ -8245,7 +8245,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 9, + "column": 10, "line": 1, }, "start": Object { @@ -8255,25 +8255,25 @@ Object { }, "range": Array [ 7, - 9, + 10, ], "type": "Numeric", - "value": "00", + "value": "0o0", }, Object { "loc": Object { "end": Object { - "column": 10, + "column": 11, "line": 1, }, "start": Object { - "column": 9, + "column": 10, "line": 1, }, }, "range": Array [ - 9, 10, + 11, ], "type": "Punctuator", "value": ";", diff --git a/packages/typescript-eslint-shared-fixtures/fixtures/javascript/arrowFunctions/not-strict-octal.src.js b/packages/typescript-eslint-shared-fixtures/fixtures/javascript/arrowFunctions/not-strict-octal.src.js index 0e6918d7d43c..dd77023f6314 100644 --- a/packages/typescript-eslint-shared-fixtures/fixtures/javascript/arrowFunctions/not-strict-octal.src.js +++ b/packages/typescript-eslint-shared-fixtures/fixtures/javascript/arrowFunctions/not-strict-octal.src.js @@ -1 +1 @@ -(a) => 00; \ No newline at end of file +(a) => 0o0; diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 6040a4dbfcaa..10b9ed3c8d4f 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1780,17 +1780,10 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { break; case SyntaxKind.NumericLiteral: { - const rawValue = node.getText(); - let value = Number(node.text); - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Deprecated_octal - // http://www.ecma-international.org/ecma-262/6.0/#sec-additional-syntax-numeric-literals - if (/^(-?)0([0-7]+)$/i.test(rawValue)) { - value = parseInt(node.text, 8); - } Object.assign(result, { type: AST_NODE_TYPES.Literal, - value: value, - raw: rawValue + value: Number(node.text), + raw: node.getText() }); break; } diff --git a/packages/typescript-estree/src/semantic-errors.ts b/packages/typescript-estree/src/semantic-errors.ts index 9465037a0b0d..22e8210ba55d 100644 --- a/packages/typescript-estree/src/semantic-errors.ts +++ b/packages/typescript-estree/src/semantic-errors.ts @@ -61,6 +61,7 @@ function whitelistSupportedDiagnostics( case 1049: // ts 3.2 "A 'set' accessor must have exactly one parameter." case 1070: // ts 3.2 "'{0}' modifier cannot appear on a type member." case 1071: // ts 3.2 "'{0}' modifier cannot appear on an index signature." + case 1085: // ts 3.2 "Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '{0}'." case 1090: // ts 3.2 "'{0}' modifier cannot appear on a parameter." case 1096: // ts 3.2 "An index signature must have exactly one parameter." case 1097: // ts 3.2 "'{0}' list cannot be empty." @@ -83,6 +84,7 @@ function whitelistSupportedDiagnostics( case 2364: // ts 3.2 "The left-hand side of an assignment expression must be a variable or a property access." case 2369: // ts 3.2 "A parameter property is only allowed in a constructor implementation." case 2462: // ts 3.2 "A rest element must be last in a destructuring pattern." + case 8017: // ts 3.2 "Octal literal types must use ES2015 syntax. Use the syntax '{0}'." case 17012: // ts 3.2 "'{0}' is not a valid meta-property for keyword '{1}'. Did you mean '{2}'?" case 17013: // ts 3.2 "Meta-property '{0}' is only allowed in the body of a function declaration, function expression, or constructor." return true; diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index a1103a3fff3b..59210d587f95 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -91,7 +91,7 @@ class FixturesTester { } public getFixtures(): Fixture[] { - const fixtures = this.fixtures + return this.fixtures .map(fixture => glob .sync(`${fixture.directory}/${fixture.pattern}`, {}) @@ -102,8 +102,6 @@ class FixturesTester { })) ) .reduce((acc, x) => acc.concat(x), []); - - return fixtures; } } @@ -265,7 +263,15 @@ tester.addFixturePatternConfig('javascript/objectLiteralDuplicateProperties', { tester.addFixturePatternConfig('javascript/objectLiteralShorthandMethods'); tester.addFixturePatternConfig('javascript/objectLiteralShorthandProperties'); -tester.addFixturePatternConfig('javascript/octalLiterals'); +tester.addFixturePatternConfig('javascript/octalLiterals', { + ignore: [ + /** + * Old-style octal literals are not supported in typescript + * @see https://github.com/Microsoft/TypeScript/issues/10101 + */ + 'legacy' + ] +}); tester.addFixturePatternConfig('javascript/regex'); tester.addFixturePatternConfig('javascript/regexUFlag'); tester.addFixturePatternConfig('javascript/regexYFlag'); diff --git a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap index 25148b5f226c..eb2eb8f6f916 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/javascript.ts.snap @@ -8054,7 +8054,7 @@ Object { "body": Object { "loc": Object { "end": Object { - "column": 9, + "column": 10, "line": 1, }, "start": Object { @@ -8064,9 +8064,9 @@ Object { }, "range": Array [ 7, - 9, + 10, ], - "raw": "00", + "raw": "0o0", "type": "Literal", "value": 0, }, @@ -8075,7 +8075,7 @@ Object { "id": null, "loc": Object { "end": Object { - "column": 9, + "column": 10, "line": 1, }, "start": Object { @@ -8105,13 +8105,13 @@ Object { ], "range": Array [ 0, - 9, + 10, ], "type": "ArrowFunctionExpression", }, "loc": Object { "end": Object { - "column": 10, + "column": 11, "line": 1, }, "start": Object { @@ -8121,15 +8121,15 @@ Object { }, "range": Array [ 0, - 10, + 11, ], "type": "ExpressionStatement", }, ], "loc": Object { "end": Object { - "column": 10, - "line": 1, + "column": 0, + "line": 2, }, "start": Object { "column": 0, @@ -8138,7 +8138,7 @@ Object { }, "range": Array [ 0, - 10, + 12, ], "sourceType": "script", "tokens": Array [ @@ -8217,7 +8217,7 @@ Object { Object { "loc": Object { "end": Object { - "column": 9, + "column": 10, "line": 1, }, "start": Object { @@ -8227,25 +8227,25 @@ Object { }, "range": Array [ 7, - 9, + 10, ], "type": "Numeric", - "value": "00", + "value": "0o0", }, Object { "loc": Object { "end": Object { - "column": 10, + "column": 11, "line": 1, }, "start": Object { - "column": 9, + "column": 10, "line": 1, }, }, "range": Array [ - 9, 10, + 11, ], "type": "Punctuator", "value": ";", @@ -127116,7 +127116,7 @@ Object { ], "raw": "02343", "type": "Literal", - "value": 1251, + "value": 2343, }, "loc": Object { "end": Object { diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap index bdd65e6c15f4..3407f292ace2 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap @@ -1158,7 +1158,14 @@ Object { } `; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/octalLiterals/legacy.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/octalLiterals/legacy.src 1`] = ` +Object { + "column": 0, + "index": 0, + "lineNumber": 1, + "message": "Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o2343'.", +} +`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/octalLiterals/lowercase.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;