Skip to content

Commit 3a1b7ef

Browse files
committed
fix(preprocess-readme): check if ast instance is undefined
1 parent f7641f4 commit 3a1b7ef

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/preprocessReadme.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ export function preprocessReadme(opts: Partial<PreprocessReadmeOptions>): Pick<P
4545
if (lang === "svelte") {
4646
const { instance } = parse(source);
4747

48-
script_content = [
49-
...script_content,
50-
...source
51-
.slice(instance.start, instance.end)
52-
.split("\n")
53-
.slice(1, -1)
54-
.map((line) => line.trim().replace(new RegExp(opts.name!, "g"), opts.svelte!)),
55-
];
48+
if (instance !== undefined) {
49+
script_content = [
50+
...script_content,
51+
...source
52+
.slice(instance.start, instance.end)
53+
.split("\n")
54+
.slice(1, -1)
55+
.map((line) => line.trim().replace(new RegExp(opts.name!, "g"), opts.svelte!)),
56+
];
57+
}
5658

5759
const regex = new RegExp('"' + opts.name + '"', "g");
5860
const modifiedSource = encodeURI(source.replace(regex, '"' + opts.svelte + '"'));

0 commit comments

Comments
 (0)