@@ -27,26 +27,40 @@ function calculateLoc (node, base = null) {
27
27
function checkVExpressionContainerText ( context , node , baseNode = null ) {
28
28
if ( ! node . expression ) { return }
29
29
30
- if ( node . expression . type === 'Literal' ) {
31
- const literalNode = node . expression
32
- const loc = calculateLoc ( literalNode , baseNode )
33
- context . report ( {
34
- loc,
35
- message : `raw text '${ literalNode . value } ' is used`
36
- } )
37
- } else if ( node . expression . type === 'ConditionalExpression' ) {
38
- const targets = [ node . expression . consequent , node . expression . alternate ]
39
- targets . forEach ( target => {
40
- if ( target . type === 'Literal' ) {
41
- const loc = calculateLoc ( target , baseNode )
30
+ if ( node . parent && node . parent . type === 'VElement' ) {
31
+ // parent is element (e.g. <p>{{ ... }}</p>)
32
+ if ( node . expression . type === 'Literal' ) {
33
+ const literalNode = node . expression
34
+ const loc = calculateLoc ( literalNode , baseNode )
35
+ context . report ( {
36
+ loc,
37
+ message : `raw text '${ literalNode . value } ' is used`
38
+ } )
39
+ } else if ( node . expression . type === 'ConditionalExpression' ) {
40
+ const targets = [ node . expression . consequent , node . expression . alternate ]
41
+ targets . forEach ( target => {
42
+ if ( target . type === 'Literal' ) {
43
+ const loc = calculateLoc ( target , baseNode )
44
+ context . report ( {
45
+ loc,
46
+ message : `raw text '${ target . value } ' is used`
47
+ } )
48
+ }
49
+ } )
50
+ }
51
+ } else if ( node . parent && node . parent . type === 'VAttribute' && node . parent . directive ) {
52
+ // parent is directive (e.g <p v-xxx="..."></p>)
53
+ const attrNode = node . parent
54
+ if ( attrNode . key && attrNode . key . type === 'VDirectiveKey' ) {
55
+ if ( ( attrNode . key . name === 'text' || attrNode . key . name . name === 'text' ) && node . expression . type === 'Literal' ) {
56
+ const literalNode = node . expression
57
+ const loc = calculateLoc ( literalNode , baseNode )
42
58
context . report ( {
43
59
loc,
44
- message : `raw text '${ target . value } ' is used`
60
+ message : `raw text '${ literalNode . value } ' is used`
45
61
} )
46
62
}
47
- } )
48
- } else if ( ( node . parent && node . parent . type === 'VAttribute' && node . parent . directive ) &&
49
- ( node . parent . key && node . parent . key . type === 'VDirectiveKey' ) ) {
63
+ }
50
64
}
51
65
}
52
66
0 commit comments