MCPcopy Create free account
hub / github.com/nodejs/node / createChildren

Function createChildren

test/fixtures/snapshot/typescript.js:164006–164040  ·  view source on GitHub ↗
(node, sourceFile)

Source from the content-addressed store, hash-verified

164004 return NodeObject;
164005 }());
164006 function createChildren(node, sourceFile) {
164007 if (!ts.isNodeKind(node.kind)) {
164008 return ts.emptyArray;
164009 }
164010 var children = [];
164011 if (ts.isJSDocCommentContainingNode(node)) {
164012 /** Don't add trivia for "tokens" since this is in a comment. */
164013 node.forEachChild(function (child) {
164014 children.push(child);
164015 });
164016 return children;
164017 }
164018 ts.scanner.setText((sourceFile || node.getSourceFile()).text);
164019 var pos = node.pos;
164020 var processNode = function (child) {
164021 addSyntheticNodes(children, pos, child.pos, node);
164022 children.push(child);
164023 pos = child.end;
164024 };
164025 var processNodes = function (nodes) {
164026 addSyntheticNodes(children, pos, nodes.pos, node);
164027 children.push(createSyntaxList(nodes, node));
164028 pos = nodes.end;
164029 };
164030 // jsDocComments need to be the first children
164031 ts.forEach(node.jsDoc, processNode);
164032 // For syntactic classifications, all trivia are classified together, including jsdoc comments.
164033 // For that to work, the jsdoc comments should still be the leading trivia of the first child.
164034 // Restoring the scanner position ensures that.
164035 pos = node.pos;
164036 node.forEachChild(processNode, processNodes);
164037 addSyntheticNodes(children, pos, node.end, node);
164038 ts.scanner.setText(undefined);
164039 return children;
164040 }
164041 function addSyntheticNodes(nodes, pos, end, parent) {
164042 ts.scanner.setTextPos(pos);
164043 while (pos < end) {

Callers 1

typescript.jsFile · 0.70

Calls 4

addSyntheticNodesFunction · 0.85
forEachChildMethod · 0.80
forEachMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected