syntax icon indicating copy to clipboard operation
syntax copied to clipboard

Fix locations in the JSX ppx

Open cristianoc opened this issue 2 years ago • 1 comments

As a general ppx writing rule: the loc_ghost part of any location should be true unless it's one unique copy of an original expression, or a single new expression that corresponds to that original expression in spirit.

So no always loc_ghost=true for any auxiliary functions that were not in the original source, such as any calls to the react libraries, or any compiler internals. This should include any administrative code generated, such as the list of children.

This affects editor integration (particularly hover and jump to location). Check the consequences on editor integration for each change.

Concretely, currently the ppx "paints" occurrences of e.g. ReasonReact.fragment all over the actual code. This is in addition to whatever invisible symbols the compiler generates.The JSX ppx generates an external with @bs.obj and generates calls to it. Then the compiler's ppx transforms those into definitions of accessor functions, and calls to them, "painted" on top of the original code. So every prop x results in a Prop id and an x function appearing in the generated code.

If one wanted to properly support jump to definition for <Comp x=4 /> when clicking on x, then one would need just based on the location of x find the call Comp.makeProps(... x ) and connect it to the accessor function x generated by the compiler @obj ppx starting from the results of the JSX ppx, and connect that to the location of x in the make, not the makeProps, function at the original location, before the JSX transformation, in the component definition.

cristianoc avatar Jun 03 '22 04:06 cristianoc

  • Make "fragment" a ghost location (obviates https://github.com/rescript-lang/syntax/issues/519 ).

cristianoc avatar Jun 03 '22 07:06 cristianoc

The rescript-lang/syntax repo is obsolete and will be archived soon. If this issue is still relevant, please reopen in the compiler repo (https://github.com/rescript-lang/rescript-compiler) or comment here to ask for it to be moved. Thank you for your contributions.

stale[bot] avatar May 28 '23 15:05 stale[bot]