diff --git a/src/platforms/weex/compiler/modules/append.js b/src/platforms/weex/compiler/modules/append.js index 71a1a816018..6e7be2674dc 100644 --- a/src/platforms/weex/compiler/modules/append.js +++ b/src/platforms/weex/compiler/modules/append.js @@ -1,7 +1,13 @@ /* @flow */ +import { makeMap } from 'shared/util' + +// The "unitary tag" means that the tag node and its children +// must be sent to the native together. +const isUnitaryTag = makeMap('cell,header,cell-slot,recycle-list', true) + function preTransformNode (el: ASTElement, options: CompilerOptions) { - if (el.tag === 'cell' && !el.attrsList.some(item => item.name === 'append')) { + if (isUnitaryTag(el.tag) && !el.attrsList.some(item => item.name === 'append')) { el.attrsMap.append = 'tree' el.attrsList.push({ name: 'append', value: 'tree' }) } diff --git a/test/weex/cases/cases.spec.js b/test/weex/cases/cases.spec.js index 72a86ff6025..532544cdd17 100644 --- a/test/weex/cases/cases.spec.js +++ b/test/weex/cases/cases.spec.js @@ -136,7 +136,7 @@ describe('Usage', () => { }]).then(code => { const id = String(Date.now() * Math.random()) const instance = createInstance(id, code) - expect(tasks.length).toEqual(7) + expect(tasks.length).toEqual(3) tasks.length = 0 instance.$triggerHook(2, 'create', ['component-1']) instance.$triggerHook(2, 'create', ['component-2']) diff --git a/test/weex/cases/recycle-list/attrs.vdom.js b/test/weex/cases/recycle-list/attrs.vdom.js index 175d355fb6b..0d15ed8341b 100644 --- a/test/weex/cases/recycle-list/attrs.vdom.js +++ b/test/weex/cases/recycle-list/attrs.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A', count: 1, source: 'http://whatever.com/x.png' }, { type: 'A', count: 2, source: 'http://whatever.com/y.png' }, @@ -11,7 +12,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'image', attr: { diff --git a/test/weex/cases/recycle-list/classname.vdom.js b/test/weex/cases/recycle-list/classname.vdom.js index c09989b9224..45fcff829e3 100644 --- a/test/weex/cases/recycle-list/classname.vdom.js +++ b/test/weex/cases/recycle-list/classname.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A', color: 'red' }, { type: 'A', color: 'blue' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, style: { backgroundColor: '#FF6600' }, diff --git a/test/weex/cases/recycle-list/components/stateful-v-model.vdom.js b/test/weex/cases/recycle-list/components/stateful-v-model.vdom.js index e4bcf9ba2fa..97f055e73fb 100644 --- a/test/weex/cases/recycle-list/components/stateful-v-model.vdom.js +++ b/test/weex/cases/recycle-list/components/stateful-v-model.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A' }, { type: 'A' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'div', attr: { diff --git a/test/weex/cases/recycle-list/components/stateful.vdom.js b/test/weex/cases/recycle-list/components/stateful.vdom.js index 05af92f02da..f716bc1ad0a 100644 --- a/test/weex/cases/recycle-list/components/stateful.vdom.js +++ b/test/weex/cases/recycle-list/components/stateful.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A', number: 24 }, { type: 'A', number: 42 } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'div', attr: { diff --git a/test/weex/cases/recycle-list/components/stateless-multi-components.vdom.js b/test/weex/cases/recycle-list/components/stateless-multi-components.vdom.js index 6dd60872659..4d91101a82e 100644 --- a/test/weex/cases/recycle-list/components/stateless-multi-components.vdom.js +++ b/test/weex/cases/recycle-list/components/stateless-multi-components.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A' }, { type: 'B', poster: 'yy', title: 'y' }, @@ -11,7 +12,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'div', attr: { @@ -51,7 +52,7 @@ }] }, { type: 'cell-slot', - attr: { templateType: 'B' }, + attr: { append: 'tree', templateType: 'B' }, children: [{ type: 'div', attr: { diff --git a/test/weex/cases/recycle-list/components/stateless-with-props.vdom.js b/test/weex/cases/recycle-list/components/stateless-with-props.vdom.js index 451f3ee2488..782cdd4d93a 100644 --- a/test/weex/cases/recycle-list/components/stateless-with-props.vdom.js +++ b/test/weex/cases/recycle-list/components/stateless-with-props.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A', poster: 'xx', title: 'x' }, { type: 'A', poster: 'yy', title: 'y' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'div', attr: { diff --git a/test/weex/cases/recycle-list/components/stateless.vdom.js b/test/weex/cases/recycle-list/components/stateless.vdom.js index ac8c641e143..da3b2b52018 100644 --- a/test/weex/cases/recycle-list/components/stateless.vdom.js +++ b/test/weex/cases/recycle-list/components/stateless.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A' }, { type: 'A' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'div', attr: { diff --git a/test/weex/cases/recycle-list/inline-style.vdom.js b/test/weex/cases/recycle-list/inline-style.vdom.js index 57732c04b47..bac7961c56d 100644 --- a/test/weex/cases/recycle-list/inline-style.vdom.js +++ b/test/weex/cases/recycle-list/inline-style.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A', color: '#606060' }, { type: 'A', color: '#E5E5E5' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, style: { backgroundColor: '#FF6600' }, diff --git a/test/weex/cases/recycle-list/text-node.vdom.js b/test/weex/cases/recycle-list/text-node.vdom.js index 5808ea0bfd4..4b7c834c7f1 100644 --- a/test/weex/cases/recycle-list/text-node.vdom.js +++ b/test/weex/cases/recycle-list/text-node.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A', dynamic: 'decimal', two: '2', four: '4' }, { type: 'A', dynamic: 'binary', two: '10', four: '100' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'text', attr: { diff --git a/test/weex/cases/recycle-list/v-else-if.vdom.js b/test/weex/cases/recycle-list/v-else-if.vdom.js index 3bdcfb2be7b..781e327e4e9 100644 --- a/test/weex/cases/recycle-list/v-else-if.vdom.js +++ b/test/weex/cases/recycle-list/v-else-if.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A' }, { type: 'A' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'image', attr: { diff --git a/test/weex/cases/recycle-list/v-else.vdom.js b/test/weex/cases/recycle-list/v-else.vdom.js index 0a42c8c2bb1..466cb379a24 100644 --- a/test/weex/cases/recycle-list/v-else.vdom.js +++ b/test/weex/cases/recycle-list/v-else.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A' }, { type: 'A' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'image', attr: { diff --git a/test/weex/cases/recycle-list/v-for-iterator.vdom.js b/test/weex/cases/recycle-list/v-for-iterator.vdom.js index 872ad661b38..ea164fe93eb 100644 --- a/test/weex/cases/recycle-list/v-for-iterator.vdom.js +++ b/test/weex/cases/recycle-list/v-for-iterator.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A' }, { type: 'A' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'div', attr: { diff --git a/test/weex/cases/recycle-list/v-for.vdom.js b/test/weex/cases/recycle-list/v-for.vdom.js index 19ed8935774..0060e34c4b2 100644 --- a/test/weex/cases/recycle-list/v-for.vdom.js +++ b/test/weex/cases/recycle-list/v-for.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A' }, { type: 'A' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'div', attr: { diff --git a/test/weex/cases/recycle-list/v-if.vdom.js b/test/weex/cases/recycle-list/v-if.vdom.js index 2a3d58784ad..fc9405d80e8 100644 --- a/test/weex/cases/recycle-list/v-if.vdom.js +++ b/test/weex/cases/recycle-list/v-if.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A' }, { type: 'A' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'image', attr: { diff --git a/test/weex/cases/recycle-list/v-on-inline.vdom.js b/test/weex/cases/recycle-list/v-on-inline.vdom.js index 284871a4b2f..436a12d80ee 100644 --- a/test/weex/cases/recycle-list/v-on-inline.vdom.js +++ b/test/weex/cases/recycle-list/v-on-inline.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A' }, { type: 'A' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'text', event: ['click', { diff --git a/test/weex/cases/recycle-list/v-on.vdom.js b/test/weex/cases/recycle-list/v-on.vdom.js index 63a7c3c6aed..be347c34d8b 100644 --- a/test/weex/cases/recycle-list/v-on.vdom.js +++ b/test/weex/cases/recycle-list/v-on.vdom.js @@ -1,6 +1,7 @@ ({ type: 'recycle-list', attr: { + append: 'tree', listData: [ { type: 'A' }, { type: 'A' } @@ -10,7 +11,7 @@ }, children: [{ type: 'cell-slot', - attr: { templateType: 'A' }, + attr: { append: 'tree', templateType: 'A' }, children: [{ type: 'text', event: ['click', 'longpress'], diff --git a/test/weex/compiler/append.spec.js b/test/weex/compiler/append.spec.js index 341a8fb23e6..60ceccd328f 100644 --- a/test/weex/compiler/append.spec.js +++ b/test/weex/compiler/append.spec.js @@ -2,7 +2,7 @@ import { compile } from '../../../packages/weex-template-compiler' import { strToRegExp } from '../helpers/index' describe('append props', () => { - it('append="tree"', () => { + it('add append="tree" on ', () => { const { render, staticRenderFns, errors } = compile(``) expect(render).not.toBeUndefined() expect(staticRenderFns).not.toBeUndefined() @@ -11,4 +11,37 @@ describe('append props', () => { expect(staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`)) expect(errors).toEqual([]) }) + + it('override append="node" on ', () => { + const { render, staticRenderFns, errors } = compile(``) + expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"node"}`)) + expect(errors).toEqual([]) + }) + + it('add append="tree" on
', () => { + const { render, staticRenderFns, errors } = compile(`
`) + expect(render + staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`)) + expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`)) + expect(errors).toEqual([]) + }) + + it('add append="tree" on ', () => { + const { render, staticRenderFns, errors } = compile(`
`) + expect(render + staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`)) + expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`)) + expect(errors).toEqual([]) + }) + + it('add append="tree" on ', () => { + const { render, staticRenderFns, errors } = compile(``) + expect(render + staticRenderFns).toMatch(strToRegExp(`appendAsTree:true`)) + expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"tree"}`)) + expect(errors).toEqual([]) + }) + + it('override append="node" on ', () => { + const { render, staticRenderFns, errors } = compile(``) + expect(render + staticRenderFns).toMatch(strToRegExp(`attrs:{"append":"node"}`)) + expect(errors).toEqual([]) + }) })