@lcap/nasl 2.20.0-beta.4 → 2.20.0-beta.5
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/bak/translator.js +3 -3
- package/out/bak/translator.js.map +1 -1
- package/out/concepts/BindAttribute__.js +7 -6
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindDirective__.js +7 -6
- package/out/concepts/BindDirective__.js.map +1 -1
- package/out/concepts/BindStyle__.js +10 -10
- package/out/concepts/BindStyle__.js.map +1 -1
- package/out/concepts/ConfigProperty__.js +8 -6
- package/out/concepts/ConfigProperty__.js.map +1 -1
- package/out/concepts/DataSource__.js +11 -3
- package/out/concepts/DataSource__.js.map +1 -1
- package/out/concepts/ExternalDestination__.js +1 -1
- package/out/concepts/ExternalDestination__.js.map +1 -1
- package/out/concepts/Logic__.js +23 -14
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/Match__.d.ts +3 -0
- package/out/concepts/Match__.js +73 -2
- package/out/concepts/Match__.js.map +1 -1
- package/out/concepts/NewComposite__.d.ts +1 -0
- package/out/concepts/NewComposite__.js +20 -2
- package/out/concepts/NewComposite__.js.map +1 -1
- package/out/concepts/Return__.js +3 -0
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/StringInterpolation__.js +1 -1
- package/out/concepts/StringInterpolation__.js.map +1 -1
- package/out/concepts/TypeAnnotation__.js +1 -1
- package/out/concepts/TypeAnnotation__.js.map +1 -1
- package/out/concepts/Variable__.js +3 -0
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +1 -0
- package/out/concepts/ViewElement__.js +7 -0
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.js +21 -11
- package/out/concepts/View__.js.map +1 -1
- package/out/generator/genReleaseBody.d.ts +1 -0
- package/out/generator/genReleaseBody.js +1 -0
- package/out/generator/genReleaseBody.js.map +1 -1
- package/out/generator/permission.d.ts +1 -0
- package/out/generator/permission.js +17 -8
- package/out/generator/permission.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.js +2 -1
- package/out/index.js.map +1 -1
- package/out/server/naslServer.js +41 -18
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.js +1 -1
- package/out/service/storage/init.js +1 -1
- package/out/service/storage/init.js.map +1 -1
- package/out/translator/index.js +4 -1
- package/out/translator/index.js.map +1 -1
- package/package.json +1 -1
- package/src/bak/translator.js +3 -3
- package/src/concepts/BindAttribute__.ts +7 -5
- package/src/concepts/BindDirective__.ts +7 -5
- package/src/concepts/BindStyle__.ts +7 -6
- package/src/concepts/ConfigProperty__.ts +8 -6
- package/src/concepts/DataSource__.ts +11 -7
- package/src/concepts/ExternalDestination__.ts +1 -1
- package/src/concepts/Logic__.ts +24 -15
- package/src/concepts/Match__.ts +77 -2
- package/src/concepts/NewComposite__.ts +20 -2
- package/src/concepts/Return__.ts +2 -0
- package/src/concepts/StringInterpolation__.ts +1 -1
- package/src/concepts/TypeAnnotation__.ts +1 -1
- package/src/concepts/Variable__.ts +2 -0
- package/src/concepts/ViewElement__.ts +9 -1
- package/src/concepts/View__.ts +27 -18
- package/src/generator/genReleaseBody.ts +2 -1
- package/src/generator/permission.ts +17 -7
- package/src/index.ts +1 -1
- package/src/server/naslServer.ts +37 -17
- package/src/server/translator.ts +1 -1
- package/src/service/storage/init.ts +1 -1
- package/src/translator/index.ts +3 -1
package/src/concepts/View__.ts
CHANGED
|
@@ -1765,16 +1765,22 @@ export class View extends BaseNode {
|
|
|
1765
1765
|
// 子页面内部逻辑过滤
|
|
1766
1766
|
if (el.view !== this)
|
|
1767
1767
|
return;
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1768
|
+
if (el instanceof Assignment) {
|
|
1769
|
+
const advanceVar = this.variables?.find((variable) =>
|
|
1770
|
+
!variable.typeAnnotation && el.left?.name === variable.name);
|
|
1771
|
+
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
1772
|
+
advanceMap.set(advanceVar, el);
|
|
1773
|
+
}
|
|
1774
|
+
} else if (el instanceof BatchAssignment) {
|
|
1775
|
+
el.assignmentLines.forEach(({ leftIndex }) => {
|
|
1776
|
+
const leftCode
|
|
1777
|
+
= leftIndex.length === 1 ? el.left?.expression?.toEmbeddedTS(shiftState(state, code, { inline: true })) : el.left?.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true }));
|
|
1778
|
+
const advanceVar = this.variables?.find((variable) =>
|
|
1779
|
+
!variable.typeAnnotation && leftCode === variable.name);
|
|
1780
|
+
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
1781
|
+
advanceMap.set(advanceVar, el);
|
|
1782
|
+
}
|
|
1783
|
+
});
|
|
1778
1784
|
}
|
|
1779
1785
|
}
|
|
1780
1786
|
});
|
|
@@ -1992,12 +1998,15 @@ export class View extends BaseNode {
|
|
|
1992
1998
|
this.elements.forEach((item) => {
|
|
1993
1999
|
utils.traverse((current) => {
|
|
1994
2000
|
const { node } = current as any;
|
|
1995
|
-
|
|
1996
|
-
if (
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
) {
|
|
2000
|
-
|
|
2001
|
+
//// 处理三种情况
|
|
2002
|
+
//if (
|
|
2003
|
+
// ['BindAttribute', 'BindDirective', 'BindStyle'].includes(node.concept)
|
|
2004
|
+
// && node.needReplaceWithIdentifier
|
|
2005
|
+
//) {
|
|
2006
|
+
// bindExpressions.push(node);
|
|
2007
|
+
//}
|
|
2008
|
+
if (node.concept === 'Match') {
|
|
2009
|
+
bindExpressions.push(node as Match);
|
|
2001
2010
|
}
|
|
2002
2011
|
}, {
|
|
2003
2012
|
node: item,
|
|
@@ -2208,8 +2217,8 @@ export class View extends BaseNode {
|
|
|
2208
2217
|
return code;
|
|
2209
2218
|
}
|
|
2210
2219
|
|
|
2211
|
-
getViewCallLogics():string[] {
|
|
2212
|
-
const callbackLogics
|
|
2220
|
+
getViewCallLogics(): string[] {
|
|
2221
|
+
const callbackLogics: string[] = [];
|
|
2213
2222
|
this.traverseChildren((el) => {
|
|
2214
2223
|
if (el instanceof Identifier && el.namespace?.endsWith('logics')) {
|
|
2215
2224
|
callbackLogics.push(el.namespace + '.' + el.name);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { App, Assignment, BatchAssignment, CallFunction, CallInterface, CallLogic, ForEachStatement, IfStatement, Logic, LogicItem, Match, MatchCase, MemberExpression, Role, SwitchCase, SwitchStatement, View, ViewElement, WhileStatement, StringInterpolation, Frontend, ExternalDestination, NewComposite, SelectMembers, NewList } from '../concepts';
|
|
2
2
|
import { genFrontendBundleFiles } from './genBundleFiles';
|
|
3
|
-
import { genPermissionData } from './permission';
|
|
3
|
+
import { genPermissionData, genLogicAuthFlag } from './permission';
|
|
4
4
|
import * as utils from '../utils';
|
|
5
5
|
|
|
6
6
|
export async function genReleaseBody(app: App, {
|
|
@@ -47,6 +47,7 @@ export async function genReleaseBody(app: App, {
|
|
|
47
47
|
const body = {
|
|
48
48
|
...authReport, // 如果发布需要上报权限,导出源码不需要
|
|
49
49
|
logicPageResourceDtoList,
|
|
50
|
+
logicAuthFlag: genLogicAuthFlag(app),
|
|
50
51
|
noAuthApiPathList: getAuthApiPathList(app, frontends),
|
|
51
52
|
reportIdList: findAllReportIdList(app, frontends),
|
|
52
53
|
appId: app.id,
|
|
@@ -102,13 +102,11 @@ function findResourcesOfUI(view: View | ViewElement) {
|
|
|
102
102
|
path: node.authPath,
|
|
103
103
|
type: 'page',
|
|
104
104
|
});
|
|
105
|
-
else if (node instanceof ViewElement) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
type: 'component',
|
|
111
|
-
});
|
|
105
|
+
else if (node instanceof ViewElement && node.auth) {
|
|
106
|
+
res.push({
|
|
107
|
+
path: node.authPath,
|
|
108
|
+
type: 'component',
|
|
109
|
+
});
|
|
112
110
|
}
|
|
113
111
|
node = node.parentNode;
|
|
114
112
|
}
|
|
@@ -275,3 +273,15 @@ export async function genPermissionData(app: App) {
|
|
|
275
273
|
// console.timeEnd('xxx');
|
|
276
274
|
return logicPageResourceDtoList;
|
|
277
275
|
}
|
|
276
|
+
|
|
277
|
+
export function genLogicAuthFlag(app: App) {
|
|
278
|
+
let flag = false;
|
|
279
|
+
app.traverseChildren((node) => {
|
|
280
|
+
if(flag) return;
|
|
281
|
+
|
|
282
|
+
if((node instanceof View || node instanceof ViewElement) && node.auth)
|
|
283
|
+
flag = true;
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
return flag;
|
|
287
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { EventEmitter, EventPayload, BaseNode } from './common';
|
|
2
2
|
export * from './concepts';
|
|
3
|
-
export { genBundleFiles, genFrontendBundleFiles, genMetaData, genReleaseBody, genPermissionData } from './generator';
|
|
3
|
+
export { genBundleFiles, genFrontendBundleFiles, genMetaData, genReleaseBody, genPermissionData, genLogicAuthFlag } from './generator';
|
|
4
4
|
export * from './translator';
|
|
5
5
|
// export { default as diagnosticManager } from './manager/diagnostic';
|
|
6
6
|
export { default as server, NaslServer } from './server';
|
package/src/server/naslServer.ts
CHANGED
|
@@ -1104,7 +1104,7 @@ export class NaslServer {
|
|
|
1104
1104
|
if (Array.isArray(body) && body.length) {
|
|
1105
1105
|
const lastExpression = body[body.length - 1];
|
|
1106
1106
|
diagnostic.node = lastExpression;
|
|
1107
|
-
diagnostic.message =
|
|
1107
|
+
diagnostic.message = `匹配:该分支类型与多数类型不一致,将产生Union类型。当前类型:${typeAnnotation?.headTitle},多数类型:${maxTypeAnnotation?.headTitle}`;
|
|
1108
1108
|
this.baseNodeAssignmentTsError(lastExpression, diagnostic);
|
|
1109
1109
|
diagnostics.push(diagnostic);
|
|
1110
1110
|
}
|
|
@@ -1378,7 +1378,12 @@ export class NaslServer {
|
|
|
1378
1378
|
if (node.logic && node.logic !== nodeIn.logic)
|
|
1379
1379
|
return;
|
|
1380
1380
|
// 跟变量无关的赋值过滤
|
|
1381
|
-
|
|
1381
|
+
let jsCode = '';
|
|
1382
|
+
try {
|
|
1383
|
+
jsCode = nodeIn.toJS();
|
|
1384
|
+
} catch (err) {
|
|
1385
|
+
console.log(err);
|
|
1386
|
+
}
|
|
1382
1387
|
if (!jsCode.includes(`${node.name} = `))
|
|
1383
1388
|
return;
|
|
1384
1389
|
// 页面局部变量
|
|
@@ -1551,16 +1556,24 @@ export class NaslServer {
|
|
|
1551
1556
|
fileNode?.sourceMap.forEach((valueIn, nodeIn) => {
|
|
1552
1557
|
if (!used && nodeIn
|
|
1553
1558
|
&& (nodeIn instanceof BatchAssignment || (nodeIn instanceof Assignment && nodeIn.left?.name))
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1559
|
+
) {
|
|
1560
|
+
let jsCode = '';
|
|
1561
|
+
try {
|
|
1562
|
+
jsCode = nodeIn.toJS();
|
|
1563
|
+
} catch (err) {
|
|
1564
|
+
console.log(err);
|
|
1565
|
+
}
|
|
1566
|
+
if (jsCode.includes(`${node.name} = `)) {
|
|
1567
|
+
used = true;
|
|
1568
|
+
if (!nodeIn.tsErrorDetail) {
|
|
1569
|
+
const diagnostic = {
|
|
1570
|
+
node: nodeIn,
|
|
1571
|
+
severity: 'error',
|
|
1572
|
+
message: `${nodeIn.label}左边 ${node.name} 未设置类型,右边必须为有返回值的内容。`,
|
|
1573
|
+
};
|
|
1574
|
+
nodeIn.tsErrorDetail = diagnostic;
|
|
1575
|
+
diagnostics.push(diagnostic);
|
|
1576
|
+
}
|
|
1564
1577
|
}
|
|
1565
1578
|
}
|
|
1566
1579
|
});
|
|
@@ -1649,8 +1662,8 @@ export class NaslServer {
|
|
|
1649
1662
|
const diagnostic = {
|
|
1650
1663
|
node,
|
|
1651
1664
|
severity: 'error',
|
|
1652
|
-
message: '
|
|
1653
|
-
titleTip: '
|
|
1665
|
+
message: '匹配分支:返回内容不能为空',
|
|
1666
|
+
titleTip: '返回内容不能为空',
|
|
1654
1667
|
};
|
|
1655
1668
|
node.tsErrorDetail = diagnostic;
|
|
1656
1669
|
diagnostics.push(diagnostic);
|
|
@@ -1766,6 +1779,8 @@ export class NaslServer {
|
|
|
1766
1779
|
// 先特殊处理等 类型合并后就可以去掉了
|
|
1767
1780
|
if (excludeList.includes(leftType.sortedTypeKey) && excludeList.includes(rightType.sortedTypeKey)) {
|
|
1768
1781
|
return null;
|
|
1782
|
+
} else if (['nasl.collection.List<>'].includes(leftType.sortedTypeKey) || ['nasl.collection.List<>'].includes(rightType.sortedTypeKey)) {
|
|
1783
|
+
return null;
|
|
1769
1784
|
}
|
|
1770
1785
|
const diagnostic = {
|
|
1771
1786
|
node: node.right,
|
|
@@ -2775,6 +2790,7 @@ export class NaslServer {
|
|
|
2775
2790
|
&& !(fileNode.parentNode instanceof App)
|
|
2776
2791
|
&& !(fileNode.parentNode instanceof Module)
|
|
2777
2792
|
&& !(fileNode.parentNode instanceof DataSource)
|
|
2793
|
+
&& !(fileNode.parentNode instanceof Frontend)
|
|
2778
2794
|
&& !(fileNode instanceof View)
|
|
2779
2795
|
&& !(fileNode instanceof ConfigProperty)
|
|
2780
2796
|
) {
|
|
@@ -3024,7 +3040,11 @@ export class NaslServer {
|
|
|
3024
3040
|
}
|
|
3025
3041
|
} else if (node.concept === 'Match') {
|
|
3026
3042
|
// 去查return 后面的返回值,变成函数调用
|
|
3027
|
-
|
|
3043
|
+
if (item.code?.endsWith(';\n')) {
|
|
3044
|
+
fileDetail.line = item.range.end.line - 1;
|
|
3045
|
+
} else {
|
|
3046
|
+
fileDetail.line = item.range.end.line;
|
|
3047
|
+
}
|
|
3028
3048
|
const indexOf = item.code.indexOf('return __MatchExpressionFuntion');
|
|
3029
3049
|
let newCode = item.code.substring(0, indexOf);
|
|
3030
3050
|
newCode = newCode.substring(newCode.lastIndexOf('\n'), indexOf);
|
|
@@ -3076,8 +3096,8 @@ export class NaslServer {
|
|
|
3076
3096
|
// 直接从最后一项的返回值取,有就有没有就没有
|
|
3077
3097
|
if (node.body?.length) {
|
|
3078
3098
|
const last = node.body[node.body.length - 1];
|
|
3079
|
-
if (last
|
|
3080
|
-
types.set(node, last
|
|
3099
|
+
if (types.get(last)) {
|
|
3100
|
+
types.set(node, types.get(last));
|
|
3081
3101
|
}
|
|
3082
3102
|
}
|
|
3083
3103
|
}
|
package/src/server/translator.ts
CHANGED
|
@@ -537,7 +537,7 @@ export function naslNodeTranslateMessage(minRange: MinRange, tsErrorDetail: Diag
|
|
|
537
537
|
// 赋值左右侧类型不一致, 把文字换一下
|
|
538
538
|
if (/Argument of type '(.+?)' is not assignable to parameter of type '(.+?)'/.exec(text)) {
|
|
539
539
|
if (node instanceof OqlQueryComponent) {
|
|
540
|
-
tsErrorDetail.message = tsErrorDetail.message.replace('参数类型不一致!传入类型:', '类型不一致!传入类型:').replace('接收类型:', '
|
|
540
|
+
tsErrorDetail.message = tsErrorDetail.message.replace('参数类型不一致!传入类型:', '类型不一致!传入类型:').replace('接收类型:', '期望类型:');
|
|
541
541
|
} else if (node.parentNode instanceof Assignment) {
|
|
542
542
|
// OQL 的返回类型报错需要转换翻译,其内部 SQL 语句的参数类型报错不转换翻译
|
|
543
543
|
if (node instanceof OqlQueryComponent) {
|
|
@@ -318,7 +318,7 @@ async function doAction(app: any, actionItem: any) {
|
|
|
318
318
|
undo: '已撤销操作:',
|
|
319
319
|
redo: '已重做操作:',
|
|
320
320
|
};
|
|
321
|
-
let msg = actionMap[action as 'undo' | 'redo'];
|
|
321
|
+
let msg = actionMap[action as 'undo' | 'redo'] || '';
|
|
322
322
|
msg += actionMsg;
|
|
323
323
|
Vue.prototype.$toast.info(msg);
|
|
324
324
|
app._historying = false;
|
package/src/translator/index.ts
CHANGED
|
@@ -89,7 +89,9 @@ export function withSourceMap() {
|
|
|
89
89
|
descriptor.value = function (this: BaseNode, state?: TranslatorState, ...args: any[]) {
|
|
90
90
|
// 重新生成ts代码就先把类型清除掉
|
|
91
91
|
// 注意排查错误的时候,调用了这个方法,就会把节点上缓存的__TypeAnnotation清除
|
|
92
|
-
|
|
92
|
+
try {
|
|
93
|
+
this.__isCorrectTypeAnnotation = false;
|
|
94
|
+
} catch (err) {}
|
|
93
95
|
if (!state) {
|
|
94
96
|
// 没有状态不生成 SourceMap
|
|
95
97
|
return oldMethod.call(this);
|