|
8 | 8 | // Requirements
|
9 | 9 | // ------------------------------------------------------------------------------
|
10 | 10 |
|
| 11 | +const { isVElement } = require('../utils') |
| 12 | + |
11 | 13 | // ------------------------------------------------------------------------------
|
12 | 14 | // Rule Definition
|
13 | 15 | // ------------------------------------------------------------------------------
|
14 | 16 |
|
15 | 17 | /**
|
16 | 18 | * check whether has attribute `src`
|
| 19 | + * @param {VElement} componentBlock |
17 | 20 | */
|
18 | 21 | function hasAttributeSrc(componentBlock) {
|
19 | 22 | const hasAttribute = componentBlock.startTag.attributes.length > 0
|
20 | 23 |
|
21 | 24 | const hasSrc =
|
22 | 25 | componentBlock.startTag.attributes.filter(
|
23 | 26 | (attribute) =>
|
24 | | - attribute.key.name === 'src' && attribute.value.value !== '' |
| 27 | + !attribute.directive && |
| 28 | + attribute.key.name === 'src' && |
| 29 | + attribute.value && |
| 30 | + attribute.value.value !== '' |
25 | 31 | ).length > 0
|
26 | 32 |
|
27 | 33 | return hasAttribute && hasSrc
|
28 | 34 | }
|
29 | 35 |
|
30 | 36 | /**
|
31 | 37 | * check whether value under the component block is only whitespaces or break lines
|
| 38 | + * @param {VElement} componentBlock |
32 | 39 | */
|
33 | 40 | function isValueOnlyWhiteSpacesOrLineBreaks(componentBlock) {
|
34 | 41 | return (
|
@@ -63,11 +70,12 @@ module.exports = {
|
63 | 70 | return {}
|
64 | 71 | }
|
65 | 72 |
|
66 | | - const componentBlocks = context.parserServices.getDocumentFragment() |
67 | | - .children |
| 73 | + const componentBlocks = context.parserServices |
| 74 | + .getDocumentFragment() |
| 75 | + .children.filter(isVElement) |
68 | 76 |
|
69 | 77 | return {
|
70 | | - Program(node) { |
| 78 | + Program() { |
71 | 79 | for (const componentBlock of componentBlocks) {
|
72 | 80 | if (
|
73 | 81 | componentBlock.name !== 'template' &&
|
|
0 commit comments