@vitarx/plugin-vite 1.0.4 → 1.0.5
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/passes/directives/processDirectives.d.ts +1 -1
- package/dist/passes/directives/processDirectives.js +15 -10
- package/dist/passes/hmr/inject-state.d.ts +1 -1
- package/dist/passes/hmr/inject-state.js +38 -57
- package/dist/passes/imports/collectRefVariables.d.ts +1 -0
- package/dist/passes/imports/collectRefVariables.js +52 -19
- package/dist/passes/jsx/processJSXFragment.js +18 -1
- package/dist/passes/props/attribute.d.ts +3 -0
- package/dist/passes/props/attribute.js +13 -3
- package/dist/transform.js +5 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/branch-factory.js +26 -6
- package/dist/utils/component-collect.d.ts +7 -0
- package/dist/utils/component-collect.js +12 -236
- package/dist/utils/default-export.d.ts +38 -0
- package/dist/utils/default-export.js +119 -0
- package/dist/utils/function-extract.d.ts +45 -0
- package/dist/utils/function-extract.js +98 -0
- package/dist/utils/generate.d.ts +7 -0
- package/dist/utils/generate.js +20 -0
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +2 -2
- package/dist/utils/jsx-helpers.d.ts +1 -4
- package/dist/utils/jsx-helpers.js +2 -15
- package/dist/utils/vif-helpers.js +6 -3
- package/package.json +2 -2
package/dist/utils/generate.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 名称生成工具模块
|
|
3
|
+
* 提供唯一别名和默认导出名称的生成功能
|
|
4
|
+
* @module utils/generate
|
|
5
|
+
*/
|
|
6
|
+
import { DEFAULT_EXPORT_BASE_NAME } from '../constants/index.js';
|
|
1
7
|
/**
|
|
2
8
|
* 生成唯一的别名
|
|
3
9
|
* 从 $1 开始递增,直到找到不冲突的名称
|
|
@@ -13,3 +19,17 @@ export function generateUniqueAlias(baseName, existingNames) {
|
|
|
13
19
|
}
|
|
14
20
|
return `${baseName}$${index}`;
|
|
15
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* 生成唯一的默认导出组件名称
|
|
24
|
+
* 优先使用基础名称,若冲突则生成唯一别名
|
|
25
|
+
* @param existingNames - 已存在的名称集合
|
|
26
|
+
* @returns 唯一的默认导出名称
|
|
27
|
+
*/
|
|
28
|
+
export function generateUniqueDefaultName(existingNames) {
|
|
29
|
+
// 如果默认名称未被占用,直接返回
|
|
30
|
+
if (!existingNames.has(DEFAULT_EXPORT_BASE_NAME)) {
|
|
31
|
+
return DEFAULT_EXPORT_BASE_NAME;
|
|
32
|
+
}
|
|
33
|
+
// 否则生成唯一别名
|
|
34
|
+
return generateUniqueAlias(DEFAULT_EXPORT_BASE_NAME, existingNames);
|
|
35
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { isWhitespaceJSXText, isJSXComment } from './ast-guards.js';
|
|
2
|
-
export { getJSXElementName, resolveJSXElementType, isPureCompileComponent, isComponent, isNativeElement, getJSXAttributeByName, hasDirective, getDirectiveValue, isVIfChain, isVIf, isVElseIf, isVElse, removeVDirectives, removeVIfChainDirectives, removeAttribute, filterWhitespaceChildren, hasEffectiveChildren, filterEffectiveChildren
|
|
2
|
+
export { getJSXElementName, resolveJSXElementType, isPureCompileComponent, isComponent, isNativeElement, getJSXAttributeByName, hasDirective, getDirectiveValue, isVIfChain, isVIf, isVElseIf, isVElse, removeVDirectives, removeVIfChainDirectives, removeAttribute, filterWhitespaceChildren, hasEffectiveChildren, filterEffectiveChildren } from './jsx-helpers.js';
|
|
3
3
|
export { createUnrefCall, createAccessorCall, createExprCall, createBranchCall, createCreateViewCall, createWithDirectivesCall, createArrowFunction, createLocationObject, addPureComment, getAlias, getDevLocInfo } from './ast-builders.js';
|
|
4
4
|
export { collectPatternBindings, collectObjectPatternBindings } from './pattern-helpers.js';
|
|
5
5
|
export { createBranch, createBinaryBranch, buildNestedCondition, type BranchConfig } from './branch-factory.js';
|
|
6
6
|
export { validateVIfChain, collectVIfChainInfo, collectFragmentVIfChains, type VIfChainInfo } from './vif-helpers.js';
|
|
7
7
|
export { collectComponentFunctions, type ComponentInfo } from './component-collect.js';
|
|
8
|
-
export { generateUniqueAlias } from './generate.js';
|
|
8
|
+
export { generateUniqueAlias, generateUniqueDefaultName } from './generate.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// 类型守卫
|
|
2
2
|
export { isWhitespaceJSXText, isJSXComment } from './ast-guards.js';
|
|
3
3
|
// JSX 辅助函数
|
|
4
|
-
export { getJSXElementName, resolveJSXElementType, isPureCompileComponent, isComponent, isNativeElement, getJSXAttributeByName, hasDirective, getDirectiveValue, isVIfChain, isVIf, isVElseIf, isVElse, removeVDirectives, removeVIfChainDirectives, removeAttribute, filterWhitespaceChildren, hasEffectiveChildren, filterEffectiveChildren
|
|
4
|
+
export { getJSXElementName, resolveJSXElementType, isPureCompileComponent, isComponent, isNativeElement, getJSXAttributeByName, hasDirective, getDirectiveValue, isVIfChain, isVIf, isVElseIf, isVElse, removeVDirectives, removeVIfChainDirectives, removeAttribute, filterWhitespaceChildren, hasEffectiveChildren, filterEffectiveChildren } from './jsx-helpers.js';
|
|
5
5
|
// AST 构建函数
|
|
6
6
|
export { createUnrefCall, createAccessorCall, createExprCall, createBranchCall, createCreateViewCall, createWithDirectivesCall, createArrowFunction, createLocationObject, addPureComment, getAlias, getDevLocInfo } from './ast-builders.js';
|
|
7
7
|
// 模式处理辅助函数
|
|
@@ -13,4 +13,4 @@ export { validateVIfChain, collectVIfChainInfo, collectFragmentVIfChains } from
|
|
|
13
13
|
// 组件收集
|
|
14
14
|
export { collectComponentFunctions } from './component-collect.js';
|
|
15
15
|
// 生成器
|
|
16
|
-
export { generateUniqueAlias } from './generate.js';
|
|
16
|
+
export { generateUniqueAlias, generateUniqueDefaultName } from './generate.js';
|
|
@@ -101,8 +101,5 @@ export declare function hasEffectiveChildren(node: JSXElement): boolean;
|
|
|
101
101
|
*/
|
|
102
102
|
export declare function filterEffectiveChildren(node: JSXElement): t.Node[];
|
|
103
103
|
/**
|
|
104
|
-
*
|
|
105
|
-
* Match 必须在 Switch 内使用,非 Switch 元素的子节点中不允许出现 Match
|
|
106
|
-
* @param children - 子节点数组
|
|
104
|
+
* 过滤掉空白文本子节点
|
|
107
105
|
*/
|
|
108
|
-
export declare function validateNoDirectMatchChild(children: t.Node[]): void;
|
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
* @module utils/jsx-helpers
|
|
5
5
|
*/
|
|
6
6
|
import * as t from '@babel/types';
|
|
7
|
-
import {
|
|
7
|
+
import { isJSXText } from '@babel/types';
|
|
8
8
|
import { DIRECTIVE_PREFIX, PURE_COMPILE_COMPONENTS, V_IF_CHAIN_DIRECTIVES } from '../constants/index.js';
|
|
9
|
-
import { createError } from '../error.js';
|
|
10
9
|
import { isWhitespaceJSXText } from './ast-guards.js';
|
|
11
10
|
/**
|
|
12
11
|
* 获取 JSX 元素的名称
|
|
@@ -253,17 +252,5 @@ export function filterEffectiveChildren(node) {
|
|
|
253
252
|
return node.children.filter(isEffectiveChild);
|
|
254
253
|
}
|
|
255
254
|
/**
|
|
256
|
-
*
|
|
257
|
-
* Match 必须在 Switch 内使用,非 Switch 元素的子节点中不允许出现 Match
|
|
258
|
-
* @param children - 子节点数组
|
|
255
|
+
* 过滤掉空白文本子节点
|
|
259
256
|
*/
|
|
260
|
-
export function validateNoDirectMatchChild(children) {
|
|
261
|
-
for (const child of children) {
|
|
262
|
-
if (isJSXElement(child)) {
|
|
263
|
-
const childName = getJSXElementName(child);
|
|
264
|
-
if (childName === 'Match') {
|
|
265
|
-
throw createError('E012', child);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
@@ -125,7 +125,9 @@ export function collectFragmentVIfChains(children) {
|
|
|
125
125
|
*/
|
|
126
126
|
function collectSingleChainFromFragment(children, startIndex) {
|
|
127
127
|
const nodes = [children[startIndex]];
|
|
128
|
-
|
|
128
|
+
// v-if 指令值已由 validateVIfChain 保证存在,fallback 为 true(无表达式时)
|
|
129
|
+
const vIfValue = getDirectiveValue(nodes[0], 'v-if') ?? t.booleanLiteral(true);
|
|
130
|
+
const conditions = [vIfValue];
|
|
129
131
|
let j = startIndex + 1;
|
|
130
132
|
// 继续收集后续的 v-else-if 和 v-else
|
|
131
133
|
while (j < children.length) {
|
|
@@ -147,9 +149,10 @@ function collectSingleChainFromFragment(children, startIndex) {
|
|
|
147
149
|
if (!isVIfChain(nextChild))
|
|
148
150
|
break;
|
|
149
151
|
if (isVElseIf(nextChild)) {
|
|
150
|
-
// 收集 v-else-if
|
|
152
|
+
// 收集 v-else-if,值已由 validateVIfChain 保证存在
|
|
151
153
|
nodes.push(nextChild);
|
|
152
|
-
|
|
154
|
+
const vElseIfValue = getDirectiveValue(nextChild, 'v-else-if') ?? t.booleanLiteral(true);
|
|
155
|
+
conditions.push(vElseIfValue);
|
|
153
156
|
j++;
|
|
154
157
|
}
|
|
155
158
|
else if (isVElse(nextChild)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitarx/plugin-vite",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "The official plugin for Vitarx support in Vite.",
|
|
5
5
|
"author": "ZhuChongLin <8210856@qq.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"rimraf": "^6.1.3",
|
|
62
62
|
"vitest": "^4.0.18",
|
|
63
63
|
"vite": "^8.0.5",
|
|
64
|
-
"vitarx": "^4.0.
|
|
64
|
+
"vitarx": "^4.0.6"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
67
|
"build": "vitest run && rimraf dist && tsc -p tsconfig.build.json",
|