@ant-yasa/uast-parser-java-js 0.2.6 → 0.2.8

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "version": "0.0.0",
4
4
  "description": "for converting specific language to UAST",
5
5
  "dependencies": {
6
- "@ant-yasa/uast-spec": "file:../specification",
6
+ "@ant-yasa/uast-spec": "^0.2.0",
7
7
  "@babel/core": "^7.18.0",
8
8
  "@babel/parser": "^7.18.0",
9
9
  "@babel/plugin-proposal-class-properties": "7.18.6",
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@ant-yasa/uast-parser-java-js",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "for converting specific language to UAST",
5
5
  "dependencies": {
6
- "@ant-yasa/uast-spec": "file:../specification",
6
+ "@ant-yasa/uast-spec": "^0.2.0",
7
7
  "@babel/core": "^7.18.0",
8
8
  "@babel/parser": "^7.18.0",
9
9
  "@babel/plugin-proposal-class-properties": "7.18.6",
package/tests/index.ts CHANGED
@@ -10,8 +10,8 @@ function getCurrentVersion(): string {
10
10
  return process.env.UAST_VERSION || require('../package.json').version;
11
11
  }
12
12
 
13
- // 动态替换 AST 中的 sourcefile 和 version 字段
14
- function normalizeAst(ast: any, currentSourceFile: string, currentVersion: string): any {
13
+ // 动态替换 AST 中的 sourcefile 和 version 字段,避免 baseline 混入机器绝对路径。
14
+ function normalizeAst(ast: any, stableSourceFile: string, currentVersion: string): any {
15
15
  if (!ast || typeof ast !== 'object') return ast;
16
16
 
17
17
  const cloned = Array.isArray(ast) ? [...ast] : { ...ast };
@@ -20,7 +20,7 @@ function normalizeAst(ast: any, currentSourceFile: string, currentVersion: strin
20
20
  if (Object.prototype.hasOwnProperty.call(cloned, key)) {
21
21
  // 替换 sourcefile 为当前环境的真实路径
22
22
  if (key === 'sourcefile' && typeof cloned[key] === 'string') {
23
- cloned[key] = currentSourceFile;
23
+ cloned[key] = stableSourceFile;
24
24
  }
25
25
  // 替换 version 为当前版本
26
26
  else if (key === 'version' && typeof cloned[key] === 'string') {
@@ -32,7 +32,7 @@ function normalizeAst(ast: any, currentSourceFile: string, currentVersion: strin
32
32
  }
33
33
  // 递归处理子节点
34
34
  else {
35
- cloned[key] = normalizeAst(cloned[key], currentSourceFile, currentVersion);
35
+ cloned[key] = normalizeAst(cloned[key], stableSourceFile, currentVersion);
36
36
  }
37
37
  // 删除 _meta._extra.start/end(避免字节偏移差异)
38
38
  if (key === '_meta' && cloned[key]?.['_extra']?.hasOwnProperty('start')) {
@@ -112,8 +112,8 @@ describe('benchmark for javascript', () => {
112
112
  }
113
113
 
114
114
  // ✅ 标准化:替换 sourcefile 和 version,移除 _extra.start/end
115
- const normalizedExpected = normalizeAst(expected, fullPath, currentVersion);
116
- const normalizedActual = normalizeAst(actual, fullPath, currentVersion);
115
+ const normalizedExpected = normalizeAst(expected, jsFile, currentVersion);
116
+ const normalizedActual = normalizeAst(actual, jsFile, currentVersion);
117
117
 
118
118
  // 字符串化对比(格式化一致)
119
119
  const actualStr = JSON.stringify(normalizedActual, null, 2);