提交 421b2fb6 编写于 作者: fxy060608's avatar fxy060608

fix(vue2): tap.native=>click.native (#3259)

上级 c5b25d9f
......@@ -5,17 +5,25 @@ const deprecated = {
}
}
module.exports = function parseEvent (el) {
if (el.events) {
if (el.events || el.nativeEvents) {
const {
events: eventsMap
} = deprecated
Object.keys(el.events).forEach(name => {
// 过时事件类型转换
if (eventsMap[name]) {
el.events[eventsMap[name]] = el.events[name]
delete el.events[name]
// warnLogs.add(`警告:事件${name}已过时,推荐使用${eventsMap[name]}代替`)
}
})
normalizeEvent(el.events, eventsMap)
normalizeEvent(el.nativeEvents, eventsMap)
}
}
function normalizeEvent (events, eventsMap) {
if (!events) {
return
}
Object.keys(events).forEach(name => {
// 过时事件类型转换
if (eventsMap[name]) {
events[eventsMap[name]] = events[name]
delete events[name]
// warnLogs.add(`警告:事件${name}已过时,推荐使用${eventsMap[name]}代替`)
}
})
}
......@@ -10,8 +10,9 @@ function isFunction (expr) {
try {
const body = parser.parse(`(${expr})`).program.body[0]
const expression = body.expression
return t.isFunctionDeclaration(body) || t.isArrowFunctionExpression(expression) || t.isFunctionExpression(expression)
} catch (error) { }
return t.isFunctionDeclaration(body) || t.isArrowFunctionExpression(expression) || t.isFunctionExpression(
expression)
} catch (error) {}
}
function processEvent (expr, filterModules) {
......@@ -80,31 +81,39 @@ module.exports = {
})
}
}
if (el.events) {
if (el.events || el.nativeEvents) {
filterModules = filterModules || []
const {
events: eventsMap
} = deprecated
// const warnLogs = new Set()
Object.keys(el.events).forEach(name => {
// 过时事件类型转换
if (eventsMap[name]) {
el.events[eventsMap[name]] = el.events[name]
delete el.events[name]
// warnLogs.add(`警告:事件${name}已过时,推荐使用${eventsMap[name]}代替`)
name = eventsMap[name]
}
const handlers = el.events[name]
if (Array.isArray(handlers)) {
handlers.forEach(handler => {
handler.value = processEvent(handler.value, filterModules)
})
} else {
handlers.value = processEvent(handlers.value, filterModules)
}
})
normalizeEvent(el.events, eventsMap, filterModules)
normalizeEvent(el.nativeEvents, eventsMap, filterModules)
}
}
}]
}
function normalizeEvent (events, eventsMap, filterModules) {
if (!events) {
return
}
Object.keys(events).forEach(name => {
// 过时事件类型转换
if (eventsMap[name]) {
events[eventsMap[name]] = events[name]
delete events[name]
// warnLogs.add(`警告:事件${name}已过时,推荐使用${eventsMap[name]}代替`)
name = eventsMap[name]
}
const handlers = events[name]
if (Array.isArray(handlers)) {
handlers.forEach(handler => {
handler.value = processEvent(handler.value, filterModules)
})
} else {
handlers.value = processEvent(handlers.value, filterModules)
}
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册