@dolphinweex/weex-harmony 0.1.7 → 0.1.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.
package/package.json
CHANGED
@@ -42,6 +42,7 @@ export default {
|
|
42
42
|
width: this.width,
|
43
43
|
height: this.height,
|
44
44
|
data: this.data,
|
45
|
+
handleProgresscycleTap: this.handleProgresscycleTap,
|
45
46
|
};
|
46
47
|
},
|
47
48
|
},
|
@@ -51,6 +52,9 @@ export default {
|
|
51
52
|
},
|
52
53
|
|
53
54
|
methods: {
|
55
|
+
handleProgresscycleTap (res){
|
56
|
+
this.$emit("progresscycleTap", res);
|
57
|
+
},
|
54
58
|
},
|
55
59
|
};
|
56
60
|
</script>
|
package/src/transform-loader.js
CHANGED
@@ -3,7 +3,7 @@ const parser = require('@babel/parser')
|
|
3
3
|
const traverse = require('@babel/traverse').default
|
4
4
|
const generator = require('@babel/generator').default
|
5
5
|
const t = require('@babel/types')
|
6
|
-
const { parse } = require('@dolphinweex/himalaya')
|
6
|
+
const { parse, stringify } = require('@dolphinweex/himalaya')
|
7
7
|
const path = require('path')
|
8
8
|
|
9
9
|
let currentModulePath = ''
|
@@ -21,6 +21,7 @@ const baseUrl = '../src/components/'
|
|
21
21
|
const componentMap = require("./index")
|
22
22
|
|
23
23
|
const componentSet = new Set()
|
24
|
+
const vBindMap = new Map()
|
24
25
|
|
25
26
|
/**
|
26
27
|
* 判断是否为windows环境
|
@@ -72,6 +73,43 @@ function traverseNode(node) {
|
|
72
73
|
if (hasElement) {
|
73
74
|
componentSet.add(componentName)
|
74
75
|
}
|
76
|
+
if (node.attributes) {
|
77
|
+
node.attributes.forEach((attr, index) => {
|
78
|
+
if (attr.key === 'v-bind') {
|
79
|
+
//对象的话
|
80
|
+
if (attr.value.trim().startsWith('{') && attr.value.trim().endsWith('}')) {
|
81
|
+
const parsedAst = parser.parseExpression(attr.value);
|
82
|
+
const styleProperty = parsedAst.properties.find(prop => prop.key && prop.key.name === 'style');
|
83
|
+
if (styleProperty) {
|
84
|
+
const styleValue = styleProperty.value;
|
85
|
+
|
86
|
+
// style 的值套上 _px2rem 方法
|
87
|
+
styleProperty.value = {
|
88
|
+
type: 'CallExpression',
|
89
|
+
callee: {
|
90
|
+
type: 'Identifier',
|
91
|
+
name: '_px2rem'
|
92
|
+
},
|
93
|
+
arguments: [styleValue] // 将原始的 style 对象作为参数传递给 _px2rem
|
94
|
+
};
|
95
|
+
}
|
96
|
+
node.attributes[index] = {
|
97
|
+
key: 'v-bind',
|
98
|
+
value: generator(parsedAst).code
|
99
|
+
};
|
100
|
+
} else {
|
101
|
+
const customComputedName = `customVBindComputed${index}`; // 自定义的名字
|
102
|
+
vBindMap.set(customComputedName, {
|
103
|
+
computedName: attr.value,
|
104
|
+
customComputedName
|
105
|
+
});
|
106
|
+
|
107
|
+
// 更新属性值为自定义名字
|
108
|
+
node.attributes[index].value = customComputedName;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
});
|
112
|
+
}
|
75
113
|
if (node.children) {
|
76
114
|
node.children.forEach((child) => {
|
77
115
|
traverseNode(child)
|
@@ -128,6 +166,56 @@ function getComponentLoc(name) {
|
|
128
166
|
return getAbsPath(address)
|
129
167
|
}
|
130
168
|
}
|
169
|
+
function createComputedProperty(vBindValue, computedName) {
|
170
|
+
return t.objectProperty(
|
171
|
+
t.identifier('computed'), // 为对象添加 computed 属性
|
172
|
+
t.objectExpression([ // 计算属性
|
173
|
+
t.objectProperty(
|
174
|
+
t.identifier(computedName), // 计算属性的名称
|
175
|
+
t.functionExpression( // 计算属性的值是一个函数
|
176
|
+
null, //不需要传参
|
177
|
+
[],
|
178
|
+
t.blockStatement([ // 函数体是一个块语句,包含多个语句
|
179
|
+
t.ifStatement(// if (this.scrollerWrapProps && this.scrollerWrapProps.style)
|
180
|
+
t.logicalExpression(
|
181
|
+
'&&', // 使用逻辑“与”操作符
|
182
|
+
t.memberExpression(t.thisExpression(), t.identifier(vBindValue)), // this.scrollerWrapProps
|
183
|
+
t.memberExpression(
|
184
|
+
t.memberExpression(t.thisExpression(), t.identifier(vBindValue)),
|
185
|
+
t.identifier('style') // this.scrollerWrapProps.style
|
186
|
+
)
|
187
|
+
),
|
188
|
+
t.blockStatement([ // 如果条件符合妖气
|
189
|
+
t.expressionStatement(
|
190
|
+
t.assignmentExpression(
|
191
|
+
'=', // 赋值操作
|
192
|
+
t.memberExpression(
|
193
|
+
t.memberExpression(t.thisExpression(), t.identifier(vBindValue)),
|
194
|
+
t.identifier('style') // this.scrollerWrapProps.style
|
195
|
+
),
|
196
|
+
t.callExpression(
|
197
|
+
t.identifier('this._px2rem'), // weex._px2remFn 函数
|
198
|
+
[//函数传参
|
199
|
+
t.memberExpression(
|
200
|
+
t.memberExpression(t.thisExpression(), t.identifier(vBindValue)),
|
201
|
+
t.identifier('style')
|
202
|
+
)
|
203
|
+
]
|
204
|
+
)
|
205
|
+
)
|
206
|
+
)
|
207
|
+
]),
|
208
|
+
),
|
209
|
+
t.returnStatement( //return 值
|
210
|
+
t.memberExpression(t.thisExpression(), t.identifier(vBindValue)) // this.scrollerWrapProps
|
211
|
+
)
|
212
|
+
])
|
213
|
+
)
|
214
|
+
)
|
215
|
+
])
|
216
|
+
);
|
217
|
+
}
|
218
|
+
|
131
219
|
|
132
220
|
/**
|
133
221
|
* 根据引入的路径获取组件导入的路径
|
@@ -198,24 +286,70 @@ function addComponentsProperty(data) {
|
|
198
286
|
})
|
199
287
|
}
|
200
288
|
}
|
289
|
+
function addComputedPropertyToScript(scriptAst, vBindMap) {
|
290
|
+
vBindMap.forEach((obj,customComputedName) => {
|
291
|
+
const computedProperty = createComputedProperty(obj.computedName, customComputedName);
|
292
|
+
traverse(scriptAst, {
|
293
|
+
ObjectExpression(path) { //对象key value
|
294
|
+
const computedNode = path.node.properties.find(
|
295
|
+
(property) => property.key && property.key.name === 'computed'
|
296
|
+
);
|
297
|
+
if (computedNode) { // 如果找到了computed,检查是否已经存在该计算属性
|
298
|
+
const existingProperty = computedNode.value.properties.find(
|
299
|
+
(property) => property.key && property.key.name === customComputedName
|
300
|
+
);
|
301
|
+
|
302
|
+
if (!existingProperty) { // 如果没有相同名称的计算属性,插入新计算属性
|
303
|
+
computedNode.value.properties.push(computedProperty.value.properties[0]);
|
304
|
+
}
|
305
|
+
}
|
306
|
+
},
|
307
|
+
// 判断computed是否存在
|
308
|
+
ExportDefaultDeclaration(path) {
|
309
|
+
if (t.isObjectExpression(path.node.declaration)) {
|
310
|
+
const properties = path.node.declaration.properties;
|
311
|
+
let computedPropertyNode = properties.find((item) => item.key.name === 'computed');
|
312
|
+
if (!computedPropertyNode) {//创建
|
313
|
+
computedPropertyNode = t.objectProperty(t.identifier('computed'), t.objectExpression([]));
|
314
|
+
properties.push(computedPropertyNode);
|
315
|
+
}
|
316
|
+
// 继续检查是否已存在相同名称的计算属性
|
317
|
+
const existingProperty = computedPropertyNode.value.properties.find(
|
318
|
+
(property) => property.key && property.key.name === customComputedName
|
319
|
+
);
|
320
|
+
|
321
|
+
if (!existingProperty) {
|
322
|
+
computedPropertyNode.value.properties.push(computedProperty.value.properties[0]);
|
323
|
+
}
|
324
|
+
}
|
325
|
+
}
|
326
|
+
});
|
327
|
+
});
|
328
|
+
}
|
201
329
|
|
202
330
|
module.exports = function (source) {
|
203
331
|
if (process.env.ISHARMONY === 'true') {
|
204
332
|
currentModulePath = this.resourcePath
|
205
333
|
const moduleResoveRet = compiler.parseComponent(source)
|
206
|
-
|
334
|
+
let {
|
335
|
+
template,
|
336
|
+
script,
|
337
|
+
styles
|
338
|
+
} = moduleResoveRet
|
207
339
|
const tempAst = parse(template.content)
|
208
340
|
tempAst.forEach((node) => {
|
209
341
|
traverseNode(node)
|
210
342
|
})
|
211
|
-
|
212
|
-
|
343
|
+
|
344
|
+
moduleResoveRet.template.content = stringify(tempAst);
|
345
|
+
|
346
|
+
const scriptAst = parser.parse(script.content, {
|
347
|
+
sourceType: 'module',
|
348
|
+
// 在此添加需要解析的插件
|
349
|
+
})
|
350
|
+
|
351
|
+
// 单模块中引入了自定义组件 if (componentSet.size !== 0) {
|
213
352
|
if (componentSet.size !== 0) {
|
214
|
-
const scriptAst = parser.parse(script.content, {
|
215
|
-
sourceType: 'module',
|
216
|
-
// 在此添加需要解析的插件
|
217
|
-
})
|
218
|
-
|
219
353
|
traverse(scriptAst, {
|
220
354
|
Program(path) {
|
221
355
|
componentSet.forEach((componentName) => {
|
@@ -260,14 +394,21 @@ module.exports = function (source) {
|
|
260
394
|
}
|
261
395
|
}
|
262
396
|
})
|
263
|
-
|
264
397
|
// 清除componentSet中的缓存,准备进入下次循环
|
265
398
|
componentSet.clear()
|
399
|
+
}
|
266
400
|
|
267
|
-
|
268
|
-
|
269
|
-
|
401
|
+
if (vBindMap.size !== 0) {
|
402
|
+
addComputedPropertyToScript(scriptAst, vBindMap);
|
403
|
+
vBindMap.clear()
|
270
404
|
}
|
405
|
+
|
406
|
+
const {
|
407
|
+
code
|
408
|
+
} = generator(scriptAst)
|
409
|
+
moduleResoveRet.script.content = code
|
410
|
+
source = generateCode(moduleResoveRet)
|
271
411
|
}
|
272
412
|
return source
|
413
|
+
|
273
414
|
}
|
package/src/.DS_Store
DELETED
Binary file
|
package/src/components/.DS_Store
DELETED
Binary file
|