HarmonyExports.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /** @typedef {import("../Parser").ParserState} ParserState */
  7. /** @type {WeakMap<ParserState, boolean>} */
  8. const parserStateExportsState = new WeakMap();
  9. /**
  10. * @param {ParserState} parserState parser state
  11. * @param {boolean} isStrictHarmony strict harmony mode should be enabled
  12. * @returns {void}
  13. */
  14. exports.enable = (parserState, isStrictHarmony) => {
  15. const value = parserStateExportsState.get(parserState);
  16. if (value === false) return;
  17. parserStateExportsState.set(parserState, true);
  18. if (value !== true) {
  19. parserState.module.buildMeta.exportsType = "namespace";
  20. parserState.module.buildInfo.strict = true;
  21. parserState.module.buildInfo.exportsArgument = "__webpack_exports__";
  22. if (isStrictHarmony) {
  23. parserState.module.buildMeta.strictHarmonyModule = true;
  24. parserState.module.buildInfo.moduleArgument = "__webpack_module__";
  25. }
  26. }
  27. };
  28. /**
  29. * @param {ParserState} parserState parser state
  30. * @returns {boolean} true, when enabled
  31. */
  32. exports.isEnabled = parserState => {
  33. const value = parserStateExportsState.get(parserState);
  34. return value === true;
  35. };