[6a3a178] | 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 | (function (factory) {
|
---|
| 9 | if (typeof module === "object" && typeof module.exports === "object") {
|
---|
| 10 | var v = factory(require, exports);
|
---|
| 11 | if (v !== undefined) module.exports = v;
|
---|
| 12 | }
|
---|
| 13 | else if (typeof define === "function" && define.amd) {
|
---|
| 14 | define("@angular/compiler/src/ast_path", ["require", "exports"], factory);
|
---|
| 15 | }
|
---|
| 16 | })(function (require, exports) {
|
---|
| 17 | "use strict";
|
---|
| 18 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 19 | exports.AstPath = void 0;
|
---|
| 20 | /**
|
---|
| 21 | * A path is an ordered set of elements. Typically a path is to a
|
---|
| 22 | * particular offset in a source file. The head of the list is the top
|
---|
| 23 | * most node. The tail is the node that contains the offset directly.
|
---|
| 24 | *
|
---|
| 25 | * For example, the expression `a + b + c` might have an ast that looks
|
---|
| 26 | * like:
|
---|
| 27 | * +
|
---|
| 28 | * / \
|
---|
| 29 | * a +
|
---|
| 30 | * / \
|
---|
| 31 | * b c
|
---|
| 32 | *
|
---|
| 33 | * The path to the node at offset 9 would be `['+' at 1-10, '+' at 7-10,
|
---|
| 34 | * 'c' at 9-10]` and the path the node at offset 1 would be
|
---|
| 35 | * `['+' at 1-10, 'a' at 1-2]`.
|
---|
| 36 | */
|
---|
| 37 | var AstPath = /** @class */ (function () {
|
---|
| 38 | function AstPath(path, position) {
|
---|
| 39 | if (position === void 0) { position = -1; }
|
---|
| 40 | this.path = path;
|
---|
| 41 | this.position = position;
|
---|
| 42 | }
|
---|
| 43 | Object.defineProperty(AstPath.prototype, "empty", {
|
---|
| 44 | get: function () {
|
---|
| 45 | return !this.path || !this.path.length;
|
---|
| 46 | },
|
---|
| 47 | enumerable: false,
|
---|
| 48 | configurable: true
|
---|
| 49 | });
|
---|
| 50 | Object.defineProperty(AstPath.prototype, "head", {
|
---|
| 51 | get: function () {
|
---|
| 52 | return this.path[0];
|
---|
| 53 | },
|
---|
| 54 | enumerable: false,
|
---|
| 55 | configurable: true
|
---|
| 56 | });
|
---|
| 57 | Object.defineProperty(AstPath.prototype, "tail", {
|
---|
| 58 | get: function () {
|
---|
| 59 | return this.path[this.path.length - 1];
|
---|
| 60 | },
|
---|
| 61 | enumerable: false,
|
---|
| 62 | configurable: true
|
---|
| 63 | });
|
---|
| 64 | AstPath.prototype.parentOf = function (node) {
|
---|
| 65 | return node && this.path[this.path.indexOf(node) - 1];
|
---|
| 66 | };
|
---|
| 67 | AstPath.prototype.childOf = function (node) {
|
---|
| 68 | return this.path[this.path.indexOf(node) + 1];
|
---|
| 69 | };
|
---|
| 70 | AstPath.prototype.first = function (ctor) {
|
---|
| 71 | for (var i = this.path.length - 1; i >= 0; i--) {
|
---|
| 72 | var item = this.path[i];
|
---|
| 73 | if (item instanceof ctor)
|
---|
| 74 | return item;
|
---|
| 75 | }
|
---|
| 76 | };
|
---|
| 77 | AstPath.prototype.push = function (node) {
|
---|
| 78 | this.path.push(node);
|
---|
| 79 | };
|
---|
| 80 | AstPath.prototype.pop = function () {
|
---|
| 81 | return this.path.pop();
|
---|
| 82 | };
|
---|
| 83 | return AstPath;
|
---|
| 84 | }());
|
---|
| 85 | exports.AstPath = AstPath;
|
---|
| 86 | });
|
---|
| 87 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXN0X3BhdGguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9jb21waWxlci9zcmMvYXN0X3BhdGgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HOzs7Ozs7Ozs7Ozs7O0lBRUg7Ozs7Ozs7Oz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