@aiot-toolkit/parser 2.0.5-widget-provider-beta.2 → 2.0.5

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.
Files changed (49) hide show
  1. package/README.md +11 -11
  2. package/lib/utils/ParserUtil.js +15 -15
  3. package/lib/ux/config/ExtensionConfig.js +2 -2
  4. package/lib/ux/config/FeatureConfig.js +19 -19
  5. package/lib/ux/config/vela/ElementConfig.js +0 -8
  6. package/lib/ux/config/vela/StyleAttributeConfig.js +134 -88
  7. package/lib/ux/enum/StyleSelectorType.js +6 -6
  8. package/lib/ux/enum/TemplateNodeType.js +2 -2
  9. package/lib/ux/enum/android/StyleSelectorName.js +2 -2
  10. package/lib/ux/interface/IUxAst.d.ts +2 -0
  11. package/lib/ux/parser/ScriptParser.js +2 -2
  12. package/lib/ux/parser/StyleParser.js +79 -72
  13. package/lib/ux/parser/TemplateValueParser.js +49 -49
  14. package/lib/ux/parser/UxParser.js +18 -12
  15. package/lib/ux/translate/android/StyleToTypescript.js +51 -51
  16. package/lib/ux/translate/android/TemplateToTypescript.js +51 -51
  17. package/lib/ux/translate/android/UxToTypescript.js +14 -14
  18. package/lib/ux/translate/android/attributeTranslate/ForTranslate.js +17 -17
  19. package/lib/ux/translate/android/attributeTranslate/IfTranslate.js +9 -9
  20. package/lib/ux/translate/vela/ScriptToTypescript.js +10 -10
  21. package/lib/ux/translate/vela/StyleToTypescript.js +10 -10
  22. package/lib/ux/translate/vela/TemplateToTypescript.js +74 -74
  23. package/lib/ux/translate/vela/TranslateCache.js +2 -2
  24. package/lib/ux/translate/vela/UxToTypescript.js +6 -6
  25. package/lib/ux/translate/vela/VelaContext.js +2 -2
  26. package/lib/ux/translate/vela/plugins/e2e.js +63 -62
  27. package/lib/ux/translate/vela/plugins/startPage.js +1 -1
  28. package/lib/ux/translate/vela/protobuf/BinaryPlugin.js +172 -172
  29. package/lib/ux/translate/vela/protobuf/protobuf.js +235 -235
  30. package/lib/ux/translate/vela/protobuf/protobufControl.js +159 -159
  31. package/lib/ux/translate/vela/protobuf/vdom_pb.js +2374 -2374
  32. package/lib/ux/translate/vela/runtime/velaTestLibrary.js +104 -104
  33. package/lib/ux/translate/vela/utils/AttributeConfig.js +15 -15
  34. package/lib/ux/translate/vela/utils/ExtendedBoxStyle.js +38 -38
  35. package/lib/ux/translate/vela/utils/SourceMapUtil.d.ts +0 -4
  36. package/lib/ux/translate/vela/utils/SourceMapUtil.js +30 -36
  37. package/lib/ux/translate/vela/utils/TemplateUtil.js +180 -180
  38. package/lib/ux/translate/vela/wrap/CbTranslate.js +8 -8
  39. package/lib/ux/translate/vela/wrap/CfTranslate.js +14 -14
  40. package/lib/ux/translate/vela/wrap/CiTranslate.js +11 -11
  41. package/lib/ux/utils/BabelUtil.js +35 -35
  42. package/lib/ux/utils/ElementConfigUtil.js +24 -24
  43. package/lib/ux/utils/StyleMapUtil.js +15 -15
  44. package/lib/ux/utils/StyleUtil.d.ts +1 -1
  45. package/lib/ux/utils/StyleUtil.js +192 -248
  46. package/lib/ux/utils/UxUtil.js +32 -32
  47. package/lib/ux/validate/ElementValidate.js +2 -2
  48. package/lib/ux/validate/UxFileValidate.js +2 -2
  49. package/package.json +4 -4
