componentsjs 5.0.0-beta.2 → 5.0.0-beta.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.
@@ -1,5 +1,6 @@
1
1
  import type { RdfObjectLoader, Resource } from 'rdf-object';
2
- import type { GenericsContext } from '../GenericsContext';
2
+ import type { IErrorContext } from '../../util/ErrorResourcesContext';
3
+ import { GenericsContext } from '../GenericsContext';
3
4
  import type { IParameterPropertyHandler } from './IParameterPropertyHandler';
4
5
  /**
5
6
  * If a param range is defined, apply the type and validate the range.
@@ -20,16 +21,35 @@ export declare class ParameterPropertyHandlerRange implements IParameterProperty
20
21
  */
21
22
  captureType(value: Resource | undefined, param: Resource, genericsContext: GenericsContext): Resource | undefined;
22
23
  /**
23
- * Apply the given datatype to the given literal.
24
- * Checks if the datatype is correct and casts to the correct js type.
25
- * Will throw an error if the type has an invalid value.
26
- * Will be ignored if the value is not a literal or the type is not recognized.
24
+ * Check if the given value is of the given type.
25
+ *
26
+ * For valid literals, the `valueRaw` field will be set.
27
+ *
27
28
  * @param value The value.
28
- * @param param The parameter.
29
- * @param paramRange The parameter's range.
29
+ * @param type The parameter's range.
30
30
  * @param genericsContext Context for generic types.
31
+ * @param errorContext The context for error reporting.
32
+ * @return IParamValueConflict A conflict value if there was an error, or undefined if there was no error
31
33
  */
