HarmonyExports.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const RuntimeGlobals = require("../RuntimeGlobals");
  7. /** @import { BuildInfo } from "../Module" */
  8. /**
  9. * @import {
  10. * JavascriptModuleBuildMeta
  11. * } from "../javascript/JavascriptModule"
  12. */
  13. /** @import { JavascriptParserState } from "../javascript/JavascriptParser" */
  14. /** @type {WeakMap<JavascriptParserState, boolean>} */
  15. const parserStateExportsState = new WeakMap();
  16. /**
  17. * Processes the provided parser state.
  18. * @param {JavascriptParserState} parserState parser state
  19. * @param {boolean} isStrictHarmony strict harmony mode should be enabled
  20. * @returns {void}
  21. */
  22. module.exports.enable = (parserState, isStrictHarmony) => {
  23. const value = parserStateExportsState.get(parserState);
  24. if (value === false) return;
  25. parserStateExportsState.set(parserState, true);
  26. if (value !== true) {
  27. const buildMeta =
  28. /** @type {JavascriptModuleBuildMeta} */
  29. (parserState.module.buildMeta);
  30. buildMeta.exportsType = "namespace";
  31. const buildInfo = /** @type {BuildInfo} */ (parserState.module.buildInfo);
  32. buildInfo.strict = true;
  33. buildInfo.exportsArgument = RuntimeGlobals.exports;
  34. if (isStrictHarmony) {
  35. buildMeta.strictHarmonyModule = true;
  36. buildInfo.moduleArgument = "__webpack_module__";
  37. }
  38. }
  39. };
  40. /**
  41. * Returns true, when enabled.
  42. * @param {JavascriptParserState} parserState parser state
  43. * @returns {boolean} true, when enabled
  44. */
  45. module.exports.isEnabled = (parserState) => {
  46. const value = parserStateExportsState.get(parserState);
  47. return value === true;
  48. };