Skip to content

Declare reportError as returning never in fourslash #53741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4510,24 +4510,23 @@ const enum State {
inObjectMarker
}

function reportError(fileName: string, line: number, col: number, message: string) {
function reportError(fileName: string, line: number, col: number, message: string): never {
const errorMessage = fileName + "(" + line + "," + col + "): " + message;
throw new Error(errorMessage);
}

function recordObjectMarker(fileName: string, location: LocationInformation, text: string, markerMap: Map<string, Marker>, markers: Marker[]): Marker | undefined {
let markerValue: any;
let markerValue;
try {
// Attempt to parse the marker value as JSON
markerValue = JSON.parse("{ " + text + " }");
markerValue = JSON.parse("{ " + text + " }") as { name?: unknown };
}
catch (e) {
reportError(fileName, location.sourceLine, location.sourceColumn, "Unable to parse marker text " + e.message);
}

if (markerValue === undefined) {
reportError(fileName, location.sourceLine, location.sourceColumn, "Object markers can not be empty");
return undefined;
}

const marker: Marker = {
Expand All @@ -4537,7 +4536,7 @@ function recordObjectMarker(fileName: string, location: LocationInformation, tex
};

// Object markers can be anonymous
if (markerValue.name) {
if (typeof markerValue.name === "string") {
markerMap.set(markerValue.name, marker);
}

Expand All @@ -4556,7 +4555,6 @@ function recordMarker(fileName: string, location: LocationInformation, name: str
if (markerMap.has(name)) {
const message = "Marker '" + name + "' is duplicated in the source file contents.";
reportError(marker.fileName, location.sourceLine, location.sourceColumn, message);
return undefined;
}
else {
markerMap.set(name, marker);
Expand Down Expand Up @@ -4623,7 +4621,7 @@ function parseFileContent(content: string, fileName: string, markerMap: Map<stri
// found a range end
const rangeStart = openRanges.pop();
if (!rangeStart) {
throw reportError(fileName, line, column, "Found range end with no matching start.");
reportError(fileName, line, column, "Found range end with no matching start.");
}

const range: Range = {
Expand Down