Files
test-repo/changelog_unreleased/json/10346.md
T

657 B

Stricter JSON parser (#10346, #10443, #10456, #10434 by @fisker)

Prettier internally uses a JavaScript expression parser to parse JSON. That's why the json and json5 parsers used to be very forgiving and allowed all kinds of JavaScript expressions. Now they are much stricter, although some simple non-standard syntax is still allowed (e.g., JSON6 is supported, except for multiple minus signs: ----123).

// Input
[1, 2, 1 + 2]

// Prettier stable
[1, 2, 1 + 2]

// Prettier main
SyntaxError: BinaryExpression is not allowed in JSON. (1:8)
> 1 | [1, 2, 1 + 2]
    |        ^