@@ -8,6 +8,8 @@ import importMeta from '@babel/plugin-syntax-import-meta'
8
8
import { parseJSXIdentifier } from '../utils'
9
9
10
10
const EXCLUDE_TAG = [ 'template' , 'script' , 'style' ]
11
+ const KEY_DATA = 'data-v-inspector'
12
+
11
13
interface CompileSFCTemplateOptions {
12
14
code : string
13
15
id : string
@@ -27,17 +29,18 @@ export async function compileSFCTemplate(
27
29
( node ) => {
28
30
if ( node . type === 1 ) {
29
31
if ( node . tagType === 0 && ! EXCLUDE_TAG . includes ( node . tag ) ) {
30
- if ( node . loc . source . includes ( 'data-v-inspector-options' ) )
32
+ if ( node . loc . source . includes ( KEY_DATA ) )
31
33
return
32
34
33
- const insertPosition = node . loc . start . offset + node . tag . length + 1
35
+ const insertPosition = node . props . length ? Math . max ( ... node . props . map ( i => i . loc . end . offset ) ) : node . loc . start . offset + node . tag . length + 1
34
36
const { line, column } = node . loc . start
35
37
36
- const content = ` data-v-inspector-options ="${ relativePath } :${ line } :${ column } "`
38
+ const content = ` ${ KEY_DATA } ="${ relativePath } :${ line } :${ column } "`
37
39
38
40
s . prependLeft (
39
41
insertPosition ,
40
- content )
42
+ content ,
43
+ )
41
44
}
42
45
}
43
46
} ,
@@ -64,14 +67,14 @@ export async function compileSFCTemplate(
64
67
babelTraverse ( ast , {
65
68
enter ( { node } ) {
66
69
if ( node . type === 'JSXElement' ) {
67
- if ( node . openingElement . attributes . some ( attr => attr . type !== 'JSXSpreadAttribute' && attr . name . name === 'data-v-inspector-options' ,
70
+ if ( node . openingElement . attributes . some ( attr => attr . type !== 'JSXSpreadAttribute' && attr . name . name === KEY_DATA ,
68
71
) )
69
72
return
70
73
71
- const insertPosition = node . start + parseJSXIdentifier ( node . openingElement . name as any ) . length + 1
74
+ const insertPosition = node . openingElement . end - 1
72
75
const { line, column } = node . loc . start
73
76
74
- const content = ` data-v-inspector-options ="${ relativePath } :${ line } :${ column } "`
77
+ const content = ` ${ KEY_DATA } ="${ relativePath } :${ line } :${ column } "`
75
78
76
79
s . prependLeft (
77
80
insertPosition ,
0 commit comments