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