@vitarx/plugin-vite 1.0.0-beta.7 → 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.
@@ -114,6 +114,21 @@ function processChildExpression(expr, ctx) {
114
114
  // 其他类型的表达式直接返回,无需特殊处理
115
115
  return expr;
116
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
+ }
117
132
  /**
118
133
  * 处理条件表达式,转换为 branch 调用
119
134
  * 该函数接收一个条件表达式节点和转换上下文,将其转换为二元分支调用
@@ -128,9 +143,9 @@ ctx // 转换上下文,提供转换过程中需要的辅助方法和状态
128
143
  // 解构条件表达式节点的三个主要部分:测试条件、真分支和假分支
129
144
  const { test, consequent, alternate } = node;
130
145
  // 处理真分支,如果处理结果为空则使用 null 字面量作为默认值
131
- const processedConsequent = processChildNode(consequent, ctx) || t.nullLiteral();
146
+ const processedConsequent = processBranchExpression(consequent, ctx) || t.nullLiteral();
132
147
  // 处理假分支,如果处理结果为空则使用 null 字面量作为默认值
133
- const processedAlternate = processChildNode(alternate, ctx) || t.nullLiteral();
148
+ const processedAlternate = processBranchExpression(alternate, ctx) || t.nullLiteral();
134
149
  // 创建并返回一个二元分支调用,传入测试条件、处理后的真分支和假分支
135
150
  return createBinaryBranch(test, processedConsequent, processedAlternate, ctx);
136
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitarx/plugin-vite",
3
- "version": "1.0.0-beta.7",
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",