lazy-result.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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.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).then(result => {
  96. * console.log(result.css);
  97. * });
  98. */
  99. LazyResult.prototype.then = function then(onFulfilled, onRejected) {
  100. return this.async().then(onFulfilled, onRejected);
  101. };
  102. /**
  103. * Processes input CSS through synchronous and asynchronous plugins
  104. * and calls onRejected for each error thrown in any plugin.
  105. *
  106. * It implements standard Promise API.
  107. *
  108. * @param {onRejected} onRejected - callback will be executed on any error
  109. *
  110. * @return {Promise} Promise API to make queue
  111. *
  112. * @example
  113. * postcss([cssnext]).process(css).then(result => {
  114. * console.log(result.css);
  115. * }).catch(error => {
  116. * console.error(error);
  117. * });
  118. */
  119. LazyResult.prototype.catch = function _catch(onRejected) {
  120. return this.async().catch(onRejected);
  121. };
  122. LazyResult.prototype.handleError = function handleError(error, plugin) {
  123. try {
  124. this.error = error;
  125. if (error.name === 'CssSyntaxError' && !error.plugin) {
  126. error.plugin = plugin.postcssPlugin;
  127. error.setMessage();
  128. } else if (plugin.postcssVersion) {
  129. var pluginName = plugin.postcssPlugin;
  130. var pluginVer = plugin.postcssVersion;
  131. var runtimeVer = this.result.processor.version;
  132. var a = pluginVer.split('.');
  133. var b = runtimeVer.split('.');
  134. if (a[0] !== b[0] || parseInt(a[1]) > parseInt(b[1])) {
  135. (0, _warnOnce2.default)('Your current PostCSS version ' + 'is ' + runtimeVer + ', but ' + pluginName + ' ' + 'uses ' + pluginVer + '. Perhaps this is ' + 'the source of the error below.');
  136. }
  137. }
  138. } catch (err) {
  139. if (console && console.error) console.error(err);
  140. }
  141. };
  142. LazyResult.prototype.asyncTick = function asyncTick(resolve, reject) {
  143. var _this = this;
  144. if (this.plugin >= this.processor.plugins.length) {
  145. this.processed = true;
  146. return resolve();
  147. }
  148. try {
  149. var plugin = this.processor.plugins[this.plugin];
  150. var promise = this.run(plugin);
  151. this.plugin += 1;
  152. if (isPromise(promise)) {
  153. promise.then(function () {
  154. _this.asyncTick(resolve, reject);
  155. }).catch(function (error) {
  156. _this.handleError(error, plugin);
  157. _this.processed = true;
  158. reject(error);
  159. });
  160. } else {
  161. this.asyncTick(resolve, reject);
  162. }
  163. } catch (error) {
  164. this.processed = true;
  165. reject(error);
  166. }
  167. };
  168. LazyResult.prototype.async = function async() {
  169. var _this2 = this;
  170. if (this.processed) {
  171. return new Promise(function (resolve, reject) {
  172. if (_this2.error) {
  173. reject(_this2.error);
  174. } else {
  175. resolve(_this2.stringify());
  176. }
  177. });
  178. }
  179. if (this.processing) {
  180. return this.processing;
  181. }
  182. this.processing = new Promise(function (resolve, reject) {
  183. if (_this2.error) return reject(_this2.error);
  184. _this2.plugin = 0;
  185. _this2.asyncTick(resolve, reject);
  186. }).then(function () {
  187. _this2.processed = true;
  188. return _this2.stringify();
  189. });
  190. return this.processing;
  191. };
  192. LazyResult.prototype.sync = function sync() {
  193. if (this.processed) return this.result;
  194. this.processed = true;
  195. if (this.processing) {
  196. throw new Error('Use process(css).then(cb) to work with async plugins');
  197. }
  198. if (this.error) throw this.error;
  199. for (var _iterator = this.result.processor.plugins, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  200. var _ref;
  201. if (_isArray) {
  202. if (_i >= _iterator.length) break;
  203. _ref = _iterator[_i++];
  204. } else {
  205. _i = _iterator.next();
  206. if (_i.done) break;
  207. _ref = _i.value;
  208. }
  209. var plugin = _ref;
  210. var promise = this.run(plugin);
  211. if (isPromise(promise)) {
  212. throw new Error('Use process(css).then(cb) to work with async plugins');
  213. }
  214. }
  215. return this.result;
  216. };
  217. LazyResult.prototype.run = function run(plugin) {
  218. this.result.lastPlugin = plugin;
  219. try {
  220. return plugin(this.result.root, this.result);
  221. } catch (error) {
  222. this.handleError(error, plugin);
  223. throw error;
  224. }
  225. };
  226. LazyResult.prototype.stringify = function stringify() {
  227. if (this.stringified) return this.result;
  228. this.stringified = true;
  229. this.sync();
  230. var opts = this.result.opts;
  231. var str = _stringify3.default;
  232. if (opts.syntax) str = opts.syntax.stringify;
  233. if (opts.stringifier) str = opts.stringifier;
  234. if (str.stringify) str = str.stringify;
  235. var map = new _mapGenerator2.default(str, this.result.root, this.result.opts);
  236. var data = map.generate();
  237. this.result.css = data[0];
  238. this.result.map = data[1];
  239. return this.result;
  240. };
  241. _createClass(LazyResult, [{
  242. key: 'processor',
  243. get: function get() {
  244. return this.result.processor;
  245. }
  246. /**
  247. * Options from the {@link Processor#process} call.
  248. * @type {processOptions}
  249. */
  250. }, {
  251. key: 'opts',
  252. get: function get() {
  253. return this.result.opts;
  254. }
  255. /**
  256. * Processes input CSS through synchronous plugins, converts `Root`
  257. * to a CSS string and returns {@link Result#css}.
  258. *
  259. * This property will only work with synchronous plugins.
  260. * If the processor contains any asynchronous plugins
  261. * it will throw an error. This is why this method is only
  262. * for debug purpose, you should always use {@link LazyResult#then}.
  263. *
  264. * @type {string}
  265. * @see Result#css
  266. */
  267. }, {
  268. key: 'css',
  269. get: function get() {
  270. return this.stringify().css;
  271. }
  272. /**
  273. * An alias for the `css` property. Use it with syntaxes
  274. * that generate non-CSS output.
  275. *
  276. * This property will only work with synchronous plugins.
  277. * If the processor contains any asynchronous plugins
  278. * it will throw an error. This is why this method is only
  279. * for debug purpose, you should always use {@link LazyResult#then}.
  280. *
  281. * @type {string}
  282. * @see Result#content
  283. */
  284. }, {
  285. key: 'content',
  286. get: function get() {
  287. return this.stringify().content;
  288. }
  289. /**
  290. * Processes input CSS through synchronous plugins
  291. * and returns {@link Result#map}.
  292. *
  293. * This property will only work with synchronous plugins.
  294. * If the processor contains any asynchronous plugins
  295. * it will throw an error. This is why this method is only
  296. * for debug purpose, you should always use {@link LazyResult#then}.
  297. *
  298. * @type {SourceMapGenerator}
  299. * @see Result#map
  300. */
  301. }, {
  302. key: 'map',
  303. get: function get() {
  304. return this.stringify().map;
  305. }
  306. /**
  307. * Processes input CSS through synchronous plugins
  308. * and returns {@link Result#root}.
  309. *
  310. * This property will only work with synchronous plugins. If the processor
  311. * contains any asynchronous plugins it will throw an error.
  312. *
  313. * This is why this method is only for debug purpose,
  314. * you should always use {@link LazyResult#then}.
  315. *
  316. * @type {Root}
  317. * @see Result#root
  318. */
  319. }, {
  320. key: 'root',
  321. get: function get() {
  322. return this.sync().root;
  323. }
  324. /**
  325. * Processes input CSS through synchronous plugins
  326. * and returns {@link Result#messages}.
  327. *
  328. * This property will only work with synchronous plugins. If the processor
  329. * contains any asynchronous plugins it will throw an error.
  330. *
  331. * This is why this method is only for debug purpose,
  332. * you should always use {@link LazyResult#then}.
  333. *
  334. * @type {Message[]}
  335. * @see Result#messages
  336. */
  337. }, {
  338. key: 'messages',
  339. get: function get() {
  340. return this.sync().messages;
  341. }
  342. }]);
  343. return LazyResult;
  344. }();
  345. exports.default = LazyResult;
  346. /**
  347. * @callback onFulfilled
  348. * @param {Result} result
  349. */
  350. /**
  351. * @callback onRejected
  352. * @param {Error} error
  353. */
  354. module.exports = exports['default'];
  355. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImxhenktcmVzdWx0LmVzNiJdLCJuYW1lcyI6WyJpc1Byb21pc2UiLCJvYmoiLCJ0aGVuIiwiTGF6eVJlc3VsdCIsInByb2Nlc3NvciIsImNzcyIsIm9wdHMiLCJzdHJpbmdpZmllZCIsInByb2Nlc3NlZCIsInJvb3QiLCJ0eXBlIiwibWFwIiwiaW5saW5lIiwicHJldiIsInBhcnNlciIsInN5bnRheCIsInBhcnNlIiwiZXJyb3IiLCJyZXN1bHQiLCJ3YXJuaW5ncyIsInN5bmMiLCJ0b1N0cmluZyIsIm9uRnVsZmlsbGVkIiwib25SZWplY3RlZCIsImFzeW5j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0BsaW5rIFByb2Nlc3NvciNwcm9jZXNzfS5cbiAqXG4gKiBAZXhhbXBsZVxuICogY29uc3QgbGF6eSA9IHBvc3Rjc3MoW2Nzc25leHRdKS5wcm9jZXNzKGNzcyk7XG4gKi9cbmNsYXNzIExhenlSZXN1bHQge1xuXG4gICAgY29uc3RydWN0b3IocHJvY2Vzc29yLCBjc3MsIG9wdHMpIHtcbiAgICAgICAgdGhpcy5zdHJpbmdpZmllZCA9IGZhbHNlO1xuICAgICAgICB0aGlzLnByb2Nlc3NlZCAgID0gZmFsc2U7XG5cbiAgICAgICAgbGV0IHJvb3Q7XG4gICAgICAgIGlmICggdHlwZW9mIGNzcyA9PT0gJ29iamVjdCcgJiYgY3NzLnR5cGUgPT09ICdyb290JyApIHtcbiAgICAgICAgICAgIHJvb3QgPSBjc3M7XG4gICAgICAgIH0gZWxzZSBpZiAoIGNzcyBpbnN0YW5jZW9mIExhenlSZXN1bHQgfHwgY3NzIGluc3RhbmNlb2YgUmVzdWx0ICkge1xuICAgICAgICAgICAgcm9vdCA9IGNzcy5yb290O1xuICAgICAgICAgICAgaWYgKCBjc3MubWFwICkge1xuICAgICAgICAgICAgICAgIGlmICggdHlwZW9mIG9wdHMubWFwID09PSAndW5kZWZpbmVkJyApIG9wdHMubWFwID0geyB9O1xuICAgICAgICAgICAgICAgIGlmICggIW9wdHMubWFwLmlubGluZSApIG9wdHMubWFwLmlubGluZSA9IGZhbHNlO1xuICAgICAgICAgICAgICAgIG9wdHMubWFwLnByZXYgPSBjc3MubWFwO1xuICAgICAgICAgICAgfVxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgbGV0IHBhcnNlciA9IHBhcnNlO1xuICAgICAgICAgICAgaWYgKCBvcHRzLnN5bnRheCApICBwYXJzZXIgPSBvcHRzLnN5bnRheC5wYXJzZTtcbiAgICAgICAgICAgIGlmICggb3B0cy5wYXJzZXIgKSAgcGFyc2VyID0gb3B0cy5wYXJzZXI7XG4gICAgICAgICAgICBpZi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5sb2cocmVzdWx0LmNzcyk7XG4gICAgICogfSkuY2F0Y2goZXJyb3IgPT4ge1xuICAgICAqICAgY29uc29sZS5lcnJvcihlcnJvcik7XG4gICAgICogfSk7XG4gICAgICovXG4gICAgY2F0Y2gob25SZWplY3RlZCkge1xuICAgICAgICByZXR1cm4gdGhpcy5hc3luYygpLmNhdGNoKG9uUmVqZWN0ZWQpO1xuICAgIH1cblxuICAgIGhhbmRsZUVycm9yKGVycm9yLCBwbHVnaW4pIHtcbiAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgIHRoaXMuZXJyb3IgPSBlcnJvcjtcbiAgICAgICAgICAgIGlmICggZXJyb3IubmFtZSA9PT0gJ0Nzc1N5bnRheEVycm9yJyAmJiAhZXJyb3IucGx1Z2luICkge1xuICAgICAgICAgICAgICAgIGVycm9yLnBsdWdpbiA9IHBsdWdpbi5wb3N0Y3NzUGx1Z2luO1xuICAgICAgICAgICAgICAgIGVycm9yLnNldE1lc3NhZ2UoKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoIHBsdWdpbi5wb3N0Y3NzVmVyc2lvbiApIHtcbiAgICAgICAgICAgICAgICBsZXQgcGx1Z2luTmFtZSA9IHBsdWdpbi5wb3N0Y3NzUGx1Z2luO1xuICAgICAgICAgICAgICAgIGxldCBwbHVnaW5WZXIgID0gcGx1Z2luLnBvc3Rjc3NWZXJzaW9uO1xuICAgICAgICAgICAgICAgIGxldCBydW50aW1lVmVyID0gdGhpcy5yZXN1bHQucHJvY2Vzc29yLnZlcnNpb247XG4gICAgICAgICAgICAgICAgbGV0IGEgPSBwbHVnaW5WZXIuc3BsaXQoJy4nKTtcbiAgICAgICAgICAgICAgICBsZXQgYiA9IHJ1bnRpbWVWZXIuc3BsaXQoJy4nKTtcblxuICAgICAgICAgICAgICAgIGlmICggYVswXSAhPT0gYlswXSB8fCBwYXJzZUludChhWzFdKSA+IHBhcnNlSW50KGJbMV0pICkge1xuICAgICAgICAgICAgICAgICAgICB3YXJuT25jZSgnWW91ciBjdXJyZW50IFBvc3RDU1MgdmVyc2lvbiAnICtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ2lzICcgKyBydW50aW1lVmVyICsgJywgYnV0ICcgKyBwbHVnaW5OYW1lICsgJyAnICtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ3VzZXMgJyArIHBsdWdpblZlciArICcuIFBlcmhhcHMgdGhpcyBpcyAnICtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ3RoZSBzb3VyY2Ugb2YgdGhlIGVycm9yIGJlbG93LicpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBjYXRjaCAoZXJyKSB7XG4gICAgICAgICAgICBpZiAoIGNvbnNvbGUgJiYgY29uc29sZS5lcnJvciApIGNvbnNvbGUuZXJyb3IoZXJyKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGFzeW5jVGljayhyZXNvbHZlLCByZWplY3QpIHtcbiAgICAgICAgaWYgKCB0aGlzLnBsdWdpbiA+PSB0aGlzLnByb2Nlc3Nvci5wbHVnaW5zLmxlbmd0aCApIHtcbiAgICAgICAgICAgIHRoaXMucHJvY2Vzc2VkID0gdHJ1ZTtcbiAgICAgICAgICAgIHJldHVybiByZXNvbHZlKCk7XG4gICAgICAgIH1cblxuICAgICAgICB0cnkge1xuICAgICAgICAgICAgbGV0IHBsdWdpbiAgPSB0aGlzLnByb2Nlc3Nvci5wbHVnaW5zW3RoaXMucGx1Z2luXTtcbiAgICAgICAgICAgIGxldCBwcm9taXNlID0gdGhpcy5ydW4ocGx1Z2luKTtcbiAgICAgICAgICAgIHRoaXMucGx1Z2luICs9IDE7XG5cbiAgICAgICAgICAgIGlmICggaXNQcm9taXNlKHByb21pc2UpICkge1xuICAgICAgICAgICAgICAgIHByb21pc2UudGhlbiggKCkgPT4ge1xuICAgICAgICAgICAgICAgICAgICB0aGlzLmFzeW5jVGljayhyZXNvbHZlLCByZWplY3QpO1xuICAgICAgICAgICAgICAgIH0pLmNhdGNoKCBlcnJvciA9PiB7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMuaGFuZGxlRXJyb3IoZXJyb3IsIHBsdWdpbik7XG4gICAgICAgICAgICAgICAgICAgIHRoaXMucHJvY2Vzc2VkID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICAgICAgcmVqZWN0KGVycm9yKTtcbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgdGhpcy5hc3luY1RpY2socmVzb2x2ZSwgcmVqZWN0KTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICB9IGNhdGNoIChlcnJvcikge1xuICAgICAgICAgICAgdGhpcy5wcm9jZXNzZWQgPSB0cnVlO1xuICAgICAgICAgICAgcmVqZWN0KGVycm9yKTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGFzeW5jKCkge1xuICAgICAgICBpZiAoIHRoaXMucHJvY2Vzc2VkICkge1xuICAgICAgICAgICAgcmV0dXJuIG5ldyBQcm9taXNlKCAocmVzb2x2ZSwgcmVqZWN0KSA9PiB7XG4gICAgICAgICAgICAgICAgaWYgKCB0aGlzLmVycm9yICkge1xuICAgICAgICAgICAgICAgICAgICByZWplY3QodGhpcy5lcnJvcik7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcmVzb2x2ZSh0aGlzLnN0cmluZ2lmeSgpKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICBpZiAoIHRoaXMucHJvY2Vzc2luZyApIHtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLnByb2Nlc3Npbmc7XG4gICAgICAgIH1cblxuICAgICAgICB0aGlzLnByb2Nlc3NpbmcgPSBuZXcgUHJvbWlzZSggKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgICAgICAgaWYgKCB0aGlzLmVycm9yICkgcmV0dXJuIHJlamVjdCh0aGlzLmVycm9yKTtcbiAgICAgICAgICAgIHRoaXMucGx1Z2luID0gMDtcbiAgICAgICAgICAgIHRoaXMuYXN5bmNUaWNrKHJlc29sdmUsIHJlamVjdCk7XG4gICAgICAgIH0pLnRoZW4oICgpID0+IHtcbiAgICAgICAgICAgIHRoaXMucHJvY2Vzc2VkID0gdHJ1ZTtcbiAgICAgICAgICAgIHJldHVybiB0aGlzLnN0cmluZ2lmeSgpO1xuICAgICAgICB9KTtcblxuICAgICAgICByZXR1cm4gdGhpcy5wcm9jZXNzaW5nO1xuICAgIH1cblxuICAgIHN5bmMoKSB7XG4gICAgICAgIGlmICggdGhpcy5wcm9jZXNzZWQgKSByZXR1cm4gdGhpcy5yZXN1bHQ7XG4gICAgICAgIHRoaXMucHJvY2Vzc2VkID0gdHJ1ZTtcblxuICAgICAgICBpZiAoIHRoaXMucHJvY2Vzc2luZyApIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihcbiAgICAgICAgICAgICAgICAnVXNlIHByb2Nlc3MoY3NzKS50aGVuKGNiKSB0byB3b3JrIHdpdGggYXN5bmMgcGx1Z2lucycpO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKCB0aGlzLmVycm9yICkgdGhyb3cgdGhpcy5lcnJvcjtcblxuICAgICAgICBmb3IgKCBsZXQgcGx1Z2luIG9mIHRoaXMucmVzdWx0LnByb2Nlc3Nvci5wbHVnaW5zICkge1xuICAgICAgICAgICAgbGV0IHByb21pc2UgPSB0aGlzLnJ1bihwbHVnaW4pO1xuICAgICAgICAgICAgaWYgKCBpc1Byb21pc2UocHJvbWlzZSkgKSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKFxuICAgICAgICAgICAgICAgICAgICAnVXNlIHByb2Nlc3MoY3NzKS50aGVuKGNiKSB0byB3b3JrIHdpdGggYXN5bmMgcGx1Z2lucycpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbi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