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