MCPcopy
hub / github.com/webpack/webpack / asBool

Method asBool

lib/javascript/BasicEvaluatedExpression.js:241–263  ·  view source on GitHub ↗

* Creates a boolean representation of this evaluated expression. * @returns {boolean | undefined} true: truthy, false: falsy, undefined: unknown

()

Source from the content-addressed store, hash-verified

239 * @returns {boolean | undefined} true: truthy, false: falsy, undefined: unknown
240 */
241 asBool() {
242 if (this.truthy) return true;
243 if (this.falsy || this.nullish) return false;
244 if (this.isBoolean()) return this.bool;
245 if (this.isNull()) return false;
246 if (this.isUndefined()) return false;
247 if (this.isString()) return this.string !== "";
248 if (this.isNumber()) return this.number !== 0;
249 if (this.isBigInt()) return this.bigint !== BigInt(0);
250 if (this.isRegExp()) return true;
251 if (this.isArray()) return true;
252 if (this.isConstArray()) return true;
253 if (this.isWrapped()) {
254 return (this.prefix && this.prefix.asBool()) ||
255 (this.postfix && this.postfix.asBool())
256 ? true
257 : undefined;
258 }
259 if (this.isTemplateString()) {
260 const str = this.asString();
261 if (typeof str === "string") return str !== "";
262 }
263 }
264
265 /**
266 * Creates a nullish coalescing representation of this evaluated expression.

Callers 5

applyMethod · 0.80
handlerMethod · 0.80
_initializeEvaluatingMethod · 0.80
collectMethod · 0.80

Calls 12

isBooleanMethod · 0.95
isNullMethod · 0.95
isUndefinedMethod · 0.95
isStringMethod · 0.95
isNumberMethod · 0.95
isBigIntMethod · 0.95
isRegExpMethod · 0.95
isArrayMethod · 0.95
isConstArrayMethod · 0.95
isWrappedMethod · 0.95
isTemplateStringMethod · 0.95
asStringMethod · 0.95

Tested by

no test coverage detected