Skip to content

Commit 473a548

Browse files
authored
Merge pull request #196 from takker99:fix-project-link-detection
fix: `/*@__PURE__*/` is not a project link
2 parents a59ab5b + d2e6eaa commit 473a548

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

parseLink.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@ Deno.test("internal link", () => {
6262
title: "title/with#/",
6363
});
6464
});
65+
66+
Deno.test("project-like title", () => {
67+
assertEquals(parseLink({ pathType: "root", href: "/*@__PURE__*/" }), {
68+
title: "/*@__PURE__*/",
69+
});
70+
});

parseLink.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,20 @@ export const parseLink = (
1515
title: string;
1616
hash?: string;
1717
} => {
18-
if (link.pathType === "root") {
18+
root: if (link.pathType === "root") {
1919
const [, project = "", title = ""] = link.href.match(
2020
/\/([\w\-]+)(?:\/?|\/(.*))$/,
2121
) ?? ["", "", ""];
22-
if (project === "") {
23-
throw SyntaxError(`Failed to get a project name from "${link.href}"`);
24-
}
22+
if (project === "") break root;
2523
const [, hash] = title?.match?.(/#([a-f\d]{24,32})$/) ?? ["", ""];
2624
return title === ""
2725
? { project }
2826
: hash === ""
2927
? { project, title }
3028
: { project, title: title.slice(0, -1 - hash.length), hash };
31-
} else {
32-
const [, hash] = link.href.match(/#([a-f\d]{24,32})$/) ?? ["", ""];
33-
return hash === ""
34-
? { title: link.href }
35-
: { title: link.href.slice(0, -1 - hash.length), hash };
3629
}
30+
const [, hash] = link.href.match(/#([a-f\d]{24,32})$/) ?? ["", ""];
31+
return hash === ""
32+
? { title: link.href }
33+
: { title: link.href.slice(0, -1 - hash.length), hash };
3734
};

0 commit comments

Comments
 (0)