@vitarx/plugin-vite 1.0.0-beta.5 → 1.0.0-beta.7
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
|
-
*
|
|
11
|
+
* 处理成员表达式
|
|
12
|
+
* object 为简单标识符时使用 accessor(细粒度追踪)
|
|
13
|
+
* object 为其他表达式(嵌套成员访问等)时降级为 expr(粗粒度追踪)
|
|
12
14
|
*/
|
|
13
15
|
function handleMemberExpression(expr, ctx) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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 包装表达式
|
|
@@ -55,10 +60,9 @@ export function processChildren(children, ctx) {
|
|
|
55
60
|
*/
|
|
56
61
|
function processChildNode(node, ctx) {
|
|
57
62
|
if (isJSXText(node)) {
|
|
58
|
-
|
|
59
|
-
if (!trimmed)
|
|
63
|
+
if (!node.value.trim())
|
|
60
64
|
return null;
|
|
61
|
-
const collapsed =
|
|
65
|
+
const collapsed = node.value.replace(/\s+/g, ' ');
|
|
62
66
|
return t.stringLiteral(collapsed);
|
|
63
67
|
}
|
|
64
68
|
// 处理 JSX 表达式容器,递归处理容器内的表达式
|