Skip to content

Commit 063d180

Browse files
Refactored fixed LCETypeNotIdentified types to constants
1 parent 3567801 commit 063d180

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

typescript/src/core/concepts/type.concept.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,15 @@ export class LCETypeNotIdentified extends LCEType {
195195
public static override conceptId = "not-identified-type";
196196
public static readonly typeId = "not-identified";
197197

198+
public static readonly COMPLEX_VALUE = new this("Complex Value");
199+
public static readonly CLASS_EXPRESSION = new this("Class Expression");
200+
public static readonly CONSTRUCTOR = new this("Constructor");
201+
public static readonly SETTER = new this("Setter");
202+
public static readonly INDEXED_ACCESS_TYPE = new this("Type containing a (potentially recursive) indexed access type");
203+
public static readonly DEEP_PARTIAL_OBJECT = new this("Type containing DeepPartialObject (not supported)");
204+
198205
/**
199-
* @param identifier string representation of type that could not successfully parsed
206+
* @param identifier string representation of type that could not successfully be parsed
200207
*/
201208
constructor(public identifier: string) {
202209
super(LCETypeNotIdentified.typeId);

typescript/src/core/concepts/value.concept.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class LCEValueClass extends LCEValue {
171171
public static readonly valueTypeId = "class";
172172

173173
constructor() {
174-
super(LCEValueClass.valueTypeId, new LCETypeNotIdentified("class expression"));
174+
super(LCEValueClass.valueTypeId, LCETypeNotIdentified.CLASS_EXPRESSION);
175175
}
176176
}
177177

@@ -186,7 +186,7 @@ export class LCEValueComplex extends LCEValue {
186186
* @param expression string representation of the value's expression
187187
*/
188188
constructor(public expression: string) {
189-
super(LCEValueComplex.valueTypeId, new LCETypeNotIdentified("complex"));
189+
super(LCEValueComplex.valueTypeId, LCETypeNotIdentified.COMPLEX_VALUE);
190190
}
191191
}
192192

typescript/src/core/processors/class-like-declaration.processor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export class PropertyProcessor extends Processor {
320320
// indexed access type check to prevent infinite recursion on native type parsing
321321
const isIndexedAccessType = getAndDeleteChildConcepts<LCEIndexAccessTypeAnnotation>(PropertyTraverser.TYPE_ANNOTATION_PROP, LCEIndexAccessTypeAnnotation.conceptId, childConcepts).length > 0;
322322
const type = isIndexedAccessType ?
323-
new LCETypeNotIdentified("Type contains indexed access type (potentially recursive)") :
323+
LCETypeNotIdentified.INDEXED_ACCESS_TYPE :
324324
parseClassPropertyType({ globalContext, localContexts, node, ...unusedProcessingContext }, node.key);
325325

326326
return mergeConceptMaps(

typescript/src/core/processors/type.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function parseMethodType(
129129
)
130130
);
131131
}
132-
return new LCETypeFunction(new LCETypeNotIdentified("constructor"), parameters, false, []);
132+
return new LCETypeFunction(LCETypeNotIdentified.CONSTRUCTOR, parameters, false, []);
133133
} else if (esMethodDecl.kind === "get") {
134134
// getter
135135
return new LCETypeFunction(parseType(processingContext, methodType, methodNode), [], false, []);
@@ -140,7 +140,7 @@ export function parseMethodType(
140140
const paramNode = globalContext.services.esTreeNodeToTSNodeMap.get(param);
141141
const paramType = tc.getTypeAtLocation(paramNode);
142142
return new LCETypeFunction(
143-
new LCETypeNotIdentified("setter"),
143+
LCETypeNotIdentified.SETTER,
144144
[new LCETypeFunctionParameter(0, paramName, false, parseType(processingContext, paramType, methodNode))],
145145
false,
146146
[]
@@ -337,7 +337,7 @@ function parseType(processingContext: ProcessingContext, type: Type, node: Node,
337337
) {
338338
// TODO: handle recursive types like `_DeepPartialObject`
339339
if (type.aliasSymbol?.getName() === "_DeepPartialObject") {
340-
return new LCETypeNotIdentified("DeepPartialObject is not supported");
340+
return LCETypeNotIdentified.DEEP_PARTIAL_OBJECT;
341341
}
342342

343343
// anonymous type

typescript/test/core/integration/interface-declarations.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ describe("interface declarations test", () => {
521521
);
522522
expect(propA.type).toBeDefined();
523523
expect(propA.type.type).toBe(LCETypeNotIdentified.typeId);
524-
expect((propA.type as LCETypeNotIdentified).identifier).toBe("Type contains indexed access type (potentially recursive)");
524+
expect((propA.type as LCETypeNotIdentified).identifier).toBe(LCETypeNotIdentified.INDEXED_ACCESS_TYPE.identifier);
525525

526526
// The following would represent a correct check with full type tracing: (TODO: implement fine-grained indexed access type resolution)
527527
// const propAObjType = expectObjectType(propA.type, 3);
@@ -556,7 +556,7 @@ describe("interface declarations test", () => {
556556
);
557557
expect(propB.type).toBeDefined();
558558
expect(propB.type.type).toBe(LCETypeNotIdentified.typeId);
559-
expect((propB.type as LCETypeNotIdentified).identifier).toBe("Type contains indexed access type (potentially recursive)");
559+
expect((propB.type as LCETypeNotIdentified).identifier).toBe(LCETypeNotIdentified.INDEXED_ACCESS_TYPE.identifier);
560560

561561
// The following would represent a correct check with full type tracing:
562562
// const propBObjType = expectObjectType(propB.type, 3);

typescript/test/core/integration/variable-declarations.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ describe("variable declarations test", () => {
463463

464464
expect(decl.initValue.type).toBeDefined();
465465
expect(decl.initValue.type.type).toBe(LCETypeNotIdentified.typeId);
466-
expect((decl.initValue.type as LCETypeNotIdentified).identifier).toBe("class expression");
466+
expect((decl.initValue.type as LCETypeNotIdentified).identifier).toBe(LCETypeNotIdentified.CLASS_EXPRESSION.identifier);
467467
}
468468
}
469469
});
@@ -555,7 +555,7 @@ describe("variable declarations test", () => {
555555

556556
expect(decl.initValue.type).toBeDefined();
557557
expect(decl.initValue.type.type).toBe(LCETypeNotIdentified.typeId);
558-
expect((decl.initValue.type as LCETypeNotIdentified).identifier).toBe("complex");
558+
expect((decl.initValue.type as LCETypeNotIdentified).identifier).toBe(LCETypeNotIdentified.COMPLEX_VALUE.identifier);
559559
}
560560
}
561561
});
@@ -736,7 +736,7 @@ describe("variable declarations test", () => {
736736

737737
expect(decl.initValue.type).toBeDefined();
738738
expect(decl.initValue.type.type).toBe(LCETypeNotIdentified.typeId);
739-
expect((decl.initValue.type as LCETypeNotIdentified).identifier).toBe("complex");
739+
expect((decl.initValue.type as LCETypeNotIdentified).identifier).toBe(LCETypeNotIdentified.COMPLEX_VALUE.identifier);
740740
}
741741
}
742742

@@ -874,7 +874,7 @@ describe("variable declarations test", () => {
874874

875875
expect(decl.initValue.type).toBeDefined();
876876
expect(decl.initValue.type.type).toBe(LCETypeNotIdentified.typeId);
877-
expect((decl.initValue.type as LCETypeNotIdentified).identifier).toBe("complex");
877+
expect((decl.initValue.type as LCETypeNotIdentified).identifier).toBe(LCETypeNotIdentified.COMPLEX_VALUE.identifier);
878878
}
879879
}
880880

0 commit comments

Comments
 (0)