Skip to content

Commit 2ddd253

Browse files
committed
feat: warn when using v-for on a list-view
1 parent 2f74750 commit 2ddd253

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

platform/nativescript/compiler/modules/list-view.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
import { normalizeElementName } from '../../element-registry'
22
import { parseFor } from 'compiler/parser/index'
33
import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers'
4+
import { warn } from 'core/util/debug'
45

56
function preTransformNode(el) {
67
if (normalizeElementName(el.tag) !== 'listview') {
78
return
89
}
9-
const exp = getAndRemoveAttr(el, 'for')
10+
11+
const vfor = getAndRemoveAttr(el, 'v-for')
12+
delete el.attrsMap['v-for']
13+
if (process.env.NODE_ENV !== 'production' && vfor) {
14+
warn(
15+
`The v-for directive is not supported on a ${el.tag}, ` +
16+
'Use the "for" attribute instead. For example, instead of ' +
17+
`<${el.tag} v-for="${vfor}"> use <${el.tag} for="${vfor}">.`
18+
)
19+
}
20+
21+
const exp = getAndRemoveAttr(el, 'for') || vfor
1022
if (!exp) return
1123

1224
const res = parseFor(exp)
13-
if (!res) return
25+
if (!res) {
26+
if (process.env.NODE_ENV !== 'production') {
27+
warn(`Invalid for expression: ${exp}`)
28+
}
29+
return
30+
}
1431

1532
addRawAttr(el, ':items', res.for)
1633
addRawAttr(el, '+alias', res.alias)

0 commit comments

Comments
 (0)