@dolphinweex/weex-harmony 0.1.67 → 0.1.68
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.
- package/package.json +1 -1
- package/src/transform-loader.js +49 -21
package/package.json
CHANGED
package/src/transform-loader.js
CHANGED
|
@@ -190,7 +190,25 @@ function getComponentLoc(name) {
|
|
|
190
190
|
return getAbsPath(address)
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
+
//解决v-bind传的是 a.b.c这种 可能a是空导致报错
|
|
193
194
|
function createComputedProperty(vBindValue, computedName) {
|
|
195
|
+
// 使用辅助函数创建成员表达式,支持嵌套属性路径
|
|
196
|
+
const valueExpression = createMemberExpressionFromPath(vBindValue);
|
|
197
|
+
const styleExpression = t.memberExpression(createMemberExpressionFromPath(vBindValue), t.identifier('style'));
|
|
198
|
+
|
|
199
|
+
// 为嵌套路径创建逐级空值检查(如 a.b.c 需要检查 a && a.b && a.b.c)
|
|
200
|
+
const parts = vBindValue.split('.');
|
|
201
|
+
const nullCheckConditions = [];
|
|
202
|
+
for (let i = 0; i < parts.length; i++) {
|
|
203
|
+
nullCheckConditions.push(createMemberExpressionFromPath(parts.slice(0, i + 1).join('.')));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 构建逐级 && 检查表达式
|
|
207
|
+
let nullCheckExpression = nullCheckConditions[0];
|
|
208
|
+
for (let i = 1; i < nullCheckConditions.length; i++) {
|
|
209
|
+
nullCheckExpression = t.logicalExpression('&&', nullCheckExpression, nullCheckConditions[i]);
|
|
210
|
+
}
|
|
211
|
+
|
|
194
212
|
return t.objectProperty(
|
|
195
213
|
t.identifier('computed'), // 为对象添加 computed 属性
|
|
196
214
|
t.objectExpression([ // 计算属性
|
|
@@ -200,31 +218,27 @@ function createComputedProperty(vBindValue, computedName) {
|
|
|
200
218
|
null, //不需要传参
|
|
201
219
|
[],
|
|
202
220
|
t.blockStatement([ // 函数体是一个块语句,包含多个语句
|
|
203
|
-
|
|
221
|
+
// 先判断对象本身是否存在(逐级检查),不存在直接返回空对象
|
|
222
|
+
t.ifStatement(
|
|
223
|
+
t.unaryExpression('!', nullCheckExpression),
|
|
224
|
+
t.blockStatement([
|
|
225
|
+
t.returnStatement(t.objectExpression([]))
|
|
226
|
+
])
|
|
227
|
+
),
|
|
228
|
+
t.ifStatement(// if (this.xxx && this.xxx.style)
|
|
204
229
|
t.logicalExpression(
|
|
205
|
-
'&&', //
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
t.memberExpression(t.thisExpression(), t.identifier(vBindValue)),
|
|
209
|
-
t.identifier('style') // this.scrollerWrapProps.style
|
|
210
|
-
)
|
|
230
|
+
'&&', // 使用逻辑"与"操作符
|
|
231
|
+
valueExpression,
|
|
232
|
+
styleExpression
|
|
211
233
|
),
|
|
212
|
-
t.blockStatement([ //
|
|
234
|
+
t.blockStatement([ // 如果条件符合
|
|
213
235
|
t.expressionStatement(
|
|
214
236
|
t.assignmentExpression(
|
|
215
237
|
'=', // 赋值操作
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
t.identifier('
|
|
219
|
-
|
|
220
|
-
t.callExpression(
|
|
221
|
-
t.identifier('this._px2rem'), // weex._px2remFn 函数
|
|
222
|
-
[//函数传参
|
|
223
|
-
t.memberExpression(
|
|
224
|
-
t.memberExpression(t.thisExpression(), t.identifier(vBindValue)),
|
|
225
|
-
t.identifier('style')
|
|
226
|
-
)
|
|
227
|
-
]
|
|
238
|
+
styleExpression,
|
|
239
|
+
t.callExpression(
|
|
240
|
+
t.memberExpression(t.thisExpression(), t.identifier('_px2rem')), // this._px2rem 函数
|
|
241
|
+
[styleExpression]
|
|
228
242
|
)
|
|
229
243
|
)
|
|
230
244
|
)
|
|
@@ -237,7 +251,7 @@ function createComputedProperty(vBindValue, computedName) {
|
|
|
237
251
|
t.memberExpression(t.identifier('Object'), t.identifier('assign')),
|
|
238
252
|
[
|
|
239
253
|
t.objectExpression([]),
|
|
240
|
-
|
|
254
|
+
valueExpression
|
|
241
255
|
]
|
|
242
256
|
)
|
|
243
257
|
)
|
|
@@ -265,6 +279,20 @@ function getAbsPath(address){
|
|
|
265
279
|
}
|
|
266
280
|
}
|
|
267
281
|
|
|
282
|
+
/**
|
|
283
|
+
* 根据属性路径字符串(如 'a.b.c')创建 AST 成员表达式
|
|
284
|
+
* @param {*} propertyPath 属性路径字符串
|
|
285
|
+
* @returns AST 成员表达式节点
|
|
286
|
+
*/
|
|
287
|
+
function createMemberExpressionFromPath(propertyPath) {
|
|
288
|
+
const parts = propertyPath.split('.');
|
|
289
|
+
let expression = t.memberExpression(t.thisExpression(), t.identifier(parts[0]));
|
|
290
|
+
for (let i = 1; i < parts.length; i++) {
|
|
291
|
+
expression = t.memberExpression(expression, t.identifier(parts[i]));
|
|
292
|
+
}
|
|
293
|
+
return expression;
|
|
294
|
+
}
|
|
295
|
+
|
|
268
296
|
/**
|
|
269
297
|
* 生产SFC代码
|
|
270
298
|
* @param {*} moduleResoveRet
|