HarmonyExports.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. /** @typedef {import("../Module").BuildInfo} BuildInfo */
  8. /** @typedef {import("../Module").BuildMeta} BuildMeta */
  9. /** @typedef {import("../Parser").ParserState} ParserState */
  10. /** @type {WeakMap<ParserState, boolean>} */
  11. const parserStateExportsState = new WeakMap();
  12. /**
  13. * @param {ParserState} parserState parser state
  14. * @param {boolean} isStrictHarmony strict harmony mode should be enabled
  15. * @returns {void}
  16. */
  17. exports.enable = (parserState, isStrictHarmony) => {
  18. const value = parserStateExportsState.get(parserState);
  19. if (value === false) return;
  20. parserStateExportsState.set(parserState, true);
  21. if (value !== true) {
  22. const buildMeta = /** @type {BuildMeta} */ (parserState.module.buildMeta);
  23. buildMeta.exportsType = "namespace";
  24. const buildInfo = /** @type {BuildInfo} */ (parserState.module.buildInfo);
  25. buildInfo.strict = true;
  26. buildInfo.exportsArgument = RuntimeGlobals.exports;
  27. if (isStrictHarmony) {
  28. buildMeta.strictHarmonyModule = true;
  29. buildInfo.moduleArgument = "__webpack_module__";
  30. }
  31. }
  32. };
  33. /**
  34. * @param {ParserState} parserState parser state
  35. * @returns {boolean} true, when enabled
  36. */
  37. exports.isEnabled = parserState => {
  38. const value = parserStateExportsState.get(parserState);
  39. return value === true;
  40. };