Repository navigation
fix(core): parse with the latest ECMAScript version and upgrade acorn (#414) - #452
Merged
Merged
Conversation
…#414) Parse with acorn's `ecmaVersion: 'latest'` instead of 13 (ES2022), so the parser accepts hashbangs, `using` / `await using` declarations, and the regex `v` flag and modifiers, and upgrade acorn to 8.18.0. Keep a hashbang as the first line of compiled and type-only output (esrap would print the parser's hashbang comment as `//…`), put the Vite dep-scan prelude after it, and print it as written in the Prettier plugin. Reject `using` in `for...in` heads like acorn's own `parseForAfterInit`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 25, 2026
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 d587bf4. Configure here.
… it (#414) Empty statements take no comments, so in `#!…\n;\nfoo();` the parser attaches the hashbang to a later statement than the first, where markHashbangComment didn't look, and the formatter printed it as `///usr/bin/env node`. Find it by position instead: the `Line` comment at offset 0 of a file that starts with `#!`, on whichever node holds it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
leonidaz
added a commit
that referenced
this pull request
Sep 25, 2026
…ixes on main With #452 (latest ECMAScript version), #404 and #427 (statement boundaries) on main, 29 cases the parser used to reject now parse and format like Prettier, and so does a call whose type arguments start on the next line. The fragment with a comment after `<` now parses but hits #467. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 task done
domgan-oai
pushed a commit
that referenced
this pull request
Sep 25, 2026
…ested with Prettier's own tests (#409) * feat(tsrx-prettier-plugin): add a Prettier plugin built on Prettier's own printer A new, unpublished package that formats everything except TSRX syntax with Prettier's `estree` printer (`prettier/plugins/estree`), instead of printing every node itself like `@tsrx/prettier-plugin`: - The parser reshapes the acorn-typescript AST into the typescript-estree shape Prettier expects, and hands Prettier the comments to attach. - The printer prints `@{ … }`, `@if`, `@for`, `@switch`, `@try`, `{value}` shorthand props, and `<style>`/`<script>` bodies (as CSS/TypeScript), and delegates the rest. Directive heads are laid out like their statements. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(tsrx-prettier-plugin): run Prettier's own JavaScript, JSX, and TypeScript format tests `scripts/import-prettier-tests.js` imports the cases of Prettier's format tests (3.9.6) that apply to TSRX: Prettier's `typescript` parser prints the snapshot's output, and the input is valid TSX in a strict-mode module. The 2044 imported cases run through the plugin: 1807 pass, and 251 known failures (122 of them rejected by the TSRX parser) run as expected failures until fixed. Overrides record where TSRX deliberately differs (`<T,>` arrow type parameters, CommonJS `await(…)`). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tsrx-prettier-plugin): end statements where Prettier's parsers do Prettier attaches comments using its parsers' `locEnd`, which ends a statement where its content ends: before a semicolon that comments separate from it (`__contentEnd`), at the keyword or label of `break`, `continue`, and `debugger`, at the last declarator, and at the body of `if`, loops, and labeled statements. Match it, so comments near those statements attach like Prettier's instead of moving or going unprinted. 39 more Prettier cases pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tsrx-prettier-plugin): reshape the AST like Prettier's parser postprocess Port the steps of Prettier's `parse/postprocess` that the printer relies on: rebalance same-operator logical expressions (`a || (b || c)`), drop unions and intersections of one type, join touching JSDoc comments, and make the program span the whole text. Also rebuild the whitespace between JSX children, which the TSRX parser leaves out of its text nodes and Prettier reads to keep blank lines and choose line breaks. 32 more Prettier cases pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tsrx-prettier-plugin): reshape accessors, import options, dotted namespaces, and export import Match typescript-estree where the acorn-typescript AST differs: `accessor` fields become `AccessorProperty`, dynamic `import()` options move from `arguments` to `options`, `namespace A.B {}` is one declaration named by a qualified name, and `export import a = A` is an export of the import-equals declaration. The printer also sees the options as its own `typescript` parser's, since it checks the parser name for TypeScript-only rules such as keeping the quotes of class property keys. 41 more Prettier cases pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(tsrx-prettier-plugin): leave out Prettier's sloppy-mode tests A `.tsrx` file is a strict-mode module, so the importer now also leaves out Prettier's `js/sloppy-mode` tests and `interface` used as a name, which the TSRX parser rightly rejects. The rejection messages ("Unexpected token") don't say strict mode, so the check uses the directory. The known-failures check also no longer compares against the list while it is being rewritten. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(tsrx-prettier-plugin): keep comments between JSX children in place TSRX reads `//` and `/* */` between JSX children as comments, where TSX reads text, and Prettier's JSX printer has no place for them. The adapter now rebuilds each element's text children from the source and turns such a comment into a `TSRXJSXComment` child. Elements with comment children are laid out by a copy of Prettier's `printJsxElementInternal`/`printJsxChildren` (`src/jsx.js`) in which a comment keeps its line: one on its own line stays there, one after other content stays on that line, a line comment always ends its line, and JSDoc-style block comments are re-indented. Every other element is still printed by Prettier. Comments are also given their source text: the core parser dedents a multi-line block comment's value for its own printer, which moved the lines of such comments. All 69 `.tsrx` files in the repository now format stably, and 9 more Prettier cases pass (one, where TSX reads the text as text, is an override). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tsrx-prettier-plugin): reshape decorators and heritage names, and reject recovered markup - Decorators on a constructor parameter property belong to the `TSParameterProperty`, as in typescript-estree. - `export default @d class {}` declares an anonymous class; only a parenthesized class stays a `ClassExpression`. - `extends a.b.C` in `implements`/interface heritage is a member expression, not a qualified type name. - The parser collects errors so that mistakes TypeScript reports only as diagnostics (a redeclared variable) still format. But after an unclosed or mismatched tag it guesses the markup's structure, and formatting that guess garbles the file, so those errors are now thrown like any parse error. 6 more Prettier cases pass. The two layout failures left are parser issues: #439 (`static` before a line break) and TSRX's line-start tag rule. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(tsrx-prettier-plugin): format only code scripts, with this plugin's parser A `<script>` body is now formatted only when it holds JavaScript or TypeScript (no `type`, `module`, or a JavaScript/TypeScript type, as in Prettier's HTML printer). JSON, import maps, and other bodies are kept as written, instead of being reformatted as code (`[1,2]` became `[1, 2];`, which isn't JSON; #441 for `@tsrx/prettier-plugin`). Code bodies are formatted with this plugin's `tsrx` parser instead of Prettier's `typescript`, so `prettier/standalone` needs no other plugin; a test runs the plugin there alone. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(tsrx-prettier-plugin): refresh Prettier's cases for the parser fixes on main With #452 (latest ECMAScript version), #404 and #427 (statement boundaries) on main, 29 cases the parser used to reject now parse and format like Prettier, and so does a call whose type arguments start on the next line. The fragment with a comment after `<` now parses but hits #467. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(tsrx-prettier-plugin): refresh Prettier's cases for #471 With #471 on main, the 6 cases behind #416 and #419 parse and format like Prettier. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(tsrx-prettier-plugin): give `@{ … }` values and directives JSX's parentheses Like `@tsrx/prettier-plugin` on main, and as Prettier lays out a JSX element: a directive, or a `@{ … }` block used as a value, is wrapped in `(` … `)` where it is assigned, returned, thrown, or an arrow's body (a `@{ … }` arrow or function body stays on its line), with its comments inside the parentheses. While its parent prints, such a value presents itself as a JSX element, so Prettier's JSX-specific layout applies too, such as keeping a last-argument arrow on the call's line (`list.map((item) => (` … `))`). Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(tsrx-prettier-plugin): refresh Prettier's cases for #495 With #495 on main, the parser reads JSX spread children, and Prettier's `jsx/spread/child.js` case formats like Prettier. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(tsrx-prettier-plugin): skip Prettier's private field destructuring cases Destructuring private fields (`const { #x: x } = this`) is a TC39 Stage 2 proposal, which TSRX will parse once it becomes part of JavaScript. Its 8 Prettier cases are skipped with that reason instead of listed as known failures (#424). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Sep 25, 2026
This was referenced Oct 2, 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 #414.
Summary
createParserin@tsrx/coreparses with acorn'secmaVersion: 'latest'instead of13(ES2022). The parser now accepts a hashbang on the first line,using/await usingdeclarations (with TypeScript annotations, and infor...of/for await...ofheads), the regexvflag, and regex modifiers.^8.17.0(locked 8.17.0) to^8.18.0(locked 8.18.0), and the lockfile's one remaining@sveltejs/[email protected]is deduped to 1.0.13. See acorn upgrade.onCommentas aLinecomment at offset 0. Two consumers mishandled that comment, so this PR fixes them: compile output dropped the hashbang, and the Prettier plugin printed it as///usr/bin/env node. See Hashbang.parseForAfterInitWithIndexoverride now rejectsusingin afor...inhead, like acorn's ownparseForAfterInitdoes. Before this PR theusingbranch inparseForStatementnever ran, because acorn only recognizesusingatecmaVersion17 and above. Once it ran, the override acceptedfor (using x in y).Changes
packages/tsrx/src/parse/index.jsecmaVersion: 'latest'packages/tsrx/types/parse.d.tsParse.ParseInputOptionsfor the staticparse. It takes acorn'secmaVersionvalues such as'latest', whileParse.Options.ecmaVersionstays the normalized number thatthis.optionsholdspackages/tsrx/src/plugin.jsfor...in+usingcheck, and an updated comment that still described TSRX as parsing at 13packages/tsrx/src/comment-utils.jsget_hashbang(source)packages/tsrx/src/transform/jsx/helpers.js,transform/jsx/index.jstsx_with_ts_locations(…, hashbang)writes the hashbang as the first line of every target's build and type-only output, mapped to 1:0, and never prints the offset-0 comment as a preserved commentpackages/tsrx/src/vite/dep-scan.jsimport "react/jsx-runtime";…) goes after a hashbang instead of before itpackages/prettier-plugin/src/index.jsparserecords the hashbang comment andprintCommentprints it as#!…pnpm-workspace.yaml,pnpm-lock.yaml@sveltejs/acorn-typescriptdedupe.changeset/parser-latest-ecma-version.mdpatchfor@tsrx/coreand@tsrx/prettier-pluginTests are added to the existing files:
tests/utils/parser.test.jscovers each syntax without options, with the formatter's{ collect: true, comments: [] }, and in loose mode. It also checks that a hashbang not at the start is still rejected and thatusinginfor...inis rejected.tests/shared/compile.jsruns for React, Preact, Solid, Vue, and Hono. It checks hashbang preservation in build output with and withoutcollect,using/await using/ regex output, and the type-only virtual code: hashbang first, no TS parse diagnostics, mappings after the hashbang still exact.tests/vite/dep-scan.test.jschecks the prelude after a hashbang for both plugin kinds.tests/utils/platform.test.jsrunsreplacePlatformFlagson a module with a hashbang,using, and avregex. The Turbopack plugin runs this over every non-foreign.js/.tsfile when a platform is configured, and those files used to fail to parse.prettier-plugin/src/index.test.jschecks that hashbangs,usingdeclarations, and regexes are kept. It also checks that a real///usr/bin/env nodecomment stays a comment.All 33 new tests fail with the source changes reverted.
Hashbang: what each consumer does with it
Before this PR every consumer failed at parse time (
Unexpected character '!'). The table shows what each consumer did withecmaVersion: 'latest'alone, and what it does now.'latest'onlycompile()for React, Preact, Solid, Vue, Hono (server and dom), with and withoutcollect#!/usr/bin/env nodeis line 1, once, ahead of injected imports (vue-jsx-vapor, runtime helpers); source map maps it to 1:0compile_to_volar_mappings()(type-only TSX used by the language server,typescript-plugin,tsrx-tsc)// @…survivecreateDepScanTransformPlugin/createDepScanLoadPlugin)replacePlatformFlags(Turbopack platform loader)packages/prettier-plugin///usr/bin/env nodetypescriptoutput@tsrx/eslint-parser#!with//before calling any parser (languages/js/index.js)A hashbang is never turned into
// …, moved, or duplicated in any of these outputs.usingin compile outputA component with
usingat module scope, in the component body, in@if/@for/@try/@switchcase bodies and nested code blocks, plus a function withawait using(multiple declarators),for (using x of y), andfor await (await using x of y), compiles in all five targets, in build and type-only output, with every declaration printed unchanged by esrap (kind: 'using'/'await using')./[\p{L}--[a-z]]/vand/(?i:a)b/print unchanged too. The generated code has no TypeScript parse diagnostics.The exception is a
usingdeclaration in a template@forhead,@for (using item of items). It compiles, but the loop variable becomes a plain callback parameter and the item is never disposed. That's a separate root cause in the@forlowering, filed as #453.Other
ecmaVersionsettingsgit grep ecmaVersion(excludingnode_modules):packages/tsrx/src/parse/index.js'latest'packages/tsrx/src/plugin.js(this.options.ecmaVersion >= 6/8/9)packages/tsrx/types/parse.d.tsParseInputOptions(above)packages/eslint-plugin/src/index.ts(parserOptions.ecmaVersion: 'latest').tsrxfiles'latest'.@tsrx/eslint-parserignoresparserOptions.ecmaVersionand always callsparseModule, so it follows the core change automatically. ESLint's scope analysis useslanguageOptions.ecmaVersion, default'latest'. Linting a.tsrxfile withusingand a hashbang throughLinterworkspackages/eslint-plugin/tests/rules/*.test.ts(parserOptions.ecmaVersion: 2022)No other package parses TSRX or JS itself. The language server,
typescript-plugin, and the target compilers all go through@tsrx/core'sparseModule, and the TypeScript side already usesScriptTarget.Latest/ESNext. The build plugins' esbuild/oxc targets are allesnext.acorn upgrade
npm view acorn versiongives 8.18.0, published 2026-07-28T06:47:49Z (npm view acorn time).pnpm-workspace.yamlhasminimumReleaseAge: 1440(one day), which 8.18.0 is well past, so nominimumReleaseAgeExcludeentry is needed.pnpm install --frozen-lockfilereports "Lockfile passes supply-chain policies". 8.18.0 adds astartLocationoption and rejects**with an unparenthesized arrow function on its left (() => {} ** x). The AST comparison below found no other change.@sveltejs/acorn-typescript1.0.13 declarespeerDependencies: { acorn: "^8.9.0" }, so it accepts 8.18.0. It only comparesecmaVersionagainst lower bounds (6 to 13), so'latest'doesn't change its behavior.@tsrx/core's importer move to[email protected]/@sveltejs/[email protected]([email protected]). A plainpnpm installalso re-resolvedespreeand the external@tsrx/[email protected]from acorn 8.16.0 to 8.17.0; I kept those as they were.pnpm install --lockfile-onlyleaves the result unchanged.@sveltejs/acorn-typescriptin the tree,1.0.10([email protected]), is deduped to1.0.13([email protected]). It came from the published@tsrx/[email protected](via[email protected], a dependency of@tsrx/typescript-pluginandtsrx-website), which declares@sveltejs/acorn-typescript: ^1.0.10, so no override was needed. The tree now has one@sveltejs/acorn-typescriptversion with three peer variants (acorn 8.16.0 for@tsrx/[email protected], 8.17.0 for@tsrx/[email protected]via@tsrx/ripple/ripple/@ripple-ts/vite-plugin, 8.18.0 for the workspace). External packages keep their locked acorn: espree 11.2.0 and@tsrx/[email protected]on 8.16.0,@tsrx/[email protected]on 8.17.0. Their ranges allow 8.18, but moving them isn't needed here.minimumReleaseAgeExcludestill lists@sveltejs/[email protected](published 2026-08-13), which it no longer needs. Left as is.Verification
AST comparison. Only the new syntax changes. The corpus has 6,538 unique sources:
.tsrxfiles in the repoEach source is parsed plain, with
{ collect: true, comments: [] }, and in loose mode, for 19,614 parses. Each result (AST including comments and collected errors, or the error message) is hashed and compared. The baseline isorigin/main's parser with acorn 8.17.0 andecmaVersion: 13; this branch uses acorn 8.18.0 and'latest'. 19,455 results are identical. The rest are the 26 distinct Prettier inputs behind #414's 28 cases, which go from errors to ASTs, and the new-syntax sources in the tests this PR adds. Acorn 8.17.0 vs 8.18.0 atecmaVersion: 13alone: identical.#409's harness. The 28 cases #414 lists all pass when run through #409's plugin on top of this branch's
@tsrx/core(outside #409's worktree, using its own harness logic, overrides, and snapshots).Checks.
pnpm test(118 files, 6,382 passed, 60 skipped; eslint-parser, typescript-plugin, and language-server built first),pnpm typecheck,pnpm format:check, andpnpm changeset:checkall pass.Note for #409
#409 (the new
tsrx-prettier-plugin) lists 28 Prettier test cases under #414 inprettier-known-failures.json. They start passing once this merges, and a listed case that passes fails #409's run, so its known-failures list needs a refresh (UPDATE_KNOWN_FAILURES=1 pnpm test --project tsrx-prettier-plugin). This PR doesn't touch #409's files.Related findings
@for (using item of items)drops theusing, so template loop items are never disposed #453:@for (using item of items)in a template compiles to a plain callback parameter in every target, so the item is never disposed and the virtual TypeScript doesn't check it'sDisposable. It's reachable only with this PR.@tsrx/eslint-parserreturnsast.comments || []andast.tokens || [], but the parser collects comments into a separate array, so ESLint gets no comments or tokens for.tsrxfiles.// eslint-disable-next-lineand other directive comments are ignored. This is pre-existing and unrelated to the ECMAScript version.usingandawait usingdeclarations as errors #455: the tree-sitter grammar parsesusing/await usingasERRORnodes, and the TextMate grammar doesn't highlightusingas a keyword. Hashbangs and thevflag are fine in both.js/explicit-resource-management/invalid-duplicate-using-bindings.jspasses because feat: add tsrx-prettier-plugin, built on Prettier's own printer and tested with Prettier's own tests #409 parses withcollectand anerrorsarray. A plain parse throws acorn'sIdentifier 'f' has already been declared, as it already does for duplicatelet/const.🤖 Generated with Claude Code
Note
Medium Risk
Touches the core parser and all compile/format/scan output paths; behavior change is intentional but affects every
.tsrxand plain JS/TS module parsed by the toolchain.Overview
Parser and acorn now use
ecmaVersion: 'latest'(was ES2022 /13) with acorn 8.18.0, so modules can parse hashbangs,using/await using(including infor...ofheads), and regexvflags and modifiers. The TSRX parser rejectsusinginfor...inloops to match acorn.Hashbang preservation is wired through the pipeline:
get_hashbangdrives compile/type-only output (tsx_with_ts_locations) as the first line without duplicating the offset-0 line comment; Vite dep-scan prepends runtime imports after the hashbang; the Prettier plugin marks and prints#!…instead of//….Types add
ParseInputOptionsfor acorn’secmaVersioninput shape. Broad tests cover parsing, compile, dep-scan, platform flag pass, and Prettier formatting for the new syntax.Reviewed by Cursor Bugbot for commit 8b91879. Bugbot is set up for automated code reviews on this repo. Configure here.