提交 305b8398 编写于 作者: Q qiang

Merge branch 'dev' into alpha

# Conflicts:
#	packages/uni-h5/dist/index.umd.min.js
......@@ -55,6 +55,10 @@ const DEPS = {
createIntersectionObserver: [
['/core/view/bridge/subscribe/api/request-component-observer.js', 'requestComponentObserver'],
['/core/view/bridge/subscribe/api/request-component-observer.js', 'destroyComponentObserver']
],
createMediaQueryObserver: [
['/core/view/bridge/subscribe/api/request-media-query-observer.js', 'requestMediaQueryObserver'],
['/core/view/bridge/subscribe/api/request-media-query-observer.js', 'destroyMediaQueryObserver']
]
}
......
此差异已折叠。
......@@ -337,6 +337,11 @@ describe('mp:compiler-extra', () => {
'<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"></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,item.length,undefined)}}}'
)
assertCodegen(
'<view v-for="(item,index) in list" :key="index"><view @click="event=>showEventInfo(event,item)"></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"></view></view></block>',
'with(this){if(!_isMounted){e0=(event,item,...args)=>{var _temp=args[args.length-1].currentTarget.dataset,_temp2=_temp.eventParams||_temp["event-params"],item=_temp2.item;var _temp,_temp2;return showEventInfo(event,item)}}}'
)
})
it('generate class binding', () => {
......
......@@ -202,6 +202,10 @@ function parseEventByCallExpression (callExpr, methods) {
methods.push(t.arrayExpression(arrayExpression))
}
function isValuePath (path) {
return path.key !== 'key' && path.key !== 'id' && (path.key !== 'property' || path.parent.computed) && !(path.key === 'value' && path.parentPath.parentPath.isObjectPattern()) && !(path.key === 'left' && path.parentPath.parentPath.parentPath.isObjectPattern())
}
function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false, tagName, ret) {
const key = keyPath.node
let type = key.value || key.name || ''
......@@ -268,18 +272,31 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
state.errors.add(
`${tagName} 组件 ${type} 事件仅支持 @${type}="methodName" 方式绑定`
)
} else if (funcPath.isArrowFunctionExpression()) { // e=>count++
methods.push(addEventExpressionStatement(funcPath, state, isCustom))
} else {
let anonymous = true
// "click":function($event) {click1(item);click2(item);}
const body = funcPath.node.body && funcPath.node.body.body
if (body && body.length) {
const funcParams = funcPath.node.params
if (body && body.length && funcParams && funcParams.length === 1) {
const exprStatements = body.filter(node => {
return t.isExpressionStatement(node) && t.isCallExpression(node.expression)
})
if (exprStatements.length === body.length) {
const paramPath = funcPath.get('params')[0]
const paramName = paramPath.node.name
if (paramName !== '$event') {
funcPath.get('body').traverse({
Identifier (path) {
const node = path.node
const binding = path.scope.getBinding(node.name)
if (binding && binding.identifier === paramPath.node && isValuePath(path)) {
path.replaceWith(t.identifier('$event'))
}
}
})
paramPath.replaceWith(t.identifier('$event'))
}
anonymous = false
exprStatements.forEach(exprStatement => {
parseEventByCallExpression(exprStatement.expression, methods)
......@@ -335,7 +352,7 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
const scope = path.scope
const node = path.node
const name = node.name
if (path.key !== 'key' && (path.key !== 'property' || path.parent.computed) && scope && !scope.hasOwnBinding(name) && scope.hasBinding(name) && !params.includes(name) && name !== 'undefined') {
if (isValuePath(path) && scope && !scope.hasOwnBinding(name) && scope.hasBinding(name) && !params.includes(name) && name !== 'undefined') {
params.push(name)
}
}
......@@ -344,10 +361,15 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
funcPath.node.params.push(t.identifier(name))
})
if (params.length) {
let argumentsName = 'arguments'
if (funcPath.isArrowFunctionExpression()) {
argumentsName = 'args'
funcPath.node.params.push(t.restElement(t.identifier(argumentsName)))
}
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}'],${params.map(item => `${item}=${paramsUid}.${item}`).join(',')}`
const code = `var ${datasetUid}=${argumentsName}[${argumentsName}.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))
......
......@@ -16,14 +16,15 @@ function isFunction (expr) {
function processEvent (expr, filterModules) {
const isMethodPath = simplePathRE.test(expr)
expr = `(${expr})`
if (isMethodPath || isFunction(expr)) {
if (filterModules.find(name => expr.indexOf(name + '.') === 0)) {
return `
$event = $handleWxsEvent($event);
(${expr})($event, $getComponentDescriptor())
${expr}($event, $getComponentDescriptor())
`
} else {
expr = `(${expr})(...arguments)`
expr = `${expr}(...arguments)`
}
}
return `
......
......@@ -6,10 +6,12 @@
<uni-top-window
v-if="topWindow"
v-show="showTopWindow && topWindowMediaQuery"
ref="topWindow"
:style="topWindowStyle"
>
<div class="uni-top-window">
<div
ref="topWindow"
class="uni-top-window"
:style="topWindowStyle"
>
<v-uni-top-window
ref="top"
@hook:mounted="onTopWindowInit"
......@@ -214,7 +216,7 @@ export default {
onTopWindowInit () {
// TODO page header
let windowTopHeight = '0px'
if (this.topWindowStyle && this.topWindowStyle.width) {
if (this.topWindowStyle && this.topWindowStyle.height) {
windowTopHeight = this.$refs.topWindow.offsetHeight + 'px'
} else {
windowTopHeight = this.$refs.top.$el.offsetHeight + 'px'
......@@ -273,6 +275,7 @@ export default {
left: 0;
right: 0;
top: 0;
z-index: 998;
z-index: 998;
overflow: hidden;
}
</style>
function cssSupports (css) {
return window.CSS && window.CSS.supports && window.CSS.supports(css)
return window.CSS && window.CSS.supports && (window.CSS.supports(css) || window.CSS.supports('--a', 0))
}
export default {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册