fix(faces): strip trailing ; from module name in JaffaScript imports#120
Merged
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a string-stripping bug in
transform_importinsidelib/js_face.mlthat corrupted module names when the import ended with a semicolon (the normal JS style).Root cause:
import { println } from "io";causedtransform_importto setmod_part = "\"io\";". The code then sliced off the surrounding quote characters withString.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 resultingusedeclaration wasuse io"::{println};— a syntactically invalid module path.Fix: In all three import branches (
import { x } from "m";,import * from "m";, andimport name from "m";), strip a trailing;frommod_part/quotedbefore the quote-stripping slice.Files changed
lib/js_face.mltransform_importexamples/faces/hello-jaffa.affineimport { println } from "io";to exercise the import path in the regression testtests/faces/hello-jaffa.expected.txtuse io::{println};Test plan
opam exec -- dune build lib/ bin/— confirms OCaml compiles./tools/run_face_transformer_tests.sh— snapshot regression:hello-jaffa.expected.txtshould matchpreview-jsoutputaffinescript preview-js examples/faces/hello-jaffa.affine— visually confirmuse io::{println};appears correctlyaffinescript parse examples/faces/hello-jaffa.affine— confirm the lowered file parses without errorsGenerated by Claude Code