lazy-result.js 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4. 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; };
  5. var _mapGenerator = require('./map-generator');
  6. var _mapGenerator2 = _interopRequireDefault(_mapGenerator);
  7. var _stringify2 = require('./stringify');
  8. var _stringify3 = _interopRequireDefault(_stringify2);
  9. var _warnOnce = require('./warn-once');
  10. var _warnOnce2 = _interopRequireDefault(_warnOnce);
  11. var _result = require('./result');
  12. var _result2 = _interopRequireDefault(_result);
  13. var _parse = require('./parse');
  14. var _parse2 = _interopRequireDefault(_parse);
  15. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  16. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  17. function isPromise(obj) {
  18. return (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && typeof obj.then === 'function';
  19. }
  20. /**
  21. * A Promise proxy for the result of PostCSS transformations.
  22. *
  23. * A `LazyResult` instance is returned by {@link Processor#process}.
  24. *
  25. * @example
  26. * const lazy = postcss([cssnext]).process(css);
  27. */
  28. var LazyResult = function () {
  29. function LazyResult(processor, css, opts) {
  30. _classCallCheck(this, LazyResult);
  31. this.stringified = false;
  32. this.processed = false;
  33. var root = void 0;
  34. if ((typeof css === 'undefined' ? 'undefined' : _typeof(css)) === 'object' && css !== null && css.type === 'root') {
  35. root = css;
  36. } else if (css instanceof LazyResult || css instanceof _result2.default) {
  37. root = css.root;
  38. if (css.map) {
  39. if (typeof opts.map === 'undefined') opts.map = {};
  40. if (!opts.map.inline) opts.map.inline = false;
  41. opts.map.prev = css.map;
  42. }
  43. } else {
  44. var parser = _parse2.default;
  45. if (opts.syntax) parser = opts.syntax.parse;
  46. if (opts.parser) parser = opts.parser;
  47. if (parser.parse) parser = parser.parse;
  48. try {
  49. root = parser(css, opts);
  50. } catch (error) {
  51. this.error = error;
  52. }
  53. }
  54. this.result = new _result2.default(processor, root, opts);
  55. }
  56. /**
  57. * Returns a {@link Processor} instance, which will be used
  58. * for CSS transformations.
  59. * @type {Processor}
  60. */
  61. /**
  62. * Processes input CSS through synchronous plugins
  63. * and calls {@link Result#warnings()}.
  64. *
  65. * @return {Warning[]} warnings from plugins
  66. */
  67. LazyResult.prototype.warnings = function warnings() {
  68. return this.sync().warnings();
  69. };
  70. /**
  71. * Alias for the {@link LazyResult#css} property.
  72. *
  73. * @example
  74. * lazy + '' === lazy.css;
  75. *
  76. * @return {string} output CSS
  77. */
  78. LazyResult.prototype.toString = function toString() {
  79. return this.css;
  80. };
  81. /**
  82. * Processes input CSS through synchronous and asynchronous plugins
  83. * and calls `onFulfilled` with a Result instance. If a plugin throws
  84. * an error, the `onRejected` callback will be executed.
  85. *
  86. * It implements standard Promise API.
  87. *
  88. * @param {onFulfilled} onFulfilled - callback will be executed
  89. * when all plugins will finish work
  90. * @param {onRejected} onRejected - callback will be executed on any error
  91. *
  92. * @return {Promise} Promise API to make queue
  93. *
  94. * @example
  95. * postcss([cssnext]).process(css, { from: cssPath }).then(result => {
  96. * console.log(result.css);
  97. * });
  98. */
  99. LazyResult.prototype.then = function then(onFulfilled, onRejected) {
  100. if (!('from' in this.opts)) {
  101. (0, _warnOnce2.default)('Without `from` option PostCSS could generate wrong ' + 'source map and will not find Browserslist config. ' + 'Set it to CSS file path or to `undefined` to prevent ' + 'this warning.');
  102. }
  103. return this.async().then(onFulfilled, onRejected);
  104. };
  105. /**
  106. * Processes input CSS through synchronous and asynchronous plugins
  107. * and calls onRejected for each error thrown in any plugin.
  108. *
  109. * It implements standard Promise API.
  110. *
  111. * @param {onRejected} onRejected - callback will be executed on any error
  112. *
  113. * @return {Promise} Promise API to make queue
  114. *
  115. * @example
  116. * postcss([cssnext]).process(css).then(result => {
  117. * console.log(result.css);
  118. * }).catch(error => {
  119. * console.error(error);
  120. * });
  121. */
  122. LazyResult.prototype.catch = function _catch(onRejected) {
  123. return this.async().catch(onRejected);
  124. };
  125. LazyResult.prototype.handleError = function handleError(error, plugin) {
  126. try {
  127. this.error = error;
  128. if (error.name === 'CssSyntaxError' && !error.plugin) {
  129. error.plugin = plugin.postcssPlugin;
  130. error.setMessage();
  131. } else if (plugin.postcssVersion) {
  132. var pluginName = plugin.postcssPlugin;
  133. var pluginVer = plugin.postcssVersion;
  134. var runtimeVer = this.result.processor.version;
  135. var a = pluginVer.split('.');
  136. var b = runtimeVer.split('.');
  137. if (a[0] !== b[0] || parseInt(a[1]) > parseInt(b[1])) {
  138. console.error('Unknown error from PostCSS plugin. ' + 'Your current PostCSS version ' + 'is ' + runtimeVer + ', but ' + pluginName + ' ' + 'uses ' + pluginVer + '. Perhaps this is ' + 'the source of the error below.');
  139. }
  140. }
  141. } catch (err) {
  142. if (console && console.error) console.error(err);
  143. }
  144. };
  145. LazyResult.prototype.asyncTick = function asyncTick(resolve, reject) {
  146. var _this = this;
  147. if (this.plugin >= this.processor.plugins.length) {
  148. this.processed = true;
  149. return resolve();
  150. }
  151. try {
  152. var plugin = this.processor.plugins[this.plugin];
  153. var promise = this.run(plugin);
  154. this.plugin += 1;
  155. if (isPromise(promise)) {
  156. promise.then(function () {
  157. _this.asyncTick(resolve, reject);
  158. }).catch(function (error) {
  159. _this.handleError(error, plugin);
  160. _this.processed = true;
  161. reject(error);
  162. });
  163. } else {
  164. this.asyncTick(resolve, reject);
  165. }
  166. } catch (error) {
  167. this.processed = true;
  168. reject(error);
  169. }
  170. };
  171. LazyResult.prototype.async = function async() {
  172. var _this2 = this;
  173. if (this.processed) {
  174. return new Promise(function (resolve, reject) {
  175. if (_this2.error) {
  176. reject(_this2.error);
  177. } else {
  178. resolve(_this2.stringify());
  179. }
  180. });
  181. }
  182. if (this.processing) {
  183. return this.processing;
  184. }
  185. this.processing = new Promise(function (resolve, reject) {
  186. if (_this2.error) return reject(_this2.error);
  187. _this2.plugin = 0;
  188. _this2.asyncTick(resolve, reject);
  189. }).then(function () {
  190. _this2.processed = true;
  191. return _this2.stringify();
  192. });
  193. return this.processing;
  194. };
  195. LazyResult.prototype.sync = function sync() {
  196. if (this.processed) return this.result;
  197. this.processed = true;
  198. if (this.processing) {
  199. throw new Error('Use process(css).then(cb) to work with async plugins');
  200. }
  201. if (this.error) throw this.error;
  202. for (var _iterator = this.result.processor.plugins, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  203. var _ref;
  204. if (_isArray) {
  205. if (_i >= _iterator.length) break;
  206. _ref = _iterator[_i++];
  207. } else {
  208. _i = _iterator.next();
  209. if (_i.done) break;
  210. _ref = _i.value;
  211. }
  212. var plugin = _ref;
  213. var promise = this.run(plugin);
  214. if (isPromise(promise)) {
  215. throw new Error('Use process(css).then(cb) to work with async plugins');
  216. }
  217. }
  218. return this.result;
  219. };
  220. LazyResult.prototype.run = function run(plugin) {
  221. this.result.lastPlugin = plugin;
  222. try {
  223. return plugin(this.result.root, this.result);
  224. } catch (error) {
  225. this.handleError(error, plugin);
  226. throw error;
  227. }
  228. };
  229. LazyResult.prototype.stringify = function stringify() {
  230. if (this.stringified) return this.result;
  231. this.stringified = true;
  232. this.sync();
  233. var opts = this.result.opts;
  234. var str = _stringify3.default;
  235. if (opts.syntax) str = opts.syntax.stringify;
  236. if (opts.stringifier) str = opts.stringifier;
  237. if (str.stringify) str = str.stringify;
  238. var map = new _mapGenerator2.default(str, this.result.root, this.result.opts);
  239. var data = map.generate();
  240. this.result.css = data[0];
  241. this.result.map = data[1];
  242. return this.result;
  243. };
  244. _createClass(LazyResult, [{
  245. key: 'processor',
  246. get: function get() {
  247. return this.result.processor;
  248. }
  249. /**
  250. * Options from the {@link Processor#process} call.
  251. * @type {processOptions}
  252. */
  253. }, {
  254. key: 'opts',
  255. get: function get() {
  256. return this.result.opts;
  257. }
  258. /**
  259. * Processes input CSS through synchronous plugins, converts `Root`
  260. * to a CSS string and returns {@link Result#css}.
  261. *
  262. * This property will only work with synchronous plugins.
  263. * If the processor contains any asynchronous plugins
  264. * it will throw an error. This is why this method is only
  265. * for debug purpose, you should always use {@link LazyResult#then}.
  266. *
  267. * @type {string}
  268. * @see Result#css
  269. */
  270. }, {
  271. key: 'css',
  272. get: function get() {
  273. return this.stringify().css;
  274. }
  275. /**
  276. * An alias for the `css` property. Use it with syntaxes
  277. * that generate non-CSS output.
  278. *
  279. * This property will only work with synchronous plugins.
  280. * If the processor contains any asynchronous plugins
  281. * it will throw an error. This is why this method is only
  282. * for debug purpose, you should always use {@link LazyResult#then}.
  283. *
  284. * @type {string}
  285. * @see Result#content
  286. */
  287. }, {
  288. key: 'content',
  289. get: function get() {
  290. return this.stringify().content;
  291. }
  292. /**
  293. * Processes input CSS through synchronous plugins
  294. * and returns {@link Result#map}.
  295. *
  296. * This property will only work with synchronous plugins.
  297. * If the processor contains any asynchronous plugins
  298. * it will throw an error. This is why this method is only
  299. * for debug purpose, you should always use {@link LazyResult#then}.
  300. *
  301. * @type {SourceMapGenerator}
  302. * @see Result#map
  303. */
  304. }, {
  305. key: 'map',
  306. get: function get() {
  307. return this.stringify().map;
  308. }
  309. /**
  310. * Processes input CSS through synchronous plugins
  311. * and returns {@link Result#root}.
  312. *
  313. * This property will only work with synchronous plugins. If the processor
  314. * contains any asynchronous plugins it will throw an error.
  315. *
  316. * This is why this method is only for debug purpose,
  317. * you should always use {@link LazyResult#then}.
  318. *
  319. * @type {Root}
  320. * @see Result#root
  321. */
  322. }, {
  323. key: 'root',
  324. get: function get() {
  325. return this.sync().root;
  326. }
  327. /**
  328. * Processes input CSS through synchronous plugins
  329. * and returns {@link Result#messages}.
  330. *
  331. * This property will only work with synchronous plugins. If the processor
  332. * contains any asynchronous plugins it will throw an error.
  333. *
  334. * This is why this method is only for debug purpose,
  335. * you should always use {@link LazyResult#then}.
  336. *
  337. * @type {Message[]}
  338. * @see Result#messages
  339. */
  340. }, {
  341. key: 'messages',
  342. get: function get() {
  343. return this.sync().messages;
  344. }
  345. }]);
  346. return LazyResult;
  347. }();
  348. exports.default = LazyResult;
  349. /**
  350. * @callback onFulfilled
  351. * @param {Result} result
  352. */
  353. /**
  354. * @callback onRejected
  355. * @param {Error} error
  356. */
  357. module.exports = exports['default'];
  358. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImxhenktcmVzdWx0LmVzNiJdLCJuYW1lcyI6WyJpc1Byb21pc2UiLCJvYmoiLCJ0aGVuIiwiTGF6eVJlc3VsdCIsInByb2Nlc3NvciIsImNzcyIsIm9wdHMiLCJzdHJpbmdpZmllZCIsInByb2Nlc3NlZCIsInJvb3QiLCJ0eXBlIiwiUmVzdWx0IiwibWFwIi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gob25SZWplY3RlZCk7XG4gICAgfVxuXG4gICAgaGFuZGxlRXJyb3IoZXJyb3IsIHBsdWdpbikge1xuICAgICAgICB0cnkge1xuICAgICAgICAgICAgdGhpcy5lcnJvciA9IGVycm9yO1xuICAgICAgICAgICAgaWYgKCBlcnJvci5uYW1lID09PSAnQ3NzU3ludGF4RXJyb3InICYmICFlcnJvci5wbHVnaW4gKSB7XG4gICAgICAgICAgICAgICAgZXJyb3IucGx1Z2luID0gcGx1Z2luLnBvc3Rjc3NQbHVnaW47XG4gICAgICAgICAgICAgICAgZXJyb3Iuc2V0TWVzc2FnZSgpO1xuICAgICAgICAgICAgfSBlbHNlIGlmICggcGx1Z2luLnBvc3Rjc3NWZXJzaW9uICkge1xuICAgICAgICAgICAgICAgIGxldCBwbHVnaW5OYW1lID0gcGx1Z2luLnBvc3Rjc3NQbHVnaW47XG4gICAgICAgICAgICAgICAgbGV0IHBsdWdpblZlciAgPSBwbHVnaW4ucG9zdGNzc1ZlcnNpb247XG4gICAgICAgICAgICAgICAgbGV0IHJ1bnRpbWVWZXIgPSB0aGlzLnJlc3VsdC5wcm9jZXNzb3IudmVyc2lvbjtcbiAgICAgICAgICAgICAgICBsZXQgYSA9IHBsdWdpblZlci5zcGxpdCgnLicpO1xuICAgICAgICAgICAgICAgIGxldCBiID0gcnVudGltZVZlci5zcGxpdCgnLicpO1xuXG4gICAgICAgICAgICAgICAgaWYgKCBhWzBdICE9PSBiWzBdIHx8IHBhcnNlSW50KGFbMV0pID4gcGFyc2VJbnQoYlsxXSkgKSB7XG4gICAgICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoXG4gICAgICAgICAgICAgICAgICAgICAgICAnVW5rbm93biBlcnJvciBmcm9tIFBvc3RDU1MgcGx1Z2luLiAnICtcbiAgICAgICAgICAgICAgICAgICAgICAgICdZb3VyIGN1cnJlbnQgUG9zdENTUyB2ZXJzaW9uICcgK1xuICAgICAgICAgICAgICAgICAgICAgICAgJ2lzICcgKyBydW50aW1lVmVyICsgJywgYnV0ICcgKyBwbHVnaW5OYW1lICsgJyAnICtcbiAgICAgICAgICAgICAgICAgICAgICAgICd1c2VzICcgKyBwbHVnaW5WZXIgKyAnLiBQZXJoYXBzIHRoaXMgaXMgJyArXG4gICAgICAgICAgICAgICAgICAgICAgICAndGhlIHNvdXJjZSBvZiB0aGUgZXJyb3IgYmVsb3cuJyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9IGNhdGNoIChlcnIpIHtcbiAgICAgICAgICAgIGlmICggY29uc29sZSAmJiBjb25zb2xlLmVycm9yICkgY29uc29sZS5lcnJvcihlcnIpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgYXN5bmNUaWNrKHJlc29sdmUsIHJlamVjdCkge1xuICAgICAgICBpZiAoIHRoaXMucGx1Z2luID49IHRoaXMucHJvY2Vzc29yLnBsdWdpbnMubGVuZ3RoICkge1xuICAgICAgICAgICAgdGhpcy5wcm9jZXNzZWQgPSB0cnVlO1xuICAgICAgICAgICAgcmV0dXJuIHJlc29sdmUoKTtcbiAgICAgICAgfVxuXG4gICAgICAgIHRyeSB7XG4gICAgICAgICAgICBsZXQgcGx1Z2luICA9IHRoaXMucHJvY2Vzc29yLnBsdWdpbnNbdGhpcy5wbHVnaW5dO1xuICAgICAgICAgICAgbGV0IHByb21pc2UgPSB0aGlzLnJ1bihwbHVnaW4pO1xuICAgICAgICAgICAgdGhpcy5wbHVnaW4gKz0gMTtcblxuICAgICAgICAgICAgaWYgKCBpc1Byb21pc2UocHJvbWlzZSkgKSB7XG4gICAgICAgICAgICAgICAgcHJvbWlzZS50aGVuKCAoKSA9PiB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuYXN5bmNUaWNrKHJlc29sdmUsIHJlamVjdCk7XG4gICAgICAgICAgICAgICAgfSkuY2F0Y2goIGVycm9yID0+IHtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5oYW5kbGVFcnJvcihlcnJvciwgcGx1Z2luKTtcbiAgICAgICAgICAgICAgICAgICAgdGhpcy5wcm9jZXNzZWQgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICByZWplY3QoZXJyb3IpO1xuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICB0aGlzLmFzeW5jVGljayhyZXNvbHZlLCByZWplY3QpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgIH0gY2F0Y2ggKGVycm9yKSB7XG4gICAgICAgICAgICB0aGlzLnByb2Nlc3NlZCA9IHRydWU7XG4gICAgICAgICAgICByZWplY3QoZXJyb3IpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgYXN5bmMoKSB7XG4gICAgICAgIGlmICggdGhpcy5wcm9jZXNzZWQgKSB7XG4gICAgICAgICAgICByZXR1cm4gbmV3IFByb21pc2UoIChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgICAgICAgICAgICBpZiAoIHRoaXMuZXJyb3IgKSB7XG4gICAgICAgICAgICAgICAgICAgIHJlamVjdCh0aGlzLmVycm9yKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICByZXNvbHZlKHRoaXMuc3RyaW5naWZ5KCkpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIGlmICggdGhpcy5wcm9jZXNzaW5nICkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMucHJvY2Vzc2luZztcbiAgICAgICAgfVxuXG4gICAgICAgIHRoaXMucHJvY2Vzc2luZyA9IG5ldyBQcm9taXNlKCAocmVzb2x2ZSwgcmVqZWN0KSA9PiB7XG4gICAgICAgICAgICBpZiAoIHRoaXMuZXJyb3IgKSByZXR1cm4gcmVqZWN0KHRoaXMuZXJyb3IpO1xuICAgICAgICAgICAgdGhpcy5wbHVnaW4gPSAwO1xuICAgICAgICAgICAgdGhpcy5hc3luY1RpY2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