From 0a1c22de7941dcfcf3e1835e58dc43eeb2a2d2d7 Mon Sep 17 00:00:00 2001 From: Armano Date: Tue, 22 Jan 2019 00:58:05 +0100 Subject: [PATCH 1/2] fix(typescript-estree): fix range of assignment in parameter --- packages/typescript-estree/src/convert.ts | 6 ++++ packages/typescript-estree/src/node-utils.ts | 2 +- .../tests/ast-alignment/fixtures-to-test.ts | 9 ------ .../lib/__snapshots__/typescript.ts.snap | 28 +++++++++---------- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index f75547953df8..998e48c23009 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -1318,6 +1318,12 @@ export default function convert(config: ConvertConfig): ESTreeNode | null { left: parameter, right: convertChild(node.initializer) }); + + if (node.modifiers) { + // AssignmentPattern should not contain modifiers in range + result.range[0] = parameter.range[0]; + result.loc = getLocFor(result.range[0], result.range[1], ast); + } } else { parameter = result = convert({ node: node.name, diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 678c97215fa0..fa780cfe8e97 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -161,7 +161,7 @@ export function hasModifier( * @param node TypeScript AST node * @returns returns last modifier if present or null */ -export function getLastModifier(node: ts.Node): ts.Node | null { +export function getLastModifier(node: ts.Node): ts.Modifier | null { return ( (!!node.modifiers && !!node.modifiers.length && 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 2e478b0fb1b1..3b1a21e43d80 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -341,15 +341,6 @@ tester.addFixturePatternConfig('typescript/basics', { 'abstract-class-with-abstract-method', // babel parse errors 'abstract-class-with-optional-method', // babel parse errors 'declare-class-with-optional-method', // babel parse errors - /** - * 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', /** * Was expected to be fixed by PR into Babel: https://github.com/babel/babel/pull/9302 * But not fixed in Babel 7.3 diff --git a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap index 5ad5989309a8..6341ffcd7d74 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap @@ -21291,12 +21291,12 @@ Object { "line": 4, }, "start": Object { - "column": 14, + "column": 22, "line": 4, }, }, "range": Array [ - 116, + 124, 140, ], "right": Object { @@ -21397,12 +21397,12 @@ Object { "line": 5, }, "start": Object { - "column": 14, + "column": 31, "line": 5, }, }, "range": Array [ - 156, + 173, 197, ], "right": Object { @@ -24408,12 +24408,12 @@ Object { "line": 4, }, "start": Object { - "column": 14, + "column": 24, "line": 4, }, }, "range": Array [ - 120, + 130, 146, ], "right": Object { @@ -24514,12 +24514,12 @@ Object { "line": 5, }, "start": Object { - "column": 14, + "column": 33, "line": 5, }, }, "range": Array [ - 162, + 181, 205, ], "right": Object { @@ -25533,12 +25533,12 @@ Object { "line": 4, }, "start": Object { - "column": 14, + "column": 21, "line": 4, }, }, "range": Array [ - 114, + 121, 137, ], "right": Object { @@ -25639,12 +25639,12 @@ Object { "line": 5, }, "start": Object { - "column": 14, + "column": 30, "line": 5, }, }, "range": Array [ - 153, + 169, 193, ], "right": Object { @@ -26586,12 +26586,12 @@ Object { "line": 3, }, "start": Object { - "column": 14, + "column": 23, "line": 3, }, }, "range": Array [ - 68, + 77, 103, ], "right": Object { From bbe4a9b13caff93da2203fc7f883a29bb853455a Mon Sep 17 00:00:00 2001 From: Armano Date: Tue, 22 Jan 2019 01:16:54 +0100 Subject: [PATCH 2/2] test(parser): update parser snapshots --- .../lib/__snapshots__/typescript.ts.snap | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap index b1013b958c11..046f4e2081a2 100644 --- a/packages/parser/tests/lib/__snapshots__/typescript.ts.snap +++ b/packages/parser/tests/lib/__snapshots__/typescript.ts.snap @@ -21333,12 +21333,12 @@ Object { "line": 4, }, "start": Object { - "column": 14, + "column": 22, "line": 4, }, }, "range": Array [ - 116, + 124, 140, ], "right": Object { @@ -21439,12 +21439,12 @@ Object { "line": 5, }, "start": Object { - "column": 14, + "column": 31, "line": 5, }, }, "range": Array [ - 156, + 173, 197, ], "right": Object { @@ -24453,12 +24453,12 @@ Object { "line": 4, }, "start": Object { - "column": 14, + "column": 24, "line": 4, }, }, "range": Array [ - 120, + 130, 146, ], "right": Object { @@ -24559,12 +24559,12 @@ Object { "line": 5, }, "start": Object { - "column": 14, + "column": 33, "line": 5, }, }, "range": Array [ - 162, + 181, 205, ], "right": Object { @@ -25579,12 +25579,12 @@ Object { "line": 4, }, "start": Object { - "column": 14, + "column": 21, "line": 4, }, }, "range": Array [ - 114, + 121, 137, ], "right": Object { @@ -25685,12 +25685,12 @@ Object { "line": 5, }, "start": Object { - "column": 14, + "column": 30, "line": 5, }, }, "range": Array [ - 153, + 169, 193, ], "right": Object { @@ -26633,12 +26633,12 @@ Object { "line": 3, }, "start": Object { - "column": 14, + "column": 23, "line": 3, }, }, "range": Array [ - 68, + 77, 103, ], "right": Object {