feat: typescript support#19
Draft
jacob-ebey wants to merge 5 commits into
Draft
Conversation
Run TypeScript files directly through the runtime, mirroring Node.js's
native type-stripping (stable since Node 23.6). `node app.ts`,
`require('./mod.ts')`, and `index.ts` directory resolution now work out
of the box.
Implemented with `acorn-typescript`, a pure-JS acorn plugin — no
`typescript` compiler dependency and no wasm. This keeps stripping
synchronous (required for `require()`) and adds minimal bundle weight
(index.mjs stays ~1.2MB rather than ballooning to ~10MB as it would by
pulling in the full typescript package).
Type-only syntax is replaced with whitespace, preserving source
positions: annotations, interfaces, type aliases, generics,
`import type`/`export type`, `as`/`satisfies`, non-null `!`, definite
assignment, `declare`, class member modifiers, and `implements`.
Details:
- New `src/frameworks/strip-types.ts`: parses with acorn-typescript and
blanks TS-only AST node ranges, then the existing ESM→CJS pipeline runs.
- runtime.ts: strip types before the ESM→CJS transform in loadModule and
execute; .cts treated as CommonJS, .mts/.ts as ESM-capable; added
.ts/.mts/.cts (and index.* variants) to module resolution.
- child_process.ts: `node` command resolves .ts files, including the
extensionless `node app` -> app.ts case.
Matches Node's strip-only mode: constructs needing code generation
(enums, namespaces, parameter-property assignment) are not emitted.
Only .ts/.mts/.cts are handled; .tsx/JSX continues to go through the
Vite/Next dev servers via esbuild.
Adds tests/typescript-files.test.ts and `node app.ts` coverage in
tests/child_process.test.ts. Full suite (2261) green, tsc clean.
…local binding preservation for named exports
…nment compatibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.