walkerFn.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var ngWalker_1 = require("../angular/ngWalker");
  17. var function_1 = require("../util/function");
  18. function validate(syntaxKind) {
  19. return function (validateFn) { return ({
  20. kind: 'Node',
  21. validate: function (node, options) { return (node.kind === syntaxKind ? validateFn(node, options) : function_1.Maybe.nothing); }
  22. }); };
  23. }
  24. exports.validate = validate;
  25. function validateComponent(validate) {
  26. return {
  27. kind: 'NgComponent',
  28. validate: validate
  29. };
  30. }
  31. exports.validateComponent = validateComponent;
  32. function all() {
  33. var validators = [];
  34. for (var _i = 0; _i < arguments.length; _i++) {
  35. validators[_i] = arguments[_i];
  36. }
  37. return function (sourceFile, options) {
  38. var e = (function (_super) {
  39. __extends(class_1, _super);
  40. function class_1() {
  41. return _super !== null && _super.apply(this, arguments) || this;
  42. }
  43. class_1.prototype.visitNgComponent = function (meta) {
  44. var _this = this;
  45. validators.forEach(function (v) {
  46. if (v.kind === 'NgComponent') {
  47. v.validate(meta, _this.getOptions()).fmap(function (failures) { return failures.forEach(function (f) { return _this.generateFailure(f); }); });
  48. }
  49. });
  50. _super.prototype.visitNgComponent.call(this, meta);
  51. };
  52. class_1.prototype.visitNode = function (node) {
  53. var _this = this;
  54. validators.forEach(function (v) {
  55. if (v.kind === 'Node') {
  56. v.validate(node, _this.getOptions()).fmap(function (failures) { return failures.forEach(function (f) { return _this.generateFailure(f); }); });
  57. }
  58. });
  59. _super.prototype.visitNode.call(this, node);
  60. };
  61. class_1.prototype.generateFailure = function (failure) {
  62. this.addFailureAtNode(failure.node, failure.message);
  63. };
  64. return class_1;
  65. }(ngWalker_1.NgWalker));
  66. return new e(sourceFile, options);
  67. };
  68. }
  69. exports.all = all;