Skip to content

Commit 6c0390a

Browse files
committed
chore: remove cache event name
1 parent 27179f6 commit 6c0390a

File tree

4 files changed

+4
-63
lines changed

4 files changed

+4
-63
lines changed

packages/compiler/src/generate.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ export class CodegenContext {
3838
identifiers: Record<string, (string | SimpleExpressionNode)[]> =
3939
Object.create(null)
4040

41-
seenInlineHandlerNames: Record<string, number> = Object.create(null)
42-
4341
block: BlockIRNode
4442
withId<T>(
4543
fn: () => T,

packages/compiler/src/generators/component.ts

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
createSimpleExpression,
3-
isMemberExpression,
4-
toValidAssetId,
5-
type SimpleExpressionNode,
6-
} from '@vue/compiler-dom'
1+
import { createSimpleExpression, toValidAssetId } from '@vue/compiler-dom'
72
import { camelize, extend, isArray } from '@vue/shared'
83
import { walkIdentifiers } from 'ast-kit'
94
import {
@@ -48,21 +43,11 @@ export function genCreateComponent(
4843

4944
const tag = genTag()
5045
const { root, props, slots, once } = operation
46+
const rawProps = genRawProps(props, context)
5147
const rawSlots = genRawSlots(slots, context)
52-
const [ids, handlers] = processInlineHandlers(props, context)
53-
const rawProps = context.withId(() => genRawProps(props, context), ids)
54-
55-
const inlineHandlers: CodeFragment[] = handlers.reduce<CodeFragment[]>(
56-
(acc, { name, value }) => {
57-
const handler = genEventHandler(context, value, undefined, false)
58-
return [...acc, `const ${name} = `, ...handler, NEWLINE]
59-
},
60-
[],
61-
)
6248

6349
return [
6450
NEWLINE,
65-
...inlineHandlers,
6651
`const n${operation.id} = `,
6752
...genCall(
6853
operation.dynamic && !operation.dynamic.isStatic
@@ -100,47 +85,6 @@ export function genCreateComponent(
10085
}
10186
}
10287

103-
function getUniqueHandlerName(context: CodegenContext, name: string): string {
104-
const { seenInlineHandlerNames } = context
105-
const count = seenInlineHandlerNames[name] || 0
106-
seenInlineHandlerNames[name] = count + 1
107-
return count === 0 ? name : `${name}${count}`
108-
}
109-
110-
type InlineHandler = {
111-
name: string
112-
value: SimpleExpressionNode
113-
}
114-
115-
function processInlineHandlers(
116-
props: IRProps[],
117-
context: CodegenContext,
118-
): [Record<string, null>, InlineHandler[]] {
119-
const ids: Record<string, null> = Object.create(null)
120-
const handlers: InlineHandler[] = []
121-
const staticProps = props[0]
122-
if (isArray(staticProps)) {
123-
for (const prop of staticProps) {
124-
if (!prop.handler) continue
125-
prop.values.forEach((value, i) => {
126-
const isMemberExp = isMemberExpression(value, context.options)
127-
// cache inline handlers (fn expression or inline statement)
128-
if (!isMemberExp) {
129-
const name = getUniqueHandlerName(
130-
context,
131-
`_on_${prop.key.content.replace(':', '_')}`,
132-
)
133-
handlers.push({ name, value })
134-
ids[name] = null
135-
// replace the original prop value with the handler name
136-
prop.values[i] = extend({ ast: null }, createSimpleExpression(name))
137-
}
138-
})
139-
}
140-
}
141-
return [ids, handlers]
142-
}
143-
14488
export function genRawProps(
14589
props: IRProps[],
14690
context: CodegenContext,

packages/compiler/test/transforms/__snapshots__/vOn.spec.ts.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ exports[`v-on > event modifier 1`] = `
5858

5959
exports[`v-on > namespace event with Component 1`] = `
6060
"
61-
const _on_update_modelValue = () => {}
62-
const n0 = _createComponent(Comp, { "onUpdate:modelValue": () => _on_update_modelValue }, null, true)
61+
const n0 = _createComponent(Comp, { "onUpdate:modelValue": () => () => {} }, null, true)
6362
return n0
6463
"
6564
`;

packages/compiler/test/transforms/vOn.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ describe('v-on', () => {
331331
const { code } = compileWithVOn(`<Comp onUpdate:modelValue={() => {}} />`)
332332
expect(code).toMatchSnapshot()
333333
expect(code).contains(
334-
'_createComponent(Comp, { "onUpdate:modelValue": () => _on_update_modelValue }, null, true)',
334+
'_createComponent(Comp, { "onUpdate:modelValue": () => () => {} }, null, true)',
335335
)
336336
})
337337

0 commit comments

Comments
 (0)