css-syntax-error.js 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _supportsColor = require('supports-color');
  4. var _supportsColor2 = _interopRequireDefault(_supportsColor);
  5. var _chalk = require('chalk');
  6. var _chalk2 = _interopRequireDefault(_chalk);
  7. var _terminalHighlight = require('./terminal-highlight');
  8. var _terminalHighlight2 = _interopRequireDefault(_terminalHighlight);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11. /**
  12. * The CSS parser throws this error for broken CSS.
  13. *
  14. * Custom parsers can throw this error for broken custom syntax using
  15. * the {@link Node#error} method.
  16. *
  17. * PostCSS will use the input source map to detect the original error location.
  18. * If you wrote a Sass file, compiled it to CSS and then parsed it with PostCSS,
  19. * PostCSS will show the original position in the Sass file.
  20. *
  21. * If you need the position in the PostCSS input
  22. * (e.g., to debug the previous compiler), use `error.input.file`.
  23. *
  24. * @example
  25. * // Catching and checking syntax error
  26. * try {
  27. * postcss.parse('a{')
  28. * } catch (error) {
  29. * if ( error.name === 'CssSyntaxError' ) {
  30. * error //=> CssSyntaxError
  31. * }
  32. * }
  33. *
  34. * @example
  35. * // Raising error from plugin
  36. * throw node.error('Unknown variable', { plugin: 'postcss-vars' });
  37. */
  38. var CssSyntaxError = function () {
  39. /**
  40. * @param {string} message - error message
  41. * @param {number} [line] - source line of the error
  42. * @param {number} [column] - source column of the error
  43. * @param {string} [source] - source code of the broken file
  44. * @param {string} [file] - absolute path to the broken file
  45. * @param {string} [plugin] - PostCSS plugin name, if error came from plugin
  46. */
  47. function CssSyntaxError(message, line, column, source, file, plugin) {
  48. _classCallCheck(this, CssSyntaxError);
  49. /**
  50. * @member {string} - Always equal to `'CssSyntaxError'`. You should
  51. * always check error type
  52. * by `error.name === 'CssSyntaxError'` instead of
  53. * `error instanceof CssSyntaxError`, because
  54. * npm could have several PostCSS versions.
  55. *
  56. * @example
  57. * if ( error.name === 'CssSyntaxError' ) {
  58. * error //=> CssSyntaxError
  59. * }
  60. */
  61. this.name = 'CssSyntaxError';
  62. /**
  63. * @member {string} - Error message.
  64. *
  65. * @example
  66. * error.message //=> 'Unclosed block'
  67. */
  68. this.reason = message;
  69. if (file) {
  70. /**
  71. * @member {string} - Absolute path to the broken file.
  72. *
  73. * @example
  74. * error.file //=> 'a.sass'
  75. * error.input.file //=> 'a.css'
  76. */
  77. this.file = file;
  78. }
  79. if (source) {
  80. /**
  81. * @member {string} - Source code of the broken file.
  82. *
  83. * @example
  84. * error.source //=> 'a { b {} }'
  85. * error.input.column //=> 'a b { }'
  86. */
  87. this.source = source;
  88. }
  89. if (plugin) {
  90. /**
  91. * @member {string} - Plugin name, if error came from plugin.
  92. *
  93. * @example
  94. * error.plugin //=> 'postcss-vars'
  95. */
  96. this.plugin = plugin;
  97. }
  98. if (typeof line !== 'undefined' && typeof column !== 'undefined') {
  99. /**
  100. * @member {number} - Source line of the error.
  101. *
  102. * @example
  103. * error.line //=> 2
  104. * error.input.line //=> 4
  105. */
  106. this.line = line;
  107. /**
  108. * @member {number} - Source column of the error.
  109. *
  110. * @example
  111. * error.column //=> 1
  112. * error.input.column //=> 4
  113. */
  114. this.column = column;
  115. }
  116. this.setMessage();
  117. if (Error.captureStackTrace) {
  118. Error.captureStackTrace(this, CssSyntaxError);
  119. }
  120. }
  121. CssSyntaxError.prototype.setMessage = function setMessage() {
  122. /**
  123. * @member {string} - Full error text in the GNU error format
  124. * with plugin, file, line and column.
  125. *
  126. * @example
  127. * error.message //=> 'a.css:1:1: Unclosed block'
  128. */
  129. this.message = this.plugin ? this.plugin + ': ' : '';
  130. this.message += this.file ? this.file : '<css input>';
  131. if (typeof this.line !== 'undefined') {
  132. this.message += ':' + this.line + ':' + this.column;
  133. }
  134. this.message += ': ' + this.reason;
  135. };
  136. /**
  137. * Returns a few lines of CSS source that caused the error.
  138. *
  139. * If the CSS has an input source map without `sourceContent`,
  140. * this method will return an empty string.
  141. *
  142. * @param {boolean} [color] whether arrow will be colored red by terminal
  143. * color codes. By default, PostCSS will detect
  144. * color support by `process.stdout.isTTY`
  145. * and `process.env.NODE_DISABLE_COLORS`.
  146. *
  147. * @example
  148. * error.showSourceCode() //=> " 4 | }
  149. * // 5 | a {
  150. * // > 6 | bad
  151. * // | ^
  152. * // 7 | }
  153. * // 8 | b {"
  154. *
  155. * @return {string} few lines of CSS source that caused the error
  156. */
  157. CssSyntaxError.prototype.showSourceCode = function showSourceCode(color) {
  158. var _this = this;
  159. if (!this.source) return '';
  160. var css = this.source;
  161. if (typeof color === 'undefined') color = _supportsColor2.default.stdout;
  162. if (color) css = (0, _terminalHighlight2.default)(css);
  163. var lines = css.split(/\r?\n/);
  164. var start = Math.max(this.line - 3, 0);
  165. var end = Math.min(this.line + 2, lines.length);
  166. var maxWidth = String(end).length;
  167. function mark(text) {
  168. if (color && _chalk2.default.red) {
  169. return _chalk2.default.red.bold(text);
  170. } else {
  171. return text;
  172. }
  173. }
  174. function aside(text) {
  175. if (color && _chalk2.default.gray) {
  176. return _chalk2.default.gray(text);
  177. } else {
  178. return text;
  179. }
  180. }
  181. return lines.slice(start, end).map(function (line, index) {
  182. var number = start + 1 + index;
  183. var gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ';
  184. if (number === _this.line) {
  185. var spacing = aside(gutter.replace(/\d/g, ' ')) + line.slice(0, _this.column - 1).replace(/[^\t]/g, ' ');
  186. return mark('>') + aside(gutter) + line + '\n ' + spacing + mark('^');
  187. } else {
  188. return ' ' + aside(gutter) + line;
  189. }
  190. }).join('\n');
  191. };
  192. /**
  193. * Returns error position, message and source code of the broken part.
  194. *
  195. * @example
  196. * error.toString() //=> "CssSyntaxError: app.css:1:1: Unclosed block
  197. * // > 1 | a {
  198. * // | ^"
  199. *
  200. * @return {string} error position, message and source code
  201. */
  202. CssSyntaxError.prototype.toString = function toString() {
  203. var code = this.showSourceCode();
  204. if (code) {
  205. code = '\n\n' + code + '\n';
  206. }
  207. return this.name + ': ' + this.message + code;
  208. };
  209. /**
  210. * @memberof CssSyntaxError#
  211. * @member {Input} input - Input object with PostCSS internal information
  212. * about input file. If input has source map
  213. * from previous tool, PostCSS will use origin
  214. * (for example, Sass) source. You can use this
  215. * object to get PostCSS input source.
  216. *
  217. * @example
  218. * error.input.file //=> 'a.css'
  219. * error.file //=> 'a.sass'
  220. */
  221. return CssSyntaxError;
  222. }();
  223. exports.default = CssSyntaxError;
  224. module.exports = exports['default'];
  225. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNzcy1zeW50YXgtZXJyb3IuZXM2Il0sIm5hbWVzIjpbIkNzc1N5bnRheEVycm9yIiwibWVzc2FnZSIsImxpbmUiLCJjb2x1bW4iLCJzb3VyY2UiLCJmaWxlIiwicGx1Z2luIiwibmFtZSIsInJlYXNvbiIsInNldE1lc3NhZ2UiLCJFcnJvciIsImNhcHR1cmVTdGFja1RyYWNlIiwic2hvd1NvdXJjZUNvZGUiLCJjb2xvciIsImNzcyIsInN1cHBvcnRzQ29sb3IiLCJzdGRvdXQiLCJsaW5lcyIsInNwbGl0Iiwic3RhcnQiLCJNYXRoIiwibWF4IiwiZW5kIiwibWluIiwibGVuZ3RoIiwibWF4V2lkdGgiLCJTdHJpbmciLCJtYXJrIiwidGV4dCIsImNoYWxrIiwicmVkIiwiYm9sZCIsImFzaWRlIiwiZ3JheSIsInNsaWNlIiwibWFwIiwiaW5kZXgiLCJudW1iZXIiLCJndXR0ZXIiLCJzcGF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RXJyb3InICkge1xuICAgICAgICAgKiAgIGVycm9yIC8vPT4gQ3NzU3ludGF4RXJyb3JcbiAgICAgICAgICogfVxuICAgICAgICAgKi9cbiAgICAgICAgdGhpcy5uYW1lID0gJ0Nzc1N5bnRheEVycm9yJztcbiAgICAgICAgLyoqXG4gICAgICAgICAqIEBtZW1iZXIge3N0cmluZ30gLSBFcnJvciBtZXNzYWdlLlxuICAgICAgICAgKlxuICAgICAgICAgKiBAZXhhbXBsZVxuICAgICAgICAgKiBlcnJvci5tZXNzYWdlIC8vPT4gJ1VuY2xvc2VkIGJsb2NrJ1xuICAgICAgICAgKi9cbiAgICAgICAgdGhpcy5yZWFzb24gPSBtZXNzYWdlO1xuXG4gICAgICAgIGlmICggZmlsZSApIHtcbiAgICAgICAgICAgIC8qKlxuICAgICAgICAgICAgICogQG1lbWJlciB7c3RyaW5nfSAtIEFic29sdXRlIHBhdGggdG8gdGhlIGJyb2tlbiBmaWxlLlxuICAgICAgICAgICAgICpcbiAgICAgICAgICAgICAqIEBleGFtcGxlXG4gICAgICAgICAgICAgKiBlcnJvci5maWxlICAgICAgIC8vPT4gJ2Euc2FzcydcbiAgICAgICAgICAgICAqIGVycm9yLmlucHV0LmZpbGUgLy89PiAnYS5jc3MnXG4gICAgICAgICAgICAgKi9cbiAgICAgICAgICAgIHRoaXMuZmlsZSA9IGZpbGU7XG4gICAgICAgIH1cbiAgICAgICAgaWYgKCBzb3VyY2UgKSB7XG4gICAgICAgICAgICAvKipcbiAgICAgICAgICAgICAqIEBtZW1iZXIge3N0cmluZ30gLSBTb3VyY2UgY29kZSBvZiB0aGUgYnJva2VuIGZpbGUuXG4gICAgICAgICAgICAgKlxuICAgICAgICAgICAgICogQGV4YW1wbGVcbiAgICAgICAgICAgICAqIGVycm9yLnNvdXJjZSAgICAgICAvLz0+ICdhIHsgYiB7fSB9J1xuICAgICAgICAgICAgICogZXJyb3IuaW5wdXQuY29sdW1uIC8vPT4gJ2EgYiB7IH0nXG4gICAgICAgICAgICAgKi9cbiAgICAgICAgICAgIHRoaXMuc291cmNlID0gc291cmNlO1xuICAgICAgICB9XG4gICAgICAgIGlmICggcGx1Z2luICkge1xuICAgICAgICAgICAgLyoqXG4gICAgICAgICAgICAgKiBAbWVtYmVyIHtzdHJpbmd9IC0gUGx1Z2luIG5hbWUsIGlmIGVycm9yIGNhbWUgZnJvbSBwbHVnaW4uXG4gICAgICAgICAgICAgKlxuICAgICAgICAgICAgICogQGV4YW1wbGVcbiAgICAgICAgICAgICAqIGVycm9yLnBsdWdpbiAvLz0+ICdwb3N0Y3NzLXZhcnMnXG4gICAgICAgICAgICAgKi9cbiAgICAgICAgICAgIHRoaXMucGx1Z2luID0gcGx1Z2luO1xuICAgICAgICB9XG4gICAgICAgIGlmICggdHlwZW9mIGxpbmUgIT09ICd1bmRlZmluZWQnICYmIHR5cGVvZiBjb2x1bW4gIT09ICd1bmRlZmluZWQnICkge1xuICAgICAgICAgICAgLyoqXG4gICAgICAgICAgICAgKiBAbWVtYmVyIHtudW1iZXJ9IC0gU291cmNlIGxpbmUgb2YgdGhlIGVycm9yLlxuICAgICAgICAgICAgICpcbiAgICAgICAgICAgICAqIEBleGFtcGxlXG4gICAgICAgICAgICAgKiBlcnJvci5saW5lICAgICAgIC8vPT4gMlxuICAgICAgICAgICAgICogZXJyb3IuaW5wdXQubGluZSAvLz0+IDRcbiAgICAgICAgICAgICAqL1xuICAgICAgICAgICAgdGhpcy5saW5lICAgPSBsaW5lO1xuICAgICAgICAgICAgLyoqXG4gICAgICAgICAgICAgKiBAbWVtYmVyIHtudW1iZXJ9IC0gU291cmNlIGNvbHVtbiBvZiB0aGUgZXJyb3IuXG4gICAgICAgICAgICAgKlxuICAgICAgICAgICAgICogQGV4YW1wbGVcbiAgICAgICAgICAgICAqIGVycm9yLmNvbHVtbiAgICAgICAvLz0+IDFcbiAgICAgICAgICAgICAqIGVycm9yLmlucHV0LmNvbHVtbiAvLz0+IDRcbiAgICAgICAgICAgICAqL1xuICAgICAgICAgICAgdGhpcy5jb2x1bW4gPSBjb2x1bW47XG4gICAgICAgIH1cblxuICAgICAgICB0aGlzLnNldE1lc3NhZ2UoKTtcblxuICAgICAgICBpZiAoIEVycm9yLmNhcHR1cmVTdGFja1RyYWNlICkge1xuICAgICAgICAgICAgRXJyb3IuY2FwdHVyZVN0YWNrVHJhY2UodGhpcywgQ3NzU3ludGF4RXJyb3IpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgc2V0TWVzc2FnZSgpIHtcbiAgICAgICAgLyoqXG4gICAgICAgICAqIEBtZW1iZXIge3N0cmluZ30gLSBGdWxsIGVycm9yIHRleHQgaW4gdGhlIEdOVSBlcnJvciBmb3JtYXRcbiAgICAgICAgICogICAgICAgICAgICAgICAgICAgIHdpdGggcGx1Z2luLCBmaWxlLCBsaW5lIGFuZCBjb2x1bW4uXG4gICAgICAgICAqXG4gICAgICAgICAqIEBleGFtcGxlXG4gICAgICAgICAqIGVycm9yLm1lc3NhZ2UgLy89PiAnYS5jc3M6MToxOiBVbmNsb3NlZCBibG9jaydcbiAgICAgICAgICovXG4gICAgICAgIHRoaXMubWVzc2FnZSAgPSB0aGlzLnBsdWdpbiA/IHRoaXMucGx1Z2luICsgJzogJyA6ICcnO1xuICAgICAgICB0aGlzLm1lc3NhZ2UgKz0gdGhpcy5maWxlID8gdGhpcy5maWxlIDogJzxjc3MgaW5wdXQ+JztcbiAgICAgICAgaWYgKCB0eXBlb2YgdGhpcy5saW5lICE9PSAndW5kZWZpbmVkJyApIHtcbiAgICAgICAgICAgIHRoaXMubWVzc2FnZSArPSAnOicgKyB0aGlzLmxpbmUgKyAnOicgKyB0aGlzLmNvbHVtbjtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLm1lc3NhZ2UgKz0gJzogJyArIHRoaXMucmVhc29uO1xuICAgIH1cblxuICAgIC8qKlxuICAgICAqIFJldHVybnMgYSBmZXcgbGluZXMgb2YgQ1NTIHNvdXJjZSB0aGF0IGNhdXNlZCB0aGUgZXJyb3IuXG4gICAgICpcbiAgICAgKiBJZiB0aGUgQ1NTIGhhcyBhbiBpbnB1dCBzb3VyY2UgbWFwIHdpdGhvdXQgYHNvdXJjZUNvbnRlbnRgLFxuICAgICAqIHRoaXMgbWV0aG9kIHdpbGwgcmV0dXJuIGFuIGVtcHR5IHN0cmluZy5cbiAgICAgKlxuICAgICAqIEBwYXJhbSB7Ym9vbGVhbn0gW2NvbG9yXSB3aGV0aGVyIGFycm93IHdpbGwgYmUgY29sb3JlZCByZWQgYnkgdGVybWluYWxcbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgY29sb3IgY29kZXMuIEJ5IGRlZmF1bHQsIFBvc3RDU1Mgd2lsbCBkZXRlY3RcbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgY29sb3Igc3VwcG9ydCBieSBgcHJvY2Vzcy5zdGRvdXQuaXNUVFlgXG4gICAgICogICAgICAgICAgICAgICAgICAgICAgICAgIGFuZCBgcHJvY2Vzcy5lbnYuTk9ERV9ESVNBQkxFX0NPTE9SU2AuXG4gICAgICpcbiAgICAgKiBAZXhhbXBsZVxuICAgICAqIGVycm9yLnNob3dTb3VyY2VDb2RlKCkgLy89PiBcIiAgNCB8IH1cbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgIC8vICAgICAgNSB8IGEge1xuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgLy8gICAgPiA2IHwgICBiYWRcbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgIC8vICAgICAgICB8ICAgXlxuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgLy8gICAgICA3IHwgfVxuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgLy8gICAgICA4IHwgYiB7XCJcbiAgICAgKlxuICAgICAqIEByZXR1cm4ge3N0cmluZ30gZmV3IGxpbmVzIG9mIENTUyBzb3VyY2UgdGhhdCBjYXVzZWQgdGhlIGVycm9yXG4gICAgICovXG4gICAgc2hvd1NvdXJjZUNvZGUoY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hcCggKGxpbmUsIGluZGV4KSA9PiB7XG4gICAgICAgICAgICBsZXQgbnVtYmVyID0gc3RhcnQgKyAxICsgaW5kZXg7XG4gICAgICAgICAgICBsZXQgZ3V0dGVyID0gJyAnICsgKCcgJyArIG51bWJlcikuc2xpY2UoLW1heFdpZHRoKSArICcgfCAnO1xuICAgICAgICAgICAgaWYgKCBudW1iZXIgPT09IHRoaXMubGluZSApIHtcbiAgICAgICAgICAgICAgICBsZXQgc3BhY2luZyA9XG4gICAgICAgICAgICAgICAgICAgIGFzaWRlKGd1dHRlci5yZXBsYWNlKC9cXGQvZywgJyAnKSkgK1xuICAgICAgICAgICAgICAgICAgICBsaW5lLnNsaWNlKDAsIHRoaXMuY29sdW1uIC0gMSkucmVwbGFjZSgvW15cXHRdL2csICcgJyk7XG4gICAgICAgICAgICAgICAgcmV0dXJuIG1hcmsoJz4nKSArIGFzaWRlKGd1dHRlcikgKyBsaW5lICsgJ1xcbiAnICtcbiAgICAgICAgICAgICAgICAgICAgICAgc3BhY2luZyArIG1hcmsoJ14nKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuICcgJyArIGFzaWRlKGd1dHRlcikgKyBsaW5lO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KS5qb2luKCdcXG4nKTtcbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBSZXR1cm5zIGVycm9yIHBvc2l0aW9uLCBtZXNzYWdlIGFuZCBzb3VyY2UgY29kZSBvZiB0aGUgYnJva2VuIHBhcnQuXG4gICAgICpcbiAgICAgKiBAZXhhbXBsZVxuICAgICAqIGVycm9yLnRvU3RyaW5nKCkgLy89PiBcIkNzc1N5bnRheEVycm9yOiBhcHAuY3NzOjE6MTogVW5jbG9zZWQgYmxvY2tcbiAgICAgKiAgICAgICAgICAgICAgICAgIC8vICAgID4gMSB8IGEge1xuICAgICAqICAgICAgICAgICAgICAgICAgLy8gICAgICAgIHwgXlwiXG4gICAgICpcbiAgICAgKiBAcmV0dXJuIHtzdHJpbmd9IGVycm9yIHBvc2l0aW9uLCBtZXNzYWdlIGFuZCBzb3VyY2UgY29kZVxuICAgICAqL1xuICAgIHRvU3RyaW5nKCkge1xuICAgICAgICBsZXQgY29kZSA9IHRoaXMuc2hvd1NvdXJjZUNvZGUoKTtcbiAgICAgICAgaWYgKCBjb2RlICkge1xuICAgICAgICAgICAgY29kZSA9ICdcXG5cXG4nICsgY29kZSArICdcXG4nO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiB0aGlzLm5hbWUgKyAnOiAnICsgdGhpcy5tZXNzYWdlICsgY29kZTtcbiAgICB9XG5cbiAgICAvKipcbiAgICAgKiBAbWVtYmVyb2YgQ3NzU3ludGF4RXJyb3IjXG4gICAgICogQG1lbWJlciB7SW5wdXR9IGlucHV0IC0gSW5wdXQgb2JqZWN0IHdpdGggUG9zdENTUyBpbnRlcm5hbCBpbmZvcm1hdGlvblxuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgIGFib3V0IGlucHV0IGZpbGUuIElmIGlucHV0IGhhcyBzb3VyY2UgbWFwXG4gICAgICogICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSBwcmV2aW91cyB0b29sLCBQb3N0Q1NTIHdpbGwgdXNlIG9yaWdpblxuICAgICAqICAgICAgICAgICAgICAgICAgICAgICAgIChmb3IgZXhhbXBsZSwgU2Fzcykgc291cmNlLiBZb3UgY2FuIHVzZSB0aGlzXG4gICAgICogICAgICAgICAgICAgICAgICAgICAgICAgb2JqZWN0IHRvIGdldCBQb3N0Q1NTIGlucHV0IHNvdXJjZS5cbiAgICAgKlxuICAgICAqIEBleGFtcGxlXG4gICAgICogZXJyb3IuaW5wdXQuZmlsZSAvLz0+ICdhLmNzcydcbiAgICAgKiBlcnJvci5maWxlICAgICAgIC8vPT4gJ2Euc2FzcydcbiAgICAgKi9cblxufVxuXG5leHBvcnQgZGVmYXVsdCBDc3NTeW50YXhFcnJvcjtcbiJdfQ==