Repository navigation
fix(cli): upgrade reads each TypeScript file in its own grammar - #11863
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
|
Packed-install check (same two files in
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
Requesting changes. The grammar fix works: both failing cases from the description now parse, and the existing upgrade suites pass unchanged. A CI test fails, and two claims about the fix do not match what the code does.
- CI's
test-node (6/7)job, and with it the aggregatetestcheck, fails onpackages/cli/foundation/doc-compiler/doc-loads.test.mjs:1379because the two new requires inrun-codemod.mjs:88-89(@babel/parserand jscodeshift's./parser/tsOptions.js) are missing from its inventory of modules that run code outside their static imports, so please add aRUNNERSentry forassets/codemods/run-codemod.mjswith exactly those two sites. - The changeset (line 5), the description and the
grammarOfcomment (run-codemod.mjs:57) say a generic arrow such as<T>(value: T) => valuestoppedastryx upgrade, but the previous TSX parser already reads it (on the base, a file holding only that arrow upgrades without an error), so please drop the generic arrow from those texts and retitle the test atrun-codemod.test.mjs:199. - The title and the changeset's opening sentence promise that each TypeScript file is read in its own grammar, but
grammarOf(run-codemod.mjs:64) recognises only.d.ts,.d.mtsand.d.cts, so a TypeScript arbitrary-extension declaration file such asstyles.d.css.tsstill fails withMissing initializer in const declaration; either follow TypeScript's rule (for example/\.d\.([^/\\]+\.)?ts$|\.d\.[cm]ts$/with a grammar-table case) or narrow the wording to those three extensions.
Claims and files checked
Review mode: full; reason: no-earlier-review
- Claim: a
.tsfile with a type assertion is reported as a parse error and the upgrade fails with exit 1. Verified: reproduced on the base (Unexpected token,Upgrade failed, exit 1). - Claim: a
.tsfile with a generic arrow is reported as a parse error. False: the base parses it, and a file holding only that arrow produces no error. - Claim: a declaration file with a value-less declaration is reported as a parse error. Verified:
Missing initializer in const declarationon the base. - Claim: the cause is that every
.tsfile, declaration files included, is parsed with the TSX grammar. Verified: the base's runner choosestsxfor.tsxand.tsin both codemod paths. - Claim: each file gets its own grammar (TSX, TypeScript without JSX, declaration mode, Babel). Verified for the listed extensions by the grammar table; TypeScript's
*.d.<ext>.tsdeclaration files are not covered (second finding). - Claim: one
grammarOfdecides, both config and code codemods bind with it, and the declaration parser is built once. Verified:run-codemod.mjs:63-98,:317,:544. - Claim: the CLI's ambient jscodeshift declaration accepts a parser object and the published authoring types are unchanged. Verified:
jscodeshift.d.ts:13; the authoring type file is untouched and the packed type surface check passes. - Claim: the reproduction prints both errors, finds 0 changes and ends with
Upgrade failed(exit 1). Verified: the errors appear under the five codemods that parse those files. - Claim: after the change both files parse, a codemod with declared words skips them, one without reads them, and one that changes them rewrites them in place. Verified: the new tests pass on the head and fail on the base; the same upgrade run exits 0.
- Claim:
.tsx,.jsxand.jskeep their parsers and the codemod, upgrade API and upgrade command suites pass unchanged (109 files, 1,291 tests). Verified: 109 files, 1,291 passed, 2 expected failures; a CLI test outside those suites fails (first finding). - Claim: the strict CLI typecheck and the published type-surface check pass. Verified for the changed files; the type-surface check passes.
- Claim: no new public API, default or interaction model, and no internal context. Verified.
- File
.changeset/upgrade-typescript-grammar.md: first finding. - File
packages/cli/assets/codemods/run-codemod.mjs: all three findings (:57comment,:64declaration-file test,:88-89unlisted requires). - File
packages/cli/assets/codemods/run-codemod.test.mjs: clear apart from the generic-arrow wording in the first finding. - File
packages/cli/assets/codemods/runner.mjs: clear. - File
packages/cli/assets/codemods/integration-runner.mjs: clear. - File
packages/cli/assets/codemods/jscodeshift.d.ts: clear.
A .ts file is TypeScript without JSX and a .d.ts file holds declarations, but the codemod runner parsed both with the TSX grammar. A type assertion (<Item>value), a generic arrow (<T>(value: T) => value) or a declaration without a value (export const limit: number;) failed to parse, and a file that fails to parse fails the upgrade even when no codemod would change it. Each file now parses in its own grammar: TSX for .tsx, TypeScript for .ts/.mts/.cts, TypeScript in declaration mode for .d.ts/.d.mts/.d.cts, and Babel for JavaScript, as before.
The declaration-file grammar loads jscodeshift's Babel parser and its TypeScript parser options on first use; the runtime-load list names them.
b3f0c3c to
0d29c5a
Compare
…-arrow claim A .ts file whose name holds .d. (an arbitrary-extension declaration file, such as styles.d.css.ts) is a declaration file too. The TSX grammar already read a generic arrow, so the fix and its tests name only the type assertion and declarations without values.
There was a problem hiding this comment.
Approving, pending CI: some required CI jobs had not finished on this head when this review was written.
All three points from the previous review are fixed: the load-inventory test now lists the two new requires, the generic-arrow claim is gone from the changeset, description and comment, and arbitrary-extension declaration files such as styles.d.css.ts now parse. On the base, astryx upgrade fails on a .ts type assertion or a value-less declaration in a declaration file; on this head the same run finishes cleanly, and the existing codemod and upgrade suites pass unchanged.
Claims and files checked
Review mode: full; reason: rebase
- Changeset: upgrade reads a
.tsfile as TypeScript without JSX and a declaration file as declarations, as TypeScript does. Verified:grammarOfandparserForinrun-codemod.mjs, and the grammar table test, follow TypeScript's declaration-file naming rule. - Changeset: a type assertion in a
.tsfile, or a value-less declaration in a.d.ts,.d.mts,.d.ctsor arbitrary-extension declaration file, no longer stops the run. Verified: an upgrade over.ts,.d.tsand.d.css.tsfixtures fails on the base and succeeds on the head;.d.mtsand.d.ctsfiles, which integration codemods that list those extensions read, fail on the base and parse on the head. - Changeset: a codemod changes such a file like any other. Verified: the rename test rewrites a
.tstype assertion and a.d.tsdeclaration in place. - Changeset:
.tsxand JavaScript read as before. Verified:.tsx,.jsx,.js,.mjsand.cjsbind the same parsers. - Description: valid TypeScript makes the upgrade fail with exit 1 even when no codemod would change the file. Verified on the base.
- Description: the cause is the TSX grammar for every
.tsfile, declaration files included. Verified: the base chosetsxfor.tsin both codemod paths. - Description: each file gets its own grammar (TSX, TypeScript without JSX for
.ts/.mts/.cts, declaration mode for declaration files as TypeScript names them, Babel for JavaScript). Verified: grammar table test and the code. - Description: TypeScript allows JSX only in
.tsx, so a.tsfile never needs the TSX grammar. Verified: no repository TypeScript file that parsed before fails in the new grammar. - Description: the runner chose TSX for
.tsfiles when it moved off the plain Babel grammar. Verified: that earlier change replaced a Babel-only choice for.tswith the TSX grammar. - Description: one
grammarOfdecides, both codemod paths bind with it, and the declaration parser is built once on first use. Verified:run-codemod.mjs:65-105,:324and:551. - Description: the CLI's own jscodeshift declaration accepts a parser object, the runners type the module with it, and the published authoring types are unchanged. Verified:
jscodeshift.d.ts:13,runner.mjs:578,integration-runner.mjs:43; the packaged type-surface check passes. - Description: on current main the reproduction prints both errors under every codemod, finds 0 changes and ends with
Upgrade failed(exit 1). Verified: the errors appear under each of the five codemods that read those files. - Description: after the change both files parse; a codemod with declared words skips them, one without reads them, and one that changes them writes them in their own grammar. Verified: the new tests fail on the base and pass on the head.
- Description:
.tsx,.jsxand.jsbind the same parsers, and the codemod, upgrade API and upgrade command suites pass unchanged (109 files, 1,291 tests). Verified: 109 files and 1,291 tests pass, with 2 expected failures. - Description: the regression tests add a grammar table, error-free runs and an in-place rename, and
doc-loads.test.mjslists the two parser modules. Verified: the inventory test passes on the head. - Description: the strict CLI typecheck and the published type-surface check pass. Verified: CI's typecheck job passed on this head, and the type-surface check passes.
- Description: one defect is restored, with no tagalong, no new public API, default or interaction model, and no internal context. Verified.
- File
.changeset/upgrade-typescript-grammar.md: clear. - File
packages/cli/assets/codemods/run-codemod.mjs: clear. - File
packages/cli/assets/codemods/run-codemod.test.mjs: clear. - File
packages/cli/assets/codemods/runner.mjs: clear. - File
packages/cli/assets/codemods/integration-runner.mjs: clear. - File
packages/cli/assets/codemods/jscodeshift.d.ts: clear. - File
packages/cli/foundation/doc-compiler/doc-loads.test.mjs: clear.
User impact
astryx upgradefails on a TypeScript project whose sources use ordinary TypeScript syntax. A.tsfile with a type assertion (<Item>value), or a declaration file with a declaration that has no value (export const limit: number;), is reported as a parse error, and the run ends withUpgrade failed(exit 1) even when no codemod would change that file. The project cannot be upgraded until those files are moved out of--path.Problem and solution fit
.tsfile, declaration files included, with the TSX grammar.<Item>valueas JSX, and code may not declare aconstwithout a value, so valid files do not parse; a file that does not parse is reported and fails the run (a codemod cannot prove an unparseable file needs no change).The fix gives each file its own grammar: TSX for
.tsx, TypeScript without JSX for.ts/.mts/.cts, TypeScript in declaration mode for a declaration file as TypeScript names one (.d.ts,.d.mts,.d.cts, or a.tsfile whose name holds.d., such asstyles.d.css.ts), and Babel for JavaScript as before. TypeScript allows JSX only in.tsxfiles, so a.tsfile never needs the TSX grammar.Expected behavior and authority
TypeScript's own rules: JSX is allowed only in
.tsxfiles, and a declaration file holds declarations without values. The runner chose TSX for.tsfiles when it moved off the plain Babel grammar, which had no TypeScript at all; nothing in that change needed JSX in.tsfiles.Smallest restoration
assets/codemods/run-codemod.mjs: onegrammarOf(filePath)decides the grammar, and both the config codemod and the code codemod paths bind jscodeshift with it. A declaration file uses jscodeshift's own TypeScript parser options with the TypeScript plugin in declaration mode, built once on first use.withParsertakes a parser object as well as a parser's name, as jscodeshift does, and the codemod runners type the module with it. The published authoring types are unchanged.Evidence
lib/protocol.d.ts(export const MAX_ITEMS: number;) andlib/util.ts(<{id: string}>x),astryx upgrade --from 0.6.0 --path libprintsMissing initializer in const declarationandUnexpected tokenfor both files under every codemod, thenFound 0 changes across 0 filesandUpgrade failed(exit 1)..tsx,.jsx,.jsfiles bind the same parsers as before; the codemod, upgrade API and upgrade command suites pass unchanged (109 files, 1,291 tests).run-codemod.test.mjsadds a grammar table (arbitrary-extension declaration files included), a run over a type assertion and declaration files with and without declared words (no errors), and a rename codemod that changes a.tstype assertion and a.d.tsdeclaration in place.doc-loads.test.mjslists the two parser modules the declaration grammar loads on first use.Scope
Components: cli (codemod runner)
Testing
npx vitest run --project node packages/cli/assets/codemods packages/cli/api/upgrade packages/cli/clients/cli/commands/upgrade(109 files passed)pnpm -F @astryxdesign/cli typecheck:strictnode .github/scripts/cli-api-types-verify.mjs