Lightning-fast type stripping and JSX lowering.
Named like an enzyme, Syntaxase removes erasable TypeScript syntax and lowers supported TypeScript and JSX runtime constructs.
npm install syntaxaseFor WebAssembly environments, install the separately published package
npm install syntaxase-wasmimport { stripTypes, transform } from "syntaxase";
const stripped = stripTypes(`
interface User { name: string }
const user: User = { name: "Ada" };
`);
const strippedTsx = stripTypes(`const view = <Card<User> user={user as User} />;`, { lang: "tsx" });
const transformed = transform(`const view: JSX.Element = <h1>Hello</h1>;`, {
jsx: true,
});Use the same named exports from syntaxase-wasm when targeting WebAssembly.
stripTypesperforms fixed-width erasure while preserving source length and line layout. Pass{ lang: "tsx" }to parse TSX while preserving JSX unchanged. Use it with source accepted by TypeScript'serasableSyntaxOnlyoption.transformadditionally lowers supported runtime TypeScript constructs and optional JSX.{ jsx: true }uses React's automatic production runtime.- The JavaScript packages return strings, not parser diagnostics. Use a TypeScript checker or another parser when validation is required.
Special thanks to Sucrase and ts-blank-space for the ideas that inspired Syntaxase; to Yuku for serving as the project's foundation; and to @sveltejs/acorn-typescript, which powered the original prototype.
See the syntaxase package documentation for all JSX options and defaults. See CONTRIBUTING.md to work on Syntaxase itself.