MCPcopy Index your code
hub / github.com/nodejs/node / generateOptionalChaining

Function generateOptionalChaining

tools/eslint-rules/prefer-optional-chaining.js:39–46  ·  view source on GitHub ↗
(ops, first, last)

Source from the content-addressed store, hash-verified

37
38 // Generate the optional chaining expression
39 function generateOptionalChaining(ops, first, last) {
40 return ops.slice(first, last + 1).reduce((chain, node, i) => {
41 const property = node.computed ?
42 `[${sourceCode.getText(node.property)}]` :
43 sourceCode.getText(node.property);
44 return i === 0 ? sourceCode.getText(node) : `${chain}?.${property}`;
45 }, '');
46 }
47
48 return {
49 'LogicalExpression[operator=&&]:exit'(node) {

Callers 1

fixFunction · 0.85

Calls 2

reduceMethod · 0.80
sliceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…