@@ -31,6 +31,8 @@ import {
3131 VForExpression ,
3232 VOnExpression ,
3333 VSlotScopeExpression ,
34+ OffsetRange ,
35+ LocationRange ,
3436} from "../ast"
3537import { debug } from "../common/debug"
3638import { LocationCalculator } from "../common/location-calculator"
@@ -66,7 +68,7 @@ function postprocess(
6668) : void {
6769 // There are cases which the same node instance appears twice in the tree.
6870 // 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 > ( )
7072
7173 traverseNodes ( result . ast , {
7274 visitorKeys : result . visitorKeys ,
@@ -78,9 +80,22 @@ function postprocess(
7880
7981 // `babel-eslint@8` has shared `Node#range` with multiple nodes.
8082 // 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 {
8396 locationCalculator . fixLocation ( node )
97+ traversed . add ( node . range )
98+ traversed . add ( node . loc )
8499 }
85100 }
86101 } ,
@@ -139,7 +154,7 @@ function normalizeLeft(
139154 */
140155function getCommaTokenBeforeNode ( tokens : Token [ ] , node : Node ) : Token | null {
141156 let tokenIndex = sortedIndexBy (
142- tokens ,
157+ tokens as { range : OffsetRange } [ ] ,
143158 { range : node . range } ,
144159 t => t . range [ 0 ] ,
145160 )
@@ -563,7 +578,6 @@ export function parseScript(
563578 require ( parserOptions . parser )
564579 : getEspree ( )
565580 const result : any =
566- // eslint-disable-next-line @mysticatea/ts/unbound-method
567581 typeof parser . parseForESLint === "function"
568582 ? parser . parseForESLint ( code , parserOptions )
569583 : parser . parse ( code , parserOptions )
0 commit comments