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.

HarmonyExportExpressionDependency.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const NullDependency = require("./NullDependency");
  7. class HarmonyExportExpressionDependency extends NullDependency {
  8. constructor(originModule, range, rangeStatement, prefix) {
  9. super();
  10. this.originModule = originModule;
  11. this.range = range;
  12. this.rangeStatement = rangeStatement;
  13. this.prefix = prefix;
  14. }
  15. get type() {
  16. return "harmony export expression";
  17. }
  18. getExports() {
  19. return {
  20. exports: ["default"],
  21. dependencies: undefined
  22. };
  23. }
  24. }
  25. HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTemplate {
  26. apply(dep, source) {
  27. const used = dep.originModule.isUsed("default");
  28. const content = this.getContent(dep.originModule, used);
  29. if (dep.range) {
  30. source.replace(
  31. dep.rangeStatement[0],
  32. dep.range[0] - 1,
  33. content + "(" + dep.prefix
  34. );
  35. source.replace(dep.range[1], dep.rangeStatement[1] - 1, ");");
  36. return;
  37. }
  38. source.replace(dep.rangeStatement[0], dep.rangeStatement[1] - 1, content);
  39. }
  40. getContent(module, used) {
  41. const exportsName = module.exportsArgument;
  42. if (used) {
  43. return `/* harmony default export */ ${exportsName}[${JSON.stringify(
  44. used
  45. )}] = `;
  46. }
  47. return "/* unused harmony default export */ var _unused_webpack_default_export = ";
  48. }
  49. };
  50. module.exports = HarmonyExportExpressionDependency;