@katana-project/laser 0.2.4 → 0.3.1
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/resolver.d.ts +1 -0
- package/dist/resolver.js +22 -3
- package/dist/unit.d.ts +2 -3
- package/dist/unit.js +14 -7
- package/package.json +2 -2
package/dist/resolver.d.ts
CHANGED
package/dist/resolver.js
CHANGED
|
@@ -46,7 +46,8 @@ const getTypeName = (node, source, limit = node.to) => {
|
|
|
46
46
|
node.parent.name !== "ClassDeclaration" &&
|
|
47
47
|
node.parent.name !== "ConstructorDeclaration" &&
|
|
48
48
|
node.parent.name !== "InterfaceDeclaration" &&
|
|
49
|
-
node.parent.name !== "LocalVariableDeclaration"
|
|
49
|
+
node.parent.name !== "LocalVariableDeclaration" &&
|
|
50
|
+
node.parent.name !== "RecordDeclaration")) {
|
|
50
51
|
// only allow getting Definition-based type names from these declarations
|
|
51
52
|
return null;
|
|
52
53
|
}
|
|
@@ -97,8 +98,10 @@ const resolveInUnit = (typeName, unit) => {
|
|
|
97
98
|
return null;
|
|
98
99
|
};
|
|
99
100
|
const resolveImported = (typeRef, unit, externalRefs) => {
|
|
101
|
+
// type imports
|
|
100
102
|
for (const imp of unit.imports) {
|
|
101
|
-
if (
|
|
103
|
+
if (imp.kind === "type" &&
|
|
104
|
+
(imp.importedName === typeRef.name || imp.importedName.endsWith(`.${typeRef.name}`))) {
|
|
102
105
|
return {
|
|
103
106
|
kind: "imported",
|
|
104
107
|
name: typeRef.name,
|
|
@@ -107,8 +110,9 @@ const resolveImported = (typeRef, unit, externalRefs) => {
|
|
|
107
110
|
};
|
|
108
111
|
}
|
|
109
112
|
}
|
|
113
|
+
// wildcard imports
|
|
110
114
|
for (const imp of unit.imports) {
|
|
111
|
-
if (imp.
|
|
115
|
+
if (imp.kind === "wildcard") {
|
|
112
116
|
const matchingExternal = externalRefs.find((ext) => `${imp.importedName}.${typeRef.name}` === ext.qualifiedName);
|
|
113
117
|
if (matchingExternal) {
|
|
114
118
|
return {
|
|
@@ -120,6 +124,21 @@ const resolveImported = (typeRef, unit, externalRefs) => {
|
|
|
120
124
|
}
|
|
121
125
|
}
|
|
122
126
|
}
|
|
127
|
+
// module imports
|
|
128
|
+
for (const imp of unit.imports) {
|
|
129
|
+
if (imp.kind === "module") {
|
|
130
|
+
const matchingExternal = externalRefs.find((ext) => ext.moduleName === imp.importedName &&
|
|
131
|
+
(ext.name === typeRef.name || ext.qualifiedName.endsWith(`.${typeRef.name}`)));
|
|
132
|
+
if (matchingExternal) {
|
|
133
|
+
return {
|
|
134
|
+
kind: "imported",
|
|
135
|
+
name: typeRef.name,
|
|
136
|
+
qualifiedName: matchingExternal.qualifiedName,
|
|
137
|
+
ref: typeRef,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
123
142
|
// same-package classes
|
|
124
143
|
let matchingExternal = externalRefs.find((ext) => ext.packageName === (unit.packageName ?? "") && ext.name === typeRef.name);
|
|
125
144
|
if (!matchingExternal) {
|
package/dist/unit.d.ts
CHANGED
|
@@ -3,16 +3,15 @@ import { SyntaxNode, Tree } from "@lezer/common";
|
|
|
3
3
|
* Represents an import statement in a Java source file.
|
|
4
4
|
*/
|
|
5
5
|
export interface ImportInfo {
|
|
6
|
+
kind: "type" | "wildcard" | "static" | "module";
|
|
6
7
|
importedName: string;
|
|
7
|
-
isStatic: boolean;
|
|
8
|
-
isWildcard: boolean;
|
|
9
8
|
node: SyntaxNode;
|
|
10
9
|
}
|
|
11
10
|
/**
|
|
12
11
|
* Represents a type declaration (class, interface, enum, annotation, module) in a Java source file.
|
|
13
12
|
*/
|
|
14
13
|
export interface TypeInfo {
|
|
15
|
-
kind: "class" | "interface" | "enum" | "annotation" | "module";
|
|
14
|
+
kind: "class" | "interface" | "enum" | "annotation" | "module" | "record";
|
|
16
15
|
name: string;
|
|
17
16
|
qualifiedName: string;
|
|
18
17
|
node: SyntaxNode;
|
package/dist/unit.js
CHANGED
|
@@ -42,16 +42,19 @@ export const parseUnit = (tree, source) => {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
else if (node.name === "ImportDeclaration") {
|
|
45
|
-
const isStatic = !!findChild(node, (c) => c.name === "static");
|
|
46
|
-
const isWildcard = !!findChild(node, (c) => c.name === "Asterisk");
|
|
47
45
|
const nameNode = findChild(node, (c) => c.name === "Identifier" || c.name === "ScopedIdentifier");
|
|
48
46
|
if (nameNode) {
|
|
49
47
|
const importedName = source.slice(nameNode.from, nameNode.to);
|
|
50
48
|
if (importedName) {
|
|
51
49
|
unit.imports.push({
|
|
50
|
+
kind: findChild(node, (c) => c.name === "module")
|
|
51
|
+
? "module"
|
|
52
|
+
: findChild(node, (c) => c.name === "static")
|
|
53
|
+
? "static"
|
|
54
|
+
: findChild(node, (c) => c.name === "Asterisk")
|
|
55
|
+
? "wildcard"
|
|
56
|
+
: "type",
|
|
52
57
|
importedName,
|
|
53
|
-
isStatic,
|
|
54
|
-
isWildcard,
|
|
55
58
|
node,
|
|
56
59
|
});
|
|
57
60
|
}
|
|
@@ -61,7 +64,8 @@ export const parseUnit = (tree, source) => {
|
|
|
61
64
|
node.name === "InterfaceDeclaration" ||
|
|
62
65
|
node.name === "EnumDeclaration" ||
|
|
63
66
|
node.name === "AnnotationTypeDeclaration" ||
|
|
64
|
-
node.name === "ModuleDeclaration"
|
|
67
|
+
node.name === "ModuleDeclaration" ||
|
|
68
|
+
node.name === "RecordDeclaration") {
|
|
65
69
|
const defNode = findChild(node, (c) => c.name === "Definition" || c.name === "Identifier");
|
|
66
70
|
if (defNode) {
|
|
67
71
|
const name = source.slice(defNode.from, defNode.to);
|
|
@@ -76,7 +80,9 @@ export const parseUnit = (tree, source) => {
|
|
|
76
80
|
? "enum"
|
|
77
81
|
: node.name === "AnnotationTypeDeclaration"
|
|
78
82
|
? "annotation"
|
|
79
|
-
: "
|
|
83
|
+
: node.name === "ModuleDeclaration"
|
|
84
|
+
? "module"
|
|
85
|
+
: "record",
|
|
80
86
|
name,
|
|
81
87
|
qualifiedName,
|
|
82
88
|
node,
|
|
@@ -86,7 +92,8 @@ export const parseUnit = (tree, source) => {
|
|
|
86
92
|
c.name === "InterfaceBody" ||
|
|
87
93
|
c.name === "AnnotationTypeBody" ||
|
|
88
94
|
c.name === "ModuleBody" ||
|
|
89
|
-
c.name === "EnumBody"
|
|
95
|
+
c.name === "EnumBody" ||
|
|
96
|
+
c.name === "RecordBody");
|
|
90
97
|
if (classBody) {
|
|
91
98
|
let child = classBody.firstChild;
|
|
92
99
|
while (child) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@katana-project/laser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "katana-project",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@lezer/common": "^1.5.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@lezer
|
|
29
|
+
"@run-slicer/lezer-java": "^1.2.1",
|
|
30
30
|
"@types/chai": "^5.2.3",
|
|
31
31
|
"@types/mocha": "^10.0.10",
|
|
32
32
|
"@types/node": "^25.0.5",
|