@aiot-toolkit/parser 2.0.5-beta.8 → 2.0.5-widget-provider-beta.1
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/README.md +11 -11
- package/lib/index.d.ts +1 -4
- package/lib/index.js +0 -27
- package/lib/utils/ParserUtil.js +15 -15
- package/lib/ux/config/ExtensionConfig.js +2 -2
- package/lib/ux/config/FeatureConfig.js +19 -19
- package/lib/ux/config/vela/StyleAttributeConfig.js +87 -87
- package/lib/ux/enum/StyleSelectorType.js +6 -6
- package/lib/ux/enum/TemplateNodeType.js +2 -2
- package/lib/ux/enum/android/StyleSelectorName.js +2 -2
- package/lib/ux/parser/ScriptParser.js +2 -2
- package/lib/ux/parser/StyleParser.js +62 -62
- package/lib/ux/parser/TemplateValueParser.js +49 -49
- package/lib/ux/parser/UxParser.js +11 -11
- package/lib/ux/translate/android/StyleToTypescript.js +51 -51
- package/lib/ux/translate/android/TemplateToTypescript.js +51 -51
- package/lib/ux/translate/android/UxToTypescript.js +14 -14
- package/lib/ux/translate/android/attributeTranslate/ForTranslate.js +17 -17
- package/lib/ux/translate/android/attributeTranslate/IfTranslate.js +9 -9
- package/lib/ux/translate/vela/ScriptToTypescript.js +13 -12
- package/lib/ux/translate/vela/StyleToTypescript.js +10 -10
- package/lib/ux/translate/vela/TemplateToTypescript.js +74 -74
- package/lib/ux/translate/vela/TranslateCache.js +2 -2
- package/lib/ux/translate/vela/UxToTypescript.js +6 -6
- package/lib/ux/translate/vela/VelaContext.js +2 -2
- package/lib/ux/translate/vela/plugins/e2e.js +61 -61
- package/lib/ux/translate/vela/protobuf/BinaryPlugin.js +172 -172
- package/lib/ux/translate/vela/protobuf/protobuf.js +235 -235
- package/lib/ux/translate/vela/protobuf/protobufControl.js +159 -159
- package/lib/ux/translate/vela/protobuf/vdom_pb.js +2374 -2374
- package/lib/ux/translate/vela/runtime/velaTestLibrary.js +104 -104
- package/lib/ux/translate/vela/utils/AttributeConfig.js +15 -15
- package/lib/ux/translate/vela/utils/ExtendedBoxStyle.js +38 -38
- package/lib/ux/translate/vela/utils/SourceMapUtil.js +30 -30
- package/lib/ux/translate/vela/utils/TemplateUtil.d.ts +10 -8
- package/lib/ux/translate/vela/utils/TemplateUtil.js +206 -191
- package/lib/ux/translate/vela/wrap/CbTranslate.js +8 -8
- package/lib/ux/translate/vela/wrap/CfTranslate.js +14 -14
- package/lib/ux/translate/vela/wrap/CiTranslate.js +11 -11
- package/lib/ux/utils/BabelUtil.js +35 -35
- package/lib/ux/utils/ElementConfigUtil.js +24 -24
- package/lib/ux/utils/StyleMapUtil.js +26 -16
- package/lib/ux/utils/StyleUtil.js +176 -174
- package/lib/ux/utils/UxUtil.js +32 -32
- package/lib/ux/validate/ElementValidate.js +2 -2
- package/lib/ux/validate/UxFileValidate.js +2 -2
- package/package.json +6 -6
- package/lib/xts/XtsParser.d.ts +0 -20
- package/lib/xts/XtsParser.js +0 -86
- package/lib/xts/XtsToTypescript.d.ts +0 -69
- package/lib/xts/XtsToTypescript.js +0 -894
- package/lib/xts/config/CommonAttributeList.d.ts +0 -6
- package/lib/xts/config/CommonAttributeList.js +0 -17
- package/lib/xts/config/classCount.json +0 -38
- package/lib/xts/config/commonAttribute.json +0 -84
- package/lib/xts/config/componentList.d.ts +0 -56
- package/lib/xts/config/componentList.js +0 -9
- package/lib/xts/config/predefinedComponent.json +0 -91
- package/lib/xts/config/render.json +0 -31
- package/lib/xts/data/ElementType.d.ts +0 -6
- package/lib/xts/data/ElementType.js +0 -5
- package/lib/xts/data/element/CommentElement.d.ts +0 -16
- package/lib/xts/data/element/CommentElement.js +0 -26
- package/lib/xts/data/element/ElementBase.d.ts +0 -14
- package/lib/xts/data/element/ElementBase.js +0 -20
- package/lib/xts/data/element/ForElement.d.ts +0 -58
- package/lib/xts/data/element/ForElement.js +0 -81
- package/lib/xts/data/element/IfElement.d.ts +0 -55
- package/lib/xts/data/element/IfElement.js +0 -87
- package/lib/xts/data/element/NodeElement.d.ts +0 -39
- package/lib/xts/data/element/NodeElement.js +0 -86
- package/lib/xts/enum/AttributeType.d.ts +0 -31
- package/lib/xts/enum/AttributeType.js +0 -53
- package/lib/xts/enum/Framework.d.ts +0 -98
- package/lib/xts/enum/Framework.js +0 -107
- package/lib/xts/interface/IContext.d.ts +0 -11
- package/lib/xts/interface/IContext.js +0 -1
- package/lib/xts/interface/IElement.d.ts +0 -17
- package/lib/xts/interface/IElement.js +0 -5
- package/lib/xts/interface/IExpressNode.d.ts +0 -20
- package/lib/xts/interface/IExpressNode.js +0 -1
- package/lib/xts/interface/config/ICommon.d.ts +0 -23
- package/lib/xts/interface/config/ICommon.js +0 -5
- package/lib/xts/interface/config/IRenderNode.d.ts +0 -25
- package/lib/xts/interface/config/IRenderNode.js +0 -1
- package/lib/xts/interface/validate/IAttibuteValidate.d.ts +0 -8
- package/lib/xts/interface/validate/IAttibuteValidate.js +0 -1
- package/lib/xts/interface/validate/IComponentValidate.d.ts +0 -9
- package/lib/xts/interface/validate/IComponentValidate.js +0 -1
- package/lib/xts/interface/validate/IRenderValidate.d.ts +0 -10
- package/lib/xts/interface/validate/IRenderValidate.js +0 -1
- package/lib/xts/interface/validate/ISourceFileValidate.d.ts +0 -7
- package/lib/xts/interface/validate/ISourceFileValidate.js +0 -1
- package/lib/xts/utils/AttributeUtil.d.ts +0 -73
- package/lib/xts/utils/AttributeUtil.js +0 -206
- package/lib/xts/utils/TypeUtil.d.ts +0 -60
- package/lib/xts/utils/TypeUtil.js +0 -97
- package/lib/xts/utils/TypescriptUtil.d.ts +0 -42
- package/lib/xts/utils/TypescriptUtil.js +0 -128
- package/lib/xts/validate/AttibuteValidate.d.ts +0 -18
- package/lib/xts/validate/AttibuteValidate.js +0 -97
- package/lib/xts/validate/ComponentValidate.d.ts +0 -19
- package/lib/xts/validate/ComponentValidate.js +0 -90
- package/lib/xts/validate/RenderValidate.d.ts +0 -63
- package/lib/xts/validate/RenderValidate.js +0 -239
- package/lib/xts/validate/SourceFileValidate.d.ts +0 -10
- package/lib/xts/validate/SourceFileValidate.js +0 -43
|
@@ -8,50 +8,50 @@ var parser = _interopRequireWildcard(require("@babel/parser"));
|
|
|
8
8
|
var t = _interopRequireWildcard(require("@babel/types"));
|
|
9
9
|
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); }
|
|
10
10
|
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; }
|
|
11
|
-
/**
|
|
12
|
-
* @see:node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js的 walkIdentifiers函数
|
|
13
|
-
* BabelUtil
|
|
11
|
+
/**
|
|
12
|
+
* @see:node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js的 walkIdentifiers函数
|
|
13
|
+
* BabelUtil
|
|
14
14
|
*/
|
|
15
15
|
class BabelUtil {
|
|
16
|
-
/**
|
|
17
|
-
* 是否是对象的标识符
|
|
18
|
-
*
|
|
19
|
-
* 例如: a = {}
|
|
20
|
-
* @param node
|
|
21
|
-
* @returns
|
|
16
|
+
/**
|
|
17
|
+
* 是否是对象的标识符
|
|
18
|
+
*
|
|
19
|
+
* 例如: a = {}
|
|
20
|
+
* @param node
|
|
21
|
+
* @returns
|
|
22
22
|
*/
|
|
23
23
|
static isObjectIdentifier(node) {
|
|
24
24
|
return node && (node.type === 'ObjectProperty' || node.type === 'ObjectMethod') && !node.computed;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
* 是否是对象键的标识符
|
|
29
|
-
*
|
|
30
|
-
* 例如: {x: **} 中的 x
|
|
31
|
-
* @param node
|
|
32
|
-
* @param parent
|
|
33
|
-
* @returns
|
|
27
|
+
/**
|
|
28
|
+
* 是否是对象键的标识符
|
|
29
|
+
*
|
|
30
|
+
* 例如: {x: **} 中的 x
|
|
31
|
+
* @param node
|
|
32
|
+
* @param parent
|
|
33
|
+
* @returns
|
|
34
34
|
*/
|
|
35
35
|
static isObjectKeyIdentifier(node, parent) {
|
|
36
36
|
return this.isObjectIdentifier(parent) && parent.key === node;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
/**
|
|
40
|
-
* 生成 babel的函数体
|
|
41
|
-
* @param code
|
|
42
|
-
* @returns
|
|
39
|
+
/**
|
|
40
|
+
* 生成 babel的函数体
|
|
41
|
+
* @param code
|
|
42
|
+
* @returns
|
|
43
43
|
*/
|
|
44
44
|
static generateFunctionBody(code) {
|
|
45
45
|
const func = `function() {${code}}`;
|
|
46
46
|
return parser.parseExpression(func).body;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
/**
|
|
50
|
-
* 插入或更新函数到对象
|
|
51
|
-
*
|
|
52
|
-
* @param functionName 函数名. 如果存在此函数,则把body插入到最后;否则,添加函数
|
|
53
|
-
* @param body 新增的函数体
|
|
54
|
-
* @param path 对象路径(babel的路径)
|
|
49
|
+
/**
|
|
50
|
+
* 插入或更新函数到对象
|
|
51
|
+
*
|
|
52
|
+
* @param functionName 函数名. 如果存在此函数,则把body插入到最后;否则,添加函数
|
|
53
|
+
* @param body 新增的函数体
|
|
54
|
+
* @param path 对象路径(babel的路径)
|
|
55
55
|
*/
|
|
56
56
|
static insertOrUpdateFunctionToObject(functionName, body, path) {
|
|
57
57
|
if (path.node.declaration.type === 'ObjectExpression') {
|
|
@@ -68,15 +68,15 @@ class BabelUtil {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
/**
|
|
72
|
-
* 插入import, 如果 `importName` 存在,则不执行操作
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* import router from '@system/router'
|
|
76
|
-
*
|
|
77
|
-
* @param importName import的名称, 例如:router
|
|
78
|
-
* @param importPath import的路径, 例如:@system/router
|
|
79
|
-
* @param param babel节点, 只有 `Program` 类型时才执行
|
|
71
|
+
/**
|
|
72
|
+
* 插入import, 如果 `importName` 存在,则不执行操作
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* import router from '@system/router'
|
|
76
|
+
*
|
|
77
|
+
* @param importName import的名称, 例如:router
|
|
78
|
+
* @param importPath import的路径, 例如:@system/router
|
|
79
|
+
* @param param babel节点, 只有 `Program` 类型时才执行
|
|
80
80
|
*/
|
|
81
81
|
static insertImportToProgram(importName, importPath, param) {
|
|
82
82
|
if (param.type === 'Program') {
|
|
@@ -8,8 +8,8 @@ var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
|
8
8
|
var _TemplateUtil = _interopRequireDefault(require("../translate/vela/utils/TemplateUtil"));
|
|
9
9
|
var _QuickAppDocHelp = require("@aiot-toolkit/shared-utils/lib/utils/QuickAppDocHelp");
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
/**
|
|
12
|
-
* ElementConfigUtil
|
|
11
|
+
/**
|
|
12
|
+
* ElementConfigUtil
|
|
13
13
|
*/
|
|
14
14
|
class ElementConfigUtil {
|
|
15
15
|
constructor(config) {
|
|
@@ -27,15 +27,15 @@ class ElementConfigUtil {
|
|
|
27
27
|
return false;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
* 对非自定义组件检查元素合法性
|
|
33
|
-
* 1. 是否有配置
|
|
34
|
-
* 2. 检查属性值是否合法
|
|
35
|
-
* 3. 检查是否缺少必填属性
|
|
36
|
-
* @param tagName 元素名称 <com id="a"> 中的 com
|
|
37
|
-
* @param importList
|
|
38
|
-
* @returns
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* 对非自定义组件检查元素合法性
|
|
33
|
+
* 1. 是否有配置
|
|
34
|
+
* 2. 检查属性值是否合法
|
|
35
|
+
* 3. 检查是否缺少必填属性
|
|
36
|
+
* @param tagName 元素名称 <com id="a"> 中的 com
|
|
37
|
+
* @param importList
|
|
38
|
+
* @returns
|
|
39
39
|
*/
|
|
40
40
|
validateElement = (options, tag, attributes, importList) => {
|
|
41
41
|
const tagName = tag.name;
|
|
@@ -92,19 +92,19 @@ class ElementConfigUtil {
|
|
|
92
92
|
return true;
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
/**
|
|
96
|
-
* 检查属性
|
|
97
|
-
* 1. 是否忽略: data-* 忽略
|
|
98
|
-
* 2. 如果是事件
|
|
99
|
-
* a. 检查是否在 元素 events 或 commonEvents 中
|
|
100
|
-
* b. 检查是否有值
|
|
101
|
-
* 3. 不是事件
|
|
102
|
-
* a. 检查是否在attributes配置中
|
|
103
|
-
* b. 是否有 enum,如果有,则检查值是否在配置中(不检查动态值)
|
|
104
|
-
* c. 是否有 validate,如果有,则执行并返回结果
|
|
105
|
-
* @param tagName 元素标签名
|
|
106
|
-
* @param attributeName 属性名
|
|
107
|
-
* @param attributeValue 属性值
|
|
95
|
+
/**
|
|
96
|
+
* 检查属性
|
|
97
|
+
* 1. 是否忽略: data-* 忽略
|
|
98
|
+
* 2. 如果是事件
|
|
99
|
+
* a. 检查是否在 元素 events 或 commonEvents 中
|
|
100
|
+
* b. 检查是否有值
|
|
101
|
+
* 3. 不是事件
|
|
102
|
+
* a. 检查是否在attributes配置中
|
|
103
|
+
* b. 是否有 enum,如果有,则检查值是否在配置中(不检查动态值)
|
|
104
|
+
* c. 是否有 validate,如果有,则执行并返回结果
|
|
105
|
+
* @param tagName 元素标签名
|
|
106
|
+
* @param attributeName 属性名
|
|
107
|
+
* @param attributeValue 属性值
|
|
108
108
|
*/
|
|
109
109
|
validateAttribute = (options, tagName, attribute) => {
|
|
110
110
|
const elementConfig = this.getElementConfig(tagName);
|
|
@@ -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 _url = require("url");
|
|
8
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
10
|
class StyleMapUtil {
|
|
10
11
|
constructor(sourceMapConsumer, lineOffset, options) {
|
|
@@ -12,21 +13,21 @@ class StyleMapUtil {
|
|
|
12
13
|
this.lineOffset = lineOffset;
|
|
13
14
|
this.options = options;
|
|
14
15
|
}
|
|
15
|
-
/**
|
|
16
|
-
* 1. 根据生成结果位置找转换前的行列值
|
|
17
|
-
* 2. 根据样式代码总体偏移量,计算出当前节点行在ux中的行
|
|
18
|
-
* 2.1 查看map信息,原始行总是从第三行开始计算,-2是去掉生成map信息时多余的偏移量
|
|
19
|
-
* 2.2 再加上样式代码总体偏移量,就可以计算出实际所在行数
|
|
20
|
-
* 3. 返回节点原始位置信息
|
|
21
|
-
* 3.1 原始位置的startLine即为上一步计算了偏移量的行信息
|
|
22
|
-
* 3.2 原始位置的startColumn为查找到的节点列信息(目前看结果不存在列偏移)
|
|
23
|
-
* 3.3 原始位置的endLine为startLine+生成结果中所占据行数的值
|
|
24
|
-
* 3.4 原始位置的endColumn根据map结果,发现存在1个位置的差异,所以-1
|
|
25
|
-
* 3.5 source存储来源的文件
|
|
26
|
-
* @param location 生成结果中节点的位置信息
|
|
27
|
-
* @param consumer 经过解析器获取的map信息生成的consumer对象
|
|
28
|
-
* @param offset 当前样式代码在ux文件中的偏移量
|
|
29
|
-
* @returns
|
|
16
|
+
/**
|
|
17
|
+
* 1. 根据生成结果位置找转换前的行列值
|
|
18
|
+
* 2. 根据样式代码总体偏移量,计算出当前节点行在ux中的行
|
|
19
|
+
* 2.1 查看map信息,原始行总是从第三行开始计算,-2是去掉生成map信息时多余的偏移量
|
|
20
|
+
* 2.2 再加上样式代码总体偏移量,就可以计算出实际所在行数
|
|
21
|
+
* 3. 返回节点原始位置信息
|
|
22
|
+
* 3.1 原始位置的startLine即为上一步计算了偏移量的行信息
|
|
23
|
+
* 3.2 原始位置的startColumn为查找到的节点列信息(目前看结果不存在列偏移)
|
|
24
|
+
* 3.3 原始位置的endLine为startLine+生成结果中所占据行数的值
|
|
25
|
+
* 3.4 原始位置的endColumn根据map结果,发现存在1个位置的差异,所以-1
|
|
26
|
+
* 3.5 source存储来源的文件
|
|
27
|
+
* @param location 生成结果中节点的位置信息
|
|
28
|
+
* @param consumer 经过解析器获取的map信息生成的consumer对象
|
|
29
|
+
* @param offset 当前样式代码在ux文件中的偏移量
|
|
30
|
+
* @returns
|
|
30
31
|
*/
|
|
31
32
|
transfromLocToPosition(location) {
|
|
32
33
|
const {
|
|
@@ -40,12 +41,21 @@ class StyleMapUtil {
|
|
|
40
41
|
line: location.end.line,
|
|
41
42
|
column: location.end.column
|
|
42
43
|
});
|
|
44
|
+
let nodeRelativePath = '';
|
|
43
45
|
if (nodeStartPosition.source?.endsWith('.ux') && nodeStartPosition.line) {
|
|
44
46
|
nodeStartPosition.line = nodeStartPosition.line - 1 + this.lineOffset;
|
|
45
47
|
}
|
|
46
48
|
if (nodeEndPosition.source?.endsWith('.ux') && nodeEndPosition.line) {
|
|
47
49
|
nodeEndPosition.line = nodeEndPosition.line - 1 + this.lineOffset;
|
|
48
50
|
}
|
|
51
|
+
// nodeStartPosition.source在scss转css时会添加file://前缀,在这里需要去掉,以免影响路径的计算
|
|
52
|
+
if (nodeStartPosition.source) {
|
|
53
|
+
let decodeStr = decodeURI(nodeStartPosition.source);
|
|
54
|
+
if (decodeStr.startsWith('file://')) {
|
|
55
|
+
decodeStr = (0, _url.fileURLToPath)(decodeStr);
|
|
56
|
+
}
|
|
57
|
+
nodeRelativePath = _path.default.relative(projectPath, decodeStr).replaceAll(_path.default.sep, _path.default.posix.sep);
|
|
58
|
+
}
|
|
49
59
|
return {
|
|
50
60
|
pos: 0,
|
|
51
61
|
end: 0,
|
|
@@ -53,7 +63,7 @@ class StyleMapUtil {
|
|
|
53
63
|
startColumn: nodeStartPosition.column || 0,
|
|
54
64
|
endLine: nodeEndPosition.line || 0,
|
|
55
65
|
endColumn: nodeEndPosition.column || 0,
|
|
56
|
-
source:
|
|
66
|
+
source: nodeRelativePath
|
|
57
67
|
};
|
|
58
68
|
}
|
|
59
69
|
}
|