Skip to content

Latest commit

 

History

History
52 lines (33 loc) · 2.15 KB

README.md

File metadata and controls

52 lines (33 loc) · 2.15 KB

Syntaxase

Lightning-fast type stripping and JSX lowering.

Named like an enzyme, Syntaxase removes erasable TypeScript syntax and lowers supported TypeScript and JSX runtime constructs.

Install

npm

npm install syntaxase

For WebAssembly environments, install the separately published package

npm

npm install syntaxase-wasm

Usage

import { 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.

API notes

  • stripTypes performs 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's erasableSyntaxOnly option.
  • transform additionally 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.

Acknowledgements

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.