Learnings from running the examples with no toolchain
Phase 1 was writing 26 example projects under examples/ and running them with stock tooling. Everything failed, in three distinct ways, and each failure dictated a piece of the MVP design.
Failure 1: the extension is a hard wall
node examples/01-hello/src/main.tsus and node --experimental-strip-types both die with ERR_UNKNOWN_FILE_EXTENSION before reading a single byte. Node's type-stripping only accepts .ts/.mts, so a new extension means we own the compile step end to end. There is no incremental "mostly works" path.
Consequence for the MVP: tsus build must exist and must emit plain .js before anything runs. Compiled output has to be standard ESM so Node and Cloudflare Workers can consume it with zero knowledge of .tsus.
Failure 2: match blocks are not parseable TypeScript
Renaming 04-match-option/src/main.tsus to .ts and running tsc --noEmit produces TS1005: ',' expected and TS1109: Expression expected at the match arms. The TS parser cannot recover into anything useful, so we cannot implement match as a tsc plugin or an AST transform over the original source.
Consequence: the MVP needs a preprocessor that runs before the TypeScript parser, scanning raw text and rewriting match (expr) { Pattern(x) => body } into a plain function call (__tsus_match). The scanner has to be a real tokenizer that understands strings, template literals (including nested ${}), and comments, because example 24 deliberately plants fake match blocks inside all of those. A regex will not survive it.
Failure 3: import specifiers with .tsus extensions break resolution
Even with compiled output, import { safeSqrt } from "./math.tsus" would still fail at runtime because nothing on disk has that name after compilation. The examples with import chains (12, 20, 21, 22) all hit this.
Consequence: the build step rewrites .tsus and .ts specifiers to .js in emitted code, and compiles sibling .ts files too, so a mixed ts+tsus project comes out as one coherent dist tree.
Smaller findings baked into the design
awaitinside a match arm: arms compile to arrow functions, so an arm whose body containsawaitmust become anasyncarrow, and__tsus_matchthen returns a promise the caller awaits. Example 19 forces this."abc".match(/\d+/)and a user function literally namedmatch(example 25) must not trigger the macro. The rewrite only fires onmatch (expr) {where the token is not preceded by.or an identifier character, and only when a{follows the closing paren.- Bare string-literal patterns (
"/" => ...in the worker example) mean patterns are not just variant tags; the runtime match needs literal equality patterns plus a_wildcard. - Circular
.tsusimports (example 21) are fine as long as the cycle is function-level, because compiled output is ESM and ESM handles cycles with hoisted bindings. The compiler does not need to detect cycles for the MVP. - The checker rules (no class, no null, no undefined, no var, no throw) apply to
.tsusfiles only. Examples 13 and 22 have.tsdependencies that use classes, null, and undefined on purpose; the checker must scope itself by extension or mixed projects are impossible.