input.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _path = _interopRequireDefault(require("path"));
  5. var _cssSyntaxError = _interopRequireDefault(require("./css-syntax-error"));
  6. var _previousMap = _interopRequireDefault(require("./previous-map"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. 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); } }
  9. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10. var sequence = 0;
  11. /**
  12. * Represents the source CSS.
  13. *
  14. * @example
  15. * const root = postcss.parse(css, { from: file })
  16. * const input = root.source.input
  17. */
  18. var Input = /*#__PURE__*/function () {
  19. /**
  20. * @param {string} css Input CSS source.
  21. * @param {object} [opts] {@link Processor#process} options.
  22. */
  23. function Input(css, opts) {
  24. if (opts === void 0) {
  25. opts = {};
  26. }
  27. if (css === null || typeof css === 'undefined' || typeof css === 'object' && !css.toString) {
  28. throw new Error("PostCSS received " + css + " instead of CSS string");
  29. }
  30. /**
  31. * Input CSS source
  32. *
  33. * @type {string}
  34. *
  35. * @example
  36. * const input = postcss.parse('a{}', { from: file }).input
  37. * input.css //=> "a{}"
  38. */
  39. this.css = css.toString();
  40. if (this.css[0] === "\uFEFF" || this.css[0] === "\uFFFE") {
  41. this.hasBOM = true;
  42. this.css = this.css.slice(1);
  43. } else {
  44. this.hasBOM = false;
  45. }
  46. if (opts.from) {
  47. if (/^\w+:\/\//.test(opts.from) || _path.default.isAbsolute(opts.from)) {
  48. /**
  49. * The absolute path to the CSS source file defined
  50. * with the `from` option.
  51. *
  52. * @type {string}
  53. *
  54. * @example
  55. * const root = postcss.parse(css, { from: 'a.css' })
  56. * root.source.input.file //=> '/home/ai/a.css'
  57. */
  58. this.file = opts.from;
  59. } else {
  60. this.file = _path.default.resolve(opts.from);
  61. }
  62. }
  63. var map = new _previousMap.default(this.css, opts);
  64. if (map.text) {
  65. /**
  66. * The input source map passed from a compilation step before PostCSS
  67. * (for example, from Sass compiler).
  68. *
  69. * @type {PreviousMap}
  70. *
  71. * @example
  72. * root.source.input.map.consumer().sources //=> ['a.sass']
  73. */
  74. this.map = map;
  75. var file = map.consumer().file;
  76. if (!this.file && file) this.file = this.mapResolve(file);
  77. }
  78. if (!this.file) {
  79. sequence += 1;
  80. /**
  81. * The unique ID of the CSS source. It will be created if `from` option
  82. * is not provided (because PostCSS does not know the file path).
  83. *
  84. * @type {string}
  85. *
  86. * @example
  87. * const root = postcss.parse(css)
  88. * root.source.input.file //=> undefined
  89. * root.source.input.id //=> "<input css 1>"
  90. */
  91. this.id = '<input css ' + sequence + '>';
  92. }
  93. if (this.map) this.map.file = this.from;
  94. }
  95. var _proto = Input.prototype;
  96. _proto.error = function error(message, line, column, opts) {
  97. if (opts === void 0) {
  98. opts = {};
  99. }
  100. var result;
  101. var origin = this.origin(line, column);
  102. if (origin) {
  103. result = new _cssSyntaxError.default(message, origin.line, origin.column, origin.source, origin.file, opts.plugin);
  104. } else {
  105. result = new _cssSyntaxError.default(message, line, column, this.css, this.file, opts.plugin);
  106. }
  107. result.input = {
  108. line: line,
  109. column: column,
  110. source: this.css
  111. };
  112. if (this.file) result.input.file = this.file;
  113. return result;
  114. }
  115. /**
  116. * Reads the input source map and returns a symbol position
  117. * in the input source (e.g., in a Sass file that was compiled
  118. * to CSS before being passed to PostCSS).
  119. *
  120. * @param {number} line Line in input CSS.
  121. * @param {number} column Column in input CSS.
  122. *
  123. * @return {filePosition} Position in input source.
  124. *
  125. * @example
  126. * root.source.input.origin(1, 1) //=> { file: 'a.css', line: 3, column: 1 }
  127. */
  128. ;
  129. _proto.origin = function origin(line, column) {
  130. if (!this.map) return false;
  131. var consumer = this.map.consumer();
  132. var from = consumer.originalPositionFor({
  133. line: line,
  134. column: column
  135. });
  136. if (!from.source) return false;
  137. var result = {
  138. file: this.mapResolve(from.source),
  139. line: from.line,
  140. column: from.column
  141. };
  142. var source = consumer.sourceContentFor(from.source);
  143. if (source) result.source = source;
  144. return result;
  145. };
  146. _proto.mapResolve = function mapResolve(file) {
  147. if (/^\w+:\/\//.test(file)) {
  148. return file;
  149. }
  150. return _path.default.resolve(this.map.consumer().sourceRoot || '.', file);
  151. }
  152. /**
  153. * The CSS source identifier. Contains {@link Input#file} if the user
  154. * set the `from` option, or {@link Input#id} if they did not.
  155. *
  156. * @type {string}
  157. *
  158. * @example
  159. * const root = postcss.parse(css, { from: 'a.css' })
  160. * root.source.input.from //=> "/home/ai/a.css"
  161. *
  162. * const root = postcss.parse(css)
  163. * root.source.input.from //=> "<input css 1>"
  164. */
  165. ;
  166. _createClass(Input, [{
  167. key: "from",
  168. get: function get() {
  169. return this.file || this.id;
  170. }
  171. }]);
  172. return Input;
  173. }();
  174. var _default = Input;
  175. /**
  176. * @typedef {object} filePosition
  177. * @property {string} file Path to file.
  178. * @property {number} line Source line in file.
  179. * @property {number} column Source column in file.
  180. */
  181. exports.default = _default;
  182. module.exports = exports.default;
  183. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImlucHV0LmVzNiJdLCJuYW1lcyI6WyJzZXF1ZW5jZSIsIklucHV0IiwiY3NzIiwib3B0cyIsInRvU3RyaW5nIiwiRXJyb3IiLCJoYXNCT00iLCJzbGljZSIsImZyb20iLCJ0ZXN0IiwicGF0aCIsImlzQWJzb2x1dGUiLCJ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