Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions e2e-tests/code-editing-and-ast-interaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
5 changes: 2 additions & 3 deletions src/hooks/use-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ export function useAST() {
bom: false,
},
{
languageOptions: {
allowTrailingCommas,
},
languageOptions:
jsonMode === "jsonc" ? { allowTrailingCommas } : {},
},
);
break;
Expand Down
Loading