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.
134 lines
8.5 KiB
134 lines
8.5 KiB
4 years ago
|
"use strict";
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.default = void 0;
|
||
|
|
||
|
/**
|
||
|
* Represents a plugin’s warning. It can be created using {@link Node#warn}.
|
||
|
*
|
||
|
* @example
|
||
|
* if (decl.important) {
|
||
|
* decl.warn(result, 'Avoid !important', { word: '!important' })
|
||
|
* }
|
||
|
*/
|
||
|
var Warning =
|
||
|
/*#__PURE__*/
|
||
|
function () {
|
||
|
/**
|
||
|
* @param {string} text Warning message.
|
||
|
* @param {Object} [opts] Warning options.
|
||
|
* @param {Node} opts.node CSS node that caused the warning.
|
||
|
* @param {string} opts.word Word in CSS source that caused the warning.
|
||
|
* @param {number} opts.index Index in CSS node string that caused
|
||
|
* the warning.
|
||
|
* @param {string} opts.plugin Name of the plugin that created
|
||
|
* this warning. {@link Result#warn} fills
|
||
|
* this property automatically.
|
||
|
*/
|
||
|
function Warning(text, opts) {
|
||
|
if (opts === void 0) {
|
||
|
opts = {};
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Type to filter warnings from {@link Result#messages}.
|
||
|
* Always equal to `"warning"`.
|
||
|
*
|
||
|
* @type {string}
|
||
|
*
|
||
|
* @example
|
||
|
* const nonWarning = result.messages.filter(i => i.type !== 'warning')
|
||
|
*/
|
||
|
this.type = 'warning';
|
||
|
/**
|
||
|
* The warning message.
|
||
|
*
|
||
|
* @type {string}
|
||
|
*
|
||
|
* @example
|
||
|
* warning.text //=> 'Try to avoid !important'
|
||
|
*/
|
||
|
|
||
|
this.text = text;
|
||
|
|
||
|
if (opts.node && opts.node.source) {
|
||
|
var pos = opts.node.positionBy(opts);
|
||
|
/**
|
||
|
* Line in the input file with this warning’s source.
|
||
|
* @type {number}
|
||
|
*
|
||
|
* @example
|
||
|
* warning.line //=> 5
|
||
|
*/
|
||
|
|
||
|
this.line = pos.line;
|
||
|
/**
|
||
|
* Column in the input file with this warning’s source.
|
||
|
*
|
||
|
* @type {number}
|
||
|
*
|
||
|
* @example
|
||
|
* warning.column //=> 6
|
||
|
*/
|
||
|
|
||
|
this.column = pos.column;
|
||
|
}
|
||
|
|
||
|
for (var opt in opts) {
|
||
|
this[opt] = opts[opt];
|
||
|
}
|
||
|
}
|
||
|
/**
|
||
|
* Returns a warning position and message.
|
||
|
*
|
||
|
* @example
|
||
|
* warning.toString() //=> 'postcss-lint:a.css:10:14: Avoid !important'
|
||
|
*
|
||
|
* @return {string} Warning position and message.
|
||
|
*/
|
||
|
|
||
|
|
||
|
var _proto = Warning.prototype;
|
||
|
|
||
|
_proto.toString = function toString() {
|
||
|
if (this.node) {
|
||
|
return this.node.error(this.text, {
|
||
|
plugin: this.plugin,
|
||
|
index: this.index,
|
||
|
word: this.word
|
||
|
}).message;
|
||
|
}
|
||
|
|
||
|
if (this.plugin) {
|
||
|
return this.plugin + ': ' + this.text;
|
||
|
}
|
||
|
|
||
|
return this.text;
|
||
|
}
|
||
|
/**
|
||
|
* @memberof Warning#
|
||
|
* @member {string} plugin The name of the plugin that created
|
||
|
* it will fill this property automatically.
|
||
|
* this warning. When you call {@link Node#warn}
|
||
|
*
|
||
|
* @example
|
||
|
* warning.plugin //=> 'postcss-important'
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @memberof Warning#
|
||
|
* @member {Node} node Contains the CSS node that caused the warning.
|
||
|
*
|
||
|
* @example
|
||
|
* warning.node.toString() //=> 'color: white !important'
|
||
|
*/
|
||
|
;
|
||
|
|
||
|
return Warning;
|
||
|
}();
|
||
|
|
||
|
var _default = Warning;
|
||
|
exports.default = _default;
|
||
|
module.exports = exports.default;
|
||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIndhcm5pbmcuZXM2Il0sIm5hbWVzIjpbIldhcm5pbmciLCJ0ZXh0Iiwib3B0cyIsInR5cGUiLCJub2RlIiwic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