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 _cssSyntaxError = require('./css-syntax-error');
9 var _cssSyntaxError2 = _interopRequireDefault(_cssSyntaxError);
11 var _previousMap = require('./previous-map');
13 var _previousMap2 = _interopRequireDefault(_previousMap);
15 var _path = require('path');
17 var _path2 = _interopRequireDefault(_path);
19 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
25 var Input = function () {
27 var opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
29 _classCallCheck(this, Input);
31 this.css = css.toString();
33 if (this.css[0] === '' || this.css[0] === '') {
34 this.css = this.css.slice(1);
37 if (opts.from) this.file = _path2.default.resolve(opts.from);
39 var map = new _previousMap2.default(this.css, opts);
42 var file = map.consumer().file;
43 if (!this.file && file) this.file = this.mapResolve(file);
48 this.id = '<input css ' + sequence + '>';
50 if (this.map) this.map.file = this.from;
53 Input.prototype.error = function error(message, line, column) {
54 var opts = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
57 var origin = this.origin(line, column);
59 result = new _cssSyntaxError2.default(message, origin.line, origin.column, origin.source, origin.file, opts.plugin);
61 result = new _cssSyntaxError2.default(message, line, column, this.css, this.file, opts.plugin);
64 result.input = { line: line, column: column, source: this.css };
65 if (this.file) result.input.file = this.file;
70 Input.prototype.origin = function origin(line, column) {
71 if (!this.map) return false;
72 var consumer = this.map.consumer();
74 var from = consumer.originalPositionFor({ line: line, column: column });
75 if (!from.source) return false;
78 file: this.mapResolve(from.source),
83 var source = consumer.sourceContentFor(from.source);
84 if (source) result.source = source;
89 Input.prototype.mapResolve = function mapResolve(file) {
90 return _path2.default.resolve(this.map.consumer().sourceRoot || '.', file);
93 _createClass(Input, [{
96 return this.file || this.id;
103 exports.default = Input;
104 module.exports = exports['default'];