Skip to content

Commit 6324fc1

Browse files
committed
refactor(parser): combine statements with the same return type
1 parent 6486352 commit 6324fc1

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/parser.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,7 @@ export function parseFromProgram(filePath: string, program: ts.Program) {
253253
return t.undefinedNode();
254254
}
255255

256-
if (type.flags & ts.TypeFlags.Object) {
257-
return type.getCallSignatures().length === 0 ? t.objectNode() : t.functionNode();
258-
}
259-
260-
if (type.flags & ts.TypeFlags.Any) {
256+
if (type.flags & ts.TypeFlags.Any || type.flags & ts.TypeFlags.Unknown) {
261257
return t.anyNode();
262258
}
263259

@@ -271,21 +267,25 @@ export function parseFromProgram(filePath: string, program: ts.Program) {
271267
return t.literalNode(checker.typeToString(type));
272268
}
273269

274-
if (type.flags & ts.TypeFlags.NonPrimitive && checker.typeToString(type) === 'object') {
275-
return t.objectNode();
276-
}
277-
278270
if (type.flags & ts.TypeFlags.Null) {
279271
return t.literalNode('null');
280272
}
281273

282-
// {foo: string} & {bar: string}
283-
if (type.isIntersection()) {
274+
if (type.getCallSignatures().length) {
275+
return t.functionNode();
276+
}
277+
278+
// Object-like type
279+
if (type.getProperties().length) {
284280
return t.objectNode();
285281
}
286282

287-
if (type.flags & ts.TypeFlags.Unknown) {
288-
return t.anyNode();
283+
// Object without properties or object keyword
284+
if (
285+
type.flags & ts.TypeFlags.Object ||
286+
(type.flags & ts.TypeFlags.NonPrimitive && checker.typeToString(type) === 'object')
287+
) {
288+
return t.objectNode();
289289
}
290290

291291
console.warn(

0 commit comments

Comments
 (0)