提交 7251c5c3 编写于 作者: Q qiang

Merge branch 'dev' into alpha

...@@ -29,7 +29,8 @@ module.exports = { ...@@ -29,7 +29,8 @@ module.exports = {
'sitemap.json', 'sitemap.json',
'ext.json', 'ext.json',
'custom-tab-bar', 'custom-tab-bar',
'functional-pages' 'functional-pages',
'project.private.config.json'
] ]
if (process.env.UNI_MP_PLUGIN) { if (process.env.UNI_MP_PLUGIN) {
......
...@@ -274,6 +274,29 @@ describe('mp:compiler-extra', () => { ...@@ -274,6 +274,29 @@ describe('mp:compiler-extra', () => {
) )
}) })
it('generate v-slot with v-if', () => {
assertCodegen(
'<custom-view><template v-if="show">hello</template></custom-view>',
'<custom-view vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block wx:if="{{show}}">hello</block></custom-view>'
)
assertCodegen(
'<custom-view><template v-if="show" #name>hello</template></custom-view>',
'<custom-view vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'name\']}}"><view slot="name" wx:if="{{show}}">hello</view></custom-view>'
)
assertCodegen(
'<custom-view><template v-if="show" #name><text>hello</text></template></custom-view>',
'<custom-view vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'name\']}}"><text slot="name" wx:if="{{show}}">hello</text></custom-view>'
)
assertCodegen(
'<custom-view><template v-if="show" #name><view>hello</view></template></custom-view>',
'<custom-view vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'name\']}}"><view slot="name" wx:if="{{show}}">hello</view></custom-view>'
)
assertCodegen(
'<custom-view><template v-if="show" #name><view v-if="test1||test2">hello</view></template></custom-view>',
'<custom-view vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'name\']}}"><view slot="name" wx:if="{{(show)&&(test1||test2)}}">hello</view></custom-view>'
)
})
it('generate events inside v-for', () => { it('generate events inside v-for', () => {
assertCodegen( assertCodegen(
'<view v-for="item in dataList" :key="item.id" @click="click1(item, 1);click2(item, 2);"/>', '<view v-for="item in dataList" :key="item.id" @click="click1(item, 1);click2(item, 2);"/>',
......
...@@ -116,7 +116,7 @@ describe('mp:compiler-mp-alipay', () => { ...@@ -116,7 +116,7 @@ describe('mp:compiler-mp-alipay', () => {
) )
assertCodegen( assertCodegen(
'<my-component><template v-slot="{item}">{{getValue(item)}}<template></my-component>', '<my-component><template v-slot="{item}">{{getValue(item)}}<template></my-component>',
'<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" onVueInit="__l"><block><block a:if="{{$root.m0}}">{{$root.m1}}</block></block></my-component>', '<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" onVueInit="__l"><block a:if="{{$root.m0}}">{{$root.m1}}</block></my-component>',
'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default","item")):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}', 'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default","item")):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}',
{ {
scopedSlotsCompiler: 'auto' scopedSlotsCompiler: 'auto'
...@@ -124,7 +124,7 @@ describe('mp:compiler-mp-alipay', () => { ...@@ -124,7 +124,7 @@ describe('mp:compiler-mp-alipay', () => {
) )
assertCodegen( assertCodegen(
'<my-component><template v-slot="item">{{getValue(item.text)}}<template></my-component>', '<my-component><template v-slot="item">{{getValue(item.text)}}<template></my-component>',
'<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" onVueInit="__l"><block><block a:if="{{$root.m0}}">{{$root.m1}}</block></block></my-component>', '<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" onVueInit="__l"><block a:if="{{$root.m0}}">{{$root.m1}}</block></my-component>',
'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default").text):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}', 'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default").text):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}',
{ {
scopedSlotsCompiler: 'auto' scopedSlotsCompiler: 'auto'
......
...@@ -87,14 +87,14 @@ describe('mp:compiler-mp-baidu', () => { ...@@ -87,14 +87,14 @@ describe('mp:compiler-mp-baidu', () => {
) )
assertCodegen( assertCodegen(
'<my-component><template v-slot="{item}">{{getValue(item)}}<template></my-component>', '<my-component><template v-slot="{item}">{{getValue(item)}}<template></my-component>',
'<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" vue-slots="{{[\'default\']}}"><block><block s-if="{{$root.m0}}">{{$root.m1}}</block></block></my-component>', '<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" vue-slots="{{[\'default\']}}"><block s-if="{{$root.m0}}">{{$root.m1}}</block></my-component>',
'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default","item")):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}', { 'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default","item")):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}', {
scopedSlotsCompiler: 'auto' scopedSlotsCompiler: 'auto'
} }
) )
assertCodegen( assertCodegen(
'<my-component><template v-slot="item">{{getValue(item.text)}}<template></my-component>', '<my-component><template v-slot="item">{{getValue(item.text)}}<template></my-component>',
'<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" vue-slots="{{[\'default\']}}"><block><block s-if="{{$root.m0}}">{{$root.m1}}</block></block></my-component>', '<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" vue-slots="{{[\'default\']}}"><block s-if="{{$root.m0}}">{{$root.m1}}</block></my-component>',
'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default").text):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}', { 'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default").text):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}', {
scopedSlotsCompiler: 'auto' scopedSlotsCompiler: 'auto'
} }
......
...@@ -144,7 +144,7 @@ describe('mp:compiler-mp-weixin', () => { ...@@ -144,7 +144,7 @@ describe('mp:compiler-mp-weixin', () => {
) )
assertCodegen( assertCodegen(
'<my-component><template v-slot="{item}">{{getValue(item)}}<template></my-component>', '<my-component><template v-slot="{item}">{{getValue(item)}}<template></my-component>',
'<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block><block wx:if="{{$root.m0}}">{{$root.m1}}</block></block></my-component>', '<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block wx:if="{{$root.m0}}">{{$root.m1}}</block></my-component>',
'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default","item")):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}', 'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default","item")):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}',
{ {
scopedSlotsCompiler: 'auto' scopedSlotsCompiler: 'auto'
...@@ -152,7 +152,7 @@ describe('mp:compiler-mp-weixin', () => { ...@@ -152,7 +152,7 @@ describe('mp:compiler-mp-weixin', () => {
) )
assertCodegen( assertCodegen(
'<my-component><template v-slot="item">{{getValue(item.text)}}<template></my-component>', '<my-component><template v-slot="item">{{getValue(item.text)}}<template></my-component>',
'<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block><block wx:if="{{$root.m0}}">{{$root.m1}}</block></block></my-component>', '<my-component scoped-slots-compiler="augmented" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block wx:if="{{$root.m0}}">{{$root.m1}}</block></my-component>',
'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default").text):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}', 'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default").text):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}',
{ {
scopedSlotsCompiler: 'auto' scopedSlotsCompiler: 'auto'
...@@ -219,7 +219,7 @@ describe('mp:compiler-mp-weixin', () => { ...@@ -219,7 +219,7 @@ describe('mp:compiler-mp-weixin', () => {
it('generate scoped slot with scopedSlotsCompiler: augmented', () => { it('generate scoped slot with scopedSlotsCompiler: augmented', () => {
assertCodegen( assertCodegen(
'<my-component><template v-slot="{item}">{{getValue(item)}}<template></my-component>', '<my-component><template v-slot="{item}">{{getValue(item)}}<template></my-component>',
'<my-component vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block><block wx:if="{{$root.m0}}">{{$root.m1}}</block></block></my-component>', '<my-component vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block wx:if="{{$root.m0}}">{{$root.m1}}</block></my-component>',
'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default","item")):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}', 'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default","item")):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}',
{ {
scopedSlotsCompiler: 'augmented' scopedSlotsCompiler: 'augmented'
...@@ -227,7 +227,7 @@ describe('mp:compiler-mp-weixin', () => { ...@@ -227,7 +227,7 @@ describe('mp:compiler-mp-weixin', () => {
) )
assertCodegen( assertCodegen(
'<my-component><template v-slot="{item}">{{item}}<template></my-component>', '<my-component><template v-slot="{item}">{{item}}<template></my-component>',
'<my-component vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block><block wx:if="{{$root.m0}}">{{$root.m1}}</block></block></my-component>', '<my-component vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block wx:if="{{$root.m0}}">{{$root.m1}}</block></my-component>',
'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?$getScopedSlotsParams("551070e6-1","default","item"):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}', 'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?$getScopedSlotsParams("551070e6-1","default","item"):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}',
{ {
scopedSlotsCompiler: 'augmented' scopedSlotsCompiler: 'augmented'
...@@ -235,7 +235,7 @@ describe('mp:compiler-mp-weixin', () => { ...@@ -235,7 +235,7 @@ describe('mp:compiler-mp-weixin', () => {
) )
assertCodegen( assertCodegen(
'<my-component><template v-slot="item">{{getValue(item.text)}}<template></my-component>', '<my-component><template v-slot="item">{{getValue(item.text)}}<template></my-component>',
'<my-component vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block><block wx:if="{{$root.m0}}">{{$root.m1}}</block></block></my-component>', '<my-component vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block wx:if="{{$root.m0}}">{{$root.m1}}</block></my-component>',
'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default").text):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}', 'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?getValue($getScopedSlotsParams("551070e6-1","default").text):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}',
{ {
scopedSlotsCompiler: 'augmented' scopedSlotsCompiler: 'augmented'
...@@ -243,7 +243,7 @@ describe('mp:compiler-mp-weixin', () => { ...@@ -243,7 +243,7 @@ describe('mp:compiler-mp-weixin', () => {
) )
assertCodegen( assertCodegen(
'<my-component1><my-component2><template v-slot="{item}">{{getValue(item)}}<template></my-component2></my-component1>', '<my-component1><my-component2><template v-slot="{item}">{{getValue(item)}}<template></my-component2></my-component1>',
'<my-component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><my-component2 vue-id="{{(\'551070e6-2\')+\',\'+(\'551070e6-1\')}}" bind:__l="__l" vue-slots="{{[\'default\']}}"><block><block wx:if="{{$root.m0}}">{{$root.m1}}</block></block></my-component2></my-component1>', '<my-component1 vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><my-component2 vue-id="{{(\'551070e6-2\')+\',\'+(\'551070e6-1\')}}" bind:__l="__l" vue-slots="{{[\'default\']}}"><block wx:if="{{$root.m0}}">{{$root.m1}}</block></my-component2></my-component1>',
'with(this){var m0=$hasScopedSlotsParams("551070e6-2");var m1=m0?getValue($getScopedSlotsParams("551070e6-2","default","item")):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}', 'with(this){var m0=$hasScopedSlotsParams("551070e6-2");var m1=m0?getValue($getScopedSlotsParams("551070e6-2","default","item")):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1}})}',
{ {
scopedSlotsCompiler: 'augmented' scopedSlotsCompiler: 'augmented'
...@@ -274,8 +274,8 @@ describe('mp:compiler-mp-weixin', () => { ...@@ -274,8 +274,8 @@ describe('mp:compiler-mp-weixin', () => {
} }
) )
assertCodegen( assertCodegen(
'<my-component><template v-slot="{item}">{{item}}<my-component><template v-slot="{item}">{{item}}<template></my-component><template></my-component>', '<my-component><template v-slot="{item}">{{item}}<my-component><template v-slot="{item}">{{item}}</template></my-component></template></my-component>',
'<my-component vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block><block wx:if="{{$root.m0}}">{{$root.m1}}<my-component vue-id="{{(\'551070e6-2\')+\',\'+(\'551070e6-1\')}}" bind:__l="__l" vue-slots="{{[\'default\']}}"><block><block wx:if="{{$root.m2}}">{{$root.m3}}</block></block></my-component></block></block></my-component>', '<my-component vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'default\']}}"><block wx:if="{{$root.m0}}">{{$root.m1}}<my-component vue-id="{{(\'551070e6-2\')+\',\'+(\'551070e6-1\')}}" bind:__l="__l" vue-slots="{{[\'default\']}}"><block wx:if="{{$root.m2}}">{{$root.m3}}</block></my-component></block></my-component>',
'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?$getScopedSlotsParams("551070e6-1","default","item"):null;var m2=$hasScopedSlotsParams("551070e6-2");var m3=m2?$getScopedSlotsParams("551070e6-2","default","item"):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1,m2:m2,m3:m3}})}', 'with(this){var m0=$hasScopedSlotsParams("551070e6-1");var m1=m0?$getScopedSlotsParams("551070e6-1","default","item"):null;var m2=$hasScopedSlotsParams("551070e6-2");var m3=m2?$getScopedSlotsParams("551070e6-2","default","item"):null;$mp.data=Object.assign({},{$root:{m0:m0,m1:m1,m2:m2,m3:m3}})}',
{ {
scopedSlotsCompiler: 'augmented' scopedSlotsCompiler: 'augmented'
......
...@@ -182,6 +182,30 @@ describe('mp:compiler', () => { ...@@ -182,6 +182,30 @@ describe('mp:compiler', () => {
'<view><slot name="one"></slot></view>', '<view><slot name="one"></slot></view>',
'<view><slot name="one"></slot></view>' '<view><slot name="one"></slot></view>'
) )
assertCodegen(
'<view><slot :name="one"></slot></view>',
'<view><slot name="{{one}}"></slot></view>'
)
assertCodegen(
'<view><slot :name="one+\'test\'"></slot></view>',
'<view><slot name="{{one+\'test\'}}"></slot></view>'
)
assertCodegen(
'<view><slot :name="one" :test="test"></slot></view>',
'<view><slot name="{{one}}"></slot></view>',
'with(this){{$setScopedSlotsParams(one,{"test":test})}}',
{
scopedSlotsCompiler: 'augmented'
}
)
assertCodegen(
'<view><slot :name="one">text</slot></view>',
'<view><block wx:if="{{$slots[one]}}"><slot name="{{one}}"></slot></block><block wx:else>text</block></view>'
)
assertCodegen(
'<view><slot :name="one+\'test\'">text</slot></view>',
'<view><block wx:if="{{$slots[one+\'test\']}}"><slot name="{{one+\'test\'}}"></slot></block><block wx:else>text</block></view>'
)
}) })
// it('generate slot fallback content', () => { // it('generate slot fallback content', () => {
......
...@@ -15,12 +15,13 @@ module.exports = { ...@@ -15,12 +15,13 @@ module.exports = {
preTransformNode (el, { preTransformNode (el, {
warn warn
}) { }) {
if (el.tag === 'slot' && !el.attrsMap.name) { const attrsMap = el.attrsMap
if (el.tag === 'slot' && !(attrsMap.name || attrsMap[':name'])) {
el.attrsList.push({ el.attrsList.push({
name: 'SLOT_DEFAULT', name: 'SLOT_DEFAULT',
value: true value: true
}) })
el.attrsMap.SLOT_DEFAULT = true attrsMap.SLOT_DEFAULT = true
} }
// 处理 attr // 处理 attr
el.attrsList.forEach(attr => { el.attrsList.forEach(attr => {
...@@ -31,11 +32,11 @@ module.exports = { ...@@ -31,11 +32,11 @@ module.exports = {
const origName = attr.name const origName = attr.name
const newName = origName.replace('.lazy', '') const newName = origName.replace('.lazy', '')
attr.name = newName attr.name = newName
el.attrsMap[newName] = attr.value attrsMap[newName] = attr.value
delete el.attrsMap[origName] delete attrsMap[origName]
} else if (onRE.test(attr.name) && !attr.value.trim()) { // 事件为空 } else if (onRE.test(attr.name) && !attr.value.trim()) { // 事件为空
attr.value = '__HOLDER__' attr.value = '__HOLDER__'
el.attrsMap[attr.name] = attr.value attrsMap[attr.name] = attr.value
} }
}) })
// 暂不支持的指令 // 暂不支持的指令
......
...@@ -32,7 +32,7 @@ module.exports = function getRenderSlot (path, state) { ...@@ -32,7 +32,7 @@ module.exports = function getRenderSlot (path, state) {
const scoped = state.scoped const scoped = state.scoped
// TODO 判断是否包含作用域内变量 // TODO 判断是否包含作用域内变量
const renderSlotStatementArray = scoped && scoped.length ? scoped[scoped.length - 1].renderSlotStatementArray : state.renderSlotStatementArray const renderSlotStatementArray = scoped && scoped.length ? scoped[scoped.length - 1].renderSlotStatementArray : state.renderSlotStatementArray
renderSlotStatementArray.push(t.expressionStatement(t.callExpression(t.identifier('$setScopedSlotsParams'), [t.stringLiteral(name.node.value), valueNode]))) renderSlotStatementArray.push(t.expressionStatement(t.callExpression(t.identifier('$setScopedSlotsParams'), [name.node, valueNode])))
} }
// TODO 组件嵌套 // TODO 组件嵌套
} }
...@@ -51,7 +51,12 @@ function replaceId (path, ids) { ...@@ -51,7 +51,12 @@ function replaceId (path, ids) {
} }
module.exports = function getResolveScopedSlots (parent, state) { module.exports = function getResolveScopedSlots (parent, state) {
const properties = parent.get('arguments.0.elements.0.properties') let objectPath = parent.get('arguments.0.elements.0')
// TODO v-else
if (objectPath.isConditionalExpression()) {
objectPath = objectPath.get('consequent')
}
const properties = objectPath.get('properties')
const fn = properties.find(path => path.get('key').isIdentifier({ name: 'fn' })) const fn = properties.find(path => path.get('key').isIdentifier({ name: 'fn' }))
const params = fn.get('value.params.0') const params = fn.get('value.params.0')
if (!params) { if (!params) {
...@@ -83,7 +88,7 @@ module.exports = function getResolveScopedSlots (parent, state) { ...@@ -83,7 +88,7 @@ module.exports = function getResolveScopedSlots (parent, state) {
const test = t.callExpression(t.identifier('$hasScopedSlotsParams'), [vueId]) const test = t.callExpression(t.identifier('$hasScopedSlotsParams'), [vueId])
orgin.replaceWith(t.arrayExpression([t.conditionalExpression(test, node, t.callExpression(t.identifier(METHOD_CREATE_EMPTY_VNODE), []))])) orgin.replaceWith(t.arrayExpression([t.conditionalExpression(test, node, t.callExpression(t.identifier(METHOD_CREATE_EMPTY_VNODE), []))]))
// scopedSlotsCompiler auto // scopedSlotsCompiler auto
parent.get('arguments.0.elements.0').node.scopedSlotsCompiler = 'augmented' objectPath.node.scopedSlotsCompiler = 'augmented'
} }
} }
} }
...@@ -270,7 +270,7 @@ function traverseArrayExpression (arrayExprNodes, state) { ...@@ -270,7 +270,7 @@ function traverseArrayExpression (arrayExprNodes, state) {
}, []) }, [])
} }
function genSlotNode (slotName, slotNode, fallbackNodes, state) { function genSlotNode (slotName, slotNode, fallbackNodes, state, isStaticSlotName = true) {
if (!fallbackNodes || t.isNullLiteral(fallbackNodes)) { if (!fallbackNodes || t.isNullLiteral(fallbackNodes)) {
return slotNode return slotNode
} }
...@@ -282,7 +282,7 @@ function genSlotNode (slotName, slotNode, fallbackNodes, state) { ...@@ -282,7 +282,7 @@ function genSlotNode (slotName, slotNode, fallbackNodes, state) {
return [{ return [{
type: 'block', type: 'block',
attr: { attr: {
[prefix + 'if']: '{{$slots.' + slotName + '}}' [prefix + 'if']: isStaticSlotName ? '{{$slots.' + slotName + '}}' : '{{$slots[' + slotName.replace(/^{{/, '').replace(/}}$/, '') + ']}}'
}, },
children: [].concat(slotNode) children: [].concat(slotNode)
}, { }, {
...@@ -297,12 +297,9 @@ function genSlotNode (slotName, slotNode, fallbackNodes, state) { ...@@ -297,12 +297,9 @@ function genSlotNode (slotName, slotNode, fallbackNodes, state) {
} }
function traverseRenderSlot (callExprNode, state) { function traverseRenderSlot (callExprNode, state) {
if (!t.isStringLiteral(callExprNode.arguments[0])) { const slotNameNode = callExprNode.arguments[0]
state.errors.add(uniI18n.__('templateCompiler.notSupportDynamicSlotName', { 0: 'v-slot' })) const isStaticSlotName = t.isStringLiteral(slotNameNode)
return const slotName = isStaticSlotName ? slotNameNode.value : genCode(slotNameNode)
}
const slotName = callExprNode.arguments[0].value
let deleteSlotName = false // 标记是否组件 slot 手动指定了 name="default" let deleteSlotName = false // 标记是否组件 slot 手动指定了 name="default"
if (state.options.scopedSlotsCompiler !== 'augmented' && callExprNode.arguments.length > 2) { // 作用域插槽 if (state.options.scopedSlotsCompiler !== 'augmented' && callExprNode.arguments.length > 2) { // 作用域插槽
...@@ -312,6 +309,10 @@ function traverseRenderSlot (callExprNode, state) { ...@@ -312,6 +309,10 @@ function traverseRenderSlot (callExprNode, state) {
}) })
deleteSlotName = props.SLOT_DEFAULT && Object.keys(props).length === 1 deleteSlotName = props.SLOT_DEFAULT && Object.keys(props).length === 1
if (!deleteSlotName) { if (!deleteSlotName) {
if (!isStaticSlotName) {
state.errors.add(uniI18n.__('templateCompiler.notSupportDynamicSlotName', { 0: 'v-slot' }))
return
}
delete props.SLOT_DEFAULT delete props.SLOT_DEFAULT
return genSlotNode( return genSlotNode(
slotName, slotName,
...@@ -334,28 +335,50 @@ function traverseRenderSlot (callExprNode, state) { ...@@ -334,28 +335,50 @@ function traverseRenderSlot (callExprNode, state) {
delete node.attr.name delete node.attr.name
} }
return genSlotNode(slotName, node, callExprNode.arguments[1], state) return genSlotNode(slotName, node, callExprNode.arguments[1], state, isStaticSlotName)
} }
function traverseResolveScopedSlots (callExprNode, state) { function traverseResolveScopedSlots (callExprNode, state) {
function single (children, slotName, ignore) { const options = state.options
if (Array.isArray(children) && children.length === 1) { const vIfAttrName = options.platform.directive + 'if'
const child = children[0] function single (node, slotName, vIfCode, ignore) {
if (!child.type) { let last = node
return const vIfs = vIfCode ? [vIfCode] : []
} function find (children) {
if (ignore.includes(child.type)) { if (Array.isArray(children) && children.length === 1) {
return single(child.children, slotName, ignore) const child = children[0]
if (!child.type) {
return
}
last = child
if (child.attr && child.attr[vIfAttrName]) {
vIfs.push(child.attr[vIfAttrName])
delete child.attr[vIfAttrName]
}
if (ignore.includes(child.type) && !(child.attr && Object.keys(child.attr).length)) {
find(child.children, ignore)
}
} }
child.attr = child.attr || {}
child.attr.slot = slotName
return true
} }
find(node.children)
last.attr = last.attr || {}
last.attr.slot = slotName
if (vIfs.length) {
// 简易合并
last.attr[vIfAttrName] = vIfs.length > 1 ? `{{${vIfs.map(str => str.replace(/^\{\{(.+)\}\}$/, '($1)')).join('&&')}}}` : vIfs[0]
}
return last
} }
return callExprNode.arguments[0].elements.map(slotNode => { return callExprNode.arguments[0].elements.map(slotNode => {
let keyProperty = false let keyProperty = false
let fnProperty = false let fnProperty = false
let proxyProperty = false let proxyProperty = false
let vIfCode
// TODO v-else
if (t.isConditionalExpression(slotNode)) {
vIfCode = genCode(slotNode.test)
slotNode = slotNode.consequent
}
slotNode.properties.forEach(property => { slotNode.properties.forEach(property => {
switch (property.key.name) { switch (property.key.name) {
case 'key': case 'key':
...@@ -371,14 +394,14 @@ function traverseResolveScopedSlots (callExprNode, state) { ...@@ -371,14 +394,14 @@ function traverseResolveScopedSlots (callExprNode, state) {
const slotName = keyProperty.value.value const slotName = keyProperty.value.value
const returnExprNodes = fnProperty.value.body.body[0].argument const returnExprNodes = fnProperty.value.body.body[0].argument
const parentNode = callExprNode.$node const parentNode = callExprNode.$node
if (slotNode.scopedSlotsCompiler !== 'augmented' && !proxyProperty) { if (options.scopedSlotsCompiler !== 'augmented' && slotNode.scopedSlotsCompiler !== 'augmented' && !proxyProperty) {
const resourcePath = state.options.resourcePath const resourcePath = options.resourcePath
const ownerName = path.basename(resourcePath, path.extname(resourcePath)) const ownerName = path.basename(resourcePath, path.extname(resourcePath))
const parentName = parentNode.type const parentName = parentNode.type
const paramExprNode = fnProperty.value.params[0] const paramExprNode = fnProperty.value.params[0]
return state.options.platform.resolveScopedSlots( return options.platform.resolveScopedSlots(
slotName, { slotName, {
genCode, genCode,
generate, generate,
...@@ -398,21 +421,14 @@ function traverseResolveScopedSlots (callExprNode, state) { ...@@ -398,21 +421,14 @@ function traverseResolveScopedSlots (callExprNode, state) {
state state
) )
} }
if (state.options.scopedSlotsCompiler === 'auto' && slotNode.scopedSlotsCompiler === 'augmented') { if (options.scopedSlotsCompiler === 'auto' && slotNode.scopedSlotsCompiler === 'augmented') {
parentNode.attr['scoped-slots-compiler'] = 'augmented' parentNode.attr['scoped-slots-compiler'] = 'augmented'
} }
const children = normalizeChildren(traverseExpr(returnExprNodes, state))
// 除百度、字节外其他小程序仅默认插槽可以支持多个节点 // 除百度、字节外其他小程序仅默认插槽可以支持多个节点
if (single(children, slotName, ['template', 'block'])) { return single({
return children[0]
}
return {
type: 'block', type: 'block',
attr: { children: normalizeChildren(traverseExpr(returnExprNodes, state))
slot: slotName }, slotName, vIfCode, ['template', 'block'])
},
children
}
}) })
} }
......
...@@ -285,7 +285,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt ...@@ -285,7 +285,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
process.env.UNI_PLATFORM !== 'mp-alipay' && process.env.UNI_PLATFORM !== 'mp-alipay' &&
process.env.UNI_PLATFORM !== 'quickapp-webview' // 目前 ov 的开发工具支持 eval 模式 process.env.UNI_PLATFORM !== 'quickapp-webview' // 目前 ov 的开发工具支持 eval 模式
) { ) {
plugins.push(sourceMap.createSourceMapDevToolPlugin(process.env.UNI_PLATFORM === 'mp-weixin')) plugins.push(sourceMap.createSourceMapDevToolPlugin(process.env.UNI_PLATFORM === 'mp-weixin' || process.env.UNI_PLATFORM === 'mp-toutiao'))
} }
} }
......
...@@ -4,13 +4,13 @@ module.exports = function (appJson) { ...@@ -4,13 +4,13 @@ module.exports = function (appJson) {
} }
if (!appJson.plugins['uni-ad']) { if (!appJson.plugins['uni-ad']) {
appJson.plugins['uni-ad'] = { appJson.plugins['uni-ad'] = {
version: '1.0.3', version: '1.1.0',
provider: 'wx999bf02c8e05dfc9' provider: 'wx999bf02c8e05dfc9'
} }
} }
if (!appJson.plugins['coral-adv']) { if (!appJson.plugins['coral-adv']) {
appJson.plugins['coral-adv'] = { appJson.plugins['coral-adv'] = {
version: '1.0.7', version: '1.0.9',
provider: 'wx0e203209e27b1e66' provider: 'wx0e203209e27b1e66'
} }
} }
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
} from './interceptor' } from './interceptor'
const SYNC_API_RE = const SYNC_API_RE =
/^\$|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale|invokePushCallback|getWindowInfo|getDeviceInfo|getAppBaseInfo/ /^\$|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale|invokePushCallback|getWindowInfo|getDeviceInfo|getAppBaseInfo|getSystemSetting|getAppAuthorizeSetting/
const CONTEXT_API_RE = /^create|Manager$/ const CONTEXT_API_RE = /^create|Manager$/
......
...@@ -10,6 +10,29 @@ export { ...@@ -10,6 +10,29 @@ export {
} }
from './create-app' from './create-app'
export let createLaunchOptions = function () {
const scene = 1001
const referrerInfo = {
appId: '',
extraData: {},
}
try {
return {
path: this.$route.meta && this.$route.meta.pagePath,
query: this.$route.query,
scene,
referrerInfo
}
} catch (error) {
return {
path: '',
query: {},
scene,
referrerInfo
}
}
}
export function createAppMixin (Vue, routes, entryRoute) { export function createAppMixin (Vue, routes, entryRoute) {
return { return {
created: function AppCreated () { created: function AppCreated () {
...@@ -31,13 +54,10 @@ export function createAppMixin (Vue, routes, entryRoute) { ...@@ -31,13 +54,10 @@ export function createAppMixin (Vue, routes, entryRoute) {
}, },
mounted: function appMounted () { mounted: function appMounted () {
// 稍微靠后点,让 App 有机会在 mounted 事件前注册一些全局事件监听,如 UI 显示(showModal) // 稍微靠后点,让 App 有机会在 mounted 事件前注册一些全局事件监听,如 UI 显示(showModal)
const args = { createLaunchOptions = createLaunchOptions.bind(this)
path: this.$route.meta && this.$route.meta.pagePath, const args = createLaunchOptions()
query: this.$route.query,
scene: 1001
}
callAppHook(this, 'onLaunch', args) callAppHook(this, 'onLaunch', args)
callAppHook(this, 'onShow', args) callAppHook(this, 'onShow', args)
} }
} }
} }
...@@ -130,6 +130,8 @@ export default { ...@@ -130,6 +130,8 @@ export default {
touchstart: this._hoverTouchStart, touchstart: this._hoverTouchStart,
touchend: this._hoverTouchEnd, touchend: this._hoverTouchEnd,
touchcancel: this._hoverTouchCancel, touchcancel: this._hoverTouchCancel,
mousedown: this._hoverMousedown,
mouseup: this._hoverMouseup,
click: this._onClick click: this._onClick
} }
}, },
...@@ -429,4 +431,4 @@ export default { ...@@ -429,4 +431,4 @@ export default {
border-color: rgba(230, 67, 64, 0.6); border-color: rgba(230, 67, 64, 0.6);
background-color: transparent; background-color: transparent;
} }
</style> </style>
...@@ -185,6 +185,9 @@ export default { ...@@ -185,6 +185,9 @@ export default {
ySync (val) { ySync (val) {
this._setY(val) this._setY(val)
}, },
disabled () {
this.__handleTouchStart()
},
scaleValue (val) { scaleValue (val) {
this.scaleValueSync = Number(val) || 0 this.scaleValueSync = Number(val) || 0
}, },
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
@touchstart="_hoverTouchStart" @touchstart="_hoverTouchStart"
@touchend="_hoverTouchEnd" @touchend="_hoverTouchEnd"
@touchcancel="_hoverTouchCancel" @touchcancel="_hoverTouchCancel"
@mousedown="_hoverMousedown"
@mouseup="_hoverMouseup"
@click="_onClick" @click="_onClick"
v-on="$listeners" v-on="$listeners"
> >
......
...@@ -4,6 +4,7 @@ export default { ...@@ -4,6 +4,7 @@ export default {
hovering: false hovering: false
} }
}, },
props: { props: {
hoverClass: { hoverClass: {
type: String, type: String,
...@@ -22,8 +23,25 @@ export default { ...@@ -22,8 +23,25 @@ export default {
default: 400 default: 400
} }
}, },
methods: { methods: {
_hoverTouchStart (evt) { _hoverTouchStart (evt) {
if (evt.touches.length > 1) {
return
}
this._handleHoverStart(evt)
},
_hoverMousedown (evt) {
if (this._hoverTouch) {
return
}
this._handleHoverStart(evt)
window.addEventListener('mouseup', this._hoverMouseup)
},
_handleHoverStart (evt) {
// TODO detect scrolling // TODO detect scrolling
if (evt._hoverPropagationStopped) { if (evt._hoverPropagationStopped) {
return return
...@@ -31,9 +49,6 @@ export default { ...@@ -31,9 +49,6 @@ export default {
if (!this.hoverClass || this.hoverClass === 'none' || this.disabled) { if (!this.hoverClass || this.hoverClass === 'none' || this.disabled) {
return return
} }
if (evt.touches.length > 1) {
return
}
if (this.hoverStopPropagation) { if (this.hoverStopPropagation) {
evt._hoverPropagationStopped = true evt._hoverPropagationStopped = true
} }
...@@ -45,12 +60,27 @@ export default { ...@@ -45,12 +60,27 @@ export default {
} }
}, this.hoverStartTime) }, this.hoverStartTime)
}, },
_hoverTouchEnd (evt) {
_hoverMouseup () {
if (!this._hoverTouch) {
return
}
this._handleHoverEnd()
window.removeEventListener('mouseup', this._hoverMouseup)
},
_hoverTouchEnd () {
this._handleHoverEnd()
},
_handleHoverEnd () {
this._hoverTouch = false this._hoverTouch = false
if (this.hovering) { if (this.hovering) {
this._hoverReset() this._hoverReset()
} }
}, },
_hoverReset () { _hoverReset () {
requestAnimationFrame(() => { requestAnimationFrame(() => {
clearTimeout(this._hoverStayTimer) clearTimeout(this._hoverStayTimer)
...@@ -59,10 +89,11 @@ export default { ...@@ -59,10 +89,11 @@ export default {
}, this.hoverStayTime) }, this.hoverStayTime)
}) })
}, },
_hoverTouchCancel (evt) {
_hoverTouchCancel () {
this._hoverTouch = false this._hoverTouch = false
this.hovering = false this.hovering = false
clearTimeout(this._hoverStartTimer) clearTimeout(this._hoverStartTimer)
} }
} }
} }
import { import {
invoke invoke
} from '../../bridge' } from '../../bridge'
import { isFn, isPlainObject } from 'uni-shared'
const providers = { const providers = {
oauth (callback) { oauth (callback) {
...@@ -11,7 +12,7 @@ const providers = { ...@@ -11,7 +12,7 @@ const providers = {
}) => { }) => {
provider.push(id) provider.push(id)
}) })
callback(null, provider) callback(null, provider, services)
}, err => { }, err => {
callback(err) callback(err)
}) })
...@@ -24,7 +25,7 @@ const providers = { ...@@ -24,7 +25,7 @@ const providers = {
}) => { }) => {
provider.push(id) provider.push(id)
}) })
callback(null, provider) callback(null, provider, services)
}, err => { }, err => {
callback(err) callback(err)
}) })
...@@ -37,14 +38,15 @@ const providers = { ...@@ -37,14 +38,15 @@ const providers = {
}) => { }) => {
provider.push(id) provider.push(id)
}) })
callback(null, provider) callback(null, provider, services)
}, err => { }, err => {
callback(err) callback(err)
}) })
}, },
push (callback) { push (callback) {
if (typeof weex !== 'undefined' || typeof plus !== 'undefined') { if (typeof weex !== 'undefined' || typeof plus !== 'undefined') {
callback(null, [plus.push.getClientInfo().id]) const clientInfo = plus.push.getClientInfo()
callback(null, [clientInfo.id], [clientInfo])
} else { } else {
callback(null, []) callback(null, [])
} }
...@@ -55,7 +57,7 @@ export function getProvider ({ ...@@ -55,7 +57,7 @@ export function getProvider ({
service service
}, callbackId) { }, callbackId) {
if (providers[service]) { if (providers[service]) {
providers[service]((err, provider) => { providers[service]((err, provider, providers) => {
if (err) { if (err) {
invoke(callbackId, { invoke(callbackId, {
errMsg: 'getProvider:fail ' + err.message errMsg: 'getProvider:fail ' + err.message
...@@ -64,7 +66,25 @@ export function getProvider ({ ...@@ -64,7 +66,25 @@ export function getProvider ({
invoke(callbackId, { invoke(callbackId, {
errMsg: 'getProvider:ok', errMsg: 'getProvider:ok',
service, service,
provider provider,
providers: providers.map((provider) => {
const returnProvider = {}
if (isPlainObject(provider)) {
for (const key in provider) {
if (Object.hasOwnProperty.call(provider, key)) {
const item = provider[key]
if (!isFn(item) && typeof item !== 'undefined') {
const _key =
key === 'nativeClient' || key === 'serviceReady'
? 'isAppExist'
: key
returnProvider[_key] = item
}
}
}
}
return returnProvider
})
}) })
} }
}) })
......
...@@ -320,7 +320,9 @@ export default { ...@@ -320,7 +320,9 @@ export default {
if (id || id === 0) { if (id || id === 0) {
nativeMarker.onclick = (e) => { nativeMarker.onclick = (e) => {
this.$trigger('markertap', {}, { this.$trigger('markertap', {}, {
markerId: id markerId: id,
latitude,
longitude
}) })
} }
if (nativeBubble) { if (nativeBubble) {
......
import {
createLaunchOptions
} from 'uni-core/service/plugins/app'
export function getLaunchOptionsSync () {
return createLaunchOptions()
}
export function getEnterOptionsSync () {
return createLaunchOptions()
}
...@@ -374,10 +374,6 @@ export default { ...@@ -374,10 +374,6 @@ export default {
this.isBoundsReady = true this.isBoundsReady = true
this.$emit('boundsready') this.$emit('boundsready')
}) })
maps.event.addListener(map, 'click', () => {
// TODO 编译器将 tap 转换为click
this.$trigger('click', {}, {})
})
maps.event.addListener(map, 'dragstart', () => { maps.event.addListener(map, 'dragstart', () => {
this.$trigger('regionchange', {}, { this.$trigger('regionchange', {}, {
type: 'begin', type: 'begin',
......
...@@ -95,7 +95,7 @@ export default { ...@@ -95,7 +95,7 @@ export default {
}) })
this.$parent._markers[this.idString] = marker this.$parent._markers[this.idString] = marker
this.updateMarker(props) this.updateMarker(props)
maps.event.addListener(marker, 'click', () => { maps.event.addListener(marker, 'click', (e) => {
const callout = marker.callout const callout = marker.callout
if (callout) { if (callout) {
const div = callout.div const div = callout.div
...@@ -110,9 +110,14 @@ export default { ...@@ -110,9 +110,14 @@ export default {
} }
if (this.idString) { if (this.idString) {
this.$parent.$trigger('markertap', {}, { this.$parent.$trigger('markertap', {}, {
markerId: Number(this.idString) markerId: Number(this.idString),
latitude: typeof e.latLng.lat === 'function' ? e.latLng.lat() : e.latLng.lat,
longitude: typeof e.latLng.lat === 'function' ? e.latLng.lng() : e.latLng.lng
}) })
} }
const event = e.event || e.domEvent
event.stopPropagation()
}) })
}, },
updateMarker (option) { updateMarker (option) {
......
...@@ -5,13 +5,15 @@ ...@@ -5,13 +5,15 @@
@touchstart="_hoverTouchStart" @touchstart="_hoverTouchStart"
@touchend="_hoverTouchEnd" @touchend="_hoverTouchEnd"
@touchcancel="_hoverTouchCancel" @touchcancel="_hoverTouchCancel"
@mousedown="_hoverMousedown"
@mouseup="_hoverMouseup"
v-on="$listeners" v-on="$listeners"
> >
<slot /> <slot />
</uni-view> </uni-view>
<uni-view <uni-view
v-else v-else
v-on="$listeners" v-on="$listeners"
> >
<slot /> <slot />
</uni-view> </uni-view>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册