Skip to content

Commit

Permalink
feat(weex): split text into separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 19, 2017
1 parent 08660e8 commit c104cc5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/platforms/weex/compiler/modules/recycle-list/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import { addAttr } from 'compiler/helpers'
import { transformText } from './text'

let currentRecycleList = null

Expand All @@ -20,27 +20,14 @@ 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) {
currentRecycleList = null
}
}

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,
Expand Down
22 changes: 22 additions & 0 deletions src/platforms/weex/compiler/modules/recycle-list/text.js
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit c104cc5

Please sign in to comment.