d6967cce640b2bff6b9da72838c1df10d00fc887913e3d7bae5478ebf36ebddf599fcf97a90b02412e3b731b89cdeeb59575c0485591a4a939e38a91a3ed4f 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* @flow */
  2. import { preTransformRecycleList } from './recycle-list'
  3. import { postTransformComponent } from './component'
  4. import { postTransformComponentRoot } from './component-root'
  5. import { postTransformText } from './text'
  6. import { preTransformVBind } from './v-bind'
  7. import { preTransformVIf } from './v-if'
  8. import { preTransformVFor } from './v-for'
  9. import { postTransformVOn } from './v-on'
  10. import { preTransformVOnce } from './v-once'
  11. let currentRecycleList = null
  12. function shouldCompile (el: ASTElement, options: WeexCompilerOptions) {
  13. return options.recyclable ||
  14. (currentRecycleList && el !== currentRecycleList)
  15. }
  16. function preTransformNode (el: ASTElement, options: WeexCompilerOptions) {
  17. if (el.tag === 'recycle-list') {
  18. preTransformRecycleList(el, options)
  19. currentRecycleList = el
  20. }
  21. if (shouldCompile(el, options)) {
  22. preTransformVBind(el)
  23. preTransformVIf(el, options) // also v-else-if and v-else
  24. preTransformVFor(el, options)
  25. preTransformVOnce(el)
  26. }
  27. }
  28. function transformNode (el: ASTElement, options: WeexCompilerOptions) {
  29. if (shouldCompile(el, options)) {
  30. // do nothing yet
  31. }
  32. }
  33. function postTransformNode (el: ASTElement, options: WeexCompilerOptions) {
  34. if (shouldCompile(el, options)) {
  35. // mark child component in parent template
  36. postTransformComponent(el, options)
  37. // mark root in child component template
  38. postTransformComponentRoot(el)
  39. // <text>: transform children text into value attr
  40. if (el.tag === 'text') {
  41. postTransformText(el)
  42. }
  43. postTransformVOn(el)
  44. }
  45. if (el === currentRecycleList) {
  46. currentRecycleList = null
  47. }
  48. }
  49. export default {
  50. preTransformNode,
  51. transformNode,
  52. postTransformNode
  53. }