input.js 2.2 KB

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