MCPcopy Create free account
hub / github.com/angular/angular / getBoundTemplate

Function getBoundTemplate

packages/compiler-cli/src/ngtsc/indexer/test/util.ts:59–136  ·  view source on GitHub ↗
(
  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;
  }> = [],
)

Source from the content-addressed store, hash-verified

57 * @param components components to bind to the template target
58 */
59export 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;

Callers 3

bindFunction · 0.90
template_spec.tsFile · 0.90
transform_spec.tsFile · 0.90

Calls 11

addSelectablesMethod · 0.95
bindMethod · 0.95
isNgpTestModeFunction · 0.90
createNgpBoundTemplateFunction · 0.90
getFileSystemFunction · 0.90
parseTemplateFunction · 0.90
getTestFilePathFunction · 0.85
mapMethod · 0.80
getTextMethod · 0.80
fromMappedObjectMethod · 0.80
parseMethod · 0.65

Tested by

no test coverage detected