Skip to content

Write the JavaScript from the type check, and run Jest without a transformer - #105

Merged
SleeplessByte merged 4 commits into
mainfrom
tsc-emit
Nov 26, 2026
Merged

SleeplessByte merged 4 commits into
mainfrom
tsc-emit

Conversation

@exercism-agent

@exercism-agent exercism-agent Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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.cjs runs tsc's own command-line code, so its output and exit code match tsc --noEmit exactly. 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.cjs just strips the types, with transpileModule. Jest then runs the written files with no transformer (transform: {}).

  • Writing the files adds 0.08s to 0.17s to the type check.
  • Stack traces and console output still point at the right .ts lines, through the source maps.
  • Type errors look exactly as they do today.
  • Enums and parameter properties work, because tsc writes their code itself.
  • It adds no new dependency, and works in a read-only container.

Every test passes or fails as before. Three messages change:

  • Errors name imports two_fer_ts_1 where Babel's output gave _twoFer.
  • Stack frames name functions with their real names, for example at twoFer where Babel's output said at a.
  • A syntax error in the test file uses TypeScript's wording, with no code frame.

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

…sformer

Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SleeplessByte

Copy link
Copy Markdown
Member

Can this now be undrafted?

@exercism-agent exercism-agent Bot changed the title Write the JavaScript from the type check, and run Jest without a transformer (draft) Write the JavaScript from the type check, and run Jest without a transformer Nov 25, 2026
@exercism-agent
exercism-agent Bot marked this pull request as ready for review November 25, 2026 02:58
@exercism-agent
exercism-agent Bot requested a review from a team as a code owner November 25, 2026 02:58
@exercism-agent

Copy link
Copy Markdown
Contributor Author

@SleeplessByte Yes, it's ready for review now. #106 and #107 build on it and are still drafts.

@SleeplessByte

Copy link
Copy Markdown
Member

Tests are failing. Snapshots may need update?

@SleeplessByte

Copy link
Copy Markdown
Member

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>
@exercism-agent

Copy link
Copy Markdown
Contributor Author

@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.

Comment thread bin/compile.cjs Resolved
{
"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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think two_fer_1. is clear, _twoFer was already debatable. Anything to be done here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Now I like the rewrite. please do yes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in bf50a57: the message now reads twoFer is not a function (or TwoFerKlazz.method / the default export), and CI passes.

iHiD and others added 2 commits November 26, 2026 00:10
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>
@SleeplessByte
SleeplessByte merged commit 6895958 into main Nov 26, 2026
5 checks passed
@SleeplessByte
SleeplessByte deleted the tsc-emit branch November 26, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants