Skip to content

fix(faces): strip trailing ; from module name in JaffaScript imports#120

Merged
hyperpolymath merged 1 commit into
mainfrom
fix/faces-js-import-semis
May 16, 2026
Merged

fix(faces): strip trailing ; from module name in JaffaScript imports#120
hyperpolymath merged 1 commit into
mainfrom
fix/faces-js-import-semis

Conversation

@hyperpolymath
Copy link
Copy Markdown
Owner

Summary

Fixes a string-stripping bug in transform_import inside lib/js_face.ml that corrupted module names when the import ended with a semicolon (the normal JS style).

Root cause: import { println } from "io"; caused transform_import to set mod_part = "\"io\";". The code then sliced off the surrounding quote characters with String.sub mod_part 1 (String.length mod_part - 2), but because the last character was ; rather than ", the slice yielded "io\"" (trailing quote instead of nothing). The resulting use declaration was use io"::{println}; — a syntactically invalid module path.

Fix: In all three import branches (import { x } from "m";, import * from "m";, and import name from "m";), strip a trailing ; from mod_part / quoted before the quote-stripping slice.

Files changed

File Change
lib/js_face.ml Three-branch semicolon-strip fix in transform_import
examples/faces/hello-jaffa.affine Added import { println } from "io"; to exercise the import path in the regression test
tests/faces/hello-jaffa.expected.txt Refreshed snapshot — now includes use io::{println};

Test plan

  • opam exec -- dune build lib/ bin/ — confirms OCaml compiles
  • ./tools/run_face_transformer_tests.sh — snapshot regression: hello-jaffa.expected.txt should match preview-js output
  • affinescript preview-js examples/faces/hello-jaffa.affine — visually confirm use io::{println}; appears correctly
  • affinescript parse examples/faces/hello-jaffa.affine — confirm the lowered file parses without errors

Note: OCaml toolchain is not available in the authoring environment; changes were manually traced through the transformer logic. CI is the source of truth for build correctness.


Generated by Claude Code

`transform_import` extracted the module name by stripping surrounding
quote characters with `String.sub mod_part 1 (len - 2)`.  When the
import ends with a semicolon (the normal JS style: `import { x } from
\"m\";`), `mod_part` is `\"m\";` — the last character is `;`, not `\"`, so
the slice kept the trailing `\"` in the module name and produced
`use m\"::{x};` instead of `use m::{x};`.

Fix: in all three import branches (`import { x }`, `import *`, and
`import name`), strip a trailing `;` from `mod_part` / `quoted` before
the quote-stripping slice.

Updated `examples/faces/hello-jaffa.affine` to include
`import { println } from \"io\";` so the import path is exercised by the
regression test.  Updated snapshot.
@hyperpolymath hyperpolymath marked this pull request as ready for review May 16, 2026 12:33
@hyperpolymath hyperpolymath merged commit d2811a9 into main May 16, 2026
20 of 21 checks passed
@hyperpolymath hyperpolymath deleted the fix/faces-js-import-semis branch May 16, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant