You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
8.5 KiB

4 years ago
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. /**
  5. * Represents a plugins warning. It can be created using {@link Node#warn}.
  6. *
  7. * @example
  8. * if (decl.important) {
  9. * decl.warn(result, 'Avoid !important', { word: '!important' })
  10. * }
  11. */
  12. var Warning =
  13. /*#__PURE__*/
  14. function () {
  15. /**
  16. * @param {string} text Warning message.
  17. * @param {Object} [opts] Warning options.
  18. * @param {Node} opts.node CSS node that caused the warning.
  19. * @param {string} opts.word Word in CSS source that caused the warning.
  20. * @param {number} opts.index Index in CSS node string that caused
  21. * the warning.
  22. * @param {string} opts.plugin Name of the plugin that created
  23. * this warning. {@link Result#warn} fills
  24. * this property automatically.
  25. */
  26. function Warning(text, opts) {
  27. if (opts === void 0) {
  28. opts = {};
  29. }
  30. /**
  31. * Type to filter warnings from {@link Result#messages}.
  32. * Always equal to `"warning"`.
  33. *
  34. * @type {string}
  35. *
  36. * @example
  37. * const nonWarning = result.messages.filter(i => i.type !== 'warning')
  38. */
  39. this.type = 'warning';
  40. /**
  41. * The warning message.
  42. *
  43. * @type {string}
  44. *
  45. * @example
  46. * warning.text //=> 'Try to avoid !important'
  47. */
  48. this.text = text;
  49. if (opts.node && opts.node.source) {
  50. var pos = opts.node.positionBy(opts);
  51. /**
  52. * Line in the input file with this warnings source.
  53. * @type {number}
  54. *
  55. * @example
  56. * warning.line //=> 5
  57. */
  58. this.line = pos.line;
  59. /**
  60. * Column in the input file with this warnings source.
  61. *
  62. * @type {number}
  63. *
  64. * @example
  65. * warning.column //=> 6
  66. */
  67. this.column = pos.column;
  68. }
  69. for (var opt in opts) {
  70. this[opt] = opts[opt];
  71. }
  72. }
  73. /**
  74. * Returns a warning position and message.
  75. *
  76. * @example
  77. * warning.toString() //=> 'postcss-lint:a.css:10:14: Avoid !important'
  78. *
  79. * @return {string} Warning position and message.
  80. */
  81. var _proto = Warning.prototype;
  82. _proto.toString = function toString() {
  83. if (this.node) {
  84. return this.node.error(this.text, {
  85. plugin: this.plugin,
  86. index: this.index,
  87. word: this.word
  88. }).message;
  89. }
  90. if (this.plugin) {
  91. return this.plugin + ': ' + this.text;
  92. }
  93. return this.text;
  94. }
  95. /**
  96. * @memberof Warning#
  97. * @member {string} plugin The name of the plugin that created
  98. * it will fill this property automatically.
  99. * this warning. When you call {@link Node#warn}
  100. *
  101. * @example
  102. * warning.plugin //=> 'postcss-important'
  103. */
  104. /**
  105. * @memberof Warning#
  106. * @member {Node} node Contains the CSS node that caused the warning.
  107. *
  108. * @example
  109. * warning.node.toString() //=> 'color: white !important'
  110. */
  111. ;
  112. return Warning;
  113. }();
  114. var _default = Warning;
  115. exports.default = _default;
  116. module.exports = exports.default;
  117. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndhcm5pbmcuZXM2Il0sIm5hbWVzIjpbIldhcm5pbmciLCJ0ZXh0Iiwib3B0cyIsInR5cGUiLCJub2RlIiwic291cmNlIiwicG9zIiwicG9zaXRpb25CeSIsImxpbmUiLCJjb2x1bW4iLCJvcHQiLCJ0b1N0cmluZyIsImVycm9yIiwicGx1Z2luIiwiaW5kZXgiLCJ3b3JkIiwibWVzc2FnZSJdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQTs7Ozs7Ozs7SUFRTUEsTzs7O0FBQ0o7Ozs7Ozs7Ozs7O0FBV0EsbUJBQWFDLElBQWIsRUFBbUJDLElBQW5CLEVBQStCO0FBQUEsUUFBWkEsSUFBWTtBQUFaQSxNQUFBQSxJQUFZLEdBQUwsRUFBSztBQUFBOztBQUM3Qjs7Ozs7Ozs7O0FBU0EsU0FBS0MsSUFBTCxHQUFZLFNBQVo7QUFDQTs7Ozs7Ozs7O0FBUUEsU0FBS0YsSUFBTCxHQUFZQSxJQUFaOztBQUVBLFFBQUlDLElBQUksQ0FBQ0UsSUFBTCxJQUFh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