Skip to content

Commit cdf00e6

Browse files
committed
revert: #5214
1 parent 3cef963 commit cdf00e6

File tree

3 files changed

+16
-52
lines changed

3 files changed

+16
-52
lines changed

packages/language-core/lib/codegen/template/elementEvents.ts

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ export function* generateElementEvents(
2424
for (const prop of node.props) {
2525
if (
2626
prop.type === CompilerDOM.NodeTypes.DIRECTIVE
27-
&& (
28-
prop.name === 'on' && (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)
29-
|| prop.name === 'model' && (!prop.arg || prop.arg.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic)
30-
)
27+
&& prop.name === 'on'
28+
&& prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION
29+
&& prop.arg.isStatic
3130
) {
3231
ctx.currentComponent!.used = true;
3332
if (!emitVar) {
@@ -38,33 +37,21 @@ export function* generateElementEvents(
3837
yield `let ${eventsVar}!: __VLS_NormalizeEmits<typeof ${emitVar}>${endOfLine}`;
3938
yield `let ${propsVar}!: __VLS_FunctionalComponentProps<typeof ${componentFunctionalVar}, typeof ${componentVNodeVar}>${endOfLine}`;
4039
}
41-
42-
let source = prop.arg?.loc.source ?? 'model-value';
43-
let start = prop.arg?.loc.start.offset;
44-
let propPrefix = 'on-';
40+
let source = prop.arg.loc.source;
41+
let start = prop.arg.loc.start.offset;
42+
let propPrefix = 'on';
4543
let emitPrefix = '';
46-
if (prop.name === 'model') {
47-
propPrefix = 'onUpdate:';
48-
emitPrefix = 'update:';
49-
}
50-
else if (source.startsWith('vue:')) {
44+
if (source.startsWith('vue:')) {
5145
source = source.slice('vue:'.length);
52-
start = start! + 'vue:'.length;
53-
propPrefix = 'onVnode-';
46+
start = start + 'vue:'.length;
47+
propPrefix = 'onVnode';
5448
emitPrefix = 'vnode-';
5549
}
56-
57-
yield `(): __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${eventsVar}, '${camelize(propPrefix + source)}', '${emitPrefix + source}', '${camelize(emitPrefix + source)}'> => ({${newLine}`;
58-
if (prop.name === 'on') {
59-
yield* generateEventArg(ctx, source, start!, propPrefix.slice(0, -1));
60-
yield `: `;
61-
yield* generateEventExpression(options, ctx, prop);
62-
}
63-
else {
64-
yield `'${camelize(propPrefix + source)}': `;
65-
yield* generateModelEventExpression(options, ctx, prop);
66-
}
67-
yield `})${endOfLine}`;
50+
yield `const ${ctx.getInternalVariable()}: __VLS_NormalizeComponentEvent<typeof ${propsVar}, typeof ${eventsVar}, '${camelize(propPrefix + '-' + source)}', '${emitPrefix}${source}', '${camelize(emitPrefix + source)}'> = {${newLine}`;
51+
yield* generateEventArg(ctx, source, start, propPrefix);
52+
yield `: `;
53+
yield* generateEventExpression(options, ctx, prop);
54+
yield `}${endOfLine}`;
6855
}
6956
}
7057
}
@@ -172,29 +159,6 @@ export function* generateEventExpression(
172159
}
173160
}
174161

175-
export function* generateModelEventExpression(
176-
options: TemplateCodegenOptions,
177-
ctx: TemplateCodegenContext,
178-
prop: CompilerDOM.DirectiveNode
179-
): Generator<Code> {
180-
if (prop.exp?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
181-
yield `(...[$event]) => (`;
182-
yield* generateInterpolation(
183-
options,
184-
ctx,
185-
'template',
186-
ctx.codeFeatures.verification,
187-
prop.exp.content,
188-
prop.exp.loc.start.offset,
189-
prop.exp.loc
190-
);
191-
yield ` = $event)`;
192-
}
193-
else {
194-
yield `() => {}`;
195-
}
196-
}
197-
198162
export function isCompoundExpression(ts: typeof import('typescript'), ast: ts.SourceFile) {
199163
let result = true;
200164
if (ast.statements.length === 0) {

test-workspace/tsc/passedFixtures/vue3/#4646/parent.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import child from './child.vue';
55
import child2 from './child2.vue';
66
77
const msg = ref<string | null>('test');
8-
const other = ref<string | null | undefined>('test2');
8+
const other = ref<string | null>('test2');
99
</script>
1010

1111
<template>

test-workspace/tsc/passedFixtures/vue3/#4822/main.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default defineComponent({
1111
</script>
1212

1313
<script setup lang="ts">
14-
let foo!: number | undefined;
14+
let foo!: number;
1515
</script>
1616

1717
<template>

0 commit comments

Comments
 (0)