MakeNamespaceObjectRuntimeModule.js 972 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. const RuntimeGlobals = require("../RuntimeGlobals");
  6. const Template = require("../Template");
  7. const HelperRuntimeModule = require("./HelperRuntimeModule");
  8. class MakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
  9. constructor() {
  10. super("make namespace object");
  11. }
  12. /**
  13. * @returns {string} runtime code
  14. */
  15. generate() {
  16. const { runtimeTemplate } = this.compilation;
  17. const fn = RuntimeGlobals.makeNamespaceObject;
  18. return Template.asString([
  19. "// define __esModule on exports",
  20. `${fn} = ${runtimeTemplate.basicFunction("exports", [
  21. "if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {",
  22. Template.indent([
  23. "Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });"
  24. ]),
  25. "}",
  26. "Object.defineProperty(exports, '__esModule', { value: true });"
  27. ])};`
  28. ]);
  29. }
  30. }
  31. module.exports = MakeNamespaceObjectRuntimeModule;