@vitarx/plugin-vite 0.0.1-alpha.0 → 0.0.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/components.d.ts +86 -0
  2. package/dist/constants/index.d.ts +58 -0
  3. package/dist/context.d.ts +118 -0
  4. package/dist/error.d.ts +117 -0
  5. package/dist/hmr-client/index.d.ts +56 -0
  6. package/dist/hmr-client/update.d.ts +7 -0
  7. package/dist/hmr-client/utils.d.ts +23 -0
  8. package/dist/index.d.ts +22 -0
  9. package/dist/passes/components/ifBlock.d.ts +12 -0
  10. package/dist/passes/components/index.d.ts +17 -0
  11. package/dist/passes/components/switch.d.ts +14 -0
  12. package/dist/passes/directives/index.d.ts +6 -0
  13. package/dist/passes/directives/processDirectives.d.ts +16 -0
  14. package/dist/passes/directives/vIf.d.ts +20 -0
  15. package/dist/passes/hmr/index.d.ts +5 -0
  16. package/dist/passes/hmr/inject.d.ts +15 -0
  17. package/dist/passes/imports/collectImports.d.ts +22 -0
  18. package/dist/passes/imports/collectRefVariables.d.ts +22 -0
  19. package/dist/passes/imports/index.d.ts +7 -0
  20. package/dist/passes/imports/injectImports.d.ts +14 -0
  21. package/dist/passes/index.d.ts +10 -0
  22. package/dist/passes/jsx/index.d.ts +7 -0
  23. package/dist/passes/jsx/processChildren.d.ts +14 -0
  24. package/dist/passes/jsx/processJSXElement.d.ts +22 -0
  25. package/dist/passes/jsx/processJSXFragment.d.ts +14 -0
  26. package/dist/passes/props/attribute.d.ts +30 -0
  27. package/dist/passes/props/index.d.ts +40 -0
  28. package/dist/passes/props/types.d.ts +42 -0
  29. package/dist/passes/props/vmodel.d.ts +27 -0
  30. package/dist/transform.d.ts +15 -0
  31. package/dist/utils/ast-builders.d.ts +75 -0
  32. package/dist/utils/ast-guards.d.ts +12 -0
  33. package/dist/utils/branch-factory.d.ts +47 -0
  34. package/dist/utils/component-collect.d.ts +17 -0
  35. package/dist/utils/generate.d.ts +5 -0
  36. package/dist/utils/index.d.ts +8 -0
  37. package/dist/utils/jsx-helpers.d.ts +67 -0
  38. package/dist/utils/pattern-helpers.d.ts +20 -0
  39. package/dist/utils/vif-helpers.d.ts +31 -0
  40. package/package.json +1 -1
