UNPKG

3.27 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8/// <amd-module name="@angular/core/schematics/utils/template_ast_visitor" />
9import type { TmplAstBoundAttribute, TmplAstBoundEvent, TmplAstBoundText, TmplAstContent, TmplAstElement, TmplAstIcu, TmplAstNode, TmplAstRecursiveVisitor, TmplAstReference, TmplAstTemplate, TmplAstText, TmplAstTextAttribute, TmplAstVariable } from '@angular/compiler';
10/**
11 * A base class that can be used to implement a Render3 Template AST visitor.
12 * This class is used instead of the `NullVisitor` found within the `@angular/compiler` because
13 * the `NullVisitor` requires a deep import which is no longer supported with the ESM bundled
14 * packages as of v13.
15 * Schematics are also currently required to be CommonJS to support execution within the Angular
16 * CLI. As a result, the ESM `@angular/compiler` package must be loaded via a native dynamic import.
17 * Using a dynamic import makes classes extending from classes present in `@angular/compiler`
18 * complicated due to the class not being present at module evaluation time. The classes using a
19 * base class found within `@angular/compiler` must be wrapped in a factory to allow the class value
20 * to be accessible at runtime after the dynamic import has completed. This class implements the
21 * interface of the `TmplAstRecursiveVisitor` class (but does not extend) as the
22 * `TmplAstRecursiveVisitor` as an interface provides the required set of visit methods. The base
23 * interface `Visitor<T>` is not exported.
24 */
25export declare class TemplateAstVisitor implements TmplAstRecursiveVisitor {
26 protected readonly compilerModule: typeof import('@angular/compiler');
27 /**
28 * Creates a new Render3 Template AST visitor using an instance of the `@angular/compiler`
29 * package. Passing in the compiler is required due to the need to dynamically import the
30 * ESM `@angular/compiler` into a CommonJS schematic.
31 *
32 * @param compilerModule The compiler instance that should be used within the visitor.
33 */
34 constructor(compilerModule: typeof import('@angular/compiler'));
35 visitElement(element: TmplAstElement): void;
36 visitTemplate(template: TmplAstTemplate): void;
37 visitContent(content: TmplAstContent): void;
38 visitVariable(variable: TmplAstVariable): void;
39 visitReference(reference: TmplAstReference): void;
40 visitTextAttribute(attribute: TmplAstTextAttribute): void;
41 visitBoundAttribute(attribute: TmplAstBoundAttribute): void;
42 visitBoundEvent(attribute: TmplAstBoundEvent): void;
43 visitText(text: TmplAstText): void;
44 visitBoundText(text: TmplAstBoundText): void;
45 visitIcu(icu: TmplAstIcu): void;
46 /**
47 * Visits all the provided nodes in order using this Visitor's visit methods.
48 * This is a simplified variant of the `visitAll` function found inside of (but not
49 * exported from) the `@angular/compiler` that does not support returning a value
50 * since the migrations do not directly transform the nodes.
51 *
52 * @param nodes An iterable of nodes to visit using this visitor.
53 */
54 visitAll(nodes: Iterable<TmplAstNode>): void;
55}