Node.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. var __assign = (this && this.__assign) || function () {
  18. __assign = Object.assign || function(t) {
  19. for (var s, i = 1, n = arguments.length; i < n; i++) {
  20. s = arguments[i];
  21. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  22. t[p] = s[p];
  23. }
  24. return t;
  25. };
  26. return __assign.apply(this, arguments);
  27. };
  28. var __values = (this && this.__values) || function(o) {
  29. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  30. if (m) return m.call(o);
  31. if (o && typeof o.length === "number") return {
  32. next: function () {
  33. if (o && i >= o.length) o = void 0;
  34. return { value: o && o[i++], done: !o };
  35. }
  36. };
  37. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  38. };
  39. Object.defineProperty(exports, "__esModule", { value: true });
  40. exports.AbstractEmptyNode = exports.AbstractNode = void 0;
  41. var AbstractNode = (function () {
  42. function AbstractNode(factory, properties, children) {
  43. var e_1, _a;
  44. if (properties === void 0) { properties = {}; }
  45. if (children === void 0) { children = []; }
  46. this.factory = factory;
  47. this.parent = null;
  48. this.properties = {};
  49. this.childNodes = [];
  50. try {
  51. for (var _b = __values(Object.keys(properties)), _c = _b.next(); !_c.done; _c = _b.next()) {
  52. var name_1 = _c.value;
  53. this.setProperty(name_1, properties[name_1]);
  54. }
  55. }
  56. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  57. finally {
  58. try {
  59. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  60. }
  61. finally { if (e_1) throw e_1.error; }
  62. }
  63. if (children.length) {
  64. this.setChildren(children);
  65. }
  66. }
  67. Object.defineProperty(AbstractNode.prototype, "kind", {
  68. get: function () {
  69. return 'unknown';
  70. },
  71. enumerable: false,
  72. configurable: true
  73. });
  74. AbstractNode.prototype.setProperty = function (name, value) {
  75. this.properties[name] = value;
  76. };
  77. AbstractNode.prototype.getProperty = function (name) {
  78. return this.properties[name];
  79. };
  80. AbstractNode.prototype.getPropertyNames = function () {
  81. return Object.keys(this.properties);
  82. };
  83. AbstractNode.prototype.getAllProperties = function () {
  84. return this.properties;
  85. };
  86. AbstractNode.prototype.removeProperty = function () {
  87. var e_2, _a;
  88. var names = [];
  89. for (var _i = 0; _i < arguments.length; _i++) {
  90. names[_i] = arguments[_i];
  91. }
  92. try {
  93. for (var names_1 = __values(names), names_1_1 = names_1.next(); !names_1_1.done; names_1_1 = names_1.next()) {
  94. var name_2 = names_1_1.value;
  95. delete this.properties[name_2];
  96. }
  97. }
  98. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  99. finally {
  100. try {
  101. if (names_1_1 && !names_1_1.done && (_a = names_1.return)) _a.call(names_1);
  102. }
  103. finally { if (e_2) throw e_2.error; }
  104. }
  105. };
  106. AbstractNode.prototype.isKind = function (kind) {
  107. return this.factory.nodeIsKind(this, kind);
  108. };
  109. AbstractNode.prototype.setChildren = function (children) {
  110. var e_3, _a;
  111. this.childNodes = [];
  112. try {
  113. for (var children_1 = __values(children), children_1_1 = children_1.next(); !children_1_1.done; children_1_1 = children_1.next()) {
  114. var child = children_1_1.value;
  115. this.appendChild(child);
  116. }
  117. }
  118. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  119. finally {
  120. try {
  121. if (children_1_1 && !children_1_1.done && (_a = children_1.return)) _a.call(children_1);
  122. }
  123. finally { if (e_3) throw e_3.error; }
  124. }
  125. };
  126. AbstractNode.prototype.appendChild = function (child) {
  127. this.childNodes.push(child);
  128. child.parent = this;
  129. return child;
  130. };
  131. AbstractNode.prototype.replaceChild = function (newChild, oldChild) {
  132. var i = this.childIndex(oldChild);
  133. if (i !== null) {
  134. this.childNodes[i] = newChild;
  135. newChild.parent = this;
  136. oldChild.parent = null;
  137. }
  138. return newChild;
  139. };
  140. AbstractNode.prototype.removeChild = function (child) {
  141. var i = this.childIndex(child);
  142. if (i !== null) {
  143. this.childNodes.splice(i, 1);
  144. child.parent = null;
  145. }
  146. return child;
  147. };
  148. AbstractNode.prototype.childIndex = function (node) {
  149. var i = this.childNodes.indexOf(node);
  150. return (i === -1 ? null : i);
  151. };
  152. AbstractNode.prototype.copy = function () {
  153. var e_4, _a;
  154. var node = this.factory.create(this.kind);
  155. node.properties = __assign({}, this.properties);
  156. try {
  157. for (var _b = __values(this.childNodes || []), _c = _b.next(); !_c.done; _c = _b.next()) {
  158. var child = _c.value;
  159. if (child) {
  160. node.appendChild(child.copy());
  161. }
  162. }
  163. }
  164. catch (e_4_1) { e_4 = { error: e_4_1 }; }
  165. finally {
  166. try {
  167. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  168. }
  169. finally { if (e_4) throw e_4.error; }
  170. }
  171. return node;
  172. };
  173. AbstractNode.prototype.findNodes = function (kind) {
  174. var nodes = [];
  175. this.walkTree(function (node) {
  176. if (node.isKind(kind)) {
  177. nodes.push(node);
  178. }
  179. });
  180. return nodes;
  181. };
  182. AbstractNode.prototype.walkTree = function (func, data) {
  183. var e_5, _a;
  184. func(this, data);
  185. try {
  186. for (var _b = __values(this.childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
  187. var child = _c.value;
  188. if (child) {
  189. child.walkTree(func, data);
  190. }
  191. }
  192. }
  193. catch (e_5_1) { e_5 = { error: e_5_1 }; }
  194. finally {
  195. try {
  196. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  197. }
  198. finally { if (e_5) throw e_5.error; }
  199. }
  200. return data;
  201. };
  202. AbstractNode.prototype.toString = function () {
  203. return this.kind + '(' + this.childNodes.join(',') + ')';
  204. };
  205. return AbstractNode;
  206. }());
  207. exports.AbstractNode = AbstractNode;
  208. var AbstractEmptyNode = (function (_super) {
  209. __extends(AbstractEmptyNode, _super);
  210. function AbstractEmptyNode() {
  211. return _super !== null && _super.apply(this, arguments) || this;
  212. }
  213. AbstractEmptyNode.prototype.setChildren = function (_children) {
  214. };
  215. AbstractEmptyNode.prototype.appendChild = function (child) {
  216. return child;
  217. };
  218. AbstractEmptyNode.prototype.replaceChild = function (_newChild, oldChild) {
  219. return oldChild;
  220. };
  221. AbstractEmptyNode.prototype.childIndex = function (_node) {
  222. return null;
  223. };
  224. AbstractEmptyNode.prototype.walkTree = function (func, data) {
  225. func(this, data);
  226. return data;
  227. };
  228. AbstractEmptyNode.prototype.toString = function () {
  229. return this.kind;
  230. };
  231. return AbstractEmptyNode;
  232. }(AbstractNode));
  233. exports.AbstractEmptyNode = AbstractEmptyNode;
  234. //# sourceMappingURL=Node.js.map