MakeNamespaceObjectRuntimeModule.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. /** @typedef {import("../Compilation")} Compilation */
  9. class MakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
  10. constructor() {
  11. super("make namespace object");
  12. }
  13. /**
  14. * @returns {string | null} runtime code
  15. */
  16. generate() {
  17. const compilation = /** @type {Compilation} */ (this.compilation);
  18. const { runtimeTemplate } = compilation;
  19. const fn = RuntimeGlobals.makeNamespaceObject;
  20. return Template.asString([
  21. "// define __esModule on exports",
  22. `${fn} = ${runtimeTemplate.basicFunction("exports", [
  23. "if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {",
  24. Template.indent([
  25. "Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });"
  26. ]),
  27. "}",
  28. "Object.defineProperty(exports, '__esModule', { value: true });"
  29. ])};`
  30. ]);
  31. }
  32. }
  33. module.exports = MakeNamespaceObjectRuntimeModule;