593d1003a3774a6378d27f6d3ee74585208d69cfc5cede70f1b58beb11c88649f7b8010ec9c683772d3d91e5eb97f6bda2cb3d8f43fc5e9332b95138cd20e4 537 B

1234567891011121314151617181920212223
  1. /* @flow */
  2. import { addAttr } from 'compiler/helpers'
  3. function genText (node: ASTNode) {
  4. const value = node.type === 3
  5. ? node.text
  6. : node.type === 2
  7. ? node.tokens.length === 1
  8. ? node.tokens[0]
  9. : node.tokens
  10. : ''
  11. return JSON.stringify(value)
  12. }
  13. export function postTransformText (el: ASTElement) {
  14. // weex <text> can only contain text, so the parser
  15. // always generates a single child.
  16. if (el.children.length) {
  17. addAttr(el, 'value', genText(el.children[0]))
  18. el.children = []
  19. }
  20. }