Security update for Core, with self-updated composer
[yaffs-website] / node_modules / uncss / node_modules / postcss / lib / css-syntax-error.js
1 'use strict';
2
3 exports.__esModule = true;
4
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; }; }();
6
7 var _supportsColor = require('supports-color');
8
9 var _supportsColor2 = _interopRequireDefault(_supportsColor);
10
11 var _warnOnce = require('./warn-once');
12
13 var _warnOnce2 = _interopRequireDefault(_warnOnce);
14
15 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
19 var CssSyntaxError = function () {
20     function CssSyntaxError(message, line, column, source, file, plugin) {
21         _classCallCheck(this, CssSyntaxError);
22
23         this.name = 'CssSyntaxError';
24
25         this.reason = message;
26
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') {
31             this.line = line;
32             this.column = column;
33         }
34
35         this.setMessage();
36
37         if (Error.captureStackTrace) {
38             Error.captureStackTrace(this, CssSyntaxError);
39         }
40     }
41
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;
47         }
48         this.message += ': ' + this.reason;
49     };
50
51     CssSyntaxError.prototype.showSourceCode = function showSourceCode(color) {
52         if (!this.source) return '';
53
54         var num = this.line - 1;
55         var lines = this.source.split('\n');
56
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] : '';
60
61         var mark = '\n';
62         for (var i = 0; i < this.column - 1; i++) {
63             mark += ' ';
64         }
65
66         if (typeof color === 'undefined') color = _supportsColor2.default;
67         if (color) {
68             mark += '\x1B[1;31m^\x1B[0m';
69         } else {
70             mark += '^';
71         }
72
73         return '\n' + prev + broken + mark + next;
74     };
75
76     CssSyntaxError.prototype.toString = function toString() {
77         return this.name + ': ' + this.message + this.showSourceCode();
78     };
79
80     /* istanbul ignore next */
81
82
83     _createClass(CssSyntaxError, [{
84         key: 'generated',
85         get: function get() {
86             (0, _warnOnce2.default)('CssSyntaxError#generated is depreacted. Use input instead.');
87             return this.input;
88         }
89     }]);
90
91     return CssSyntaxError;
92 }();
93
94 exports.default = CssSyntaxError;
95 module.exports = exports['default'];