32
- hasParamValueValidType(value: Resource | undefined, param: Resource, paramRange: Resource, genericsContext: GenericsContext): boolean;
33
- protected throwIncorrectTypeError(value: Resource | undefined, parameter: Resource, genericsContext: GenericsContext): never;
34
- rangeToDisplayString(paramRange: Resource | undefined, genericsContext: GenericsContext): string;
34
+ hasValueType(value: Resource | undefined, type: Resource | undefined, errorContext: IErrorContext, genericsContext: GenericsContext): IParamValueConflict | undefined;
35
+ static throwIncorrectTypeError(value: Resource | undefined, parameter: Resource, genericsContext: GenericsContext, conflict: IParamValueConflict): never;
36
+ /**
37
+ * Check if the given value is of the given type.
38
+ * @param value A value.
39
+ * @param type A type.
40
+ * @param genericsContext The current generics context.
41
+ * @param genericTypeInstancesComponentScope
42
+ * @param genericTypeInstances
43
+ * @param errorContext
44
+ */
45
+ hasType(value: Resource, type: Resource, genericsContext: GenericsContext, genericTypeInstancesComponentScope: Resource | undefined, genericTypeInstances: Resource[], errorContext: IErrorContext): IParamValueConflict | undefined;
46
+ static rangeToDisplayString(paramRange: Resource | undefined, genericsContext: GenericsContext): string;
47
+ }
48
+ /**
49
+ * Represents a conflict between a value and a type.
50
+ */
51
+ export interface IParamValueConflict {
52
+ description: string;
53
+ context: IErrorContext;
54
+ causes?: IParamValueConflict[];
35
55
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ParameterPropertyHandlerRange = void 0;
4
4
  const Iris_1 = require("../../rdf/Iris");
5
5
  const ErrorResourcesContext_1 = require("../../util/ErrorResourcesContext");
6
+ const GenericsContext_1 = require("../GenericsContext");
6
7
  /**
7
8
  * If a param range is defined, apply the type and validate the range.
8
9
  */
@@ -27,33 +28,45 @@ class ParameterPropertyHandlerRange {
27
28
  * @param genericsContext Context for generic types.
28
29
  */
29
30
  captureType(value, param, genericsContext) {
30
- if (this.hasParamValueValidType(value, param, param.property.range, genericsContext)) {
31
+ const errorContext = { param };
32
+ const conflict = this.hasValueType(value, param.property.range, errorContext, genericsContext);
33
+ if (!conflict) {
31
34
  return value;
32
35
  }
33
- this.throwIncorrectTypeError(value, param, genericsContext);
36
+ ParameterPropertyHandlerRange.throwIncorrectTypeError(value, param, genericsContext, conflict);
34
37
  }
35
38
  /**
36
- * Apply the given datatype to the given literal.
37
- * Checks if the datatype is correct and casts to the correct js type.
38
- * Will throw an error if the type has an invalid value.
39
- * Will be ignored if the value is not a literal or the type is not recognized.
39
+ * Check if the given value is of the given type.
40
+ *
41
+ * For valid literals, the `valueRaw` field will be set.
42
+ *
40
43
  * @param value The value.
41
- * @param param The parameter.
42
- * @param paramRange The parameter's range.
44
+ * @param type The parameter's range.
43
45
  * @param genericsContext Context for generic types.
46
+ * @param errorContext The context for error reporting.
47
+ * @return IParamValueConflict A conflict value if there was an error, or undefined if there was no error
44
48
  */
45
- hasParamValueValidType(value, param, paramRange, genericsContext) {
46
- if (!paramRange) {
47
- return true;
49
+ hasValueType(value, type, errorContext, genericsContext) {
50
+ errorContext = Object.assign(Object.assign({}, errorContext), { value, type });
51
+ if (!type) {
52
+ return;
53
+ }
54
+ if (type.isA('ParameterRangeWildcard')) {
55
+ return;
48
56
  }
49
- if (!value && paramRange.isA('ParameterRangeUndefined')) {
50
- return true;
57
+ if (!value && type.isA('ParameterRangeUndefined')) {
58
+ return;
51
59
  }
60
+ // Always match variable values
61
+ if (value && value.isA('Variable')) {
62
+ return;
63
+ }
64
+ // Handle literal values
52
65
  if (value && value.type === 'Literal') {
53
66
  let parsed;
54
- switch (paramRange.value) {
67
+ switch (type.value) {
55
68
  case Iris_1.IRIS_XSD.string:
56
- return true;
69
+ return;
57
70
  case Iris_1.IRIS_XSD.boolean:
58
71
  if (value.value === 'true') {
59
72
  value.term.valueRaw = true;
@@ -62,9 +75,12 @@ class ParameterPropertyHandlerRange {
62
75
  value.term.valueRaw = false;
63
76
  }
64
77
  else {
65
- return false;
78
+ return {
79
+ description: 'value must either be "true" or "false"',
80
+ context: errorContext,
81
+ };
66
82
  }
67
- return true;
83
+ return;
68
84
  case Iris_1.IRIS_XSD.integer:
69
85
  case Iris_1.IRIS_XSD.number:
70
86
  case Iris_1.IRIS_XSD.int:
@@ -72,172 +88,372 @@ class ParameterPropertyHandlerRange {
72
88
  case Iris_1.IRIS_XSD.long:
73
89
  parsed = Number.parseInt(value.value, 10);
74
90
  if (Number.isNaN(parsed)) {
75
- return false;
91
+ return {
92
+ description: `value is not a number`,
93
+ context: errorContext,
94
+ };
76
95
  }
77
96
  // ParseInt also parses floats to ints!
78
97
  if (String(parsed) !== value.value) {
79
- return false;
98
+ return {
99
+ description: `value can not be a float`,
100
+ context: errorContext,
101
+ };
80
102
  }
81
103
  value.term.valueRaw = parsed;
82
- return true;
104
+ return;
83
105
  case Iris_1.IRIS_XSD.float:
84
106
  case Iris_1.IRIS_XSD.decimal:
85
107
  case Iris_1.IRIS_XSD.double:
86
108
  parsed = Number.parseFloat(value.value);
87
109
  if (Number.isNaN(parsed)) {
88
- return false;
110
+ return {
111
+ description: `value is not a number`,
112
+ context: errorContext,
113
+ };
89
114
  }
90
115
  value.term.valueRaw = parsed;
91
- return true;
116
+ return;
92
117
  case Iris_1.IRIS_RDF.JSON:
93
118
  try {
94
119
  parsed = JSON.parse(value.value);
95
120
  value.term.valueRaw = parsed;
96
121
  }
97
- catch (_a) {
98
- return false;
122
+ catch (error) {
123
+ return {
124
+ description: `JSON parse exception: ${error.message}`,
125
+ context: errorContext,
126
+ };
99
127
  }
100
- return true;
128
+ return;
101
129
  }
102
130
  }
103
131
  // Allow IRIs to be casted to strings
104
- if (value && paramRange && paramRange.value === Iris_1.IRIS_XSD.string && value.type === 'NamedNode') {
105
- return true;
132
+ if (value && type.value === Iris_1.IRIS_XSD.string && value.type === 'NamedNode') {
133
+ return;
134
+ }
135
+ // Try to match the value with the parameter's range (which will always be defined at this stage)
136
+ // Check if the value has a super-type that equals the parameter's range
137
+ let hasTypeConflict;
138
+ if (value) {
139
+ const hasTypeConflictInner = this.hasType(value, type, genericsContext, value.property.genericTypeInstancesComponentScope, value.properties.genericTypeInstances, errorContext);
140
+ if (!hasTypeConflictInner) {
141
+ return;
142
+ }
143
+ hasTypeConflict = hasTypeConflictInner;
144
+ }
145
+ else {
146
+ hasTypeConflict = undefined;
147
+ }
148
+ // Check if the param type is an array
149
+ if (value && type.isA('ParameterRangeArray')) {
150
+ if (!value.list) {
151
+ return {
152
+ description: `value is not an RDF list`,
153
+ context: errorContext,
154
+ };
155
+ }
156
+ const subConflicts = value.list.map(listElement => this
157
+ .hasValueType(listElement, type.property.parameterRangeValue, errorContext, genericsContext))
158
+ .filter(subConflict => subConflict !== undefined);
159
+ return subConflicts.length === 0 ?
160
+ undefined :
161
+ {
162
+ description: `one or more array values are invalid`,
163
+ context: errorContext,
164
+ causes: subConflicts,
165
+ };
106
166
  }
107
- if (paramRange && (!value || (!value.isA('Variable') && !value.isA(paramRange.term)))) {
108
- if (value && paramRange.isA('ParameterRangeArray')) {
109
- if (!value.list) {
110
- return false;
167
+ // Check if the param type is a composed type
168
+ if (type.isA('ParameterRangeUnion')) {
169
+ const subConflicts = [];
170
+ for (const parameterRangeElement of type.properties.parameterRangeElements) {
171
+ const subConflict = this.hasValueType(value, parameterRangeElement, errorContext, genericsContext);
172
+ if (!subConflict) {
173
+ return;
111
174
  }
112
- return value.list.every(listElement => this
113
- .hasParamValueValidType(listElement, param, paramRange.property.parameterRangeValue, genericsContext));
175
+ subConflicts.push(subConflict);
114
176
  }
115
- // Check if the param type is a composed type
116
- if (paramRange.isA('ParameterRangeUnion')) {
117
- return paramRange.properties.parameterRangeElements
118
- .some(child => this.hasParamValueValidType(value, param, child, genericsContext));
177
+ return {
178
+ description: `no union values are valid`,
179
+ context: errorContext,
180
+ causes: subConflicts,
181
+ };
182
+ }
183
+ if (type.isA('ParameterRangeIntersection')) {
184
+ const subConflicts = type.properties.parameterRangeElements
185
+ .map(child => this.hasValueType(value, child, errorContext, genericsContext));
186
+ if (subConflicts.every(subConflict => subConflict === undefined)) {
187
+ return;
119
188
  }
120
- if (paramRange.isA('ParameterRangeIntersection')) {
121
- return paramRange.properties.parameterRangeElements
122
- .every(child => this.hasParamValueValidType(value, param, child, genericsContext));
189
+ return {
190
+ description: `not all intersection values are valid`,
191
+ context: errorContext,
192
+ causes: subConflicts.filter(subConflict => subConflict !== undefined),
193
+ };
194
+ }
195
+ if (type.isA('ParameterRangeTuple')) {
196
+ if (!value) {
197
+ return {
198
+ description: `undefined value is not an RDF list`,
199
+ context: errorContext,
200
+ };
123
201
  }
124
- if (paramRange.isA('ParameterRangeTuple')) {
125
- if (!value || !value.list) {
126
- return false;
127
- }
128
- // Iterate over list elements and try to match with tuple types
129
- const listElements = value.list;
130
- const tupleTypes = paramRange.properties.parameterRangeElements;
131
- let listIndex = 0;
132
- let tupleIndex = 0;
133
- while (listIndex < listElements.length && tupleIndex < tupleTypes.length) {
134
- if (tupleTypes[tupleIndex].isA('ParameterRangeRest')) {
135
- // Rest types can match multiple list elements, so only increment index if no match is found.
136
- if (!this.hasParamValueValidType(listElements[listIndex], param, tupleTypes[tupleIndex].property.parameterRangeValue, genericsContext)) {
137
- tupleIndex++;
138
- }
139
- else {
140
- listIndex++;
141
- }
202
+ if (!value.list) {
203
+ return {
204
+ description: `value is not an RDF list`,
205
+ context: errorContext,
206
+ };
207
+ }
208
+ // Iterate over list elements and try to match with tuple types
209
+ const listElements = value.list;
210
+ const tupleTypes = type.properties.parameterRangeElements;
211
+ let listIndex = 0;
212
+ let tupleIndex = 0;
213
+ while (listIndex < listElements.length && tupleIndex < tupleTypes.length) {
214
+ if (tupleTypes[tupleIndex].isA('ParameterRangeRest')) {
215
+ // Rest types can match multiple list elements, so only increment index if no match is found.
216
+ const subConflict = this.hasValueType(listElements[listIndex], tupleTypes[tupleIndex].property.parameterRangeValue, errorContext, genericsContext);
217
+ if (subConflict) {
218
+ tupleIndex++;
142
219
  }
143
220
  else {
144
- if (!this.hasParamValueValidType(listElements[listIndex], param, tupleTypes[tupleIndex], genericsContext)) {
145
- return false;
146
- }
147
- tupleIndex++;
148
221
  listIndex++;
149
222
  }
150
223
  }
151
- return listIndex === listElements.length &&
152
- (tupleIndex === tupleTypes.length ||
153
- (tupleIndex === tupleTypes.length - 1 && tupleTypes[tupleIndex].isA('ParameterRangeRest')));
224
+ else {
225
+ const subConflict = this.hasValueType(listElements[listIndex], tupleTypes[tupleIndex], errorContext, genericsContext);
226
+ if (subConflict) {
227
+ return {
228
+ description: `tuple element is invalid`,
229
+ context: errorContext,
230
+ causes: [subConflict],
231
+ };
232
+ }
233
+ tupleIndex++;
234
+ listIndex++;
235
+ }
154
236
  }
155
- if (paramRange.isA('ParameterRangeLiteral')) {
156
- return Boolean(value && value.term.equals(paramRange.property.parameterRangeValue.term));
237
+ if (!(listIndex === listElements.length &&
238
+ (tupleIndex === tupleTypes.length ||
239
+ (tupleIndex === tupleTypes.length - 1 && tupleTypes[tupleIndex].isA('ParameterRangeRest'))))) {
240
+ return {
241
+ description: `tuple does not contain the expected number of elements`,
242
+ context: errorContext,
243
+ };
157
244
  }
158
- // Check if the range refers to `keyof ...`
159
- if (paramRange.isA('ParameterRangeKeyof')) {
160
- const component = paramRange.property.parameterRangeValue;
161
- // Simulate a union of the member keys as literal parameter ranges
162
- const simulatedUnionRange = this.objectLoader.createCompactedResource({
163
- '@type': 'ParameterRangeUnion',
164
- parameterRangeElements: component.properties.memberKeys.map(memberKey => ({
165
- '@type': 'ParameterRangeLiteral',
166
- parameterRangeValue: memberKey,
167
- })),
168
- });
169
- return this.hasParamValueValidType(value, param, simulatedUnionRange, genericsContext);
245
+ return;
246
+ }
247
+ if (type.isA('ParameterRangeLiteral')) {
248
+ if (value && value.term.equals(type.property.parameterRangeValue.term)) {
249
+ return;
170
250
  }
171
- // Check if the range refers to a generic type
172
- if (paramRange.isA('ParameterRangeGenericTypeReference')) {
173
- return genericsContext.bindGenericTypeToValue(paramRange.property.parameterRangeGenericType.value, value, (subValue, subType) => this.hasParamValueValidType(subValue, param, subType, genericsContext));
251
+ return {
252
+ description: `literal value is unequal`,
253
+ context: errorContext,
254
+ };
255
+ }
256
+ // Check if the range refers to `keyof ...`
257
+ if (type.isA('ParameterRangeKeyof')) {
258
+ const component = type.property.parameterRangeValue;
259
+ // Simulate a union of the member keys as literal parameter ranges
260
+ const simulatedUnionRange = this.objectLoader.createCompactedResource({
261
+ '@type': 'ParameterRangeUnion',
262
+ parameterRangeElements: component.properties.memberKeys.map(memberKey => ({
263
+ '@type': 'ParameterRangeLiteral',
264
+ parameterRangeValue: memberKey,
265
+ })),
266
+ });
267
+ const subConflict = this.hasValueType(value, simulatedUnionRange, errorContext, genericsContext);
268
+ if (!subConflict) {
269
+ return;
174
270
  }
175
- // Check if the range refers to a component with a generic type
176
- if (paramRange.isA('ParameterRangeGenericComponent')) {
177
- if (value) {
178
- if (value.property.genericTypeInstances) {
179
- // Once we support manual generics setting, we'll need to check here if we can merge with it.
180
- throw new ErrorResourcesContext_1.ErrorResourcesContext(`Simultaneous manual generic type passing and generic type inference are not supported yet.`, { parameter: param, value });
181
- }
182
- // For the defined generic type instances, apply them into the instance so they can be checked later
183
- value.properties.genericTypeInstances = paramRange.properties.genericTypeInstances
184
- .map(genericTypeInstance => this.objectLoader.createCompactedResource({
185
- type: 'ParameterRangeGenericTypeReference',
186
- parameterRangeGenericType: genericTypeInstance.property.parameterRangeGenericType.value,
187
- parameterRangeGenericBindings: genericsContext
188
- .bindings[genericTypeInstance.property.parameterRangeGenericType.value],
189
- }));
271
+ return {
272
+ description: `keyof value is invalid`,
273
+ context: errorContext,
274
+ causes: [subConflict],
275
+ };
276
+ }
277
+ // Check if the range refers to a generic type
278
+ if (type.isA('ParameterRangeGenericTypeReference')) {
279
+ return genericsContext.bindGenericTypeToValue(type.property.parameterRangeGenericType.value, value, (subValue, subType) => this.hasValueType(subValue, subType, errorContext, genericsContext), (subType, superType) => this.hasType(subType, superType, genericsContext, undefined, [], errorContext));
280
+ }
281
+ // Check if the range refers to a component with a generic type
282
+ if (type.isA('ParameterRangeGenericComponent')) {
283
+ if (value) {
284
+ if (!value.property.genericTypeInstances) {
285
+ // For the defined generic type instances, apply them into the instance so they can be checked later during a
286
+ // call to GenericsContext#bindComponentGenericTypes.
287
+ value.property.genericTypeInstancesComponentScope = type.property.component;
288
+ value.properties.genericTypeInstances = type.properties.genericTypeInstances
289
+ .map(genericTypeInstance => {
290
+ // If we have a generic param type reference, instantiate them based on the current generics context
291
+ if (genericTypeInstance.isA('ParameterRangeGenericTypeReference')) {
292
+ if (!genericTypeInstance.property.parameterRangeGenericType) {
293
+ throw new ErrorResourcesContext_1.ErrorResourcesContext(`Invalid generic type instance in a ParameterRangeGenericComponent was detected: missing parameterRangeGenericType property.`, Object.assign(Object.assign({}, errorContext), { genericTypeInstance }));
294
+ }
295
+ return this.objectLoader.createCompactedResource({
296
+ '@type': 'ParameterRangeGenericTypeReference',
297
+ parameterRangeGenericType: genericTypeInstance.property.parameterRangeGenericType.value,
298
+ parameterRangeGenericBindings: genericsContext
299
+ .bindings[genericTypeInstance.property.parameterRangeGenericType.value],
300
+ });
301
+ }
302
+ // For all other param types, return the as-is
303
+ return genericTypeInstance;
304
+ });
305
+ }
306
+ else {
307
+ // TODO: Once we support manual generics setting, we'll need to check here if we can merge with it.
308
+ // (sometimes, it can also be identical)
190
309
  }
191
- return this.hasParamValueValidType(value, param, paramRange.property.component, genericsContext);
192
310
  }
193
- // Check if this param defines a field with sub-params
194
- if (paramRange.isA('ParameterRangeCollectEntries')) {
195
- // TODO: Add support for type-checking nested fields with collectEntries
196
- return true;
311
+ const subConflict = this.hasValueType(value, type.property.component, errorContext, genericsContext);
312
+ if (!subConflict) {
313
+ return;
197
314
  }
198
- return false;
315
+ return {
316
+ description: `generic component is invalid`,
317
+ context: errorContext,
318
+ causes: [subConflict],
319
+ };
320
+ }
321
+ // Check if this param defines a field with sub-params
322
+ if (type.isA('ParameterRangeCollectEntries')) {
323
+ // TODO: Add support for type-checking nested fields with collectEntries
324
+ return;
199
325
  }
200
- return true;
326
+ return hasTypeConflict || { description: 'unknown parameter type', context: errorContext };
201
327
  }
202
- throwIncorrectTypeError(value, parameter, genericsContext) {
328
+ static throwIncorrectTypeError(value, parameter, genericsContext, conflict) {
203
329
  const withTypes = value && value.properties.types.length > 0 ? ` with types "${value.properties.types.map(resource => resource.value)}"` : '';
204
330
  // eslint-disable-next-line @typescript-eslint/no-extra-parens
205
331
  const valueString = value ? (value.list ? `[${value.list.map(subValue => subValue.value).join(', ')}]` : value.value) : 'undefined';
206
- throw new ErrorResourcesContext_1.ErrorResourcesContext(`The value "${valueString}"${withTypes} for parameter "${parameter.value}" is not of required range type "${this.rangeToDisplayString(parameter.property.range, genericsContext)}"`, Object.assign(Object.assign({ value: value || 'undefined' }, Object.keys(genericsContext.bindings).length > 0 ?
332
+ throw new ErrorResourcesContext_1.ErrorResourcesContext(`The value "${valueString}"${withTypes} for parameter "${parameter.value}" is not of required range type "${ParameterPropertyHandlerRange.rangeToDisplayString(parameter.property.range, genericsContext)}"`, Object.assign(Object.assign({ cause: conflict, value: value || 'undefined' }, Object.keys(genericsContext.bindings).length > 0 ?
207
333
  { generics: `[\n ${Object.entries(genericsContext.bindings)
208
- .map(([id, values]) => `<${id}> => ${values.map(subValue => subValue.value)}`)
334
+ .map(([id, subValue]) => `<${id}> => ${ParameterPropertyHandlerRange.rangeToDisplayString(subValue, genericsContext)}`)
209
335
  .join(',\n ')}\n]` } :
210
336
  {}), { parameter }));
211
337
  }
212
- rangeToDisplayString(paramRange, genericsContext) {
213
- if (!paramRange) {
338
+ /**
339
+ * Check if the given value is of the given type.
340
+ * @param value A value.
341
+ * @param type A type.
342
+ * @param genericsContext The current generics context.
343
+ * @param genericTypeInstancesComponentScope
344
+ * @param genericTypeInstances
345
+ * @param errorContext
346
+ */
347
+ hasType(value, type, genericsContext, genericTypeInstancesComponentScope, genericTypeInstances, errorContext) {
348
+ var _a;
349
+ // Immediately return if the terms are equal
350
+ if (value.term.equals(type.term)) {
351
+ return;
352
+ }
353
+ // Otherwise, iterate over the value's super types are recursively call this method again.
354
+ const subConflictTypes = [];
355
+ for (const valueSuperType of [...value.properties.extends, ...value.properties.type]) {
356
+ // Special case: if the super component is wrapped in a generic component instantiation, unwrap it.
357
+ if (((_a = valueSuperType.property.type) === null || _a === void 0 ? void 0 : _a.value) === this.objectLoader.contextResolved
358
+ .expandTerm('oo:GenericComponentExtension')) {
359
+ // First recursively continue calling hasType for the unwrapped component
360
+ const hasTypeConflict = this.hasType(valueSuperType.property.component, type, genericsContext, genericTypeInstancesComponentScope, genericTypeInstances, errorContext);
361
+ if (!hasTypeConflict) {
362
+ // If hasType has passed, validate the generic instantiations
363
+ // AND (possibly) the parameter's generic type instances against the component's generic params.
364
+ const superComponent = valueSuperType.property.component;
365
+ const genericsContextInner = new GenericsContext_1.GenericsContext(this.objectLoader, superComponent.properties.genericTypeParameters);
366
+ const typeTypeValidator = (subType, superType) => this
367
+ .hasType(subType, superType, genericsContextInner, undefined, [], errorContext);
368
+ // Try to bind the generic instances from the wrapped generic component instantiation
369
+ const subConflictWrapped = genericsContextInner.bindComponentGenericTypes(superComponent, valueSuperType.properties.genericTypeInstances
370
+ .map(instance => this.objectLoader.createCompactedResource({
371
+ parameterRangeGenericBindings: instance,
372
+ })), { value }, typeTypeValidator);
373
+ if (subConflictWrapped) {
374
+ return {
375
+ description: `invalid wrapped bindings for generic type instances for generic component extension of "${superComponent.value}"`,
376
+ context: { value, type },
377
+ causes: [subConflictWrapped],
378
+ };
379
+ }
380
+ // If the given generic type component scope applies to this component,
381
+ // Try to bind the generic instances from the parameter type-checking.
382
+ if (genericTypeInstancesComponentScope && genericTypeInstancesComponentScope.value === superComponent.value) {
383
+ const subConflictParam = genericsContextInner.bindComponentGenericTypes(superComponent, genericTypeInstances, { value }, typeTypeValidator);
384
+ if (subConflictParam) {
385
+ return {
386
+ description: `invalid parameter bindings for generic type instances for generic component extension of "${superComponent.value}"`,
387
+ context: { value, type },
388
+ causes: [subConflictParam],
389
+ };
390
+ }
391
+ // Extract the bound generic instances from the inner context into the actual context.
392
+ // This is needed for cases where param generics are bound via a wrapped generic component instantiation.
393
+ for (const [i, genericTypeInstance] of genericTypeInstances.entries()) {
394
+ const innerGenericType = genericTypeInstancesComponentScope.properties.genericTypeParameters[i].value;
395
+ if (genericTypeInstance.isA('ParameterRangeGenericTypeReference')) {
396
+ // If the generic type instance refers to another generic,
397
+ // bind it to the corresponding value of the inner context
398
+ const outerGenericType = genericTypeInstance.property.parameterRangeGenericType.value;
399
+ genericsContext.bindings[outerGenericType] = genericsContextInner.bindings[innerGenericType];
400
+ }
401
+ else if (!genericsContextInner.mergeRanges(genericsContextInner.bindings[innerGenericType], genericTypeInstance, typeTypeValidator)) {
402
+ // If the generic type instance is just a type, check it against the value in the inner context.
403
+ // If it does not match, return an error.
404
+ return {
405
+ description: `invalid binding for generic type <${innerGenericType}> in generic component extension of "${superComponent.value}": existing range "${ParameterPropertyHandlerRange.rangeToDisplayString(genericsContextInner.bindings[innerGenericType], genericsContextInner)}" can not be bound to range "${ParameterPropertyHandlerRange.rangeToDisplayString(genericTypeInstance, genericsContextInner)}"`,
406
+ context: { value, type },
407
+ };
408
+ }
409
+ }
410
+ }
411
+ return;
412
+ }
413
+ return {
414
+ description: `value is not a subtype of the referenced component in the generic component extension of "${valueSuperType.property.component.value}"`,
415
+ context: { value, type },
416
+ causes: [hasTypeConflict],
417
+ };
418
+ }
419
+ // The default case just checks the super type recursively.
420
+ const subConflictType = this.hasType(valueSuperType, type, genericsContext, genericTypeInstancesComponentScope, genericTypeInstances, errorContext);
421
+ if (!subConflictType) {
422
+ return;
423
+ }
424
+ subConflictTypes.push(subConflictType);
425
+ }
426
+ return Object.assign({ description: `value is not a subtype of "${type.value}"`, context: { value, type } }, subConflictTypes.length > 0 ? { causes: subConflictTypes } : {});
427
+ }
428
+ static rangeToDisplayString(paramRange, genericsContext) {
429
+ if (!paramRange || paramRange.isA('ParameterRangeWildcard')) {
214
430
  return `any`;
215
431
  }
216
432
  if (paramRange.isA('ParameterRangeUndefined')) {
217
433
  return `undefined`;
218
434
  }
219
435
  if (paramRange.isA('ParameterRangeArray')) {
220
- return `${this.rangeToDisplayString(paramRange.property.parameterRangeValue, genericsContext)}[]`;
436
+ return `${ParameterPropertyHandlerRange.rangeToDisplayString(paramRange.property.parameterRangeValue, genericsContext)}[]`;
221
437
  }
222
438
  if (paramRange.isA('ParameterRangeRest')) {
223
- return `...${this.rangeToDisplayString(paramRange.property.parameterRangeValue, genericsContext)}`;
439
+ return `...${ParameterPropertyHandlerRange.rangeToDisplayString(paramRange.property.parameterRangeValue, genericsContext)}`;
224
440
  }
225
441
  if (paramRange.isA('ParameterRangeKeyof')) {
226
- return `keyof ${this.rangeToDisplayString(paramRange.property.parameterRangeValue, genericsContext)}`;
442
+ return `keyof ${ParameterPropertyHandlerRange.rangeToDisplayString(paramRange.property.parameterRangeValue, genericsContext)}`;
227
443
  }
228
444
  if (paramRange.isA('ParameterRangeUnion')) {
229
445
  return paramRange.properties.parameterRangeElements
230
- .map(child => this.rangeToDisplayString(child, genericsContext))
446
+ .map(child => ParameterPropertyHandlerRange.rangeToDisplayString(child, genericsContext))
231
447
  .join(' | ');
232
448
  }
233
449
  if (paramRange.isA('ParameterRangeIntersection')) {
234
450
  return paramRange.properties.parameterRangeElements
235
- .map(child => this.rangeToDisplayString(child, genericsContext))
451
+ .map(child => ParameterPropertyHandlerRange.rangeToDisplayString(child, genericsContext))
236
452
  .join(' & ');
237
453
  }
238
454
  if (paramRange.isA('ParameterRangeTuple')) {
239
455
  return `[${paramRange.properties.parameterRangeElements
240
- .map(child => this.rangeToDisplayString(child, genericsContext))
456
+ .map(child => ParameterPropertyHandlerRange.rangeToDisplayString(child, genericsContext))
241
457
  .join(', ')}]`;
242
458
  }
243
459
  if (paramRange.isA('ParameterRangeLiteral')) {
@@ -245,11 +461,11 @@ class ParameterPropertyHandlerRange {
245
461
  }
246
462
  if (paramRange.isA('ParameterRangeGenericTypeReference')) {
247
463
  const valid = paramRange.property.parameterRangeGenericType.value in genericsContext.genericTypeIds;
248
- return `<${valid ? '' : 'UNKNOWN GENERIC: '}${paramRange.property.parameterRangeGenericType.value}>`;
464
+ return `${valid ? 'GENERIC: ' : 'UNKNOWN GENERIC: '}${paramRange.property.parameterRangeGenericType.value}`;
249
465
  }
250
466
  if (paramRange.isA('ParameterRangeGenericComponent')) {
251
- return `(${this.rangeToDisplayString(paramRange.property.component, genericsContext)})${paramRange.properties.genericTypeInstances
252
- .map(genericTypeInstance => this.rangeToDisplayString(genericTypeInstance, genericsContext)).join('')}`;
467
+ return `(${ParameterPropertyHandlerRange.rangeToDisplayString(paramRange.property.component, genericsContext)})<${paramRange.properties.genericTypeInstances
468
+ .map(genericTypeInstance => ParameterPropertyHandlerRange.rangeToDisplayString(genericTypeInstance, genericsContext)).join(', ')}>`;
253
469
  }
254
470
  return paramRange.value;
255
471
  }