diff --git a/e2e-tests/code-editing-and-ast-interaction.test.ts b/e2e-tests/code-editing-and-ast-interaction.test.ts index ee2df7de..74b84feb 100644 --- a/e2e-tests/code-editing-and-ast-interaction.test.ts +++ b/e2e-tests/code-editing-and-ast-interaction.test.ts @@ -593,6 +593,34 @@ test.describe("AST node expansion", () => { page.getByRole("button", { name: "6. RBrace" }), ).toBeVisible(); }); + + test("Allow Trailing Commas: true, then Mode: JSON", async ({ + page, + }) => { + // `Mode`: `JSONC` + await setComboboxOption(page, "Mode", "jsonc"); + + // `Allow Trailing Commas`: `true` + await setSwitchOption(page, "Allow Trailing Commas", true); + + // `Mode`: `JSON`, which hides the `Allow Trailing Commas` switch. + await setComboboxOption(page, "Mode", "json"); + + // Hide the settings menu to ensure it doesn't interfere with the test. + await page.keyboard.press("Escape"); + + // Fill a JSON sample with a trailing comma into the editor. + await page + .getByRole("textbox", { exact: true, name: "Code Editor" }) + .fill('{"foo":"bar",}'); + + // Verify that the trailing comma is still a parse error in JSON mode. + await expect( + page.getByText("Error: Unexpected token RBrace found. (1:14)", { + exact: true, + }), + ).toBeVisible(); + }); }); test.describe("Language: Markdown", () => { diff --git a/src/hooks/use-ast.ts b/src/hooks/use-ast.ts index 0f92c687..bdecf0d0 100644 --- a/src/hooks/use-ast.ts +++ b/src/hooks/use-ast.ts @@ -57,9 +57,8 @@ export function useAST() { bom: false, }, { - languageOptions: { - allowTrailingCommas, - }, + languageOptions: + jsonMode === "jsonc" ? { allowTrailingCommas } : {}, }, ); break;