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