Skip to content

@js transpiler: broaden coverage + escape hatch for browser APIs (MediaRecorder/FileReader/streaming) #18

Description

@LoboGuardian

Summary (enhancement)

The Python→JS transpiler (src/HTeaLeaf/JS/py2js.py) covers a useful core (assignments, if/while/for, calls, f-strings, list/dict/tuple literals, operators), but several common constructs aren't handled, and non-trivial client logic hits a wall. Concretely:

  • generic_visit raises NotImplementedError for any unhandled expression node (py2js.py:74).
  • _emit_body emits /* TODO: <NodeName> */ for unhandled statements (py2js.py:67) — i.e. silently produces broken JS.

No visit_* for: try/except (Try), comprehensions (ListComp/DictComp/SetComp/GeneratorExp), Lambda, ClassDef, With, Raise, Assert, await/async defs.

Why it matters

Rich client features can't be expressed in @js today and fall back to hand-written JSCode, which erodes the "write the client in Python" value. Examples we need:

  • Voice capture: navigator.mediaDevices.getUserMedia + MediaRecorder (events, async).
  • File reading: FileReader / Blob for attachments.
  • Incremental streaming client: EventSource/WebSocket handlers that accumulate chunks and patch the DOM (pairs with Server push (SSE / WebSocket) for streaming responses and real-time UIs #16).
  • Error handling (try/except) and comprehensions for shaping data before render.

What would help (any subset)

  1. Broaden transpiler coverage: at minimum try/except, comprehensions, lambda.
  2. A first-class, typed escape hatch for browser APIs — e.g. JSCode/window proxies for navigator, MediaRecorder, FileReader, EventSource, fetch().body streaming — so @js functions can call them without raw string injection.
  3. Make unhandled nodes a hard error rather than a silent /* TODO */ that ships broken JS.

Context

Raised while evaluating HTeaLeaf to replace a Vue + FastAPI frontend with pure Python. The DSL is great for static + simple-interaction views; this is the gap for the dynamic client logic (chat streaming, voice). Related: #16 (server push), and the multipart upload issue.

Metadata

Metadata

Assignees

Labels

Client-sideRenderingHow the HTML is rendered and sent to the clientenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions