MCPcopy
hub / github.com/webpack/webpack / optionalChaining

Method optionalChaining

lib/RuntimeTemplate.js:386–392  ·  view source on GitHub ↗

* Guards an access/call on `object` with optional chaining when supported, * otherwise an equivalent `&&` short-circuit. `object` is evaluated twice in * the fallback, so it must be side-effect free. * @param {string} object base expression (side-effect free) * @param {string} access continu

(object, access)

Source from the content-addressed store, hash-verified

384 * @returns {string} guarded access expression
385 */
386 optionalChaining(object, access) {
387 if (this.supportsOptionalChaining()) {
388 return `${object}?.${access}`;
389 }
390 const sep = access[0] === "(" || access[0] === "[" ? "" : ".";
391 return `${object} && ${object}${sep}${access}`;
392 }
393
394 /**
395 * Reads a node builtin via `process.getBuiltinModule()`, guarded to stay falsy off node so universal `["node", "web"]` bundles don't crash (also falsy on node <22.3).

Callers 15

generateMethod · 0.80
generateMethod · 0.80
generateMethod · 0.80
generateMethod · 0.80
generateMethod · 0.80
generateMethod · 0.80
applyMethod · 0.80
codeGenerationMethod · 0.80
generateMethod · 0.80
generateMethod · 0.80
generateMethod · 0.80
generateMethod · 0.80

Calls 1

Tested by

no test coverage detected