Parcourir la source

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

三咲智子 Kevin Deng il y a 2 ans
Parent
commit
ce570751c6

+ 0 - 20
packages/compiler-vapor/__tests__/transforms/vOn.spec.ts

@@ -440,26 +440,6 @@ describe('v-on', () => {
     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', () => {
     const { code, ir, vaporHelpers } = compileWithVOn(
       `<div @click.stop.prevent.capture.once="test"/>`,

+ 0 - 1
packages/compiler-vapor/src/ir.ts

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

+ 9 - 22
packages/compiler-vapor/src/transforms/vOn.ts

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