@vitarx/plugin-vite 1.0.6 → 1.0.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.
|
@@ -9,11 +9,18 @@ import { markImport } from '../../context.js';
|
|
|
9
9
|
import { addPureComment, createAccessorCall, createBinaryBranch, createExprCall, getAlias } from '../../utils/index.js';
|
|
10
10
|
/**
|
|
11
11
|
* 处理成员表达式
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* 静态成员(obj.prop,computed=false)时使用 accessor(细粒度追踪),
|
|
13
|
+
* property 标识符即属性名,字符串化后作为 key;
|
|
14
|
+
* 计算成员(obj[keyExpr],computed=true)时降级为 expr(粗粒度追踪)——
|
|
15
|
+
* accessor(obj, key) 的 key 在构建期一次求值,无法追踪 key 本身的变化,
|
|
16
|
+
* 且 key 为标识符时若误字符串化会读成 obj.key 改变语义(读取不存在的属性
|
|
17
|
+
* 渲染为空),必须保留动态求值语义。
|
|
14
18
|
*/
|
|
15
19
|
function handleMemberExpression(expr, ctx) {
|
|
16
|
-
|
|
20
|
+
// key 静态(obj.prop 或 obj['prop'])才可 accessor:字符串字面量 key 原样
|
|
21
|
+
// 透传即为正确的静态 key;标识符(非计算成员)即属性名,由 accessor 构建器字符串化
|
|
22
|
+
const isStaticKey = !expr.computed || t.isStringLiteral(expr.property);
|
|
23
|
+
if (isStaticKey && isIdentifier(expr.object)) {
|
|
17
24
|
markImport(ctx, 'accessor');
|
|
18
25
|
const accessorAlias = getAlias(ctx.vitarxAliases, 'accessor');
|
|
19
26
|
return createAccessorCall(expr.object, expr.property, accessorAlias);
|