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

Function createNodeArray

test/fixtures/snapshot/typescript.js:22737–22771  ·  view source on GitHub ↗
(elements, hasTrailingComma)

Source from the content-addressed store, hash-verified

22735 return factory;
22736 // @api
22737 function createNodeArray(elements, hasTrailingComma) {
22738 if (elements === undefined || elements === ts.emptyArray) {
22739 elements = [];
22740 }
22741 else if (ts.isNodeArray(elements)) {
22742 if (hasTrailingComma === undefined || elements.hasTrailingComma === hasTrailingComma) {
22743 // Ensure the transform flags have been aggregated for this NodeArray
22744 if (elements.transformFlags === undefined) {
22745 aggregateChildrenFlags(elements);
22746 }
22747 ts.Debug.attachNodeArrayDebugInfo(elements);
22748 return elements;
22749 }
22750 // This *was* a `NodeArray`, but the `hasTrailingComma` option differs. Recreate the
22751 // array with the same elements, text range, and transform flags but with the updated
22752 // value for `hasTrailingComma`
22753 var array_8 = elements.slice();
22754 array_8.pos = elements.pos;
22755 array_8.end = elements.end;
22756 array_8.hasTrailingComma = hasTrailingComma;
22757 array_8.transformFlags = elements.transformFlags;
22758 ts.Debug.attachNodeArrayDebugInfo(array_8);
22759 return array_8;
22760 }
22761 // Since the element list of a node array is typically created by starting with an empty array and
22762 // repeatedly calling push(), the list may not have the optimal memory layout. We invoke slice() for
22763 // small arrays (1 to 4 elements) to give the VM a chance to allocate an optimal representation.
22764 var length = elements.length;
22765 var array = (length >= 1 && length <= 4 ? elements.slice() : elements);
22766 ts.setTextRangePosEnd(array, -1, -1);
22767 array.hasTrailingComma = !!hasTrailingComma;
22768 aggregateChildrenFlags(array);
22769 ts.Debug.attachNodeArrayDebugInfo(array);
22770 return array;
22771 }
22772 function createBaseNode(kind) {
22773 return baseFactory.createBaseNode(kind);
22774 }

Callers 15

createIdentifierFunction · 0.85
createTypeReferenceNodeFunction · 0.85
createTypeLiteralNodeFunction · 0.85
createTupleTypeNodeFunction · 0.85
createMappedTypeNodeFunction · 0.85

Calls 2

aggregateChildrenFlagsFunction · 0.85
sliceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…