processor.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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] !== '6' ) {
  30. * throw new Error('This plugin works only with PostCSS 6');
  31. * }
  32. */
  33. this.version = '6.0.23';
  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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInByb2Nlc3Nvci5lczYiXSwibmFtZXMiOlsiUHJvY2Vzc29yIiwicGx1Z2lucyIsInZlcnNpb24iLCJub3JtYWxpemUiLCJ1c2UiLCJwbHVnaW4iLCJjb25jYXQiLCJwcm9jZXNzIiwiY3NzIiwib3B0cyIsIkxhenlSZXN1bHQiLCJub3JtYWxpemVkIiwiaSIsInBvc3Rjc3MiLCJBcnJheSIsImlzQXJyYXkiLCJwdXNoIiwicGFyc2UiLCJzdHJpbmdpZnkiLCJFcnJvciJdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUE7Ozs7Ozs7O0FBRUE7Ozs7Ozs7OztJQVNNQSxTOztBQUVGOzs7O0FBSUEsdUJBQTBCO0FBQUEsUUFBZEMsT0FBYyx1RU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H0gbWV0aG9kcy5cbiAgICAgKlxuICAgICAqIEBwYXJhbSB7c3RyaW5nfHRvU3RyaW5nfFJlc3VsdH0gY3NzIC0gU3RyaW5nIHdpdGggaW5wdXQgQ1NTIG9yXG4gICAgICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbnkgb2JqZWN0IHdpdGggYSBgdG9TdHJpbmcoKWBcbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1ldGhvZCwgbGlrZSBhIEJ1ZmZlci5cbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIE9wdGlvbmFsbHksIHNlbmQgYSB7QGxpbmsgUmVzdWx0fVxuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaW5zdGFuY2UgYW5kIHRoZSBwcm9jZXNzb3Igd2lsbFxuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdGFrZSB0aGUge0BsaW5rIFJvb3R9IGZyb20gaXQuXG4gICAgICogQHBhcmFtIHtwcm9jZXNzT3B0aW9uc30gW29wdHNdICAgICAgLSBvcHRpb25zXG4gICAgICpcbiAgICAgKiBAcmV0dXJuIHtMYXp5UmVzdWx0fSBQcm9taXNlIHByb3h5XG4gICAgICpcbiAgICAgKiBAZXhhbXBsZVxuICAgICAqIHByb2Nlc3Nvci5wcm9jZXNzKGNzcywgeyBmcm9tOiAnYS5jc3MnLCB0bzogJ2Eub3V0LmNzcycgfSlcbiAgICAgKiAgIC50aGVuKHJlc3VsdCA9PiB7XG4gICAgICogICAgICBjb25zb2xlLmxvZyhyZXN1bHQuY3NzKTtcbiAgICAgKiAgIH0pO1xuICAgICAqL1xuICAgIHByb2Nlc3MoY3NzLCBvcHRzID0geyB9KSB7XG4gICAgICAgIHJldHVybiBuZXcgTGF6eVJlc3VsdCh0aGlzLCBjc3MsIG9wdHMpO1xuICAgIH1cblxuICAgIG5vcm1hbGl6ZShwbHVnaW5zKSB7XG4gICAgICAgIGxldCBub3JtYWxpemVkID0gW107XG4gICAgICAgIGZvciAoIGxldCBpIG9mIHBsdWdpbnMgKSB7XG4gICAgICAgICAgICBpZiAoIGkucG9zdGNzcyApIGkgPSBpLnBvc3Rjc3M7XG5cbiAgICAgICAgICAgIGlmICggdHlwZW9mIGkgPT09ICdvYmplY3QnICYmIEFycmF5LmlzQXJyYXkoaS5wbHVnaW5zKSApIHtcbiAgICAgICAgICAgICAgICBub3JtYWxpemVkID0gbm9ybWFsaXplZC5jb25jYXQoaS5wbHVnaW5zKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoIHR5cGVvZiBpID09PSAnZnVuY3Rpb24nICkge1xuICAgICAgICAgICAgICAgIG5vcm1hbGl6ZWQucHVzaChpKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoIHR5cGVvZiBpID09PSAnb2JqZWN0JyAmJiAoaS5wYXJzZSB8fCBpLnN0cmluZ2lmeSkgKSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdQb3N0Q1NTIHN5bnRheGVzIGNhbm5vdCBiZSB1c2VkIGFzIHBsdWdpbnMuICcgK1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAnSW5zdGVhZCwgcGxlYXNlIHVzZSBvbmUgb2YgdGhlICcgK1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAnc3ludGF4L3BhcnNlci9zdHJpbmdpZmllciBvcHRpb25zIGFzICcgK1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAnb3V0bGluZWQgaW4geW91ciBQb3N0Q1NTICcgK1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAncnVubmVyIGRvY3VtZW50YXRpb24uJyk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihpICsgJyBpcyBub3QgYSBQb3N0Q1NTIHBsdWdpbicpO1xuICA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AgICAgICAgICAgICAgICAgICAgICAgIGJlY2F1c2UgaXQgaXMgdXNlZCBpbiBzb3VyY2UgbWFwXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGdlbmVyYXRpb24gYW5kIHN5bnRheCBlcnJvciBtZXNzYWdlcy5cbiAqIEBwcm9wZXJ0eSB7c3RyaW5nfSB0byAgICAgICAgICAgICAgIC0gdGhlIHBhdGggd2hlcmUgeW914oCZbGwgcHV0IHRoZSBvdXRwdXRcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQ1NTIGZpbGUuIFlvdSBzaG91bGQgYWx3YXlzIHNldCBgdG9gXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRvIGdlbmVyYXRlIGNvcnJlY3Qgc291cmNlIG1hcHMuXG4gKiBAcHJvcGVydHkge3BhcnNlcn0gcGFyc2VyICAgICAgICAgICAtIGZ1bmN0aW9uIHRvIGdlbmVyYXRlIEFTVCBieSBzdHJpbmdcbiAqIEBwcm9wZXJ0eSB7c3RyaW5naWZpZXJ9IHN0cmluZ2lmaWVyIC0gY2xhc3MgdG8gZ2VuZXJhdGUgc3RyaW5nIGJ5IEFTVFxuICogQHByb3BlcnR5IHtzeW50YXh9IHN5bnRheCAgICAgICAgICAgLSBvYmplY3Qgd2l0aCBgcGFyc2VgIGFuZCBgc3RyaW5naWZ5YFxuICogQHByb3BlcnR5IHtvYmplY3R9IG1hcCAgICAgICAgICAgICAgLSBzb3VyY2UgbWFwIG9wdGlvbnNcbiAqIEBwcm9wZXJ0eSB7Ym9vbGVhbn0gbWFwLmlubGluZSAgICAgICAgICAgICAgICAgICAgLSBkb2VzIHNvdXJjZSBtYXAgc2hvdWxkXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYmUgZW1iZWRkZWQgaW4gdGhlIG91dHB1dFxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIENTUyBhcyBhIGJhc2U2NC1lbmNvZGVkXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29tbWVudFxuICogQHByb3BlcnR5IHtzdHJpbmd8b2JqZWN0fGZhbHNlfGZ1bmN0aW9ufSBtYXAucHJldiAtIHNvdXJjZSBtYXAgY29udGVudFxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gYSBwcmV2aW91c1xuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHByb2Nlc3Npbmcgc3RlcFxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChmb3IgZXhhbXBsZSwgU2FzcykuXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUG9zdENTUyB3aWxsIHRyeSB0byBmaW5kXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcHJldmlvdXMgbWFwXG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYXV0b21hdGljYWxseSwgc28geW91XG4gKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY291bGQgZGlzYWJsZSBpdCBieVxuICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGBmYWxzZWAgdmFsdWUuXG4gKiBAcHJvcGVydHkge2Jvb2xlYW59IG1hcC5zb3VyY2VzQ29udGVudCAgICAgICAgICAgIC0gZG9lcyBQb3N0Q1NTIHNob3VsZCBzZXRcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGUgb3JpZ2luIGNvbnRlbnQgdG8gbWFwXG4gKiBAcHJvcGVydHkge3N0cmluZ3xmYWxzZX0gbWFwLmFubm90YXRpb24gICAgICAgICAgIC0gZG9lcyBQb3N0Q1NTIHNob3VsZCBzZXRcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbm5vdGF0aW9uIGNvbW1lbnQgdG8gbWFwXG4gKiBAcHJvcGVydHkge3N0cmluZ30gbWFwLmZyb20gICAgICAgICAgICAgICAgICAgICAgIC0gb3ZlcnJpZGUgYGZyb21gIGluIG1hcOKAmXNcbiAqICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBgc291cmNlc2BcbiAqL1xuIl19