提交 10f51f22 编写于 作者: Q qiang

Merge branch 'dev' into alpha

......@@ -174,12 +174,14 @@ function findHooks(vueOptions, hooks = new Set()) {
hooks.add(name);
}
});
const { extends: extendsOptions, mixins } = vueOptions;
if (mixins) {
mixins.forEach(mixin => findHooks(mixin, hooks));
}
if (extendsOptions) {
findHooks(extendsOptions, hooks);
if (__VUE_OPTIONS_API__) {
const { extends: extendsOptions, mixins } = vueOptions;
if (mixins) {
mixins.forEach(mixin => findHooks(mixin, hooks));
}
if (extendsOptions) {
findHooks(extendsOptions, hooks);
}
}
}
return hooks;
......
......@@ -165,12 +165,14 @@ function findHooks(vueOptions, hooks = new Set()) {
hooks.add(name);
}
});
const { extends: extendsOptions, mixins } = vueOptions;
if (mixins) {
mixins.forEach(mixin => findHooks(mixin, hooks));
}
if (extendsOptions) {
findHooks(extendsOptions, hooks);
if (__VUE_OPTIONS_API__) {
const { extends: extendsOptions, mixins } = vueOptions;
if (mixins) {
mixins.forEach(mixin => findHooks(mixin, hooks));
}
if (extendsOptions) {
findHooks(extendsOptions, hooks);
}
}
}
return hooks;
......
......@@ -165,12 +165,14 @@ function findHooks(vueOptions, hooks = new Set()) {
hooks.add(name);
}
});
const { extends: extendsOptions, mixins } = vueOptions;
if (mixins) {
mixins.forEach(mixin => findHooks(mixin, hooks));
}
if (extendsOptions) {
findHooks(extendsOptions, hooks);
if (__VUE_OPTIONS_API__) {
const { extends: extendsOptions, mixins } = vueOptions;
if (mixins) {
mixins.forEach(mixin => findHooks(mixin, hooks));
}
if (extendsOptions) {
findHooks(extendsOptions, hooks);
}
}
}
return hooks;
......
......@@ -165,12 +165,14 @@ function findHooks(vueOptions, hooks = new Set()) {
hooks.add(name);
}
});
const { extends: extendsOptions, mixins } = vueOptions;
if (mixins) {
mixins.forEach(mixin => findHooks(mixin, hooks));
}
if (extendsOptions) {
findHooks(extendsOptions, hooks);
if (__VUE_OPTIONS_API__) {
const { extends: extendsOptions, mixins } = vueOptions;
if (mixins) {
mixins.forEach(mixin => findHooks(mixin, hooks));
}
if (extendsOptions) {
findHooks(extendsOptions, hooks);
}
}
}
return hooks;
......
......@@ -165,12 +165,14 @@ function findHooks(vueOptions, hooks = new Set()) {
hooks.add(name);
}
});
const { extends: extendsOptions, mixins } = vueOptions;
if (mixins) {
mixins.forEach(mixin => findHooks(mixin, hooks));
}
if (extendsOptions) {
findHooks(extendsOptions, hooks);
if (__VUE_OPTIONS_API__) {
const { extends: extendsOptions, mixins } = vueOptions;
if (mixins) {
mixins.forEach(mixin => findHooks(mixin, hooks));
}
if (extendsOptions) {
findHooks(extendsOptions, hooks);
}
}
}
return hooks;
......
......@@ -165,12 +165,14 @@ function findHooks(vueOptions, hooks = new Set()) {
hooks.add(name);
}
});
const { extends: extendsOptions, mixins } = vueOptions;
if (mixins) {
mixins.forEach(mixin => findHooks(mixin, hooks));
}
if (extendsOptions) {
findHooks(extendsOptions, hooks);
if (__VUE_OPTIONS_API__) {
const { extends: extendsOptions, mixins } = vueOptions;
if (mixins) {
mixins.forEach(mixin => findHooks(mixin, hooks));
}
if (extendsOptions) {
findHooks(extendsOptions, hooks);
}
}
}
return hooks;
......
......@@ -18,7 +18,7 @@ describe('mp:compiler-mp-alipay', () => {
it('generate v-for directive', () => {
assertCodegen(
'<view><view v-for="(item,index) in items" :key="index"></view></view>',
'<view><block a:for="{{items}}" a:for-item="item" a:for-index="index" a:key="index"><view></view></block></view>'
'<view><view a:for="{{items}}" a:for-item="item" a:for-index="index" a:key="index"></view></view>'
)
})
......@@ -39,11 +39,11 @@ describe('mp:compiler-mp-alipay', () => {
)
assertCodegen(
'<component1 v-for="item in items" ref="c3"></component1>',
'<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{\'551070e6-1-\'+__i0__}}" ref="__r" data-ref-in-for="c3" onVueInit="__l"></component1></block>'
'<component1 vue-id="{{\'551070e6-1-\'+__i0__}}" ref="__r" data-ref-in-for="c3" a:for="{{items}}" a:for-item="item" a:for-index="__i0__" onVueInit="__l"></component1>'
)
assertCodegen(
'<component1 v-for="item in items" :ref="c4"></component1>',
'<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{\'551070e6-1-\'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" onVueInit="__l"></component1></block>'
'<component1 vue-id="{{\'551070e6-1-\'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" a:for="{{items}}" a:for-item="item" a:for-index="__i0__" onVueInit="__l"></component1>'
)
})
it('generate default slot', () => {
......@@ -126,8 +126,8 @@ describe('mp:compiler-mp-alipay', () => {
it('generate events with v-on directive', () => {
assertCodegen(
'<uni-list-item title="标题文字" note="描述信息" show-extra-icon="true" :extra-icon="{color: \'#4cd964\',size: \'22\',type: \'spinner\'}"></uni-list-item>',
'<uni-list-item vue-id="551070e6-1" title="标题文字" note="描述信息" show-extra-icon="true" extra-icon="{{$root.a0}}" onVueInit="__l"></uni-list-item>',
'with(this){var a0={color:"#4cd964",size:"22",type:"spinner"};$mp.data=Object.assign({},{$root:{a0:a0}})}'
'<uni-list-item vue-id="551070e6-1" title="标题文字" note="描述信息" show-extra-icon="true" extra-icon="{{({color:\'#4cd964\',size:\'22\',type:\'spinner\'})}}" onVueInit="__l"></uni-list-item>',
'with(this){}'
)
assertCodegen(
......
......@@ -120,4 +120,16 @@ describe('mp:compiler-mp-weixin', () => {
'<view><slot-comp generic:scoped-slots-test="test-slot-comp-test" vue-id="551070e6-1" bind:__l="__l" vue-slots="{{[\'test\']}}"></slot-comp><slot-comp generic:scoped-slots-test="test-slot-comp-test1" vue-id="551070e6-2" bind:__l="__l" vue-slots="{{[\'test\']}}"></slot-comp><slot-comp generic:scoped-slots-test="test-slot-comp-test2" vue-id="551070e6-3" bind:__l="__l" vue-slots="{{[\'test\']}}"></slot-comp><slot-comp generic:scoped-slots-test="test-slot-comp-test3" vue-id="551070e6-4" bind:__l="__l" vue-slots="{{[\'test\']}}"></slot-comp></view>'
)
})
it('generate ObjectExpression', () => {
assertCodegen(
'<view v-for="(item,key) in {x:0}" :key="key">{{item}}</view>',
'<block wx:for="{{({x:0})}}" wx:for-item="item" wx:for-index="key" wx:key="key"><view>{{item}}</view></block>'
)
assertCodegen(
'<template v-for="(item, key) in { list1, list2 }"></template>',
'<block wx:for="{{({list1,list2})}}" wx:for-item="item" wx:for-index="key"></block>'
)
assertCodegen('<test :obj="{x:0}"></test>', '<test vue-id="551070e6-1" obj="{{({x:0})}}" bind:__l="__l"></test>')
})
})
......@@ -329,8 +329,8 @@ describe('mp:compiler', () => {
// v-for
assertCodegen(
'<view v-for="(item,index) in list" :key="index"><view @click="$test.test(item)">test</view></view>',
'<block wx:for="{{list}}" wx:for-item="item" wx:for-index="index" wx:key="index"><view><view data-event-opts="{{[[\'tap\',[[\'e0\',[\'$event\']]]]]}}" data-event-params="{{[{item}]}}" bindtap="__e">test</view></view></block>',
'with(this){if(!_isMounted){e0=function($event,item){var _temp=arguments[arguments.length-1].currentTarget.dataset,_temp2=(_temp.eventParams||_temp["event-params"])[0],item=_temp2.item;var _temp,_temp2;return $test.test(item)}}}'
'<block wx:for="{{list}}" wx:for-item="item" wx:for-index="index" wx:key="index"><view><view data-event-opts="{{[[\'tap\',[[\'e0\',[\'$event\']]]]]}}" data-event-params="{{({item})}}" bindtap="__e">test</view></view></block>',
'with(this){if(!_isMounted){e0=function($event,item){var _temp=arguments[arguments.length-1].currentTarget.dataset,_temp2=_temp.eventParams||_temp["event-params"],item=_temp2.item;var _temp,_temp2;return $test.test(item)}}}'
)
// tricky symbols in args
// assertCodegen(
......
const {
IDENTIFIER_ATTR
} = require('../../../constants')
// const {
// IDENTIFIER_ATTR
// } = require('../../../constants')
const getMemberExpr = require('../member-expr')
// const getMemberExpr = require('../member-expr')
module.exports = function processAttrs (paths, path, state, isComponent, tagName) {
const attrsPath = paths.attrs
if (attrsPath) {
attrsPath.get('value.properties').forEach(propertyPath => {
const valuePath = propertyPath.get('value')
if (valuePath.isObjectExpression()) {
valuePath.replaceWith(getMemberExpr(null, IDENTIFIER_ATTR, valuePath.node, state))
}
})
}
// 不再单独处理ObjectExpression,改为在转换temlplte时用()包裹(微信、QQ)
// const attrsPath = paths.attrs
// if (attrsPath) {
// attrsPath.get('value.properties').forEach(propertyPath => {
// const valuePath = propertyPath.get('value')
// if (valuePath.isObjectExpression()) {
// valuePath.replaceWith(getMemberExpr(null, IDENTIFIER_ATTR, valuePath.node, state))
// }
// })
// }
return []
}
}
......@@ -347,7 +347,7 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
const datasetUid = funcPath.scope.generateDeclaredUidIdentifier().name
const paramsUid = funcPath.scope.generateDeclaredUidIdentifier().name
const dataset = ATTR_DATA_EVENT_PARAMS.substring(5)
const code = `var ${datasetUid}=arguments[arguments.length-1].currentTarget.dataset,${paramsUid}=(${datasetUid}.${dataset.replace(/-([a-z])/, (_, str) => str.toUpperCase())}||${datasetUid}['${dataset}'])[0],${params.map(item => `${item}=${paramsUid}.${item}`).join(',')}`
const code = `var ${datasetUid}=arguments[arguments.length-1].currentTarget.dataset,${paramsUid}=${datasetUid}.${dataset.replace(/-([a-z])/, (_, str) => str.toUpperCase())}||${datasetUid}['${dataset}'],${params.map(item => `${item}=${paramsUid}.${item}`).join(',')}`
funcPath.node.body.body.unshift(parser.parse(code).program.body[0])
}
methods.push(addEventExpressionStatement(funcPath, state, isComponent, isNativeOn))
......@@ -478,8 +478,8 @@ module.exports = function processEvent (paths, path, state, isComponent, tagName
ret.push(
t.objectProperty(
t.stringLiteral(ATTR_DATA_EVENT_PARAMS),
// 使用数组格式,直接使用对象格式微信小程序编译会报错
t.stringLiteral(`{{[{${params.join(',')}}]}}`)
// 直接使用对象格式微信小程序编译会报错
t.stringLiteral(`{{({${params.join(',')}})}}`)
)
)
}
......
......@@ -105,7 +105,10 @@ function genElement (ast, state, isRoot = false) {
if (ast.attr[name] === '' && name !== 'value') { // value属性需要保留=''
return name
}
return `${name}="${ast.attr[name]}"`
let value = ast.attr[name]
// 微信和QQ小程序解析 {{{}}} 报错,需要使用()包裹
value = value.replace(/(\{\{)(\{.+?\})(\}\})/, '$1($2)$3')
return `${name}="${value}"`
})
.join(' ')
: ''
......
......@@ -399,10 +399,17 @@ function traverseRenderList (callExprNode, state) {
}
}
const children = traverseExpr(forReturnStatementArgument, state)
// 支付宝小程序在 block 标签上使用 key 时顺序不能保障
if (state.options.platform.name === 'mp-alipay' && t.isCallExpression(forReturnStatementArgument) && children && children.type) {
children.attr = children.attr || {}
Object.assign(children.attr, attr)
return children
}
return {
type: 'block',
attr,
children: normalizeChildren(traverseExpr(forReturnStatementArgument, state))
children: normalizeChildren(children)
}
}
......
import {
newSetStatusBarStyle
newSetStatusBarStyle,
restoreOldSetStatusBarStyle
} from '../../bridge'
export function restoreGlobal (
......@@ -19,7 +20,8 @@ export function restoreGlobal (
console.log(`[restoreGlobal][${Date.now()}]`)
}
weex = newWeex
plus = newPlus
plus = newPlus
restoreOldSetStatusBarStyle(plus.navigator.setStatusBarStyle)
plus.navigator.setStatusBarStyle = newSetStatusBarStyle
/* eslint-disable no-global-assign */
setTimeout = newSetTimeout
......
......@@ -23,7 +23,11 @@ export function publish (name, ...args) {
export let lastStatusBarStyle
const oldSetStatusBarStyle = plus.navigator.setStatusBarStyle
let oldSetStatusBarStyle = plus.navigator.setStatusBarStyle
export function restoreOldSetStatusBarStyle (setStatusBarStyle) {
oldSetStatusBarStyle = setStatusBarStyle
}
export function newSetStatusBarStyle (style) {
lastStatusBarStyle = style
......
......@@ -128,10 +128,12 @@ export function triggerEvent (type, detail, options) {
}
const eventOpts = this.props['data-event-opts']
const eventParams = this.props['data-event-params']
const target = {
dataset: {
eventOpts
eventOpts,
eventParams
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册