From b9e99151f70f291dd21dad16be111a61f6a55819 Mon Sep 17 00:00:00 2001 From: James Henry Date: Mon, 21 Jan 2019 17:46:20 -0500 Subject: [PATCH 1/2] test(typescript-estree): enable more alignment tests --- package.json | 2 +- .../tests/ast-alignment/fixtures-to-test.ts | 69 +++++-------------- yarn.lock | 8 +-- 3 files changed, 21 insertions(+), 58 deletions(-) diff --git a/package.json b/package.json index ed6bbf422c9e..c7a27e9a643d 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "devDependencies": { "@babel/code-frame": "7.0.0", - "@babel/parser": "7.2.3", + "@babel/parser": "7.3.0", "@commitlint/cli": "^7.1.2", "@commitlint/config-conventional": "^7.1.2", "@commitlint/travis-cli": "^7.1.2", 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 178b86573537..be7e4c72cab0 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -197,7 +197,14 @@ tester.addFixturePatternConfig('javascript/destructuring-and-arrowFunctions'); tester.addFixturePatternConfig('javascript/destructuring-and-blockBindings'); tester.addFixturePatternConfig('javascript/destructuring-and-defaultParams'); tester.addFixturePatternConfig('javascript/destructuring-and-forOf'); -tester.addFixturePatternConfig('javascript/destructuring-and-spread'); +tester.addFixturePatternConfig('javascript/destructuring-and-spread', { + ignore: [ + /** + * Trailing comma is not permitted after a "RestElement" in Babel + */ + 'invalid-not-final-array-empty' + ] +}); tester.addFixturePatternConfig('javascript/experimentalAsyncIteration'); tester.addFixturePatternConfig('javascript/experimentalDynamicImport'); @@ -330,16 +337,6 @@ tester.addFixturePatternConfig('typescript/basics', { * TODO: Investigate in more depth, potentially split up different parts of the interface */ 'interface-with-all-property-types', // babel parse errors - /** - * PR for generic ArrowFunctionExpression ranges has been merged into Babel: https://github.com/babel/babel/pull/9295 - * TODO: remove me in next babel > 7.2.3 - */ - 'arrow-function-with-type-parameters', - /** - * PR for this type predicate ranges has been merged into Babel: https://github.com/babel/babel/pull/9339 - * TODO: remove me in next babel > 7.2.3 - */ - 'type-guard-in-method', /** * there is difference in range between babel and ts-estree */ @@ -351,11 +348,6 @@ tester.addFixturePatternConfig('typescript/basics', { * TODO: report it to babel */ 'interface-with-extends-member-expression', - /** - * PR for parsing exported abstract interface has been merged into Babel: https://github.com/babel/babel/pull/9336 - * TODO: remove me in next babel > 7.2.3 - */ - 'abstract-interface', /** * Babel bug for optional or abstract methods * https://github.com/babel/babel/issues/9305 @@ -364,46 +356,32 @@ tester.addFixturePatternConfig('typescript/basics', { 'abstract-class-with-optional-method', // babel parse errors 'declare-class-with-optional-method', // babel parse errors /** - * PR for parameter property ranges has been merged into Babel: https://github.com/babel/babel/pull/9284 - * TODO: remove me in next babel > 7.2.3 + * Was expected to be fixed by PR into Babel: https://github.com/babel/babel/pull/9284 + * But not fixed in Babel 7.3 + * TODO: Investigate differences */ 'class-with-private-parameter-properties', 'class-with-protected-parameter-properties', 'class-with-public-parameter-properties', 'class-with-readonly-parameter-properties', /** - * PR for type import has been merged into Babel: https://github.com/babel/babel/pull/9302 - * TODO: remove me in next babel > 7.2.3 + * Was expected to be fixed by PR into Babel: https://github.com/babel/babel/pull/9302 + * But not fixed in Babel 7.3 + * TODO: Investigate differences */ 'import-type', 'import-type-with-type-parameters-in-type-reference', - /** - * PR for BigInt support has been merged into Babel: https://github.com/babel/babel/pull/9230 - * TODO: remove me in next babel > 7.2.3 - */ - 'typed-keyword-bigint', /** * Not yet supported in Babel https://github.com/babel/babel/issues/9228 * Directive field is not added to module and namespace */ 'directive-in-module', 'directive-in-namespace', - /** - * PR for type assertions ranges has been merged into Babel: https://github.com/babel/babel/pull/9284 - * TODO: remove me in next babel > 7.2.3 - */ - 'type-assertion', /** * Babel parses this incorrectly * https://github.com/babel/babel/issues/9324 */ - 'type-assertion-arrow-function', - /** - * PR for type parsing declare and abstract classes has been merged into Babel: https://github.com/babel/babel/pull/9328 - * TODO: remove me in next babel > 7.2.3 - */ - 'class-multi-line-keyword-declare', - 'class-multi-line-keyword-abstract' + 'type-assertion-arrow-function' ], ignoreSourceType: [ /** @@ -443,27 +421,12 @@ tester.addFixturePatternConfig('typescript/expressions', { }); tester.addFixturePatternConfig('typescript/errorRecovery', { - fileType: 'ts', - ignore: [ - /** - * PR with errors in empty extends and implements has been merged into Babel: https://github.com/babel/babel/pull/9292 - * TODO: remove me in next babel > 7.2.3 - */ - 'interface-empty-extends', - 'class-extends-empty-implements' - ] + fileType: 'ts' }); tester.addFixturePatternConfig('typescript/types', { fileType: 'ts', ignore: [ - /** - * PR for type Identifier in TSIndexSignature ranges has been merged into Babel: https://github.com/babel/babel/pull/9335 - * TODO: remove me in next babel > 7.2.3 - */ - 'index-signature', - 'index-signature-readonly', - 'index-signature-without-type', /** * AST difference */ diff --git a/yarn.lock b/yarn.lock index a80ac0413712..e2d917cdc557 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18,10 +18,10 @@ esutils "^2.0.2" js-tokens "^4.0.0" -"@babel/parser@7.2.3": - version "7.2.3" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.2.3.tgz#32f5df65744b70888d17872ec106b02434ba1489" - integrity sha512-0LyEcVlfCoFmci8mXx8A5oIkpkOgyo8dRHtxBnK9RRBwxO2+JZPNsqtVEZQ7mJFPxnXF9lfmU24mHOPI0qnlkA== +"@babel/parser@7.3.0": + version "7.3.0" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.3.0.tgz#930251fe6714df47ce540a919ccdf6dcfb652b61" + integrity sha512-8M30TzMpLHGmuthHZStm4F+az5wxyYeh8U+LWK7+b2qnlQ0anXBmOQ1I8DCMV1K981wPY3C3kWZ4SA1lR3Y3xQ== "@commitlint/cli@^7.1.2", "@commitlint/cli@^7.3.2": version "7.3.2" From c4a384385ea487090e245b99528df196df9eb000 Mon Sep 17 00:00:00 2001 From: James Henry Date: Mon, 21 Jan 2019 17:57:00 -0500 Subject: [PATCH 2/2] feat(typescript-estree): report on TS 1013 --- .../typescript-estree/src/semantic-errors.ts | 1 + .../tests/ast-alignment/fixtures-to-test.ts | 18 ++---------------- .../semantic-diagnostics-enabled.ts.snap | 18 ++++++++++++++++-- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/typescript-estree/src/semantic-errors.ts b/packages/typescript-estree/src/semantic-errors.ts index 22e8210ba55d..169031947d3f 100644 --- a/packages/typescript-estree/src/semantic-errors.ts +++ b/packages/typescript-estree/src/semantic-errors.ts @@ -54,6 +54,7 @@ function whitelistSupportedDiagnostics( ): ReadonlyArray { return diagnostics.filter(diagnostic => { switch (diagnostic.code) { + case 1013: // ts 3.2 "A rest parameter or binding pattern may not have a trailing comma." case 1014: // ts 3.2 "A rest parameter must be last in a parameter list." case 1044: // ts 3.2 "'{0}' modifier cannot appear on a module or namespace element." case 1045: // ts 3.2 "A '{0}' modifier cannot be used with an interface declaration." 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 be7e4c72cab0..2e478b0fb1b1 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -147,14 +147,7 @@ tester.addFixturePatternConfig('javascript/simple-literals'); tester.addFixturePatternConfig('javascript/directives'); -tester.addFixturePatternConfig('javascript/experimentalObjectRestSpread', { - ignore: [ - /** - * Trailing comma is not permitted after a "RestElement" in Babel - */ - 'invalid-rest-trailing-comma' - ] -}); +tester.addFixturePatternConfig('javascript/experimentalObjectRestSpread'); tester.addFixturePatternConfig('javascript/arrowFunctions', { ignore: [ @@ -197,14 +190,7 @@ tester.addFixturePatternConfig('javascript/destructuring-and-arrowFunctions'); tester.addFixturePatternConfig('javascript/destructuring-and-blockBindings'); tester.addFixturePatternConfig('javascript/destructuring-and-defaultParams'); tester.addFixturePatternConfig('javascript/destructuring-and-forOf'); -tester.addFixturePatternConfig('javascript/destructuring-and-spread', { - ignore: [ - /** - * Trailing comma is not permitted after a "RestElement" in Babel - */ - 'invalid-not-final-array-empty' - ] -}); +tester.addFixturePatternConfig('javascript/destructuring-and-spread'); tester.addFixturePatternConfig('javascript/experimentalAsyncIteration'); tester.addFixturePatternConfig('javascript/experimentalDynamicImport'); 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 3407f292ace2..dfd7dbf783d0 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 @@ -560,7 +560,14 @@ Object { } `; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/destructuring-and-spread/invalid-not-final-array-empty.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/destructuring-and-spread/invalid-not-final-array-empty.src 1`] = ` +Object { + "column": 5, + "index": 5, + "lineNumber": 1, + "message": "A rest parameter or binding pattern may not have a trailing comma.", +} +`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/destructuring-and-spread/multi-destructured.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; @@ -622,7 +629,14 @@ Object { } `; -exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/experimentalObjectRestSpread/invalid-rest-trailing-comma.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/experimentalObjectRestSpread/invalid-rest-trailing-comma.src 1`] = ` +Object { + "column": 16, + "index": 16, + "lineNumber": 1, + "message": "A rest parameter or binding pattern may not have a trailing comma.", +} +`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/experimentalObjectRestSpread/object-rest.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;