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

Method markTypeScriptOnlyLines

lib/internal/test_runner/coverage.js:155–204  ·  view source on GitHub ↗
(fileUrl, source)

Source from the content-addressed store, hash-verified

153 }
154
155 markTypeScriptOnlyLines(fileUrl, source) {
156 if (this.#typeScriptLines.has(fileUrl)) {
157 return;
158 }
159 this.#typeScriptLines.add(fileUrl);
160
161 if (RegExpPrototypeExec(kTypeScriptSourceRegex, fileUrl) === null) {
162 return;
163 }
164
165 const lines = this.getLines(fileUrl, source);
166 if (!lines) {
167 return;
168 }
169
170 let strippedLines;
171 const stripSource = getStripTypeScriptTypesForCoverage();
172
173 if (stripSource) {
174 source ??= readFileSync(fileURLToPath(fileUrl), 'utf8');
175
176 try {
177 strippedLines = RegExpPrototypeSymbolSplit(
178 kLineSplitRegex,
179 stripSource(source),
180 );
181 } catch {
182 strippedLines = undefined;
183 }
184 }
185
186 for (let i = 0; i < lines.length; ++i) {
187 const originalLine = lines[i].src;
188
189 if (StringPrototypeTrim(originalLine).length === 0) {
190 continue;
191 }
192
193 if (strippedLines?.[i] !== undefined) {
194 if (StringPrototypeTrim(strippedLines[i]).length === 0) {
195 lines[i].ignore = true;
196 }
197 continue;
198 }
199
200 if (RegExpPrototypeExec(kTypeOnlyImportRegex, originalLine) !== null) {
201 lines[i].ignore = true;
202 }
203 }
204 }
205
206 summary() {
207 internalBinding('profiler').takeCoverage();

Callers 1

Calls 6

getLinesMethod · 0.95
fileURLToPathFunction · 0.85
hasMethod · 0.65
addMethod · 0.65
readFileSyncFunction · 0.50

Tested by

no test coverage detected