Skip to content

Commit 193ea08

Browse files
committed
Generate wildcard parameter ranges
1 parent 9816599 commit 193ea08

7 files changed

Lines changed: 58 additions & 16 deletions

File tree

lib/parse/ParameterLoader.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,13 @@ export class ParameterLoader {
387387
};
388388
case AST_NODE_TYPES.TSParenthesizedType:
389389
return this.getRangeFromTypeNode(classLoaded, typeNode.typeAnnotation, errorIdentifier);
390-
case AST_NODE_TYPES.TSUnknownKeyword:
391390
case AST_NODE_TYPES.TSUndefinedKeyword:
391+
return { type: 'undefined' };
392+
case AST_NODE_TYPES.TSUnknownKeyword:
392393
case AST_NODE_TYPES.TSVoidKeyword:
393394
case AST_NODE_TYPES.TSNullKeyword:
394395
case AST_NODE_TYPES.TSAnyKeyword:
395-
return { type: 'undefined' };
396+
return { type: 'wildcard' };
396397
case AST_NODE_TYPES.TSTupleType:
397398
return {
398399
type: 'tuple',
@@ -508,6 +509,7 @@ export class ParameterLoader {
508509
// Replace these types
509510
return override;
510511
case 'undefined':
512+
case 'wildcard':
511513
case 'override':
512514
// Override has no effect here
513515
return range;
@@ -731,6 +733,8 @@ export type ParameterRangeUnresolved = {
731733
value: TSTypeLiteral;
732734
} | {
733735
type: 'undefined';
736+
} | {
737+
type: 'wildcard';
734738
} | {
735739
type: 'union';
736740
elements: ParameterRangeUnresolved[];
@@ -772,6 +776,8 @@ export type ParameterRangeResolved = {
772776
value: ParameterData<ParameterRangeResolved>[];
773777
} | {
774778
type: 'undefined';
779+
} | {
780+
type: 'wildcard';
775781
} | {
776782
type: 'union';
777783
elements: ParameterRangeResolved[];

lib/parse/ParameterResolver.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class ParameterResolver {
211211
case 'interface':
212212
if (this.isIgnored(range.qualifiedPath, range.value)) {
213213
return {
214-
type: 'undefined',
214+
type: 'wildcard',
215215
};
216216
}
217217

@@ -243,6 +243,10 @@ export class ParameterResolver {
243243
value: await this
244244
.getNestedFieldsFromHash(range.value, owningClass, genericTypeRemappings, handlingInterfaces),
245245
};
246+
case 'wildcard':
247+
return {
248+
type: 'wildcard',
249+
};
246250
case 'undefined':
247251
return {
248252
type: 'undefined',
@@ -291,6 +295,8 @@ export class ParameterResolver {
291295
switch (range.type) {
292296
case 'undefined':
293297
return 'undefined';
298+
case 'wildcard':
299+
return 'wildcard';
294300
case 'interface':
295301
case 'genericTypeReference':
296302
case 'raw':

lib/serialize/ComponentConstructor.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,16 @@ export class ComponentConstructor {
731731
case 'nested':
732732
// TODO: Composition of nested fields is unsupported
733733
return {
734-
'@type': 'ParameterRangeUndefined',
734+
'@type': 'ParameterRangeWildcard',
735735
};
736736
case 'undefined':
737737
return {
738738
'@type': 'ParameterRangeUndefined',
739739
};
740+
case 'wildcard':
741+
return {
742+
'@type': 'ParameterRangeWildcard',
743+
};
740744
case 'union':
741745
case 'intersection':
742746
case 'tuple':

lib/serialize/ComponentDefinitions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export type ParameterDefinitionRange = string | { '@id': string; parameters: Par
5858
parameterRangeValue: ParameterDefinitionRange;
5959
} | {
6060
'@type': 'ParameterRangeUndefined';
61+
} | {
62+
'@type': 'ParameterRangeWildcard';
6163
} | {
6264
'@type': 'ParameterRangeCollectEntries';
6365
'parameterRangeCollectEntriesParameters': ParameterDefinition[];

test/parse/ParameterLoader.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,29 +1779,29 @@ export interface A{
17791779
});
17801780
});
17811781

1782-
it('should get the range of an unknown type as undefined', async() => {
1782+
it('should get the range of an unknown type as wildcard', async() => {
17831783
expect(await getFieldRange('fieldA: unknown', {}))
1784-
.toEqual({ type: 'undefined' });
1784+
.toEqual({ type: 'wildcard' });
17851785
});
17861786

17871787
it('should get the range of an undefined type as undefined', async() => {
17881788
expect(await getFieldRange('fieldA: undefined', {}))
17891789
.toEqual({ type: 'undefined' });
17901790
});
17911791

1792-
it('should get the range of an any type as undefined', async() => {
1792+
it('should get the range of an any type as wildcard', async() => {
17931793
expect(await getFieldRange('fieldA: any', {}))
1794-
.toEqual({ type: 'undefined' });
1794+
.toEqual({ type: 'wildcard' });
17951795
});
17961796

1797-
it('should get the range of an void type as undefined', async() => {
1797+
it('should get the range of an void type as wildcard', async() => {
17981798
expect(await getFieldRange('fieldA: void', {}))
1799-
.toEqual({ type: 'undefined' });
1799+
.toEqual({ type: 'wildcard' });
18001800
});
18011801

1802-
it('should get the range of a null type as undefined', async() => {
1802+
it('should get the range of a null type as wildcard', async() => {
18031803
expect(await getFieldRange('fieldA: null', {}))
1804-
.toEqual({ type: 'undefined' });
1804+
.toEqual({ type: 'wildcard' });
18051805
});
18061806

18071807
it('should get the range of a union type of two raw types', async() => {

test/parse/ParameterResolver.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,11 @@ describe('ParameterResolver', () => {
542542
.toEqual('undefined');
543543
});
544544

545+
it('should hash wildcard', () => {
546+
expect(loader.hashParameterRangeUnresolved({ type: 'wildcard' }))
547+
.toEqual('wildcard');
548+
});
549+
545550
it('should hash interface', () => {
546551
expect(loader.hashParameterRangeUnresolved(<any> { type: 'interface', value: 'IFACE' }))
547552
.toEqual('interface:IFACE');
@@ -724,7 +729,7 @@ describe('ParameterResolver', () => {
724729
genericTypeParameterInstantiations: [],
725730
origin: classReference,
726731
}, classReference, {}, true, new Set())).toMatchObject({
727-
type: 'undefined',
732+
type: 'wildcard',
728733
});
729734
});
730735

@@ -741,7 +746,7 @@ describe('ParameterResolver', () => {
741746
genericTypeParameterInstantiations: [],
742747
origin: classReference,
743748
}, classReference, {}, true, new Set())).toMatchObject({
744-
type: 'undefined',
749+
type: 'wildcard',
745750
});
746751
});
747752

@@ -805,6 +810,14 @@ export interface MyInterface extends IgnoredInterface{};
805810
});
806811
});
807812

813+
it('should handle a wildcard range', async() => {
814+
expect(await loader.resolveRange({
815+
type: 'wildcard',
816+
}, classReference, {}, true, new Set())).toMatchObject({
817+
type: 'wildcard',
818+
});
819+
});
820+
808821
it('should handle an undefined range', async() => {
809822
expect(await loader.resolveRange({
810823
type: 'undefined',

test/serialize/ComponentConstructor.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,15 +2468,15 @@ describe('ComponentConstructor', () => {
24682468
});
24692469
});
24702470

2471-
it('should construct on a nested parameter range as undefined', async() => {
2471+
it('should construct on a nested parameter range as wildcard', async() => {
24722472
const rangeValue: ParameterData<any>[] = [];
24732473
expect(await ctor.constructParameterRange(
24742474
{ type: 'nested', value: rangeValue },
24752475
context,
24762476
externalContextsCallback,
24772477
'mp:components/a/b/file-param.jsonld#MyClass_field',
24782478
)).toEqual({
2479-
'@type': 'ParameterRangeUndefined',
2479+
'@type': 'ParameterRangeWildcard',
24802480
});
24812481
});
24822482

@@ -2491,6 +2491,17 @@ describe('ComponentConstructor', () => {
24912491
});
24922492
});
24932493

2494+
it('should construct a wildcard parameter range', async() => {
2495+
expect(await ctor.constructParameterRange(
2496+
{ type: 'wildcard' },
2497+
context,
2498+
externalContextsCallback,
2499+
'mp:components/a/b/file-param.jsonld#MyClass_field',
2500+
)).toEqual({
2501+
'@type': 'ParameterRangeWildcard',
2502+
});
2503+
});
2504+
24942505
it('should construct a union parameter range', async() => {
24952506
const rangeValueClass: ClassReferenceLoaded = <any> {
24962507
packageName: 'my-package',

0 commit comments

Comments
 (0)