|
1 | 1 | import * as CompilerDOM from '@vue/compiler-dom';
|
2 | 2 | import type { Code } from '../../types';
|
3 |
| -import { collectVars, createTsAst, newLine } from '../common'; |
| 3 | +import { collectVars, createTsAst, endOfLine, newLine } from '../common'; |
4 | 4 | import type { TemplateCodegenContext } from './context';
|
5 | 5 | import type { TemplateCodegenOptions } from './index';
|
6 | 6 | import { isFragment } from './index';
|
@@ -48,12 +48,33 @@ export function* generateVFor(
|
48 | 48 | yield `{} as any`;
|
49 | 49 | }
|
50 | 50 | yield `) {${newLine}`;
|
51 |
| - if (isFragment(node)) { |
52 |
| - yield* ctx.resetDirectiveComments('end of v-for start'); |
53 |
| - } |
54 | 51 | for (const varName of forBlockVars) {
|
55 | 52 | ctx.addLocalVariable(varName);
|
56 | 53 | }
|
| 54 | + for (const argument of node.codegenNode?.children.arguments ?? []) { |
| 55 | + if ( |
| 56 | + argument.type === CompilerDOM.NodeTypes.JS_FUNCTION_EXPRESSION |
| 57 | + && argument.returns.type === CompilerDOM.NodeTypes.VNODE_CALL |
| 58 | + && argument.returns.props?.type === CompilerDOM.NodeTypes.JS_OBJECT_EXPRESSION |
| 59 | + ) { |
| 60 | + for (const prop of argument.returns.props.properties) { |
| 61 | + yield* generateInterpolation( |
| 62 | + options, |
| 63 | + ctx, |
| 64 | + prop.value.loc.source, |
| 65 | + prop.value.loc, |
| 66 | + prop.value.loc.start.offset, |
| 67 | + ctx.codeFeatures.all, |
| 68 | + '(', |
| 69 | + ')', |
| 70 | + ); |
| 71 | + yield endOfLine; |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + if (isFragment(node)) { |
| 76 | + yield* ctx.resetDirectiveComments('end of v-for start'); |
| 77 | + } |
57 | 78 | let prev: CompilerDOM.TemplateChildNode | undefined;
|
58 | 79 | for (const childNode of node.children) {
|
59 | 80 | yield* generateTemplateChild(options, ctx, childNode, currentComponent, prev, componentCtxVar);
|
|
0 commit comments