input.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _previousMap = require('./previous-map');
  4. var _previousMap2 = _interopRequireDefault(_previousMap);
  5. var _path = require('path');
  6. var _path2 = _interopRequireDefault(_path);
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9. var sequence = 0;
  10. var Input = function () {
  11. function Input(css) {
  12. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  13. _classCallCheck(this, Input);
  14. this.css = css.toString();
  15. if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
  16. this.css = this.css.slice(1);
  17. }
  18. if (opts.from) this.file = _path2.default.resolve(opts.from);
  19. var map = new _previousMap2.default(this.css, opts, this.id);
  20. if (map.text) {
  21. this.map = map;
  22. var file = map.consumer().file;
  23. if (!this.file && file) this.file = this.mapResolve(file);
  24. }
  25. if (this.file) {
  26. this.from = this.file;
  27. } else {
  28. sequence += 1;
  29. this.id = '<input css ' + sequence + '>';
  30. this.from = this.id;
  31. }
  32. if (this.map) this.map.file = this.from;
  33. }
  34. Input.prototype.mapResolve = function mapResolve(file) {
  35. return _path2.default.resolve(this.map.consumer().sourceRoot || '.', file);
  36. };
  37. return Input;
  38. }();
  39. exports.default = Input;