Skip to content

Commit 4d7be3d

Browse files
committed
Don't use ghost location in jsx transform
1 parent 352fa02 commit 4d7be3d

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

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 =
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)