mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(compiler): remove unused AstPath (#44411)
This code is no longer used now that ViewEngine has been removed. PR Close #44411
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* A path is an ordered set of elements. Typically a path is to a
|
||||
* particular offset in a source file. The head of the list is the top
|
||||
* most node. The tail is the node that contains the offset directly.
|
||||
*
|
||||
* For example, the expression `a + b + c` might have an ast that looks
|
||||
* like:
|
||||
* +
|
||||
* / \
|
||||
* a +
|
||||
* / \
|
||||
* b c
|
||||
*
|
||||
* The path to the node at offset 9 would be `['+' at 1-10, '+' at 7-10,
|
||||
* 'c' at 9-10]` and the path the node at offset 1 would be
|
||||
* `['+' at 1-10, 'a' at 1-2]`.
|
||||
*/
|
||||
export class AstPath<T> {
|
||||
constructor(private path: T[], public position: number = -1) {}
|
||||
|
||||
get empty(): boolean {
|
||||
return !this.path || !this.path.length;
|
||||
}
|
||||
get head(): T|undefined {
|
||||
return this.path[0];
|
||||
}
|
||||
get tail(): T|undefined {
|
||||
return this.path[this.path.length - 1];
|
||||
}
|
||||
|
||||
parentOf(node: T|undefined): T|undefined {
|
||||
return node && this.path[this.path.indexOf(node) - 1];
|
||||
}
|
||||
childOf(node: T): T|undefined {
|
||||
return this.path[this.path.indexOf(node) + 1];
|
||||
}
|
||||
|
||||
first<N extends T>(ctor: {new(...args: any[]): N}): N|undefined {
|
||||
for (let i = this.path.length - 1; i >= 0; i--) {
|
||||
let item = this.path[i];
|
||||
if (item instanceof ctor) return <N>item;
|
||||
}
|
||||
}
|
||||
|
||||
push(node: T) {
|
||||
this.path.push(node);
|
||||
}
|
||||
|
||||
pop(): T {
|
||||
return this.path.pop()!;
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,6 @@ export {core};
|
||||
|
||||
export * from './version';
|
||||
export {CompilerConfig, preserveWhitespacesDefault} from './config';
|
||||
export * from './ast_path';
|
||||
export {Identifiers} from './identifiers';
|
||||
export * from './resource_loader';
|
||||
export {ConstantPool} from './constant_pool';
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AstPath} from '../ast_path';
|
||||
import {I18nMeta} from '../i18n/i18n_ast';
|
||||
import {ParseSourceSpan} from '../parse_util';
|
||||
|
||||
import {InterpolatedAttributeToken, InterpolatedTextToken} from './tokens';
|
||||
|
||||
interface BaseNode {
|
||||
@@ -147,38 +147,3 @@ export class RecursiveVisitor implements Visitor {
|
||||
return Array.prototype.concat.apply([], results);
|
||||
}
|
||||
}
|
||||
|
||||
export type HtmlAstPath = AstPath<Node>;
|
||||
|
||||
function spanOf(ast: Node) {
|
||||
const start = ast.sourceSpan.start.offset;
|
||||
let end = ast.sourceSpan.end.offset;
|
||||
if (ast instanceof Element) {
|
||||
if (ast.endSourceSpan) {
|
||||
end = ast.endSourceSpan.end.offset;
|
||||
} else if (ast.children && ast.children.length) {
|
||||
end = spanOf(ast.children[ast.children.length - 1]).end;
|
||||
}
|
||||
}
|
||||
return {start, end};
|
||||
}
|
||||
|
||||
export function findNode(nodes: Node[], position: number): HtmlAstPath {
|
||||
const path: Node[] = [];
|
||||
|
||||
const visitor = new class extends RecursiveVisitor {
|
||||
visit(ast: Node, context: any): any {
|
||||
const span = spanOf(ast);
|
||||
if (span.start <= position && position < span.end) {
|
||||
path.push(ast);
|
||||
} else {
|
||||
// Returning a value here will result in the children being skipped.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
visitAll(visitor, nodes);
|
||||
|
||||
return new AstPath<Node>(path, position);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user