ExtractedModule.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 _webpackSources = require('webpack-sources');
  7. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8. var ExtractedModule = function () {
  9. function ExtractedModule(identifier, originalModule, source, sourceMap, addtitionalInformation, prevModules) {
  10. _classCallCheck(this, ExtractedModule);
  11. this._identifier = identifier;
  12. this._originalModule = originalModule;
  13. this._source = source;
  14. this._sourceMap = sourceMap;
  15. this._prevModules = prevModules;
  16. this.addtitionalInformation = addtitionalInformation;
  17. this.chunks = [];
  18. }
  19. _createClass(ExtractedModule, [{
  20. key: 'getOrder',
  21. value: function getOrder() {
  22. // http://stackoverflow.com/a/14676665/1458162
  23. return (/^@import url/.test(this._source) ? 0 : 1
  24. );
  25. }
  26. }, {
  27. key: 'addChunk',
  28. value: function addChunk(chunk) {
  29. var idx = this.chunks.indexOf(chunk);
  30. if (idx < 0) {
  31. this.chunks.push(chunk);
  32. }
  33. }
  34. }, {
  35. key: 'removeChunk',
  36. value: function removeChunk(chunk) {
  37. var idx = this.chunks.indexOf(chunk);
  38. if (idx >= 0) {
  39. this.chunks.splice(idx, 1);
  40. chunk.removeModule(this);
  41. return true;
  42. }
  43. return false;
  44. }
  45. }, {
  46. key: 'rewriteChunkInReasons',
  47. value: function rewriteChunkInReasons(oldChunk, newChunks) {} // eslint-disable-line
  48. }, {
  49. key: 'identifier',
  50. value: function identifier() {
  51. return this._identifier;
  52. }
  53. }, {
  54. key: 'source',
  55. value: function source() {
  56. if (this._sourceMap) {
  57. return new _webpackSources.SourceMapSource(this._source, null, this._sourceMap);
  58. }
  59. return new _webpackSources.RawSource(this._source);
  60. }
  61. }, {
  62. key: 'getOriginalModule',
  63. value: function getOriginalModule() {
  64. return this._originalModule;
  65. }
  66. }, {
  67. key: 'getPrevModules',
  68. value: function getPrevModules() {
  69. return this._prevModules;
  70. }
  71. }, {
  72. key: 'addPrevModules',
  73. value: function addPrevModules(prevModules) {
  74. var _this = this;
  75. prevModules.forEach(function (m) {
  76. if (_this._prevModules.indexOf(m) < 0) {
  77. _this._prevModules.push(m);
  78. }
  79. }, this);
  80. }
  81. }, {
  82. key: 'setOriginalModule',
  83. value: function setOriginalModule(originalModule) {
  84. this._originalModule = originalModule;
  85. }
  86. }]);
  87. return ExtractedModule;
  88. }();
  89. exports.default = ExtractedModule;