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

Function tcb

packages/compiler/test/typecheck/util.ts:158–228  ·  view source on GitHub ↗
(
  template: string,
  declarations: TestDeclaration[] = [],
  config?: Partial<TypeCheckingConfig>,
  options?: {emitSpans?: boolean},
  templateParserOptions?: ParseTemplateOptions,
  foreignComponents: string[] = [],
)

Source from the content-addressed store, hash-verified

156 * @param foreignComponents Names of foreign components available in the template scope.
157 */
158export function tcb(
159 template: string,
160 declarations: TestDeclaration[] = [],
161 config?: Partial<TypeCheckingConfig>,
162 options?: {emitSpans?: boolean},
163 templateParserOptions?: ParseTemplateOptions,
164 foreignComponents: string[] = [],
165): string {
166 const fullConfig: TypeCheckingConfig = {...DEFAULT_CONFIG, ...config};
167 const {nodes, errors} = parseTemplate(template, 'synthetic.html', templateParserOptions);
168
169 if (errors !== null) {
170 throw new Error('Template parse errors: \n' + errors.join('\n'));
171 }
172
173 const {matcher, pipes, foreignMatcher} = prepareDeclarations(
174 declarations,
175 fullConfig,
176 foreignComponents,
177 );
178 const boundTarget = new R3TargetBinder<TcbDirectiveMetadata>(matcher, foreignMatcher).bind({
179 template: nodes,
180 });
181
182 // Only pipes that are actually used by the template are passed to the generator.
183 const usedPipes = new Map<string, TcbPipeMetadata>();
184 for (const name of boundTarget.getUsedPipes()) {
185 const pipe = pipes.get(name);
186 if (pipe !== undefined) {
187 usedPipes.set(name, pipe);
188 }
189 }
190
191 const meta: TcbTypeCheckBlockMetadata = {
192 id: 'tcb' as TypeCheckId,
193 boundTarget,
194 pipes: usedPipes,
195 schemas: [],
196 isStandalone: false,
197 preserveWhitespaces: false,
198 };
199
200 const typeParameters = toTcbTypeParameters(DEFAULT_TYPE_PARAMETERS);
201 const component: TcbComponentMetadata = {
202 ref: createReference(COMPONENT_NAME),
203 typeParameters,
204 typeArguments: fullConfig.useContextGenericType
205 ? typeParameters.map((param) => param.name)
206 : typeParameters.map(() => 'any'),
207 };
208
209 const env = new TestTcbEnvironment(fullConfig);
210 env.addTypeCheckBlock(
211 generateTypeCheckBlock(
212 env,
213 component,
214 '_tcb1',
215 meta,

Callers 2

tcbWithSpansFunction · 0.90

Calls 14

addTypeCheckBlockMethod · 0.95
renderMethod · 0.95
parseTemplateFunction · 0.90
generateTypeCheckBlockFunction · 0.90
toTcbTypeParametersFunction · 0.85
createReferenceFunction · 0.85
mapMethod · 0.80
prepareDeclarationsFunction · 0.70
joinMethod · 0.65
bindMethod · 0.65
getUsedPipesMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected