File tree Expand file tree Collapse file tree 3 files changed +55
-2
lines changed Expand file tree Collapse file tree 3 files changed +55
-2
lines changed Original file line number Diff line number Diff line change @@ -35,14 +35,20 @@ interface ESLintCustomParser {
35
35
function postprocess ( ast : ESLintProgram , locationCalculator : LocationCalculator ) : void {
36
36
// There are cases which the same node instance appears twice in the tree.
37
37
// E.g. `let {a} = {}` // This `a` appears twice at `Property#key` and `Property#value`.
38
- const traversed = new Set < Node > ( )
38
+ const traversed = new Set < Node | number [ ] > ( )
39
39
40
40
traverseNodes ( ast , {
41
41
enterNode ( node , parent ) {
42
42
if ( ! traversed . has ( node ) ) {
43
43
traversed . add ( node )
44
44
node . parent = parent
45
- locationCalculator . fixLocation ( node )
45
+
46
+ // `babel-eslint@8` has shared `Node#range` with multiple nodes.
47
+ // See also: https://github.com/vuejs/eslint-plugin-vue/issues/208
48
+ if ( ! traversed . has ( node . range ) ) {
49
+ traversed . add ( node . range )
50
+ locationCalculator . fixLocation ( node )
51
+ }
46
52
}
47
53
} ,
48
54
leaveNode ( ) {
Original file line number Diff line number Diff line change
1
+ <style >
2
+ </style >
3
+
4
+ <template >
5
+ <div id =" app" >
6
+ <img src =" ./assets/logo.png" >
7
+ <hello ></hello >
8
+ </div >
9
+ </template >
10
+
11
+ <script >
12
+ import { a , b } from ' ./deps' ;
13
+ import Hello from ' ./components/Hello' ;
14
+
15
+ export default {
16
+ name: ' app' ,
17
+ calc (x ) {
18
+ return x + a + b;
19
+ },
20
+ components: {
21
+ Hello
22
+ }
23
+ }
24
+ </script >
Original file line number Diff line number Diff line change @@ -345,6 +345,29 @@ describe("Basic tests", () => {
345
345
} )
346
346
} )
347
347
348
+ describe ( "About fixtures/location-issue-with-babel-eslint.vue" , ( ) => {
349
+ it ( "Identifiers in import declarations should has correct location." , ( ) => {
350
+ const cli = new CLIEngine ( {
351
+ cwd : FIXTURE_DIR ,
352
+ envs : [ "browser" , "node" ] ,
353
+ parser : PARSER_PATH ,
354
+ parserOptions : {
355
+ parser : "babel-eslint" ,
356
+ sourceType : "module" ,
357
+ ecmaVersion : 2017 ,
358
+ } ,
359
+ rules : {
360
+ "no-use-before-define" : "error" ,
361
+ } ,
362
+ useEslintrc : false ,
363
+ } )
364
+ const report = cli . executeOnFiles ( [ "location-issue-with-babel-eslint.vue" ] )
365
+ const messages = report . results [ 0 ] . messages
366
+
367
+ assert ( messages . length === 0 )
368
+ } )
369
+ } )
370
+
348
371
describe ( "About unexpected-null-character errors" , ( ) => {
349
372
it ( "should keep NULL in DATA state." , ( ) => {
350
373
const ast = parse ( "<template>\u0000</template>" )
You can’t perform that action at this time.
0 commit comments