@aiot-toolkit/parser 2.0.6-beta.1 → 2.0.6-beta.10
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/StyleAttributeConfig.d.ts → StyleBaseConfig.d.ts} +1 -1
- package/lib/ux/config/{vela/StyleAttributeConfig.js → StyleBaseConfig.js} +16 -24
- package/lib/ux/config/vela/ElementConfig.js +6 -0
- package/lib/ux/interface/IE2eConfig.d.ts +44 -0
- package/lib/ux/interface/IE2eConfig.js +1 -0
- package/lib/ux/interface/IStyleError.d.ts +2 -1
- package/lib/ux/parser/ScriptParser.js +2 -1
- package/lib/ux/parser/StyleParser.d.ts +3 -2
- package/lib/ux/parser/StyleParser.js +27 -30
- package/lib/ux/parser/UxParser.d.ts +1 -0
- package/lib/ux/parser/UxParser.js +17 -15
- package/lib/ux/translate/vela/ScriptToTypescript.d.ts +2 -1
- package/lib/ux/translate/vela/ScriptToTypescript.js +13 -6
- package/lib/ux/translate/vela/StyleToTypescript.js +8 -11
- package/lib/ux/translate/vela/plugins/e2e.js +30 -138
- package/lib/ux/translate/vela/utils/AttributeConfig.js +1 -1
- 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/StyleMapUtil.d.ts +2 -3
- package/lib/ux/utils/StyleMapUtil.js +6 -5
- package/lib/ux/utils/StyleUtil.d.ts +2 -0
- package/lib/ux/utils/StyleUtil.js +60 -48
- package/lib/ux/utils/UxUtil.d.ts +5 -0
- package/lib/ux/utils/UxUtil.js +24 -0
- package/package.json +4 -4
|
@@ -11,8 +11,8 @@ var _lodash = _interopRequireDefault(require("lodash"));
|
|
|
11
11
|
var _path = _interopRequireDefault(require("path"));
|
|
12
12
|
var _CompressConfig = require("../config/CompressConfig");
|
|
13
13
|
var _StyleSelectorType = require("../enum/StyleSelectorType");
|
|
14
|
-
var _StyleAttributeConfig = require("../config/vela/StyleAttributeConfig");
|
|
15
14
|
var _tinycolor = _interopRequireDefault(require("tinycolor2"));
|
|
15
|
+
var _StyleBaseConfig = require("../config/StyleBaseConfig");
|
|
16
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
17
|
/**
|
|
18
18
|
* 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
|
}
|
|
@@ -291,7 +280,9 @@ class StyleUtil {
|
|
|
291
280
|
loc
|
|
292
281
|
} = fallbackNode;
|
|
293
282
|
parserError = {
|
|
294
|
-
|
|
283
|
+
messages: [{
|
|
284
|
+
word: name
|
|
285
|
+
}],
|
|
295
286
|
details: message,
|
|
296
287
|
startLine: loc?.start?.line || loc?.start?.startLine || 0,
|
|
297
288
|
startCol: loc?.start?.column || loc?.start?.startCol || 0,
|
|
@@ -321,14 +312,29 @@ class StyleUtil {
|
|
|
321
312
|
message,
|
|
322
313
|
details,
|
|
323
314
|
loc,
|
|
324
|
-
css
|
|
315
|
+
css,
|
|
316
|
+
property
|
|
325
317
|
} = error;
|
|
326
|
-
|
|
318
|
+
let messages = [];
|
|
319
|
+
if (message.includes('Unknown property') && _StyleBaseConfig.STYLE_ATTRIBUTE_LIST.includes(_sharedUtils.StringUtil.hyphenedToCamel(error.property)) || message.includes('Invalid value for `@media` prelude')) {
|
|
327
320
|
continue;
|
|
328
321
|
}
|
|
322
|
+
// 优化值报错的信息,csstree-validator值报错时为Invalida value for
|
|
323
|
+
if (message.includes('Invalid value for')) {
|
|
324
|
+
// 请检查属性的值是否符合要求
|
|
325
|
+
messages = [`The value of attribute`, {
|
|
326
|
+
word: `${property}: ${css}`
|
|
327
|
+
}, 'is invalid.'];
|
|
328
|
+
css = '';
|
|
329
|
+
} else {
|
|
330
|
+
// 高亮原始报错信息
|
|
331
|
+
messages = [{
|
|
332
|
+
word: message
|
|
333
|
+
}];
|
|
334
|
+
}
|
|
329
335
|
if (loc) {
|
|
330
336
|
syntaxErrors.push({
|
|
331
|
-
|
|
337
|
+
messages,
|
|
332
338
|
details,
|
|
333
339
|
startLine: loc?.start?.line || 0,
|
|
334
340
|
startCol: loc?.start?.column || 1,
|
|
@@ -341,7 +347,7 @@ class StyleUtil {
|
|
|
341
347
|
} else {
|
|
342
348
|
const propertyLength = error?.property?.length || 0;
|
|
343
349
|
syntaxErrors.push({
|
|
344
|
-
|
|
350
|
+
messages,
|
|
345
351
|
details,
|
|
346
352
|
startLine: error.line || 0,
|
|
347
353
|
startCol: error.column || 0,
|
|
@@ -351,7 +357,6 @@ class StyleUtil {
|
|
|
351
357
|
endOffset: (error.offset || 0) + propertyLength,
|
|
352
358
|
source: css
|
|
353
359
|
});
|
|
354
|
-
continue;
|
|
355
360
|
}
|
|
356
361
|
}
|
|
357
362
|
return syntaxErrors;
|
|
@@ -568,10 +573,6 @@ class StyleUtil {
|
|
|
568
573
|
* @returns
|
|
569
574
|
*/
|
|
570
575
|
static translateKeyFramesRule(rule, options) {
|
|
571
|
-
const {
|
|
572
|
-
onLog,
|
|
573
|
-
filePath
|
|
574
|
-
} = options;
|
|
575
576
|
const {
|
|
576
577
|
prelude,
|
|
577
578
|
block,
|
|
@@ -594,12 +595,8 @@ class StyleUtil {
|
|
|
594
595
|
result.time = 100;
|
|
595
596
|
break;
|
|
596
597
|
default:
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
message: `${firstName} is not a valid time value`,
|
|
600
|
-
filePath,
|
|
601
|
-
position
|
|
602
|
-
});
|
|
598
|
+
const errorMessage = [`${firstName} is not a valid time value`];
|
|
599
|
+
StyleUtil.handleStyleError(_sharedUtils.Loglevel.THROW, errorMessage, options, position);
|
|
603
600
|
break;
|
|
604
601
|
}
|
|
605
602
|
}
|
|
@@ -633,20 +630,14 @@ class StyleUtil {
|
|
|
633
630
|
value: valueNode
|
|
634
631
|
} = sourceNode;
|
|
635
632
|
// 属性校验
|
|
636
|
-
const config =
|
|
633
|
+
const config = _StyleBaseConfig.STYLE_ATTRIBUTE_CONFIG[name];
|
|
637
634
|
if (config?.validate) {
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
onLog({
|
|
645
|
-
filePath: filePath,
|
|
646
|
-
level: validateResult.level,
|
|
647
|
-
position: sourceNode.position,
|
|
648
|
-
message: [`Attribute verification failed,`, ...validateResult.message]
|
|
649
|
-
});
|
|
635
|
+
const {
|
|
636
|
+
message: validMessages,
|
|
637
|
+
level: validInfoLevel
|
|
638
|
+
} = config.validate(sourceNode);
|
|
639
|
+
if (validMessages.length > 0) {
|
|
640
|
+
StyleUtil.handleStyleError(validInfoLevel, validMessages, options, sourceNode.position);
|
|
650
641
|
}
|
|
651
642
|
}
|
|
652
643
|
if (config?.translate) {
|
|
@@ -770,5 +761,26 @@ class StyleUtil {
|
|
|
770
761
|
}
|
|
771
762
|
return value;
|
|
772
763
|
}
|
|
764
|
+
static handleStyleError(errorLevel, messages, options, position) {
|
|
765
|
+
const {
|
|
766
|
+
onLog,
|
|
767
|
+
filePath,
|
|
768
|
+
projectPath
|
|
769
|
+
} = options;
|
|
770
|
+
// position.source存储的是相对路径,报错时要用绝对路径
|
|
771
|
+
let updatedPosition;
|
|
772
|
+
if (position) {
|
|
773
|
+
updatedPosition = {
|
|
774
|
+
...position,
|
|
775
|
+
source: position.source && _path.default.resolve(projectPath, position.source)
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
onLog({
|
|
779
|
+
level: errorLevel,
|
|
780
|
+
message: messages,
|
|
781
|
+
filePath,
|
|
782
|
+
position: updatedPosition
|
|
783
|
+
});
|
|
784
|
+
}
|
|
773
785
|
}
|
|
774
786
|
var _default = exports.default = StyleUtil;
|
package/lib/ux/utils/UxUtil.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Dictionary } from '@aiot-toolkit/shared-utils';
|
|
|
2
2
|
import { Element } from 'aiot-parse5/dist/tree-adapters/default';
|
|
3
3
|
import IImportAst from '../interface/IImportAst';
|
|
4
4
|
import ITranslateOption from '../interface/ITranslateOption';
|
|
5
|
+
import IE2eConfig from '../interface/IE2eConfig';
|
|
5
6
|
/**
|
|
6
7
|
* UxParserUtil
|
|
7
8
|
*/
|
|
@@ -47,5 +48,9 @@ declare class UxUtil {
|
|
|
47
48
|
*/
|
|
48
49
|
static isAbsoluteResource(path?: string): boolean;
|
|
49
50
|
static importToTypescript(importList: IImportAst[], compilerOption: ITranslateOption): string[];
|
|
51
|
+
static getE2eConfig(option: {
|
|
52
|
+
projectPath: string;
|
|
53
|
+
e2eConfigPath?: string;
|
|
54
|
+
}): IE2eConfig;
|
|
50
55
|
}
|
|
51
56
|
export default UxUtil;
|
package/lib/ux/utils/UxUtil.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _path = _interopRequireDefault(require("path"));
|
|
8
|
+
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
8
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
10
|
/**
|
|
10
11
|
* UxParserUtil
|
|
@@ -108,5 +109,28 @@ class UxUtil {
|
|
|
108
109
|
}
|
|
109
110
|
return appImport;
|
|
110
111
|
}
|
|
112
|
+
static getE2eConfig(option) {
|
|
113
|
+
const defaultTestDir = 'test';
|
|
114
|
+
let result = {
|
|
115
|
+
dir: _path.default.join(option.projectPath, defaultTestDir)
|
|
116
|
+
};
|
|
117
|
+
const {
|
|
118
|
+
projectPath,
|
|
119
|
+
e2eConfigPath
|
|
120
|
+
} = option;
|
|
121
|
+
if (e2eConfigPath) {
|
|
122
|
+
const configFilePath = _path.default.resolve(projectPath, e2eConfigPath);
|
|
123
|
+
const configFileDir = _path.default.dirname(configFilePath);
|
|
124
|
+
if (_fsExtra.default.existsSync(configFilePath)) {
|
|
125
|
+
result = _fsExtra.default.readJSONSync(configFilePath, 'utf-8');
|
|
126
|
+
if (result) {
|
|
127
|
+
result.dir = _path.default.resolve(configFileDir, result.dir || defaultTestDir);
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
throw new Error(`e2e Configuration file does not exist: ${configFilePath}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
111
135
|
}
|
|
112
136
|
var _default = exports.default = UxUtil;
|
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.10",
|
|
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.10",
|
|
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.10",
|
|
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": "b6a63385af95a6ba445e65225a92014026ce3144"
|
|
64
64
|
}
|