Skip to content

Commit

Permalink
fix(typescript-estree): fix range of assignment in parameter (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 authored and JamesHenry committed Jan 22, 2019
1 parent 5841cd2 commit 4e781f1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 38 deletions.
28 changes: 14 additions & 14 deletions packages/parser/tests/lib/__snapshots__/typescript.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21333,12 +21333,12 @@ Object {
"line": 4,
},
"start": Object {
"column": 14,
"column": 22,
"line": 4,
},
},
"range": Array [
116,
124,
140,
],
"right": Object {
Expand Down Expand Up @@ -21439,12 +21439,12 @@ Object {
"line": 5,
},
"start": Object {
"column": 14,
"column": 31,
"line": 5,
},
},
"range": Array [
156,
173,
197,
],
"right": Object {
Expand Down Expand Up @@ -24453,12 +24453,12 @@ Object {
"line": 4,
},
"start": Object {
"column": 14,
"column": 24,
"line": 4,
},
},
"range": Array [
120,
130,
146,
],
"right": Object {
Expand Down Expand Up @@ -24559,12 +24559,12 @@ Object {
"line": 5,
},
"start": Object {
"column": 14,
"column": 33,
"line": 5,
},
},
"range": Array [
162,
181,
205,
],
"right": Object {
Expand Down Expand Up @@ -25579,12 +25579,12 @@ Object {
"line": 4,
},
"start": Object {
"column": 14,
"column": 21,
"line": 4,
},
},
"range": Array [
114,
121,
137,
],
"right": Object {
Expand Down Expand Up @@ -25685,12 +25685,12 @@ Object {
"line": 5,
},
"start": Object {
"column": 14,
"column": 30,
"line": 5,
},
},
"range": Array [
153,
169,
193,
],
"right": Object {
Expand Down Expand Up @@ -26633,12 +26633,12 @@ Object {
"line": 3,
},
"start": Object {
"column": 14,
"column": 23,
"line": 3,
},
},
"range": Array [
68,
77,
103,
],
"right": Object {
Expand Down
6 changes: 6 additions & 0 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-estree/src/node-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21291,12 +21291,12 @@ Object {
"line": 4,
},
"start": Object {
"column": 14,
"column": 22,
"line": 4,
},
},
"range": Array [
116,
124,
140,
],
"right": Object {
Expand Down Expand Up @@ -21397,12 +21397,12 @@ Object {
"line": 5,
},
"start": Object {
"column": 14,
"column": 31,
"line": 5,
},
},
"range": Array [
156,
173,
197,
],
"right": Object {
Expand Down Expand Up @@ -24408,12 +24408,12 @@ Object {
"line": 4,
},
"start": Object {
"column": 14,
"column": 24,
"line": 4,
},
},
"range": Array [
120,
130,
146,
],
"right": Object {
Expand Down Expand Up @@ -24514,12 +24514,12 @@ Object {
"line": 5,
},
"start": Object {
"column": 14,
"column": 33,
"line": 5,
},
},
"range": Array [
162,
181,
205,
],
"right": Object {
Expand Down Expand Up @@ -25533,12 +25533,12 @@ Object {
"line": 4,
},
"start": Object {
"column": 14,
"column": 21,
"line": 4,
},
},
"range": Array [
114,
121,
137,
],
"right": Object {
Expand Down Expand Up @@ -25639,12 +25639,12 @@ Object {
"line": 5,
},
"start": Object {
"column": 14,
"column": 30,
"line": 5,
},
},
"range": Array [
153,
169,
193,
],
"right": Object {
Expand Down Expand Up @@ -26586,12 +26586,12 @@ Object {
"line": 3,
},
"start": Object {
"column": 14,
"column": 23,
"line": 3,
},
},
"range": Array [
68,
77,
103,
],
"right": Object {
Expand Down

0 comments on commit 4e781f1

Please sign in to comment.