@ant-yasa/uast-parser-java-js 0.1.83 → 0.2.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/dist/package.json +1 -1
- package/dist/src/frontend/java/ASTBuilder.d.ts +1 -1
- package/dist/src/frontend/java/ASTBuilder.js +4 -3
- package/dist/src/frontend/java/ASTBuilder.js.map +1 -1
- package/dist/src/frontend/java/testBuilder.d.ts +128 -128
- package/dist/src/frontend/javascript/parser.js +4 -2
- package/dist/src/frontend/javascript/parser.js.map +1 -1
- package/package.json +2 -2
- package/tests/benchmark/base/class.js.json +83 -85
- package/tests/benchmark/base/class_test.js.json +17 -19
- package/tests/benchmark/base/comment.js.json +63 -65
- package/tests/benchmark/base/empty.js.json +10 -10
- package/tests/benchmark/base/export.js.json +296 -296
- package/tests/benchmark/base/export1.js.json +13 -13
- package/tests/benchmark/base/export2.js.json +147 -147
- package/tests/benchmark/base/expressions.js.json +76 -76
- package/tests/benchmark/base/for.js.json +35 -35
- package/tests/benchmark/base/function.js.json +72 -72
- package/tests/benchmark/base/import.js.json +22 -22
- package/tests/benchmark/base/literal.js.json +55 -55
- package/tests/benchmark/base/param.js.json +19 -19
- package/tests/benchmark/base/parseerror.js.json +10 -10
- package/tests/benchmark/base/patternlike.js.json +194 -194
- package/tests/benchmark/base/react.js.json +9 -9
- package/tests/benchmark/base/switch.js.json +36 -36
- package/tests/benchmark/base/temp.js.json +928 -930
- package/tests/benchmark/base/tmp.js.json +713 -716
- package/tests/benchmark/base/vardecl.js.json +23 -23
- package/tests/index.ts +10 -9
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"line": 1,
|
|
22
22
|
"column": 6
|
|
23
23
|
},
|
|
24
|
-
"sourcefile": "
|
|
24
|
+
"sourcefile": "vardecl.js"
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"init": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"line": 1,
|
|
44
44
|
"column": 10
|
|
45
45
|
},
|
|
46
|
-
"sourcefile": "
|
|
46
|
+
"sourcefile": "vardecl.js"
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"cloned": false,
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"line": 1,
|
|
67
67
|
"column": 10
|
|
68
68
|
},
|
|
69
|
-
"sourcefile": "
|
|
69
|
+
"sourcefile": "vardecl.js"
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
{
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"line": 3,
|
|
90
90
|
"column": 6
|
|
91
91
|
},
|
|
92
|
-
"sourcefile": "
|
|
92
|
+
"sourcefile": "vardecl.js"
|
|
93
93
|
}
|
|
94
94
|
},
|
|
95
95
|
"init": {
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"line": 3,
|
|
111
111
|
"column": 10
|
|
112
112
|
},
|
|
113
|
-
"sourcefile": "
|
|
113
|
+
"sourcefile": "vardecl.js"
|
|
114
114
|
}
|
|
115
115
|
},
|
|
116
116
|
"cloned": false,
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
"line": 3,
|
|
135
135
|
"column": 10
|
|
136
136
|
},
|
|
137
|
-
"sourcefile": "
|
|
137
|
+
"sourcefile": "vardecl.js"
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
140
|
{
|
|
@@ -157,7 +157,7 @@
|
|
|
157
157
|
"line": 5,
|
|
158
158
|
"column": 8
|
|
159
159
|
},
|
|
160
|
-
"sourcefile": "
|
|
160
|
+
"sourcefile": "vardecl.js"
|
|
161
161
|
}
|
|
162
162
|
},
|
|
163
163
|
"init": {
|
|
@@ -178,7 +178,7 @@
|
|
|
178
178
|
"line": 5,
|
|
179
179
|
"column": 12
|
|
180
180
|
},
|
|
181
|
-
"sourcefile": "
|
|
181
|
+
"sourcefile": "vardecl.js"
|
|
182
182
|
}
|
|
183
183
|
},
|
|
184
184
|
"cloned": false,
|
|
@@ -202,7 +202,7 @@
|
|
|
202
202
|
"line": 5,
|
|
203
203
|
"column": 12
|
|
204
204
|
},
|
|
205
|
-
"sourcefile": "
|
|
205
|
+
"sourcefile": "vardecl.js"
|
|
206
206
|
}
|
|
207
207
|
},
|
|
208
208
|
{
|
|
@@ -228,7 +228,7 @@
|
|
|
228
228
|
"line": 7,
|
|
229
229
|
"column": 7
|
|
230
230
|
},
|
|
231
|
-
"sourcefile": "
|
|
231
|
+
"sourcefile": "vardecl.js"
|
|
232
232
|
}
|
|
233
233
|
},
|
|
234
234
|
"init": {
|
|
@@ -250,7 +250,7 @@
|
|
|
250
250
|
"line": 7,
|
|
251
251
|
"column": 14
|
|
252
252
|
},
|
|
253
|
-
"sourcefile": "
|
|
253
|
+
"sourcefile": "vardecl.js"
|
|
254
254
|
}
|
|
255
255
|
},
|
|
256
256
|
"cloned": false,
|
|
@@ -269,7 +269,7 @@
|
|
|
269
269
|
"line": 7,
|
|
270
270
|
"column": 14
|
|
271
271
|
},
|
|
272
|
-
"sourcefile": "
|
|
272
|
+
"sourcefile": "vardecl.js"
|
|
273
273
|
}
|
|
274
274
|
},
|
|
275
275
|
{
|
|
@@ -292,7 +292,7 @@
|
|
|
292
292
|
"line": 7,
|
|
293
293
|
"column": 18
|
|
294
294
|
},
|
|
295
|
-
"sourcefile": "
|
|
295
|
+
"sourcefile": "vardecl.js"
|
|
296
296
|
}
|
|
297
297
|
},
|
|
298
298
|
"init": {
|
|
@@ -314,7 +314,7 @@
|
|
|
314
314
|
"line": 7,
|
|
315
315
|
"column": 26
|
|
316
316
|
},
|
|
317
|
-
"sourcefile": "
|
|
317
|
+
"sourcefile": "vardecl.js"
|
|
318
318
|
}
|
|
319
319
|
},
|
|
320
320
|
"cloned": false,
|
|
@@ -333,7 +333,7 @@
|
|
|
333
333
|
"line": 7,
|
|
334
334
|
"column": 26
|
|
335
335
|
},
|
|
336
|
-
"sourcefile": "
|
|
336
|
+
"sourcefile": "vardecl.js"
|
|
337
337
|
}
|
|
338
338
|
},
|
|
339
339
|
{
|
|
@@ -356,7 +356,7 @@
|
|
|
356
356
|
"line": 7,
|
|
357
357
|
"column": 30
|
|
358
358
|
},
|
|
359
|
-
"sourcefile": "
|
|
359
|
+
"sourcefile": "vardecl.js"
|
|
360
360
|
}
|
|
361
361
|
},
|
|
362
362
|
"init": {
|
|
@@ -377,7 +377,7 @@
|
|
|
377
377
|
"line": 7,
|
|
378
378
|
"column": 35
|
|
379
379
|
},
|
|
380
|
-
"sourcefile": "
|
|
380
|
+
"sourcefile": "vardecl.js"
|
|
381
381
|
}
|
|
382
382
|
},
|
|
383
383
|
"cloned": false,
|
|
@@ -396,7 +396,7 @@
|
|
|
396
396
|
"line": 7,
|
|
397
397
|
"column": 35
|
|
398
398
|
},
|
|
399
|
-
"sourcefile": "
|
|
399
|
+
"sourcefile": "vardecl.js"
|
|
400
400
|
}
|
|
401
401
|
}
|
|
402
402
|
],
|
|
@@ -415,7 +415,7 @@
|
|
|
415
415
|
"line": 7,
|
|
416
416
|
"column": 36
|
|
417
417
|
},
|
|
418
|
-
"sourcefile": "
|
|
418
|
+
"sourcefile": "vardecl.js"
|
|
419
419
|
}
|
|
420
420
|
},
|
|
421
421
|
{
|
|
@@ -438,7 +438,7 @@
|
|
|
438
438
|
"line": 9,
|
|
439
439
|
"column": 7
|
|
440
440
|
},
|
|
441
|
-
"sourcefile": "
|
|
441
|
+
"sourcefile": "vardecl.js"
|
|
442
442
|
}
|
|
443
443
|
},
|
|
444
444
|
"init": null,
|
|
@@ -463,14 +463,14 @@
|
|
|
463
463
|
"line": 9,
|
|
464
464
|
"column": 7
|
|
465
465
|
},
|
|
466
|
-
"sourcefile": "
|
|
466
|
+
"sourcefile": "vardecl.js"
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
469
|
],
|
|
470
470
|
"language": "javascript",
|
|
471
471
|
"languageVersion": null,
|
|
472
472
|
"uri": "",
|
|
473
|
-
"version": "0.
|
|
473
|
+
"version": "0.0.0",
|
|
474
474
|
"_meta": {
|
|
475
475
|
"_extra": {
|
|
476
476
|
"end": 83,
|
|
@@ -486,6 +486,6 @@
|
|
|
486
486
|
"line": 10,
|
|
487
487
|
"column": 1
|
|
488
488
|
},
|
|
489
|
-
"sourcefile": "
|
|
489
|
+
"sourcefile": "vardecl.js"
|
|
490
490
|
}
|
|
491
491
|
}
|
package/tests/index.ts
CHANGED
|
@@ -30,17 +30,17 @@ function normalizeAst(ast: any, currentSourceFile: string, currentVersion: strin
|
|
|
30
30
|
else if (key === 'uri' && cloned[key] === '') {
|
|
31
31
|
delete cloned[key];
|
|
32
32
|
}
|
|
33
|
-
//
|
|
34
|
-
else
|
|
33
|
+
// 递归处理子节点
|
|
34
|
+
else {
|
|
35
|
+
cloned[key] = normalizeAst(cloned[key], currentSourceFile, currentVersion);
|
|
36
|
+
}
|
|
37
|
+
// 删除 _meta._extra.start/end(避免字节偏移差异)
|
|
38
|
+
if (key === '_meta' && cloned[key]?.['_extra']?.hasOwnProperty('start')) {
|
|
35
39
|
const extra = { ...cloned[key]['_extra'] };
|
|
36
40
|
delete extra.start;
|
|
37
41
|
delete extra.end;
|
|
38
42
|
cloned[key] = { ...cloned[key], _extra: extra };
|
|
39
43
|
}
|
|
40
|
-
// 递归处理子节点
|
|
41
|
-
else {
|
|
42
|
-
cloned[key] = normalizeAst(cloned[key], currentSourceFile, currentVersion);
|
|
43
|
-
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
return cloned;
|
|
@@ -57,7 +57,7 @@ function refreshUastJson() {
|
|
|
57
57
|
for (const file of jsFiles) {
|
|
58
58
|
const fullPath = path.join(BASE_DIR, file);
|
|
59
59
|
const content = fs.readFileSync(fullPath, 'utf8');
|
|
60
|
-
const ast = parse(content, { sourcefile:
|
|
60
|
+
const ast = parse(content, { sourcefile: file, language: 'javascript' });
|
|
61
61
|
|
|
62
62
|
// ✅ 写入当前版本
|
|
63
63
|
ast.version = currentVersion;
|
|
@@ -111,11 +111,12 @@ describe('benchmark for javascript', () => {
|
|
|
111
111
|
assert.fail(`❌ Failed to read baseline ${baselinePath}: ${err}`);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
// ✅
|
|
114
|
+
// ✅ 标准化:替换 sourcefile 和 version,移除 _extra.start/end
|
|
115
115
|
const normalizedExpected = normalizeAst(expected, fullPath, currentVersion);
|
|
116
|
+
const normalizedActual = normalizeAst(actual, fullPath, currentVersion);
|
|
116
117
|
|
|
117
118
|
// 字符串化对比(格式化一致)
|
|
118
|
-
const actualStr = JSON.stringify(
|
|
119
|
+
const actualStr = JSON.stringify(normalizedActual, null, 2);
|
|
119
120
|
const expectedStr = JSON.stringify(normalizedExpected, null, 2);
|
|
120
121
|
|
|
121
122
|
// 断言
|