Skip to content

Commit 4e781f1

Browse files
armano2JamesHenry
authored andcommitted
fix(typescript-estree): fix range of assignment in parameter (#115)
1 parent 5841cd2 commit 4e781f1

File tree

5 files changed

+35
-38
lines changed

5 files changed

+35
-38
lines changed

packages/parser/tests/lib/__snapshots__/typescript.ts.snap

+14-14
Original file line numberDiff line numberDiff line change
@@ -21333,12 +21333,12 @@ Object {
2133321333
"line": 4,
2133421334
},
2133521335
"start": Object {
21336-
"column": 14,
21336+
"column": 22,
2133721337
"line": 4,
2133821338
},
2133921339
},
2134021340
"range": Array [
21341-
116,
21341+
124,
2134221342
140,
2134321343
],
2134421344
"right": Object {
@@ -21439,12 +21439,12 @@ Object {
2143921439
"line": 5,
2144021440
},
2144121441
"start": Object {
21442-
"column": 14,
21442+
"column": 31,
2144321443
"line": 5,
2144421444
},
2144521445
},
2144621446
"range": Array [
21447-
156,
21447+
173,
2144821448
197,
2144921449
],
2145021450
"right": Object {
@@ -24453,12 +24453,12 @@ Object {
2445324453
"line": 4,
2445424454
},
2445524455
"start": Object {
24456-
"column": 14,
24456+
"column": 24,
2445724457
"line": 4,
2445824458
},
2445924459
},
2446024460
"range": Array [
24461-
120,
24461+
130,
2446224462
146,
2446324463
],
2446424464
"right": Object {
@@ -24559,12 +24559,12 @@ Object {
2455924559
"line": 5,
2456024560
},
2456124561
"start": Object {
24562-
"column": 14,
24562+
"column": 33,
2456324563
"line": 5,
2456424564
},
2456524565
},
2456624566
"range": Array [
24567-
162,
24567+
181,
2456824568
205,
2456924569
],
2457024570
"right": Object {
@@ -25579,12 +25579,12 @@ Object {
2557925579
"line": 4,
2558025580
},
2558125581
"start": Object {
25582-
"column": 14,
25582+
"column": 21,
2558325583
"line": 4,
2558425584
},
2558525585
},
2558625586
"range": Array [
25587-
114,
25587+
121,
2558825588
137,
2558925589
],
2559025590
"right": Object {
@@ -25685,12 +25685,12 @@ Object {
2568525685
"line": 5,
2568625686
},
2568725687
"start": Object {
25688-
"column": 14,
25688+
"column": 30,
2568925689
"line": 5,
2569025690
},
2569125691
},
2569225692
"range": Array [
25693-
153,
25693+
169,
2569425694
193,
2569525695
],
2569625696
"right": Object {
@@ -26633,12 +26633,12 @@ Object {
2663326633
"line": 3,
2663426634
},
2663526635
"start": Object {
26636-
"column": 14,
26636+
"column": 23,
2663726637
"line": 3,
2663826638
},
2663926639
},
2664026640
"range": Array [
26641-
68,
26641+
77,
2664226642
103,
2664326643
],
2664426644
"right": Object {

packages/typescript-estree/src/convert.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,12 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
13181318
left: parameter,
13191319
right: convertChild(node.initializer)
13201320
});
1321+
1322+
if (node.modifiers) {
1323+
// AssignmentPattern should not contain modifiers in range
1324+
result.range[0] = parameter.range[0];
1325+
result.loc = getLocFor(result.range[0], result.range[1], ast);
1326+
}
13211327
} else {
13221328
parameter = result = convert({
13231329
node: node.name,

packages/typescript-estree/src/node-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export function hasModifier(
161161
* @param node TypeScript AST node
162162
* @returns returns last modifier if present or null
163163
*/
164-
export function getLastModifier(node: ts.Node): ts.Node | null {
164+
export function getLastModifier(node: ts.Node): ts.Modifier | null {
165165
return (
166166
(!!node.modifiers &&
167167
!!node.modifiers.length &&

packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts

-9
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,6 @@ tester.addFixturePatternConfig('typescript/basics', {
341341
'abstract-class-with-abstract-method', // babel parse errors
342342
'abstract-class-with-optional-method', // babel parse errors
343343
'declare-class-with-optional-method', // babel parse errors
344-
/**
345-
* Was expected to be fixed by PR into Babel: https://github.com/babel/babel/pull/9284
346-
* But not fixed in Babel 7.3
347-
* TODO: Investigate differences
348-
*/
349-
'class-with-private-parameter-properties',
350-
'class-with-protected-parameter-properties',
351-
'class-with-public-parameter-properties',
352-
'class-with-readonly-parameter-properties',
353344
/**
354345
* Was expected to be fixed by PR into Babel: https://github.com/babel/babel/pull/9302
355346
* But not fixed in Babel 7.3

packages/typescript-estree/tests/lib/__snapshots__/typescript.ts.snap

+14-14
Original file line numberDiff line numberDiff line change
@@ -21291,12 +21291,12 @@ Object {
2129121291
"line": 4,
2129221292
},
2129321293
"start": Object {
21294-
"column": 14,
21294+
"column": 22,
2129521295
"line": 4,
2129621296
},
2129721297
},
2129821298
"range": Array [
21299-
116,
21299+
124,
2130021300
140,
2130121301
],
2130221302
"right": Object {
@@ -21397,12 +21397,12 @@ Object {
2139721397
"line": 5,
2139821398
},
2139921399
"start": Object {
21400-
"column": 14,
21400+
"column": 31,
2140121401
"line": 5,
2140221402
},
2140321403
},
2140421404
"range": Array [
21405-
156,
21405+
173,
2140621406
197,
2140721407
],
2140821408
"right": Object {
@@ -24408,12 +24408,12 @@ Object {
2440824408
"line": 4,
2440924409
},
2441024410
"start": Object {
24411-
"column": 14,
24411+
"column": 24,
2441224412
"line": 4,
2441324413
},
2441424414
},
2441524415
"range": Array [
24416-
120,
24416+
130,
2441724417
146,
2441824418
],
2441924419
"right": Object {
@@ -24514,12 +24514,12 @@ Object {
2451424514
"line": 5,
2451524515
},
2451624516
"start": Object {
24517-
"column": 14,
24517+
"column": 33,
2451824518
"line": 5,
2451924519
},
2452024520
},
2452124521
"range": Array [
24522-
162,
24522+
181,
2452324523
205,
2452424524
],
2452524525
"right": Object {
@@ -25533,12 +25533,12 @@ Object {
2553325533
"line": 4,
2553425534
},
2553525535
"start": Object {
25536-
"column": 14,
25536+
"column": 21,
2553725537
"line": 4,
2553825538
},
2553925539
},
2554025540
"range": Array [
25541-
114,
25541+
121,
2554225542
137,
2554325543
],
2554425544
"right": Object {
@@ -25639,12 +25639,12 @@ Object {
2563925639
"line": 5,
2564025640
},
2564125641
"start": Object {
25642-
"column": 14,
25642+
"column": 30,
2564325643
"line": 5,
2564425644
},
2564525645
},
2564625646
"range": Array [
25647-
153,
25647+
169,
2564825648
193,
2564925649
],
2565025650
"right": Object {
@@ -26586,12 +26586,12 @@ Object {
2658626586
"line": 3,
2658726587
},
2658826588
"start": Object {
26589-
"column": 14,
26589+
"column": 23,
2659026590
"line": 3,
2659126591
},
2659226592
},
2659326593
"range": Array [
26594-
68,
26594+
77,
2659526595
103,
2659626596
],
2659726597
"right": Object {

0 commit comments

Comments
 (0)