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("../Parser").ParserState} ParserState */
|
---|
9 |
|
---|
10 | /** @type {WeakMap<ParserState, boolean>} */
|
---|
11 | const parserStateExportsState = new WeakMap();
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * @param {ParserState} parserState parser state
|
---|
15 | * @returns {void}
|
---|
16 | */
|
---|
17 | exports.bailout = parserState => {
|
---|
18 | const value = parserStateExportsState.get(parserState);
|
---|
19 | parserStateExportsState.set(parserState, false);
|
---|
20 | if (value === true) {
|
---|
21 | parserState.module.buildMeta.exportsType = undefined;
|
---|
22 | parserState.module.buildMeta.defaultObject = false;
|
---|
23 | }
|
---|
24 | };
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * @param {ParserState} parserState parser state
|
---|
28 | * @returns {void}
|
---|
29 | */
|
---|
30 | exports.enable = parserState => {
|
---|
31 | const value = parserStateExportsState.get(parserState);
|
---|
32 | if (value === false) return;
|
---|
33 | parserStateExportsState.set(parserState, true);
|
---|
34 | if (value !== true) {
|
---|
35 | parserState.module.buildMeta.exportsType = "default";
|
---|
36 | parserState.module.buildMeta.defaultObject = "redirect";
|
---|
37 | }
|
---|
38 | };
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * @param {ParserState} parserState parser state
|
---|
42 | * @returns {void}
|
---|
43 | */
|
---|
44 | exports.setFlagged = parserState => {
|
---|
45 | const value = parserStateExportsState.get(parserState);
|
---|
46 | if (value !== true) return;
|
---|
47 | const buildMeta = parserState.module.buildMeta;
|
---|
48 | if (buildMeta.exportsType === "dynamic") return;
|
---|
49 | buildMeta.exportsType = "flagged";
|
---|
50 | };
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * @param {ParserState} parserState parser state
|
---|
54 | * @returns {void}
|
---|
55 | */
|
---|
56 | exports.setDynamic = parserState => {
|
---|
57 | const value = parserStateExportsState.get(parserState);
|
---|
58 | if (value !== true) return;
|
---|
59 | parserState.module.buildMeta.exportsType = "dynamic";
|
---|
60 | };
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * @param {ParserState} parserState parser state
|
---|
64 | * @returns {boolean} true, when enabled
|
---|
65 | */
|
---|
66 | exports.isEnabled = parserState => {
|
---|
67 | const value = parserStateExportsState.get(parserState);
|
---|
68 | return value === true;
|
---|
69 | };
|
---|