@katana-project/laser 0.2.2 → 0.2.3
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.js +9 -8
- package/package.json +1 -1
package/dist/resolver.js
CHANGED
|
@@ -9,14 +9,16 @@ const ALLOWED_PARENTS = new Set([
|
|
|
9
9
|
"Definition",
|
|
10
10
|
"FieldAccess",
|
|
11
11
|
]);
|
|
12
|
-
|
|
12
|
+
// the limit here is kinda hacking around cases where we don't want the entire fully qualified name
|
|
13
|
+
// the AST is a bit awkward to work with in this regard
|
|
14
|
+
const getTypeName = (node, source, limit = node.to) => {
|
|
13
15
|
switch (node.name) {
|
|
14
16
|
case "TypeName":
|
|
15
17
|
case "ScopedTypeName": {
|
|
16
18
|
if (node.parent && ALLOWED_PARENTS.has(node.parent.type.name)) {
|
|
17
|
-
return getTypeName(node.parent, source);
|
|
19
|
+
return getTypeName(node.parent, source, limit);
|
|
18
20
|
}
|
|
19
|
-
return source.slice(node.from, node.to);
|
|
21
|
+
return source.slice(node.from, Math.min(limit, node.to));
|
|
20
22
|
}
|
|
21
23
|
case "PrimitiveType":
|
|
22
24
|
case "void": {
|
|
@@ -30,10 +32,9 @@ const getTypeName = (node, source) => {
|
|
|
30
32
|
}
|
|
31
33
|
else if (node.parent.name !== "MarkerAnnotation" &&
|
|
32
34
|
node.parent.name !== "Annotation" &&
|
|
33
|
-
node.parent.name !== "AnnotationTypeDeclaration"
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
// only allow getting Identifier-based type names from annotations or class literals
|
|
35
|
+
node.parent.name !== "AnnotationTypeDeclaration") {
|
|
36
|
+
// TODO: class literals are a bit broken in the AST, work around that here
|
|
37
|
+
// only allow getting Identifier-based type names from annotations
|
|
37
38
|
return null;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
@@ -169,7 +170,7 @@ export const resolveTypeReference = (typeRef, unit, externalRefs = []) => {
|
|
|
169
170
|
if (localResolved) {
|
|
170
171
|
return {
|
|
171
172
|
kind: "declared",
|
|
172
|
-
name: localResolved.qualifiedName,
|
|
173
|
+
name: typeName.includes(".") ? typeName : localResolved.qualifiedName,
|
|
173
174
|
qualifiedName: (unit.packageName ? `${unit.packageName}.` : "") + localResolved.qualifiedName,
|
|
174
175
|
declaration: localResolved.node,
|
|
175
176
|
ref: typeRef,
|