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

chore: merge

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