@vitarx/plugin-vite 1.0.0-beta.6 → 1.0.0-beta.8

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.
@@ -8,12 +8,17 @@ import { isBinaryExpression, isConditionalExpression, isIdentifier, isJSXElement
8
8
  import { markImport } from '../../context.js';
9
9
  import { addPureComment, createAccessorCall, createBinaryBranch, createExprCall, getAlias } from '../../utils/index.js';
10
10
  /**
11
- * 处理成员表达式,生成 accessor 调用
11
+ * 处理成员表达式
12
+ * object 为简单标识符时使用 accessor(细粒度追踪)
13
+ * object 为其他表达式(嵌套成员访问等)时降级为 expr(粗粒度追踪)
12
14
  */
13
15
  function handleMemberExpression(expr, ctx) {
14
- markImport(ctx, 'accessor');
15
- const accessorAlias = getAlias(ctx.vitarxAliases, 'accessor');
16
- return createAccessorCall(expr.object, expr.property, accessorAlias);
16
+ if (isIdentifier(expr.object)) {
17
+ markImport(ctx, 'accessor');
18
+ const accessorAlias = getAlias(ctx.vitarxAliases, 'accessor');
19
+ return createAccessorCall(expr.object, expr.property, accessorAlias);
20
+ }
21
+ return wrapWithExpr(expr, ctx);
17
22
  }
18
23
  /**
19
24
  * 使用 expr 包装表达式
@@ -109,6 +114,21 @@ function processChildExpression(expr, ctx) {
109
114
  // 其他类型的表达式直接返回,无需特殊处理
110
115
  return expr;
111
116
  }
117
+ /**
118
+ * 处理条件分支中的表达式
119
+ * JSXElement/JSXFragment 和已转换的 API 调用(createView/branch 等)直接透传
120
+ * 其他表达式按 children 规则处理(如 CallExpression 需要 expr 包装等)
121
+ */
122
+ function processBranchExpression(node, ctx) {
123
+ if (isJSXElement(node) || isJSXFragment(node)) {
124
+ return node;
125
+ }
126
+ // 已转换的 API 调用(带 @__PURE__ 注释的 createView/branch 等)直接透传
127
+ if (node.type === 'CallExpression' && ctx.pureCommentedNodes.has(node)) {
128
+ return node;
129
+ }
130
+ return processChildExpression(node, ctx);
131
+ }
112
132
  /**
113
133
  * 处理条件表达式,转换为 branch 调用
114
134
  * 该函数接收一个条件表达式节点和转换上下文,将其转换为二元分支调用
@@ -123,9 +143,9 @@ ctx // 转换上下文,提供转换过程中需要的辅助方法和状态
123
143
  // 解构条件表达式节点的三个主要部分:测试条件、真分支和假分支
124
144
  const { test, consequent, alternate } = node;
125
145
  // 处理真分支,如果处理结果为空则使用 null 字面量作为默认值
126
- const processedConsequent = processChildNode(consequent, ctx) || t.nullLiteral();
146
+ const processedConsequent = processBranchExpression(consequent, ctx) || t.nullLiteral();
127
147
  // 处理假分支,如果处理结果为空则使用 null 字面量作为默认值
128
- const processedAlternate = processChildNode(alternate, ctx) || t.nullLiteral();
148
+ const processedAlternate = processBranchExpression(alternate, ctx) || t.nullLiteral();
129
149
  // 创建并返回一个二元分支调用,传入测试条件、处理后的真分支和假分支
130
150
  return createBinaryBranch(test, processedConsequent, processedAlternate, ctx);
131
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitarx/plugin-vite",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.8",
4
4
  "description": "The official plugin for Vitarx support in Vite.",
5
5
  "author": "ZhuChongLin <8210856@qq.com>",
6
6
  "license": "MIT",