Skip to content

Commit

Permalink
Fix parsing constructors with assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
FirentisTFW committed Nov 16, 2024
1 parent c275401 commit 0dbe556
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/util/dart_class_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ function parseLinesToClassFields(input: Array<string>): Array<DartClassField> {

function parseLinesToClassName(lines: Array<string>): string {
// TODO What about class modifiers? Are they used in widgets too?
return lines.find((line) => line.startsWith("class "))?.split(" ")[1] ?? "";
return (
lines
.find((line) => line.startsWith("class "))
?.split(" ")[1]
?.substringUpTo("<") ?? ""
);
}

function parseLinesToConstructors(
Expand All @@ -92,14 +97,11 @@ function parseLinesToConstructors(
let openParenthesisCount = 0;

for (let j = i; j < lines.length; j++) {
// FIXME Possibly many occurrences in one line?
if (lines[j].includes("(")) {
openParenthesisCount++;
}
if (lines[j].includes(")")) {
openParenthesisCount--;
for (const char of lines[j]) {
if (char === "(") openParenthesisCount++;
else if (char === ")") openParenthesisCount--;
}
if (openParenthesisCount > 0) {
if (openParenthesisCount > 0 && !lines[j].includes("assert(")) {
continue;
}

Expand Down

0 comments on commit 0dbe556

Please sign in to comment.