diff --git a/packages/compiler/src/ast_path.ts b/packages/compiler/src/ast_path.ts deleted file mode 100644 index 532ed3bc229..00000000000 --- a/packages/compiler/src/ast_path.ts +++ /dev/null @@ -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 { - 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(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 item; - } - } - - push(node: T) { - this.path.push(node); - } - - pop(): T { - return this.path.pop()!; - } -} diff --git a/packages/compiler/src/compiler.ts b/packages/compiler/src/compiler.ts index cc5f99950c8..b434de7f92c 100644 --- a/packages/compiler/src/compiler.ts +++ b/packages/compiler/src/compiler.ts @@ -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'; diff --git a/packages/compiler/src/ml_parser/ast.ts b/packages/compiler/src/ml_parser/ast.ts index 0d9c45f0edd..806fb79414f 100644 --- a/packages/compiler/src/ml_parser/ast.ts +++ b/packages/compiler/src/ml_parser/ast.ts @@ -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; - -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(path, position); -}