Repository navigation
fix(core): report '}' expected for a missing closing brace (#583) - #590
Merged
Merged
Conversation
A missing `}` is reported as TypeScript reports it, `'}' expected.`, instead
of acorn's `Unexpected token`, for JavaScript and template blocks alike: at
the end of the input in every `{ … }` list, and after the expression of a
template literal's `${ … }` or an expression container. Unclosed
`@if`/`@for`/`@try` bodies at the end of the input, which parsed before,
report it too.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Parse every block shape from #583 in every parse mode and check the message and position, including directive bodies that used to parse, the unclosed-tag errors and recovery before a missing `}`, and other syntax errors that keep their messages. The language server shows the error with an empty range at the end of the document, and on the token found after a container's expression. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue. You can view the agent here.
Reviewed by Cursor Bugbot for commit 457a169. Configure here.
This was referenced Sep 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #583.
Phase 1 item 1.4 of #511 (decision 15): a missing
}is reported as'}' expected, like TypeScript, not as acorn's genericUnexpected token, for template and JavaScript blocks alike. This touches error reporting like #558 (item 1.3), so it was meant to merge after it. #558 is merged now, and this branch includes it (mainis merged in, with no rebase).The rule
The parser reports
'}' expected.(TypeScript's TS1005 text) where TypeScript's parser reports it, at the same position, throughthis.raise. So it is an ordinary syntax error with acorn's(line:column)suffix,pos, andloc:{ … }list: function and statement blocks (if/else, loops,try/catch/finally, labeled and plain blocks),switchbodies andcaseblocks, class bodies and static blocks, object literals and patterns, arrow and function-expression bodies, namespaces anddeclare module/global, enums, interfaces, type literals and mapped types, import and export lists andwith { … }, template literal${ … }, JSX containers and spreads, and TSRX's@{ … },@if/@else,@for/@empty,@switch/@case/@default, and@try/@pending/@catchbodies. The position is the end of the input, after trailing whitespace and comments, where acorn'sUnexpected tokenalready pointed, so only the message changes.}, where TypeScript reports it there too: after the expression of a template literal's${ … }(value or type), and after the expression of a JSX container ({value},{...spread}, an attribute's{…}, and TSRX's{name}attribute).@if,@else,@for,@empty,@try,@pending,@catch) used to be taken as closed. With nothing around them (const v = @if (ok) {and then the end of the file) the file parsed in every mode: it compiled, and both formatters printed a}that was never written. Inside an@{ … }the enclosing body reportedUnexpected token, inside an element the element was reported unclosed, and an open@trybody reported a missing@catch. They all report'}' expected.at the end of the input now.Everything else keeps its message and position. Where TypeScript reports something else first, the error is unchanged: a missing
)or], a missing expression ({ a +,{ if (x),x = { a:,<div>{,`${), a;or,expected at the next token (x = [{ a: 1 ];,const o = { a: 1then the next declaration), a mapped type followed by another member, an import attribute without its comma, and a decorator at the end of a class body (TypeScript:Declaration expected.). The tables in #583 give TypeScript's first parse diagnostic and position for each shape (TypeScript 5.9.3,ScriptKind.TSX), and whether it adds related information pointing at the opening{.Parse modes. A missing
}is a syntax error, not a type-check-level one, so it isn't in #558'sCHECKER_LEVEL_ERRORSand throws in strict, collect, and loose mode, like the unterminated@switcharm in #497. Loose mode's recoveries are unchanged: an unclosed tag, including an unclosed<style>(#71), is still recorded and parsed past (or thrown first, when not collecting), and the missing}after it now reads'}' expected.instead ofUnexpected token. The only inputs that parsed before and throw now are directive bodies left open at the end of the input, as described above.Language server. No change needed. It shows the thrown error as a
tsrx-compile-errordiagnostic frompos: at the end of the document the range is empty, like TypeScript's zero-length diagnostic, and after a container's expression it covers the token found (raisedAt), like TypeScript's. Two new tests cover both. TypeScript's related information (the opening{) isn't reproduced: aCompileErrorhas one position.Where the change lives
All in
TSRXPlugin(packages/tsrx/src/plugin.js), plus three method types intypes/parse.d.ts. The new methods are at the end of the class, away from #551's, #555's, and #558's overrides.expect(type):'}' expected.when a}is expected at the end of the input or after a template span's expression (the${context is under the current token); when a comma is expected at the end of the input right after an element of a{ … }list; and when an expected{is followed by the end of the input (aswitchbody before its firstcase, where acorn callsunexpected()itself). Every{that acorn, acorn-typescript, or TSRX expects opens a list.{ … }lists check for the end of the input before reading an element, and record where the element ended forexpect's comma check:parseProperty,parseImportSpecifier,parseExportSpecifier,tsParseEnumMember,tsParseTypeMember(one shared#parseBraceListElementwrapper),parseClassElement(not right after a decorator;parseDecoratorrecords where one ended), andparseStatementwithout acontext, which is the next statement of a block,case, or module body. Afterif (…),else, a loop head, or a label (contextset) it keepsUnexpected token, where TypeScript reports a missing expression.#parseCodeBlock(@{ … }, checked before the return-statement check now),#parseTemplateControlFlowBlock(the directive bodies, which didn't check at all), and the@switchbody when no@casefollows. The JSX container and spreadexpect(tt.braceR)calls go through#expectContainerClosingBrace, which reports at any token.No upstream issue: this is a message choice, not an acorn or acorn-typescript defect.
Verification
packages/tsrx/tests/utils/closing-brace.test.jsparses 84 JavaScript and 34 template shapes at the end of the input, 8 directive bodies that used to parse, and 12 template-span and container shapes with a token after the expression, in strict, collect, and loose mode, in a worker (parse_in_worker). Each checks the message and position. It also checks that an unclosed tag is still thrown first when not collecting and recovered in collect and loose mode, that 38 other syntax errors keep their messages, and that the shapes left out keep theirs (below). Two existing tests of the unterminated@switcharm (fix(core): stop an @switch arm body at the end of the input (#492) #497) now expect'}' expected.. The language server tests check the diagnostic's message, code, and range.main(935dfe42) against this branch, strict andparseModule(text, file, { collect: true, errors: [], comments: [], preserveParens: true }), in 4 worker threads with a hard timeout. The inputs are 16,803: the 69 tracked.tsrxfiles, the input and the output of all 2,040 Prettier snapshot cases inpackages/tsrx-prettier-plugin/tests/prettier/(readSnapshotEntries/readFormatCase), and 12,654 distinct string literals from test files. Without the 253 strings from this PR's own tests:.tsrxfile and no Prettier input or output changed at all;Unexpected tokento'}' expected., all at the same position;'}' expected.in both modes:@if (…) {and@for (…) {lines used as grammar and completion fixtures, which end in an open directive body.@trybodies and directive bodies inside an element, whose missing-@catchand unclosed-tag errors become'}' expected.at the end of the input).vitest run --maxWorkers=4fortsrx-utils,tsrx-analyze,tsrx-vite,prettier-plugin,tsrx-prettier-plugin,language-server,typescript-plugin,eslint-parser, and thetsrx-react/-preact/-solid/-vue/-honocompilers (which run the shared compile tests): 57 files, 8,655 passed, 7 expected failures, 70 skipped.pnpm typecheck: all 36 steps pass.tsrx-tscisn't linked afterpnpm install --ignore-scripts, so I built@tsrx/typescript-pluginand ran the@tsrx/vite-plugin-honotypecheck:testsstep throughpackages/typescript-plugin/dist/tsc.js.pnpm format:checkandpnpm changeset:checkpass. Changeset:patchfor@tsrx/core.Unexpected tokenfor a missing}. ThetoThrow(/Unexpected token/)tests intsrx-react,tsrx-vue, andprettier-pluginare about other errors and still pass.Findings
Left out, with their own issues because their causes are elsewhere (section F of #583's tables):
}before a closing tag reads</as less-than and a regular expression, unlike TSX #586:</right after an expression (<p>{count</p>) reads as<and a regular expression, so a missing}before a closing tag reportsUnterminated regular expressionpast the tag. TSX reads</as a closing tag and reports'}' expectedat it.importandexportinside a block, which TypeScript reports from its checker #587: collect mode throws forimportandexportinside a block, which TypeScript reports from its checker (TS1184, TS1232). With a missing}, the next top-levelexportlands in the block, and the editor shows that error instead of'}' expectedat the end of the file.constorvarwith no declarator and a barelet, which TypeScript reports from its checker #588: collect mode throws forconstorvarwith no declarator and a barelet, which TypeScript parses and reports from its checker (TS1123, TS1214), so{ constat the end of the input doesn't reach the missing}.Same cause as this issue, left out because acorn reads them differently before the list can see the end of the input (both keep
Unexpected tokenat the end of the input, a test pins them):x = { getat the end of the input: acorn takesgetas a getter's keyword and fails reading its name. TypeScript reads a shorthand property and reports'}' expected.import a from './a.json' with { type: 'json',at the end of the input: acorn-typescript reads the attribute list in one loop, which reads a key after the comma. The same list without the trailing comma reports'}' expected.Also:
@finally, which #583's brief listed, isn't TSRX syntax (@trytakes@pendingand@catch), so it has no body to report.🤖 Generated with Claude Code
Note
Medium Risk
Parser error messaging and EOF acceptance change affects all parse modes and previously-valid open directive snippets; scope is diagnostics/parse failure only, not runtime semantics for successfully parsed files.
Overview
The TSRX parser now surfaces missing
}as TypeScript’s'}' expected.(TS1005) instead of acorn’sUnexpected token, at the same positions: EOF inside brace-delimited JS/TS/template constructs (@{…},@if/@for/@switch/@try, blocks, objects, imports,${…}, JSX{…}, etc.) and on the token after an expression when a container’s closing}is absent.Behavior fix: standalone directive bodies left open at EOF (e.g.
const v = @if (ok) {) no longer parse silently; they error with'}' expected.instead of compiling/formatting with an implicit}.Implementation is centralized in
TSRXPluginvia#raiseClosingBraceExpected,#expectContainerClosingBrace, brace-list tracking in overriddenexpect/parseProperty/ import-export / enum / type members /parseClassElement, plus EOF checks on template code blocks and control-flow bodies. Other syntax errors and unclosed-tag precedence in non-collect modes are unchanged. Tests and a@tsrx/corepatch changeset document the rule; language-server tests asserttsrx-compile-errormessage and range (empty at EOF, token span after containers).Reviewed by Cursor Bugbot for commit 333f6ce. Bugbot is set up for automated code reviews on this repo. Configure here.