You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.7 KiB

4 years ago
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _ExtractedModule = require('./ExtractedModule');
  6. var _ExtractedModule2 = _interopRequireDefault(_ExtractedModule);
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. class ExtractTextPluginCompilation {
  9. constructor() {
  10. this.modulesByIdentifier = {};
  11. }
  12. addModule(identifier, originalModule, source, additionalInformation, sourceMap, prevModules) {
  13. let m;
  14. if (!this.modulesByIdentifier[identifier]) {
  15. m = this.modulesByIdentifier[identifier] = new _ExtractedModule2.default(identifier, originalModule, source, sourceMap, additionalInformation, prevModules);
  16. } else {
  17. m = this.modulesByIdentifier[identifier];
  18. m.addPrevModules(prevModules);
  19. if (originalModule.index2 < m.getOriginalModule().index2) {
  20. m.setOriginalModule(originalModule);
  21. }
  22. }
  23. return m;
  24. }
  25. addResultToChunk(identifier, result, originalModule, extractedChunk) {
  26. if (!Array.isArray(result)) {
  27. result = [[identifier, result]];
  28. }
  29. const counterMap = {};
  30. const prevModules = [];
  31. result.forEach(item => {
  32. const c = counterMap[item[0]];
  33. const module = this.addModule.call(this, item[0] + (c || ''), originalModule, item[1], item[2], item[3], prevModules.slice());
  34. extractedChunk.addModule(module);
  35. // extractedChunk.removeModule(originalModule);
  36. module.addChunk(extractedChunk);
  37. counterMap[item[0]] = (c || 0) + 1;
  38. prevModules.push(module);
  39. }, this);
  40. }
  41. } /* eslint-disable
  42. no-multi-assign,
  43. no-param-reassign
  44. */
  45. exports.default = ExtractTextPluginCompilation;