Skip to content

[rust-compiler] Add TDD fixtures for TS module-interop statements#36704

Closed
poteto wants to merge 1 commit into
lauren/swc-15-scope-info-empty-map-skipfrom
lauren/ts-unknown-01-fixtures
Closed

[rust-compiler] Add TDD fixtures for TS module-interop statements#36704
poteto wants to merge 1 commit into
lauren/swc-15-scope-info-empty-map-skipfrom
lauren/ts-unknown-01-fixtures

Conversation

@poteto
Copy link
Copy Markdown
Collaborator

@poteto poteto commented Jun 6, 2026

Summary

  • Adds three fixtures pinning how TS module-interop statements must behave: import lib = require(...), export = x, and export as namespace X. The TypeScript reference compiles files containing these statements and preserves them in output. The Rust port previously broke on each frontend in a different way: the Babel/NAPI path threw Failed to parse AST JSON: unknown variant ... and failed the whole file, the SWC converter rewrote the statements to EmptyStatement (silently deleting them from output), and OXC panics in its converter (deferred, documented).
  • The fixtures are born with the bare todo- prefix rather than error.*: snap asserts error.* fixtures throw on the TS side, and these compile cleanly there. They are renamed to their final ts-* names later in this stack as both frontends go green, matching the existing todo- convention for known Rust-side gaps.
  • All three function bodies allocate so the compiled snapshots visibly memoize; combined with the e2e events comparison, a degenerate whole-file bailout cannot pass them.
  • SproutTodoFilter skips only the namespace fixture (sprout's evaluator transform cannot process export as namespace); TODO.md documents the cross-frontend state and the planned fixes.

Known-red at this point in the stack

Babel and SWC e2e fail on exactly these three fixtures, and test-babel-ast.sh fails on them at AST deserialization. The next two PRs in this stack turn them green (Babel first, then SWC). TS-side snap is green throughout.

Test plan

  • yarn snap -p 'todo-ts-*': 3 Tests, 3 Passed
  • Scoped e2e per fixture shows exactly the documented red state (babel: unknown-variant throw; swc: statement missing from output while events pass)

Stack

PR Slice Base
#36517#36518#36522 SWC parity stack (open) pr-36173
#36704 TDD fixtures (red) #36522's branch
#36705 Unknown-statement tolerance (Babel green) #36704's branch
#36706 SWC preservation + renames (SWC green) #36705's branch

Merge order: bottom up.

@meta-cla meta-cla Bot added the CLA Signed label Jun 6, 2026
@github-actions github-actions Bot added the React Core Team Opened by a member of the React Core Team label Jun 6, 2026
@poteto poteto force-pushed the lauren/swc-15-scope-info-empty-map-skip branch from 48eb0d1 to a12b3d8 Compare June 6, 2026 22:37
@poteto poteto force-pushed the lauren/ts-unknown-01-fixtures branch from fb7d3cc to 1e41304 Compare June 6, 2026 22:37
Pin how TSImportEqualsDeclaration, TSExportAssignment, and
TSNamespaceExportDeclaration must behave: the statement is preserved in
output and the file's functions still compile, as the TS reference
already does. The three frontends share the broken symptom today via
three different root causes: the Babel/NAPI path throws "Failed to
parse AST JSON: unknown variant ..." (the typed AST's tagged enums have
no catch-all) and fails the whole file; the SWC converter explicitly
rewrites the statements to EmptyStatement, erasing them from output
with no error and no event; OXC todo!()-panics in its converter
(deferred).

The fixtures use the bare todo- prefix rather than error.*: snap
asserts error.* fixtures throw on the TS side, and these compile
cleanly there. All three function bodies allocate so the compiled
snapshots visibly memoize; combined with the e2e events comparison,
a degenerate whole-file bailout cannot pass them.

Known-red until the fix slices land: Babel and SWC e2e on these three
fixtures, and test-babel-ast.sh (both round_trip and
scope_resolution_rename deserialize the same fixture JSON). TS-side
snap is green. SproutTodoFilter skips only the namespace fixture:
export as namespace is .d.ts-shaped and sprout's evaluator transform
cannot process it; the other two transform to CJS and evaluate fine.
@poteto poteto force-pushed the lauren/ts-unknown-01-fixtures branch from 1e41304 to e4141db Compare June 6, 2026 22:47
@poteto poteto force-pushed the lauren/swc-15-scope-info-empty-map-skip branch from a12b3d8 to ee61071 Compare June 6, 2026 22:47
@poteto
Copy link
Copy Markdown
Collaborator Author

poteto commented Jun 7, 2026

Closing: this stack's content is being ported directly to the umbrella PR branch (rust-research, #36173) rather than staged through pr-36173.

@poteto poteto closed this Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant