@lcap/nasl 4.3.0-beta.9 → 4.3.0-creator.2
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/out/generator/genBundleFiles.d.ts +1 -0
- package/out/generator/genBundleFiles.d.ts.map +1 -1
- package/out/generator/genBundleFiles.js +2 -1
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/genSimpleBundleFile.d.ts +19 -0
- package/out/generator/genSimpleBundleFile.d.ts.map +1 -0
- package/out/generator/genSimpleBundleFile.js +114 -0
- package/out/generator/genSimpleBundleFile.js.map +1 -0
- package/out/generator/index.d.ts +1 -0
- package/out/generator/index.d.ts.map +1 -1
- package/out/generator/index.js +1 -0
- package/out/generator/index.js.map +1 -1
- package/out/generator/release-body/data.d.ts.map +1 -1
- package/out/generator/release-body/data.js +2 -0
- package/out/generator/release-body/data.js.map +1 -1
- package/out/generator/release-body/utils.d.ts.map +1 -1
- package/out/generator/release-body/utils.js +2 -1
- package/out/generator/release-body/utils.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +2 -1
- package/out/index.js.map +1 -1
- package/out/natural/index.d.ts +2 -0
- package/out/natural/index.d.ts.map +1 -1
- package/out/natural/index.js +4 -0
- package/out/natural/index.js.map +1 -1
- package/out/natural/parseNaturalTS.d.ts +5 -8
- package/out/natural/parseNaturalTS.d.ts.map +1 -1
- package/out/natural/parseNaturalTS.js +211 -50
- package/out/natural/parseNaturalTS.js.map +1 -1
- package/out/natural/parseNaturalTSXView.d.ts +18 -0
- package/out/natural/parseNaturalTSXView.d.ts.map +1 -0
- package/out/natural/parseNaturalTSXView.js +641 -0
- package/out/natural/parseNaturalTSXView.js.map +1 -0
- package/out/natural/transformTS2UI.d.ts.map +1 -1
- package/out/natural/transformTS2UI.js +16 -17
- package/out/natural/transformTS2UI.js.map +1 -1
- package/out/natural/transformTSCode.d.ts.map +1 -1
- package/out/natural/transformTSCode.js +4 -4
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/natural/transforms/transform2Entity.d.ts +3 -1
- package/out/natural/transforms/transform2Entity.d.ts.map +1 -1
- package/out/natural/transforms/transform2Entity.js +31 -7
- package/out/natural/transforms/transform2Entity.js.map +1 -1
- package/out/natural/transforms/transform2Enum.d.ts +3 -1
- package/out/natural/transforms/transform2Enum.d.ts.map +1 -1
- package/out/natural/transforms/transform2Enum.js +19 -3
- package/out/natural/transforms/transform2Enum.js.map +1 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts +3 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.d.ts.map +1 -1
- package/out/natural/transforms/transform2GlobalLogicDeclaration.js +3 -3
- package/out/natural/transforms/transform2GlobalLogicDeclaration.js.map +1 -1
- package/out/natural/transforms/transform2Logic.d.ts +9 -1
- package/out/natural/transforms/transform2Logic.d.ts.map +1 -1
- package/out/natural/transforms/transform2Logic.js +44 -7
- package/out/natural/transforms/transform2Logic.js.map +1 -1
- package/out/natural/transforms/transform2LogicItem.d.ts +61 -28
- package/out/natural/transforms/transform2LogicItem.d.ts.map +1 -1
- package/out/natural/transforms/transform2LogicItem.js +459 -198
- package/out/natural/transforms/transform2LogicItem.js.map +1 -1
- package/out/natural/transforms/transform2MetadataType.d.ts +5 -0
- package/out/natural/transforms/transform2MetadataType.d.ts.map +1 -0
- package/out/natural/transforms/transform2MetadataType.js +14 -0
- package/out/natural/transforms/transform2MetadataType.js.map +1 -0
- package/out/natural/transforms/transform2Structure.d.ts +3 -1
- package/out/natural/transforms/transform2Structure.d.ts.map +1 -1
- package/out/natural/transforms/transform2Structure.js +4 -4
- package/out/natural/transforms/transform2Structure.js.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.d.ts +3 -1
- package/out/natural/transforms/transform2TypeAnnotation.d.ts.map +1 -1
- package/out/natural/transforms/transform2TypeAnnotation.js +15 -11
- package/out/natural/transforms/transform2TypeAnnotation.js.map +1 -1
- package/out/natural/transforms/transform2ValidationRule.d.ts +5 -0
- package/out/natural/transforms/transform2ValidationRule.d.ts.map +1 -0
- package/out/natural/transforms/transform2ValidationRule.js +24 -0
- package/out/natural/transforms/transform2ValidationRule.js.map +1 -0
- package/out/natural/transforms/transform2Variable.d.ts +6 -1
- package/out/natural/transforms/transform2Variable.d.ts.map +1 -1
- package/out/natural/transforms/transform2Variable.js +30 -6
- package/out/natural/transforms/transform2Variable.js.map +1 -1
- package/out/natural/transforms/transformThemeAndStyle.d.ts +28 -0
- package/out/natural/transforms/transformThemeAndStyle.d.ts.map +1 -0
- package/out/natural/transforms/transformThemeAndStyle.js +269 -0
- package/out/natural/transforms/transformThemeAndStyle.js.map +1 -0
- package/out/natural/transforms/utils.d.ts +22 -3
- package/out/natural/transforms/utils.d.ts.map +1 -1
- package/out/natural/transforms/utils.js +80 -12
- package/out/natural/transforms/utils.js.map +1 -1
- package/out/server/OQL/oql-cache.d.ts.map +1 -1
- package/out/server/OQL/oql-cache.js +3 -1
- package/out/server/OQL/oql-cache.js.map +1 -1
- package/out/server/OQL/sqlCategory.json +410 -0
- package/out/server/OQL/sqlFunctions.json +695 -7
- package/out/server/extendBaseNode.js +1 -1
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/index.d.ts +1 -0
- package/out/server/index.d.ts.map +1 -1
- package/out/server/index.js +1 -0
- package/out/server/index.js.map +1 -1
- package/out/server/naslServer.d.ts +6 -1
- package/out/server/naslServer.d.ts.map +1 -1
- package/out/server/naslServer.js +76 -21
- package/out/server/naslServer.js.map +1 -1
- package/out/service/autofix/rules/rule-delete-void-expression.d.ts.map +1 -1
- package/out/service/autofix/rules/rule-delete-void-expression.js +5 -1
- package/out/service/autofix/rules/rule-delete-void-expression.js.map +1 -1
- package/out/service/creator/errHandles.js +0 -5
- package/out/service/creator/errHandles.js.map +1 -1
- package/out/service/initial/form-designer.d.ts +1 -1
- package/out/service/initial/form-designer.d.ts.map +1 -1
- package/out/service/initial/form-designer.js +4 -1
- package/out/service/initial/form-designer.js.map +1 -1
- package/out/service/initial/processV2.d.ts +1 -1
- package/out/service/initial/processV2.d.ts.map +1 -1
- package/out/service/initial/processV2.js +4 -1
- package/out/service/initial/processV2.js.map +1 -1
- package/out/service/initial/types.d.ts +1 -0
- package/out/service/initial/types.d.ts.map +1 -1
- package/out/service/storage/init.d.ts +5 -0
- package/out/service/storage/init.d.ts.map +1 -1
- package/out/service/storage/init.js +9 -3
- package/out/service/storage/init.js.map +1 -1
- package/out/service/storage/service.d.ts.map +1 -1
- package/out/service/storage/service.js +1 -0
- package/out/service/storage/service.js.map +1 -1
- package/out/templator/utils.d.ts +16 -7
- package/out/templator/utils.d.ts.map +1 -1
- package/out/templator/utils.js +14 -2
- package/out/templator/utils.js.map +1 -1
- package/package.json +14 -12
- package/sandbox/stdlib/nasl.io.ts +10 -0
- package/sandbox/stdlib/nasl.oql.ts +1 -0
- package/sandbox/stdlib/nasl.ui.ts +1 -9
- package/out/natural/transforms/registerTransform.d.ts +0 -8
- package/out/natural/transforms/registerTransform.d.ts.map +0 -1
- package/out/natural/transforms/registerTransform.js +0 -24
- package/out/natural/transforms/registerTransform.js.map +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { babelTypes, naslTypes } from './transforms/utils';
|
|
2
|
+
export declare function transform2Variables(node: babelTypes.VariableDeclaration, options?: {
|
|
3
|
+
parsingId?: number;
|
|
4
|
+
}): naslTypes.Variable[];
|
|
5
|
+
export declare function transformJSXElement2ViewElement(node: babelTypes.JSXElement, options?: {
|
|
6
|
+
parsingId?: number;
|
|
7
|
+
nameMap?: Map<string, boolean>;
|
|
8
|
+
}): naslTypes.ViewElement | void;
|
|
9
|
+
export declare function transform2View(func: babelTypes.FunctionDeclaration, decorator?: babelTypes.CallExpression, options?: {
|
|
10
|
+
parsingId?: number;
|
|
11
|
+
}): naslTypes.View;
|
|
12
|
+
export declare function transformTSDeclareFunction2View(func: babelTypes.TSDeclareFunction, decorator?: babelTypes.CallExpression, options?: {
|
|
13
|
+
parsingId?: number;
|
|
14
|
+
}): naslTypes.View;
|
|
15
|
+
export declare function parseNaturalTSXView(tsCode: string, options?: {
|
|
16
|
+
parsingId?: number;
|
|
17
|
+
}): naslTypes.View;
|
|
18
|
+
//# sourceMappingURL=parseNaturalTSXView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseNaturalTSXView.d.ts","sourceRoot":"","sources":["../../src/natural/parseNaturalTSXView.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAoD,MAAM,oBAAoB,CAAC;AAiB7G,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,CAAC,mBAAmB,EAAE,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,CAmBhI;AA4BD,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,UAAU,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAAG,SAAS,CAAC,WAAW,GAAG,IAAI,CAgV3K;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,CAAC,mBAAmB,EAAE,SAAS,CAAC,EAAE,UAAU,CAAC,cAAc,EAAE,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,kBAwG3I;AAED,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,UAAU,CAAC,iBAAiB,EAAE,SAAS,CAAC,EAAE,UAAU,CAAC,cAAc,EAAE,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,kBAiC1J;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,kBA0BnF"}
|
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.parseNaturalTSXView = exports.transformTSDeclareFunction2View = exports.transform2View = exports.transformJSXElement2ViewElement = exports.transform2Variables = void 0;
|
|
27
|
+
/* eslint-disable global-require */
|
|
28
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
29
|
+
const utils_1 = require("./transforms/utils");
|
|
30
|
+
const lodash_1 = require("lodash");
|
|
31
|
+
const babel = __importStar(require("@babel/core"));
|
|
32
|
+
const utils_2 = require("../utils");
|
|
33
|
+
const transform2TypeAnnotation_1 = require("./transforms/transform2TypeAnnotation");
|
|
34
|
+
const transform2LogicItem_1 = require("./transforms/transform2LogicItem");
|
|
35
|
+
const transform2Logic_1 = require("./transforms/transform2Logic");
|
|
36
|
+
const transform2ValidationRule_1 = require("./transforms/transform2ValidationRule");
|
|
37
|
+
const transformThemeAndStyle_1 = require("./transforms/transformThemeAndStyle");
|
|
38
|
+
function transform2Variables(node, options) {
|
|
39
|
+
const variables = [];
|
|
40
|
+
const declList = node?.declarations || [];
|
|
41
|
+
declList.forEach((decl) => {
|
|
42
|
+
const variableName = decl.id.name;
|
|
43
|
+
let typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(decl.id.typeAnnotation?.typeAnnotation, options) || undefined;
|
|
44
|
+
const variable = new utils_1.naslTypes.Variable({
|
|
45
|
+
name: variableName,
|
|
46
|
+
typeAnnotation,
|
|
47
|
+
});
|
|
48
|
+
if (decl.init) {
|
|
49
|
+
variable.defaultValue = new utils_1.naslTypes.DefaultValue({
|
|
50
|
+
expression: (0, transform2LogicItem_1.transform2LogicItem)(decl.init, { ...options, transformType: 'attr', typeAnnotation, isRestricted: true, isInFrontend: true }),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
variables.push(variable);
|
|
54
|
+
});
|
|
55
|
+
return variables;
|
|
56
|
+
}
|
|
57
|
+
exports.transform2Variables = transform2Variables;
|
|
58
|
+
function transform2EventLogics(node, eventName, options) {
|
|
59
|
+
if (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') {
|
|
60
|
+
const logic = (0, transform2Logic_1.transform2Logic)(node, eventName, options);
|
|
61
|
+
logic.params = [];
|
|
62
|
+
return [logic];
|
|
63
|
+
}
|
|
64
|
+
else if (node.type === 'CallExpression') {
|
|
65
|
+
if (node.callee.type === 'Identifier' && node.callee.name === '$all') {
|
|
66
|
+
const args = node.arguments;
|
|
67
|
+
return args.map((node) => {
|
|
68
|
+
if (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') {
|
|
69
|
+
const logic = (0, transform2Logic_1.transform2Logic)(node, eventName, options);
|
|
70
|
+
logic.params = [];
|
|
71
|
+
return logic;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return (0, utils_1.throwError)(options?.parsingId, '事件逻辑参数不支持的类型', node.type, node);
|
|
75
|
+
}
|
|
76
|
+
}).filter(Boolean);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return (0, utils_1.throwError)(options?.parsingId, '事件逻辑参数不正确', node);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return (0, utils_1.throwError)(options?.parsingId, '事件逻辑参数不正确', node);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function transformJSXElement2ViewElement(node, options) {
|
|
87
|
+
const el = node.openingElement;
|
|
88
|
+
if (el.name.type === 'JSXIdentifier') {
|
|
89
|
+
let tag = (0, lodash_1.kebabCase)(el.name.name);
|
|
90
|
+
if (tag === 'el-form-date-time-picker')
|
|
91
|
+
tag = 'el-form-date-picker';
|
|
92
|
+
if (tag === 'el-form-input-date')
|
|
93
|
+
tag = 'el-form-date-picker';
|
|
94
|
+
if (tag === 'el-form-textarea')
|
|
95
|
+
tag = 'el-form-input';
|
|
96
|
+
if (tag === 'el-form-item')
|
|
97
|
+
tag = 'el-form-input';
|
|
98
|
+
const viewElement = new utils_1.naslTypes.ViewElement({
|
|
99
|
+
tag,
|
|
100
|
+
});
|
|
101
|
+
const attrs = el.attributes;
|
|
102
|
+
let directivePrefix = '$';
|
|
103
|
+
let eventPrefix = 'on';
|
|
104
|
+
let slotPrefix = 'slot';
|
|
105
|
+
function addJSXChild(node, slotTarget = 'default', slotScope = '') {
|
|
106
|
+
if (node.type === 'JSXElement') {
|
|
107
|
+
if (slotTarget === 'default' && !slotScope) {
|
|
108
|
+
const child = transformJSXElement2ViewElement(node, options);
|
|
109
|
+
child && viewElement.children.push(child);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const child = transformJSXElement2ViewElement(node, options);
|
|
113
|
+
let templateName = 'template_' + (0, utils_2.uuidv4)().slice(0, 5);
|
|
114
|
+
// 确保模板名称也不重复
|
|
115
|
+
while (options.nameMap.has(templateName)) {
|
|
116
|
+
templateName = 'template_' + (0, utils_2.uuidv4)().slice(0, 5);
|
|
117
|
+
}
|
|
118
|
+
options.nameMap.set(templateName, true);
|
|
119
|
+
const templateChild = new utils_1.naslTypes.ViewElement({
|
|
120
|
+
tag: 'template',
|
|
121
|
+
name: templateName,
|
|
122
|
+
slotTarget,
|
|
123
|
+
slotScope,
|
|
124
|
+
children: child ? [child] : [],
|
|
125
|
+
});
|
|
126
|
+
if (viewElement.children.some((child) => child.tag === 'template' && child.slotTarget === slotTarget))
|
|
127
|
+
(0, utils_1.throwError)(options?.parsingId, `slot${(0, utils_2.firstUpperCase)(slotTarget)} 不能重复`, node);
|
|
128
|
+
viewElement.children.push(templateChild);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (node.type === 'JSXFragment') {
|
|
132
|
+
const children = node.children;
|
|
133
|
+
if (slotTarget === 'default' && !slotScope) {
|
|
134
|
+
viewElement.children.push(...children.filter((child) => child.type === 'JSXElement').map((child) => transformJSXElement2ViewElement(child, options)).filter(Boolean));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
let templateName = 'template_' + (0, utils_2.uuidv4)().slice(0, 5);
|
|
138
|
+
// 确保模板名称也不重复
|
|
139
|
+
while (options.nameMap.has(templateName)) {
|
|
140
|
+
templateName = 'template_' + (0, utils_2.uuidv4)().slice(0, 5);
|
|
141
|
+
}
|
|
142
|
+
options.nameMap.set(templateName, true);
|
|
143
|
+
const templateChild = new utils_1.naslTypes.ViewElement({
|
|
144
|
+
tag: 'template',
|
|
145
|
+
name: templateName,
|
|
146
|
+
slotTarget,
|
|
147
|
+
slotScope,
|
|
148
|
+
children: children.filter((child) => child.type === 'JSXElement').map((child) => transformJSXElement2ViewElement(child, options)).filter(Boolean),
|
|
149
|
+
});
|
|
150
|
+
if (viewElement.children.some((child) => child.tag === 'template' && child.slotTarget === slotTarget))
|
|
151
|
+
(0, utils_1.throwError)(options?.parsingId, `slot${(0, utils_2.firstUpperCase)(slotTarget)} 不能重复`, node);
|
|
152
|
+
viewElement.children.push(templateChild);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的JSX子元素类型', node);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function addArrowFunctionJSXChild(node, slotTarget = 'default') {
|
|
160
|
+
const slotScopeName = node.params[0]?.name;
|
|
161
|
+
if (slotScopeName && slotScopeName !== 'current' && !slotScopeName?.startsWith('current')) {
|
|
162
|
+
return (0, utils_1.throwError)(options?.parsingId, `slotScope 需以 current 参数名开头`, node);
|
|
163
|
+
}
|
|
164
|
+
let slotScope = '';
|
|
165
|
+
if (slotScopeName) {
|
|
166
|
+
slotScope = 'current';
|
|
167
|
+
}
|
|
168
|
+
const body = node.body;
|
|
169
|
+
if (body.type === 'JSXElement' || body.type === 'JSXFragment') {
|
|
170
|
+
addJSXChild(body, slotTarget, slotScope);
|
|
171
|
+
}
|
|
172
|
+
else if (body.type === 'ArrayExpression') {
|
|
173
|
+
const elements = body.elements;
|
|
174
|
+
elements.forEach((element) => {
|
|
175
|
+
addJSXChild(element, slotTarget, slotScope);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的JSX子元素类型', body.type, body);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
attrs.forEach((attr) => {
|
|
183
|
+
if (attr.type === 'JSXAttribute') {
|
|
184
|
+
const attrName = attr.name.name;
|
|
185
|
+
if (attrName === 'ref') {
|
|
186
|
+
if (attr.value?.type === 'StringLiteral') {
|
|
187
|
+
const proposedName = attr.value.value;
|
|
188
|
+
if (options.nameMap.has(proposedName)) {
|
|
189
|
+
return (0, utils_1.throwError)(options?.parsingId, `ref 属性值 "${proposedName}" 已存在,不能重复使用`, attr);
|
|
190
|
+
}
|
|
191
|
+
viewElement.name = proposedName;
|
|
192
|
+
options.nameMap.set(proposedName, true);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
return (0, utils_1.throwError)(options?.parsingId, 'ref 属性值不正确', attr.value);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (attrName === 'style') {
|
|
199
|
+
if (attr.value?.type === 'StringLiteral') {
|
|
200
|
+
viewElement.staticStyle = attr.value.value;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
return (0, utils_1.throwError)(options?.parsingId, 'style 属性只能用字符串字面量', attr.value);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else if (attrName === '$extraStyle') {
|
|
207
|
+
if (!attr.value) {
|
|
208
|
+
(0, utils_1.throwError)(options?.parsingId, '$extraStyle 属性只能用字符串字面量', attr);
|
|
209
|
+
}
|
|
210
|
+
else if (attr.value.type === 'StringLiteral') {
|
|
211
|
+
viewElement.cssRules = (0, transformThemeAndStyle_1.transformStyle)(attr.value.value, options);
|
|
212
|
+
}
|
|
213
|
+
else if (attr.value.type === 'JSXExpressionContainer') {
|
|
214
|
+
const templateLiteral = attr.value.expression;
|
|
215
|
+
if (templateLiteral.type === 'TemplateLiteral') {
|
|
216
|
+
if (templateLiteral.expressions.length > 0) {
|
|
217
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持在 $theme 中使用动态表达式');
|
|
218
|
+
}
|
|
219
|
+
const css = templateLiteral.quasis[0].value.raw;
|
|
220
|
+
viewElement.cssRules = (0, transformThemeAndStyle_1.transformStyle)(css, options);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
return (0, utils_1.throwError)(options?.parsingId, '$extraStyle 属性只能用字符串字面量', attr.value);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
return (0, utils_1.throwError)(options?.parsingId, '$extraStyle 属性只能用字符串字面量', attr.value);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else if (attrName === '$dynamicStyle') {
|
|
231
|
+
if (!attr.value) {
|
|
232
|
+
(0, utils_1.throwError)(options?.parsingId, '$dynamicStyle 属性只能用字符串字面量', attr);
|
|
233
|
+
}
|
|
234
|
+
else if (attr.value.type === 'JSXExpressionContainer') {
|
|
235
|
+
const expression = attr.value.expression;
|
|
236
|
+
if (expression.type === 'ObjectExpression') {
|
|
237
|
+
const properties = expression.properties;
|
|
238
|
+
properties.forEach((property) => {
|
|
239
|
+
if (property.type === 'ObjectProperty') {
|
|
240
|
+
const name = (0, lodash_1.kebabCase)(property.key.name);
|
|
241
|
+
viewElement.bindStyles = viewElement.bindStyles || [];
|
|
242
|
+
viewElement.addBindStyle(new utils_1.naslTypes.BindStyle({
|
|
243
|
+
name,
|
|
244
|
+
expression: (0, transform2LogicItem_1.transform2LogicItem)(property.value, {
|
|
245
|
+
...options,
|
|
246
|
+
transformType: 'attr',
|
|
247
|
+
isRestricted: true,
|
|
248
|
+
isInFrontend: true,
|
|
249
|
+
}),
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
return (0, utils_1.throwError)(options?.parsingId, 'style 属性值不正确', attr.value);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
else if (attrName.startsWith(directivePrefix)) {
|
|
260
|
+
const directiveName = attrName.slice(directivePrefix.length);
|
|
261
|
+
const directive = new utils_1.naslTypes.BindDirective({
|
|
262
|
+
name: directiveName,
|
|
263
|
+
});
|
|
264
|
+
if (!attr.value) {
|
|
265
|
+
directive.type = 'static';
|
|
266
|
+
directive.value = 'true';
|
|
267
|
+
}
|
|
268
|
+
else if (attr.value.type === 'StringLiteral') {
|
|
269
|
+
directive.type = 'string';
|
|
270
|
+
directive.value = attr.value.value;
|
|
271
|
+
}
|
|
272
|
+
else if (attr.value.type === 'JSXExpressionContainer') {
|
|
273
|
+
if (attr.value.expression.type === 'BooleanLiteral' || attr.value.expression.type === 'NumericLiteral' || attr.value.expression.type === 'NullLiteral' || attr.value.expression.type === 'StringLiteral') {
|
|
274
|
+
directive.type = 'static';
|
|
275
|
+
directive.value = (0, utils_1.generate)(attr.value.expression).code;
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
directive.type = 'dynamic';
|
|
279
|
+
if (attr.value.expression.type === 'FunctionExpression')
|
|
280
|
+
return (0, utils_1.throwError)(options?.parsingId, '指令不支持传函数表达式', attr);
|
|
281
|
+
directive.expression = (0, transform2LogicItem_1.transform2LogicItem)(attr.value.expression, {
|
|
282
|
+
...options,
|
|
283
|
+
transformType: 'attr',
|
|
284
|
+
isRestricted: true,
|
|
285
|
+
isInFrontend: true,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的指令类型', attr.value.type, attr.value);
|
|
291
|
+
}
|
|
292
|
+
if (directiveName !== 'for') {
|
|
293
|
+
viewElement.addBindDirective(directive);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else if (attrName.startsWith(eventPrefix)) {
|
|
297
|
+
const eventName = (0, utils_2.firstLowerCase)(attrName.slice(eventPrefix.length));
|
|
298
|
+
if (attr.value?.type === 'JSXExpressionContainer') {
|
|
299
|
+
const bindEvent = new utils_1.naslTypes.BindEvent({
|
|
300
|
+
name: eventName,
|
|
301
|
+
logics: transform2EventLogics(attr.value.expression, eventName, options) || [],
|
|
302
|
+
});
|
|
303
|
+
viewElement.addBindEvent(bindEvent);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
return (0, utils_1.throwError)(options?.parsingId, '事件逻辑参数不正确', attr.value);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else if (attrName.startsWith(slotPrefix)) {
|
|
310
|
+
const slotTarget = (0, utils_2.firstLowerCase)(attrName.slice(slotPrefix.length));
|
|
311
|
+
if (attr.value?.type === 'JSXExpressionContainer') {
|
|
312
|
+
const expression = attr.value.expression;
|
|
313
|
+
if (expression.type === 'JSXElement' || expression.type === 'JSXFragment') {
|
|
314
|
+
addJSXChild(expression, slotTarget);
|
|
315
|
+
}
|
|
316
|
+
else if (expression.type === 'ArrowFunctionExpression') {
|
|
317
|
+
addArrowFunctionJSXChild(expression, slotTarget);
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
return (0, utils_1.throwError)(options?.parsingId, 'slot 属性值不正确', attr.value);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
else if (attrName === 'rules') {
|
|
325
|
+
const bindAttribute = new utils_1.naslTypes.BindAttribute({
|
|
326
|
+
name: attrName,
|
|
327
|
+
});
|
|
328
|
+
if (attr.value?.type === 'JSXExpressionContainer') {
|
|
329
|
+
if (attr.value.expression.type === 'ArrayExpression') {
|
|
330
|
+
const elements = attr.value.expression.elements;
|
|
331
|
+
bindAttribute.rules = elements.map((node) => (0, transform2ValidationRule_1.transform2ValidationRule)(node, options)).filter(Boolean);
|
|
332
|
+
}
|
|
333
|
+
else if (attr.value.expression.type === 'CallExpression') {
|
|
334
|
+
const callee = (0, utils_1.generate)(attr.value.expression.callee).code;
|
|
335
|
+
if (callee === 'nasl.util.NewList' || callee === 'NewList') {
|
|
336
|
+
const elements = attr.value.expression.arguments[0].elements;
|
|
337
|
+
bindAttribute.rules = elements.map((node) => (0, transform2ValidationRule_1.transform2ValidationRule)(node, options)).filter(Boolean);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
return (0, utils_1.throwError)(options?.parsingId, 'rules 属性值不正确', attr.value);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
return (0, utils_1.throwError)(options?.parsingId, 'rules 属性值不正确', attr.value);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
return (0, utils_1.throwError)(options?.parsingId, 'rules 属性值不正确', attr.value);
|
|
349
|
+
}
|
|
350
|
+
viewElement.addBindAttribute(bindAttribute);
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
const bindAttribute = new utils_1.naslTypes.BindAttribute({
|
|
354
|
+
name: attrName,
|
|
355
|
+
});
|
|
356
|
+
if (!attr.value) {
|
|
357
|
+
bindAttribute.type = 'static';
|
|
358
|
+
bindAttribute.value = 'true';
|
|
359
|
+
}
|
|
360
|
+
else if (attr.value.type === 'StringLiteral') {
|
|
361
|
+
bindAttribute.type = 'string';
|
|
362
|
+
bindAttribute.value = attr.value.value;
|
|
363
|
+
}
|
|
364
|
+
else if (attr.value.type === 'JSXExpressionContainer') {
|
|
365
|
+
if (attr.value.expression.type === 'BooleanLiteral' || attr.value.expression.type === 'NumericLiteral' || attr.value.expression.type === 'NullLiteral' || attr.value.expression.type === 'StringLiteral') {
|
|
366
|
+
bindAttribute.type = 'static';
|
|
367
|
+
bindAttribute.value = (0, utils_1.generate)(attr.value.expression).code;
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
let expr = attr.value.expression;
|
|
371
|
+
if (attrName === 'prop' || attrName.endsWith('Field')) {
|
|
372
|
+
if (expr.type === 'ArrowFunctionExpression') {
|
|
373
|
+
bindAttribute.type = 'string';
|
|
374
|
+
const paramName = expr.params[0]?.name || 'item';
|
|
375
|
+
const code = (0, utils_1.generate)(expr.body).code;
|
|
376
|
+
bindAttribute.value = code.replace(new RegExp(`${paramName}\\.`, 'g'), '');
|
|
377
|
+
if (bindAttribute.value === 'item')
|
|
378
|
+
bindAttribute.value = '';
|
|
379
|
+
viewElement.addBindAttribute(bindAttribute);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
bindAttribute.type = 'dynamic';
|
|
384
|
+
if (expr.type === 'CallExpression' && expr.callee.type === 'Identifier' && expr.callee.name === '$sync') {
|
|
385
|
+
bindAttribute.sync = true;
|
|
386
|
+
if (expr.arguments.length > 0) {
|
|
387
|
+
expr = expr.arguments[0];
|
|
388
|
+
if (!expr)
|
|
389
|
+
return (0, utils_1.throwError)(options?.parsingId, '$sync 的参数不能为空', attr);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (expr.type === 'FunctionExpression')
|
|
393
|
+
return (0, utils_1.throwError)(options?.parsingId, '属性不支持传函数表达式', attr);
|
|
394
|
+
const expression = (0, transform2LogicItem_1.transform2LogicItem)(expr, {
|
|
395
|
+
...options,
|
|
396
|
+
transformType: 'attr',
|
|
397
|
+
isRestricted: attrName !== 'dataSource',
|
|
398
|
+
isInFrontend: true,
|
|
399
|
+
});
|
|
400
|
+
if (expression?.concept === 'Destination') {
|
|
401
|
+
bindAttribute.destination = expression;
|
|
402
|
+
}
|
|
403
|
+
else if (expression?.concept === 'ExternalDestination') {
|
|
404
|
+
bindAttribute.externalDestination = expression;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
bindAttribute.expression = expression;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的指令类型', attr.value.type, attr.value);
|
|
413
|
+
}
|
|
414
|
+
viewElement.addBindAttribute(bindAttribute);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的JSX属性类型', attr.type, attr);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
{ /* 临时补救 EnumToList 问题 */
|
|
422
|
+
if (viewElement.bindAttrs.some((bindAttr) => bindAttr.name === 'dataSource' && bindAttr.expression?.concept === 'CallFunction' && bindAttr.expression?.calleeName === 'EnumToList')) {
|
|
423
|
+
const index = viewElement.bindAttrs.findIndex((bindAttr) => bindAttr.name === 'valueField');
|
|
424
|
+
~index && viewElement.bindAttrs.splice(index, 1);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
node.children.forEach((child) => {
|
|
428
|
+
if (child.type === 'JSXElement' || child.type === 'JSXFragment') {
|
|
429
|
+
addJSXChild(child);
|
|
430
|
+
}
|
|
431
|
+
else if (child.type === 'JSXExpressionContainer') {
|
|
432
|
+
const expression = child.expression;
|
|
433
|
+
if (expression.type === 'JSXElement' || expression.type === 'JSXFragment') {
|
|
434
|
+
addJSXChild(expression);
|
|
435
|
+
}
|
|
436
|
+
else if (expression.type === 'ArrowFunctionExpression') {
|
|
437
|
+
addArrowFunctionJSXChild(expression);
|
|
438
|
+
}
|
|
439
|
+
else if (expression.type === 'JSXEmptyExpression') {
|
|
440
|
+
// ignore
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的JSX子元素类型', expression.type, expression);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
else if (child.type === 'JSXText') {
|
|
447
|
+
// ignore
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的JSX子元素类型', child.type, child);
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
if (!viewElement.name) {
|
|
454
|
+
let generatedName = viewElement.tag.replace(/-/g, '_') + '_' + (0, utils_2.uuidv4)().slice(0, 5);
|
|
455
|
+
// 确保生成的名称也不重复
|
|
456
|
+
while (options.nameMap.has(generatedName)) {
|
|
457
|
+
generatedName = viewElement.tag.replace(/-/g, '_') + '_' + (0, utils_2.uuidv4)().slice(0, 5);
|
|
458
|
+
}
|
|
459
|
+
viewElement.name = generatedName;
|
|
460
|
+
options.nameMap.set(generatedName, true);
|
|
461
|
+
}
|
|
462
|
+
return viewElement;
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的JSX元素类型', el.name.type, el);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
exports.transformJSXElement2ViewElement = transformJSXElement2ViewElement;
|
|
469
|
+
function transform2View(func, decorator, options) {
|
|
470
|
+
const statements = func.body.body;
|
|
471
|
+
// 为每个视图创建独立的 nameMap
|
|
472
|
+
const nameMap = new Map();
|
|
473
|
+
const view = new utils_1.naslTypes.View({
|
|
474
|
+
name: func.id?.name,
|
|
475
|
+
});
|
|
476
|
+
if (decorator) {
|
|
477
|
+
if (decorator.arguments[0].type === 'ObjectExpression') {
|
|
478
|
+
const viewObj = (0, utils_1.pickDecoratorObject)(decorator.arguments[0], new Set([
|
|
479
|
+
'pageTemplateId',
|
|
480
|
+
'uuid',
|
|
481
|
+
'title',
|
|
482
|
+
'crumb',
|
|
483
|
+
'auth',
|
|
484
|
+
'authDescription',
|
|
485
|
+
'isIndex',
|
|
486
|
+
]), options);
|
|
487
|
+
Object.assign(view, viewObj);
|
|
488
|
+
view.crumb = new utils_1.naslTypes.StaticString({
|
|
489
|
+
value: viewObj.crumb,
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的装饰器类型', decorator.type, decorator);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
func.params.forEach((param) => {
|
|
497
|
+
if (param.type === 'Identifier') {
|
|
498
|
+
const _param = (0, transform2LogicItem_1.transform2Param)(param, { ...options, transformType: 'attr' });
|
|
499
|
+
_param && view.params.push(_param);
|
|
500
|
+
}
|
|
501
|
+
else if (param.type === 'ObjectPattern') {
|
|
502
|
+
const propertyMap = {};
|
|
503
|
+
param.properties.forEach((property) => {
|
|
504
|
+
if (property.type === 'ObjectProperty') {
|
|
505
|
+
if (property.value.type === 'Identifier') {
|
|
506
|
+
propertyMap[property.value.name] = {
|
|
507
|
+
type: 'AssignmentPattern',
|
|
508
|
+
left: property.value,
|
|
509
|
+
right: undefined,
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
else if (property.value.type === 'AssignmentPattern') {
|
|
513
|
+
propertyMap[property.value.left.name] = property.value;
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的参数类型', property.value.type, property.value);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
const type = param.typeAnnotation?.typeAnnotation;
|
|
521
|
+
if (!type)
|
|
522
|
+
return (0, utils_1.throwError)(options?.parsingId, 'param 没有对应的类型', param);
|
|
523
|
+
type.members.forEach((member) => {
|
|
524
|
+
if (member.type === 'TSPropertySignature') {
|
|
525
|
+
const name = member.key.name;
|
|
526
|
+
if (propertyMap[name]) {
|
|
527
|
+
propertyMap[name].left.typeAnnotation = member.typeAnnotation;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
Object.values(propertyMap).forEach((property) => {
|
|
532
|
+
const param = (0, transform2LogicItem_1.transform2Param)(property, { ...options, transformType: 'attr' });
|
|
533
|
+
param && view.params.push(param);
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
statements.forEach((statement) => {
|
|
538
|
+
if (statement.type === 'VariableDeclaration') {
|
|
539
|
+
const variables = transform2Variables(statement);
|
|
540
|
+
variables.forEach((variable) => {
|
|
541
|
+
view.addVariable(variable);
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
else if (statement.type === 'FunctionDeclaration') {
|
|
545
|
+
const logic = (0, transform2Logic_1.transform2Logic)(statement, undefined, options);
|
|
546
|
+
view.addLogic(logic);
|
|
547
|
+
}
|
|
548
|
+
else if (statement.type === 'ExpressionStatement' && statement.expression.type === 'CallExpression') {
|
|
549
|
+
const expression = statement.expression;
|
|
550
|
+
if (expression.callee.type == 'Identifier' && expression.callee.name.startsWith('on')) {
|
|
551
|
+
const eventName = (0, utils_2.firstLowerCase)(expression.callee.name.slice(2));
|
|
552
|
+
const arg = expression.arguments[0];
|
|
553
|
+
const bindEvent = new utils_1.naslTypes.BindEvent({
|
|
554
|
+
name: eventName,
|
|
555
|
+
logics: transform2EventLogics(arg, eventName, options) || [],
|
|
556
|
+
});
|
|
557
|
+
view.addBindEvent(bindEvent);
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的表达式', statement);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
else if (statement.type === 'ReturnStatement') {
|
|
564
|
+
const arg = statement.argument;
|
|
565
|
+
if (arg.type === 'JSXElement') {
|
|
566
|
+
const child = transformJSXElement2ViewElement(arg, { ...options, nameMap });
|
|
567
|
+
view.elements = child ? [child] : [];
|
|
568
|
+
}
|
|
569
|
+
else if (arg.type === 'JSXFragment') {
|
|
570
|
+
view.elements = arg.children.filter((child) => child.type === 'JSXElement').map((child) => transformJSXElement2ViewElement(child, { ...options, nameMap })).filter(Boolean);
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
return (0, utils_1.throwError)(options?.parsingId, '返回值不正确', arg);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的表达式', statement);
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
return view;
|
|
581
|
+
}
|
|
582
|
+
exports.transform2View = transform2View;
|
|
583
|
+
function transformTSDeclareFunction2View(func, decorator, options) {
|
|
584
|
+
const view = new utils_1.naslTypes.View({
|
|
585
|
+
name: func.id?.name,
|
|
586
|
+
});
|
|
587
|
+
if (decorator) {
|
|
588
|
+
if (decorator.arguments[0].type === 'ObjectExpression') {
|
|
589
|
+
const viewObj = (0, utils_1.pickDecoratorObject)(decorator.arguments[0], new Set([
|
|
590
|
+
'pageTemplateId',
|
|
591
|
+
'uuid',
|
|
592
|
+
'title',
|
|
593
|
+
'crumb',
|
|
594
|
+
'auth',
|
|
595
|
+
'authDescription',
|
|
596
|
+
'isIndex',
|
|
597
|
+
]), options);
|
|
598
|
+
Object.assign(view, viewObj);
|
|
599
|
+
view.crumb = new utils_1.naslTypes.StaticString({
|
|
600
|
+
value: viewObj.crumb,
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
return (0, utils_1.throwError)(options?.parsingId, '不支持的装饰器类型', decorator.type, decorator);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
func.params.forEach((param) => {
|
|
608
|
+
if (param.type === 'Identifier') {
|
|
609
|
+
const _param = (0, transform2LogicItem_1.transform2Param)(param, { ...options, transformType: 'attr' });
|
|
610
|
+
_param && view.params.push(_param);
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
return view;
|
|
614
|
+
}
|
|
615
|
+
exports.transformTSDeclareFunction2View = transformTSDeclareFunction2View;
|
|
616
|
+
function parseNaturalTSXView(tsCode, options) {
|
|
617
|
+
const root = babel.parseSync(tsCode, {
|
|
618
|
+
filename: 'result.tsx',
|
|
619
|
+
presets: [require('@babel/preset-typescript')],
|
|
620
|
+
});
|
|
621
|
+
let func;
|
|
622
|
+
let funcIndex = 0;
|
|
623
|
+
let decorator;
|
|
624
|
+
root.program.body.forEach((statement, index) => {
|
|
625
|
+
if (statement.type === 'ExportNamedDeclaration' && statement.declaration.type === 'FunctionDeclaration') {
|
|
626
|
+
func = statement.declaration;
|
|
627
|
+
funcIndex = index;
|
|
628
|
+
}
|
|
629
|
+
else if (statement.type === 'FunctionDeclaration') {
|
|
630
|
+
func = statement;
|
|
631
|
+
funcIndex = index;
|
|
632
|
+
}
|
|
633
|
+
const prevStatement = root.program.body[index - 1];
|
|
634
|
+
if (prevStatement?.type === 'ExpressionStatement' && prevStatement.expression.type === 'CallExpression' && prevStatement.expression.callee.type === 'Identifier' && prevStatement.expression.callee.name === '$View') {
|
|
635
|
+
decorator = prevStatement.expression;
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
return transform2View(func, decorator, options);
|
|
639
|
+
}
|
|
640
|
+
exports.parseNaturalTSXView = parseNaturalTSXView;
|
|
641
|
+
//# sourceMappingURL=parseNaturalTSXView.js.map
|