@vitarx/plugin-vite 1.0.3 → 1.0.4

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.
@@ -11,3 +11,11 @@ import { type Node } from '@babel/types';
11
11
  * @returns 是否为纯空白文本
12
12
  */
13
13
  export declare function isWhitespaceJSXText(node: Node): boolean;
14
+ /**
15
+ * 判断节点是否为 JSX 注释
16
+ * JSX 注释写作 {/* comment *\/},解析为 JSXExpressionContainer,
17
+ * 其 expression 为 JSXEmptyExpression(注释文本挂在 innerComments 上)
18
+ * @param node - AST 节点
19
+ * @returns 是否为 JSX 注释
20
+ */
21
+ export declare function isJSXComment(node: Node): boolean;
@@ -17,3 +17,14 @@ export function isWhitespaceJSXText(node) {
17
17
  // 使用正则表达式判断是否只包含空白字符
18
18
  return /^\s*$/.test(node.value);
19
19
  }
20
+ /**
21
+ * 判断节点是否为 JSX 注释
22
+ * JSX 注释写作 {/* comment *\/},解析为 JSXExpressionContainer,
23
+ * 其 expression 为 JSXEmptyExpression(注释文本挂在 innerComments 上)
24
+ * @param node - AST 节点
25
+ * @returns 是否为 JSX 注释
26
+ */
27
+ export function isJSXComment(node) {
28
+ return (node.type === 'JSXExpressionContainer' &&
29
+ node.expression.type === 'JSXEmptyExpression');
30
+ }
@@ -1,4 +1,4 @@
1
- export { isWhitespaceJSXText } from './ast-guards.js';
1
+ export { isWhitespaceJSXText, isJSXComment } from './ast-guards.js';
2
2
  export { getJSXElementName, resolveJSXElementType, isPureCompileComponent, isComponent, isNativeElement, getJSXAttributeByName, hasDirective, getDirectiveValue, isVIfChain, isVIf, isVElseIf, isVElse, removeVDirectives, removeVIfChainDirectives, removeAttribute, filterWhitespaceChildren, hasEffectiveChildren, filterEffectiveChildren, validateNoDirectMatchChild } 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';
@@ -1,5 +1,5 @@
1
1
  // 类型守卫
2
- export { isWhitespaceJSXText } from './ast-guards.js';
2
+ export { isWhitespaceJSXText, isJSXComment } from './ast-guards.js';
3
3
  // JSX 辅助函数
4
4
  export { getJSXElementName, resolveJSXElementType, isPureCompileComponent, isComponent, isNativeElement, getJSXAttributeByName, hasDirective, getDirectiveValue, isVIfChain, isVIf, isVElseIf, isVElse, removeVDirectives, removeVIfChainDirectives, removeAttribute, filterWhitespaceChildren, hasEffectiveChildren, filterEffectiveChildren, validateNoDirectMatchChild } from './jsx-helpers.js';
5
5
  // AST 构建函数
@@ -6,7 +6,7 @@
6
6
  import * as t from '@babel/types';
7
7
  import { isJSXElement, isJSXText } from '@babel/types';
8
8
  import { createError } from '../error.js';
9
- import { isWhitespaceJSXText } from './ast-guards.js';
9
+ import { isJSXComment, isWhitespaceJSXText } from './ast-guards.js';
10
10
  import { getDirectiveValue, hasDirective, isVElse, isVElseIf, isVIf, isVIfChain } from './jsx-helpers.js';
11
11
  /**
12
12
  * 验证 v-if 链的合法性
@@ -135,6 +135,11 @@ function collectSingleChainFromFragment(children, startIndex) {
135
135
  j++;
136
136
  continue;
137
137
  }
138
+ // 跳过 JSX 注释节点(允许链元素间有注释,如 {/* comment *\/})
139
+ if (isJSXComment(nextChild)) {
140
+ j++;
141
+ continue;
142
+ }
138
143
  // 遇到非 JSXElement,链结束
139
144
  if (!isJSXElement(nextChild))
140
145
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitarx/plugin-vite",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "The official plugin for Vitarx support in Vite.",
5
5
  "author": "ZhuChongLin <8210856@qq.com>",
6
6
  "license": "MIT",