refactor(compiler-vapor): remove vnode-related, adjust key override

This commit is contained in:
三咲智子 Kevin Deng 2024-02-08 03:26:51 +08:00
parent 3957dabb8c
commit ce570751c6
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
3 changed files with 9 additions and 43 deletions

View File

@ -440,26 +440,6 @@ describe('v-on', () => {
expect(code).contains('fooBar') expect(code).contains('fooBar')
}) })
test('error for vnode hooks', () => {
const onError = vi.fn()
compileWithVOn(`<div v-on:vnode-mounted="onMount"/>`, { onError })
expect(onError.mock.calls[0][0]).toMatchObject({
code: ErrorCodes.X_VNODE_HOOKS,
loc: {
start: {
line: 1,
column: 11,
},
end: {
line: 1,
column: 24,
},
},
})
})
test.todo('vue: prefixed events')
test('should support multiple modifiers and event options w/ prefixIdentifiers: true', () => { test('should support multiple modifiers and event options w/ prefixIdentifiers: true', () => {
const { code, ir, vaporHelpers } = compileWithVOn( const { code, ir, vaporHelpers } = compileWithVOn(
`<div @click.stop.prevent.capture.once="test"/>`, `<div @click.stop.prevent.capture.once="test"/>`,

View File

@ -220,7 +220,6 @@ export interface IRDynamicInfo {
export type IRExpression = SimpleExpressionNode | string export type IRExpression = SimpleExpressionNode | string
export interface IREffect { export interface IREffect {
// TODO multi-expression effect
expressions: IRExpression[] expressions: IRExpression[]
operations: OperationNode[] operations: OperationNode[]
} }

View File

@ -22,18 +22,7 @@ export const transformVOn: DirectiveTransform = (dir, node, context) => {
} }
if (arg.isStatic) { if (arg.isStatic) {
let rawName = arg.content if (node.tagType !== ElementTypes.ELEMENT || !/[A-Z]/.test(arg.content)) {
if (__DEV__ && rawName.startsWith('vnode')) {
context.options.onError(
createCompilerError(ErrorCodes.X_VNODE_HOOKS, arg.loc),
)
}
if (
node.tagType !== ElementTypes.ELEMENT ||
rawName.startsWith('vnode') ||
!/[A-Z]/.test(rawName)
) {
arg.content = camelize(arg.content) arg.content = camelize(arg.content)
} }
} }
@ -47,18 +36,9 @@ export const transformVOn: DirectiveTransform = (dir, node, context) => {
) )
let keyOverride: KeyOverride | undefined let keyOverride: KeyOverride | undefined
// normalize click.right and click.middle since they don't actually fire
const isStaticClick = arg.isStatic && arg.content.toLowerCase() === 'click' const isStaticClick = arg.isStatic && arg.content.toLowerCase() === 'click'
if (nonKeyModifiers.includes('right')) { // normalize click.right and click.middle since they don't actually fire
if (isStaticClick) {
arg = extend({}, arg, { content: 'contextmenu' })
} else if (!arg.isStatic) {
keyOverride = ['click', 'contextmenu']
}
}
if (nonKeyModifiers.includes('middle')) { if (nonKeyModifiers.includes('middle')) {
if (keyOverride) { if (keyOverride) {
// TODO error here // TODO error here
@ -69,6 +49,13 @@ export const transformVOn: DirectiveTransform = (dir, node, context) => {
keyOverride = ['click', 'mouseup'] keyOverride = ['click', 'mouseup']
} }
} }
if (nonKeyModifiers.includes('right')) {
if (isStaticClick) {
arg = extend({}, arg, { content: 'contextmenu' })
} else if (!arg.isStatic) {
keyOverride = ['click', 'contextmenu']
}
}
const operation: SetEventIRNode = { const operation: SetEventIRNode = {
type: IRNodeTypes.SET_EVENT, type: IRNodeTypes.SET_EVENT,