GoScrobble/web/node_modules/@pmmmwh/react-refresh-webpack-plugin/lib/utils/getParserHelpers.js

45 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-04-25 02:47:15 +00:00
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;