processor.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  4. var _lazyResult = require('./lazy-result');
  5. var _lazyResult2 = _interopRequireDefault(_lazyResult);
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  7. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8. /**
  9. * Contains plugins to process CSS. Create one `Processor` instance,
  10. * initialize its plugins, and then use that instance on numerous CSS files.
  11. *
  12. * @example
  13. * const processor = postcss([autoprefixer, precss]);
  14. * processor.process(css1).then(result => console.log(result.css));
  15. * processor.process(css2).then(result => console.log(result.css));
  16. */
  17. var Processor = function () {
  18. /**
  19. * @param {Array.<Plugin|pluginFunction>|Processor} plugins - PostCSS
  20. * plugins. See {@link Processor#use} for plugin format.
  21. */
  22. function Processor() {
  23. var plugins = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  24. _classCallCheck(this, Processor);
  25. /**
  26. * @member {string} - Current PostCSS version.
  27. *
  28. * @example
  29. * if ( result.processor.version.split('.')[0] !== '5' ) {
  30. * throw new Error('This plugin works only with PostCSS 5');
  31. * }
  32. */
  33. this.version = '5.2.18';
  34. /**
  35. * @member {pluginFunction[]} - Plugins added to this processor.
  36. *
  37. * @example
  38. * const processor = postcss([autoprefixer, precss]);
  39. * processor.plugins.length //=> 2
  40. */
  41. this.plugins = this.normalize(plugins);
  42. }
  43. /**
  44. * Adds a plugin to be used as a CSS processor.
  45. *
  46. * PostCSS plugin can be in 4 formats:
  47. * * A plugin created by {@link postcss.plugin} method.
  48. * * A function. PostCSS will pass the function a @{link Root}
  49. * as the first argument and current {@link Result} instance
  50. * as the second.
  51. * * An object with a `postcss` method. PostCSS will use that method
  52. * as described in #2.
  53. * * Another {@link Processor} instance. PostCSS will copy plugins
  54. * from that instance into this one.
  55. *
  56. * Plugins can also be added by passing them as arguments when creating
  57. * a `postcss` instance (see [`postcss(plugins)`]).
  58. *
  59. * Asynchronous plugins should return a `Promise` instance.
  60. *
  61. * @param {Plugin|pluginFunction|Processor} plugin - PostCSS plugin
  62. * or {@link Processor}
  63. * with plugins
  64. *
  65. * @example
  66. * const processor = postcss()
  67. * .use(autoprefixer)
  68. * .use(precss);
  69. *
  70. * @return {Processes} current processor to make methods chain
  71. */
  72. Processor.prototype.use = function use(plugin) {
  73. this.plugins = this.plugins.concat(this.normalize([plugin]));
  74. return this;
  75. };
  76. /**
  77. * Parses source CSS and returns a {@link LazyResult} Promise proxy.
  78. * Because some plugins can be asynchronous it doesn’t make
  79. * any transformations. Transformations will be applied
  80. * in the {@link LazyResult} methods.
  81. *
  82. * @param {string|toString|Result} css - String with input CSS or
  83. * any object with a `toString()`
  84. * method, like a Buffer.
  85. * Optionally, send a {@link Result}
  86. * instance and the processor will
  87. * take the {@link Root} from it.
  88. * @param {processOptions} [opts] - options
  89. *
  90. * @return {LazyResult} Promise proxy
  91. *
  92. * @example
  93. * processor.process(css, { from: 'a.css', to: 'a.out.css' })
  94. * .then(result => {
  95. * console.log(result.css);
  96. * });
  97. */
  98. Processor.prototype.process = function process(css) {
  99. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  100. return new _lazyResult2.default(this, css, opts);
  101. };
  102. Processor.prototype.normalize = function normalize(plugins) {
  103. var normalized = [];
  104. for (var _iterator = plugins, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  105. var _ref;
  106. if (_isArray) {
  107. if (_i >= _iterator.length) break;
  108. _ref = _iterator[_i++];
  109. } else {
  110. _i = _iterator.next();
  111. if (_i.done) break;
  112. _ref = _i.value;
  113. }
  114. var i = _ref;
  115. if (i.postcss) i = i.postcss;
  116. if ((typeof i === 'undefined' ? 'undefined' : _typeof(i)) === 'object' && Array.isArray(i.plugins)) {
  117. normalized = normalized.concat(i.plugins);
  118. } else if (typeof i === 'function') {
  119. normalized.push(i);
  120. } else if ((typeof i === 'undefined' ? 'undefined' : _typeof(i)) === 'object' && (i.parse || i.stringify)) {
  121. throw new Error('PostCSS syntaxes cannot be used as plugins. ' + 'Instead, please use one of the ' + 'syntax/parser/stringifier options as ' + 'outlined in your PostCSS ' + 'runner documentation.');
  122. } else {
  123. throw new Error(i + ' is not a PostCSS plugin');
  124. }
  125. }
  126. return normalized;
  127. };
  128. return Processor;
  129. }();
  130. exports.default = Processor;
  131. /**
  132. * @callback builder
  133. * @param {string} part - part of generated CSS connected to this node
  134. * @param {Node} node - AST node
  135. * @param {"start"|"end"} [type] - node’s part type
  136. */
  137. /**
  138. * @callback parser
  139. *
  140. * @param {string|toString} css - string with input CSS or any object
  141. * with toString() method, like a Buffer
  142. * @param {processOptions} [opts] - options with only `from` and `map` keys
  143. *
  144. * @return {Root} PostCSS AST
  145. */
  146. /**
  147. * @callback stringifier
  148. *
  149. * @param {Node} node - start node for stringifing. Usually {@link Root}.
  150. * @param {builder} builder - function to concatenate CSS from node’s parts
  151. * or generate string and source map
  152. *
  153. * @return {void}
  154. */
  155. /**
  156. * @typedef {object} syntax
  157. * @property {parser} parse - function to generate AST by string
  158. * @property {stringifier} stringify - function to generate string by AST
  159. */
  160. /**
  161. * @typedef {object} toString
  162. * @property {function} toString
  163. */
  164. /**
  165. * @callback pluginFunction
  166. * @param {Root} root - parsed input CSS
  167. * @param {Result} result - result to set warnings or check other plugins
  168. */
  169. /**
  170. * @typedef {object} Plugin
  171. * @property {function} postcss - PostCSS plugin function
  172. */
  173. /**
  174. * @typedef {object} processOptions
  175. * @property {string} from - the path of the CSS source file.
  176. * You should always set `from`,
  177. * because it is used in source map
  178. * generation and syntax error messages.
  179. * @property {string} to - the path where you’ll put the output
  180. * CSS file. You should always set `to`
  181. * to generate correct source maps.
  182. * @property {parser} parser - function to generate AST by string
  183. * @property {stringifier} stringifier - class to generate string by AST
  184. * @property {syntax} syntax - object with `parse` and `stringify`
  185. * @property {object} map - source map options
  186. * @property {boolean} map.inline - does source map should
  187. * be embedded in the output
  188. * CSS as a base64-encoded
  189. * comment
  190. * @property {string|object|false|function} map.prev - source map content
  191. * from a previous
  192. * processing step
  193. * (for example, Sass).
  194. * PostCSS will try to find
  195. * previous map
  196. * automatically, so you
  197. * could disable it by
  198. * `false` value.
  199. * @property {boolean} map.sourcesContent - does PostCSS should set
  200. * the origin content to map
  201. * @property {string|false} map.annotation - does PostCSS should set
  202. * annotation comment to map
  203. * @property {string} map.from - override `from` in map’s
  204. * `sources`
  205. */
  206. module.exports = exports['default'];
  207. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInByb2Nlc3Nvci5lczYiXSwibmFtZXMiOlsiUHJvY2Vzc29yIiwicGx1Z2lucyIsInZlcnNpb24iLCJub3JtYWxpemUiLCJ1c2UiLCJwbHVnaW4iLCJjb25jYXQiLCJwcm9jZXNzIiwiY3NzIiwib3B0cyIsIm5vcm1hbGl6ZWQiLCJpIiwicG9zdGNzcyIsIkFycmF5IiwiaXNBcnJheSIsInB1c2giLCJwYXJzZSIsInN0cmluZ2lmeSIsIkVycm9yIl0sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQTs7Ozs7Ozs7QUFFQTs7Ozs7Ozs7O0lBU01BLFM7O0FBRUY7Ozs7QUFJQSx1QkFBMEI7QUFBQSxRQUFkQyxPQUFjLHVFQUFKLEVBQUk7O0FB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dpbnMgc2hvdWxkIHJldHVybiBhIGBQcm9taXNlYCBpbnN0YW5jZS5cbiAgICAgKlxuICAgICAqIEBwYXJhbSB7UGx1Z2lufHBsdWdpbkZ1bmN0aW9ufFByb2Nlc3Nvcn0gcGx1Z2luIC0gUG9zdENTUyBwbHVnaW5cbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9yIHtAbGluayBQcm9jZXNzb3J9XG4gICAgICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3aXRoIHBsdWdpbnNcbiAgICAgKlxuICAgICAqIEBleGFtcGxlXG4gICAgICogY29uc3QgcHJvY2Vzc29yID0gcG9zdGNzcygpXG4gICAgICogICAudXNlKGF1dG9wcmVmaXhlcilcbiAgICAgKiAgIC51c2UocHJlY3NzKTtcbiAgICAgKlxuICAgICAqIEByZXR1cm4ge1Byb2Nlc3Nlc30gY3VycmVudCBwcm9jZXNzb3IgdG8gbWFrZSBtZXRob2RzIGNoYWluXG4gICAgICovXG4gICAgdXNlKHBsdWdpbikge1xuICAgICAgICB0aGlzLnBsdWdpbnMgPSB0aGlzLnBsdWdpbnMuY29uY2F0KHRoaXMubm9ybWFsaXplKFtwbHVnaW5dKSk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFBhcnNlcyBzb3VyY2UgQ1NTIGFuZCByZXR1cm5zIGEge0BsaW5rIExhenlSZXN1bHR9IFByb21pc2UgcHJveHkuXG4gICAgICogQmVjYXVzZSBzb21lIHBsdWdpbnMgY2FuIGJlIGFzeW5jaHJvbm91cyBpdCBkb2VzbuKAmXQgbWFrZVxuICAgICAqIGFueSB0cmFuc2Zvcm1hdGlvbnMuIFRyYW5zZm9ybWF0aW9ucyB3aWxsIGJlIGFwcGxpZWRcbiAgICAgKiBpbiB0aGUge0BsaW5rIExhenlSZXN1bHR9IG1ldGhvZHMuXG4gICAgICpcbiAgICAgKiBAcGFyYW0ge3N0cmluZ3x0b1N0cmluZ3xSZXN1bHR9IGNzcyAtIFN0cmluZyB3aXRoIGlucHV0IENTUyBvclxuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYW55IG9iamVjdCB3aXRoIGEgYHRvU3RyaW5nKClgXG4gICAgICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtZXRob2QsIGxpa2UgYSBCdWZmZXIuXG4gICAgICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBPcHRpb25hbGx5LCBzZW5kIGEge0BsaW5rIFJlc3VsdH1cbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGluc3RhbmNlIGFuZCB0aGUgcHJvY2Vzc29yIHdpbGxcbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRha2UgdGhlIHtAbGluayBSb290fSBmcm9tIGl0LlxuICAgICAqIEBwYXJhbSB7cHJvY2Vzc09wdGlvbnN9IFtvcHRzXSAgICAgIC0gb3B0aW9uc1xuICAgICAqXG4gICAgICogQHJldHVybiB7TGF6eVJlc3VsdH0gUHJvbWlzZSBwcm94eVxuICAgICAqXG4gICAgICogQGV4YW1wbGVcbiAgICAgKiBwcm9jZXNzb3IucHJvY2Vzcyhjc3MsIHsgZnJvbTogJ2EuY3NzJywgdG86ICdhLm91dC5jc3MnIH0pXG4gICAgICogICAudGhlbihyZXN1bHQgPT4ge1xuICAgICAqICAgICAgY29uc29sZS5sb2cocmVzdWx0LmNzcyk7XG4gICAgICogICB9KTtcbiAgICAgKi9cbiAgICBwcm9jZXNzKGNzcywgb3B0cyA9IHsgfSkge1xuICAgICAgICByZXR1cm4gbmV3IExhenlSZXN1bHQodGhpcywgY3NzLCBvcHRzKTtcbiAgICB9XG5cbiAgICBub3JtYWxpemUocGx1Z2lucykge1xuICAgICAgICBsZXQgbm9ybWFsaXplZCA9IFtdO1xuICAgICAgICBmb3IgKCBsZXQgaSBvZiBwbHVnaW5zICkge1xuICAgICAgICAgICAgaWYgKCBpLnBvc3Rjc3MgKSBpID0gaS5wb3N0Y3NzO1xuXG4gICAgICAgICAgICBpZiAoIHR5cGVvZiBpID09PSAnb2JqZWN0JyAmJiBBcnJheS5pc0FycmF5KGkucGx1Z2lucykgKSB7XG4gICAgICAgICAgICAgICAgbm9ybWFsaXplZCA9IG5vcm1hbGl6ZWQuY29uY2F0KGkucGx1Z2lucyk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKCB0eXBlb2YgaSA9PT0gJ2Z1bmN0aW9uJyApIHtcbiAgICAgICAgICAgICAgICBub3JtYWxpemVkLnB1c2goaSk7XG4gICAgICAgICAgICB9IGVsc2UgaWYgKCB0eXBlb2YgaSA9PT0gJ29iamVjdCcgJiYgKGkucGFyc2UgfHwgaS5zdHJpbmdpZnkpICkge1xuICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignUG9zdENTUyBzeW50YXhlcyBjYW5ub3QgYmUgdXNlZCBhcyBwbHVnaW5zLiAnICtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ0luc3RlYWQsIHBsZWFzZSB1c2Ugb25lIG9mIHRoZSAnICtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ3N5bnRheC9wYXJzZXIvc3RyaW5naWZpZXIgb3B0aW9ucyBhcyAnICtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ291dGxpbmVkIGluIHlvdXIgUG9zdENTUyAnICtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ3J1bm5lciBkb2N1bWVudGF0aW9uLicpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoaSArICcgaXMgbm90IGEgUG9zdENTUyBwbHVnaW4nKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICByZ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QgaW4gc291cmNlIG1hcFxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBnZW5lcmF0aW9uIGFuZCBzeW50YXggZXJyb3IgbWVzc2FnZXMuXG4gKiBAcHJvcGVydHkge3N0cmluZ30gdG8gICAgICAgICAgICAgICAtIHRoZSBwYXRoIHdoZXJlIHlvdeKAmWxsIHB1dCB0aGUgb3V0cHV0XG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIENTUyBmaWxlLiBZb3Ugc2hvdWxkIGFsd2F5cyBzZXQgYHRvYFxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0byBnZW5lcmF0ZSBjb3JyZWN0IHNvdXJjZSBtYXBzLlxuICogQHByb3BlcnR5IHtwYXJzZXJ9IHBhcnNlciAgICAgICAgICAgLSBmdW5jdGlvbiB0byBnZW5lcmF0ZSBBU1QgYnkgc3RyaW5nXG4gKiBAcHJvcGVydHkge3N0cmluZ2lmaWVyfSBzdHJpbmdpZmllciAtIGNsYXNzIHRvIGdlbmVyYXRlIHN0cmluZyBieSBBU1RcbiAqIEBwcm9wZXJ0eSB7c3ludGF4fSBzeW50YXggICAgICAgICAgIC0gb2JqZWN0IHdpdGggYHBhcnNlYCBhbmQgYHN0cmluZ2lmeWBcbiAqIEBwcm9wZXJ0eSB7b2JqZWN0fSBtYXAgICAgICAgICAgICAgIC0gc291cmNlIG1hcCBvcHRpb25zXG4gKiBAcHJvcGVydHkge2Jvb2xlYW59IG1hcC5pbmxpbmUgICAgICAgICAgICAgICAgICAgIC0gZG9lcyBzb3VyY2UgbWFwIHNob3VsZFxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJlIGVtYmVkZGVkIGluIHRoZSBvdXRwdXRcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBDU1MgYXMgYSBiYXNlNjQtZW5jb2RlZFxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbW1lbnRcbiAqIEBwcm9wZXJ0eSB7c3RyaW5nfG9iamVjdHxmYWxzZXxmdW5jdGlvbn0gbWFwLnByZXYgLSBzb3VyY2UgbWFwIGNvbnRlbnRcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tIGEgcHJldmlvdXNcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwcm9jZXNzaW5nIHN0ZXBcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAoZm9yIGV4YW1wbGUsIFNhc3MpLlxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFBvc3RDU1Mgd2lsbCB0cnkgdG8gZmluZFxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHByZXZpb3VzIG1hcFxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGF1dG9tYXRpY2FsbHksIHNvIHlvdVxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvdWxkIGRpc2FibGUgaXQgYnlcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBgZmFsc2VgIHZhbHVlLlxuICogQHByb3BlcnR5IHtib29sZWFufSBtYXAuc291cmNlc0NvbnRlbnQgICAgICAgICAgICAtIGRvZXMgUG9zdENTUyBzaG91bGQgc2V0XG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGhlIG9yaWdpbiBjb250ZW50IHRvIG1hcFxuICogQHByb3BlcnR5IHtzdHJpbmd8ZmFsc2V9IG1hcC5hbm5vdGF0aW9uICAgICAgICAgICAtIGRvZXMgUG9zdENTUyBzaG91bGQgc2V0XG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYW5ub3RhdGlvbiBjb21tZW50IHRvIG1hcFxuICogQHByb3BlcnR5IHtzdHJpbmd9IG1hcC5mcm9tICAgICAgICAgICAgICAgICAgICAgICAtIG92ZXJyaWRlIGBmcm9tYCBpbiBtYXDigJlzXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYHNvdXJjZXNgXG4gKi9cbiJdfQ==