quoted js* expressions substitution #33
Draft
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.
As discovered when trying to compose the helix react wrapper with missionary, cloroutine SSA transformation can introduce substitution errors, when processing
js*
forms in cljs.That's because
js*
has fexpr-like semantics, where (js) AST snippets are substituted into the js source verbatim. For expressions that are quoted by javascript, this can make local variable names show up in javascript values:(note that
js-obj
has a compiler macro, that expands to(js* "({~{}:~{}})" "key" "val")
, in which then the key expression is mangled bycr
)Analysis
I believe just skipping introduction of local variables for
:op :const
AST nodes during SSA (maybe even just when used asjs*
argument?) should fix most any case that we care about: For anything but a constant, relying on the quoted JS form would be very brittle and probably an error.I've added two tests, one for strings and one for object keys. There may be other affected edge cases when building up JS syntax, e.g. for labelled statements, but since
cr
necessarily needs to work without knowledge whether an expression will be quoted by JS, fixing:op :const
nodes should fix all cases that can be reasonably fixed.Things done
For now, I've just added tests, since I'm not that familiar with
cr
's SSA transformer. Help is welcome and I may reach out on slack.