@aiot-toolkit/parser 2.0.5-beta.9 → 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 +165 -165
- 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 +4 -5
- 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
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Node, ts } from 'ts-morph';
|
|
2
|
-
import IContext from '../IContext';
|
|
3
|
-
/**
|
|
4
|
-
* IRenderValidate
|
|
5
|
-
*/
|
|
6
|
-
export default interface IRenderValidate {
|
|
7
|
-
validateNodeElement(elementList: Node<ts.Node>[], startIndex: number, context: IContext): Error[];
|
|
8
|
-
validateRenderer(context: IContext, element: Node<ts.Node>): Error[];
|
|
9
|
-
validateForEach(context: IContext, element: Node<ts.Node>, argumentList: Node<ts.Node>[]): Error[];
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Node, ObjectLiteralExpression, OptionalKind, PropertyAssignment, PropertyAssignmentStructure, VariableStatement, ts } from 'ts-morph';
|
|
2
|
-
import AttributeType from '../enum/AttributeType';
|
|
3
|
-
import { tsFrameWorkExports } from '../enum/Framework';
|
|
4
|
-
import IExpressNode from '../interface/IExpressNode';
|
|
5
|
-
/**
|
|
6
|
-
* AttributeUtil
|
|
7
|
-
*/
|
|
8
|
-
declare class AttributeUtil {
|
|
9
|
-
/**
|
|
10
|
-
* 通过属性名称,判断属性类型
|
|
11
|
-
* @param name 属性名称
|
|
12
|
-
*/
|
|
13
|
-
static getAttributeType(name: string): AttributeType;
|
|
14
|
-
/**
|
|
15
|
-
* 是否是静态属性
|
|
16
|
-
* @param value
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
static isDynamicValue(value: Node<ts.Node>): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* 根据 表达式式节点的内容,向 object对象 添加属性
|
|
22
|
-
*
|
|
23
|
-
* @description 根据 width(100) 向 {} 添加 style: {width: 100 } 属性
|
|
24
|
-
* 1. 通过 width 判断属性为应该是 style
|
|
25
|
-
* 2. 取得 width 的值100
|
|
26
|
-
* 3. 修改 {} 为 { style: {width: 100 }}
|
|
27
|
-
*
|
|
28
|
-
* @param expressNode
|
|
29
|
-
* @param target
|
|
30
|
-
* @returns
|
|
31
|
-
*/
|
|
32
|
-
static addAttribute(expressNode: IExpressNode, map: Map<string, VariableStatement>, index: number, fileDir: string, root: string, pushXtsImport: (target: tsFrameWorkExports) => void): {
|
|
33
|
-
type: string;
|
|
34
|
-
attributeItem: import("ts-morph").VariableDeclaration;
|
|
35
|
-
isDynamic: boolean;
|
|
36
|
-
} | {
|
|
37
|
-
type: string;
|
|
38
|
-
attributeItem: PropertyAssignment;
|
|
39
|
-
isDynamic: boolean;
|
|
40
|
-
};
|
|
41
|
-
static addEvent(expressNode: IExpressNode, map: Map<string, VariableStatement>, index: number, fileDir: string, root: string, pushXtsImport: (target: tsFrameWorkExports) => void): {
|
|
42
|
-
type: string;
|
|
43
|
-
attributeItem: PropertyAssignment;
|
|
44
|
-
isDynamic: boolean;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* 根据表达式式节点的内容,向 object 对象添加属性
|
|
48
|
-
*
|
|
49
|
-
* @description 根据 style({backgrourd:'red'}) 向 {} 添加 style: { backgrourd:'red' } 属性
|
|
50
|
-
*
|
|
51
|
-
* @param expressNode
|
|
52
|
-
* @param target
|
|
53
|
-
* @returns
|
|
54
|
-
*/
|
|
55
|
-
static addStyle(expressNode: IExpressNode, styleType: string, map: Map<string, VariableStatement>, index: number, fileDir: string, root: string): {
|
|
56
|
-
type: string;
|
|
57
|
-
attributeItem: import("ts-morph").VariableDeclaration;
|
|
58
|
-
isDynamic: boolean;
|
|
59
|
-
};
|
|
60
|
-
/** 给一个对象节点添加属性,若已存在则删除原属性后添加 */
|
|
61
|
-
static assignProp(tar: ObjectLiteralExpression, structure: OptionalKind<PropertyAssignmentStructure>): PropertyAssignment;
|
|
62
|
-
static createVarName(type: string, index: number): string;
|
|
63
|
-
static reverseVarName(name: string): string;
|
|
64
|
-
/**
|
|
65
|
-
* 将图片的 src 相对路径改为从根路径开始的绝对路径
|
|
66
|
-
* @param src 用户设置的 src
|
|
67
|
-
* @param fileDir 该文件的目录
|
|
68
|
-
* @param root 项目根目录
|
|
69
|
-
*/
|
|
70
|
-
static transformSrc(src: string, fileDir: string, root: string): string;
|
|
71
|
-
static getFrameworkImportFrom(srouceFilePath: string, root: string): string;
|
|
72
|
-
}
|
|
73
|
-
export default AttributeUtil;
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
var _tsMorph = require("ts-morph");
|
|
10
|
-
var _AttributeType = _interopRequireDefault(require("../enum/AttributeType"));
|
|
11
|
-
var _Framework = require("../enum/Framework");
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
/**
|
|
14
|
-
* AttributeUtil
|
|
15
|
-
*/
|
|
16
|
-
class AttributeUtil {
|
|
17
|
-
/**
|
|
18
|
-
* 通过属性名称,判断属性类型
|
|
19
|
-
* @param name 属性名称
|
|
20
|
-
*/
|
|
21
|
-
static getAttributeType(name) {
|
|
22
|
-
// 临时规则,需要改成从配置文件中读取
|
|
23
|
-
// 如果是 on 开头的,是 event
|
|
24
|
-
// 如果是 width 是style
|
|
25
|
-
// 其它是 attr
|
|
26
|
-
if (name.startsWith('on')) {
|
|
27
|
-
return _AttributeType.default.EVENT;
|
|
28
|
-
} else if (_Framework.NodeStyles.includes(name)) {
|
|
29
|
-
return _AttributeType.default.STYLE;
|
|
30
|
-
}
|
|
31
|
-
return _AttributeType.default.ATTRIBUTE;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 是否是静态属性
|
|
36
|
-
* @param value
|
|
37
|
-
* @returns
|
|
38
|
-
*/
|
|
39
|
-
static isDynamicValue(value) {
|
|
40
|
-
if ([_tsMorph.SyntaxKind.StringLiteral, _tsMorph.SyntaxKind.NumericLiteral].includes(value.getKind())) return false;else if (value.getKind() === _tsMorph.SyntaxKind.ObjectLiteralExpression) {
|
|
41
|
-
const props = value.getProperties();
|
|
42
|
-
let hasDynamic = false;
|
|
43
|
-
for (const p of props) {
|
|
44
|
-
hasDynamic = AttributeUtil.isDynamicValue(p.getInitializer());
|
|
45
|
-
if (hasDynamic) break;
|
|
46
|
-
}
|
|
47
|
-
return hasDynamic;
|
|
48
|
-
}
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 根据 表达式式节点的内容,向 object对象 添加属性
|
|
54
|
-
*
|
|
55
|
-
* @description 根据 width(100) 向 {} 添加 style: {width: 100 } 属性
|
|
56
|
-
* 1. 通过 width 判断属性为应该是 style
|
|
57
|
-
* 2. 取得 width 的值100
|
|
58
|
-
* 3. 修改 {} 为 { style: {width: 100 }}
|
|
59
|
-
*
|
|
60
|
-
* @param expressNode
|
|
61
|
-
* @param target
|
|
62
|
-
* @returns
|
|
63
|
-
*/
|
|
64
|
-
static addAttribute(expressNode, map, index, fileDir, root, pushXtsImport) {
|
|
65
|
-
const styleType = _AttributeType.default.isStyle(expressNode.name.getText());
|
|
66
|
-
if (styleType) {
|
|
67
|
-
return AttributeUtil.addStyle(expressNode, styleType, map, index, fileDir, root);
|
|
68
|
-
}
|
|
69
|
-
const type = this.getAttributeType(expressNode.name.getText());
|
|
70
|
-
if (type === _AttributeType.default.EVENT) {
|
|
71
|
-
return AttributeUtil.addEvent(expressNode, map, index, fileDir, root, pushXtsImport);
|
|
72
|
-
}
|
|
73
|
-
const attributeName = _AttributeType.default.toString(type);
|
|
74
|
-
const key = AttributeUtil.createVarName(attributeName, index);
|
|
75
|
-
const variableStatement = map.get(key);
|
|
76
|
-
const obj = variableStatement.getDeclarations()[0];
|
|
77
|
-
const value = expressNode.value[0];
|
|
78
|
-
let initStr = value ? value.getText() : '';
|
|
79
|
-
|
|
80
|
-
// 如果是 图片相关的属性,需要进行转换
|
|
81
|
-
if (_AttributeType.default.ImageAttrs.includes(expressNode.name.getText())) {
|
|
82
|
-
initStr = AttributeUtil.transformSrc(initStr, fileDir, root);
|
|
83
|
-
}
|
|
84
|
-
const attributeItem = AttributeUtil.assignProp(obj.getInitializer(), {
|
|
85
|
-
name: expressNode.name.getText(),
|
|
86
|
-
initializer: initStr
|
|
87
|
-
});
|
|
88
|
-
return {
|
|
89
|
-
type: attributeName,
|
|
90
|
-
attributeItem,
|
|
91
|
-
isDynamic: value ? this.isDynamicValue(value) : false
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
static addEvent(expressNode, map, index, fileDir, root, pushXtsImport) {
|
|
95
|
-
const attributeName = _AttributeType.default.toString(_AttributeType.default.EVENT);
|
|
96
|
-
const key = AttributeUtil.createVarName(attributeName, index);
|
|
97
|
-
const variableStatement = map.get(key);
|
|
98
|
-
const obj = variableStatement.getDeclarations()[0];
|
|
99
|
-
const isCustomEvnet = expressNode.name.getText() === 'onEvent';
|
|
100
|
-
const funcNode = isCustomEvnet ? expressNode.value[1] : expressNode.value[0];
|
|
101
|
-
const eventName = isCustomEvnet ? expressNode.value[0].getText() : expressNode.name.getText();
|
|
102
|
-
const eventType = funcNode.getParameters && funcNode.getParameters()?.at(0)?.getTypeNode()?.getText() || 'PlainObject';
|
|
103
|
-
let callParams = '';
|
|
104
|
-
if (!isCustomEvnet) {
|
|
105
|
-
callParams = `e__ as ${eventType}`;
|
|
106
|
-
pushXtsImport(eventType);
|
|
107
|
-
} else if (isCustomEvnet && funcNode.getParameters() && funcNode.getParameters().length > 0) {
|
|
108
|
-
callParams = '(e__ as CustomEvent).data';
|
|
109
|
-
pushXtsImport(_Framework.tsFrameWork.exports.CustomEvent);
|
|
110
|
-
}
|
|
111
|
-
let initStr = funcNode ? `(e__: Event) => {
|
|
112
|
-
(${funcNode.getText()})(${callParams})
|
|
113
|
-
}` : '';
|
|
114
|
-
pushXtsImport(_Framework.tsFrameWork.exports.Event);
|
|
115
|
-
|
|
116
|
-
// 如果是 图片相关的属性,需要进行转换
|
|
117
|
-
if (_AttributeType.default.ImageAttrs.includes(expressNode.name.getText())) {
|
|
118
|
-
initStr = AttributeUtil.transformSrc(initStr, fileDir, root);
|
|
119
|
-
}
|
|
120
|
-
const attributeItem = AttributeUtil.assignProp(obj.getInitializer(), {
|
|
121
|
-
name: eventName,
|
|
122
|
-
initializer: initStr
|
|
123
|
-
});
|
|
124
|
-
return {
|
|
125
|
-
type: attributeName,
|
|
126
|
-
attributeItem,
|
|
127
|
-
isDynamic: funcNode ? this.isDynamicValue(funcNode) : false
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* 根据表达式式节点的内容,向 object 对象添加属性
|
|
133
|
-
*
|
|
134
|
-
* @description 根据 style({backgrourd:'red'}) 向 {} 添加 style: { backgrourd:'red' } 属性
|
|
135
|
-
*
|
|
136
|
-
* @param expressNode
|
|
137
|
-
* @param target
|
|
138
|
-
* @returns
|
|
139
|
-
*/
|
|
140
|
-
static addStyle(expressNode, styleType, map, index, fileDir, root) {
|
|
141
|
-
const key = AttributeUtil.createVarName(styleType, index);
|
|
142
|
-
const variableStatement = map.get(key);
|
|
143
|
-
const obj = variableStatement.getDeclarations()[0];
|
|
144
|
-
const value = expressNode.value[0]
|
|
145
|
-
// TODO: value 有可能不是对象的情况
|
|
146
|
-
;
|
|
147
|
-
value.getProperties().forEach(prop => {
|
|
148
|
-
const oldStyle = obj.getInitializer();
|
|
149
|
-
let initializer = prop.getInitializer().getText();
|
|
150
|
-
// 如果是 图片相关的属性,需要进行转换
|
|
151
|
-
if (_AttributeType.default.ImageAttrs.includes(_sharedUtils.StringUtil.removeQuotes(prop.getName()))) {
|
|
152
|
-
initializer = AttributeUtil.transformSrc(initializer, fileDir, root);
|
|
153
|
-
}
|
|
154
|
-
AttributeUtil.assignProp(oldStyle, {
|
|
155
|
-
name: prop.getName(),
|
|
156
|
-
initializer
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
return {
|
|
160
|
-
type: styleType,
|
|
161
|
-
attributeItem: obj,
|
|
162
|
-
isDynamic: value ? this.isDynamicValue(value) : false
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/** 给一个对象节点添加属性,若已存在则删除原属性后添加 */
|
|
167
|
-
static assignProp(tar, structure) {
|
|
168
|
-
const allProps = tar.getProperties();
|
|
169
|
-
for (const p of allProps) {
|
|
170
|
-
if (p.getName() === structure.name) {
|
|
171
|
-
p.remove();
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return tar.addPropertyAssignment(structure);
|
|
176
|
-
}
|
|
177
|
-
static createVarName(type, index) {
|
|
178
|
-
return `${type}_${index}`;
|
|
179
|
-
}
|
|
180
|
-
static reverseVarName(name) {
|
|
181
|
-
return name.replace(/_\d/, '');
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* 将图片的 src 相对路径改为从根路径开始的绝对路径
|
|
186
|
-
* @param src 用户设置的 src
|
|
187
|
-
* @param fileDir 该文件的目录
|
|
188
|
-
* @param root 项目根目录
|
|
189
|
-
*/
|
|
190
|
-
static transformSrc(src, fileDir, root) {
|
|
191
|
-
// 网络地址不用处理
|
|
192
|
-
if (src.startsWith('http')) return src;
|
|
193
|
-
|
|
194
|
-
// 绝对路径
|
|
195
|
-
const p1 = _path.default.resolve(fileDir, _sharedUtils.StringUtil.removeQuotes(src));
|
|
196
|
-
return `'${p1.replace(root, '').replace('/src', '')}'`;
|
|
197
|
-
}
|
|
198
|
-
static getFrameworkImportFrom(srouceFilePath, root) {
|
|
199
|
-
const frameworkPath = require.resolve(_Framework.tsFrameWork.name, {
|
|
200
|
-
paths: [root]
|
|
201
|
-
});
|
|
202
|
-
const res = _path.default.relative(srouceFilePath, frameworkPath).replace(/\\/g, '/');
|
|
203
|
-
return res.replace('.ts', '');
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
var _default = exports.default = AttributeUtil;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ClassDeclaration, PropertyDeclaration, TypeReferenceNode } from 'ts-morph';
|
|
2
|
-
/**
|
|
3
|
-
* TypeUtil
|
|
4
|
-
*/
|
|
5
|
-
declare class TypeUtil {
|
|
6
|
-
static SIMPLE_DATA_TYPE: string[];
|
|
7
|
-
static PRIMAITIVE_TYPES: string[];
|
|
8
|
-
static COMPLEX_DTAT_TYPE: string[];
|
|
9
|
-
static SPECIAL_DECORATORS: string[];
|
|
10
|
-
static SPECIAL_PARENT_DECORATORS: {
|
|
11
|
-
label: string;
|
|
12
|
-
replaceLabel: string;
|
|
13
|
-
}[];
|
|
14
|
-
/**
|
|
15
|
-
* 判断类型是否是 ts 原始类型
|
|
16
|
-
* @param type
|
|
17
|
-
* @returns
|
|
18
|
-
*/
|
|
19
|
-
static isPrimitiveType(type?: string): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* 判断数据类型是否为简单类型
|
|
22
|
-
* @param dataType
|
|
23
|
-
* @returns
|
|
24
|
-
*/
|
|
25
|
-
static isSimpleType(dataType?: string): boolean | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* 判断数据类型是否为自定义类型
|
|
28
|
-
* @param dataType
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
|
-
static isCustomType(dataType: TypeReferenceNode): boolean;
|
|
32
|
-
/**
|
|
33
|
-
* 判断类节点是否为一般类
|
|
34
|
-
* @param sourceNode
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
static isNormalClass(sourceNode: ClassDeclaration): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* 判断节点identifier是否为特殊类关键词,并返回匹配项
|
|
40
|
-
* @param sourceText
|
|
41
|
-
* @returns
|
|
42
|
-
*/
|
|
43
|
-
static getSpecialParentDecorator(sourceText: string): {
|
|
44
|
-
label: string;
|
|
45
|
-
replaceLabel: string;
|
|
46
|
-
} | undefined;
|
|
47
|
-
/**
|
|
48
|
-
* 获取数据节点的特定修饰符
|
|
49
|
-
* @param node
|
|
50
|
-
* @returns
|
|
51
|
-
*/
|
|
52
|
-
static getSpecialDecorator(node: PropertyDeclaration): string | undefined;
|
|
53
|
-
/**
|
|
54
|
-
* 获取数据节点的特定修饰符是否为'@Prop', '@PropRequired'
|
|
55
|
-
* @param node
|
|
56
|
-
* @returns
|
|
57
|
-
*/
|
|
58
|
-
static isDecoratorProps(node: PropertyDeclaration): boolean | "" | undefined;
|
|
59
|
-
}
|
|
60
|
-
export default TypeUtil;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* TypeUtil
|
|
9
|
-
*/
|
|
10
|
-
class TypeUtil {
|
|
11
|
-
static SIMPLE_DATA_TYPE = ['string', 'number', 'boolean', 'Date'];
|
|
12
|
-
static PRIMAITIVE_TYPES = ['number', 'string', 'boolean', 'null', 'undefined', 'symbol'];
|
|
13
|
-
static COMPLEX_DTAT_TYPE = ['Array', 'Map', 'Set'];
|
|
14
|
-
static SPECIAL_DECORATORS = ['@State', '@Prop', '@PropRequired'];
|
|
15
|
-
static SPECIAL_PARENT_DECORATORS = [{
|
|
16
|
-
label: 'app',
|
|
17
|
-
replaceLabel: `@parentClass(App) class`
|
|
18
|
-
}, {
|
|
19
|
-
label: 'vaspect',
|
|
20
|
-
replaceLabel: `@parentClass(ViewAspect) class`
|
|
21
|
-
}, {
|
|
22
|
-
label: 'component',
|
|
23
|
-
replaceLabel: `@parentClass(Component) class`
|
|
24
|
-
}];
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 判断类型是否是 ts 原始类型
|
|
28
|
-
* @param type
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
|
-
static isPrimitiveType(type) {
|
|
32
|
-
if (!type) return false;
|
|
33
|
-
return this.PRIMAITIVE_TYPES.includes(type);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 判断数据类型是否为简单类型
|
|
38
|
-
* @param dataType
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
static isSimpleType(dataType) {
|
|
42
|
-
if (!dataType) return;
|
|
43
|
-
return this.SIMPLE_DATA_TYPE.includes(dataType);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* 判断数据类型是否为自定义类型
|
|
47
|
-
* @param dataType
|
|
48
|
-
* @returns
|
|
49
|
-
*/
|
|
50
|
-
static isCustomType(dataType) {
|
|
51
|
-
const name = dataType?.getTypeName().getText();
|
|
52
|
-
return !this.COMPLEX_DTAT_TYPE.includes(name);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* 判断类节点是否为一般类
|
|
56
|
-
* @param sourceNode
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
static isNormalClass(sourceNode) {
|
|
60
|
-
const decorators = sourceNode.getDecorators();
|
|
61
|
-
return !decorators.find(decorator => {
|
|
62
|
-
const decoratorContent = decorator.getText();
|
|
63
|
-
return this.SPECIAL_PARENT_DECORATORS.some(item => item.replaceLabel === `${decoratorContent} class`);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* 判断节点identifier是否为特殊类关键词,并返回匹配项
|
|
68
|
-
* @param sourceText
|
|
69
|
-
* @returns
|
|
70
|
-
*/
|
|
71
|
-
static getSpecialParentDecorator(sourceText) {
|
|
72
|
-
const matched = this.SPECIAL_PARENT_DECORATORS.find(item => item.label === sourceText);
|
|
73
|
-
return matched;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* 获取数据节点的特定修饰符
|
|
77
|
-
* @param node
|
|
78
|
-
* @returns
|
|
79
|
-
*/
|
|
80
|
-
static getSpecialDecorator(node) {
|
|
81
|
-
const decorators = node.getDecorators();
|
|
82
|
-
const specialDecoratorNode = decorators.find(dec => {
|
|
83
|
-
return this.SPECIAL_DECORATORS.includes(dec.getText());
|
|
84
|
-
});
|
|
85
|
-
return specialDecoratorNode?.getText();
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* 获取数据节点的特定修饰符是否为'@Prop', '@PropRequired'
|
|
89
|
-
* @param node
|
|
90
|
-
* @returns
|
|
91
|
-
*/
|
|
92
|
-
static isDecoratorProps(node) {
|
|
93
|
-
const spDecoratorStr = this.getSpecialDecorator(node);
|
|
94
|
-
return spDecoratorStr && spDecoratorStr !== this.SPECIAL_DECORATORS[0];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
var _default = exports.default = TypeUtil;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { IPosition } from '@aiot-toolkit/shared-utils';
|
|
2
|
-
import { Block, ExpressionStatement, Node, SourceFile, ts } from 'ts-morph';
|
|
3
|
-
import IOffset from '../../interface/IOffset';
|
|
4
|
-
import IExpressNode from '../interface/IExpressNode';
|
|
5
|
-
/**
|
|
6
|
-
* TypescriptUtil
|
|
7
|
-
*/
|
|
8
|
-
declare class TypescriptUtil {
|
|
9
|
-
/**
|
|
10
|
-
* 拆分表达式为多个节点列表
|
|
11
|
-
*
|
|
12
|
-
* 一个表达式可能包含多项值,且是反向的,需要分离并把顺序调正
|
|
13
|
-
*
|
|
14
|
-
* 例如 a().width(100).height(200) 1个表达式包含3项,且第1项是 height,最后一项是 a;需要分离为 [a, width, height]
|
|
15
|
-
* @param node
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
static splitExpression(expression: ExpressionStatement): IExpressNode[];
|
|
19
|
-
static throwError(message: string, node?: Node, sourceFile?: SourceFile, offsetList?: IOffset[]): void;
|
|
20
|
-
/**
|
|
21
|
-
* 获取目标代码的节点在源码中的位置
|
|
22
|
-
* @param node 节点
|
|
23
|
-
* @param sourceFile 目标文件对象
|
|
24
|
-
* @param offsetList 源码相对目标代码的偏移量列表
|
|
25
|
-
* @returns
|
|
26
|
-
*/
|
|
27
|
-
static getNodePostion(node: Node, sourceFile: SourceFile, offsetList?: IOffset[]): IPosition;
|
|
28
|
-
/**
|
|
29
|
-
* 通过 getChildren 方法获取 block 的子元素
|
|
30
|
-
*
|
|
31
|
-
* 例如,下面的代码,需要获取 Row 的子元素列表
|
|
32
|
-
* ```
|
|
33
|
-
* Row(){
|
|
34
|
-
* Button().x(10)
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
* @param block
|
|
38
|
-
* @returns
|
|
39
|
-
*/
|
|
40
|
-
static getBlockChildren(block: Block): Node<ts.Node>[];
|
|
41
|
-
}
|
|
42
|
-
export default TypescriptUtil;
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _sharedUtils = require("@aiot-toolkit/shared-utils");
|
|
8
|
-
var _tsMorph = require("ts-morph");
|
|
9
|
-
var _ParserUtil = _interopRequireDefault(require("../../utils/ParserUtil"));
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
/**
|
|
12
|
-
* TypescriptUtil
|
|
13
|
-
*/
|
|
14
|
-
class TypescriptUtil {
|
|
15
|
-
/**
|
|
16
|
-
* 拆分表达式为多个节点列表
|
|
17
|
-
*
|
|
18
|
-
* 一个表达式可能包含多项值,且是反向的,需要分离并把顺序调正
|
|
19
|
-
*
|
|
20
|
-
* 例如 a().width(100).height(200) 1个表达式包含3项,且第1项是 height,最后一项是 a;需要分离为 [a, width, height]
|
|
21
|
-
* @param node
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
static splitExpression(expression) {
|
|
25
|
-
const result = [];
|
|
26
|
-
let currentItem = expression.getExpression();
|
|
27
|
-
while (currentItem) {
|
|
28
|
-
if (currentItem.getKind() === _tsMorph.SyntaxKind.CallExpression) {
|
|
29
|
-
const express = currentItem.getExpression();
|
|
30
|
-
// 属性节点 row().width()中的 width()
|
|
31
|
-
if (express instanceof _tsMorph.PropertyAccessExpression) {
|
|
32
|
-
result.push({
|
|
33
|
-
name: express.getNameNode(),
|
|
34
|
-
value: currentItem.getArguments()
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
// 起始节点 row().width()中的 row()
|
|
38
|
-
else if (_tsMorph.ts.isIdentifier(express.compilerNode)) {
|
|
39
|
-
result.push({
|
|
40
|
-
name: express,
|
|
41
|
-
value: currentItem.getArguments()
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (currentItem.getExpression) {
|
|
46
|
-
currentItem = currentItem.getExpression();
|
|
47
|
-
} else {
|
|
48
|
-
currentItem = undefined;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return result.reverse();
|
|
52
|
-
}
|
|
53
|
-
static throwError(message, node, sourceFile, offsetList) {
|
|
54
|
-
let str = message;
|
|
55
|
-
if (node) {
|
|
56
|
-
const position = sourceFile ? this.getNodePostion(node, sourceFile, offsetList) : undefined;
|
|
57
|
-
str = JSON.stringify({
|
|
58
|
-
message,
|
|
59
|
-
code: node.getText(),
|
|
60
|
-
position
|
|
61
|
-
}, undefined, 2);
|
|
62
|
-
if (position) {
|
|
63
|
-
throw new _sharedUtils.PositionError(position, str);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
throw new Error(str);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* 获取目标代码的节点在源码中的位置
|
|
71
|
-
* @param node 节点
|
|
72
|
-
* @param sourceFile 目标文件对象
|
|
73
|
-
* @param offsetList 源码相对目标代码的偏移量列表
|
|
74
|
-
* @returns
|
|
75
|
-
*/
|
|
76
|
-
static getNodePostion(node, sourceFile) {
|
|
77
|
-
let offsetList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
78
|
-
const start = node.getStart();
|
|
79
|
-
const end = node.getEnd();
|
|
80
|
-
const offset = offsetList ? _ParserUtil.default.getOffsetPos(start, offsetList) : 0;
|
|
81
|
-
const {
|
|
82
|
-
line: startLine,
|
|
83
|
-
column: startColumn
|
|
84
|
-
} = sourceFile.getLineAndColumnAtPos(start);
|
|
85
|
-
const {
|
|
86
|
-
line: endLine,
|
|
87
|
-
column: endColumn
|
|
88
|
-
} = sourceFile.getLineAndColumnAtPos(end);
|
|
89
|
-
const columnOffset = _ParserUtil.default.getOffsetColumn({
|
|
90
|
-
line: startLine,
|
|
91
|
-
pos: start
|
|
92
|
-
}, offsetList);
|
|
93
|
-
return {
|
|
94
|
-
pos: start + offset,
|
|
95
|
-
end: end + offset,
|
|
96
|
-
startLine,
|
|
97
|
-
startColumn: startColumn + columnOffset,
|
|
98
|
-
endLine,
|
|
99
|
-
endColumn: endColumn + columnOffset
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 通过 getChildren 方法获取 block 的子元素
|
|
105
|
-
*
|
|
106
|
-
* 例如,下面的代码,需要获取 Row 的子元素列表
|
|
107
|
-
* ```
|
|
108
|
-
* Row(){
|
|
109
|
-
* Button().x(10)
|
|
110
|
-
* }
|
|
111
|
-
* ```
|
|
112
|
-
* @param block
|
|
113
|
-
* @returns
|
|
114
|
-
*/
|
|
115
|
-
static getBlockChildren(block) {
|
|
116
|
-
if (!block) {
|
|
117
|
-
return [];
|
|
118
|
-
}
|
|
119
|
-
const blockChildren = block.getChildren();
|
|
120
|
-
// 获取SyntaxKind.SyntaxList的节点,并获取它的children
|
|
121
|
-
const syntaxListNode = blockChildren.find(item => item.getKind() === _tsMorph.SyntaxKind.SyntaxList);
|
|
122
|
-
if (syntaxListNode) {
|
|
123
|
-
return syntaxListNode.getChildren();
|
|
124
|
-
}
|
|
125
|
-
return [];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
var _default = exports.default = TypescriptUtil;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import IContext from '../interface/IContext';
|
|
2
|
-
import IExpressNode from '../interface/IExpressNode';
|
|
3
|
-
import IAttibuteValidate from '../interface/validate/IAttibuteValidate';
|
|
4
|
-
/**
|
|
5
|
-
* AttibuteValidate
|
|
6
|
-
*/
|
|
7
|
-
declare class AttibuteValidate implements IAttibuteValidate {
|
|
8
|
-
private TRANSLATE_TYPE;
|
|
9
|
-
validate(element: IExpressNode, context: IContext, componentName: string): Error[];
|
|
10
|
-
private isISubTypeArray;
|
|
11
|
-
/**
|
|
12
|
-
* 检查属性类型是否正确
|
|
13
|
-
* @param elemType
|
|
14
|
-
* @param attrType
|
|
15
|
-
*/
|
|
16
|
-
private checkElemType;
|
|
17
|
-
}
|
|
18
|
-
export default AttibuteValidate;
|