partial-tsx
v0.0.2
Published
Utilities for completing prefix-growing TSX.
Readme
partial-tsx
Completes prefix-growing TSX.
Input
import { completePartialTsx, normalizeGeneratedTsx } from "partial-tsx";
completePartialTsx("<div>Hello");
completePartialTsx("function App() { return <div>Hello", { mode: "streaming" });
normalizeGeneratedTsx("function Card() { return <button>OK");Output
completePartialTsx(code)returns syntactically safer TSX for a partial prefix.normalizeGeneratedTsx(code)returns renderer-ready TSX:- Markdown fences removed.
- Safe partial syntax completed.
- Missing default export added when a component can be found.
- Missing imports added for known React hooks such as
useState.
{ mode: "streaming" }first rolls script back to its last committed syntax boundary. It never closes an unfinished call, initializer, callback, control-flow statement, or JSX{expression; unterminated JSX string attributes remain the one value-completion exception.- The default
{ mode: "final" }preserves the existing completion behavior.partial-reactuses streaming mode only for incremental frames and sends final input to the compiler unchanged.
Corner Cases
- Incomplete component/tag names are left alone when completing them would likely render the wrong element.
- Unterminated JSX string attributes can be closed; incomplete expression attributes are dropped.
- Void HTML tags are normalized as self-closing tags.
- Unknown hooks or custom hooks are not auto-imported.
- Existing default exports are preserved.
- Invalid TypeScript semantics are not repaired.
Test
bun test lib/partial-tsx