Skip to content

Commit e40fef9

Browse files
committed
Ignore unsupported function types
1 parent d58bfa2 commit e40fef9

4 files changed

Lines changed: 28 additions & 9 deletions

File tree

lib/parse/MemberLoader.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ export class MemberLoader {
5151
case AST_NODE_TYPES.TSPropertySignature:
5252
case AST_NODE_TYPES.TSMethodSignature:
5353
if (element.key.type === 'Identifier') {
54-
const typeNode = 'typeAnnotation' in element ? element.typeAnnotation!.typeAnnotation : undefined;
54+
// TODO: more types may be needed here, such as AST_NODE_TYPES.TSPropertySignature
55+
const typeNode = element.type === AST_NODE_TYPES.ClassProperty ||
56+
element.type === AST_NODE_TYPES.TSAbstractClassProperty ?
57+
element.typeAnnotation?.typeAnnotation :
58+
undefined;
5559
members.push({
5660
name: element.key.name,
5761
range: typeNode ?

lib/parse/ParameterLoader.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ export class ParameterLoader {
400400
case AST_NODE_TYPES.TSNullKeyword:
401401
case AST_NODE_TYPES.TSAnyKeyword:
402402
return { type: 'wildcard' };
403+
case AST_NODE_TYPES.TSFunctionType:
404+
case AST_NODE_TYPES.TSImportType:
405+
// These types are explicitly not supported
406+
return { type: 'wildcard' };
403407
case AST_NODE_TYPES.TSTupleType:
404408
return {
405409
type: 'tuple',

test/parse/MemberLoader.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ private functionB(): string{}
184184
},
185185
]);
186186
});
187+
188+
it('for simple fields without type annotation', async() => {
189+
expect(parser.collectClassFields(getClassBody(`
190+
fieldA;
191+
fieldB;
192+
`))).toMatchObject([
193+
{
194+
name: 'fieldA',
195+
},
196+
{
197+
name: 'fieldB',
198+
},
199+
]);
200+
});
187201
});
188202

189203
describe('for interfaces', () => {
@@ -198,17 +212,9 @@ fieldB: MyClass;
198212
`))).toMatchObject([
199213
{
200214
name: 'fieldA',
201-
range: {
202-
type: 'raw',
203-
value: 'string',
204-
},
205215
},
206216
{
207217
name: 'fieldB',
208-
range: {
209-
type: 'interface',
210-
value: 'MyClass',
211-
},
212218
},
213219
]);
214220
});

test/parse/ParameterLoader.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,11 @@ export interface A{
18231823
.toEqual({ type: 'wildcard' });
18241824
});
18251825

1826+
it('should get the range of unsupported types as wildcard', async() => {
1827+
expect(await getFieldRange('fieldA: () => void', {}))
1828+
.toEqual({ type: 'wildcard' });
1829+
});
1830+
18261831
it('should get the range of a union type of two raw types', async() => {
18271832
expect(await getFieldRange('fieldA: number | string', {}))
18281833
.toEqual({

0 commit comments

Comments
 (0)