Skip to content

Commit c104cc5

Browse files
committed
feat(weex): split text into separate module
1 parent 08660e8 commit c104cc5

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

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

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import { addAttr } from 'compiler/helpers'
3+
import { transformText } from './text'
44

55
let currentRecycleList = null
66

@@ -20,27 +20,14 @@ function postTransformNode (el: ASTElement) {
2020
if (currentRecycleList) {
2121
// <text>: transform children text into value attr
2222
if (el.tag === 'text') {
23-
addAttr(el, 'value', genText(el.children[0]))
24-
el.children = []
25-
el.plain = false
23+
transformText(el)
2624
}
2725
}
2826
if (el === currentRecycleList) {
2927
currentRecycleList = null
3028
}
3129
}
3230

33-
function genText (node) {
34-
const value = node.type === 3
35-
? node.text
36-
: node.type === 2
37-
? node.tokens.length === 1
38-
? node.tokens[0]
39-
: node.tokens
40-
: ''
41-
return JSON.stringify(value)
42-
}
43-
4431
export default {
4532
preTransformNode,
4633
transformNode,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* @flow */
2+
3+
import { addAttr } from 'compiler/helpers'
4+
5+
function genText (node: ASTNode) {
6+
const value = node.type === 3
7+
? node.text
8+
: node.type === 2
9+
? node.tokens.length === 1
10+
? node.tokens[0]
11+
: node.tokens
12+
: ''
13+
return JSON.stringify(value)
14+
}
15+
16+
export function transformText (el: ASTElement) {
17+
// weex <text> can only contain text, so the parser
18+
// always generates a single child.
19+
addAttr(el, 'value', genText(el.children[0]))
20+
el.children = []
21+
el.plain = false
22+
}

0 commit comments

Comments
 (0)