@ant-yasa/uast-parser-java-js 0.1.21-beta.1 → 0.1.21
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/output.txt +3820 -0
- package/package.json +1 -1
- package/tests/benchmark/base/demo.ts +14 -6
- package/tests/index.ts +55 -118
- package/tests/temp-output.json +0 -1809
package/package.json
CHANGED
|
@@ -202,7 +202,15 @@ export class RESOURCEMANAGER extends ServiceSummary {
|
|
|
202
202
|
},
|
|
203
203
|
columns: ['full_host_name']
|
|
204
204
|
})
|
|
205
|
-
|
|
205
|
+
// serviceStatusRecord = [{
|
|
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
|
|
206
214
|
this.ret['haState'] = []
|
|
207
215
|
for (let i = 0; i < serviceStatusRecord.length; i++) {
|
|
208
216
|
let fullHostName = serviceStatusRecord[i].full_host_name
|
|
@@ -401,7 +409,7 @@ export class NODEMANAGER extends ServiceSummary {
|
|
|
401
409
|
|
|
402
410
|
public async getPartitionsByNmServiceName (nmServiceName: string) {
|
|
403
411
|
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
404
|
-
// rmActiveHost = 'rm-dsaas.prefromoffice.
|
|
412
|
+
// rmActiveHost = 'rm-dsaas.prefromoffice.alipay.net'
|
|
405
413
|
return this.getPartitionsByRmHost(rmActiveHost)
|
|
406
414
|
}
|
|
407
415
|
|
|
@@ -519,7 +527,7 @@ export class NODEMANAGER extends ServiceSummary {
|
|
|
519
527
|
*/
|
|
520
528
|
public async getNodeToLabels (nmServiceName: string) {
|
|
521
529
|
// console.log('nmServiceName', nmServiceName)
|
|
522
|
-
// let rmActiveHost = 'antyarn1.inc.
|
|
530
|
+
// let rmActiveHost = 'antyarn1.inc.alipay.net'
|
|
523
531
|
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
524
532
|
let entry = []
|
|
525
533
|
const options = {
|
|
@@ -583,7 +591,7 @@ export class NODEMANAGER extends ServiceSummary {
|
|
|
583
591
|
*/
|
|
584
592
|
public async getNodeListByLabel (nmServiceName: string, labelList: string[]) {
|
|
585
593
|
|
|
586
|
-
// rmActiveHost = 'rm2-dsaas.prefromoffice.
|
|
594
|
+
// rmActiveHost = 'rm2-dsaas.prefromoffice.alipay.net'
|
|
587
595
|
|
|
588
596
|
let nodeToLabels = await this.getNodeToLabels(nmServiceName)
|
|
589
597
|
let nodeHostList = []
|
|
@@ -629,7 +637,7 @@ export class NODEMANAGER extends ServiceSummary {
|
|
|
629
637
|
public async getClusterMetaOfNodeList (nmServiceName: string) {
|
|
630
638
|
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
631
639
|
|
|
632
|
-
// rmActiveHost = 'rm2-dsaas.prefromoffice.
|
|
640
|
+
// rmActiveHost = 'rm2-dsaas.prefromoffice.alipay.net'
|
|
633
641
|
|
|
634
642
|
let nodes = await this.getClusterNodesByRmHost(rmActiveHost)
|
|
635
643
|
let queues = await this.getClusterQueuesByRmHost(rmActiveHost)
|
|
@@ -695,7 +703,7 @@ export class NODEMANAGER extends ServiceSummary {
|
|
|
695
703
|
public async getSummary (nmServiceName) {
|
|
696
704
|
// console.log('nmServiceName', nmServiceName)
|
|
697
705
|
let rmActiveHost = await this.getActiveRmHostByNmServiceName(nmServiceName)
|
|
698
|
-
// let rmActiveHost = 'antyarn1.inc.
|
|
706
|
+
// let rmActiveHost = 'antyarn1.inc.alipay.net'
|
|
699
707
|
let nodes = await this.getClusterNodesByRmHost(rmActiveHost)
|
|
700
708
|
|
|
701
709
|
this.ctx.logger.warn('nodes nodes nodes', JSON.stringify(nodes))
|
package/tests/index.ts
CHANGED
|
@@ -1,129 +1,66 @@
|
|
|
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
|
-
// 获取当前版本:优先使用环境变量,否则 fallback 到 package.json
|
|
9
|
-
function getCurrentVersion(): string {
|
|
10
|
-
return process.env.UAST_VERSION || require('../package.json').version;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// 动态替换 AST 中的 sourcefile 和 version 字段
|
|
14
|
-
function normalizeAst(ast: any, currentSourceFile: string, currentVersion: string): any {
|
|
15
|
-
if (!ast || typeof ast !== 'object') return ast;
|
|
16
|
-
|
|
17
|
-
const cloned = Array.isArray(ast) ? [...ast] : { ...ast };
|
|
18
|
-
|
|
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
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return cloned;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// 用于开发者更新 baseline(会写入当前版本)
|
|
50
8
|
function refreshUastJson() {
|
|
51
|
-
const
|
|
52
|
-
const jsFiles = globby.sync(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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`);
|
|
9
|
+
const suffixMatch = ['*.js'];
|
|
10
|
+
const jsFiles = globby.sync(suffixMatch, { cwd: path.join(__dirname, '/benchmark/base') });
|
|
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');
|
|
67
15
|
}
|
|
68
|
-
|
|
69
|
-
console.log('✅ All baselines updated.');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 检查是否是刷新模式
|
|
73
|
-
function shouldRefresh(): boolean {
|
|
74
|
-
return process.argv.includes('--refresh') || process.argv.includes('-r');
|
|
75
16
|
}
|
|
76
17
|
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
}
|
|
18
|
+
// uastparser变更了以后,确认修改都对的情况下,使用tsc编译在yasa替换uastparser验证无误以后
|
|
19
|
+
// 需要重新生成baseline
|
|
20
|
+
// refreshUastJson()
|
|
113
21
|
|
|
114
|
-
// ✅ 标准化 baseline:替换 sourcefile 和 version
|
|
115
|
-
const normalizedExpected = normalizeAst(expected, fullPath, currentVersion);
|
|
116
22
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
23
|
+
describe('benchmark for javascript', () => {
|
|
24
|
+
const suffixMatch = ['*.js'];
|
|
25
|
+
const jsFiles = globby.sync(suffixMatch, { cwd: path.join(__dirname, '/benchmark/base') });
|
|
26
|
+
for (const jsFile of jsFiles) {
|
|
27
|
+
it(jsFile, () => {
|
|
28
|
+
// fs.writeFileSync(path.join(__dirname, `test.json`), JSON.stringify(parse(content), null, 2), 'utf8');
|
|
29
|
+
const content = fs.readFileSync(path.join(__dirname, '/benchmark/base', jsFile), 'utf8');
|
|
30
|
+
const actual = parse(content,{sourcefile :path.join(__dirname, '/benchmark/base', jsFile),language:"javascript"});
|
|
31
|
+
// console.log(JSON.stringify(parsed));
|
|
32
|
+
// const filePath = path.join(__dirname, '/benchmark/base', jsFile + '.json');
|
|
33
|
+
// fs.writeFile(filePath, JSON.stringify(actual,null,2), (err) => {
|
|
34
|
+
// if (err) {
|
|
35
|
+
// console.error('写入文件时发生错误:', err);
|
|
36
|
+
// return;
|
|
37
|
+
// }
|
|
38
|
+
// console.log('文件已成功写入:', filePath);
|
|
39
|
+
// });
|
|
40
|
+
const baselineJson = fs.readFileSync(path.join(__dirname, '/benchmark/base', jsFile + '.json'), 'utf8')
|
|
41
|
+
// const baseline = JSON.parse(jsonContent);
|
|
42
|
+
// assert.ok(deepEqual(parsed, baseline), jsFile);
|
|
43
|
+
|
|
44
|
+
assert.strictEqual(JSON.stringify(actual,null,2),baselineJson,jsFile)
|
|
45
|
+
});
|
|
46
|
+
}
|
|
129
47
|
});
|
|
48
|
+
|
|
49
|
+
function deepEqual(obj1: any, obj2: any): boolean {
|
|
50
|
+
if (obj1 === obj2) return true
|
|
51
|
+
|
|
52
|
+
if ((typeof obj1 === 'object' && obj1 !== null) && (typeof obj2 === 'object' && obj2 !== null)) {
|
|
53
|
+
if (Object.keys(obj1).length !== Object.keys(obj2).length)
|
|
54
|
+
return false;
|
|
55
|
+
|
|
56
|
+
for (const prop in obj1) {
|
|
57
|
+
if (Object.prototype.hasOwnProperty.call(obj2, prop)) {
|
|
58
|
+
if (!deepEqual(obj1[prop], obj2[prop]))
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
} else {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|