@@ -1,104 +1,104 @@
1
- /*
2
- * Copyright (C) 2017, hapjs.org. All rights reserved.
3
- */
4
-
5
- /**
6
- * assert文档:http://chaijs.com/api/assert/
7
- */
8
-
9
- const chai = require('vela-chai')
10
- const quickAppText = require('vela-quickapp-test')
11
-
12
- // 注入全局
13
- global.assert = chai.assert
14
-
15
- for (let key in quickAppText) {
16
- global[key] = quickAppText[key]
17
- }
18
-
19
- /**
20
- * 标准化(去除px单位、合并或者展开、尺寸标准化)
21
- */
22
- global.normalize = function (map) {
23
- map = map || {}
24
-
25
- Object.keys(map).forEach(function (key) {
26
- // 去除px单位
27
- map[key] && map[key].replace && (map[key] = map[key].replace(/px/g, ''))
28
- let val = map[key]
29
-
30
- // 合并或者展开
31
- if (['margin', 'padding', 'borderWidth', 'borderColor'].indexOf(key) > -1 && /\s+/.test(val)) {
32
- const valList = val.replace(/,\s+/g, ',').split(/\s+/)
33
- const valHash = valList.reduce((sum, v) => {
34
- sum[v] = true
35
- return sum
36
- }, {})
37
-
38
- if (Object.keys(valHash).length === 1) {
39
- // 合并
40
- map[key] = valList[0]
41
- } else {
42
- // 完全展开
43
- }
44
- }
45
-
46
- // 750标准尺寸
47
- val = map[key]
48
- if (/^\d*\.?\d*$/.test(val) && !isNaN(parseFloat(val))) {
49
- map[key] = +val
50
- // 标准尺寸
51
- map[key + 'Std'] = Math.round((map[key] * global.Env.designWidth) / global.Env.deviceWidth)
52
- }
53
- })
54
- return map
55
- }
56
-
57
- /**
58
- * 获取宽高以及相对距离
59
- * @desc 相当于 node.getBoundingRect()
60
- * @param ref
61
- * @return {*|{content}|{}}
62
- */
63
- global.nodeRect = function (ref) {
64
- // Node节点转换
65
- ref = ref.ref || ref
66
-
67
- return global.model.getBoundingRect({ ref: ref }) || {}
68
- }
69
-
70
- /**
71
- * 获取设置的节点属性
72
- * @param ref
73
- * @return {*|{}}
74
- */
75
- global.nodeAttr = function (ref) {
76
- // Node节点转换
77
- ref = ref.ref || ref
78
-
79
- return global.model.getComputedAttr({ ref: ref }) || {}
80
- }
81
-
82
- /**
83
- * 获取设置的节点样式
84
- * @param ref
85
- * @return {*|{content}|CSSStyleDeclaration|CssStyle|{}}
86
- */
87
- global.nodeStyle = function (ref) {
88
- // Node节点转换
89
- ref = ref.ref || ref
90
-
91
- return global.model.getComputedStyle({ ref: ref }) || {}
92
- }
93
-
94
- /**
95
- * 获取节点信息
96
- * @param ref
97
- * @return {*|{content}|{}}
98
- */
99
- global.nodeInfo = function (ref) {
100
- // Node节点转换
101
- ref = ref.ref || ref
102
-
103
- return global.model.getComponent({ ref: ref }) || {}
104
- }
1
+ /*
2
+ * Copyright (C) 2017, hapjs.org. All rights reserved.
3
+ */
4
+
5
+ /**
6
+ * assert文档:http://chaijs.com/api/assert/
7
+ */
8
+
9
+ const chai = require('vela-chai')
10
+ const quickAppText = require('vela-quickapp-test')
11
+
12
+ // 注入全局
13
+ global.assert = chai.assert
14
+
15
+ for (let key in quickAppText) {
16
+ global[key] = quickAppText[key]
17
+ }
18
+
19
+ /**
20
+ * 标准化(去除px单位、合并或者展开、尺寸标准化)
21
+ */
22
+ global.normalize = function (map) {
23
+ map = map || {}
24
+
25
+ Object.keys(map).forEach(function (key) {
26
+ // 去除px单位
27
+ map[key] && map[key].replace && (map[key] = map[key].replace(/px/g, ''))
28
+ let val = map[key]
29
+
30
+ // 合并或者展开
31
+ if (['margin', 'padding', 'borderWidth', 'borderColor'].indexOf(key) > -1 && /\s+/.test(val)) {
32
+ const valList = val.replace(/,\s+/g, ',').split(/\s+/)
33
+ const valHash = valList.reduce((sum, v) => {
34
+ sum[v] = true
35
+ return sum
36
+ }, {})
37
+
38
+ if (Object.keys(valHash).length === 1) {
39
+ // 合并
40
+ map[key] = valList[0]
41
+ } else {
42
+ // 完全展开
43
+ }
44
+ }
45
+
46
+ // 750标准尺寸
47
+ val = map[key]
48
+ if (/^\d*\.?\d*$/.test(val) && !isNaN(parseFloat(val))) {
49
+ map[key] = +val
50
+ // 标准尺寸
51
+ map[key + 'Std'] = Math.round((map[key] * global.Env.designWidth) / global.Env.deviceWidth)
52
+ }
53
+ })
54
+ return map
55
+ }
56
+
57
+ /**
58
+ * 获取宽高以及相对距离
59
+ * @desc 相当于 node.getBoundingRect()
60
+ * @param ref
61
+ * @return {*|{content}|{}}
62
+ */
63
+ global.nodeRect = function (ref) {
64
+ // Node节点转换
65
+ ref = ref.ref || ref
66
+
67
+ return global.model.getBoundingRect({ ref: ref }) || {}
68
+ }
69
+
70
+ /**
71
+ * 获取设置的节点属性
72
+ * @param ref
73
+ * @return {*|{}}
74
+ */
75
+ global.nodeAttr = function (ref) {
76
+ // Node节点转换
77
+ ref = ref.ref || ref
78
+
79
+ return global.model.getComputedAttr({ ref: ref }) || {}
80
+ }
81
+
82
+ /**
83
+ * 获取设置的节点样式
84
+ * @param ref
85
+ * @return {*|{content}|CSSStyleDeclaration|CssStyle|{}}
86
+ */
87
+ global.nodeStyle = function (ref) {
88
+ // Node节点转换
89
+ ref = ref.ref || ref
90
+
91
+ return global.model.getComputedStyle({ ref: ref }) || {}
92
+ }
93
+
94
+ /**
95
+ * 获取节点信息
96
+ * @param ref
97
+ * @return {*|{content}|{}}
98
+ */
99
+ global.nodeInfo = function (ref) {
100
+ // Node节点转换
101
+ ref = ref.ref || ref
102
+
103
+ return global.model.getComponent({ ref: ref }) || {}
104
+ }
@@ -100,11 +100,11 @@ const ATTRIBUTE_CONFIG = {
100
100
  }
