123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- 'use strict';
- exports.__esModule = true;
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
- 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; }; }();
- var _cssSyntaxError = require('./css-syntax-error');
- var _cssSyntaxError2 = _interopRequireDefault(_cssSyntaxError);
- var _previousMap = require('./previous-map');
- var _previousMap2 = _interopRequireDefault(_previousMap);
- var _path = require('path');
- var _path2 = _interopRequireDefault(_path);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- var sequence = 0;
- var Input = function () {
-
- function Input(css) {
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- _classCallCheck(this, Input);
- if (css === null || (typeof css === 'undefined' ? 'undefined' : _typeof(css)) === 'object' && !css.toString) {
- throw new Error('PostCSS received ' + css + ' instead of CSS string');
- }
-
- this.css = css.toString();
- if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
- this.css = this.css.slice(1);
- }
- if (opts.from) {
- if (/^\w+:\/\//.test(opts.from)) {
-
- this.file = opts.from;
- } else {
- this.file = _path2.default.resolve(opts.from);
- }
- }
- var map = new _previousMap2.default(this.css, opts);
- if (map.text) {
-
- this.map = map;
- var file = map.consumer().file;
- if (!this.file && file) this.file = this.mapResolve(file);
- }
- if (!this.file) {
- sequence += 1;
-
- this.id = '<input css ' + sequence + '>';
- }
- if (this.map) this.map.file = this.from;
- }
- Input.prototype.error = function error(message, line, column) {
- var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
- var result = void 0;
- var origin = this.origin(line, column);
- if (origin) {
- result = new _cssSyntaxError2.default(message, origin.line, origin.column, origin.source, origin.file, opts.plugin);
- } else {
- result = new _cssSyntaxError2.default(message, line, column, this.css, this.file, opts.plugin);
- }
- result.input = { line: line, column: column, source: this.css };
- if (this.file) result.input.file = this.file;
- return result;
- };
-
- Input.prototype.origin = function origin(line, column) {
- if (!this.map) return false;
- var consumer = this.map.consumer();
- var from = consumer.originalPositionFor({ line: line, column: column });
- if (!from.source) return false;
- var result = {
- file: this.mapResolve(from.source),
- line: from.line,
- column: from.column
- };
- var source = consumer.sourceContentFor(from.source);
- if (source) result.source = source;
- return result;
- };
- Input.prototype.mapResolve = function mapResolve(file) {
- if (/^\w+:\/\//.test(file)) {
- return file;
- } else {
- return _path2.default.resolve(this.map.consumer().sourceRoot || '.', file);
- }
- };
-
- _createClass(Input, [{
- key: 'from',
- get: function get() {
- return this.file || this.id;
- }
- }]);
- return Input;
- }();
- exports.default = Input;
- module.exports = exports['default'];
|