feat($compiler): supports compiling v-for to the weex native directive

This commit is contained in:
Hanks 2017-09-16 15:30:32 +08:00 committed by Evan You
parent 7ad368ebb6
commit 9bd1483803
2 changed files with 37 additions and 0 deletions

View File

@ -3,6 +3,7 @@
import { transformText } from './text'
import { transformVBind } from './v-bind'
import { transformVIf } from './v-if'
import { transformVFor } from './v-for'
let currentRecycleList = null
@ -16,6 +17,7 @@ function transformNode (el: ASTElement) {
if (currentRecycleList) {
// TODO
transformVIf(el)
transformVFor(el)
transformVBind(el)
}
}

View File

@ -0,0 +1,35 @@
/* @flow */
import { addAttr } from 'compiler/helpers'
function isVForAttr (name: string): boolean {
return /^v\-for/.test(name)
}
export function transformVFor (el: ASTElement) {
for (const attr in el.attrsMap) {
if (!isVForAttr(attr)) {
continue
}
const desc: Object = {
'@expression': el.for,
'@alias': el.alias
}
if (el.iterator1) {
desc['@index'] = el.iterator1
}
if (el.iterator2) {
desc['@key'] = el.iterator1
desc['@index'] = el.iterator2
}
addAttr(el, '[[repeat]]', desc)
el.attrsMap['[[repeat]]'] = desc
el.attrsList.push({ name: '[[repeat]]', value: desc })
delete el.attrsMap[attr]
delete el.for
delete el.alias
delete el.key
delete el.iterator1
delete el.iterator2
}
}