@@ -31,6 +31,8 @@ import {
31
31
VForExpression ,
32
32
VOnExpression ,
33
33
VSlotScopeExpression ,
34
+ OffsetRange ,
35
+ LocationRange ,
34
36
} from "../ast"
35
37
import { debug } from "../common/debug"
36
38
import { LocationCalculator } from "../common/location-calculator"
@@ -66,7 +68,7 @@ function postprocess(
66
68
) : void {
67
69
// There are cases which the same node instance appears twice in the tree.
68
70
// E.g. `let {a} = {}` // This `a` appears twice at `Property#key` and `Property#value`.
69
- const traversed = new Set < Node | number [ ] > ( )
71
+ const traversed = new Set < Node | number [ ] | LocationRange > ( )
70
72
71
73
traverseNodes ( result . ast , {
72
74
visitorKeys : result . visitorKeys ,
@@ -78,9 +80,22 @@ function postprocess(
78
80
79
81
// `babel-eslint@8` has shared `Node#range` with multiple nodes.
80
82
// See also: https://github.com/vuejs/eslint-plugin-vue/issues/208
81
- if ( ! traversed . has ( node . range ) ) {
82
- traversed . add ( node . range )
83
+ if ( traversed . has ( node . range ) ) {
84
+ if ( ! traversed . has ( node . loc ) ) {
85
+ // However, `Node#loc` may not be shared.
86
+ // See also: https://github.com/vuejs/vue-eslint-parser/issues/84
87
+ node . loc . start = locationCalculator . getLocFromIndex (
88
+ node . range [ 0 ] ,
89
+ )
90
+ node . loc . end = locationCalculator . getLocFromIndex (
91
+ node . range [ 1 ] ,
92
+ )
93
+ traversed . add ( node . loc )
94
+ }
95
+ } else {
83
96
locationCalculator . fixLocation ( node )
97
+ traversed . add ( node . range )
98
+ traversed . add ( node . loc )
84
99
}
85
100
}
86
101
} ,
@@ -139,7 +154,7 @@ function normalizeLeft(
139
154
*/
140
155
function getCommaTokenBeforeNode ( tokens : Token [ ] , node : Node ) : Token | null {
141
156
let tokenIndex = sortedIndexBy (
142
- tokens ,
157
+ tokens as { range : OffsetRange } [ ] ,
143
158
{ range : node . range } ,
144
159
t => t . range [ 0 ] ,
145
160
)
@@ -563,7 +578,6 @@ export function parseScript(
563
578
require ( parserOptions . parser )
564
579
: getEspree ( )
565
580
const result : any =
566
- // eslint-disable-next-line @mysticatea/ts/unbound-method
567
581
typeof parser . parseForESLint === "function"
568
582
? parser . parseForESLint ( code , parserOptions )
569
583
: parser . parse ( code , parserOptions )
0 commit comments