MCPcopy
hub / github.com/webpack/webpack / toCode

Function toCode

lib/DefinePlugin.js:244–306  ·  view source on GitHub ↗
(
	code,
	parser,
	valueCacheVersions,
	key,
	runtimeTemplate,
	logger,
	asiSafe,
	objKeys
)

Source from the content-addressed store, hash-verified

242 * @returns {string} code converted to string that evaluates
243 */
244const toCode = (
245 code,
246 parser,
247 valueCacheVersions,
248 key,
249 runtimeTemplate,
250 logger,
251 asiSafe,
252 objKeys
253) => {
254 const transformToCode = () => {
255 if (code === null) {
256 return "null";
257 }
258 if (code === undefined) {
259 return "undefined";
260 }
261 if (Object.is(code, -0)) {
262 return "-0";
263 }
264 if (code instanceof RuntimeValue) {
265 return toCode(
266 code.exec(parser, valueCacheVersions, key),
267 parser,
268 valueCacheVersions,
269 key,
270 runtimeTemplate,
271 logger,
272 asiSafe
273 );
274 }
275 if (code instanceof RegExp && code.toString) {
276 return code.toString();
277 }
278 if (typeof code === "function" && code.toString) {
279 return `(${code.toString()})`;
280 }
281 if (typeof code === "object") {
282 return stringifyObj(
283 code,
284 parser,
285 valueCacheVersions,
286 key,
287 runtimeTemplate,
288 logger,
289 asiSafe,
290 objKeys
291 );
292 }
293 if (typeof code === "bigint") {
294 return runtimeTemplate.supportsBigIntLiteral()
295 ? `${code}n`
296 : `BigInt("${code}")`;
297 }
298 return `${code}`;
299 };
300
301 const strCode = transformToCode();

Callers 3

stringifyObjFunction · 0.85
transformToCodeFunction · 0.85
applyDefineMethod · 0.85

Calls 2

transformToCodeFunction · 0.85
debugMethod · 0.80

Tested by

no test coverage detected