1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | Author Tobias Koppers @sokra
|
---|
4 | */
|
---|
5 |
|
---|
6 | "use strict";
|
---|
7 |
|
---|
8 | /** @typedef {import("../Module").BuildMeta} BuildMeta */
|
---|
9 | /** @typedef {import("../Parser").ParserState} ParserState */
|
---|
10 |
|
---|
11 | /** @type {WeakMap<ParserState, boolean>} */
|
---|
12 | const parserStateExportsState = new WeakMap();
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * @param {ParserState} parserState parser state
|
---|
16 | * @returns {void}
|
---|
17 | */
|
---|
18 | module.exports.bailout = parserState => {
|
---|
19 | const value = parserStateExportsState.get(parserState);
|
---|
20 | parserStateExportsState.set(parserState, false);
|
---|
21 | if (value === true) {
|
---|
22 | const buildMeta = /** @type {BuildMeta} */ (parserState.module.buildMeta);
|
---|
23 | buildMeta.exportsType = undefined;
|
---|
24 | buildMeta.defaultObject = false;
|
---|
25 | }
|
---|
26 | };
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * @param {ParserState} parserState parser state
|
---|
30 | * @returns {void}
|
---|
31 | */
|
---|
32 | module.exports.enable = parserState => {
|
---|
33 | const value = parserStateExportsState.get(parserState);
|
---|
34 | if (value === false) return;
|
---|
35 | parserStateExportsState.set(parserState, true);
|
---|
36 | if (value !== true) {
|
---|
37 | const buildMeta = /** @type {BuildMeta} */ (parserState.module.buildMeta);
|
---|
38 | buildMeta.exportsType = "default";
|
---|
39 | buildMeta.defaultObject = "redirect";
|
---|
40 | }
|
---|
41 | };
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * @param {ParserState} parserState parser state
|
---|
45 | * @returns {void}
|
---|
46 | */
|
---|
47 | module.exports.setFlagged = parserState => {
|
---|
48 | const value = parserStateExportsState.get(parserState);
|
---|
49 | if (value !== true) return;
|
---|
50 | const buildMeta = /** @type {BuildMeta} */ (parserState.module.buildMeta);
|
---|
51 | if (buildMeta.exportsType === "dynamic") return;
|
---|
52 | buildMeta.exportsType = "flagged";
|
---|
53 | };
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * @param {ParserState} parserState parser state
|
---|
57 | * @returns {void}
|
---|
58 | */
|
---|
59 | module.exports.setDynamic = parserState => {
|
---|
60 | const value = parserStateExportsState.get(parserState);
|
---|
61 | if (value !== true) return;
|
---|
62 | /** @type {BuildMeta} */
|
---|
63 | (parserState.module.buildMeta).exportsType = "dynamic";
|
---|
64 | };
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * @param {ParserState} parserState parser state
|
---|
68 | * @returns {boolean} true, when enabled
|
---|
69 | */
|
---|
70 | module.exports.isEnabled = parserState => {
|
---|
71 | const value = parserStateExportsState.get(parserState);
|
---|
72 | return value === true;
|
---|
73 | };
|
---|