@@ -0,0 +1,86 @@
1
+ import type { RenderUnit, View } from 'vitarx';
2
+ interface IfBlockProps {
3
+ /**
4
+ * 子元素列表
5
+ *
6
+ * 所有子元素必须带有 v-if / v-else-if / v-else 指令,且组合顺序必须正确!
7
+ */
8
+ children: View[];
9
+ }
10
+ interface SwitchProps {
11
+ /**
12
+ * 默认渲染内容
13
+ *
14
+ * 当所有 `Match` 都不匹配时,渲染该内容
15
+ */
16
+ fallback?: RenderUnit;
17
+ /**
18
+ * 子元素列表
19
+ *
20
+ * 必须是 `Match` 组件
21
+ */
22
+ children: View | View[];
23
+ }
24
+ interface MatchProps {
25
+ /**
26
+ * 匹配条件
27
+ */
28
+ when: unknown;
29
+ /**
30
+ * 匹配成功时渲染的内容
31
+ */
32
+ children: RenderUnit;
33
+ }
34
+ declare global {
35
+ /**
36
+ * IfBlock - 编译宏组件,无需import导入
37
+ *
38
+ * IfBlock 组件不具有运行时效果,它只是为了兼容tsx类型校验,
39
+ * 例如 `<Comp><h1 v-if={cond} /><h2 v-else /><Comp>`,Comp组件的children要求传入单个元素时tsx类型会误报,使用 `IfBlock` 包裹则可以使 v-if 组合链通过 children 类型校验
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * import { View } from 'vitarx';
44
+ * function TestComp(props:{children:View}) {
45
+ * return <div>{props.children}</div>
46
+ * }
47
+ * function App() {
48
+ * return (
49
+ * <TestComp>
50
+ * <IfBlock>
51
+ * <h1 v-if={cond}/>
52
+ * <h2 v-else/>
53
+ * </IfBlock>
54
+ * </TestComp>
55
+ * )
56
+ * }
57
+ * ```
58
+ */
59
+ const IfBlock: (props: IfBlockProps) => View;
60
+ /**
61
+ * Switch - 编译宏组件,无需import导入
62
+ *
63
+ * Switch 组件用于条件渲染,`Match` 是其唯一合法子元素,
64
+ * 通过 `when` 属性判断是否匹配,匹配则渲染 `Match` 子元素,否则渲染 `fallback`
65
+ *
66
+ * @example
67
+ * ```tsx
68
+ * function App() {
69
+ * return (
70
+ * <Switch fallback="Default">
71
+ * <Match when={a}>A</Match>
72
+ * <Match when={b}>B</Match>
73
+ * </Switch>
74
+ * )
75
+ * }
76
+ * ```
77
+ */
78
+ const Switch: (props: SwitchProps) => View;
79
+ /**
80
+ * Match - 编译宏组件,无需import导入
81
+ *
82
+ * 需 `Switch` 组件搭配使用,不允许单独使用。
83
+ */
84
+ const Match: (props: MatchProps) => View;
85
+ }
86
+ export {};
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Vitarx 运行时 API 名称
3
+ * 这些 API 需要从 vitarx 包导入
4
+ */
5
+ export declare const VITARX_APIS: {
6
+ readonly CREATE_VIEW: "createView";
7
+ readonly FRAGMENT: "Fragment";
8
+ readonly BRANCH: "branch";
9
+ readonly DYNAMIC: "dynamic";
10
+ readonly ACCESS: "access";
11
+ readonly WITH_DIRECTIVES: "withDirectives";
12
+ readonly UNREF: "unref";
13
+ readonly IS_REF: "isRef";
14
+ };
15
+ /**
16
+ * Ref 相关 API 名称
17
+ * 用于识别 ref 变量
18
+ */
19
+ export declare const REF_APIS: {
20
+ readonly REF: "ref";
21
+ readonly TO_REF: "toRef";
22
+ readonly TO_REFS: "toRefs";
23
+ readonly SHALLOW_REF: "shallowRef";
24
+ readonly COMPUTED: "computed";
25
+ };
26
+ /**
27
+ * 支持的响应式模块
28
+ * 从这些模块导入的 ref API 会被识别
29
+ */
30
+ export declare const RESPONSIVE_MODULES: readonly ["vitarx", "@vitarx/responsive"];
31
+ /**
32
+ * 纯编译组件名称
33
+ * 这些组件在编译时会被完全转换
34
+ */
35
+ export declare const PURE_COMPILE_COMPONENTS: readonly ["Switch", "Match", "IfBlock"];
36
+ /**
37
+ * 指令前缀
38
+ */
39
+ export declare const DIRECTIVE_PREFIX = "v-";
40
+ /**
41
+ * 纯函数注释
42
+ */
43
+ export declare const PURE_COMMENT = "@__PURE__";
44
+ /**
45
+ * vitarx 模块名称
46
+ */
47
+ export declare const VITARX_MODULE = "vitarx";
48
+ /**
49
+ * 标识符
50
+ */
51
+ export declare enum HMR {
52
+ manager = "__$VITARX_HMR$__",
53
+ id = "__$VITARX_HMR_COMPONENT_ID$__",
54
+ view = "__$VITARX_HMR_VIEW_NODE$__",
55
+ state = "__$VITARX_HMR_VIEW_STATE$__"
56
+ }
57
+ /** 默认导出组件基础名称 */
58
+ export declare const DEFAULT_EXPORT_BASE_NAME = "_defaultExport";
@@ -0,0 +1,118 @@
1
+ /**
2
+ * 转换上下文模块
3
+ * 定义编译转换过程中的上下文数据结构
4
+ * @module context
5
+ */
6
+ import type { File } from '@babel/types';
7
+ import type { CompileOptions } from './transform.js';
8
+ import type { CompilerWarning } from './error.js';
9
+ /**
10
+ * UI 相关的 API 名称列表
11
+ * 这些 API 用于创建视图,在 HMR 时需要识别
12
+ */
13
+ export declare const UI_API_NAMES: readonly ["createView", "branch", "dynamic", "access", "withDirectives"];
14
+ export type UIApiName = (typeof UI_API_NAMES)[number];
15
+ /**
16
+ * 导入信息
17
+ * 追踪需要注入的运行时 API
18
+ */
19
+ export interface ImportInfo {
20
+ /** createView - 视图创建函数 */
21
+ createView: boolean;
22
+ /** Fragment - 片段组件 */
23
+ Fragment: boolean;
24
+ /** branch - 条件分支函数 */
25
+ branch: boolean;
26
+ /** dynamic - 动态值包装函数 */
27
+ dynamic: boolean;
28
+ /** access - 属性访问函数 */
29
+ access: boolean;
30
+ /** withDirectives - 指令包装函数 */
31
+ withDirectives: boolean;
32
+ /** unref - ref 解包函数 */
33
+ unref: boolean;
34
+ /** isRef - ref 类型检查函数 */
35
+ isRef: boolean;
36
+ }
37
+ /**
38
+ * Vitarx 导入别名映射
39
+ * 记录运行时 API 的本地别名
40
+ */
41
+ export interface VitarxImportAliases {
42
+ createView: string | null;
43
+ Fragment: string | null;
44
+ branch: string | null;
45
+ dynamic: string | null;
46
+ access: string | null;
47
+ withDirectives: string | null;
48
+ unref: string | null;
49
+ isRef: string | null;
50
+ }
51
+ /**
52
+ * Ref API 别名映射
53
+ * 记录响应式 API 的本地别名
54
+ */
55
+ export interface RefApiAliases {
56
+ ref: string | null;
57
+ toRef: string | null;
58
+ toRefs: string | null;
59
+ shallowRef: string | null;
60
+ computed: string | null;
61
+ }
62
+ /**
63
+ * 转换上下文
64
+ * 包含编译过程中需要的所有状态信息
65
+ */
66
+ export interface TransformContext {
67
+ /** 原始源代码 */
68
+ code: string;
69
+ /** 文件标识符(可能包含查询参数) */
70
+ id: string;
71
+ /** 文件名(不含查询参数) */
72
+ filename: string;
73
+ /** 编译选项 */
74
+ options: CompileOptions;
75
+ /** 解析后的 AST */
76
+ ast: File;
77
+ /** 需要注入的导入信息 */
78
+ imports: ImportInfo;
79
+ /** 已存在的导入名称集合 */
80
+ existingImports: Set<string>;
81
+ /** Vitarx API 别名映射 */
82
+ vitarxAliases: VitarxImportAliases;
83
+ /** Ref API 别名映射 */
84
+ refApiAliases: RefApiAliases;
85
+ /** ref 变量名集合 */
86
+ refVariables: Set<string>;
87
+ /** UI API 别名集合(用于 HMR 代码分离识别) */
88
+ uiApiAliases: Set<string>;
89
+ /** 编译警告列表 */
90
+ warnings: CompilerWarning[];
91
+ }
92
+ /**
93
+ * 创建转换上下文
94
+ * @param code - 源代码
95
+ * @param id - 文件标识符
96
+ * @param options - 编译选项
97
+ * @param ast - AST 节点
98
+ * @returns 转换上下文对象
99
+ */
100
+ export declare function createContext(code: string, id: string, options: CompileOptions, ast: File): TransformContext;
101
+ /**
102
+ * 标记需要注入的导入
103
+ * @param ctx - 转换上下文
104
+ * @param name - 导入名称
105
+ */
106
+ export declare function markImport(ctx: TransformContext, name: keyof ImportInfo): void;
107
+ /**
108
+ * 记录 UI API 别名
109
+ * @param ctx - 转换上下文
110
+ * @param alias - API 别名
111
+ */
112
+ export declare function markUiApiAlias(ctx: TransformContext, alias: string): void;
113
+ /**
114
+ * 添加编译警告
115
+ * @param ctx - 转换上下文
116
+ * @param warning - 编译警告
117
+ */
118
+ export declare function addWarning(ctx: TransformContext, warning: CompilerWarning): void;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * 编译错误处理模块
3
+ * 定义编译器错误类型和错误消息
4
+ * @module error
5
+ */
6
+ import type { Node } from '@babel/types';
7
+ /**
8
+ * 错误位置信息
9
+ */
10
+ export interface ErrorLocation {
11
+ /** 行号 */
12
+ line: number;
13
+ /** 列号 */
14
+ column: number;
15
+ }
16
+ /**
17
+ * 编译错误选项
18
+ */
19
+ export interface CompilerErrorOptions {
20
+ /** 错误代码 */
21
+ code: string;
22
+ /** 错误消息 */
23
+ message: string;
24
+ /** 错误位置 */
25
+ loc?: ErrorLocation;
26
+ /** 相关 AST 节点 */
27
+ node?: Node;
28
+ }
29
+ /**
30
+ * 编译器错误类
31
+ * 包含错误代码和位置信息
32
+ */
33
+ export declare class CompilerError extends Error {
34
+ /** 错误代码 */
35
+ code: string;
36
+ /** 错误位置 */
37
+ loc?: ErrorLocation;
38
+ constructor(options: CompilerErrorOptions);
39
+ }
40
+ /**
41
+ * 错误代码枚举
42
+ */
43
+ export declare const ErrorCodes: {
44
+ /** 不能同时使用展开属性和 v-bind */
45
+ readonly E001: "E001";
46
+ /** 重复的展开属性或属性键 */
47
+ readonly E002: "E002";
48
+ /** v-else 没有前置的 v-if */
49
+ readonly E003: "E003";
50
+ /** v-else-if 没有前置的 v-if */
51
+ readonly E004: "E004";
52
+ /** v-if 链不连续 */
53
+ readonly E005: "E005";
54
+ /** Switch 组件有无效子节点 */
55
+ readonly E006: "E006";
56
+ /** Match 组件缺少 when 属性 */
57
+ readonly E007: "E007";
58
+ /** IfBlock 有无效子元素 */
59
+ readonly E008: "E008";
60
+ /** v-model 与 modelValue 或 onUpdate:modelValue 冲突 */
61
+ readonly E009: "E009";
62
+ /** v-model 值必须是 Identifier 或 MemberExpression */
63
+ readonly E010: "E010";
64
+ /** v-model Identifier 必须是 ref */
65
+ readonly E011: "E011";
66
+ /** Match 组件必须在 Switch 内使用 */
67
+ readonly E012: "E012";
68
+ /** Match 组件必须有子元素 */
69
+ readonly E013: "E013";
70
+ /** IfBlock 组件必须有子元素 */
71
+ readonly E014: "E014";
72
+ /** Switch 组件必须有 Match 子元素 */
73
+ readonly E015: "E015";
74
+ };
75
+ /**
76
+ * 警告代码枚举
77
+ */
78
+ export declare const WarningCodes: {
79
+ /** children 属性和子元素同时存在 */
80
+ readonly W001: "W001";
81
+ };
82
+ /**
83
+ * 错误消息映射
84
+ */
85
+ export declare const ErrorMessages: Record<string, string>;
86
+ /**
87
+ * 警告消息映射
88
+ */
89
+ export declare const WarningMessages: Record<string, string>;
90
+ /**
91
+ * 创建编译错误
92
+ * @param code - 错误代码
93
+ * @param node - 相关 AST 节点
94
+ * @param additionalMessage - 附加消息
95
+ * @returns 编译错误实例
96
+ */
97
+ export declare function createError(code: keyof typeof ErrorCodes, node?: Node, additionalMessage?: string): CompilerError;
98
+ /**
99
+ * 编译警告类
100
+ */
101
+ export declare class CompilerWarning {
102
+ /** 警告代码 */
103
+ code: string;
104
+ /** 警告消息 */
105
+ message: string;
106
+ /** 警告位置 */
107
+ loc?: ErrorLocation;
108
+ constructor(code: string, message: string, loc?: ErrorLocation);
109
+ toString(): string;
110
+ }
111
+ /**
112
+ * 创建编译警告
113
+ * @param code - 警告代码
114
+ * @param node - 相关 AST 节点
115
+ * @returns 编译警告实例
116
+ */
117
+ export declare function createWarning(code: keyof typeof WarningCodes, node?: Node): CompilerWarning;
@@ -0,0 +1,56 @@
1
+ import { Component, ComponentView } from 'vitarx';
2
+ import type { ModuleNamespace } from 'vite/types/hot.js';
3
+ import { HMR } from '../constants/index.js';
4
+ declare global {
5
+ interface Window {
6
+ [HMR.manager]: HMRManager;
7
+ }
8
+ }
9
+ declare module 'vitarx' {
10
+ interface ComponentView {
11
+ [HMR.state]?: Record<string, any>;
12
+ }
13
+ }
14
+ export default class HMRManager {
15
+ #private;
16
+ /**
17
+ * 获取单实例
18
+ */
19
+ static get instance(): HMRManager;
20
+ /**
21
+ * 给组件绑定唯一id
22
+ *
23
+ * @param component
24
+ * @param id
25
+ */
26
+ bindId(component: Function, id: string): void;
27
+ /**
28
+ * 置换新模块
29
+ *
30
+ * 此方法提供给`jsxDev`函数调用,保持每次创建组件实例都是最新的模块!
31
+ * @param component
32
+ */
33
+ resolveComponent(component: Component): Component;
34
+ /**
35
+ * 恢复状态
36
+ *
37
+ * @param {ComponentView} view - 组件视图
38
+ * @param {string} name - 变量名称
39
+ * @example
40
+ * const state = __$VITARX_HMR$__.instance.memo(__$VITARX_HMR_VIEW_NODE$__, 'state') ?? ref(0)
41
+ */
42
+ memo(view: ComponentView, name: string): any;
43
+ /**
44
+ * 注册节点
45
+ *
46
+ * @param view - 组件视图节点
47
+ */
48
+ register(view: ComponentView): void;
49
+ /**
50
+ * 获取模块id
51
+ *
52
+ * @param component
53
+ */
54
+ getId(component: Component): string;
55
+ update(mod: ModuleNamespace): void;
56
+ }
@@ -0,0 +1,7 @@
1
+ import { Component, ComponentView } from 'vitarx';
2
+ /**
3
+ * 处理组件更新函数
4
+ * @param view - 组件视图对象,包含当前组件的实例和节点信息
5
+ * @param newComponent - 新的组件定义,用于替换现有组件
6
+ */
7
+ export declare function processUpdate(view: ComponentView, newComponent: Component): void;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 代码变更类型
3
+ */
4
+ export interface ChangeCode {
5
+ /** UI 描述代码是否变化(需要重新构建视图) */
6
+ build: boolean;
7
+ /** 非 UI 代码是否变化(需要完全重新挂载) */
8
+ logic: boolean;
9
+ }
10
+ /**
11
+ * 判断两个函数组件的代码差异
12
+ *
13
+ * 分析策略:
14
+ * 1. 解析函数代码,提取所有 createView/branch/dynamic 等 UI API 调用
15
+ * 2. 将这些调用识别为 UI 描述代码
16
+ * 3. 其余代码识别为非 UI 代码(逻辑代码)
17
+ * 4. 分别比较 UI 代码和非 UI 代码是否变化
18
+ *
19
+ * @param newCode 新函数代码
20
+ * @param oldCode 旧函数代码
21
+ * @returns {ChangeCode} 变更检测结果
22
+ */
23
+ export declare function diffComponentChange(newCode: string, oldCode: string): ChangeCode;
@@ -0,0 +1,22 @@
1
+ import { type Plugin } from 'vite';
2
+ export type * from './components.js';
3
+ /**
4
+ * vite-plugin-vitarx 配置选项
5
+ *
6
+ * 暂无配置选项
7
+ */
8
+ export interface VitePluginVitarxOptions {
9
+ }
10
+ /**
11
+ * vite-plugin-vitarx
12
+ *
13
+ * 功能:
14
+ * - jsx -> createView 编译转换
15
+ * - 支持 v-if、v-else-if、v-else 、v-model 等编译宏指令
16
+ * - 支持 Switch , IfBlock 等编译宏组件
17
+ * - 开发时 HMR 热更新相关代码注入与功能支持
18
+ *
19
+ * @param _options - 暂无可选配置。
20
+ * @returns - vite插件对象。
21
+ */
22
+ export default function vitarx(_options?: VitePluginVitarxOptions): Plugin;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * IfBlock 组件处理器
3
+ * 将 <IfBlock><div v-if>...</div><div v-else>...</div></IfBlock> 编译为 branch 调用
4
+ * @module passes/components/ifBlock
5
+ */
6
+ import type { NodePath } from '@babel/traverse';
7
+ import * as t from '@babel/types';
8
+ import { TransformContext } from '../../context.js';
9
+ /**
10
+ * 处理 IfBlock 组件
11
+ */
12
+ export declare function processIfBlock(path: NodePath<t.JSXElement>, ctx: TransformContext): void;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * 编译宏组件处理模块
3
+ * 包含 Switch、IfBlock 等纯编译组件的转换
4
+ * @module passes/components
5
+ */
6
+ import type { NodePath } from '@babel/traverse';
7
+ import * as t from '@babel/types';
8
+ import { TransformContext } from '../../context.js';
9
+ /**
10
+ * 处理纯编译组件
11
+ * 根据组件名称分发到对应的处理器
12
+ * @param path - JSX 元素路径
13
+ * @param ctx - 转换上下文
14
+ */
15
+ export declare function processPureCompileComponent(path: NodePath<t.JSXElement>, ctx: TransformContext): void;
16
+ export { processSwitch } from './switch.js';
17
+ export { processIfBlock } from './ifBlock.js';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Switch 组件处理器
3
+ * 将 <Switch><Match when={cond}>...</Match></Switch> 编译为 branch 调用
4
+ * @module passes/components/switch
5
+ */
6
+ import type { NodePath } from '@babel/traverse';
7
+ import * as t from '@babel/types';
8
+ import { TransformContext } from '../../context.js';
9
+ /**
10
+ * 处理 Switch 组件
11
+ * @param path - JSX 元素路径
12
+ * @param ctx - 转换上下文
13
+ */
14
+ export declare function processSwitch(path: NodePath<t.JSXElement>, ctx: TransformContext): void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 指令处理模块
3
+ * @module passes/directives
4
+ */
5
+ export { processVIfChain } from './vIf.js';
6
+ export { processDirectives } from './processDirectives.js';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 指令处理模块
3
+ * 处理 v-show 等指令
4
+ * @module passes/directives/processDirectives
5
+ */
6
+ import * as t from '@babel/types';
7
+ import { TransformContext } from '../../context.js';
8
+ /**
9
+ * 处理指令
10
+ * 将指令转换为 withDirectives 调用
11
+ * @param viewCall - 视图调用表达式
12
+ * @param directives - 指令映射
13
+ * @param ctx - 转换上下文
14
+ * @returns 处理后的调用表达式
15
+ */
16
+ export declare function processDirectives(viewCall: t.CallExpression, directives: Map<string, t.Expression>, ctx: TransformContext): t.CallExpression;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * v-if 链处理器
3
+ * 处理 Fragment 中的 v-if/v-else-if/v-else 链
4
+ * @module passes/directives/vIf
5
+ */
6
+ import type { NodePath } from '@babel/traverse';
7
+ import * as t from '@babel/types';
8
+ import { TransformContext } from '../../context.js';
9
+ /**
10
+ * JSX 元素转换函数类型
11
+ */
12
+ type TransformJSXElementFn = (node: t.JSXElement, ctx: TransformContext, handleVIf: boolean) => t.Expression | null;
13
+ /**
14
+ * 处理 Fragment 中的 v-if 链
15
+ * @param path - JSX Fragment 路径
16
+ * @param ctx - 转换上下文
17
+ * @param transformJSXElement - JSX 元素转换函数
18
+ */
19
+ export declare function processVIfChain(path: NodePath<t.JSXFragment>, ctx: TransformContext, transformJSXElement: TransformJSXElementFn): void;
20
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * HMR 注入模块入口
3
+ * @module passes/hmr
4
+ */
5
+ export { injectHMRSupport } from './inject.js';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * HMR 代码注入模块
3
+ * 在 HMR 模式下为组件函数注入热更新支持代码
4
+ * @module passes/hmr
5
+ */
6
+ import * as t from '@babel/types';
7
+ import { type ComponentInfo } from '../../utils/index.js';
8
+ /**
9
+ * 注入 HMR 支持
10
+ * 主入口函数,为所有组件注入完整的 HMR 支持
11
+ * @param program - AST Program 节点
12
+ * @param components - 组件信息列表
13
+ * @param filename - 文件名
14
+ */
15
+ export declare function injectHMRSupport(program: t.Program, components: ComponentInfo[], filename: string): void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 导入收集模块
3
+ * 负责收集现有导入信息和本地变量绑定
4
+ * @module passes/imports/collectImports
5
+ */
6
+ import * as t from '@babel/types';
7
+ /**
8
+ * 收集现有导入信息
9
+ * @param program - AST Program 节点
10
+ * @returns 本地变量名集合和 vitarx 导入映射
11
+ */
12
+ export declare function collectExistingImports(program: t.Program): {
13
+ localNames: Set<string>;
14
+ vitarxImports: Map<string, string>;
15
+ };
16
+ /**
17
+ * 收集本地变量绑定
18
+ * 包括导入绑定、变量声明、函数声明、类声明
19
+ * @param program - AST Program 节点
20
+ * @returns 本地变量名集合
21
+ */
22
+ export declare function collectLocalBindings(program: t.Program): Set<string>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Ref 变量收集模块
3
+ * 负责识别 ref API 别名和收集 ref 变量
4
+ * @module passes/imports/collectRefVariables
5
+ */
6
+ import * as t from '@babel/types';
7
+ import type { RefApiAliases } from '../../context.js';
8
+ /**
9
+ * 收集 ref API 的别名
10
+ * 识别从 vitarx 或 @vitarx/responsive 导入的 ref/toRef/toRefs/shallowRef/computed
11
+ * @param program - AST Program 节点
12
+ * @returns ref API 别名映射
13
+ */
14
+ export declare function collectRefApiAliases(program: t.Program): RefApiAliases;
15
+ /**
16
+ * 收集通过 ref API 定义的变量
17
+ * 包括直接赋值和 toRefs 解构
18
+ * @param program - AST Program 节点
19
+ * @param refApiAliases - ref API 别名映射
20
+ * @returns ref 变量名集合
21
+ */
22
+ export declare function collectRefVariables(program: t.Program, refApiAliases: RefApiAliases): Set<string>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 导入处理模块
3
+ * @module passes/imports
4
+ */
5
+ export { collectExistingImports, collectLocalBindings } from './collectImports.js';
6
+ export { collectRefApiAliases, collectRefVariables } from './collectRefVariables.js';
7
+ export { injectImports } from './injectImports.js';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 导入注入模块
3
+ * 负责动态注入 vitarx 导入语句
4
+ * @module passes/imports/injectImports
5
+ */
6
+ import * as t from '@babel/types';
7
+ import type { TransformContext } from '../../context.js';
8
+ /**
9
+ * 注入 vitarx 导入
10
+ * 根据已使用的 API 动态生成导入语句
11
+ * @param program - AST Program 节点
12
+ * @param ctx - 转换上下文
13
+ */
14
+ export declare function injectImports(program: t.Program, ctx: TransformContext): void;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 编译转换处理模块
3
+ * @module passes
4
+ */
5
+ export { collectExistingImports, collectLocalBindings, collectRefApiAliases, collectRefVariables, injectImports } from './imports/index.js';
6
+ export { processPureCompileComponent, processSwitch, processIfBlock } from './components/index.js';
7
+ export { processVIfChain, processDirectives } from './directives/index.js';
8
+ export { processChildren, processJSXElement, transformJSXElement, processJSXFragment } from './jsx/index.js';
9
+ export { processProps, type PropsResult } from './props/index.js';
10
+ export { injectHMRSupport } from './hmr/index.js';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * JSX 处理模块
3
+ * @module passes/jsx
4
+ */
5
+ export { processChildren } from './processChildren.js';
6
+ export { processJSXElement, transformJSXElement } from './processJSXElement.js';
7
+ export { processJSXFragment } from './processJSXFragment.js';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 子元素处理模块
3
+ * 处理 JSX 元素的子节点
4
+ * @module passes/jsx/processChildren
5
+ */
6
+ import * as t from '@babel/types';
7
+ import { TransformContext } from '../../context.js';
8
+ /**
9
+ * 处理子节点数组
10
+ * @param children - 子节点数组
11
+ * @param ctx - 转换上下文
12
+ * @returns 处理后的表达式数组
13
+ */
14
+ export declare function processChildren(children: t.Node[], ctx: TransformContext): t.Expression[];
@@ -0,0 +1,22 @@
1
+ /**
2
+ * JSX 元素处理模块
3
+ * 将 JSX 元素转换为 createView 调用
4
+ * @module passes/jsx/processJSXElement
5
+ */
6
+ import type { NodePath } from '@babel/traverse';
7
+ import * as t from '@babel/types';
8
+ import { TransformContext } from '../../context.js';
9
+ /**
10
+ * 处理 JSX 元素
11
+ * @param path - JSX 元素路径
12
+ * @param ctx - 转换上下文
13
+ */
14
+ export declare function processJSXElement(path: NodePath<t.JSXElement>, ctx: TransformContext): void;
15
+ /**
16
+ * 转换 JSX 元素为表达式
17
+ * @param node - JSX 元素节点
18
+ * @param ctx - 转换上下文
19
+ * @param handleVIf - 是否处理 v-if 指令
20
+ * @returns 转换后的表达式
21
+ */
22
+ export declare function transformJSXElement(node: t.JSXElement, ctx: TransformContext, handleVIf?: boolean): t.Expression | null;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * JSX Fragment 处理模块
3
+ * 将 JSX Fragment 转换为 createView(Fragment, ...) 调用
4
+ * @module passes/jsx/processJSXFragment
5
+ */
6
+ import type { NodePath } from '@babel/traverse';
7
+ import * as t from '@babel/types';
8
+ import { TransformContext } from '../../context.js';
9
+ /**
10
+ * 处理 JSX Fragment
11
+ * @param path - JSX Fragment 路径
12
+ * @param ctx - 转换上下文
13
+ */
14
+ export declare function processJSXFragment(path: NodePath<t.JSXFragment>, ctx: TransformContext): void;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * 属性处理模块
3
+ * 负责处理 JSX 元素的各类属性,包括普通属性、展开属性、命名空间属性等
4
+ * @module passes/props/attribute
5
+ */
6
+ import * as t from '@babel/types';
7
+ import { TransformContext } from '../../context.js';
8
+ import type { AttributeResult } from './types.js';
9
+ /**
10
+ * 处理展开属性 {...props}
11
+ * 将展开属性转换为 v-bind 特殊属性格式
12
+ * @param attr - JSX 展开属性节点
13
+ * @param hasVBind - 是否已存在 v-bind
14
+ * @param node - JSX 元素节点(用于错误定位)
15
+ * @returns 转换后的属性对象,或 null(如果已存在 v-bind)
16
+ * @throws {Error} E001 - 当已存在 v-bind 时抛出
17
+ */
18
+ export declare function processSpreadAttribute(attr: t.JSXSpreadAttribute, hasVBind: boolean, node: t.JSXElement): {
19
+ property: t.ObjectProperty;
20
+ hasVBind: boolean;
21
+ } | null;
22
+ /**
23
+ * 处理单个 JSX 属性
24
+ * 根据属性名类型分发到不同的处理逻辑
25
+ * @param attr - JSX 属性节点
26
+ * @param existingPropNames - 已存在的属性名集合
27
+ * @param ctx - 转换上下文
28
+ * @returns 属性处理结果
29
+ */
30
+ export declare function processAttribute(attr: t.JSXAttribute, existingPropNames: Set<string>, ctx: TransformContext): AttributeResult;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Props 处理模块入口
3
+ * 负责处理 JSX 元素的属性,包括 v-model 特殊指令
4
+ * @module passes/props
5
+ */
6
+ import * as t from '@babel/types';
7
+ import { TransformContext } from '../../context.js';
8
+ import type { PropsResult } from './types.js';
9
+ export type { PropsResult, VModelState, AttributeResult } from './types.js';
10
+ /**
11
+ * 处理 JSX 元素的属性
12
+ * 将 JSX 属性转换为运行时 props 对象,并提取指令
13
+ *
14
+ * 处理流程:
15
+ * 1. 遍历所有属性,分类处理
16
+ * 2. 展开属性转换为 v-bind 格式
17
+ * 3. 普通属性转换为对象属性或 getter
18
+ * 4. 指令属性提取到 directives Map
19
+ * 5. v-model 特殊处理,生成 modelValue 和 onUpdate:modelValue
20
+ *
21
+ * @param node - JSX 元素节点
22
+ * @param ctx - 转换上下文
23
+ * @param hasChildren - 是否有子元素(有子元素时跳过 children 属性)
24
+ * @returns 处理结果,包含 props 对象、指令映射和 v-bind 标记
25
+ *
26
+ * @example
27
+ * ```tsx
28
+ * // 输入
29
+ * <Input v-model={value} placeholder="text" disabled />
30
+ *
31
+ * // 输出 props
32
+ * {
33
+ * modelValue: get() { return value.value },
34
+ * 'onUpdate:modelValue': v => value.value = v,
35
+ * placeholder: "text",
36
+ * disabled: true
37
+ * }
38
+ * ```
39
+ */
40
+ export declare function processProps(node: t.JSXElement, ctx: TransformContext, hasChildren?: boolean): PropsResult;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Props 处理模块 - 类型定义
3
+ * @module passes/props/types
4
+ */
5
+ import * as t from '@babel/types';
6
+ /**
7
+ * Props 处理结果
8
+ */
9
+ export interface PropsResult {
10
+ /** 处理后的 props 对象表达式,无属性时为 null */
11
+ props: t.ObjectExpression | null;
12
+ /** 指令映射表,key 为指令名,value 为指令值表达式 */
13
+ directives: Map<string, t.Expression>;
14
+ /** 是否包含 v-bind 展开属性 */
15
+ hasVBind: boolean;
16
+ }
17
+ /**
18
+ * v-model 指令状态
19
+ */
20
+ export interface VModelState {
21
+ /** 是否存在 v-model 指令 */
22
+ hasVModel: boolean;
23
+ /** v-model 绑定的值表达式 */
24
+ value: t.Expression | null;
25
+ /** v-model 属性节点,用于错误定位 */
26
+ node: t.JSXAttribute | null;
27
+ }
28
+ /**
29
+ * 属性处理结果联合类型
30
+ * - directive: 指令类型属性
31
+ * - property: 普通属性
32
+ */
33
+ export type AttributeResult = {
34
+ type: 'directive';
35
+ name: string;
36
+ value: t.Expression;
37
+ isVBind: boolean;
38
+ isVModel: boolean;
39
+ } | {
40
+ type: 'property';
41
+ property: t.ObjectProperty | t.ObjectMethod;
42
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * v-model 指令处理模块
3
+ * 负责处理 JSX 元素的 v-model 双向绑定指令
4
+ * @module passes/props/vmodel
5
+ */
6
+ import * as t from '@babel/types';
7
+ import { TransformContext } from '../../context.js';
8
+ import type { VModelState } from './types.js';
9
+ /**
10
+ * 从属性列表中提取 v-model 状态
11
+ * @param attributes - JSX 元素属性列表
12
+ * @returns v-model 状态对象
13
+ */
14
+ export declare function extractVModelState(attributes: (t.JSXAttribute | t.JSXSpreadAttribute)[]): VModelState;
15
+ /**
16
+ * 创建 v-model 相关的 props
17
+ * 生成 modelValue getter 和 onUpdate:modelValue 回调
18
+ * @param value - v-model 绑定的值表达式
19
+ * @param attrNode - v-model 属性节点(用于错误定位)
20
+ * @param existingPropNames - 已存在的属性名集合(用于冲突检测)
21
+ * @param node - JSX 元素节点
22
+ * @param ctx - 转换上下文
23
+ * @returns 包含 modelValue 和 onUpdate:modelValue 的属性数组
24
+ * @throws {Error} E009 - 当 modelValue 或 onUpdate:modelValue 已存在时
25
+ * @throws {Error} E010 - 当 v-model 绑定值不是 Identifier 或 MemberExpression 时
26
+ */
27
+ export declare function createVModelProps(value: t.Expression, attrNode: t.JSXAttribute | null, existingPropNames: Set<string>, node: t.JSXElement, ctx: TransformContext): (t.ObjectMethod | t.ObjectProperty)[];
@@ -0,0 +1,15 @@
1
+ export interface TransformResult {
2
+ code: string;
3
+ map: any;
4
+ }
5
+ export interface CompileOptions {
6
+ hmr: boolean;
7
+ dev: boolean;
8
+ ssr: boolean;
9
+ runtimeModule: string;
10
+ sourceMap: boolean | 'inline' | 'both';
11
+ }
12
+ /**
13
+ * 转换 JSX/TSX 代码
14
+ */
15
+ export declare function transform(code: string, id: string, options: CompileOptions): Promise<TransformResult | null>;
@@ -0,0 +1,75 @@
1
+ import { type ArrowFunctionExpression, type CallExpression, type Expression, type ObjectExpression, type SourceLocation } from '@babel/types';
2
+ import type { VitarxImportAliases } from '../context.js';
3
+ /**
4
+ * 创建 unref 调用
5
+ * @param argument - 参数表达式
6
+ * @param alias - unref 别名
7
+ * @returns CallExpression
8
+ */
9
+ export declare function createUnrefCall(argument: Expression, alias?: string): CallExpression;
10
+ /**
11
+ * 创建 access 调用
12
+ * @param object - 对象表达式
13
+ * @param key - 键表达式
14
+ * @param alias - access 别名
15
+ * @returns CallExpression
16
+ */
17
+ export declare function createAccessCall(object: Expression, key: Expression, alias?: string): CallExpression;
18
+ /**
19
+ * 创建 dynamic 调用
20
+ * @param argument - 参数表达式
21
+ * @param alias - dynamic 别名
22
+ * @returns CallExpression
23
+ */
24
+ export declare function createDynamicCall(argument: Expression, alias?: string): CallExpression;
25
+ /**
26
+ * 创建 branch 调用
27
+ * @param condition - 条件函数
28
+ * @param branches - 分支函数数组
29
+ * @param alias - branch 别名
30
+ * @returns CallExpression
31
+ */
32
+ export declare function createBranchCall(condition: ArrowFunctionExpression, branches: ArrowFunctionExpression[], alias?: string): CallExpression;
33
+ /**
34
+ * 创建 createView 调用
35
+ * @param type - 元素类型
36
+ * @param props - props 对象
37
+ * @param locInfo - 位置信息对象
38
+ * @param alias - createView 别名
39
+ * @returns CallExpression
40
+ */
41
+ export declare function createCreateViewCall(type: Expression, props: ObjectExpression | null, locInfo?: ObjectExpression | null, alias?: string): CallExpression;
42
+ /**
43
+ * 创建 withDirectives 调用
44
+ * @param view - 视图节点
45
+ * @param directives - 指令数组,每项为 [指令名, 指令值]
46
+ * @param alias - withDirectives 别名
47
+ * @returns CallExpression
48
+ */
49
+ export declare function createWithDirectivesCall(view: Expression, directives: Array<[string, Expression]>, alias?: string): CallExpression;
50
+ /**
51
+ * 创建箭头函数
52
+ * @param body - 函数体表达式
53
+ * @returns ArrowFunctionExpression
54
+ */
55
+ export declare function createArrowFunction(body: Expression): ArrowFunctionExpression;
56
+ /**
57
+ * 创建位置信息对象
58
+ * @param filename - 文件名
59
+ * @param loc - 源码位置
60
+ * @returns ObjectExpression
61
+ */
62
+ export declare function createLocationObject(filename: string, loc: SourceLocation): ObjectExpression;
63
+ /**
64
+ * 为调用表达式添加 @__PURE__ 注释
65
+ * @param node - 调用表达式节点
66
+ * @returns 添加注释后的节点
67
+ */
68
+ export declare function addPureComment<T extends CallExpression>(node: T): T;
69
+ /**
70
+ * 获取 API 别名
71
+ * @param aliases - 别名映射
72
+ * @param name - API 名称
73
+ * @returns 别名或原名
74
+ */
75
+ export declare function getAlias(aliases: VitarxImportAliases, name: keyof VitarxImportAliases): string;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * AST 类型守卫函数
3
+ * 用于判断节点类型
4
+ * @module utils/ast-guards
5
+ */
6
+ import { type Node } from '@babel/types';
7
+ /**
8
+ * 判断 JSXText 是否为纯空白文本
9
+ * @param node - AST 节点
10
+ * @returns 是否为纯空白文本
11
+ */
12
+ export declare function isWhitespaceJSXText(node: Node): boolean;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Branch 调用工厂模块
3
+ * 统一处理条件分支的生成
4
+ * @module utils/branch-factory
5
+ */
6
+ import * as t from '@babel/types';
7
+ import type { TransformContext } from '../context.js';
8
+ /**
9
+ * 条件分支配置
10
+ */
11
+ export interface BranchConfig {
12
+ /** 条件表达式数组 */
13
+ conditions: t.Expression[];
14
+ /** 分支函数数组 */
15
+ branches: t.ArrowFunctionExpression[];
16
+ /** 是否使用 unref 包装标识符条件 */
17
+ useRef?: boolean;
18
+ }
19
+ /**
20
+ * 创建 branch 调用
21
+ * @param config - 分支配置
22
+ * @param ctx - 转换上下文
23
+ * @returns branch 调用表达式
24
+ */
25
+ export declare function createBranch(config: BranchConfig, ctx: TransformContext): t.CallExpression;
26
+ /**
27
+ * 构建嵌套条件表达式
28
+ * 从后向前构建三元表达式链
29
+ */
30
+ export declare function buildNestedCondition(conditions: t.Expression[], ctx: TransformContext, useRef?: boolean): t.Expression;
31
+ /**
32
+ * 从条件数组和分支节点创建完整的 branch 调用
33
+ * @param conditions - 条件表达式数组
34
+ * @param branchNodes - 分支节点数组(会被包装为箭头函数)
35
+ * @param ctx - 转换上下文
36
+ * @returns branch 调用表达式
37
+ */
38
+ export declare function createBranchFromNodes(conditions: t.Expression[], branchNodes: t.Expression[], ctx: TransformContext): t.CallExpression;
39
+ /**
40
+ * 创建简单的二元条件 branch(用于三元表达式)
41
+ * @param condition - 条件表达式
42
+ * @param consequent - 真值分支
43
+ * @param alternate - 假值分支
44
+ * @param ctx - 转换上下文
45
+ * @returns branch 调用表达式
46
+ */
47
+ export declare function createBinaryBranch(condition: t.Expression, consequent: t.Expression, alternate: t.Expression, ctx: TransformContext): t.CallExpression;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * AST 收集模块
3
+ * 负责收集导入、导出、组件等信息的收集
4
+ * @module passes/transform/collect
5
+ */
6
+ import * as t from '@babel/types';
7
+ /**
8
+ * 组件信息
9
+ */
10
+ export interface ComponentInfo {
11
+ name: string;
12
+ node: t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression;
13
+ }
14
+ /**
15
+ * 收集模块中的组件函数
16
+ */
17
+ export declare function collectComponentFunctions(program: t.Program): ComponentInfo[];
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 生成唯一的别名
3
+ * 从 $1 开始递增,直到找到不冲突的名称
4
+ */
5
+ export declare function generateUniqueAlias(baseName: string, existingNames: Set<string>): string;
@@ -0,0 +1,8 @@
1
+ export { isWhitespaceJSXText } from './ast-guards.js';
2
+ export { getJSXElementName, isPureCompileComponent, isComponent, isNativeElement, getJSXAttributeByName, hasDirective, getDirectiveValue, isVIfChain, isVIf, isVElseIf, isVElse, removeVDirectives, removeAttribute, filterWhitespaceChildren, validateMatchInSwitch } from './jsx-helpers.js';
3
+ export { createUnrefCall, createAccessCall, createDynamicCall, createBranchCall, createCreateViewCall, createWithDirectivesCall, createArrowFunction, createLocationObject, addPureComment, getAlias } from './ast-builders.js';
4
+ export { collectPatternBindings, collectObjectPatternBindings } from './pattern-helpers.js';
5
+ export { createBranch, createBinaryBranch, buildNestedCondition, type BranchConfig } from './branch-factory.js';
6
+ export { validateVIfChain, collectVIfChainInfo, collectFragmentVIfChains, type VIfChainInfo } from './vif-helpers.js';
7
+ export { collectComponentFunctions, type ComponentInfo } from './component-collect.js';
8
+ export { generateUniqueAlias } from './generate.js';
@@ -0,0 +1,67 @@
1
+ /**
2
+ * JSX 相关工具函数
3
+ * @module utils/jsx-helpers
4
+ */
5
+ import * as t from '@babel/types';
6
+ import { type Expression, type JSXAttribute, type JSXElement } from '@babel/types';
7
+ /**
8
+ * 获取 JSX 元素的名称
9
+ */
10
+ export declare function getJSXElementName(node: JSXElement): string | null;
11
+ /**
12
+ * 判断名称是否为纯编译组件
13
+ */
14
+ export declare function isPureCompileComponent(name: string): boolean;
15
+ /**
16
+ * 判断名称是否为组件(首字母大写)
17
+ */
18
+ export declare function isComponent(name: string): boolean;
19
+ /**
20
+ * 判断名称是否为原生元素
21
+ */
22
+ export declare function isNativeElement(name: string): boolean;
23
+ /**
24
+ * 根据名称获取 JSX 属性
25
+ */
26
+ export declare function getJSXAttributeByName(node: JSXElement, name: string): JSXAttribute | undefined;
27
+ /**
28
+ * 检查元素是否具有指定指令
29
+ */
30
+ export declare function hasDirective(node: JSXElement, directiveName: string): boolean;
31
+ /**
32
+ * 获取指令的值
33
+ */
34
+ export declare function getDirectiveValue(node: JSXElement, directiveName: string): Expression | null;
35
+ /**
36
+ * 检查元素是否为 v-if 链的一部分
37
+ */
38
+ export declare function isVIfChain(node: JSXElement): boolean;
39
+ /**
40
+ * 检查元素是否有 v-if 指令
41
+ */
42
+ export declare function isVIf(node: JSXElement): boolean;
43
+ /**
44
+ * 检查元素是否有 v-else-if 指令
45
+ */
46
+ export declare function isVElseIf(node: JSXElement): boolean;
47
+ /**
48
+ * 检查元素是否有 v-else 指令
49
+ */
50
+ export declare function isVElse(node: JSXElement): boolean;
51
+ /**
52
+ * 移除元素上所有 v- 开头的指令属性
53
+ */
54
+ export declare function removeVDirectives(node: JSXElement): void;
55
+ /**
56
+ * 移除元素上指定名称的属性
57
+ */
58
+ export declare function removeAttribute(node: JSXElement, attrName: string): void;
59
+ /**
60
+ * 过滤掉空白文本子节点
61
+ */
62
+ export declare function filterWhitespaceChildren(children: t.Node[]): t.Node[];
63
+ /**
64
+ * 校验 Match 组件必须在 Switch 内使用
65
+ * @param children - 子节点数组
66
+ */
67
+ export declare function validateMatchInSwitch(children: t.Node[]): void;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * AST 模式处理辅助函数
3
+ * 用于处理解构模式、绑定模式等
4
+ * @module utils/pattern-helpers
5
+ */
6
+ import type { LVal, ObjectPattern } from '@babel/types';
7
+ /**
8
+ * 从绑定模式中收集变量名
9
+ * 支持标识符、对象模式、数组模式
10
+ * @param pattern - 绑定模式
11
+ * @param variables - 变量名集合
12
+ */
13
+ export declare function collectPatternBindings(pattern: LVal, variables: Set<string>): void;
14
+ /**
15
+ * 从对象解构模式中收集变量名
16
+ * 专门用于 toRefs 解构场景
17
+ * @param pattern - 对象模式
18
+ * @param variables - 变量名集合
19
+ */
20
+ export declare function collectObjectPatternBindings(pattern: ObjectPattern, variables: Set<string>): void;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * v-if 链处理工具模块
3
+ * 统一处理 v-if/v-else-if/v-else 链的验证和收集
4
+ * @module utils/vif-helpers
5
+ */
6
+ import * as t from '@babel/types';
7
+ /**
8
+ * v-if 链信息
9
+ */
10
+ export interface VIfChainInfo {
11
+ /** 链中的元素节点 */
12
+ nodes: t.JSXElement[];
13
+ /** 条件表达式数组 */
14
+ conditions: t.Expression[];
15
+ /** 结束索引 */
16
+ endIndex: number;
17
+ }
18
+ /**
19
+ * 验证 v-if 链的合法性
20
+ */
21
+ export declare function validateVIfChain(children: t.JSXElement[]): void;
22
+ /**
23
+ * 从 JSX 元素数组收集 v-if 链信息
24
+ */
25
+ export declare function collectVIfChainInfo(nodes: t.JSXElement[]): VIfChainInfo;
26
+ /**
27
+ * 收集 Fragment 中的 v-if 链
28
+ */
29
+ export declare function collectFragmentVIfChains(children: t.Node[]): Array<VIfChainInfo & {
30
+ endIndex: number;
31
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitarx/plugin-vite",
3
- "version": "0.0.1-alpha.0",
3
+ "version": "0.0.1-alpha.1",
4
4
  "description": "The official plugin for Vitarx support in Vite.",
5
5
  "author": "ZhuChongLin <8210856@qq.com>",
6
6
  "license": "MIT",