css-syntax-error.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _picocolors = _interopRequireDefault(require("picocolors"));
  5. var _terminalHighlight = _interopRequireDefault(require("./terminal-highlight"));
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  7. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  9. function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
  10. function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
  11. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  12. function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
  13. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  15. /**
  16. * The CSS parser throws this error for broken CSS.
  17. *
  18. * Custom parsers can throw this error for broken custom syntax using
  19. * the {@link Node#error} method.
  20. *
  21. * PostCSS will use the input source map to detect the original error location.
  22. * If you wrote a Sass file, compiled it to CSS and then parsed it with PostCSS,
  23. * PostCSS will show the original position in the Sass file.
  24. *
  25. * If you need the position in the PostCSS input
  26. * (e.g., to debug the previous compiler), use `error.input.file`.
  27. *
  28. * @example
  29. * // Catching and checking syntax error
  30. * try {
  31. * postcss.parse('a{')
  32. * } catch (error) {
  33. * if (error.name === 'CssSyntaxError') {
  34. * error //=> CssSyntaxError
  35. * }
  36. * }
  37. *
  38. * @example
  39. * // Raising error from plugin
  40. * throw node.error('Unknown variable', { plugin: 'postcss-vars' })
  41. */
  42. var CssSyntaxError = /*#__PURE__*/function (_Error) {
  43. _inheritsLoose(CssSyntaxError, _Error);
  44. /**
  45. * @param {string} message Error message.
  46. * @param {number} [line] Source line of the error.
  47. * @param {number} [column] Source column of the error.
  48. * @param {string} [source] Source code of the broken file.
  49. * @param {string} [file] Absolute path to the broken file.
  50. * @param {string} [plugin] PostCSS plugin name, if error came from plugin.
  51. */
  52. function CssSyntaxError(message, line, column, source, file, plugin) {
  53. var _this;
  54. _this = _Error.call(this, message) || this;
  55. /**
  56. * Always equal to `'CssSyntaxError'`. You should always check error type
  57. * by `error.name === 'CssSyntaxError'`
  58. * instead of `error instanceof CssSyntaxError`,
  59. * because npm could have several PostCSS versions.
  60. *
  61. * @type {string}
  62. *
  63. * @example
  64. * if (error.name === 'CssSyntaxError') {
  65. * error //=> CssSyntaxError
  66. * }
  67. */
  68. _this.name = 'CssSyntaxError';
  69. /**
  70. * Error message.
  71. *
  72. * @type {string}
  73. *
  74. * @example
  75. * error.message //=> 'Unclosed block'
  76. */
  77. _this.reason = message;
  78. if (file) {
  79. /**
  80. * Absolute path to the broken file.
  81. *
  82. * @type {string}
  83. *
  84. * @example
  85. * error.file //=> 'a.sass'
  86. * error.input.file //=> 'a.css'
  87. */
  88. _this.file = file;
  89. }
  90. if (source) {
  91. /**
  92. * Source code of the broken file.
  93. *
  94. * @type {string}
  95. *
  96. * @example
  97. * error.source //=> 'a { b {} }'
  98. * error.input.column //=> 'a b { }'
  99. */
  100. _this.source = source;
  101. }
  102. if (plugin) {
  103. /**
  104. * Plugin name, if error came from plugin.
  105. *
  106. * @type {string}
  107. *
  108. * @example
  109. * error.plugin //=> 'postcss-vars'
  110. */
  111. _this.plugin = plugin;
  112. }
  113. if (typeof line !== 'undefined' && typeof column !== 'undefined') {
  114. /**
  115. * Source line of the error.
  116. *
  117. * @type {number}
  118. *
  119. * @example
  120. * error.line //=> 2
  121. * error.input.line //=> 4
  122. */
  123. _this.line = line;
  124. /**
  125. * Source column of the error.
  126. *
  127. * @type {number}
  128. *
  129. * @example
  130. * error.column //=> 1
  131. * error.input.column //=> 4
  132. */
  133. _this.column = column;
  134. }
  135. _this.setMessage();
  136. if (Error.captureStackTrace) {
  137. Error.captureStackTrace(_assertThisInitialized(_this), CssSyntaxError);
  138. }
  139. return _this;
  140. }
  141. var _proto = CssSyntaxError.prototype;
  142. _proto.setMessage = function setMessage() {
  143. /**
  144. * Full error text in the GNU error format
  145. * with plugin, file, line and column.
  146. *
  147. * @type {string}
  148. *
  149. * @example
  150. * error.message //=> 'a.css:1:1: Unclosed block'
  151. */
  152. this.message = this.plugin ? this.plugin + ': ' : '';
  153. this.message += this.file ? this.file : '<css input>';
  154. if (typeof this.line !== 'undefined') {
  155. this.message += ':' + this.line + ':' + this.column;
  156. }
  157. this.message += ': ' + this.reason;
  158. }
  159. /**
  160. * Returns a few lines of CSS source that caused the error.
  161. *
  162. * If the CSS has an input source map without `sourceContent`,
  163. * this method will return an empty string.
  164. *
  165. * @param {boolean} [color] Whether arrow will be colored red by terminal
  166. * color codes. By default, PostCSS will detect
  167. * color support by `process.stdout.isTTY`
  168. * and `process.env.NODE_DISABLE_COLORS`.
  169. *
  170. * @example
  171. * error.showSourceCode() //=> " 4 | }
  172. * // 5 | a {
  173. * // > 6 | bad
  174. * // | ^
  175. * // 7 | }
  176. * // 8 | b {"
  177. *
  178. * @return {string} Few lines of CSS source that caused the error.
  179. */
  180. ;
  181. _proto.showSourceCode = function showSourceCode(color) {
  182. var _this2 = this;
  183. if (!this.source) return '';
  184. var css = this.source;
  185. if (_terminalHighlight.default) {
  186. if (typeof color === 'undefined') color = _picocolors.default.isColorSupported;
  187. if (color) css = (0, _terminalHighlight.default)(css);
  188. }
  189. var lines = css.split(/\r?\n/);
  190. var start = Math.max(this.line - 3, 0);
  191. var end = Math.min(this.line + 2, lines.length);
  192. var maxWidth = String(end).length;
  193. function mark(text) {
  194. if (color && _picocolors.default.red) {
  195. return _picocolors.default.red(_picocolors.default.bold(text));
  196. }
  197. return text;
  198. }
  199. function aside(text) {
  200. if (color && _picocolors.default.gray) {
  201. return _picocolors.default.gray(text);
  202. }
  203. return text;
  204. }
  205. return lines.slice(start, end).map(function (line, index) {
  206. var number = start + 1 + index;
  207. var gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ';
  208. if (number === _this2.line) {
  209. var spacing = aside(gutter.replace(/\d/g, ' ')) + line.slice(0, _this2.column - 1).replace(/[^\t]/g, ' ');
  210. return mark('>') + aside(gutter) + line + '\n ' + spacing + mark('^');
  211. }
  212. return ' ' + aside(gutter) + line;
  213. }).join('\n');
  214. }
  215. /**
  216. * Returns error position, message and source code of the broken part.
  217. *
  218. * @example
  219. * error.toString() //=> "CssSyntaxError: app.css:1:1: Unclosed block
  220. * // > 1 | a {
  221. * // | ^"
  222. *
  223. * @return {string} Error position, message and source code.
  224. */
  225. ;
  226. _proto.toString = function toString() {
  227. var code = this.showSourceCode();
  228. if (code) {
  229. code = '\n\n' + code + '\n';
  230. }
  231. return this.name + ': ' + this.message + code;
  232. }
  233. /**
  234. * @memberof CssSyntaxError#
  235. * @member {Input} input Input object with PostCSS internal information
  236. * about input file. If input has source map
  237. * from previous tool, PostCSS will use origin
  238. * (for example, Sass) source. You can use this
  239. * object to get PostCSS input source.
  240. *
  241. * @example
  242. * error.input.file //=> 'a.css'
  243. * error.file //=> 'a.sass'
  244. */
  245. ;
  246. return CssSyntaxError;
  247. }( /*#__PURE__*/_wrapNativeSuper(Error));
  248. var _default = CssSyntaxError;
  249. exports.default = _default;
  250. module.exports = exports.default;
  251. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNzcy1zeW50YXgtZXJyb3IuZXM2Il0sIm5hbWVzIjpbIkNzc1N5bnRheEVycm9yIiwibWVzc2FnZSIsImxpbmUiLCJjb2x1bW4iLCJzb3VyY2UiLCJmaWxlIiwicGx1Z2luIiwibmFtZSIsInJlYXNvbiIsInNldE1lc3NhZ2UiLCJFcnJvciIsImNhcHR1cmVTdGFja1RyYWNlIiwic2hvd1NvdXJjZUNvZGUiLCJjb2xvciIsImNzcyIsInRlcm1pbmFsSGlnaGxpZ2h0IiwicGljbyIsImlzQ29sb3JTdXBwb3J0ZWQiLCJsaW5lcyIsInNwbGl0Iiwic3RhcnQiLCJNYXRoIiwibWF4IiwiZW5kIiwibWluIiwibGVuZ3RoIiwibWF4V2lkdGgiLCJTdHJpbmciLCJtYXJrIiwidGV4dCIsInJlZ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4gICAgICAgKiBlcnJvci5pbnB1dC5jb2x1bW4gLy89PiAnYSBiIHsgfSdcbiAgICAgICAqL1xuICAgICAgdGhpcy5zb3VyY2UgPSBzb3VyY2VcbiAgICB9XG4gICAgaWYgKHBsdWdpbikge1xuICAgICAgLyoqXG4gICAgICAgKiBQbHVnaW4gbmFtZSwgaWYgZXJyb3IgY2FtZSBmcm9tIHBsdWdpbi5cbiAgICAgICAqXG4gICAgICAgKiBAdHlwZSB7c3RyaW5nfVxuICAgICAgICpcbiAgICAgICAqIEBleGFtcGxlXG4gICAgICAgKiBlcnJvci5wbHVnaW4gLy89PiAncG9zdGNzcy12YXJzJ1xuICAgICAgICovXG4gICAgICB0aGlzLnBsdWdpbiA9IHBsdWdpblxuICAgIH1cbiAgICBpZiAodHlwZW9mIGxpbmUgIT09ICd1bmRlZmluZWQnICYmIHR5cGVvZiBjb2x1bW4gIT09ICd1bmRlZmluZWQnKSB7XG4gICAgICAvKipcbiAgICAgICAqIFNvdXJjZSBsaW5lIG9mIHRoZSBlcnJvci5cbiAgICAgICAqXG4gICAgICAgKiBAdHlwZSB7bnVtYmVyfVxuICAgICAgICpcbiAgICAgICAqIEBleGFtcGxlXG4gICAgICAgKiBlcnJvci5saW5lICAgICAgIC8vPT4gMlxuICAgICAgICogZXJyb3IuaW5wdXQubGluZSAvLz0+IDRcbiAgICAgICAqL1xuICAgICAgdGhpcy5saW5lID0gbGluZVxuICAgICAgLyoqXG4gICAgICAgKiBTb3VyY2UgY29sdW1uIG9mIHRoZSBlcnJvci5cbiAgICAgICAqXG4gICAgICAgKiBAdHlwZSB7bnVtYmVyfVxuICAgICAgICpcbiAgICAgICAqIEBleGFtcGxlXG4gICAgICAgKiBlcnJvci5jb2x1bW4gICAgICAgLy89PiAxXG4gICAgICAgKiBlcnJvci5pbnB1dC5jb2x1bW4gLy89PiA0XG4gICAgICAgKi9cbiAgICAgIHRoaXMuY29sdW1uID0gY29sdW1uXG4gICAgfVxuXG4gICAgdGhpcy5zZ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KlxuICAgKiBAcGFyYW0ge2Jvb2xlYW59IFtjb2xvcl0gV2hldGhlciBhcnJvdyB3aWxsIGJlIGNvbG9yZWQgcmVkIGJ5IHRlcm1pbmFsXG4gICAqICAgICAgICAgICAgICAgICAgICAgICAgICBjb2xvciBjb2Rlcy4gQnkgZGVmYXVsdCwgUG9zdENTUyB3aWxsIGRldGVjdFxuICAgKiAgICAgICAgICAgICAgICAgICAgICAgICAgY29sb3Igc3VwcG9ydCBieSBgcHJvY2Vzcy5zdGRvdXQuaXNUVFlgXG4gICAqICAgICAgICAgICAgICAgICAgICAgICAgICBhbmQgYHByb2Nlc3MuZW52Lk5PREVfRElTQUJMRV9DT0xPUlNgLlxuICAgKlxuICAgKiBAZXhhbXBsZVxuICAgKiBlcnJvci5zaG93U291cmNlQ29kZSgpIC8vPT4gXCIgIDQgfCB9XG4gICAqICAgICAgICAgICAgICAgICAgICAgICAgLy8gICAgICA1IHwgYSB7XG4gICAqICAgICAgICAgICAgICAgICAgICAgICAgLy8gICAgPiA2IHwgICBiYWRcbiAgICogICAgICAgICAgICAgICAgICAgICAgICAvLyAgICAgICAgfCAgIF5cbiAgICogICAgICAgICAgICAgICAgICAgICAgICAvLyAgICAgIDcgfCB9XG4gICAqICAgICAgICAgICAgICAgICAgICAgICAgLy8gICAgICA4IHwgYiB7XCJcbiAgICpcbiAgICogQHJldHVybiB7c3RyaW5nfSBGZXcgbGluZXMgb2YgQ1NTIHNvdXJjZSB0aGF0IGNhdXNlZCB0aGUgZXJyb3IuXG4gICAqL1xuICBzaG93U291cmNlQ29kZSAoY29sb3IpIHtcbiAgICBpZiAoIXRoaXMuc291cmNlKSByZXR1cm4gJydcblxuICAgIGxldCBjc3MgPSB0aGlzLnNvdXJjZVxuICAgIGlmICh0ZXJtaW5hbEhpZ2hsaWdodCkge1xuICAgICAgaWYgKHR5cGVvZiBjb2xvciA9PT0gJ3VuZGVmaW5lZCcpIGNvbG9yID0gcGljby5pc0NvbG9yU3VwcG9ydGVkXG4gICAgICBpZiAoY29sb3IpIGNzcyA9IHRlcm1pbmFsSGlnaGxpZ2h0KGNzcylcbiAgICB9XG5cbiAgICBsZXQgbGluZXMgPSBjc3Muc3BsaXQoL1xccj9cXG4vKVxuICAgIGxldCBzdGFydCA9IE1hdGgubWF4KHRoaXMubGluZSAtIDMsIDApXG4gICAgbGV0IGVuZCA9IE1hdGgubWluKHRoaXMubGluZSArIDIsIGxpbmVzLmxlbmd0aClcblxuICAgIGxldCBtYXhXaWR0aCA9IFN0cmluZyhlbmQpLmxlbmd0aFxuXG4gICAgZnVuY3Rpb24gbWFyayAodGV4dCkge1xuICAgICAgaWYgKGNvbG9yICYmIHBpY28ucmVkKSB7XG4gICAgICAgIHJldHVybiBwaWNvLnJlZChwaWNvLmJvbGQodGV4dCkpXG4gICAgICB9XG4gICAgICByZXR1cm4gdGV4dFxuICAgIH1cbiAgICBmdW5jdGlvbiBhc2lkZSAodGV4dCkge1xuICAgICAgaWYgKGNvbG9yICYmIHBpY28uZ3JheSkge1xuICAgICAgICByZXR1cm4gcGljby5ncmF5KHRleHQpXG4gICAgICB9XG4gICAgICByZXR1cm4gdGV4dFxuICAgIH1cblxuICAgIHJldHVybiBsaW5lc1xuICAgICAgLnNsaWNlKHN0YXJ0LCBlbmQpXG4gICAgICAubWFwKChsaW5lLCBpbmRleCkgPT4ge1xuICAgICAgICBsZXQgbnVtYmVyID0gc3RhcnQgKyAxICsgaW5kZXhcbiAgICAgICAgbGV0IGd1dHRlciA9ICcgJyArICgnICcgKyBudW1iZXIpLnNsaWNlKC1tYXhXaWR0aCkgKyAnIHwgJ1xuICAgICAgICBpZiAobnVtYmVyID09PSB0aGlzLmxpbmUpIHtcbiAgICAgICAgICBsZXQgc3BhY2luZyA9XG4gICAgICAgICAgICBhc2lkZShndXR0ZXIucmVwbGFjZSgvXFxkL2csICcgJykpICtcbiAgICAgICAgICAgIGxpbmUuc2xpY2UoMCwgdGhpcy5jb2x1bW4gLSAxKS5yZXBsYWNlKC9bXlxcdF0vZywgJyAnKVxuICAgICAgICAgIHJldHVybiBtYXJrKCc+JykgKyBhc2lkZShndXR0ZXIpICsgbGluZSArICdcXG4gJyArIHNwYWNpbmcgKyBtYXJrKCdeJylcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gJyAnICsgYXNpZGUoZ3V0dGVyKSArIGxpbmVcbiAgICAgIH0pXG4gICAgICAuam9pbignXFxuJylcbiAgfVxuXG4gIC8qKlxuICAgKiBSZXR1cm5zIGVycm9yIHBvc2l0aW9uLCBtZXNzYWdlIGFuZCBzb3VyY2UgY29kZSBvZiB0aGUgYnJva2VuIHBhcnQuXG4gICAqXG4gICAqIEBleGFtcGxlXG4gICAqIGVycm9yLnRvU3RyaW5nKCkgLy89PiBcIkNzc1N5bnRheEVycm9yOiBhcHAuY3NzOjE6MTogVW5jbG9zZWQgYmxvY2tcbiAgICogICAgICAgICAgICAgICAgICAvLyAgICA+IDEgfCBhIHtcbiAgICogICAgICAgICAgICAgICAgICAvLyAgICAgICAgfCBeXCJcbiAgICpcbiAgICogQHJldHVybiB7c3RyaW5nfSBFcnJvciBwb3NpdGlvbiwgbWVzc2FnZSBhbmQgc291cmNlIGNvZGUuXG4gICAqL1xuICB0b1N0cmluZyAoKSB7XG4gICAgbGV0IGNvZGUgPSB0aGlzLnNob3dTb3VyY2VDb2RlKClcbiAgICBpZiAoY29kZSkge1xuICAgICAgY29kZSA9ICdcXG5cXG4nICsgY29kZSArICdcXG4nXG4gICAgfVxuICAgIHJldHVybiB0aGlzLm5hbWUgKyAnOiAnICsgdGhpcy5tZXNzYWdlICsgY29kZVxuICB9XG5cbiAgLyoqXG4gICAqIEBtZW1iZXJvZiBDc3NTeW50YXhFcnJvciNcbiAgICogQG1lbWJlciB7SW5wdXR9IGlucHV0IElucHV0IG9iamVjdCB3aXRoIFBvc3RDU1MgaW50ZXJuYWwgaW5mb3JtYXRpb25cbiAgICogICAgICAgICAgICAgICAgICAgICAgIGFib3V0IGlucHV0IGZpbGUuIElmIGlucHV0IGhhcyBzb3VyY2UgbWFwXG4gICAqICAgICAgICAgICAgICAgICAgICAgICBmcm9tIHByZXZpb3VzIHRvb2wsIFBvc3RDU1Mgd2lsbCB1c2Ugb3JpZ2luXG4gICAqICAgICAgICAgICAgICAgICAgICAgICAoZm9yIGV4YW1wbGUsIFNhc3MpIHNvdXJjZS4gWW91IGNhbiB1c2UgdGhpc1xuICAgKiAgICAgICAgICAgICAgICAgICAgICAgb2JqZWN0IHRvIGdldCBQb3N0Q1NTIGlucHV0IHNvdXJjZS5cbiAgICpcbiAgICogQGV4YW1wbGVcbiAgICogZXJyb3IuaW5wdXQuZmlsZSAvLz0+ICdhLmNzcydcbiAgICogZXJyb3IuZmlsZSAgICAgICAvLz0+ICdhLnNhc3MnXG4gICAqL1xufVxuXG5leHBvcnQgZGVmYXVsdCBDc3NTeW50YXhFcnJvclxuIl0sImZpbGUiOiJjc3Mtc3ludGF4LWVycm9yLmpzIn0=