@aiot-toolkit/parser 2.0.6-beta.17 → 2.0.6-beta.18
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Dictionary, Logger } from '@aiot-toolkit/shared-utils';
|
|
2
|
+
import { IAttributeNode } from '../interface/IIdentifierNode';
|
|
2
3
|
interface IElement {
|
|
3
4
|
/**
|
|
4
5
|
* 别名
|
|
@@ -8,6 +9,19 @@ interface IElement {
|
|
|
8
9
|
* @example <img /> 生成为 image
|
|
9
10
|
*/
|
|
10
11
|
aliasName?: string;
|
|
12
|
+
/**
|
|
13
|
+
* 别名属性
|
|
14
|
+
*
|
|
15
|
+
* aliasName 生效时,会将别名属性合并到属性列表中
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```
|
|
19
|
+
* // <button /> 生成为 <input type="button" />
|
|
20
|
+
* aliasName='input'
|
|
21
|
+
* aliasAttributes=[{name:'type',value:'button'}]
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
aliasAttributes?: IAttributeNode[];
|
|
11
25
|
/**
|
|
12
26
|
* 允许文字子节点
|
|
13
27
|
*
|
|
@@ -217,6 +217,17 @@ const elementConfig = {
|
|
|
217
217
|
name: {}
|
|
218
218
|
}
|
|
219
219
|
},
|
|
220
|
+
button: {
|
|
221
|
+
aliasName: 'input',
|
|
222
|
+
aliasAttributes: [{
|
|
223
|
+
name: 'type',
|
|
224
|
+
value: 'button'
|
|
225
|
+
}],
|
|
226
|
+
attributes: {
|
|
227
|
+
name: {},
|
|
228
|
+
value: {}
|
|
229
|
+
}
|
|
230
|
+
},
|
|
220
231
|
input: {
|
|
221
232
|
events: ['change', 'enterkeyclick', 'selectionchange'],
|
|
222
233
|
attributes: {
|
|
@@ -103,7 +103,7 @@ class ScriptToTypescript {
|
|
|
103
103
|
let position = undefined;
|
|
104
104
|
let message = babelError.message;
|
|
105
105
|
if (loc) {
|
|
106
|
-
const offsetLine = (sourceTree.sourceCodeLocation?.startLine ||
|
|
106
|
+
const offsetLine = (sourceTree.sourceCodeLocation?.startLine || 1) - 1;
|
|
107
107
|
const startLine = loc.line + offsetLine;
|
|
108
108
|
const startColumn = loc.column;
|
|
109
109
|
// babel 错误信息中包含行列信息,需要替换
|
|
@@ -367,6 +367,7 @@ class TemplateUtil {
|
|
|
367
367
|
}
|
|
368
368
|
const elementConfig = getElementConfig(tag.name);
|
|
369
369
|
const effectTag = elementConfig?.aliasName || tag.name;
|
|
370
|
+
const aliasAttributes = elementConfig?.aliasAttributes;
|
|
370
371
|
const {
|
|
371
372
|
globalInstance,
|
|
372
373
|
dataInstance,
|
|
@@ -374,7 +375,7 @@ class TemplateUtil {
|
|
|
374
375
|
} = this.context;
|
|
375
376
|
const result = `${globalInstance}.${callerName}("${effectTag}", ${_sharedUtils.StringUtil.objectToString({
|
|
376
377
|
[dataInstance]: dataInstanceValue,
|
|
377
|
-
__opts__: await this.attributesToObject(attributes, identifiers, {
|
|
378
|
+
__opts__: await this.attributesToObject(aliasAttributes ? [...aliasAttributes, ...attributes] : attributes, identifiers, {
|
|
378
379
|
nameToCamel: true
|
|
379
380
|
})
|
|
380
381
|
})}, ${children})`;
|
|
@@ -537,7 +537,7 @@ class StyleUtil {
|
|
|
537
537
|
if (!(0, _StyleSelectorType.isSupportMediaType)(mediaTypeName, projectType)) {
|
|
538
538
|
// 报错
|
|
539
539
|
onLog({
|
|
540
|
-
level: _sharedUtils.Loglevel.
|
|
540
|
+
level: _sharedUtils.Loglevel.WARN,
|
|
541
541
|
filePath: filePath,
|
|
542
542
|
position: node.loc ? styleMapUil.transfromLocToPosition(node.loc) : undefined,
|
|
543
543
|
message: [`Unsupported media type `, {
|
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.18",
|
|
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.18",
|
|
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.18",
|
|
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": "bed05a2f0a6519a96d631e40387088a88cdbc4a9"
|
|
64
64
|
}
|