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.
 
 
 

215 lines
14 KiB

"use strict";
exports.__esModule = true;
exports.default = void 0;
var _warning = _interopRequireDefault(require("./warning"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/**
* Provides the result of the PostCSS transformations.
*
* A Result instance is returned by {@link LazyResult#then}
* or {@link Root#toResult} methods.
*
* @example
* postcss([autoprefixer]).process(css).then(result => {
* console.log(result.css)
* })
*
* @example
* const result2 = postcss.parse(css).toResult()
*/
var Result =
/*#__PURE__*/
function () {
/**
* @param {Processor} processor Processor used for this transformation.
* @param {Root} root Root node after all transformations.
* @param {processOptions} opts Options from the {@link Processor#process}
* or {@link Root#toResult}.
*/
function Result(processor, root, opts) {
/**
* The Processor instance used for this transformation.
*
* @type {Processor}
*
* @example
* for (const plugin of result.processor.plugins) {
* if (plugin.postcssPlugin === 'postcss-bad') {
* throw 'postcss-good is incompatible with postcss-bad'
* }
* })
*/
this.processor = processor;
/**
* Contains messages from plugins (e.g., warnings or custom messages).
* Each message should have type and plugin properties.
*
* @type {Message[]}
*
* @example
* postcss.plugin('postcss-min-browser', () => {
* return (root, result) => {
* const browsers = detectMinBrowsersByCanIUse(root)
* result.messages.push({
* type: 'min-browser',
* plugin: 'postcss-min-browser',
* browsers
* })
* }
* })
*/
this.messages = [];
/**
* Root node after all transformations.
*
* @type {Root}
*
* @example
* root.toResult().root === root
*/
this.root = root;
/**
* Options from the {@link Processor#process} or {@link Root#toResult} call
* that produced this Result instance.
*
* @type {processOptions}
*
* @example
* root.toResult(opts).opts === opts
*/
this.opts = opts;
/**
* A CSS string representing of {@link Result#root}.
*
* @type {string}
*
* @example
* postcss.parse('a{}').toResult().css //=> "a{}"
*/
this.css = undefined;
/**
* An instance of `SourceMapGenerator` class from the `source-map` library,
* representing changes to the {@link Result#root} instance.
*
* @type {SourceMapGenerator}
*
* @example
* result.map.toJSON() //=> { version: 3, file: 'a.css', … }
*
* @example
* if (result.map) {
* fs.writeFileSync(result.opts.to + '.map', result.map.toString())
* }
*/
this.map = undefined;
}
/**
* Returns for @{link Result#css} content.
*
* @example
* result + '' === result.css
*
* @return {string} String representing of {@link Result#root}.
*/
var _proto = Result.prototype;
_proto.toString = function toString() {
return this.css;
}
/**
* Creates an instance of {@link Warning} and adds it
* to {@link Result#messages}.
*
* @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.
*
* @return {Warning} Created warning.
*/
;
_proto.warn = function warn(text, opts) {
if (opts === void 0) {
opts = {};
}
if (!opts.plugin) {
if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
opts.plugin = this.lastPlugin.postcssPlugin;
}
}
var warning = new _warning.default(text, opts);
this.messages.push(warning);
return warning;
}
/**
* Returns warnings from plugins. Filters {@link Warning} instances
* from {@link Result#messages}.
*
* @example
* result.warnings().forEach(warn => {
* console.warn(warn.toString())
* })
*
* @return {Warning[]} Warnings from plugins.
*/
;
_proto.warnings = function warnings() {
return this.messages.filter(function (i) {
return i.type === 'warning';
});
}
/**
* An alias for the {@link Result#css} property.
* Use it with syntaxes that generate non-CSS output.
*
* @type {string}
*
* @example
* result.css === result.content
*/
;
_createClass(Result, [{
key: "content",
get: function get() {
return this.css;
}
}]);
return Result;
}();
var _default = Result;
/**
* @typedef {object} Message
* @property {string} type Message type.
* @property {string} plugin Source PostCS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