Skip to content

Commit 56c60ee

Browse files
authored
Don't use ghost location in jsx transform (#7533)
* Don't use ghost location in jsx transform * Add changelog * Update analysis snapshot
1 parent 352fa02 commit 56c60ee

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- Treat `throw` like `raise` in analysis. https://github.com/rescript-lang/rescript/pull/7521
2626
- 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
2727
- Don't produce duplicate type definitions for recursive types on hover. https://github.com/rescript-lang/rescript/pull/7524
28+
- 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
2829

2930
#### :nail_care: Polish
3031

compiler/syntax/src/jsx_v4.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ let mk_record_from_props mapper (jsx_expr_loc : Location.t) (props : jsx_props)
11311131
{
11321132
loc_start = first_item.loc_start;
11331133
loc_end = last_item.loc_end;
1134-
loc_ghost = true;
1134+
loc_ghost = false;
11351135
}
11361136
in
11371137
(* key should be filtered out *)
@@ -1156,7 +1156,7 @@ let mk_record_from_props mapper (jsx_expr_loc : Location.t) (props : jsx_props)
11561156
| JSXPropPunning (is_optional, name) ->
11571157
{
11581158
lid = {txt = Lident name.txt; loc = name.loc};
1159-
x = Exp.ident {txt = Lident name.txt; loc = name.loc};
1159+
x = Exp.ident ~loc:name.loc {txt = Lident name.txt; loc = name.loc};
11601160
opt = is_optional;
11611161
}
11621162
| JSXPropValue (name, is_optional, value) ->
@@ -1303,7 +1303,6 @@ let expr ~(config : Jsx_common.jsx_config) mapper expression =
13031303
pexp_loc = loc;
13041304
pexp_attributes = attrs;
13051305
} -> (
1306-
let loc = {loc with loc_ghost = true} in
13071306
match jsx_element with
13081307
| Jsx_fragment {jsx_fragment_children = children} ->
13091308
let fragment =

tests/analysis_tests/tests/src/expected/Fragment.res.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,5 @@ Hover src/Fragment.res 6:19
22
{"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"}}
33

44
Hover src/Fragment.res 9:56
5-
Nothing at that position. Now trying to use completion.
6-
posCursor:[9:56] posNoWhite:[9:55] Found expr:[9:9->9:70]
7-
posCursor:[9:56] posNoWhite:[9:55] Found expr:[9:12->9:66]
8-
JSX <SectionHeader:[9:13->9:26] > _children:9:29
9-
null
5+
{"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"}}
106

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/wrong_type_prop_punning.res:21:13-20
4+
5+
19 │ @react.component
6+
20 │ let make = (~someProp: array<int>) => {
7+
21 │ <Level2 someProp />
8+
22 │ }
9+
23 │ }
10+
11+
This has type: array<int>
12+
But it's expected to have type: float
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module React = {
2+
type element = Jsx.element
3+
@val external null: element = "null"
4+
type componentLike<'props, 'return> = Jsx.componentLike<'props, 'return>
5+
type component<'props> = Jsx.component<'props>
6+
external component: componentLike<'props, element> => component<'props> = "%identity"
7+
@module("react/jsx-runtime")
8+
external jsx: (component<'props>, 'props) => element = "jsx"
9+
}
10+
11+
module Level2 = {
12+
@react.component
13+
let make = (~someProp: float) => {
14+
React.null
15+
}
16+
}
17+
18+
module Level1 = {
19+
@react.component
20+
let make = (~someProp: array<int>) => {
21+
<Level2 someProp />
22+
}
23+
}

0 commit comments

Comments
 (0)