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("../Parser").ParserState} ParserState */
|
---|
13 |
|
---|
14 | /** @type {WeakMap<ParserState, boolean>} */
|
---|
15 | const parserStateExportsState = new WeakMap();
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * @param {ParserState} 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 = /** @type {BuildMeta} */ (parserState.module.buildMeta);
|
---|
28 | buildMeta.exportsType = "namespace";
|
---|
29 | const buildInfo = /** @type {BuildInfo} */ (parserState.module.buildInfo);
|
---|
30 | buildInfo.strict = true;
|
---|
31 | buildInfo.exportsArgument = RuntimeGlobals.exports;
|
---|
32 | if (isStrictHarmony) {
|
---|
33 | buildMeta.strictHarmonyModule = true;
|
---|
34 | buildInfo.moduleArgument = "__webpack_module__";
|
---|
35 | }
|
---|
36 | }
|
---|
37 | };
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * @param {ParserState} parserState parser state
|
---|
41 | * @returns {boolean} true, when enabled
|
---|
42 | */
|
---|
43 | module.exports.isEnabled = parserState => {
|
---|
44 | const value = parserStateExportsState.get(parserState);
|
---|
45 | return value === true;
|
---|
46 | };
|
---|