Skip to content

Commit ba014df

Browse files
committed
fix(scripts): route the codemod's parses through ts-parse.mjs's checked parse
check:parse-guard flagged the raw createSourceFile: a parse whose errors nobody read. The text now passes parseSourceFile first, which refuses a source with parse errors, and ts-morph reads the vouched-for text. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2gLghEqeDKTbDTC7Zd
1 parent 3917686 commit ba014df

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎scripts/codemod-split-sql-driver.mjs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
*
7676
* Exit codes: 0 done · 1 a proof failed (stop: the generated split is never
7777
* hand-edited to pass) · 2 the script could not run (unknown banner, missing
78-
* prerequisite, bad arguments).
78+
* prerequisite, bad arguments) · 3 an input does not parse (`ts-parse.mjs`'s
79+
* refusal, which names the parse errors).
7980
*/
8081

8182
import { createHash } from 'node:crypto';
@@ -86,6 +87,7 @@ import { join } from 'node:path';
8687
import { fileURLToPath, pathToFileURL } from 'node:url';
8788

8889
import { isEntrypoint } from './invoked-as.mjs';
90+
import { parseSourceFile } from './ts-parse.mjs';
8991

9092
const ROOT = join(fileURLToPath(new URL('.', import.meta.url)), '..');
9193
const SRC_REL = 'packages/drivers/driver-sql/src';
@@ -225,13 +227,20 @@ async function loadTsMorph() {
225227
}
226228
}
227229

228-
/** One in-memory project per parse: no file system, no lib, no build output. */
230+
/**
231+
* One in-memory project per parse: no file system, no lib, no build output.
232+
* The text goes through `ts-parse.mjs`'s checked parse first, which refuses a
233+
* source with parse errors (its exit 3) instead of handing back a recovered
234+
* partial tree; ts-morph then reads the same text, already vouched for.
235+
*/
229236
function parse(tm, fileName, text) {
237+
parseSourceFile(fileName, text);
230238
const project = new tm.Project({
231239
useInMemoryFileSystem: true,
232240
compilerOptions: { target: tm.ts.ScriptTarget.ES2020, strict: true, noLib: true, allowJs: false },
233241
});
234-
return project.createSourceFile(fileName, text, { overwrite: true });
242+
project.getFileSystem().writeFileSync(fileName, text);
243+
return project.addSourceFileAtPath(fileName);
235244
}
236245

237246
/** A reason the script cannot run at all (exit 2) — never a verdict on the split. */

0 commit comments

Comments
 (0)