biobulkbende.org/node_modules/postcss/lib/input.js

217 lines
17 KiB
JavaScript
Raw Normal View History

2020-09-16 12:23:28 +00:00
"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;
/**
* Represents the source CSS.
*
* @example
* const root = postcss.parse(css, { from: file })
* const input = root.source.input
*/
var Input =
/*#__PURE__*/
function () {
/**
* @param {string} css Input CSS source.
* @param {object} [opts] {@link Processor#process} options.
*/
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");
}
/**
* Input CSS source
*
* @type {string}
*
* @example
* const input = postcss.parse('a{}', { from: file }).input
* input.css //=> "a{}"
*/
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)) {
/**
* The absolute path to the CSS source file defined
* with the `from` option.
*
* @type {string}
*
* @example
* const root = postcss.parse(css, { from: 'a.css' })
* root.source.input.file //=> '/home/ai/a.css'
*/
this.file = opts.from;
} else {
this.file = _path.default.resolve(opts.from);
}
}
var map = new _previousMap.default(this.css, opts);
if (map.text) {
/**
* The input source map passed from a compilation step before PostCSS
* (for example, from Sass compiler).
*
* @type {PreviousMap}
*
* @example
* root.source.input.map.consumer().sources //=> ['a.sass']
*/
this.map = map;
var file = map.consumer().file;
if (!this.file && file) this.file = this.mapResolve(file);
}
if (!this.file) {
sequence += 1;
/**
* The unique ID of the CSS source. It will be created if `from` option
* is not provided (because PostCSS does not know the file path).
*
* @type {string}
*
* @example
* const root = postcss.parse(css)
* root.source.input.file //=> undefined
* root.source.input.id //=> "<input css 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;
}
/**
* Reads the input source map and returns a symbol position
* in the input source (e.g., in a Sass file that was compiled
* to CSS before being passed to PostCSS).
*
* @param {number} line Line in input CSS.
* @param {number} column Column in input CSS.
*
* @return {filePosition} Position in input source.
*
* @example
* root.source.input.origin(1, 1) //=> { file: 'a.css', line: 3, column: 1 }
*/
;
_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);
}
/**
* The CSS source identifier. Contains {@link Input#file} if the user
* set the `from` option, or {@link Input#id} if they did not.
*
* @type {string}
*
* @example
* const root = postcss.parse(css, { from: 'a.css' })
* root.source.input.from //=> "/home/ai/a.css"
*
* const root = postcss.parse(css)
* root.source.input.from //=> "<input css 1>"
*/
;
_createClass(Input, [{
key: "from",
get: function get() {
return this.file || this.id;
}
}]);
return Input;
}();
var _default = Input;
/**
* @typedef {object} filePosition
* @property {string} file Path to file.
* @property {number} line Source line in file.
* @property {number} column Source column in file.
*/
exports.default = _default;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImlucHV0LmVzNiJdLCJuYW1lcyI6WyJzZXF1ZW5jZSIsIklucHV0IiwiY3NzIiwib3B0cyIsInRvU3RyaW5nIiwiRXJyb3IiLCJoYXNCT00iLCJzbGljZSIsImZyb20iLCJ0ZXN0IiwicGF0aCIsImlzQWJzb2x1dGUiLCJmaWxlIiwicmVzb2x2ZSIsIm1hcCIsIlByZXZpb3VzTWFwIiwidGV4dCIsImNvbnN1bWVyIiwibWFwUmVzb2x2ZSIsImlkIiwiZXJyb3IiLCJtZXNzYWdlIiwibGluZSIsImNvbHVtbiIsInJlc3VsdCIsIm9yaWdpbiIsIkNzc1N5bnRheEVycm9yIiwic291cmNlIiwicGx1Z2luIiwiaW5wdXQiLCJvcmlnaW5hbFBvc2l0aW9uRm9yIiwic291cmNlQ29udGVudEZvciIsInNvdXJjZVJvb3QiXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUE7O0FBRUE7O0FBQ0E7Ozs7Ozs7O0FBRUEsSUFBSUEsUUFBUSxHQUFHLENBQWY7QUFFQTs7Ozs7Ozs7SUFPTUMsSzs7O0FBQ0o7Ozs7QUFJQSxpQkFBYUMsR0FBYixFQUFrQkMsSUFBbEIsRUFBOEI7QUFBQSxRQUFaQSxJQUFZO0FBQVpBLE1BQUFBLElBQVksR0FBTCxFQUFLO0FBQUE7O0FBQzVCLFFBQ0VELEdBQUcsS0FBSyxJQUFSLElBQ0EsT0FBT0EsR0FBUCxLQUFlLFdBRGYsSUFFQyxPQUFPQSxHQUFQLEtBQWUsUUFBZixJQUEyQixDQUFDQSxHQUFHLENBQUNFLFFBSG5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