zhangdaren / miniprogram-to-uniapp

轻松将各种小程序转换为uni-app项目
Other
1.67k stars 277 forks source link

transformEvent顺序错误 #142

Closed dvien closed 2 years ago

dvien commented 2 years ago

问题描述?

src/page/template/template-transformer.js transformEvent处理bind:与capture-bind:及catch:与capture-catch:存在冲突,匹配短的先执行,会导致capture-被替换成错误标签

重现步骤

function transformEvent(keyNode, valueNode, state) { // name, value, attribs,state var name = keyNode.content

let event = name
if (name.indexOf('bind') === 0) {
    event = transformEventName(name.replace(bindRE, ''), state)
} else if (name.indexOf('catch') === 0) {
    event = transformEventName(name.replace(catchRE, ''), state) + '.stop.prevent'
} else if (name.indexOf('capture-bind') === 0) {
    event = transformEventName(name.replace(captureBindRE, ''), state) + '.capture'
} else if (name.indexOf('capture-catch') === 0) {
    event = transformEventName(name.replace(captureCatchRE, ''), state) + '.stop.prevent.capture'
}

期望的结果

function transformEvent(keyNode, valueNode, state) { // name, value, attribs,state var name = keyNode.content

let event = name
if (name.indexOf('capture-bind') === 0) {
    event = transformEventName(name.replace(captureBindRE, ''), state) + '.capture'
} else if (name.indexOf('bind') === 0) {
    event = transformEventName(name.replace(bindRE, ''), state)
} else if (name.indexOf('capture-catch') === 0) {
    event = transformEventName(name.replace(captureCatchRE, ''), state) + '.stop.prevent.capture'
} else if  (name.indexOf('catch') === 0) {
    event = transformEventName(name.replace(catchRE, ''), state) + '.stop.prevent'
}