3 exports.__esModule = true;
5 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; }; }();
7 var _supportsColor = require('supports-color');
9 var _supportsColor2 = _interopRequireDefault(_supportsColor);
11 var _warnOnce = require('./warn-once');
13 var _warnOnce2 = _interopRequireDefault(_warnOnce);
15 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19 var CssSyntaxError = function () {
20 function CssSyntaxError(message, line, column, source, file, plugin) {
21 _classCallCheck(this, CssSyntaxError);
23 this.name = 'CssSyntaxError';
25 this.reason = message;
27 if (file) this.file = file;
28 if (source) this.source = source;
29 if (plugin) this.plugin = plugin;
30 if (typeof line !== 'undefined' && typeof column !== 'undefined') {
37 if (Error.captureStackTrace) {
38 Error.captureStackTrace(this, CssSyntaxError);
42 CssSyntaxError.prototype.setMessage = function setMessage() {
43 this.message = this.plugin ? this.plugin + ': ' : '';
44 this.message += this.file ? this.file : '<css input>';
45 if (typeof this.line !== 'undefined') {
46 this.message += ':' + this.line + ':' + this.column;
48 this.message += ': ' + this.reason;
51 CssSyntaxError.prototype.showSourceCode = function showSourceCode(color) {
52 if (!this.source) return '';
54 var num = this.line - 1;
55 var lines = this.source.split('\n');
57 var prev = num > 0 ? lines[num - 1] + '\n' : '';
58 var broken = lines[num];
59 var next = num < lines.length - 1 ? '\n' + lines[num + 1] : '';
62 for (var i = 0; i < this.column - 1; i++) {
66 if (typeof color === 'undefined') color = _supportsColor2.default;
68 mark += '\x1B[1;31m^\x1B[0m';
73 return '\n' + prev + broken + mark + next;
76 CssSyntaxError.prototype.toString = function toString() {
77 return this.name + ': ' + this.message + this.showSourceCode();
80 /* istanbul ignore next */
83 _createClass(CssSyntaxError, [{
86 (0, _warnOnce2.default)('CssSyntaxError#generated is depreacted. Use input instead.');
91 return CssSyntaxError;
94 exports.default = CssSyntaxError;
95 module.exports = exports['default'];