@aiot-toolkit/parser 2.0.6-beta.4 → 2.0.6-beta.6
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/lib/ux/config/vela/ElementConfig.js +6 -0
- package/lib/ux/parser/StyleParser.js +1 -13
- package/lib/ux/translate/vela/StyleToTypescript.js +1 -10
- package/lib/ux/translate/vela/utils/TemplateUtil.d.ts +5 -3
- package/lib/ux/translate/vela/utils/TemplateUtil.js +187 -180
- package/lib/ux/utils/StyleUtil.d.ts +2 -1
- package/lib/ux/utils/StyleUtil.js +10 -21
- package/package.json +4 -4
|
@@ -598,17 +598,10 @@ class StyleParser {
|
|
|
598
598
|
let errors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
599
599
|
let isParserError = errorType === 'parserError';
|
|
600
600
|
let sourceCodeStyle = _sharedUtils.Loglevel.WARN;
|
|
601
|
-
const {
|
|
602
|
-
onLog,
|
|
603
|
-
filePath
|
|
604
|
-
} = this.options;
|
|
605
601
|
if (isParserError) {
|
|
606
602
|
sourceCodeStyle = _sharedUtils.Loglevel.ERROR;
|
|
607
603
|
}
|
|
608
604
|
errors.forEach(error => {
|
|
609
|
-
const sourceCode = error.source ? [`, source code:`, {
|
|
610
|
-
word: `${error.source}`
|
|
611
|
-
}] : [];
|
|
612
605
|
const position = this.styleMapUtil.transfromLocToPosition({
|
|
613
606
|
start: {
|
|
614
607
|
line: error.startLine,
|
|
@@ -624,12 +617,7 @@ class StyleParser {
|
|
|
624
617
|
});
|
|
625
618
|
position.startColumn++;
|
|
626
619
|
position.endColumn++;
|
|
627
|
-
|
|
628
|
-
level: sourceCodeStyle,
|
|
629
|
-
filePath,
|
|
630
|
-
position,
|
|
631
|
-
message: [...error.messages, ...sourceCode]
|
|
632
|
-
});
|
|
620
|
+
_StyleUtil.default.handleStyleError(sourceCodeStyle, error.messages, this.options, position);
|
|
633
621
|
});
|
|
634
622
|
return [];
|
|
635
623
|
}
|
|
@@ -137,10 +137,6 @@ class StyleToTypescript {
|
|
|
137
137
|
* @param name
|
|
138
138
|
*/
|
|
139
139
|
addThorwLog(type, name, position, info) {
|
|
140
|
-
const {
|
|
141
|
-
onLog,
|
|
142
|
-
filePath
|
|
143
|
-
} = this.options;
|
|
144
140
|
const logLevel = name === ' ' || name === '>' ? _sharedUtils.Loglevel.WARN : _sharedUtils.Loglevel.THROW;
|
|
145
141
|
const message = info ? [`### StyleToTypescript ### Selector type unsupport`, {
|
|
146
142
|
word: info
|
|
@@ -149,12 +145,7 @@ class StyleToTypescript {
|
|
|
149
145
|
}, ',name:', {
|
|
150
146
|
word: name
|
|
151
147
|
}];
|
|
152
|
-
|
|
153
|
-
filePath,
|
|
154
|
-
position,
|
|
155
|
-
level: logLevel,
|
|
156
|
-
message
|
|
157
|
-
});
|
|
148
|
+
_StyleUtil.default.handleStyleError(logLevel, message, this.options, position);
|
|
158
149
|
}
|
|
159
150
|
translateAtrule(sourceNode) {
|
|
160
151
|
let targetNodes = [];
|
|
@@ -261,10 +261,10 @@ declare class TemplateUtil {
|
|
|
261
261
|
* 获取节点中的文字内容
|
|
262
262
|
*
|
|
263
263
|
* 1. 如果是文字元素,返回 value
|
|
264
|
-
*
|
|
264
|
+
* 2. 循环子元素列表
|
|
265
265
|
* 1. 如果子元素是文本,直接返回内容
|
|
266
266
|
* 2. 否则,如果子元素允许文本,则递归获取结果
|
|
267
|
-
*
|
|
267
|
+
* 3. 文字中连续的特定符号[\r\n\t ]
|
|
268
268
|
* 1. 首尾的替换为空字符串
|
|
269
269
|
* 2. 其它替换为1个空格
|
|
270
270
|
*
|
|
@@ -273,7 +273,9 @@ declare class TemplateUtil {
|
|
|
273
273
|
* a
|
|
274
274
|
* b
|
|
275
275
|
*
|
|
276
|
-
* `
|
|
276
|
+
* `
|
|
277
|
+
* -->
|
|
278
|
+
* `a b`
|
|
277
279
|
*
|
|
278
280
|
* @param node
|
|
279
281
|
*/
|
|
@@ -20,8 +20,8 @@ var _reservedWords = _interopRequireDefault(require("reserved-words"));
|
|
|
20
20
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
21
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
22
22
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
23
|
-
/**
|
|
24
|
-
* TemplateUtil
|
|
23
|
+
/**
|
|
24
|
+
* TemplateUtil
|
|
25
25
|
*/
|
|
26
26
|
class TemplateUtil {
|
|
27
27
|
static DYNAMIC_REG = '{{([\\s\\S]*?)}}';
|
|
@@ -34,26 +34,26 @@ class TemplateUtil {
|
|
|
34
34
|
this.elementConfigUtil = elementConfigUtil;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/**
|
|
38
|
-
* 属性列表转换为字典格式
|
|
39
|
-
*
|
|
40
|
-
* @param obj
|
|
41
|
-
* @returns
|
|
37
|
+
/**
|
|
38
|
+
* 属性列表转换为字典格式
|
|
39
|
+
*
|
|
40
|
+
* @param obj
|
|
41
|
+
* @returns
|
|
42
42
|
*/
|
|
43
43
|
async attributesToObject(attributes, identifiers, params) {
|
|
44
44
|
if (!attributes || !Array.isArray(attributes)) {
|
|
45
45
|
return {};
|
|
46
46
|
}
|
|
47
47
|
const dataSetStart = TemplateUtil.DATA_SET_START;
|
|
48
|
-
/**
|
|
49
|
-
* 重命名 dataset 属性
|
|
50
|
-
*
|
|
51
|
-
* 1. 去掉data-
|
|
52
|
-
* 2. -字母 转换为大写字母
|
|
53
|
-
*
|
|
54
|
-
* > data-aa-bbb 格式 转换成 aaBbb
|
|
55
|
-
* @param value
|
|
56
|
-
* @returns
|
|
48
|
+
/**
|
|
49
|
+
* 重命名 dataset 属性
|
|
50
|
+
*
|
|
51
|
+
* 1. 去掉data-
|
|
52
|
+
* 2. -字母 转换为大写字母
|
|
53
|
+
*
|
|
54
|
+
* > data-aa-bbb 格式 转换成 aaBbb
|
|
55
|
+
* @param value
|
|
56
|
+
* @returns
|
|
57
57
|
*/
|
|
58
58
|
const renameDatasetAttribute = value => {
|
|
59
59
|
return value.substring(dataSetStart.length).replace(/-([a-z])/g, function (s, m) {
|
|
@@ -100,12 +100,12 @@ class TemplateUtil {
|
|
|
100
100
|
return result;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
/**
|
|
104
|
-
* 转换属性名称
|
|
105
|
-
* 1. 配置中有别名,使用别名
|
|
106
|
-
* 2. 如果是@, on开头,则取@ on后面的文本
|
|
107
|
-
* 3. 原名称
|
|
108
|
-
* @param name
|
|
103
|
+
/**
|
|
104
|
+
* 转换属性名称
|
|
105
|
+
* 1. 配置中有别名,使用别名
|
|
106
|
+
* 2. 如果是@, on开头,则取@ on后面的文本
|
|
107
|
+
* 3. 原名称
|
|
108
|
+
* @param name
|
|
109
109
|
*/
|
|
110
110
|
translateAttributeName(name) {
|
|
111
111
|
const config = _AttributeConfig.default[name];
|
|
@@ -118,16 +118,16 @@ class TemplateUtil {
|
|
|
118
118
|
return name;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
/**
|
|
122
|
-
* 转换属性值
|
|
123
|
-
* 1. 无内容=true
|
|
124
|
-
* 2. 非字符串,直接返回结果
|
|
125
|
-
* 3. 属性值转换为 js 代码
|
|
126
|
-
* a. 如果有单独的配置,则使用配置转换
|
|
127
|
-
* b. 否则,如果是动态值,则分为事件和其它动态值
|
|
128
|
-
* c. 否则,返回源内容
|
|
129
|
-
* @param attribute
|
|
130
|
-
* @returns
|
|
121
|
+
/**
|
|
122
|
+
* 转换属性值
|
|
123
|
+
* 1. 无内容=true
|
|
124
|
+
* 2. 非字符串,直接返回结果
|
|
125
|
+
* 3. 属性值转换为 js 代码
|
|
126
|
+
* a. 如果有单独的配置,则使用配置转换
|
|
127
|
+
* b. 否则,如果是动态值,则分为事件和其它动态值
|
|
128
|
+
* c. 否则,返回源内容
|
|
129
|
+
* @param attribute
|
|
130
|
+
* @returns
|
|
131
131
|
*/
|
|
132
132
|
async translateAttributeValue(attribute, identifiers) {
|
|
133
133
|
let disabledWrap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
@@ -175,21 +175,21 @@ class TemplateUtil {
|
|
|
175
175
|
return result;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
/**
|
|
179
|
-
* 解析模板值
|
|
180
|
-
*
|
|
181
|
-
* 1. 使用TemplateValueParser.parse 解析出结果列表
|
|
182
|
-
* 2. 循环结果列表
|
|
183
|
-
* a. 代码:部分标识符加上前缀
|
|
184
|
-
* b. 文字:加上引号
|
|
185
|
-
* 3. 使用+连接各项结果
|
|
186
|
-
*
|
|
187
|
-
* @param source 模板值的原始内容: a{{b}}c
|
|
188
|
-
* @param identifiers 已存在的标识符. 存在于此参数中的标识符,不加前缀
|
|
189
|
-
* @param options
|
|
190
|
-
* @param ownerNode source 模板值所属的属性节点: for="forvalue", 表示for 这个节点
|
|
191
|
-
*
|
|
192
|
-
* @returns
|
|
178
|
+
/**
|
|
179
|
+
* 解析模板值
|
|
180
|
+
*
|
|
181
|
+
* 1. 使用TemplateValueParser.parse 解析出结果列表
|
|
182
|
+
* 2. 循环结果列表
|
|
183
|
+
* a. 代码:部分标识符加上前缀
|
|
184
|
+
* b. 文字:加上引号
|
|
185
|
+
* 3. 使用+连接各项结果
|
|
186
|
+
*
|
|
187
|
+
* @param source 模板值的原始内容: a{{b}}c
|
|
188
|
+
* @param identifiers 已存在的标识符. 存在于此参数中的标识符,不加前缀
|
|
189
|
+
* @param options
|
|
190
|
+
* @param ownerNode source 模板值所属的属性节点: for="forvalue", 表示for 这个节点
|
|
191
|
+
*
|
|
192
|
+
* @returns
|
|
193
193
|
*/
|
|
194
194
|
translateTemplateValue(source, identifiers, ownerNode) {
|
|
195
195
|
const {
|
|
@@ -198,15 +198,15 @@ class TemplateUtil {
|
|
|
198
198
|
} = this.option;
|
|
199
199
|
const nameLocation = ownerNode?.nameLocation;
|
|
200
200
|
|
|
201
|
-
/**
|
|
202
|
-
* 遍历标识符,如果满足以下条件,不加前缀
|
|
203
|
-
* a. 节点名称在参数的标签符中
|
|
204
|
-
* b. 全局定义: console
|
|
205
|
-
* c. 在局部作用域定义: `const a = 0; log(a)` 中的 a
|
|
206
|
-
* d. 是调用链且是静态值: `data.x` 的 x. *注意*:data[x] 中的 x 是动态值, data[x] --> this.data[this.x]
|
|
207
|
-
* e. 是对象的属性: `{x:**}` 的 x
|
|
208
|
-
* @param code
|
|
209
|
-
* @returns
|
|
201
|
+
/**
|
|
202
|
+
* 遍历标识符,如果满足以下条件,不加前缀
|
|
203
|
+
* a. 节点名称在参数的标签符中
|
|
204
|
+
* b. 全局定义: console
|
|
205
|
+
* c. 在局部作用域定义: `const a = 0; log(a)` 中的 a
|
|
206
|
+
* d. 是调用链且是静态值: `data.x` 的 x. *注意*:data[x] 中的 x 是动态值, data[x] --> this.data[this.x]
|
|
207
|
+
* e. 是对象的属性: `{x:**}` 的 x
|
|
208
|
+
* @param code
|
|
209
|
+
* @returns
|
|
210
210
|
*/
|
|
211
211
|
const translateJsCode = code => {
|
|
212
212
|
const {
|
|
@@ -327,17 +327,17 @@ class TemplateUtil {
|
|
|
327
327
|
})}, ${elementExpression})`;
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
-
/**
|
|
331
|
-
* 创建元素调用表达式
|
|
332
|
-
* ```
|
|
333
|
-
* aiot.__ce__(
|
|
334
|
-
* "div",
|
|
335
|
-
* {name:'div1'},
|
|
336
|
-
* children
|
|
337
|
-
* )
|
|
338
|
-
* ```
|
|
339
|
-
* @param struct
|
|
340
|
-
* @returns
|
|
330
|
+
/**
|
|
331
|
+
* 创建元素调用表达式
|
|
332
|
+
* ```
|
|
333
|
+
* aiot.__ce__(
|
|
334
|
+
* "div",
|
|
335
|
+
* {name:'div1'},
|
|
336
|
+
* children
|
|
337
|
+
* )
|
|
338
|
+
* ```
|
|
339
|
+
* @param struct
|
|
340
|
+
* @returns
|
|
341
341
|
*/
|
|
342
342
|
async createElementCallExpression(struct) {
|
|
343
343
|
const {
|
|
@@ -381,14 +381,14 @@ class TemplateUtil {
|
|
|
381
381
|
return result;
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
-
/**
|
|
385
|
-
* 获取节点指定名称的属性
|
|
386
|
-
*
|
|
387
|
-
* 此方法会排除修饰符,例如<div for.static="123" />;使用getAttribute(node, "for") 仍可取到值
|
|
388
|
-
*
|
|
389
|
-
* @param node
|
|
390
|
-
* @param name
|
|
391
|
-
* @returns
|
|
384
|
+
/**
|
|
385
|
+
* 获取节点指定名称的属性
|
|
386
|
+
*
|
|
387
|
+
* 此方法会排除修饰符,例如<div for.static="123" />;使用getAttribute(node, "for") 仍可取到值
|
|
388
|
+
*
|
|
389
|
+
* @param node
|
|
390
|
+
* @param name
|
|
391
|
+
* @returns
|
|
392
392
|
*/
|
|
393
393
|
static getAttribute(node, name) {
|
|
394
394
|
const {
|
|
@@ -403,14 +403,14 @@ class TemplateUtil {
|
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
-
/**
|
|
407
|
-
* 解析属性名为名称、修饰符
|
|
408
|
-
*
|
|
409
|
-
* 以 attr.x.y.z="123"为例
|
|
410
|
-
* + 属性名使用.分隔为数组 [attr, x, y, z]
|
|
411
|
-
* + 第0项为属性名,1-最后一项为修饰符名
|
|
412
|
-
* @param name
|
|
413
|
-
* @returns
|
|
406
|
+
/**
|
|
407
|
+
* 解析属性名为名称、修饰符
|
|
408
|
+
*
|
|
409
|
+
* 以 attr.x.y.z="123"为例
|
|
410
|
+
* + 属性名使用.分隔为数组 [attr, x, y, z]
|
|
411
|
+
* + 第0项为属性名,1-最后一项为修饰符名
|
|
412
|
+
* @param name
|
|
413
|
+
* @returns
|
|
414
414
|
*/
|
|
415
415
|
static parseAttributeName(name) {
|
|
416
416
|
if (!name) {
|
|
@@ -425,14 +425,14 @@ class TemplateUtil {
|
|
|
425
425
|
};
|
|
426
426
|
}
|
|
427
427
|
|
|
428
|
-
/**
|
|
429
|
-
* 判断是否强制为动态值
|
|
430
|
-
* 1. 事件属性
|
|
431
|
-
* 2. if for
|
|
432
|
-
* 3. 配置值
|
|
433
|
-
* @param nodeName 节点名称
|
|
434
|
-
* @param attributeName 属性名称
|
|
435
|
-
* @returns
|
|
428
|
+
/**
|
|
429
|
+
* 判断是否强制为动态值
|
|
430
|
+
* 1. 事件属性
|
|
431
|
+
* 2. if for
|
|
432
|
+
* 3. 配置值
|
|
433
|
+
* @param nodeName 节点名称
|
|
434
|
+
* @param attributeName 属性名称
|
|
435
|
+
* @returns
|
|
436
436
|
*/
|
|
437
437
|
isForceDynamicAttribute(nodeName, attributeName) {
|
|
438
438
|
const {
|
|
@@ -468,12 +468,12 @@ class TemplateUtil {
|
|
|
468
468
|
return node.nodeName === _TemplateNodeType.default.TEXT;
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
-
/**
|
|
472
|
-
* 是否为节点元素
|
|
473
|
-
*
|
|
474
|
-
* @example <span></span>
|
|
475
|
-
* @param node
|
|
476
|
-
* @returns
|
|
471
|
+
/**
|
|
472
|
+
* 是否为节点元素
|
|
473
|
+
*
|
|
474
|
+
* @example <span></span>
|
|
475
|
+
* @param node
|
|
476
|
+
* @returns
|
|
477
477
|
*/
|
|
478
478
|
static isElement(node) {
|
|
479
479
|
return ![_TemplateNodeType.default.COMMENT, _TemplateNodeType.default.DOCUMENT_TYPE, _TemplateNodeType.default.TEMPLATE, _TemplateNodeType.default.TEXT].includes(node.nodeName);
|
|
@@ -488,20 +488,20 @@ class TemplateUtil {
|
|
|
488
488
|
return name.startsWith(TemplateUtil.DATA_SET_START);
|
|
489
489
|
}
|
|
490
490
|
|
|
491
|
-
/**
|
|
492
|
-
* 是否是 model 指令的属性
|
|
493
|
-
* @param name
|
|
494
|
-
* @returns
|
|
491
|
+
/**
|
|
492
|
+
* 是否是 model 指令的属性
|
|
493
|
+
* @param name
|
|
494
|
+
* @returns
|
|
495
495
|
*/
|
|
496
496
|
static isModelAttribute(name) {
|
|
497
497
|
return name.startsWith('model:');
|
|
498
498
|
}
|
|
499
499
|
|
|
500
|
-
/**
|
|
501
|
-
* 解析model 指令属性的名称为: {modelName: '', modelValue: ''}
|
|
502
|
-
*
|
|
503
|
-
* 例如 `model:abcde="xyz"` 解析为 `{modelName: 'abcde', modelValue:'xyz'}`
|
|
504
|
-
* @param name
|
|
500
|
+
/**
|
|
501
|
+
* 解析model 指令属性的名称为: {modelName: '', modelValue: ''}
|
|
502
|
+
*
|
|
503
|
+
* 例如 `model:abcde="xyz"` 解析为 `{modelName: 'abcde', modelValue:'xyz'}`
|
|
504
|
+
* @param name
|
|
505
505
|
*/
|
|
506
506
|
parseModelAttribute(node) {
|
|
507
507
|
const {
|
|
@@ -519,12 +519,12 @@ class TemplateUtil {
|
|
|
519
519
|
return;
|
|
520
520
|
}
|
|
521
521
|
|
|
522
|
-
/**
|
|
523
|
-
* 值转换为动态值
|
|
524
|
-
*
|
|
525
|
-
* 如果已经是动态值,则不做修改
|
|
526
|
-
* @param value
|
|
527
|
-
* @returns
|
|
522
|
+
/**
|
|
523
|
+
* 值转换为动态值
|
|
524
|
+
*
|
|
525
|
+
* 如果已经是动态值,则不做修改
|
|
526
|
+
* @param value
|
|
527
|
+
* @returns
|
|
528
528
|
*/
|
|
529
529
|
static toDynamicValue(value) {
|
|
530
530
|
if (this.isDynamicValue(value)) {
|
|
@@ -533,12 +533,12 @@ class TemplateUtil {
|
|
|
533
533
|
return `{{${value}}}`;
|
|
534
534
|
}
|
|
535
535
|
|
|
536
|
-
/**
|
|
537
|
-
* 值转换为静态值
|
|
538
|
-
*
|
|
539
|
-
* 已经是静态值,不做修改
|
|
540
|
-
* @param value
|
|
541
|
-
* @returns
|
|
536
|
+
/**
|
|
537
|
+
* 值转换为静态值
|
|
538
|
+
*
|
|
539
|
+
* 已经是静态值,不做修改
|
|
540
|
+
* @param value
|
|
541
|
+
* @returns
|
|
542
542
|
*/
|
|
543
543
|
static toStaticValue(value) {
|
|
544
544
|
if (this.isDynamicValue(value)) {
|
|
@@ -547,22 +547,22 @@ class TemplateUtil {
|
|
|
547
547
|
return value;
|
|
548
548
|
}
|
|
549
549
|
|
|
550
|
-
/**
|
|
551
|
-
* 创建修饰符数据
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
* @example createDecoratorData(node, 'if', 'shown')
|
|
555
|
-
*
|
|
556
|
-
* 如果 node 有 if 属性, 例如<div if.static1.static2="aaa" />,则创建属性名为shown的修改符对象
|
|
557
|
-
* ```
|
|
558
|
-
* {
|
|
559
|
-
* shown:{static1: true,static2: true}
|
|
560
|
-
* }
|
|
561
|
-
* ```
|
|
562
|
-
* @param node
|
|
563
|
-
* @param attributeName
|
|
564
|
-
* @param decoratorName
|
|
565
|
-
* @returns
|
|
550
|
+
/**
|
|
551
|
+
* 创建修饰符数据
|
|
552
|
+
*
|
|
553
|
+
*
|
|
554
|
+
* @example createDecoratorData(node, 'if', 'shown')
|
|
555
|
+
*
|
|
556
|
+
* 如果 node 有 if 属性, 例如<div if.static1.static2="aaa" />,则创建属性名为shown的修改符对象
|
|
557
|
+
* ```
|
|
558
|
+
* {
|
|
559
|
+
* shown:{static1: true,static2: true}
|
|
560
|
+
* }
|
|
561
|
+
* ```
|
|
562
|
+
* @param node
|
|
563
|
+
* @param attributeName
|
|
564
|
+
* @param decoratorName
|
|
565
|
+
* @returns
|
|
566
566
|
*/
|
|
567
567
|
static createDecoratorData(node, attributeName, decoratorName) {
|
|
568
568
|
const attribute = TemplateUtil.getAttribute(node, attributeName);
|
|
@@ -579,13 +579,13 @@ class TemplateUtil {
|
|
|
579
579
|
return undefined;
|
|
580
580
|
}
|
|
581
581
|
|
|
582
|
-
/**
|
|
583
|
-
* 条件列表转换为表达式
|
|
584
|
-
*
|
|
585
|
-
* 转换规则为:前置条件全部取反 && 自身条件
|
|
586
|
-
*
|
|
587
|
-
* @param condition
|
|
588
|
-
* @returns
|
|
582
|
+
/**
|
|
583
|
+
* 条件列表转换为表达式
|
|
584
|
+
*
|
|
585
|
+
* 转换规则为:前置条件全部取反 && 自身条件
|
|
586
|
+
*
|
|
587
|
+
* @param condition
|
|
588
|
+
* @returns
|
|
589
589
|
*/
|
|
590
590
|
genIfConditionList(condition, identifiers) {
|
|
591
591
|
const {
|
|
@@ -598,14 +598,14 @@ class TemplateUtil {
|
|
|
598
598
|
return result;
|
|
599
599
|
}
|
|
600
600
|
|
|
601
|
-
/**
|
|
602
|
-
* 获取 `if` 的条件列表
|
|
603
|
-
*
|
|
604
|
-
* 1. selfCondition=需要取节点身的条件
|
|
605
|
-
* 2. preConditions=前置节点的条件--当前节点是 elif else 时,需要取前置节点
|
|
606
|
-
* @param node
|
|
607
|
-
* @param options
|
|
608
|
-
* @returns
|
|
601
|
+
/**
|
|
602
|
+
* 获取 `if` 的条件列表
|
|
603
|
+
*
|
|
604
|
+
* 1. selfCondition=需要取节点身的条件
|
|
605
|
+
* 2. preConditions=前置节点的条件--当前节点是 elif else 时,需要取前置节点
|
|
606
|
+
* @param node
|
|
607
|
+
* @param options
|
|
608
|
+
* @returns
|
|
609
609
|
*/
|
|
610
610
|
getIfCoditionList(node) {
|
|
611
611
|
const ifAttribute = TemplateUtil.getAttribute(node, 'if');
|
|
@@ -729,18 +729,18 @@ class TemplateUtil {
|
|
|
729
729
|
}
|
|
730
730
|
}
|
|
731
731
|
|
|
732
|
-
/**
|
|
733
|
-
* 元素的属性转换为资源路径
|
|
734
|
-
* 1. 不转换
|
|
735
|
-
* 1.1 属性本身无需转换
|
|
736
|
-
* 1.2 值不满足预设的条件: 不转换
|
|
737
|
-
* 1.3 绝对路径:不转换
|
|
738
|
-
* 2. 动态值:
|
|
739
|
-
* 2.1 第一段是静态值: 第一段转换为相对 src 的绝对路径, 示例:../a/b{{x}} --> /a/b{{x}} + 添加 warn
|
|
740
|
-
* 2.2 其它:不转换
|
|
741
|
-
* 3. 静态值:
|
|
742
|
-
* 3.1. 如果文件在src中,转换为相对src的路径, 示例:project/src/assets/a/b.png 转换为 /assets/a/b.png
|
|
743
|
-
* 3.2. 否则修改为 require()
|
|
732
|
+
/**
|
|
733
|
+
* 元素的属性转换为资源路径
|
|
734
|
+
* 1. 不转换
|
|
735
|
+
* 1.1 属性本身无需转换
|
|
736
|
+
* 1.2 值不满足预设的条件: 不转换
|
|
737
|
+
* 1.3 绝对路径:不转换
|
|
738
|
+
* 2. 动态值:
|
|
739
|
+
* 2.1 第一段是静态值: 第一段转换为相对 src 的绝对路径, 示例:../a/b{{x}} --> /a/b{{x}} + 添加 warn
|
|
740
|
+
* 2.2 其它:不转换
|
|
741
|
+
* 3. 静态值:
|
|
742
|
+
* 3.1. 如果文件在src中,转换为相对src的路径, 示例:project/src/assets/a/b.png 转换为 /assets/a/b.png
|
|
743
|
+
* 3.2. 否则修改为 require()
|
|
744
744
|
*/
|
|
745
745
|
convertResourcePath(nodeName, attrs) {
|
|
746
746
|
const shouldDic = {
|
|
@@ -872,28 +872,32 @@ class TemplateUtil {
|
|
|
872
872
|
});
|
|
873
873
|
}
|
|
874
874
|
|
|
875
|
-
/**
|
|
876
|
-
* 获取节点中的文字内容
|
|
877
|
-
*
|
|
878
|
-
* 1. 如果是文字元素,返回 value
|
|
879
|
-
*
|
|
880
|
-
* 1. 如果子元素是文本,直接返回内容
|
|
881
|
-
* 2. 否则,如果子元素允许文本,则递归获取结果
|
|
882
|
-
*
|
|
883
|
-
* 1. 首尾的替换为空字符串
|
|
884
|
-
* 2. 其它替换为1个空格
|
|
885
|
-
*
|
|
886
|
-
* @example
|
|
887
|
-
* `
|
|
888
|
-
* a
|
|
889
|
-
* b
|
|
890
|
-
*
|
|
891
|
-
* `
|
|
892
|
-
*
|
|
893
|
-
*
|
|
875
|
+
/**
|
|
876
|
+
* 获取节点中的文字内容
|
|
877
|
+
*
|
|
878
|
+
* 1. 如果是文字元素,返回 value
|
|
879
|
+
* 2. 循环子元素列表
|
|
880
|
+
* 1. 如果子元素是文本,直接返回内容
|
|
881
|
+
* 2. 否则,如果子元素允许文本,则递归获取结果
|
|
882
|
+
* 3. 文字中连续的特定符号[\r\n\t ]
|
|
883
|
+
* 1. 首尾的替换为空字符串
|
|
884
|
+
* 2. 其它替换为1个空格
|
|
885
|
+
*
|
|
886
|
+
* @example
|
|
887
|
+
* `
|
|
888
|
+
* a
|
|
889
|
+
* b
|
|
890
|
+
*
|
|
891
|
+
* `
|
|
892
|
+
* -->
|
|
893
|
+
* `a b`
|
|
894
|
+
*
|
|
895
|
+
* @param node
|
|
894
896
|
*/
|
|
895
897
|
getTextContent(node, elementConfig) {
|
|
896
898
|
let result = '';
|
|
899
|
+
// 不压缩内容的节点名称列表
|
|
900
|
+
const noCompressTextNodeNames = ['markdown'];
|
|
897
901
|
if (TemplateUtil.isText(node)) {
|
|
898
902
|
result = node.value;
|
|
899
903
|
} else {
|
|
@@ -908,6 +912,9 @@ class TemplateUtil {
|
|
|
908
912
|
}
|
|
909
913
|
});
|
|
910
914
|
}
|
|
915
|
+
if (noCompressTextNodeNames.includes(node.nodeName)) {
|
|
916
|
+
return result;
|
|
917
|
+
}
|
|
911
918
|
result = result.replace(/(^[\r\n\t ]+)|([\r\n\t ]+$)|[\r\n\t ]+/g, (match, p1, p2) => {
|
|
912
919
|
if (p1 || p2) {
|
|
913
920
|
return '';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IPosition, Loglevel, StyleMessage } from '@aiot-toolkit/shared-utils';
|
|
1
2
|
import { AtrulePrelude, CssNode, Declaration, Identifier, MediaFeature, MediaQuery, MediaQueryList, SelectorList, SyntaxParseError } from 'css-tree';
|
|
2
3
|
import IOptions from '../config/IOptions';
|
|
3
4
|
import { IImageFunction } from '../interface/IImageResource';
|
|
@@ -226,6 +227,6 @@ declare class StyleUtil {
|
|
|
226
227
|
* @returns
|
|
227
228
|
*/
|
|
228
229
|
static translateToNormalValue(value: any): any;
|
|
229
|
-
|
|
230
|
+
static handleStyleError(errorLevel: Loglevel, messages: StyleMessage[], options: IOptions, position: IPosition | undefined): void;
|
|
230
231
|
}
|
|
231
232
|
export default StyleUtil;
|
|
@@ -181,8 +181,7 @@ class StyleUtil {
|
|
|
181
181
|
}
|
|
182
182
|
const {
|
|
183
183
|
projectPath,
|
|
184
|
-
filePath
|
|
185
|
-
onLog
|
|
184
|
+
filePath
|
|
186
185
|
} = options;
|
|
187
186
|
const rootDir = compilerOption.sourceRoot;
|
|
188
187
|
const targetPath = _path.default.resolve(projectPath, rootDir);
|
|
@@ -196,12 +195,7 @@ class StyleUtil {
|
|
|
196
195
|
};
|
|
197
196
|
if (!assetsPath) {
|
|
198
197
|
// 警告,路径值不存在
|
|
199
|
-
|
|
200
|
-
filePath,
|
|
201
|
-
level: _sharedUtils.Loglevel.WARN,
|
|
202
|
-
position,
|
|
203
|
-
message: 'url value is null'
|
|
204
|
-
});
|
|
198
|
+
StyleUtil.handleStyleError(_sharedUtils.Loglevel.WARN, ['url value is null'], options, position);
|
|
205
199
|
return '';
|
|
206
200
|
}
|
|
207
201
|
// 1.
|
|
@@ -210,16 +204,11 @@ class StyleUtil {
|
|
|
210
204
|
if (_fsExtra.default.existsSync(_path.default.join(targetPath, assetsPath))) {
|
|
211
205
|
return assetsPath;
|
|
212
206
|
} else {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
word: `(${assetsAbsolutePath})`
|
|
219
|
-
}, 'to the current value ', {
|
|
220
|
-
word: `(${assetsPath})`
|
|
221
|
-
}, 'does not exist']
|
|
222
|
-
});
|
|
207
|
+
StyleUtil.handleStyleError(_sharedUtils.Loglevel.ERROR, ['The absolute path ', {
|
|
208
|
+
word: `(${assetsAbsolutePath})`
|
|
209
|
+
}, 'to the current value ', {
|
|
210
|
+
word: `(${assetsPath})`
|
|
211
|
+
}, 'does not exist'], options, position);
|
|
223
212
|
return '';
|
|
224
213
|
}
|
|
225
214
|
}
|
|
@@ -607,7 +596,7 @@ class StyleUtil {
|
|
|
607
596
|
break;
|
|
608
597
|
default:
|
|
609
598
|
const errorMessage = [`${firstName} is not a valid time value`];
|
|
610
|
-
StyleUtil.
|
|
599
|
+
StyleUtil.handleStyleError(_sharedUtils.Loglevel.THROW, errorMessage, options, position);
|
|
611
600
|
break;
|
|
612
601
|
}
|
|
613
602
|
}
|
|
@@ -648,7 +637,7 @@ class StyleUtil {
|
|
|
648
637
|
level: validInfoLevel
|
|
649
638
|
} = config.validate(sourceNode);
|
|
650
639
|
if (validMessages.length > 0) {
|
|
651
|
-
StyleUtil.
|
|
640
|
+
StyleUtil.handleStyleError(validInfoLevel, validMessages, options, sourceNode.position);
|
|
652
641
|
}
|
|
653
642
|
}
|
|
654
643
|
if (config?.translate) {
|
|
@@ -772,7 +761,7 @@ class StyleUtil {
|
|
|
772
761
|
}
|
|
773
762
|
return value;
|
|
774
763
|
}
|
|
775
|
-
static
|
|
764
|
+
static handleStyleError(errorLevel, messages, options, position) {
|
|
776
765
|
const {
|
|
777
766
|
onLog,
|
|
778
767
|
filePath,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiot-toolkit/parser",
|
|
3
|
-
"version": "2.0.6-beta.
|
|
3
|
+
"version": "2.0.6-beta.6",
|
|
4
4
|
"description": "Parse the source code of aiot and convert it to the AST (Abstract Syntax Tree) of the target code.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aiot",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"test": "node ./__tests__/parser.test.js"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@aiot-toolkit/shared-utils": "2.0.6-beta.
|
|
23
|
+
"@aiot-toolkit/shared-utils": "2.0.6-beta.6",
|
|
24
24
|
"@babel/core": "^7.23.6",
|
|
25
25
|
"@babel/generator": "^7.24.10",
|
|
26
26
|
"@babel/parser": "^7.24.8",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"css-tree": "npm:aiot-css-tree@^2.3.1",
|
|
32
32
|
"csstree-validator": "^3.0.0",
|
|
33
33
|
"eslint": "^8.46.0",
|
|
34
|
-
"file-lane": "2.0.6-beta.
|
|
34
|
+
"file-lane": "2.0.6-beta.6",
|
|
35
35
|
"fs-extra": "^11.2.0",
|
|
36
36
|
"google-protobuf": "^3.21.2",
|
|
37
37
|
"less": "^4.2.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"@types/tinycolor2": "^1.4.6",
|
|
61
61
|
"babel-plugin-tester": "^11.0.4"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "71dfc780e74e71df4d731300e7c0d6ea9e494358"
|
|
64
64
|
}
|