mirror of
https://gitee.com/vuejs/vue.git
synced 2024-11-30 02:57:43 +08:00
feat($compiler): supports compiling v-bind to the weex native directive in recycle-list
This commit is contained in:
parent
c104cc582d
commit
8b893c13d6
@ -483,15 +483,22 @@ function genComponent (
|
|||||||
})`
|
})`
|
||||||
}
|
}
|
||||||
|
|
||||||
function genProps (props: Array<{ name: string, value: string }>): string {
|
function genProps (props: Array<{ name: string, value: any }>): string {
|
||||||
let res = ''
|
let res = ''
|
||||||
for (let i = 0; i < props.length; i++) {
|
for (let i = 0; i < props.length; i++) {
|
||||||
const prop = props[i]
|
const prop = props[i]
|
||||||
res += `"${prop.name}":${transformSpecialNewlines(prop.value)},`
|
res += `"${prop.name}":${generateValue(prop.value)},`
|
||||||
}
|
}
|
||||||
return res.slice(0, -1)
|
return res.slice(0, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generateValue (value) {
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
return transformSpecialNewlines(value)
|
||||||
|
}
|
||||||
|
return JSON.stringify(value)
|
||||||
|
}
|
||||||
|
|
||||||
// #3895, #4268
|
// #3895, #4268
|
||||||
function transformSpecialNewlines (text: string): string {
|
function transformSpecialNewlines (text: string): string {
|
||||||
return text
|
return text
|
||||||
|
@ -20,7 +20,7 @@ export function addProp (el: ASTElement, name: string, value: string) {
|
|||||||
(el.props || (el.props = [])).push({ name, value })
|
(el.props || (el.props = [])).push({ name, value })
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addAttr (el: ASTElement, name: string, value: string) {
|
export function addAttr (el: ASTElement, name: string, value: any) {
|
||||||
(el.attrs || (el.attrs = [])).push({ name, value })
|
(el.attrs || (el.attrs = [])).push({ name, value })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
|
|
||||||
import { transformText } from './text'
|
import { transformText } from './text'
|
||||||
|
import { transformVBind } from './v-bind'
|
||||||
|
|
||||||
let currentRecycleList = null
|
let currentRecycleList = null
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ function postTransformNode (el: ASTElement) {
|
|||||||
if (el.tag === 'text') {
|
if (el.tag === 'text') {
|
||||||
transformText(el)
|
transformText(el)
|
||||||
}
|
}
|
||||||
|
transformVBind(el)
|
||||||
}
|
}
|
||||||
if (el === currentRecycleList) {
|
if (el === currentRecycleList) {
|
||||||
currentRecycleList = null
|
currentRecycleList = null
|
||||||
|
@ -16,7 +16,9 @@ function genText (node: ASTNode) {
|
|||||||
export function transformText (el: ASTElement) {
|
export function transformText (el: ASTElement) {
|
||||||
// weex <text> can only contain text, so the parser
|
// weex <text> can only contain text, so the parser
|
||||||
// always generates a single child.
|
// always generates a single child.
|
||||||
addAttr(el, 'value', genText(el.children[0]))
|
if (el.children.length) {
|
||||||
el.children = []
|
addAttr(el, 'value', genText(el.children[0]))
|
||||||
el.plain = false
|
el.children = []
|
||||||
|
el.plain = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
31
src/platforms/weex/compiler/modules/recycle-list/v-bind.js
Normal file
31
src/platforms/weex/compiler/modules/recycle-list/v-bind.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* @flow */
|
||||||
|
|
||||||
|
import { getAndRemoveAttr, addAttr } from 'compiler/helpers'
|
||||||
|
|
||||||
|
function isBindingAttr (name) {
|
||||||
|
return /^(v\-bind)?\:/.test(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseRealName (name: string): string {
|
||||||
|
return name.replace(/^(v\-bind)?\:/, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function transformVBind (el: ASTElement) {
|
||||||
|
if (!el.attrsList.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
el.attrsList.forEach(attr => {
|
||||||
|
// console.log('is binding attr:', attr.name, isBindingAttr(attr.name))
|
||||||
|
if (isBindingAttr(attr.name)) {
|
||||||
|
const realName: string = parseRealName(attr.name)
|
||||||
|
const binding = getAndRemoveAttr(el, attr.name)
|
||||||
|
if (el.attrs) {
|
||||||
|
el.attrs = el.attrs.filter(at => at.name !== realName) // omit duplicated
|
||||||
|
}
|
||||||
|
getAndRemoveAttr(el, realName)
|
||||||
|
addAttr(el, realName, { '@binding': binding })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
el.hasBindings = false
|
||||||
|
// el.plain = true
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user