Skip to content

Commit f755853

Browse files
JeanMechealxhub
authored andcommitted
refactor(compiler): Remove unused TransformVisitor & NullVisitor (#48646)
NullVisitor & TransformVisitor are unused and unexported outside the compiler package, we can remove them. PR Close #48646
1 parent 478c70c commit f755853

File tree

2 files changed

+1
-98
lines changed

2 files changed

+1
-98
lines changed

packages/compiler/src/render3/r3_ast.ts

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,6 @@ export interface Visitor<Result = any> {
198198
visitIcu(icu: Icu): Result;
199199
}
200200

201-
export class NullVisitor implements Visitor<void> {
202-
visitElement(element: Element): void {}
203-
visitTemplate(template: Template): void {}
204-
visitContent(content: Content): void {}
205-
visitVariable(variable: Variable): void {}
206-
visitReference(reference: Reference): void {}
207-
visitTextAttribute(attribute: TextAttribute): void {}
208-
visitBoundAttribute(attribute: BoundAttribute): void {}
209-
visitBoundEvent(attribute: BoundEvent): void {}
210-
visitText(text: Text): void {}
211-
visitBoundText(text: BoundText): void {}
212-
visitIcu(icu: Icu): void {}
213-
}
214-
215201
export class RecursiveVisitor implements Visitor<void> {
216202
visitElement(element: Element): void {
217203
visitAll(this, element.attributes);
@@ -239,78 +225,12 @@ export class RecursiveVisitor implements Visitor<void> {
239225
visitIcu(icu: Icu): void {}
240226
}
241227

242-
export class TransformVisitor implements Visitor<Node> {
243-
visitElement(element: Element): Node {
244-
const newAttributes = transformAll(this, element.attributes);
245-
const newInputs = transformAll(this, element.inputs);
246-
const newOutputs = transformAll(this, element.outputs);
247-
const newChildren = transformAll(this, element.children);
248-
const newReferences = transformAll(this, element.references);
249-
if (newAttributes != element.attributes || newInputs != element.inputs ||
250-
newOutputs != element.outputs || newChildren != element.children ||
251-
newReferences != element.references) {
252-
return new Element(
253-
element.name, newAttributes, newInputs, newOutputs, newChildren, newReferences,
254-
element.sourceSpan, element.startSourceSpan, element.endSourceSpan);
255-
}
256-
return element;
257-
}
258-
259-
visitTemplate(template: Template): Node {
260-
const newAttributes = transformAll(this, template.attributes);
261-
const newInputs = transformAll(this, template.inputs);
262-
const newOutputs = transformAll(this, template.outputs);
263-
const newTemplateAttrs = transformAll(this, template.templateAttrs);
264-
const newChildren = transformAll(this, template.children);
265-
const newReferences = transformAll(this, template.references);
266-
const newVariables = transformAll(this, template.variables);
267-
if (newAttributes != template.attributes || newInputs != template.inputs ||
268-
newOutputs != template.outputs || newTemplateAttrs != template.templateAttrs ||
269-
newChildren != template.children || newReferences != template.references ||
270-
newVariables != template.variables) {
271-
return new Template(
272-
template.tagName, newAttributes, newInputs, newOutputs, newTemplateAttrs, newChildren,
273-
newReferences, newVariables, template.sourceSpan, template.startSourceSpan,
274-
template.endSourceSpan);
275-
}
276-
return template;
277-
}
278-
279-
visitContent(content: Content): Node {
280-
return content;
281-
}
282-
283-
visitVariable(variable: Variable): Node {
284-
return variable;
285-
}
286-
visitReference(reference: Reference): Node {
287-
return reference;
288-
}
289-
visitTextAttribute(attribute: TextAttribute): Node {
290-
return attribute;
291-
}
292-
visitBoundAttribute(attribute: BoundAttribute): Node {
293-
return attribute;
294-
}
295-
visitBoundEvent(attribute: BoundEvent): Node {
296-
return attribute;
297-
}
298-
visitText(text: Text): Node {
299-
return text;
300-
}
301-
visitBoundText(text: BoundText): Node {
302-
return text;
303-
}
304-
visitIcu(icu: Icu): Node {
305-
return icu;
306-
}
307-
}
308228

309229
export function visitAll<Result>(visitor: Visitor<Result>, nodes: Node[]): Result[] {
310230
const result: Result[] = [];
311231
if (visitor.visit) {
312232
for (const node of nodes) {
313-
const newNode = visitor.visit(node) || node.visit(visitor);
233+
visitor.visit(node) || node.visit(visitor);
314234
}
315235
} else {
316236
for (const node of nodes) {
@@ -322,17 +242,3 @@ export function visitAll<Result>(visitor: Visitor<Result>, nodes: Node[]): Resul
322242
}
323243
return result;
324244
}
325-
326-
export function transformAll<Result extends Node>(
327-
visitor: Visitor<Node>, nodes: Result[]): Result[] {
328-
const result: Result[] = [];
329-
let changed = false;
330-
for (const node of nodes) {
331-
const newNode = node.visit(visitor);
332-
if (newNode) {
333-
result.push(newNode as Result);
334-
}
335-
changed = changed || newNode != node;
336-
}
337-
return changed ? result : nodes;
338-
}

packages/core/schematics/utils/template_ast_visitor.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import type {TmplAstBoundAttribute, TmplAstBoundEvent, TmplAstBoundText, TmplAst
1010

1111
/**
1212
* A base class that can be used to implement a Render3 Template AST visitor.
13-
* This class is used instead of the `NullVisitor` found within the `@angular/compiler` because
14-
* the `NullVisitor` requires a deep import which is no longer supported with the ESM bundled
15-
* packages as of v13.
1613
* Schematics are also currently required to be CommonJS to support execution within the Angular
1714
* CLI. As a result, the ESM `@angular/compiler` package must be loaded via a native dynamic import.
1815
* Using a dynamic import makes classes extending from classes present in `@angular/compiler`

0 commit comments

Comments
 (0)