input.js 18KB

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