123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- "use strict";
- exports.__esModule = true;
- exports.default = void 0;
- var _path = _interopRequireDefault(require("path"));
- var _cssSyntaxError = _interopRequireDefault(require("./css-syntax-error"));
- var _previousMap = _interopRequireDefault(require("./previous-map"));
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- 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); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var sequence = 0;
- var Input = function () {
-
- function Input(css, opts) {
- if (opts === void 0) {
- opts = {};
- }
- if (css === null || typeof css === '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.hasBOM = true;
- this.css = this.css.slice(1);
- } else {
- this.hasBOM = false;
- }
- if (opts.from) {
- if (/^\w+:\/\//.test(opts.from) || _path.default.isAbsolute(opts.from)) {
-
- this.file = opts.from;
- } else {
- this.file = _path.default.resolve(opts.from);
- }
- }
- var map = new _previousMap.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;
- }
- var _proto = Input.prototype;
- _proto.error = function error(message, line, column, opts) {
- if (opts === void 0) {
- opts = {};
- }
- var result;
- var origin = this.origin(line, column);
- if (origin) {
- result = new _cssSyntaxError.default(message, origin.line, origin.column, origin.source, origin.file, opts.plugin);
- } else {
- result = new _cssSyntaxError.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;
- }
-
- ;
- _proto.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;
- };
- _proto.mapResolve = function mapResolve(file) {
- if (/^\w+:\/\//.test(file)) {
- return file;
- }
- return _path.default.resolve(this.map.consumer().sourceRoot || '.', file);
- }
-
- ;
- _createClass(Input, [{
- key: "from",
- get: function get() {
- return this.file || this.id;
- }
- }]);
- return Input;
- }();
- var _default = Input;
- exports.default = _default;
- module.exports = exports.default;
|