From 62e47c9eb4446da79d66ad2385c199f31b4348d8 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 29 Nov 2017 15:44:06 -0500 Subject: [PATCH] feat(weex): WIP adjust component transform stage --- .../compiler/modules/recycle-list/component-root.js | 6 +++--- .../weex/compiler/modules/recycle-list/component.js | 6 +++--- .../weex/compiler/modules/recycle-list/index.js | 10 ++++++---- src/platforms/weex/util/index.js | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/platforms/weex/compiler/modules/recycle-list/component-root.js b/src/platforms/weex/compiler/modules/recycle-list/component-root.js index d527823ba9..41360786e4 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/component-root.js +++ b/src/platforms/weex/compiler/modules/recycle-list/component-root.js @@ -1,14 +1,14 @@ /* @flow */ -import { addRawAttr } from 'compiler/helpers' +import { addAttr } from 'compiler/helpers' // mark component root nodes as -export function preTransformComponentRoot ( +export function postTransformComponentRoot ( el: ASTElement, options: WeexCompilerOptions ) { if (!el.parent) { // component root - addRawAttr(el, '$isComponentRoot', true) + addAttr(el, '@isComponentRoot', 'true') } } diff --git a/src/platforms/weex/compiler/modules/recycle-list/component.js b/src/platforms/weex/compiler/modules/recycle-list/component.js index 3558558cf5..36d7dfd504 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/component.js +++ b/src/platforms/weex/compiler/modules/recycle-list/component.js @@ -1,16 +1,16 @@ /* @flow */ -import { addRawAttr } from 'compiler/helpers' +import { addAttr } from 'compiler/helpers' import { RECYCLE_LIST_MARKER } from 'weex/util/index' // mark components as inside recycle-list so that we know we need to invoke // their special @render function instead of render in create-component.js -export function preTransformComponent ( +export function postTransformComponent ( el: ASTElement, options: WeexCompilerOptions ) { // $flow-disable-line (we know isReservedTag is there) if (!options.isReservedTag(el.tag) && el.tag !== 'cell-slot') { - addRawAttr(el, RECYCLE_LIST_MARKER, 'true') + addAttr(el, RECYCLE_LIST_MARKER, 'true') } } diff --git a/src/platforms/weex/compiler/modules/recycle-list/index.js b/src/platforms/weex/compiler/modules/recycle-list/index.js index 329a19475a..d163c2d854 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/index.js +++ b/src/platforms/weex/compiler/modules/recycle-list/index.js @@ -1,7 +1,7 @@ /* @flow */ -import { preTransformComponent } from './component' -import { preTransformComponentRoot } from './component-root' +import { postTransformComponent } from './component' +import { postTransformComponentRoot } from './component-root' import { postTransformText } from './text' import { preTransformVBind } from './v-bind' import { preTransformVIf } from './v-if' @@ -20,8 +20,6 @@ function preTransformNode (el: ASTElement, options: WeexCompilerOptions) { currentRecycleList = el } if (shouldCompile(el, options)) { - preTransformComponent(el, options) - preTransformComponentRoot(el, options) preTransformVBind(el, options) preTransformVIf(el, options) // also v-else-if and v-else preTransformVFor(el, options) @@ -36,6 +34,10 @@ function transformNode (el: ASTElement, options: WeexCompilerOptions) { function postTransformNode (el: ASTElement, options: WeexCompilerOptions) { if (shouldCompile(el, options)) { + // mark child component in parent template + postTransformComponent(el, options) + // mark root in child component template + postTransformComponentRoot(el, options) // : transform children text into value attr if (el.tag === 'text') { postTransformText(el, options) diff --git a/src/platforms/weex/util/index.js b/src/platforms/weex/util/index.js index 87a3eb7474..cffc2ede79 100755 --- a/src/platforms/weex/util/index.js +++ b/src/platforms/weex/util/index.js @@ -4,7 +4,7 @@ declare var document: Object; import { makeMap } from 'shared/util' import { warn } from 'core/util/index' -export const RECYCLE_LIST_MARKER = '$inRecycleList' +export const RECYCLE_LIST_MARKER = '@inRecycleList' export const isReservedTag = makeMap( 'template,script,style,element,content,slot,link,meta,svg,view,' +