@vitarx/plugin-vite 1.0.0 → 1.0.2-alpha.0
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.
- package/dist/hmr-client/index.d.ts +15 -5
- package/dist/hmr-client/index.js +47 -25
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -6
- package/dist/passes/hmr/inject-imports.d.ts +4 -1
- package/dist/passes/hmr/inject-imports.js +8 -1
- package/dist/passes/hmr/inject-state.d.ts +6 -1
- package/dist/passes/hmr/inject-state.js +58 -5
- package/dist/passes/hmr/inject.d.ts +1 -1
- package/dist/passes/hmr/inject.js +27 -2
- package/dist/passes/imports/collectImports.d.ts +4 -4
- package/dist/passes/imports/collectImports.js +20 -5
- package/dist/passes/imports/collectRefVariables.d.ts +2 -2
- package/dist/passes/imports/collectRefVariables.js +47 -3
- package/dist/passes/imports/injectImports.d.ts +1 -0
- package/dist/passes/imports/injectImports.js +28 -2
- package/dist/transform.js +11 -1
- package/dist/utils/ast-builders.d.ts +49 -41
- package/dist/utils/ast-builders.js +60 -41
- package/dist/utils/ast-guards.d.ts +2 -1
- package/dist/utils/ast-guards.js +4 -1
- package/dist/utils/collect-names.d.ts +13 -4
- package/dist/utils/collect-names.js +38 -4
- package/dist/utils/component-collect.d.ts +4 -2
- package/dist/utils/component-collect.js +181 -6
- package/dist/utils/generate.d.ts +3 -0
- package/dist/utils/generate.js +4 -0
- package/dist/utils/jsx-helpers.d.ts +14 -0
- package/dist/utils/jsx-helpers.js +21 -0
- package/dist/utils/pattern-helpers.d.ts +4 -4
- package/dist/utils/pattern-helpers.js +13 -4
- package/dist/utils/vif-helpers.d.ts +8 -0
- package/dist/utils/vif-helpers.js +36 -0
- package/package.json +2 -2
|
@@ -14,7 +14,7 @@ import type { RefApiAliases } from '../../context.js';
|
|
|
14
14
|
export declare function collectRefApiAliases(program: t.Program): RefApiAliases;
|
|
15
15
|
/**
|
|
16
16
|
* 收集通过 ref API 定义的变量
|
|
17
|
-
*
|
|
17
|
+
* 包括直接赋值(const x = ref(0))和 toRefs 解构(const { a, b } = toRefs(obj))
|
|
18
18
|
* @param program - AST Program 节点
|
|
19
19
|
* @param refApiAliases - ref API 别名映射
|
|
20
20
|
* @returns ref 变量名集合
|
|
@@ -22,7 +22,7 @@ export declare function collectRefApiAliases(program: t.Program): RefApiAliases;
|
|
|
22
22
|
export declare function collectRefVariables(program: t.Program, refApiAliases: RefApiAliases): Set<string>;
|
|
23
23
|
/**
|
|
24
24
|
* 收集确定不是 ref 的变量
|
|
25
|
-
*
|
|
25
|
+
* 包括函数声明、箭头函数和函数表达式变量(这些不可能是 ref)
|
|
26
26
|
* @param program - AST Program 节点
|
|
27
27
|
* @returns 非 ref 变量名集合
|
|
28
28
|
*/
|
|
@@ -7,6 +7,7 @@ import { collectPatternBindings, collectObjectPatternBindings } from '../../util
|
|
|
7
7
|
* @returns ref API 别名映射
|
|
8
8
|
*/
|
|
9
9
|
export function collectRefApiAliases(program) {
|
|
10
|
+
// 初始化别名映射,默认为 null(未导入)
|
|
10
11
|
const aliases = {
|
|
11
12
|
ref: null,
|
|
12
13
|
toRef: null,
|
|
@@ -14,18 +15,25 @@ export function collectRefApiAliases(program) {
|
|
|
14
15
|
shallowRef: null,
|
|
15
16
|
computed: null
|
|
16
17
|
};
|
|
18
|
+
// 遍历程序体中的所有节点
|
|
17
19
|
for (const node of program.body) {
|
|
20
|
+
// 跳过非导入声明节点
|
|
18
21
|
if (node.type !== 'ImportDeclaration')
|
|
19
22
|
continue;
|
|
20
23
|
const source = node.source.value;
|
|
24
|
+
// 只处理 vitarx 和 @vitarx/responsive 模块
|
|
21
25
|
if (!RESPONSIVE_MODULES.includes(source))
|
|
22
26
|
continue;
|
|
27
|
+
// 遍历导入说明符
|
|
23
28
|
for (const specifier of node.specifiers) {
|
|
29
|
+
// 只处理命名导入
|
|
24
30
|
if (specifier.type !== 'ImportSpecifier')
|
|
25
31
|
continue;
|
|
32
|
+
// 获取导入的原始名称
|
|
26
33
|
const importedName = specifier.imported.type === 'Identifier'
|
|
27
34
|
? specifier.imported.name
|
|
28
35
|
: specifier.imported.value;
|
|
36
|
+
// 如果是 ref API,记录别名映射
|
|
29
37
|
if (Object.values(REF_APIS).includes(importedName)) {
|
|
30
38
|
aliases[importedName] = specifier.local.name;
|
|
31
39
|
}
|
|
@@ -35,48 +43,66 @@ export function collectRefApiAliases(program) {
|
|
|
35
43
|
}
|
|
36
44
|
/**
|
|
37
45
|
* 收集通过 ref API 定义的变量
|
|
38
|
-
*
|
|
46
|
+
* 包括直接赋值(const x = ref(0))和 toRefs 解构(const { a, b } = toRefs(obj))
|
|
39
47
|
* @param program - AST Program 节点
|
|
40
48
|
* @param refApiAliases - ref API 别名映射
|
|
41
49
|
* @returns ref 变量名集合
|
|
42
50
|
*/
|
|
43
51
|
export function collectRefVariables(program, refApiAliases) {
|
|
44
52
|
const refVariables = new Set();
|
|
53
|
+
// 构建 ref API 的本地名称集合(包括别名)
|
|
45
54
|
const { refApiLocalNames, toRefsLocalNames } = buildApiNameSets(refApiAliases);
|
|
55
|
+
// 遍历程序体中的所有节点
|
|
46
56
|
for (const node of program.body) {
|
|
47
57
|
collectRefVariablesFromNode(node, refVariables, refApiLocalNames, toRefsLocalNames);
|
|
48
58
|
}
|
|
49
59
|
return refVariables;
|
|
50
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* 从节点中递归收集 ref 变量
|
|
63
|
+
* @param node - AST 节点
|
|
64
|
+
* @param refVariables - 存储 ref 变量名的集合
|
|
65
|
+
* @param refApiLocalNames - ref API 的本地名称集合
|
|
66
|
+
* @param toRefsLocalNames - toRefs API 的本地名称集合
|
|
67
|
+
*/
|
|
51
68
|
function collectRefVariablesFromNode(node, refVariables, refApiLocalNames, toRefsLocalNames) {
|
|
69
|
+
// 处理变量声明
|
|
52
70
|
if (node.type === 'VariableDeclaration') {
|
|
53
71
|
for (const decl of node.declarations) {
|
|
72
|
+
// 跳过没有初始值的声明
|
|
54
73
|
if (!decl.init)
|
|
55
74
|
continue;
|
|
75
|
+
// 跳过 void 模式
|
|
56
76
|
if (decl.id.type === 'VoidPattern')
|
|
57
77
|
continue;
|
|
58
78
|
const init = decl.init;
|
|
79
|
+
// 检查是否为函数调用表达式
|
|
59
80
|
if (init.type !== 'CallExpression' || init.callee.type !== 'Identifier') {
|
|
60
81
|
continue;
|
|
61
82
|
}
|
|
62
83
|
const calleeName = init.callee.name;
|
|
84
|
+
// toRefs 需要特殊处理:只收集对象解构的属性
|
|
63
85
|
if (toRefsLocalNames.has(calleeName) && decl.id.type === 'ObjectPattern') {
|
|
64
86
|
collectObjectPatternBindings(decl.id, refVariables);
|
|
65
87
|
}
|
|
66
88
|
else if (refApiLocalNames.has(calleeName)) {
|
|
89
|
+
// 其他 ref API:收集变量名(支持解构)
|
|
67
90
|
collectPatternBindings(decl.id, refVariables);
|
|
68
91
|
}
|
|
69
92
|
}
|
|
70
93
|
}
|
|
71
94
|
else if (node.type === 'FunctionDeclaration' && node.body) {
|
|
95
|
+
// 递归处理函数体内的语句
|
|
72
96
|
for (const stmt of node.body.body) {
|
|
73
97
|
collectRefVariablesFromNode(stmt, refVariables, refApiLocalNames, toRefsLocalNames);
|
|
74
98
|
}
|
|
75
99
|
}
|
|
76
100
|
else if (node.type === 'ExportNamedDeclaration' && node.declaration) {
|
|
101
|
+
// 处理命名导出的声明
|
|
77
102
|
collectRefVariablesFromNode(node.declaration, refVariables, refApiLocalNames, toRefsLocalNames);
|
|
78
103
|
}
|
|
79
104
|
else if (node.type === 'ExportDefaultDeclaration') {
|
|
105
|
+
// 处理默认导出
|
|
80
106
|
const decl = node.declaration;
|
|
81
107
|
if (decl.type === 'FunctionDeclaration' && decl.body) {
|
|
82
108
|
for (const stmt of decl.body.body) {
|
|
@@ -87,20 +113,28 @@ function collectRefVariablesFromNode(node, refVariables, refApiLocalNames, toRef
|
|
|
87
113
|
}
|
|
88
114
|
/**
|
|
89
115
|
* 收集确定不是 ref 的变量
|
|
90
|
-
*
|
|
116
|
+
* 包括函数声明、箭头函数和函数表达式变量(这些不可能是 ref)
|
|
91
117
|
* @param program - AST Program 节点
|
|
92
118
|
* @returns 非 ref 变量名集合
|
|
93
119
|
*/
|
|
94
120
|
export function collectNonRefVariables(program) {
|
|
95
121
|
const nonRefVariables = new Set();
|
|
122
|
+
// 遍历程序体中的所有节点
|
|
96
123
|
for (const node of program.body) {
|
|
97
124
|
collectNonRefFromNode(node, nonRefVariables);
|
|
98
125
|
}
|
|
99
126
|
return nonRefVariables;
|
|
100
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* 从节点中递归收集非 ref 变量
|
|
130
|
+
* @param node - AST 节点
|
|
131
|
+
* @param nonRefVariables - 存储非 ref 变量名的集合
|
|
132
|
+
*/
|
|
101
133
|
function collectNonRefFromNode(node, nonRefVariables) {
|
|
134
|
+
// 函数声明一定不是 ref
|
|
102
135
|
if (node.type === 'FunctionDeclaration' && node.id) {
|
|
103
136
|
nonRefVariables.add(node.id.name);
|
|
137
|
+
// 递归处理函数体内的变量
|
|
104
138
|
if (node.body) {
|
|
105
139
|
for (const stmt of node.body.body) {
|
|
106
140
|
collectNonRefFromNode(stmt, nonRefVariables);
|
|
@@ -108,9 +142,11 @@ function collectNonRefFromNode(node, nonRefVariables) {
|
|
|
108
142
|
}
|
|
109
143
|
}
|
|
110
144
|
else if (node.type === 'VariableDeclaration') {
|
|
145
|
+
// 变量声明:只有箭头函数或函数表达式才是非 ref
|
|
111
146
|
for (const decl of node.declarations) {
|
|
112
147
|
if (!decl.init)
|
|
113
148
|
continue;
|
|
149
|
+
// 只处理简单标识符(不处理解构)
|
|
114
150
|
if (decl.id.type !== 'Identifier')
|
|
115
151
|
continue;
|
|
116
152
|
const init = decl.init;
|
|
@@ -121,11 +157,13 @@ function collectNonRefFromNode(node, nonRefVariables) {
|
|
|
121
157
|
}
|
|
122
158
|
}
|
|
123
159
|
else if (node.type === 'ExportNamedDeclaration') {
|
|
160
|
+
// 处理命名导出的声明
|
|
124
161
|
if (node.declaration) {
|
|
125
162
|
collectNonRefFromNode(node.declaration, nonRefVariables);
|
|
126
163
|
}
|
|
127
164
|
}
|
|
128
165
|
else if (node.type === 'ExportDefaultDeclaration') {
|
|
166
|
+
// 处理默认导出
|
|
129
167
|
const decl = node.declaration;
|
|
130
168
|
if (decl.type === 'FunctionDeclaration' && decl.id) {
|
|
131
169
|
nonRefVariables.add(decl.id.name);
|
|
@@ -133,14 +171,19 @@ function collectNonRefFromNode(node, nonRefVariables) {
|
|
|
133
171
|
}
|
|
134
172
|
}
|
|
135
173
|
/**
|
|
136
|
-
* 构建 API
|
|
174
|
+
* 构建 ref API 的本地名称集合
|
|
175
|
+
* 将别名映射转换为集合,便于快速查找
|
|
176
|
+
* @param refApiAliases - ref API 别名映射
|
|
177
|
+
* @returns 包含 ref API 和 toRefs API 的本地名称集合
|
|
137
178
|
*/
|
|
138
179
|
function buildApiNameSets(refApiAliases) {
|
|
139
180
|
const refApiLocalNames = new Set();
|
|
140
181
|
const toRefsLocalNames = new Set();
|
|
182
|
+
// 遍历所有 ref API
|
|
141
183
|
for (const key of Object.keys(refApiAliases)) {
|
|
142
184
|
const alias = refApiAliases[key];
|
|
143
185
|
if (alias) {
|
|
186
|
+
// 如果有别名,使用别名
|
|
144
187
|
if (key === 'toRefs') {
|
|
145
188
|
toRefsLocalNames.add(alias);
|
|
146
189
|
}
|
|
@@ -149,6 +192,7 @@ function buildApiNameSets(refApiAliases) {
|
|
|
149
192
|
}
|
|
150
193
|
}
|
|
151
194
|
else {
|
|
195
|
+
// 如果没有别名,使用原始名称
|
|
152
196
|
if (key === 'toRefs') {
|
|
153
197
|
toRefsLocalNames.add(key);
|
|
154
198
|
}
|
|
@@ -8,6 +8,7 @@ import { VITARX_MODULE } from '../../constants/index.js';
|
|
|
8
8
|
/**
|
|
9
9
|
* API 导入配置
|
|
10
10
|
* 定义需要注入的 API 及其与 ImportInfo 的映射关系
|
|
11
|
+
* 当代码中使用了特定的 vitarx API 时,自动注入对应的 import 语句
|
|
11
12
|
*/
|
|
12
13
|
const API_IMPORT_CONFIG = [
|
|
13
14
|
{ name: 'createView', importKey: 'createView' },
|
|
@@ -22,17 +23,22 @@ const API_IMPORT_CONFIG = [
|
|
|
22
23
|
/**
|
|
23
24
|
* 注入 vitarx 导入
|
|
24
25
|
* 根据已使用的 API 动态生成导入语句
|
|
26
|
+
* 如果已存在 vitarx 导入,则追加说明符;否则创建新的导入语句
|
|
25
27
|
* @param program - AST Program 节点
|
|
26
28
|
* @param ctx - 转换上下文
|
|
27
29
|
*/
|
|
28
30
|
export function injectImports(program, ctx) {
|
|
31
|
+
// 如果没有需要注入的 API,直接返回
|
|
29
32
|
if (!needsInject(ctx))
|
|
30
33
|
return;
|
|
34
|
+
// 查找已存在的 vitarx 导入语句
|
|
31
35
|
const existingVitarxImport = findExistingVitarxImport(program);
|
|
36
|
+
// 如果存在且可以追加说明符,则追加
|
|
32
37
|
if (existingVitarxImport && canAppendSpecifiers(existingVitarxImport)) {
|
|
33
38
|
appendImportSpecifiers(existingVitarxImport, ctx);
|
|
34
39
|
}
|
|
35
40
|
else {
|
|
41
|
+
// 否则创建新的导入语句
|
|
36
42
|
const specifiers = buildImportSpecifiers(ctx);
|
|
37
43
|
if (specifiers.length === 0)
|
|
38
44
|
return;
|
|
@@ -42,7 +48,9 @@ export function injectImports(program, ctx) {
|
|
|
42
48
|
}
|
|
43
49
|
/**
|
|
44
50
|
* 检查是否可以向导入语句追加说明符
|
|
45
|
-
*
|
|
51
|
+
* 只有纯命名导入才能追加,命名空间导入(import * as xxx)和默认导入(import xxx)不能追加
|
|
52
|
+
* @param importDecl - 导入声明节点
|
|
53
|
+
* @returns 是否可以追加说明符
|
|
46
54
|
*/
|
|
47
55
|
function canAppendSpecifiers(importDecl) {
|
|
48
56
|
for (const spec of importDecl.specifiers) {
|
|
@@ -55,7 +63,9 @@ function canAppendSpecifiers(importDecl) {
|
|
|
55
63
|
}
|
|
56
64
|
/**
|
|
57
65
|
* 查找已存在的 vitarx 导入语句
|
|
58
|
-
* 只查找普通的 import 语句,跳过 import type 语句
|
|
66
|
+
* 只查找普通的 import 语句,跳过 import type/typeof 语句
|
|
67
|
+
* @param program - AST Program 节点
|
|
68
|
+
* @returns 已存在的 vitarx 导入声明,不存在则返回 null
|
|
59
69
|
*/
|
|
60
70
|
function findExistingVitarxImport(program) {
|
|
61
71
|
for (const node of program.body) {
|
|
@@ -70,21 +80,29 @@ function findExistingVitarxImport(program) {
|
|
|
70
80
|
}
|
|
71
81
|
/**
|
|
72
82
|
* 向已存在的导入语句追加说明符
|
|
83
|
+
* @param importDecl - 导入声明节点
|
|
84
|
+
* @param ctx - 转换上下文
|
|
73
85
|
*/
|
|
74
86
|
function appendImportSpecifiers(importDecl, ctx) {
|
|
87
|
+
// 收集已存在的本地名称,避免重复
|
|
75
88
|
const existingLocals = new Set();
|
|
76
89
|
for (const spec of importDecl.specifiers) {
|
|
77
90
|
if (spec.type === 'ImportSpecifier') {
|
|
78
91
|
existingLocals.add(spec.local.name);
|
|
79
92
|
}
|
|
80
93
|
}
|
|
94
|
+
// 遍历需要注入的 API
|
|
81
95
|
for (const { name, importKey } of API_IMPORT_CONFIG) {
|
|
96
|
+
// 如果该 API 未被使用,跳过
|
|
82
97
|
if (!ctx.imports[importKey])
|
|
83
98
|
continue;
|
|
99
|
+
// 获取用户配置的别名,无别名则使用原始名称
|
|
84
100
|
const alias = ctx.vitarxAliases[name];
|
|
85
101
|
const localName = alias || name;
|
|
102
|
+
// 如果该本地名称已存在,跳过
|
|
86
103
|
if (existingLocals.has(localName))
|
|
87
104
|
continue;
|
|
105
|
+
// 创建导入说明符并追加
|
|
88
106
|
const imported = t.identifier(name);
|
|
89
107
|
const local = t.identifier(localName);
|
|
90
108
|
importDecl.specifiers.push(t.importSpecifier(local, imported));
|
|
@@ -92,17 +110,25 @@ function appendImportSpecifiers(importDecl, ctx) {
|
|
|
92
110
|
}
|
|
93
111
|
/**
|
|
94
112
|
* 检查是否需要注入导入
|
|
113
|
+
* @param ctx - 转换上下文
|
|
114
|
+
* @returns 是否有需要注入的 API
|
|
95
115
|
*/
|
|
96
116
|
function needsInject(ctx) {
|
|
117
|
+
// 检查 imports 对象中是否有任何值为 true
|
|
97
118
|
return Object.values(ctx.imports).some(Boolean);
|
|
98
119
|
}
|
|
99
120
|
/**
|
|
100
121
|
* 构建导入说明符列表
|
|
122
|
+
* @param ctx - 转换上下文
|
|
123
|
+
* @returns 导入说明符数组
|
|
101
124
|
*/
|
|
102
125
|
function buildImportSpecifiers(ctx) {
|
|
103
126
|
const specifiers = [];
|
|
127
|
+
// 遍历需要注入的 API
|
|
104
128
|
for (const { name, importKey } of API_IMPORT_CONFIG) {
|
|
129
|
+
// 只处理已使用的 API
|
|
105
130
|
if (ctx.imports[importKey]) {
|
|
131
|
+
// 获取用户配置的别名
|
|
106
132
|
const alias = ctx.vitarxAliases[name];
|
|
107
133
|
const imported = t.identifier(name);
|
|
108
134
|
const local = alias ? t.identifier(alias) : imported;
|
package/dist/transform.js
CHANGED
|
@@ -9,6 +9,7 @@ import traverse from '@babel/traverse';
|
|
|
9
9
|
import { createContext } from './context.js';
|
|
10
10
|
import { collectExistingImports, collectLocalBindings, collectNonRefVariables, collectRefApiAliases, collectRefVariables, injectHMRSupport, injectImports, processJSXElement, processJSXFragment, processPureCompileComponent, processVIfChain, transformJSXElement } from './passes/index.js';
|
|
11
11
|
import { collectComponentFunctions, generateUniqueAlias, getJSXElementName, isPureCompileComponent } from './utils/index.js';
|
|
12
|
+
const entryPatterns = [/\/src\/main\.(tsx|jsx)$/, /\\src\\main\.(tsx|jsx)$/];
|
|
12
13
|
/**
|
|
13
14
|
* 创建解析器选项
|
|
14
15
|
*/
|
|
@@ -127,6 +128,15 @@ export function shouldTransform(id) {
|
|
|
127
128
|
const ext = id.split('?')[0].split('.').pop()?.toLowerCase();
|
|
128
129
|
return ext === 'jsx' || ext === 'tsx';
|
|
129
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* 检查是否为入口文件
|
|
133
|
+
* 入口文件(如 src/main.tsx/src/main.jsx)不应注入 HMR,因为主脚本重新执行会导致页面内容重复
|
|
134
|
+
* 最佳实践:入口文件应为 main.ts/main.js,组件应放在 App.tsx/App.jsx 等专门的组件文件中
|
|
135
|
+
*/
|
|
136
|
+
function isEntryFile(id) {
|
|
137
|
+
const normalizedId = id.split('?')[0];
|
|
138
|
+
return entryPatterns.some(pattern => pattern.test(normalizedId));
|
|
139
|
+
}
|
|
130
140
|
/**
|
|
131
141
|
* 转换 JSX/TSX 代码
|
|
132
142
|
*/
|
|
@@ -138,7 +148,7 @@ export async function transform(code, id, options) {
|
|
|
138
148
|
const components = collectComponentFunctions(ast.program, ctx.builderAlias);
|
|
139
149
|
transformAST(ast, ctx);
|
|
140
150
|
injectImports(ast.program, ctx);
|
|
141
|
-
if (options.hmr && components.length > 0) {
|
|
151
|
+
if (options.hmr && components.length > 0 && !isEntryFile(id)) {
|
|
142
152
|
injectHMRSupport(ast.program, components, id);
|
|
143
153
|
}
|
|
144
154
|
return generateCode(ast, code, id, options.sourceMap);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AST 节点构建函数
|
|
3
|
+
* 提供各类运行时 API 调用的创建辅助函数
|
|
3
4
|
* @module utils/ast-builders
|
|
4
5
|
*/
|
|
5
6
|
import * as t from '@babel/types';
|
|
@@ -7,84 +8,91 @@ import { type ArrowFunctionExpression, type CallExpression, type Expression, typ
|
|
|
7
8
|
import type { SourceLocation } from 'acorn';
|
|
8
9
|
import type { TransformContext, VitarxImportAliases } from '../context.js';
|
|
9
10
|
/**
|
|
10
|
-
* 创建 unref
|
|
11
|
-
* @param argument -
|
|
12
|
-
* @param alias - unref
|
|
13
|
-
* @returns
|
|
11
|
+
* 创建 unref 调用表达式
|
|
12
|
+
* @param argument - 需要解包的表达式
|
|
13
|
+
* @param alias - unref 的本地别名
|
|
14
|
+
* @returns unref(arg) 调用表达式
|
|
14
15
|
*/
|
|
15
16
|
export declare function createUnrefCall(argument: Expression, alias?: string): CallExpression;
|
|
16
17
|
/**
|
|
17
|
-
* 创建 accessor
|
|
18
|
+
* 创建 accessor 调用表达式
|
|
19
|
+
* 用于细粒度响应式追踪,只追踪对象的特定属性
|
|
18
20
|
* @param object - 对象表达式
|
|
19
|
-
* @param key -
|
|
20
|
-
* @param alias - accessor
|
|
21
|
-
* @returns
|
|
21
|
+
* @param key - 属性键表达式
|
|
22
|
+
* @param alias - accessor 的本地别名
|
|
23
|
+
* @returns accessor(obj, key) 调用表达式
|
|
22
24
|
*/
|
|
23
25
|
export declare function createAccessorCall(object: Expression, key: Expression, alias?: string): CallExpression;
|
|
24
26
|
/**
|
|
25
|
-
* 创建 expr
|
|
26
|
-
*
|
|
27
|
-
* @param
|
|
28
|
-
* @
|
|
27
|
+
* 创建 expr 调用表达式
|
|
28
|
+
* 用于粗粒度响应式追踪,包装任意表达式
|
|
29
|
+
* @param argument - 需要包装的表达式
|
|
30
|
+
* @param alias - expr 的本地别名
|
|
31
|
+
* @returns expr(() => arg) 调用表达式
|
|
29
32
|
*/
|
|
30
33
|
export declare function createExprCall(argument: Expression, alias?: string): CallExpression;
|
|
31
34
|
/**
|
|
32
|
-
* 创建 branch
|
|
33
|
-
*
|
|
35
|
+
* 创建 branch 调用表达式
|
|
36
|
+
* 用于条件分支渲染,支持多分支选择
|
|
37
|
+
* @param condition - 返回分支索引的箭头函数
|
|
34
38
|
* @param branches - 分支函数数组
|
|
35
|
-
* @param alias - branch
|
|
36
|
-
* @returns
|
|
39
|
+
* @param alias - branch 的本地别名
|
|
40
|
+
* @returns branch(condition, [branches]) 调用表达式
|
|
37
41
|
*/
|
|
38
42
|
export declare function createBranchCall(condition: ArrowFunctionExpression, branches: ArrowFunctionExpression[], alias?: string): CallExpression;
|
|
39
43
|
/**
|
|
40
|
-
* 创建 createView
|
|
41
|
-
*
|
|
42
|
-
* @param
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @
|
|
44
|
+
* 创建 createView 调用表达式
|
|
45
|
+
* 这是核心的视图创建函数,将 JSX 转换为运行时调用
|
|
46
|
+
* @param type - 元素类型(字符串表示原生元素,标识符表示组件)
|
|
47
|
+
* @param props - 属性对象表达式
|
|
48
|
+
* @param locInfo - 开发环境下的位置信息(用于错误定位)
|
|
49
|
+
* @param alias - createView 的本地别名
|
|
50
|
+
* @returns createView(type, props?, locInfo?) 调用表达式
|
|
46
51
|
*/
|
|
47
52
|
export declare function createCreateViewCall(type: Expression, props: ObjectExpression | null, locInfo?: ObjectExpression | null, alias?: string): CallExpression;
|
|
48
53
|
/**
|
|
49
|
-
* 创建 withDirectives
|
|
50
|
-
*
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
53
|
-
* @
|
|
54
|
+
* 创建 withDirectives 调用表达式
|
|
55
|
+
* 用于为视图节点添加自定义指令
|
|
56
|
+
* @param view - 视图节点表达式
|
|
57
|
+
* @param directives - 指令数组,每项为 [指令名, 指令值] 元组
|
|
58
|
+
* @param alias - withDirectives 的本地别名
|
|
59
|
+
* @returns withDirectives(view, [[name, value], ...]) 调用表达式
|
|
54
60
|
*/
|
|
55
61
|
export declare function createWithDirectivesCall(view: Expression, directives: Array<[string, Expression]>, alias?: string): CallExpression;
|
|
56
62
|
/**
|
|
57
|
-
*
|
|
63
|
+
* 创建无参数箭头函数
|
|
58
64
|
* @param body - 函数体表达式
|
|
59
|
-
* @returns
|
|
65
|
+
* @returns () => body 箭头函数表达式
|
|
60
66
|
*/
|
|
61
67
|
export declare function createArrowFunction(body: Expression): ArrowFunctionExpression;
|
|
62
68
|
/**
|
|
63
69
|
* 为调用表达式添加 @__PURE__ 注释
|
|
70
|
+
* 标记纯函数调用,帮助 Tree Shaking 优化
|
|
64
71
|
* @param node - 调用表达式节点
|
|
65
|
-
* @param ctx -
|
|
66
|
-
* @returns
|
|
72
|
+
* @param ctx - 转换上下文(用于去重)
|
|
73
|
+
* @returns 添加注释后的节点(可能是原节点)
|
|
67
74
|
*/
|
|
68
75
|
export declare function addPureComment<T extends CallExpression>(node: T, ctx: TransformContext): T;
|
|
69
76
|
/**
|
|
70
|
-
* 获取 API
|
|
71
|
-
* @param aliases -
|
|
72
|
-
* @param name - API
|
|
73
|
-
* @returns
|
|
77
|
+
* 获取 API 的本地别名
|
|
78
|
+
* @param aliases - 别名映射对象
|
|
79
|
+
* @param name - API 原始名称
|
|
80
|
+
* @returns 本地别名或原始名称
|
|
74
81
|
*/
|
|
75
82
|
export declare function getAlias(aliases: VitarxImportAliases, name: keyof VitarxImportAliases): string;
|
|
76
83
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* @param
|
|
80
|
-
* @
|
|
84
|
+
* 创建源码位置信息对象
|
|
85
|
+
* 用于开发环境下的错误定位
|
|
86
|
+
* @param filename - 当前文件名
|
|
87
|
+
* @param loc - 源码位置信息
|
|
88
|
+
* @returns 位置信息对象 { fileName, lineNumber, columnNumber }
|
|
81
89
|
*/
|
|
82
90
|
export declare function createLocationObject(filename: string, loc: SourceLocation): ObjectExpression;
|
|
83
91
|
/**
|
|
84
92
|
* 获取开发环境下的位置信息对象
|
|
85
|
-
*
|
|
93
|
+
* 仅在开发模式且节点有位置信息时返回
|
|
86
94
|
* @param ctx - 转换上下文
|
|
87
|
-
* @param node - AST
|
|
95
|
+
* @param node - AST 节点或包含 loc 属性的对象
|
|
88
96
|
* @returns 位置信息对象或 null
|
|
89
97
|
*/
|
|
90
98
|
export declare function getDevLocInfo(ctx: TransformContext, node: t.Node | {
|