Skip to content

Don't use ghost location in jsx transform #7533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Treat `throw` like `raise` in analysis. https://github.com/rescript-lang/rescript/pull/7521
- Fix `index out of bounds` exception thrown in rare cases by `rescript-editor-analysis.exe codeAction` command. https://github.com/rescript-lang/rescript/pull/7523
- Don't produce duplicate type definitions for recursive types on hover. https://github.com/rescript-lang/rescript/pull/7524
- Prop punning when types don't match results in I/O error: _none_: No such file or directory. https://github.com/rescript-lang/rescript/pull/7533

#### :nail_care: Polish

Expand Down
5 changes: 2 additions & 3 deletions compiler/syntax/src/jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ let mk_record_from_props mapper (jsx_expr_loc : Location.t) (props : jsx_props)
{
loc_start = first_item.loc_start;
loc_end = last_item.loc_end;
loc_ghost = true;
loc_ghost = false;
}
in
(* key should be filtered out *)
Expand All @@ -1156,7 +1156,7 @@ let mk_record_from_props mapper (jsx_expr_loc : Location.t) (props : jsx_props)
| JSXPropPunning (is_optional, name) ->
{
lid = {txt = Lident name.txt; loc = name.loc};
x = Exp.ident {txt = Lident name.txt; loc = name.loc};
x = Exp.ident ~loc:name.loc {txt = Lident name.txt; loc = name.loc};
opt = is_optional;
}
| JSXPropValue (name, is_optional, value) ->
Expand Down Expand Up @@ -1303,7 +1303,6 @@ let expr ~(config : Jsx_common.jsx_config) mapper expression =
pexp_loc = loc;
pexp_attributes = attrs;
} -> (
let loc = {loc with loc_ghost = true} in
match jsx_element with
| Jsx_fragment {jsx_fragment_children = children} ->
let fragment =
Expand Down
6 changes: 1 addition & 5 deletions tests/analysis_tests/tests/src/expected/Fragment.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@ Hover src/Fragment.res 6:19
{"contents": {"kind": "markdown", "value": "```rescript\nReact.component<SectionHeader.props<React.element>>\n```\n\n---\n\n```\n \n```\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C12%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype SectionHeader.props<'children> = {children: 'children}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Fragment.res%22%2C1%2C2%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype React.element = Jsx.element\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C0%2C0%5D)\n"}}

Hover src/Fragment.res 9:56
Nothing at that position. Now trying to use completion.
posCursor:[9:56] posNoWhite:[9:55] Found expr:[9:9->9:70]
posCursor:[9:56] posNoWhite:[9:55] Found expr:[9:12->9:66]
JSX <SectionHeader:[9:13->9:26] > _children:9:29
null
{"contents": {"kind": "markdown", "value": "```rescript\nReact.component<React.fragmentProps>\n```\n\n---\n\n```\n \n```\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C12%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype React.fragmentProps = {children?: element}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C41%2C0%5D)\n"}}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

We've found a bug for you!
/.../fixtures/wrong_type_prop_punning.res:21:13-20

19 │ @react.component
20 │ let make = (~someProp: array<int>) => {
21 │ <Level2 someProp />
22 │ }
23 │ }

This has type: array<int>
But it's expected to have type: float
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module React = {
type element = Jsx.element
@val external null: element = "null"
type componentLike<'props, 'return> = Jsx.componentLike<'props, 'return>
type component<'props> = Jsx.component<'props>
external component: componentLike<'props, element> => component<'props> = "%identity"
@module("react/jsx-runtime")
external jsx: (component<'props>, 'props) => element = "jsx"
}

module Level2 = {
@react.component
let make = (~someProp: float) => {
React.null
}
}

module Level1 = {
@react.component
let make = (~someProp: array<int>) => {
<Level2 someProp />
}
}