Skip to content

Commit 162a273

Browse files
author
Andy
authored
Simplify some code in parseTestData (microsoft#22587)
1 parent eb4dba7 commit 162a273

File tree

1 file changed

+13
-30
lines changed

1 file changed

+13
-30
lines changed

src/harness/fourslash.ts

+13-30
Original file line numberDiff line numberDiff line change
@@ -3333,12 +3333,14 @@ ${code}
33333333
const ranges: Range[] = [];
33343334

33353335
// Stuff related to the subfile we're parsing
3336-
let currentFileContent: string;
3336+
let currentFileContent: string | undefined;
33373337
let currentFileName = fileName;
33383338
let currentFileSymlinks: string[] | undefined;
33393339
let currentFileOptions: { [s: string]: string } = {};
33403340

33413341
function nextFile() {
3342+
if (currentFileContent === undefined) return;
3343+
33423344
const file = parseFileContent(currentFileContent, currentFileName, markerPositions, markers, ranges);
33433345
file.fileOptions = currentFileOptions;
33443346
file.symlinks = currentFileSymlinks;
@@ -3353,25 +3355,13 @@ ${code}
33533355
}
33543356

33553357
for (let line of lines) {
3356-
const lineLength = line.length;
3357-
3358-
if (lineLength > 0 && line.charAt(lineLength - 1) === "\r") {
3359-
line = line.substr(0, lineLength - 1);
3358+
if (line.length > 0 && line.charAt(line.length - 1) === "\r") {
3359+
line = line.substr(0, line.length - 1);
33603360
}
33613361

33623362
if (line.substr(0, 4) === "////") {
3363-
// Subfile content line
3364-
3365-
// Append to the current subfile content, inserting a newline needed
3366-
if (currentFileContent === undefined) {
3367-
currentFileContent = "";
3368-
}
3369-
else {
3370-
// End-of-line
3371-
currentFileContent = currentFileContent + "\n";
3372-
}
3373-
3374-
currentFileContent = currentFileContent + line.substr(4);
3363+
const text = line.substr(4);
3364+
currentFileContent = currentFileContent === undefined ? text : currentFileContent + "\n" + text;
33753365
}
33763366
else if (line.substr(0, 2) === "//") {
33773367
// Comment line, check for global/file @options and record them
@@ -3389,10 +3379,7 @@ ${code}
33893379
switch (key) {
33903380
case MetadataOptionNames.fileName:
33913381
// Found an @FileName directive, if this is not the first then create a new subfile
3392-
if (currentFileContent) {
3393-
nextFile();
3394-
}
3395-
3382+
nextFile();
33963383
currentFileName = ts.isRootedDiskPath(value) ? value : basePath + "/" + value;
33973384
currentFileOptions[key] = value;
33983385
break;
@@ -3406,15 +3393,11 @@ ${code}
34063393
}
34073394
}
34083395
}
3409-
else if (line === "" || lineLength === 0) {
3410-
// Previously blank lines between fourslash content caused it to be considered as 2 files,
3411-
// Remove this behavior since it just causes errors now
3412-
}
3413-
else {
3414-
// Empty line or code line, terminate current subfile if there is one
3415-
if (currentFileContent) {
3416-
nextFile();
3417-
}
3396+
// Previously blank lines between fourslash content caused it to be considered as 2 files,
3397+
// Remove this behavior since it just causes errors now
3398+
else if (line !== "") {
3399+
// Code line, terminate current subfile if there is one
3400+
nextFile();
34183401
}
34193402
}
34203403

0 commit comments

Comments
 (0)