Skip to content

Commit

Permalink
Simplify some code in parseTestData (#22587)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy authored Mar 15, 2018
1 parent eb4dba7 commit 162a273
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3333,12 +3333,14 @@ ${code}
const ranges: Range[] = [];

// Stuff related to the subfile we're parsing
let currentFileContent: string;
let currentFileContent: string | undefined;
let currentFileName = fileName;
let currentFileSymlinks: string[] | undefined;
let currentFileOptions: { [s: string]: string } = {};

function nextFile() {
if (currentFileContent === undefined) return;

const file = parseFileContent(currentFileContent, currentFileName, markerPositions, markers, ranges);
file.fileOptions = currentFileOptions;
file.symlinks = currentFileSymlinks;
Expand All @@ -3353,25 +3355,13 @@ ${code}
}

for (let line of lines) {
const lineLength = line.length;

if (lineLength > 0 && line.charAt(lineLength - 1) === "\r") {
line = line.substr(0, lineLength - 1);
if (line.length > 0 && line.charAt(line.length - 1) === "\r") {
line = line.substr(0, line.length - 1);
}

if (line.substr(0, 4) === "////") {
// Subfile content line

// Append to the current subfile content, inserting a newline needed
if (currentFileContent === undefined) {
currentFileContent = "";
}
else {
// End-of-line
currentFileContent = currentFileContent + "\n";
}

currentFileContent = currentFileContent + line.substr(4);
const text = line.substr(4);
currentFileContent = currentFileContent === undefined ? text : currentFileContent + "\n" + text;
}
else if (line.substr(0, 2) === "//") {
// Comment line, check for global/file @options and record them
Expand All @@ -3389,10 +3379,7 @@ ${code}
switch (key) {
case MetadataOptionNames.fileName:
// Found an @FileName directive, if this is not the first then create a new subfile
if (currentFileContent) {
nextFile();
}

nextFile();
currentFileName = ts.isRootedDiskPath(value) ? value : basePath + "/" + value;
currentFileOptions[key] = value;
break;
Expand All @@ -3406,15 +3393,11 @@ ${code}
}
}
}
else if (line === "" || lineLength === 0) {
// Previously blank lines between fourslash content caused it to be considered as 2 files,
// Remove this behavior since it just causes errors now
}
else {
// Empty line or code line, terminate current subfile if there is one
if (currentFileContent) {
nextFile();
}
// Previously blank lines between fourslash content caused it to be considered as 2 files,
// Remove this behavior since it just causes errors now
else if (line !== "") {
// Code line, terminate current subfile if there is one
nextFile();
}
}

Expand Down

0 comments on commit 162a273

Please sign in to comment.