Browse Source

feat(weex): split text into separate module

dev
Evan You 7 years ago
parent
commit
c104cc582d
  1. 17
      src/platforms/weex/compiler/modules/recycle-list/index.js
  2. 22
      src/platforms/weex/compiler/modules/recycle-list/text.js

17
src/platforms/weex/compiler/modules/recycle-list/index.js

@ -1,6 +1,6 @@
/* @flow */
import { addAttr } from 'compiler/helpers'
import { transformText } from './text'
let currentRecycleList = null
@ -20,9 +20,7 @@ function postTransformNode (el: ASTElement) {
if (currentRecycleList) {
// <text>: transform children text into value attr
if (el.tag === 'text') {
addAttr(el, 'value', genText(el.children[0]))
el.children = []
el.plain = false
transformText(el)
}
}
if (el === currentRecycleList) {
@ -30,17 +28,6 @@ function postTransformNode (el: ASTElement) {
}
}
function genText (node) {
const value = node.type === 3
? node.text
: node.type === 2
? node.tokens.length === 1
? node.tokens[0]
: node.tokens
: ''
return JSON.stringify(value)
}
export default {
preTransformNode,
transformNode,

22
src/platforms/weex/compiler/modules/recycle-list/text.js

@ -0,0 +1,22 @@
/* @flow */
import { addAttr } from 'compiler/helpers'
function genText (node: ASTNode) {
const value = node.type === 3
? node.text
: node.type === 2
? node.tokens.length === 1
? node.tokens[0]
: node.tokens
: ''
return JSON.stringify(value)
}
export function transformText (el: ASTElement) {
// weex <text> can only contain text, so the parser
// always generates a single child.
addAttr(el, 'value', genText(el.children[0]))
el.children = []
el.plain = false
}
Loading…
Cancel
Save