@itrocks/parameter-name 0.0.5 → 0.2.0
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/cjs/parameter-name.js +35 -27
- package/package.json +8 -13
- package/esm/parameter-name.d.ts +0 -1
- package/esm/parameter-name.js +0 -29
package/cjs/parameter-name.js
CHANGED
|
@@ -1,35 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const node_fs_1 = require("node:fs");
|
|
8
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
9
|
-
function parameterNamesFromFile(fileName, className, methodName) {
|
|
1
|
+
import { isClassDeclaration } from 'typescript/unstable/ast';
|
|
2
|
+
import { isConstructorDeclaration } from 'typescript/unstable/ast';
|
|
3
|
+
import { isIdentifier } from 'typescript/unstable/ast';
|
|
4
|
+
import { isMethodDeclaration } from 'typescript/unstable/ast';
|
|
5
|
+
import { API } from 'typescript/unstable/sync';
|
|
6
|
+
export function parameterNamesFromFile(fileName, className, methodName) {
|
|
10
7
|
const isMethod = (methodName === 'constructor')
|
|
11
|
-
?
|
|
8
|
+
? isConstructorDeclaration
|
|
12
9
|
: function (node) {
|
|
13
|
-
return
|
|
10
|
+
return isMethodDeclaration(node) && isIdentifier(node.name) && (node.name.text === methodName);
|
|
14
11
|
};
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return typescript_1.default.forEachChild(node, searchMethod);
|
|
12
|
+
const declarationFileName = fileName.substring(0, fileName.lastIndexOf('.')) + '.d.ts';
|
|
13
|
+
const api = new API();
|
|
14
|
+
try {
|
|
15
|
+
const snapshot = api.updateSnapshot({ openFiles: [declarationFileName] });
|
|
16
|
+
const project = snapshot.getDefaultProjectForFile(declarationFileName);
|
|
17
|
+
const sourceFile = project?.program.getSourceFile(declarationFileName);
|
|
18
|
+
if (!sourceFile) {
|
|
19
|
+
return [];
|
|
24
20
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
let propertyNames = new Array;
|
|
22
|
+
function searchClass(node) {
|
|
23
|
+
if (isClassDeclaration(node)
|
|
24
|
+
&& node.name
|
|
25
|
+
&& isIdentifier(node.name)
|
|
26
|
+
&& (node.name.text === className)) {
|
|
27
|
+
return node.forEachChild(searchMethod);
|
|
28
|
+
}
|
|
29
|
+
node.forEachChild(searchClass);
|
|
30
|
+
}
|
|
31
|
+
function searchMethod(node) {
|
|
32
|
+
if (isMethod(node)) {
|
|
33
|
+
propertyNames = node.parameters.map(parameter => isIdentifier(parameter.name) ? parameter.name.text : '');
|
|
34
|
+
}
|
|
30
35
|
}
|
|
36
|
+
searchClass(sourceFile);
|
|
37
|
+
return propertyNames;
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
api.close();
|
|
31
41
|
}
|
|
32
|
-
searchClass(sourceFile);
|
|
33
|
-
return propertyNames;
|
|
34
42
|
}
|
|
35
43
|
//# sourceMappingURL=parameter-name.js.map
|
package/package.json
CHANGED
|
@@ -5,24 +5,20 @@
|
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@itrocks/class-type": "latest",
|
|
8
|
-
"typescript": "
|
|
8
|
+
"typescript": "^7.0"
|
|
9
9
|
},
|
|
10
10
|
"description": "Runtime parameter name reflection from TypeScript declaration files",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@types/node": "^24.10"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
16
|
-
},
|
|
17
|
-
"exports": {
|
|
18
|
-
"import": "./esm/parameter-name.js",
|
|
19
|
-
"require": "./cjs/parameter-name.js"
|
|
15
|
+
"node": ">=24"
|
|
20
16
|
},
|
|
17
|
+
"exports": "./cjs/parameter-name.js",
|
|
21
18
|
"files": [
|
|
22
19
|
"LICENSE",
|
|
23
20
|
"README.md",
|
|
24
|
-
"cjs
|
|
25
|
-
"esm/*",
|
|
21
|
+
"cjs",
|
|
26
22
|
"!*.map"
|
|
27
23
|
],
|
|
28
24
|
"homepage": "https://it.rocks",
|
|
@@ -51,10 +47,9 @@
|
|
|
51
47
|
"url": "git+https://github.com/itrocks-ts/parameter-name.git"
|
|
52
48
|
},
|
|
53
49
|
"scripts": {
|
|
54
|
-
"build": "
|
|
55
|
-
"
|
|
56
|
-
"
|
|
50
|
+
"build": "tsc",
|
|
51
|
+
"pretest": "npm run build",
|
|
52
|
+
"test": "node --test"
|
|
57
53
|
},
|
|
58
|
-
"
|
|
59
|
-
"version": "0.0.5"
|
|
54
|
+
"version": "0.2.0"
|
|
60
55
|
}
|
package/esm/parameter-name.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function parameterNamesFromFile(fileName: string, className: string, methodName: string): string[];
|
package/esm/parameter-name.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import ts from 'typescript';
|
|
3
|
-
export function parameterNamesFromFile(fileName, className, methodName) {
|
|
4
|
-
const isMethod = (methodName === 'constructor')
|
|
5
|
-
? ts.isConstructorDeclaration
|
|
6
|
-
: function (node) {
|
|
7
|
-
return ts.isMethodDeclaration(node) && node.name && ts.isIdentifier(node.name) && (node.name.text === methodName);
|
|
8
|
-
};
|
|
9
|
-
const content = readFileSync(fileName.substring(0, fileName.lastIndexOf('.')) + '.d.ts', 'utf8');
|
|
10
|
-
const sourceFile = ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true);
|
|
11
|
-
let propertyNames = new Array;
|
|
12
|
-
function searchClass(node) {
|
|
13
|
-
if (ts.isClassDeclaration(node)
|
|
14
|
-
&& node.name
|
|
15
|
-
&& ts.isIdentifier(node.name)
|
|
16
|
-
&& (node.name.text === className)) {
|
|
17
|
-
return ts.forEachChild(node, searchMethod);
|
|
18
|
-
}
|
|
19
|
-
ts.forEachChild(node, searchClass);
|
|
20
|
-
}
|
|
21
|
-
function searchMethod(node) {
|
|
22
|
-
if (isMethod(node)) {
|
|
23
|
-
propertyNames = node.parameters.map(parameter => ts.isIdentifier(parameter.name) ? parameter.name.text : '');
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
searchClass(sourceFile);
|
|
27
|
-
return propertyNames;
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=parameter-name.js.map
|