|
1 | | -import { |
2 | | - createSimpleExpression, |
3 | | - isMemberExpression, |
4 | | - toValidAssetId, |
5 | | - type SimpleExpressionNode, |
6 | | -} from '@vue/compiler-dom' |
| 1 | +import { createSimpleExpression, toValidAssetId } from '@vue/compiler-dom' |
7 | 2 | import { camelize, extend, isArray } from '@vue/shared' |
8 | 3 | import { walkIdentifiers } from 'ast-kit' |
9 | 4 | import { |
@@ -48,21 +43,11 @@ export function genCreateComponent( |
48 | 43 |
|
49 | 44 | const tag = genTag() |
50 | 45 | const { root, props, slots, once } = operation |
| 46 | + const rawProps = genRawProps(props, context) |
51 | 47 | 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 | | - ) |
62 | 48 |
|
63 | 49 | return [ |
64 | 50 | NEWLINE, |
65 | | - ...inlineHandlers, |
66 | 51 | `const n${operation.id} = `, |
67 | 52 | ...genCall( |
68 | 53 | operation.dynamic && !operation.dynamic.isStatic |
@@ -100,47 +85,6 @@ export function genCreateComponent( |
100 | 85 | } |
101 | 86 | } |
102 | 87 |
|
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 | | - |
144 | 88 | export function genRawProps( |
145 | 89 | props: IRProps[], |
146 | 90 | context: CodegenContext, |
|
0 commit comments