@ant-yasa/uast-parser-java-js 0.1.20 → 0.1.21-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 -29
- package/package.json +1 -1
- package/tests/benchmark/base/demo.ts +6 -14
- package/tests/index.ts +118 -55
- package/tests/temp-output.json +1809 -0
- package/output.txt +0 -3820
package/README.md
CHANGED
|
@@ -1,35 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
# @ant-yasa/uast-parser-java-js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> UAST specification is a Lodash-esque utility library for Unified-AST(UAST) nodes
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Using npm:
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```sh
|
|
10
|
+
npm install --save-dev @ant-yasa/uast-parser-java-js
|
|
11
|
+
```
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
or using yarn:
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- 安装方法:说明如何快速上手使用该项目
|
|
17
|
-
- 使用方法:列出本项目能够提供的功能以及使用这些功能的方法
|
|
18
|
-
- 文档:现阶段antcode鼓励用户使用语雀组织项目文档,在README上应当放入项目的语雀文档链接
|
|
19
|
-
|
|
20
|
-
## 附加内容
|
|
21
|
-
|
|
22
|
-
视项目的实际情况,同样也应该包含以下内容:
|
|
23
|
-
|
|
24
|
-
- 项目特性:说明本项目相较于其他同类项目所具有的特性
|
|
25
|
-
- 兼容环境:说明本项目能够在什么平台上运行
|
|
26
|
-
- 使用示例:展示一些使用本项目的小demo
|
|
27
|
-
- 主要项目负责人:使用“@”标注出本项目的主要负责人,方便项目的用户沟通
|
|
28
|
-
- 参与贡献的方式:规定好其他用户参与本项目并贡献代码的方式
|
|
29
|
-
- 项目的参与者:列出项目主要的参与人
|
|
30
|
-
- 已知用户:列出已经在生产环境中使用了本项目的全部或部分组件的公司或组织
|
|
31
|
-
- 赞助者:列出为本项目提供赞助的用户
|
|
32
|
-
|
|
33
|
-
## 参考示例
|
|
34
|
-
|
|
35
|
-
https://code.alipay.com/linkcode/antcode
|
|
15
|
+
```sh
|
|
16
|
+
yarn add @ant-yasa/uast-parser-java-js --dev
|
|
17
|
+
```
|
package/package.json
CHANGED
|
@@ -202,15 +202,7 @@ export class RESOURCEMANAGER extends ServiceSummary {
|
|
|
202
202
|
},
|
|
203
203
|
columns: ['full_host_name']
|
|
204
204
|
})
|
|
205
|
-
|
|
206
|
-
// full_host_name: 'antyarn1.inc.alipay.net'
|
|
207
|
-
// }]
|
|
208
|
-
// serviceStatusRecord = [{
|
|
209
|
-
// full_host_name: 'rm-dsaas.prefromoffice.alipay.net'
|
|
210
|
-
// }, {
|
|
211
|
-
// full_host_name: 'rm2-dsaas.prefromoffice.alipay.net'
|
|
212
|
-
// }]
|
|
213
|
-
//得到resourcemanager的Active和StandBy的RM
|
|
205
|
+
|
|
214
206
|
this.ret['haState'] = []
|
|
215
207
|
for (let i = 0; i < serviceStatusRecord.length; i++) {
|
|
216
208
|
let fullHostName = serviceStatusRecord[i].full_host_name
|
|
@@ -409,7 +401,7 @@ export class NODEMANAGER extends ServiceSummary {
|
|
|
409
401
|
|
|
410
402
|
public async getPartitionsByNmServiceName (nmServiceName: string) {
|
|
411
403
|
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
412
|
-
// rmActiveHost = 'rm-dsaas.prefromoffice.
|
|
404
|
+
// rmActiveHost = 'rm-dsaas.prefromoffice.xxxxx.net'
|
|
413
405
|
return this.getPartitionsByRmHost(rmActiveHost)
|
|
414
406
|
}
|
|
415
407
|
|
|
@@ -527,7 +519,7 @@ export class NODEMANAGER extends ServiceSummary {
|
|
|
527
519
|
*/
|
|
528
520
|
public async getNodeToLabels (nmServiceName: string) {
|
|
529
521
|
// console.log('nmServiceName', nmServiceName)
|
|
530
|
-
// let rmActiveHost = 'antyarn1.inc.
|
|
522
|
+
// let rmActiveHost = 'antyarn1.inc.xxxxx.net'
|
|
531
523
|
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
532
524
|
let entry = []
|
|
533
525
|
const options = {
|
|
@@ -591,7 +583,7 @@ export class NODEMANAGER extends ServiceSummary {
|
|
|
591
583
|
*/
|
|
592
584
|
public async getNodeListByLabel (nmServiceName: string, labelList: string[]) {
|
|
593
585
|
|
|
594
|
-
// rmActiveHost = 'rm2-dsaas.prefromoffice.
|
|
586
|
+
// rmActiveHost = 'rm2-dsaas.prefromoffice.xxxxx.net'
|
|
595
587
|
|
|
596
588
|
let nodeToLabels = await this.getNodeToLabels(nmServiceName)
|
|
597
589
|
let nodeHostList = []
|
|
@@ -637,7 +629,7 @@ export class NODEMANAGER extends ServiceSummary {
|
|
|
637
629
|
public async getClusterMetaOfNodeList (nmServiceName: string) {
|
|
638
630
|
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
639
631
|
|
|
640
|
-
// rmActiveHost = 'rm2-dsaas.prefromoffice.
|
|
632
|
+
// rmActiveHost = 'rm2-dsaas.prefromoffice.xxxxx.net'
|
|
641
633
|
|
|
642
634
|
let nodes = await this.getClusterNodesByRmHost(rmActiveHost)
|
|
643
635
|
let queues = await this.getClusterQueuesByRmHost(rmActiveHost)
|
|
@@ -703,7 +695,7 @@ export class NODEMANAGER extends ServiceSummary {
|
|
|
703
695
|
public async getSummary (nmServiceName) {
|
|
704
696
|
// console.log('nmServiceName', nmServiceName)
|
|
705
697
|
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
706
|
-
// let rmActiveHost = 'antyarn1.inc.
|
|
698
|
+
// let rmActiveHost = 'antyarn1.inc.xxxxx.net'
|
|
707
699
|
let nodes = await this.getClusterNodesByRmHost(rmActiveHost)
|
|
708
700
|
|
|
709
701
|
this.ctx.logger.warn('nodes nodes nodes', JSON.stringify(nodes))
|
package/tests/index.ts
CHANGED
|
@@ -1,66 +1,129 @@
|
|
|
1
1
|
import 'mocha';
|
|
2
2
|
import * as assert from 'assert';
|
|
3
|
-
import { parse } from '../src/frontend/javascript/parser'
|
|
4
|
-
import * as fs from 'fs'
|
|
5
|
-
import * as path from 'path'
|
|
3
|
+
import { parse } from '../src/frontend/javascript/parser';
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import * as path from 'path';
|
|
6
6
|
import * as globby from 'fast-glob';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
for (let file of jsFiles) {
|
|
12
|
-
const content = fs.readFileSync(path.join(__dirname, '/benchmark/base', file), 'utf8');
|
|
13
|
-
const ast = parse(content)
|
|
14
|
-
fs.writeFileSync(path.join(__dirname,'/benchmark/base', `${file}.json`), JSON.stringify(ast, null, 2), 'utf8');
|
|
15
|
-
}
|
|
8
|
+
// 获取当前版本:优先使用环境变量,否则 fallback 到 package.json
|
|
9
|
+
function getCurrentVersion(): string {
|
|
10
|
+
return process.env.UAST_VERSION || require('../package.json').version;
|
|
16
11
|
}
|
|
17
12
|
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
// 动态替换 AST 中的 sourcefile 和 version 字段
|
|
14
|
+
function normalizeAst(ast: any, currentSourceFile: string, currentVersion: string): any {
|
|
15
|
+
if (!ast || typeof ast !== 'object') return ast;
|
|
21
16
|
|
|
17
|
+
const cloned = Array.isArray(ast) ? [...ast] : { ...ast };
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
19
|
+
for (const key in cloned) {
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(cloned, key)) {
|
|
21
|
+
// 替换 sourcefile 为当前环境的真实路径
|
|
22
|
+
if (key === 'sourcefile' && typeof cloned[key] === 'string') {
|
|
23
|
+
cloned[key] = currentSourceFile;
|
|
24
|
+
}
|
|
25
|
+
// 替换 version 为当前版本
|
|
26
|
+
else if (key === 'version' && typeof cloned[key] === 'string') {
|
|
27
|
+
cloned[key] = currentVersion;
|
|
28
|
+
}
|
|
29
|
+
// 删除空的 uri 字段(可选)
|
|
30
|
+
else if (key === 'uri' && cloned[key] === '') {
|
|
31
|
+
delete cloned[key];
|
|
32
|
+
}
|
|
33
|
+
// 可选:删除 _meta._extra.start/end(避免字节偏移差异)
|
|
34
|
+
else if (key === '_meta' && cloned[key]?.['_extra']?.hasOwnProperty('start')) {
|
|
35
|
+
const extra = { ...cloned[key]['_extra'] };
|
|
36
|
+
delete extra.start;
|
|
37
|
+
delete extra.end;
|
|
38
|
+
cloned[key] = { ...cloned[key], _extra: extra };
|
|
39
|
+
}
|
|
40
|
+
// 递归处理子节点
|
|
41
|
+
else {
|
|
42
|
+
cloned[key] = normalizeAst(cloned[key], currentSourceFile, currentVersion);
|
|
43
|
+
}
|
|
46
44
|
}
|
|
47
|
-
}
|
|
45
|
+
}
|
|
46
|
+
return cloned;
|
|
47
|
+
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
49
|
+
// 用于开发者更新 baseline(会写入当前版本)
|
|
50
|
+
function refreshUastJson() {
|
|
51
|
+
const BASE_DIR = path.join(__dirname, 'benchmark', 'base');
|
|
52
|
+
const jsFiles = globby.sync('*.js', { cwd: BASE_DIR });
|
|
53
|
+
const currentVersion = getCurrentVersion();
|
|
54
|
+
|
|
55
|
+
console.log(`🔄 Refreshing UAST baselines with version: ${currentVersion}`);
|
|
56
|
+
|
|
57
|
+
for (const file of jsFiles) {
|
|
58
|
+
const fullPath = path.join(BASE_DIR, file);
|
|
59
|
+
const content = fs.readFileSync(fullPath, 'utf8');
|
|
60
|
+
const ast = parse(content, { sourcefile: fullPath, language: 'javascript' });
|
|
61
|
+
|
|
62
|
+
// ✅ 写入当前版本
|
|
63
|
+
ast.version = currentVersion;
|
|
64
|
+
|
|
65
|
+
fs.writeFileSync(`${fullPath}.json`, JSON.stringify(ast, null, 2), 'utf8');
|
|
66
|
+
console.log(`✅ Updated baseline: ${file}.json`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
console.log('✅ All baselines updated.');
|
|
66
70
|
}
|
|
71
|
+
|
|
72
|
+
// 检查是否是刷新模式
|
|
73
|
+
function shouldRefresh(): boolean {
|
|
74
|
+
return process.argv.includes('--refresh') || process.argv.includes('-r');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 主测试逻辑
|
|
78
|
+
describe('benchmark for javascript', () => {
|
|
79
|
+
const BASE_DIR = path.join(__dirname, 'benchmark', 'base');
|
|
80
|
+
const jsFiles = globby.sync('*.js', { cwd: BASE_DIR });
|
|
81
|
+
const currentVersion = getCurrentVersion();
|
|
82
|
+
|
|
83
|
+
// 如果是刷新模式,只更新 baseline
|
|
84
|
+
if (shouldRefresh()) {
|
|
85
|
+
before(() => {
|
|
86
|
+
refreshUastJson();
|
|
87
|
+
process.exit(0);
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 正常测试流程
|
|
93
|
+
for (const jsFile of jsFiles) {
|
|
94
|
+
it(jsFile, () => {
|
|
95
|
+
const fullPath = path.join(BASE_DIR, jsFile);
|
|
96
|
+
const content = fs.readFileSync(fullPath, 'utf8');
|
|
97
|
+
|
|
98
|
+
// 实际解析结果
|
|
99
|
+
const actual = parse(content, {
|
|
100
|
+
sourcefile: fullPath,
|
|
101
|
+
language: 'javascript',
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// 读取 baseline
|
|
105
|
+
const baselinePath = `${fullPath}.json`;
|
|
106
|
+
let expected: any;
|
|
107
|
+
try {
|
|
108
|
+
const baselineRaw = fs.readFileSync(baselinePath, 'utf8');
|
|
109
|
+
expected = JSON.parse(baselineRaw);
|
|
110
|
+
} catch (err) {
|
|
111
|
+
assert.fail(`❌ Failed to read baseline ${baselinePath}: ${err}`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ✅ 标准化 baseline:替换 sourcefile 和 version
|
|
115
|
+
const normalizedExpected = normalizeAst(expected, fullPath, currentVersion);
|
|
116
|
+
|
|
117
|
+
// 字符串化对比(格式化一致)
|
|
118
|
+
const actualStr = JSON.stringify(actual, null, 2);
|
|
119
|
+
const expectedStr = JSON.stringify(normalizedExpected, null, 2);
|
|
120
|
+
|
|
121
|
+
// 断言
|
|
122
|
+
assert.strictEqual(
|
|
123
|
+
actualStr,
|
|
124
|
+
expectedStr,
|
|
125
|
+
`UAST mismatch in ${jsFile}\n\n👉 Run with --refresh to update baselines if changes are expected.`
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|