From bd840312796174b65394c3d8d4baa0ab79daecaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Sun, 30 Jul 2023 23:11:22 +0800 Subject: [PATCH] feat(compiler-sfc): expose resolve TS type for babel plugin usage --- packages/compiler-sfc/src/index.ts | 2 ++ packages/compiler-sfc/src/script/defineEmits.ts | 2 +- packages/compiler-sfc/src/script/defineProps.ts | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/compiler-sfc/src/index.ts b/packages/compiler-sfc/src/index.ts index 76b4900d46d..7c886a280e2 100644 --- a/packages/compiler-sfc/src/index.ts +++ b/packages/compiler-sfc/src/index.ts @@ -33,6 +33,8 @@ export { // Internals for type resolution export { invalidateTypeCache, registerTS } from './script/resolveType' +export { extractRuntimeProps } from './script/defineProps' +export { extractRuntimeEmits } from './script/defineEmits' // Types export type { diff --git a/packages/compiler-sfc/src/script/defineEmits.ts b/packages/compiler-sfc/src/script/defineEmits.ts index 02014d1b276..a308093e1f9 100644 --- a/packages/compiler-sfc/src/script/defineEmits.ts +++ b/packages/compiler-sfc/src/script/defineEmits.ts @@ -57,7 +57,7 @@ export function genRuntimeEmits(ctx: ScriptCompileContext): string | undefined { return emitsDecl } -function extractRuntimeEmits(ctx: ScriptCompileContext): Set { +export function extractRuntimeEmits(ctx: ScriptCompileContext): Set { const emits = new Set() const node = ctx.emitsTypeDecl! diff --git a/packages/compiler-sfc/src/script/defineProps.ts b/packages/compiler-sfc/src/script/defineProps.ts index 5004e314da1..46f3f407c14 100644 --- a/packages/compiler-sfc/src/script/defineProps.ts +++ b/packages/compiler-sfc/src/script/defineProps.ts @@ -150,7 +150,7 @@ export function genRuntimeProps(ctx: ScriptCompileContext): string | undefined { } } } else if (ctx.propsTypeDecl) { - propsDecls = genRuntimePropsFromTypes(ctx) + propsDecls = extractRuntimeProps(ctx) } const modelsDecls = genModelProps(ctx) @@ -162,7 +162,7 @@ export function genRuntimeProps(ctx: ScriptCompileContext): string | undefined { } } -function genRuntimePropsFromTypes(ctx: ScriptCompileContext) { +export function extractRuntimeProps(ctx: ScriptCompileContext) { // this is only called if propsTypeDecl exists const props = resolveRuntimePropsFromType(ctx, ctx.propsTypeDecl!) if (!props.length) {