@ant-yasa/uast-parser-php 0.2.10 → 0.2.11
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 +0 -1
- package/dist/src/parser.js +147 -11
- package/dist/src/parser.js.map +1 -1
- package/package.json +1 -2
- package/src/index.ts +0 -26
- package/src/parser.ts +0 -1234
- package/tests/benchmark/base/advanced.php +0 -20
- package/tests/benchmark/base/advanced.php.json +0 -1269
- package/tests/benchmark/base/basic.php +0 -3
- package/tests/benchmark/base/basic.php.json +0 -292
- package/tests/benchmark/base/closure-class.php +0 -24
- package/tests/benchmark/base/closure-class.php.json +0 -1623
- package/tests/benchmark/base/control-flow.php +0 -37
- package/tests/benchmark/base/control-flow.php.json +0 -2010
- package/tests/benchmark/base/enum-trait-adapt.php +0 -31
- package/tests/benchmark/base/enum-trait-adapt.php.json +0 -965
- package/tests/benchmark/base/exprs.php +0 -4
- package/tests/benchmark/base/exprs.php.json +0 -811
- package/tests/benchmark/base/flow-extras.php +0 -12
- package/tests/benchmark/base/flow-extras.php.json +0 -897
- package/tests/benchmark/base/function.php +0 -7
- package/tests/benchmark/base/function.php.json +0 -536
- package/tests/benchmark/base/modern-php.php +0 -13
- package/tests/benchmark/base/modern-php.php.json +0 -508
- package/tests/benchmark/base/namespace.php +0 -5
- package/tests/benchmark/base/namespace.php.json +0 -307
- package/tests/benchmark/base/new-static.php +0 -3
- package/tests/benchmark/base/new-static.php.json +0 -399
- package/tests/benchmark/base/runtime.php +0 -13
- package/tests/benchmark/base/runtime.php.json +0 -1095
- package/tests/benchmark/base/strings-casts.php +0 -17
- package/tests/benchmark/base/strings-casts.php.json +0 -1357
- package/tests/benchmark/base/structures.php +0 -26
- package/tests/benchmark/base/structures.php.json +0 -1582
- package/tests/index.ts +0 -87
package/tests/index.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import 'mocha';
|
|
2
|
-
import * as assert from 'assert';
|
|
3
|
-
import * as fs from 'fs';
|
|
4
|
-
import * as path from 'path';
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import fastGlob from 'fast-glob';
|
|
7
|
-
import { init, parse } from '../src/parser';
|
|
8
|
-
|
|
9
|
-
function getCurrentVersion(): string {
|
|
10
|
-
return process.env.UAST_VERSION || require('../package.json').version;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function normalizeAst(ast: any, currentSourceFile: string, currentVersion: string): any {
|
|
14
|
-
if (!ast || typeof ast !== 'object') return ast;
|
|
15
|
-
|
|
16
|
-
const cloned = Array.isArray(ast) ? [...ast] : { ...ast };
|
|
17
|
-
|
|
18
|
-
for (const key in cloned) {
|
|
19
|
-
if (!Object.prototype.hasOwnProperty.call(cloned, key)) continue;
|
|
20
|
-
|
|
21
|
-
if (key === 'sourcefile' && typeof cloned[key] === 'string') {
|
|
22
|
-
cloned[key] = currentSourceFile;
|
|
23
|
-
} else if (key === 'version' && typeof cloned[key] === 'string') {
|
|
24
|
-
cloned[key] = currentVersion;
|
|
25
|
-
} else if (key === '_meta' && cloned[key]?.origin) {
|
|
26
|
-
const meta = { ...cloned[key] };
|
|
27
|
-
delete meta.origin;
|
|
28
|
-
cloned[key] = normalizeAst(meta, currentSourceFile, currentVersion);
|
|
29
|
-
} else {
|
|
30
|
-
cloned[key] = normalizeAst(cloned[key], currentSourceFile, currentVersion);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return cloned;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function refreshUastJson() {
|
|
38
|
-
const baseDir = path.join(__dirname, 'benchmark', 'base');
|
|
39
|
-
const phpFiles = fastGlob.sync('*.php', { cwd: baseDir });
|
|
40
|
-
const currentVersion = getCurrentVersion();
|
|
41
|
-
|
|
42
|
-
for (const file of phpFiles) {
|
|
43
|
-
const fullPath = path.join(baseDir, file);
|
|
44
|
-
const content = fs.readFileSync(fullPath, 'utf8');
|
|
45
|
-
const ast = parse(content, { sourcefile: file });
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
ast.version = currentVersion;
|
|
48
|
-
fs.writeFileSync(`${fullPath}.json`, JSON.stringify(ast, null, 2), 'utf8');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function shouldRefresh(): boolean {
|
|
53
|
-
return process.argv.includes('--refresh') || process.argv.includes('-r');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (shouldRefresh()) {
|
|
57
|
-
init().then(() => {
|
|
58
|
-
refreshUastJson();
|
|
59
|
-
process.exit(0);
|
|
60
|
-
});
|
|
61
|
-
} else {
|
|
62
|
-
|
|
63
|
-
describe('benchmark for php', () => {
|
|
64
|
-
const baseDir = path.join(__dirname, 'benchmark', 'base');
|
|
65
|
-
const phpFiles = fastGlob.sync('*.php', { cwd: baseDir });
|
|
66
|
-
const currentVersion = getCurrentVersion();
|
|
67
|
-
|
|
68
|
-
before(async () => {
|
|
69
|
-
await init();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
for (const phpFile of phpFiles) {
|
|
73
|
-
it(phpFile, () => {
|
|
74
|
-
const fullPath = path.join(baseDir, phpFile);
|
|
75
|
-
const content = fs.readFileSync(fullPath, 'utf8');
|
|
76
|
-
const actual = parse(content, { sourcefile: phpFile });
|
|
77
|
-
const expected = JSON.parse(fs.readFileSync(`${fullPath}.json`, 'utf8'));
|
|
78
|
-
|
|
79
|
-
const actualStr = JSON.stringify(normalizeAst(actual, phpFile, currentVersion), null, 2);
|
|
80
|
-
const expectedStr = JSON.stringify(normalizeAst(expected, phpFile, currentVersion), null, 2);
|
|
81
|
-
|
|
82
|
-
assert.strictEqual(actualStr, expectedStr, `UAST mismatch in ${phpFile}`);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
} // end else (not refresh)
|