getParserHelpers.js
1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const { webpackVersion } = require('../globals');
/**
* @callback EvaluateToString
* @param {string} value
* @returns {function(*): *}
*/
/**
* @callback ToConstantDependency
* @param {*} parser
* @param {string} value
* @param {string[]} [runtimeRequirements]
* @returns {function(*): boolean}
*/
/**
* @typedef {Object} ParserHelpers
* @property {EvaluateToString} evaluateToString
* @property {ToConstantDependency} toConstantDependency
*/
/**
* Gets parser helpers for specific webpack versions.
* @returns {ParserHelpers} The needed parser helpers.
*/
function getParserHelpers() {
if (webpackVersion === 4) {
const {
evaluateToString,
toConstantDependencyWithWebpackRequire,
} = require('webpack/lib/ParserHelpers');
return {
evaluateToString,
toConstantDependency: toConstantDependencyWithWebpackRequire,
};
}
if (webpackVersion === 5) {
return require('webpack/lib/javascript/JavascriptParserHelpers');
}
}
module.exports = getParserHelpers;