(
template: string,
options: ParseTemplateOptions = {},
components: Array<{
selector: string | null;
declaration: ClassDeclaration;
inputs?: Record<string, string>;
outputs?: Record<string, string>;
}> = [],
pipes: Array<{
name: string;
declaration: ClassDeclaration;
}> = [],
)
| 57 | * @param components components to bind to the template target |
| 58 | */ |
| 59 | export function getBoundTemplate( |
| 60 | template: string, |
| 61 | options: ParseTemplateOptions = {}, |
| 62 | components: Array<{ |
| 63 | selector: string | null; |
| 64 | declaration: ClassDeclaration; |
| 65 | inputs?: Record<string, string>; |
| 66 | outputs?: Record<string, string>; |
| 67 | }> = [], |
| 68 | pipes: Array<{ |
| 69 | name: string; |
| 70 | declaration: ClassDeclaration; |
| 71 | }> = [], |
| 72 | ): AbstractBoundTemplate<DeclarationNode> { |
| 73 | if (isNgpTestMode()) { |
| 74 | return createNgpBoundTemplate(getFileSystem(), template, options, components, pipes); |
| 75 | } |
| 76 | const componentsMeta = components.map(({selector, declaration, inputs = {}, outputs = {}}) => ({ |
| 77 | ref: new Reference(declaration), |
| 78 | selector, |
| 79 | name: declaration.name.getText(), |
| 80 | isComponent: true, |
| 81 | inputs: ClassPropertyMapping.fromMappedObject(inputs), |
| 82 | outputs: ClassPropertyMapping.fromMappedObject(outputs), |
| 83 | exportAs: null, |
| 84 | isStructural: false, |
| 85 | animationTriggerNames: null, |
| 86 | ngContentSelectors: null, |
| 87 | preserveWhitespaces: false, |
| 88 | matchSource: MatchSource.Selector, |
| 89 | })); |
| 90 | |
| 91 | const matcher = new SelectorMatcher<ComponentMeta[]>(); |
| 92 | |
| 93 | for (const current of componentsMeta) { |
| 94 | if (current.selector !== null) { |
| 95 | matcher.addSelectables(CssSelector.parse(current.selector), [current]); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | const binder = new R3TargetBinder(matcher); |
| 100 | |
| 101 | const boundTemplate = binder.bind({ |
| 102 | template: parseTemplate(template, getTestFilePath(), options).nodes, |
| 103 | }); |
| 104 | const abstractBoundTemplate: AbstractBoundTemplate<DeclarationNode> = { |
| 105 | getDirectivesOfNode(node) { |
| 106 | return boundTemplate.getDirectivesOfNode(node); |
| 107 | }, |
| 108 | getReferenceTarget(node) { |
| 109 | return boundTemplate.getReferenceTarget(node); |
| 110 | }, |
| 111 | getConsumerOfBinding(binding) { |
| 112 | const consumer = boundTemplate.getConsumerOfBinding(binding); |
| 113 | if (consumer && 'ref' in consumer && consumer.ref) { |
| 114 | return {ref: {node: consumer.ref.node}}; |
| 115 | } |
| 116 | return null; |
no test coverage detected