123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- "use strict";
- exports.__esModule = true;
- exports.default = void 0;
- var _picocolors = _interopRequireDefault(require("picocolors"));
- var _terminalHighlight = _interopRequireDefault(require("./terminal-highlight"));
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
- 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); }
- 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); }
- 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; } }
- function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
- var CssSyntaxError = function (_Error) {
- _inheritsLoose(CssSyntaxError, _Error);
-
- function CssSyntaxError(message, line, column, source, file, plugin) {
- var _this;
- _this = _Error.call(this, message) || this;
-
- _this.name = 'CssSyntaxError';
-
- _this.reason = message;
- if (file) {
-
- _this.file = file;
- }
- if (source) {
-
- _this.source = source;
- }
- if (plugin) {
-
- _this.plugin = plugin;
- }
- if (typeof line !== 'undefined' && typeof column !== 'undefined') {
-
- _this.line = line;
-
- _this.column = column;
- }
- _this.setMessage();
- if (Error.captureStackTrace) {
- Error.captureStackTrace(_assertThisInitialized(_this), CssSyntaxError);
- }
- return _this;
- }
- var _proto = CssSyntaxError.prototype;
- _proto.setMessage = function setMessage() {
-
- this.message = this.plugin ? this.plugin + ': ' : '';
- this.message += this.file ? this.file : '<css input>';
- if (typeof this.line !== 'undefined') {
- this.message += ':' + this.line + ':' + this.column;
- }
- this.message += ': ' + this.reason;
- }
-
- ;
- _proto.showSourceCode = function showSourceCode(color) {
- var _this2 = this;
- if (!this.source) return '';
- var css = this.source;
- if (_terminalHighlight.default) {
- if (typeof color === 'undefined') color = _picocolors.default.isColorSupported;
- if (color) css = (0, _terminalHighlight.default)(css);
- }
- var lines = css.split(/\r?\n/);
- var start = Math.max(this.line - 3, 0);
- var end = Math.min(this.line + 2, lines.length);
- var maxWidth = String(end).length;
- function mark(text) {
- if (color && _picocolors.default.red) {
- return _picocolors.default.red(_picocolors.default.bold(text));
- }
- return text;
- }
- function aside(text) {
- if (color && _picocolors.default.gray) {
- return _picocolors.default.gray(text);
- }
- return text;
- }
- return lines.slice(start, end).map(function (line, index) {
- var number = start + 1 + index;
- var gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ';
- if (number === _this2.line) {
- var spacing = aside(gutter.replace(/\d/g, ' ')) + line.slice(0, _this2.column - 1).replace(/[^\t]/g, ' ');
- return mark('>') + aside(gutter) + line + '\n ' + spacing + mark('^');
- }
- return ' ' + aside(gutter) + line;
- }).join('\n');
- }
-
- ;
- _proto.toString = function toString() {
- var code = this.showSourceCode();
- if (code) {
- code = '\n\n' + code + '\n';
- }
- return this.name + ': ' + this.message + code;
- }
-
- ;
- return CssSyntaxError;
- }( _wrapNativeSuper(Error));
- var _default = CssSyntaxError;
- exports.default = _default;
- module.exports = exports.default;
|