Repository navigation
Write the JavaScript from the type check, and run Jest without a transformer - #105
Conversation
1d764a5 to
3b47f73
Compare
…sformer Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ea05cb1 to
34e4bf1
Compare
|
Can this now be undrafted? |
|
@SleeplessByte Yes, it's ready for review now. #106 and #107 build on it and are still drafts. |
|
Tests are failing. Snapshots may need update? |
|
Thanks. Tests are failing! |
Jest now runs the JavaScript written by tsc, so a missing export is reported as two_fer_1.twoFer, and a syntax error in the test file uses TypeScript's wording. Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@SleeplessByte Two expected results files hadn't been updated for the new error messages (the import name, and tsc's wording for the malformed test file). They're updated now and CI passes. |
| { | ||
| "status": "error", | ||
| "message": "SyntaxError: <solution>/two-fer.test.ts: Unexpected token (2:0)\n\n 1 | describe('twoFer()', t('another name given', () => {\n > 2 |\n | ^\n", | ||
| "message": "SyntaxError: <solution>/two-fer.test.ts: '}' expected. (2:0)\n", |
There was a problem hiding this comment.
The old description had more information and was clearer. Is it possible to add the context in the error so users know what to change?
There was a problem hiding this comment.
Yes. TypeScript can format the error with its context (ts.formatDiagnosticsWithColorAndContext, with the colours stripped), which for this file gives:
two-fer.test.ts:2:1 - error TS1005: '}' expected.
2
two-fer.test.ts:1:52
1 describe('twoFer()', t('another name given', () => {
~
The parser expected to find a '}' to match the '{' token here.
I can make that change if you'd like.
There was a problem hiding this comment.
Done in e399e83: the message now includes the lines around the error and the marker from TypeScript, and CI passes.
| "name": "TwoFer > no name given", | ||
| "status": "fail", | ||
| "message": "TypeError: (0 , _twoFer.twoFer) is not a function", | ||
| "message": "TypeError: (0 , two_fer_1.twoFer) is not a function", |
There was a problem hiding this comment.
Don't think two_fer_1. is clear, _twoFer was already debatable. Anything to be done here?
There was a problem hiding this comment.
tsc always names a CommonJS import <file>_1, and no compiler option changes that. The runner could rewrite (0 , two_fer_1.twoFer) is not a function to twoFer is not a function with one regex in sanitizeErrorMessage in src/output.ts, which would also be clearer than Babel's version. I can make that change if you'd like.
There was a problem hiding this comment.
I think defaultImport.two_fer would be even clearer, because I think that's what's going on here? If it's a named import, the error will be correct (e.g. TwoFerKlazz.method). _1 is an implementation detail.
There was a problem hiding this comment.
It's a named import here: the test does import { twoFer } from './two-fer', and two_fer_1 is the whole ./two-fer module, so two_fer_1.twoFer is the missing named export. With the rewrite, a named import would give twoFer is not a function, and two_fer_1.TwoFerKlazz.method would give TwoFerKlazz.method is not a function. A default import compiles to two_fer_1.default, which I would reword to the default export is not a function. I can make the rewrite once you confirm the wording.
There was a problem hiding this comment.
Ah. Now I like the rewrite. please do yes
There was a problem hiding this comment.
Done in bf50a57: the message now reads twoFer is not a function (or TwoFerKlazz.method / the default export), and CI passes.
TypeScript formats the error with the source lines and a marker, as Babel's code frame did. The colours are stripped. Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tsc compiles a named import to two_fer_1.twoFer, so Node reported '(0 , two_fer_1.twoFer) is not a function'. The runner now reports 'twoFer is not a function', 'TwoFerKlazz.method is not a function' for a method, and 'the default export is not a function' for a default import. Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hello 🙂 I'm working with Claude to try and get our tooling faster.
This draft makes this project around 20% faster on top of #104. I've run it in production to benchmark things in the real world against the most recent few hundred solutions, so I'm confident that it works robustly. However, I've not written the code. I have tried my hardest to get Claude to write sensible messages and comments that explain stuff, but I'd ask for your patience in the fact I'm sending AI code to you. Everything below here is from your friendly neighbourhood LLM...
This is the first of three draft PRs. #103 and #104 are merged, so it is now based on
main. Merge it first, then #106 and #107. This PR works without the other two.What changed
Each run already type-checks the solution with
tsc --noEmit. tsc then throws its work away, and Babel strips the types again when Jest loads each file. Loading Babel and running it takes a large part of each run.The new
bin/compile.cjsruns tsc's own command-line code, so its output and exit code matchtsc --noEmitexactly. After the check, it turns emit on in the same program and writes CommonJS and source maps to a temporary folder. For the test file,bin/compile.cjsjust strips the types, withtranspileModule. Jest then runs the written files with no transformer (transform: {})..tslines, through the source maps.Every test passes or fails as before. Three messages change:
two_fer_ts_1where Babel's output gave_twoFer.at twoFerwhere Babel's output saidat a.Two fixture messages are updated to match.
I also tried SWC to strip the types. It was about as fast (SWC 2.80s, this PR 2.87s, both warm). But it adds 53 MB to the image, and it needs a native library that fails to load in a read-only container unless it is unpacked at build time.
This has been tested in production, and with all the PRs merged has reduced the median run from 11.8s to 3.3s.
🤖 Generated with Claude Code