提交 3a9f0109 编写于 作者: fxy060608's avatar fxy060608

fix: map with tap event

上级 5d477d59
......@@ -33,7 +33,13 @@ export const transformMatchMedia = createTransformTag({
})
export const transformTapToClick = createTransformEvent({
tap: 'click',
tap: (node) => {
// 地图组件有自己特定的 tap 事件
if (node.tag === 'map' || node.tag === 'v-uni-map') {
return 'tap'
}
return 'click'
},
})
export const transformComponentLink =
......
import { DirectiveNode, NodeTransform } from '@vue/compiler-core'
import { DirectiveNode, ElementNode, NodeTransform } from '@vue/compiler-core'
import { isFunction } from '@vue/shared'
import { isElementNode, isSimpleExpressionNode } from '../../vite/utils/ast'
export function createTransformEvent(
options: Record<string, string>
options: Record<
string,
string | ((node: ElementNode, dir: DirectiveNode) => string)
>
): NodeTransform {
return function transformEvent(node) {
if (!isElementNode(node)) {
......@@ -14,7 +18,11 @@ export function createTransformEvent(
const eventType = options[arg.content]
if (eventType) {
// e.g tap => click
arg.content = eventType
if (isFunction(eventType)) {
arg.content = eventType(node, prop as DirectiveNode)
} else {
arg.content = eventType
}
}
}
})
......
......@@ -2,20 +2,28 @@ import { BindingTypes } from '@vue/compiler-core'
import { compileTemplate } from '@vue/compiler-sfc'
import { compilerOptions } from '../src/plugin/uni'
const filename = 'foo.vue'
function compile(source: string) {
return compileTemplate({
source,
filename,
id: filename,
compilerOptions: {
...compilerOptions,
bindingMetadata: {
canvas: BindingTypes.SETUP_REF,
},
},
})
}
describe('h5: compiler', () => {
test('tap=>click', () => {
expect(compile('<view @tap="tap"/>').code).toContain(`onClick`)
expect(compile('<map @tap="tap"/>').code).toContain(`onTap`)
})
test('builtInComponents', () => {
expect(
compileTemplate({
source: `<canvas/>`,
filename,
id: filename,
compilerOptions: {
...compilerOptions,
bindingMetadata: {
canvas: BindingTypes.SETUP_REF,
},
},
}).code
).toContain(`_resolveComponent("v-uni-canvas")`)
expect(compile('<canvas/>').code).toContain(
`_resolveComponent("v-uni-canvas")`
)
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册