Просмотр исходного кода

feat(weex): split text into separate module

Evan You 8 лет назад
Родитель
Сommit
c104cc582d

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

@@ -1,6 +1,6 @@
 /* @flow */
 /* @flow */
 
 
-import { addAttr } from 'compiler/helpers'
+import { transformText } from './text'
 
 
 let currentRecycleList = null
 let currentRecycleList = null
 
 
@@ -20,9 +20,7 @@ function postTransformNode (el: ASTElement) {
   if (currentRecycleList) {
   if (currentRecycleList) {
     // <text>: transform children text into value attr
     // <text>: transform children text into value attr
     if (el.tag === 'text') {
     if (el.tag === 'text') {
-      addAttr(el, 'value', genText(el.children[0]))
-      el.children = []
-      el.plain = false
+      transformText(el)
     }
     }
   }
   }
   if (el === currentRecycleList) {
   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 {
 export default {
   preTransformNode,
   preTransformNode,
   transformNode,
   transformNode,

+ 22 - 0
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
+}