(ctx: ScriptCompileContext)
| 46 | } |
| 47 | |
| 48 | export function genRuntimeEmits(ctx: ScriptCompileContext): string | undefined { |
| 49 | let emitsDecl = '' |
| 50 | if (ctx.emitsRuntimeDecl) { |
| 51 | emitsDecl = ctx.getString(ctx.emitsRuntimeDecl).trim() |
| 52 | } else if (ctx.emitsTypeDecl) { |
| 53 | const typeDeclaredEmits = extractRuntimeEmits(ctx) |
| 54 | emitsDecl = typeDeclaredEmits.size |
| 55 | ? `[${Array.from(typeDeclaredEmits) |
| 56 | .map(k => JSON.stringify(k)) |
| 57 | .join(', ')}]` |
| 58 | : `` |
| 59 | } |
| 60 | if (ctx.hasDefineModelCall) { |
| 61 | let modelEmitsDecl = `[${Object.keys(ctx.modelDecls) |
| 62 | .map(n => JSON.stringify(`update:${n}`)) |
| 63 | .join(', ')}]` |
| 64 | emitsDecl = emitsDecl |
| 65 | ? `/*@__PURE__*/${ctx.helper( |
| 66 | 'mergeModels', |
| 67 | )}(${emitsDecl}, ${modelEmitsDecl})` |
| 68 | : modelEmitsDecl |
| 69 | } |
| 70 | return emitsDecl |
| 71 | } |
| 72 | |
| 73 | export function extractRuntimeEmits(ctx: TypeResolveContext): Set<string> { |
| 74 | const emits = new Set<string>() |
no test coverage detected