MCPcopy Create free account
hub / github.com/Snapchat/Valdi / getNodeComments

Function getNodeComments

compiler/companion/src/TSUtils.ts:140–170  ·  view source on GitHub ↗
(node: ts.Node)

Source from the content-addressed store, hash-verified

138}
139
140export function getNodeComments(node: ts.Node): NodeComments | undefined {
141 const leadingTriviaWidth = node.getLeadingTriviaWidth();
142 if (leadingTriviaWidth === 0) {
143 return undefined;
144 }
145 const nodeStart = node.getFullStart();
146 const sourceFileText = node.getSourceFile().text;
147
148 const leadingTriva = sourceFileText.substring(nodeStart, nodeStart + leadingTriviaWidth);
149 const trimmedLeft = leadingTriva.trimStart();
150
151 const trimLeftShrunkSize = leadingTriva.length - trimmedLeft.length;
152
153 let resolvedStart = nodeStart + trimLeftShrunkSize;
154 let resolvedWidth = leadingTriviaWidth - trimLeftShrunkSize;
155
156 const trimmedRight = trimmedLeft.trimEnd();
157
158 const trimRightShrunkSize = trimmedLeft.length - trimmedRight.length;
159 resolvedWidth -= trimRightShrunkSize;
160
161 if (!trimmedRight) {
162 return undefined;
163 }
164
165 return {
166 text: trimmedRight,
167 start: resolvedStart,
168 end: resolvedStart + resolvedWidth,
169 };
170}
171
172export interface NodeToDump {
173 node: ts.Node;

Callers 8

parseTypeFunction · 0.90
parsePropertyLikeFunction · 0.90
shouldDumpNodeMemberFunction · 0.90
dumpInterfaceFunction · 0.90
dumpFunctionFunction · 0.90
dumpVariableFunction · 0.90
dumpEnumFunction · 0.90
getRootNodesToDumpFunction · 0.85

Calls 2

substringMethod · 0.80
getSourceFileMethod · 0.45

Tested by

no test coverage detected