Skip to content

Commit 46877af

Browse files
committed
fix: parse prefs.js without semicolons
1 parent 56001a1 commit 46877af

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

packages/scaffold/src/utils/prefs-manager.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ describe("prefs-manager", () => {
4949
expect(result["test.stringified.false"]).toBe("false");
5050
});
5151

52+
it("should correctly parse prefs.js without `;`", () => {
53+
const result = prefsManager.parse(`pref("test.withoutsimi", "false")`);
54+
expect(result["test.withoutsimi"]).toBe("false");
55+
});
56+
5257
it("should correctly parse a prefs.js file", async () => {
5358
const fakePrefsContent = `
5459
pref("test.string", "hello");

packages/scaffold/src/utils/prefs-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class PrefsManager {
1515
parse(content: string) {
1616
const _map: Prefs = {};
1717
// eslint-disable-next-line regexp/no-super-linear-backtracking
18-
const prefPattern = /^(pref|user_pref)\s*\(\s*["']([^"']+)["']\s*,\s*(.+)\s*\)\s*;$/gm;
18+
const prefPattern = /^(pref|user_pref)\s*\(\s*["']([^"']+)["']\s*,\s*(.+)\s*\)\s*;?$/gm;
1919
const matches = content.matchAll(prefPattern);
2020
for (const match of matches) {
2121
const key = match[2].trim();

0 commit comments

Comments
 (0)