* Flattens the host directives of a directive into the list of matches they contribute, with only * the inputs and outputs that the host exposes (under the aliases the host exposes them as).
( decl: TestDirective, results: TcbDirectiveMetadata[] = [], )
| 508 | * the inputs and outputs that the host exposes (under the aliases the host exposes them as). |
| 509 | */ |
| 510 | function resolveHostDirectives( |
| 511 | decl: TestDirective, |
| 512 | results: TcbDirectiveMetadata[] = [], |
| 513 | ): TcbDirectiveMetadata[] { |
| 514 | for (const hostDir of decl.hostDirectives ?? []) { |
| 515 | resolveHostDirectives(hostDir.directive, results); |
| 516 | |
| 517 | const meta = toDirectiveMetadata(hostDir.directive, MatchSource.HostDirective); |
| 518 | const exposedInputs = parseMappingArray(hostDir.inputs ?? []); |
| 519 | const exposedOutputs = parseMappingArray(hostDir.outputs ?? []); |
| 520 | const inputs: {[fieldName: string]: TcbInputMapping} = {}; |
| 521 | const outputs: {[fieldName: string]: string} = {}; |
| 522 | |
| 523 | for (const [publicName, alias] of Object.entries(exposedInputs)) { |
| 524 | for (const input of meta.inputs.getByBindingPropertyName(publicName) ?? []) { |
| 525 | inputs[input.classPropertyName] = {...input, bindingPropertyName: alias}; |
| 526 | } |
| 527 | } |
| 528 | for (const [publicName, alias] of Object.entries(exposedOutputs)) { |
| 529 | for (const output of meta.outputs.getByBindingPropertyName(publicName) ?? []) { |
| 530 | outputs[output.classPropertyName] = alias; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | results.push({ |
| 535 | ...meta, |
| 536 | inputs: ClassPropertyMapping.fromMappedObject<TcbInputMapping>(inputs), |
| 537 | outputs: ClassPropertyMapping.fromMappedObject(outputs), |
| 538 | }); |
| 539 | } |
| 540 | return results; |
| 541 | } |
| 542 | |
| 543 | /** Parses `['field', 'field: alias']` style mappings into a `{field: alias}` record. */ |
| 544 | function parseMappingArray(values: string[]): {[field: string]: string} { |
no test coverage detected