101
101
  };
102
102
 
103
- /**
104
- * 转换动态值的默认方法
105
- * @param value
106
- * @param disabledWrap 是否禁用函数包裹。因为普通属性不用函数无法动态响应,而 for 的 list 属性设置函数又报错;所以这里临时加一个参数,在生成__list__的地方手动设置为 true
107
- * @returns
103
+ /**
104
+ * 转换动态值的默认方法
105
+ * @param value
106
+ * @param disabledWrap 是否禁用函数包裹。因为普通属性不用函数无法动态响应,而 for 的 list 属性设置函数又报错;所以这里临时加一个参数,在生成__list__的地方手动设置为 true
107
+ * @returns
108
108
  */
109
109
  const defaultAttributeTranslate = function (value) {
110
110
  let disabledWrap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -114,16 +114,16 @@ const defaultAttributeTranslate = function (value) {
114
114
  return `function() { return ${value} }`;
115
115
  };
116
116
 
117
- /**
118
- * 转换事件属性的值
119
- *
120
- * 1. 普通函数不转换: function(){}
121
- * 2. 函数名:_vm_.a 转换为 _vm_.a(event)
122
- * 3. 函数调用:_vm_.a(x, y) 转换为 _vm_.a(x, y, event)
123
- * 4. 箭头函数不转换: ()=>{}
124
- *
125
- * @param value
126
- * @returns
117
+ /**
118
+ * 转换事件属性的值
119
+ *
120
+ * 1. 普通函数不转换: function(){}
121
+ * 2. 函数名:_vm_.a 转换为 _vm_.a(event)
122
+ * 3. 函数调用:_vm_.a(x, y) 转换为 _vm_.a(x, y, event)
123
+ * 4. 箭头函数不转换: ()=>{}
124
+ *
125
+ * @param value
126
+ * @returns
127
127
  */
128
128
  exports.defaultAttributeTranslate = defaultAttributeTranslate;
129
129
  const eventAttributeTranslate = (options, value, attribute) => {
@@ -12,12 +12,12 @@ const borderWidthList = ['thin', 'medium', 'thick'];
12
12
  const borderStyleList = ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset'];
13
13
  const timingFunctions = ['linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out', 'cubic-bezier', 'step-start', 'step-end', 'jump-start', 'jump-end', 'jump-none', 'jump-both', 'start', 'end'];
14
14
  const REGEXP_PROPERTY_NAME = /^[a-zA-Z-]+[a-zA-Z0-9-]*/;
15
- /**
16
- * ExtendedBoxStyle
15
+ /**
16
+ * ExtendedBoxStyle
17
17
  */
18
18
 
19
- /**
20
- * ExtendedBoxStyle
19
+ /**
20
+ * ExtendedBoxStyle
21
21
  */
22
22
  class ExtendedBoxStyle {
23
23
  static extendBoxStyle(sourceNode) {
@@ -47,14 +47,14 @@ class ExtendedBoxStyle {
47
47
  }
48
48
  return targetList;
49
49
  }
50
- /**
51
- * 扩展border样式
52
- * 扩展border的前提是border的格式符合CSS标准
53
- * 1. 展开border节点为borderWidth、borderStyle、borderColor
54
- * 2. 扩展borderWidth、borderColor属性
55
- * 3. 将border[Left、Right、Top、Bottom]由第1步生成的结果赋值给targetList
56
- * @param sourceNode
57
- * @param targetList
50
+ /**
51
+ * 扩展border样式
52
+ * 扩展border的前提是border的格式符合CSS标准
53
+ * 1. 展开border节点为borderWidth、borderStyle、borderColor
54
+ * 2. 扩展borderWidth、borderColor属性
55
+ * 3. 将border[Left、Right、Top、Bottom]由第1步生成的结果赋值给targetList
56
+ * @param sourceNode
57
+ * @param targetList
58
58
  */
59
59
  static extendBorderStyle(sourceNode, targetList) {
60
60
  const {
@@ -106,15 +106,15 @@ class ExtendedBoxStyle {
106
106
  break;
107
107
  }
108
108
  }
109
- /**
110
- * 扩展元素与位置
111
- * margin->0:'marginTop', 1:'marginRight', 2:'marginBottom', 3:'marginLeft'
112
- * 解析时,只有valueList.length > 1才会返回列表
113
- * 1. 节点值为数组且长度大于1时,待扩展值顺序为数组值的顺序
114
- * 2. 若待扩展元素无对应数组值,则取对称位置的数组值index-2
115
- * 3. 节点值为非数组,则取对应节点值即可
116
- * @param sourceNode
117
- * @param targetList
109
+ /**
110
+ * 扩展元素与位置
111
+ * margin->0:'marginTop', 1:'marginRight', 2:'marginBottom', 3:'marginLeft'
112
+ * 解析时,只有valueList.length > 1才会返回列表
113
+ * 1. 节点值为数组且长度大于1时,待扩展值顺序为数组值的顺序
114
+ * 2. 若待扩展元素无对应数组值,则取对称位置的数组值index-2
115
+ * 3. 节点值为非数组,则取对应节点值即可
116
+ * @param sourceNode
117
+ * @param targetList
118
118
  */
119
119
  static extendPosition(sourceNode, targetList) {
120
120
  const {
@@ -140,19 +140,19 @@ class ExtendedBoxStyle {
140
140
  targetList[namePos] = value;
141
141
  });
142
142
  }
143
- /**
144
- * 按照大写字符拆分字符串
145
- * bordeWidth -> border,width
146
- * @param str
147
- * @returns
143
+ /**
144
+ * 按照大写字符拆分字符串
145
+ * bordeWidth -> border,width
146
+ * @param str
147
+ * @returns
148
148
  */
149
149
  static splitByUppercase(str) {
150
150
  return str.split(/(?=[A-Z])/);
151
151
  }
152
- /**
153
- * 展开border的每个值
154
- * @param sourceNode
155
- * @param extendedBorder
152
+ /**
153
+ * 展开border的每个值
154
+ * @param sourceNode
155
+ * @param extendedBorder
156
156
  */
157
157
  static extendValueTypeNode(sourceNode, extendedBorder, name) {
158
158
  // border borderLeft ---> borderWidth borderLeftWidth
@@ -168,18 +168,18 @@ class ExtendedBoxStyle {
168
168
  extendedBorder[color] = value;
169
169
  }
170
170
  }
171
- /**
172
- * 判断border节点值是否有borderWidth
173
- * @param nodeValue
174
- * @returns
171
+ /**
172
+ * 判断border节点值是否有borderWidth
173
+ * @param nodeValue
174
+ * @returns
175
175
  */
176
176
  static isBorderWidth(nodeValue) {
177
177
  return unitList.indexOf(nodeValue.unit) > -1 || borderWidthList.indexOf(nodeValue.value) > -1;
178
178
  }
179
- /**
180
- * 第一个时间为 transitionDuration
181
- * @param sourceNode
182
- * @param targetList
179
+ /**
180
+ * 第一个时间为 transitionDuration
181
+ * @param sourceNode
182
+ * @param targetList
183
183
  */
184
184
  static extendTransition(sourceNode, targetList) {
185
185
  // 默认值
@@ -52,9 +52,5 @@ declare class SourceMapUtil {
52
52
  * @returns
53
53
  */
54
54
  static countStatementLines(originStr: string): number;
55
- /**
56
- * 拼接正文和source map
57
- */
58
- static concatSourceMap(content: string, sourceMap: string): string;
59
55
  }
60
56
  export default SourceMapUtil;
@@ -5,16 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _sourceMap = require("source-map");
8
- /**
9
- * SourceMapUtil
8
+ /**
9
+ * SourceMapUtil
10
10
  */
11
11
  class SourceMapUtil {
12
- /**
13
- * 更新source map
14
- * @param sourceMapStr 更新前的source map字符串
15
- * @param offsetInfo 目标代码合并时用到的偏移量
16
- * @param options
17
- * @returns 返回更新了map的generator对象
12
+ /**
13
+ * 更新source map
14
+ * @param sourceMapStr 更新前的source map字符串
15
+ * @param offsetInfo 目标代码合并时用到的偏移量
16
+ * @param options
17
+ * @returns 返回更新了map的generator对象
18
18
  */
19
19
  static async updateSourceMap(sourceMapStr, offsetInfo, options) {
20
20
  if (!sourceMapStr) {
@@ -30,10 +30,10 @@ class SourceMapUtil {
30
30
  tempGenerator.setSourceContent(consumer.sources[0], options.content);
31
31
  return tempGenerator;
32
32
  }
33
- /**
34
- * 基于sourceMap字符串创建一个consumer对象、一个mappings为空的tempGenerator对象
35
- * @param sourceMap
36
- * @returns
33
+ /**
34
+ * 基于sourceMap字符串创建一个consumer对象、一个mappings为空的tempGenerator对象
35
+ * @param sourceMap
36
+ * @returns
37
37
  */
38
38
  static async createConsumerAndGenerator(sourceMap) {
39
39
  const consumer = await new _sourceMap.SourceMapConsumer(sourceMap);
@@ -44,10 +44,10 @@ class SourceMapUtil {
44
44
  tempGenerator
45
45
  };
46
46
  }
47
- /**
48
- * 创建一个mappings为空的tempGenerator对象
49
- * @param sourceMap
50
- * @returns
47
+ /**
48
+ * 创建一个mappings为空的tempGenerator对象
49
+ * @param sourceMap
50
+ * @returns
51
51
  */
52
52
  static async createTempGenerator(sourceMap) {
53
53
  const tempSourceMap = JSON.parse(sourceMap);
@@ -55,11 +55,11 @@ class SourceMapUtil {
55
55
  const tempConsumer = await new _sourceMap.SourceMapConsumer(tempSourceMap);
56
56
  return _sourceMap.SourceMapGenerator.fromSourceMap(tempConsumer);
57
57
  }
58
- /**
59
- * 更新tempGenerator的mappings
60
- * @param consumer 更新前mappings存储在该对象中
61
- * @param tempGenerator 待更新mappings的对象
62
- * @param updateInfo 传递更新过程中使用的偏移量
58
+ /**
59
+ * 更新tempGenerator的mappings
60
+ * @param consumer 更新前mappings存储在该对象中
61
+ * @param tempGenerator 待更新mappings的对象
62
+ * @param updateInfo 传递更新过程中使用的偏移量
63
63
  */
64
64
  static updateMappings(consumer, tempGenerator, updateInfo) {
65
65
  consumer.eachMapping(mapping => {
@@ -81,11 +81,11 @@ class SourceMapUtil {
81
81
  });
82
82
  });
83
83
  }
84
- /**
85
- * 从babel后的代码中切割出源码和source map
86
- * @param appScriptTree
87
- * @param project
88
- * @returns
84
+ /**
85
+ * 从babel后的代码中切割出源码和source map
86
+ * @param appScriptTree
87
+ * @param project
88
+ * @returns
89
89
  */
90
90
  static splitSourceMap(appScriptTree) {
91
91
  // 取出script中的source map
@@ -102,10 +102,10 @@ class SourceMapUtil {
102
102
  scriptSourceMap: result[1] ? Buffer.from(result[1], 'base64').toString() : ''
103
103
  };
104
104
  }
105
- /**
106
- * 计算addStatments中字符串所占行数
107
- * @param str
108
- * @returns
105
+ /**
106
+ * 计算addStatments中字符串所占行数
107
+ * @param str
108
+ * @returns
109
109
  */
110
110
  static countStatementLines(originStr) {
111
111
  if (!originStr) {
@@ -114,11 +114,5 @@ class SourceMapUtil {
114
114
  let lineCount = (originStr.match(/\n/g) || []).length + 1;
115
115
  return lineCount;
116
116
  }
117
- /**
118
- * 拼接正文和source map
119
- */
120
- static concatSourceMap(content, sourceMap) {
121
- return `${content}\n//# sourceMappingURL=data:application/json;base64,${Buffer.from(sourceMap).toString('base64')}`;
122
- }
123
117
  }
124
118
  var _default = exports.default = SourceMapUtil;