Skip to content

Commit 3036613

Browse files
committed
fix tag function location on error
1 parent d2604ad commit 3036613

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/unknown_tagged_template_function.res:1:11-14
4+
5+
1 │ let res = tagg`| 5 × 10 = ${5} |`
6+
7+
The value tagg can't be found
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let res = tagg`| 5 × 10 = ${5} |`

jscomp/syntax/src/res_core.ml

+4-9
Original file line numberDiff line numberDiff line change
@@ -2286,7 +2286,6 @@ and parse_template_expr ?prefix p =
22862286
Some prefix
22872287
| _ -> Some "js"
22882288
in
2289-
let start_pos = p.Parser.start_pos in
22902289

22912290
let parse_parts p =
22922291
let rec aux acc =
@@ -2319,13 +2318,9 @@ and parse_template_expr ?prefix p =
23192318
let parts = parse_parts p in
23202319
let strings = List.map fst parts in
23212320
let values = Ext_list.filter_map parts snd in
2322-
let end_pos = p.Parser.end_pos in
23232321

2324-
let gen_tagged_template_call lident =
2325-
let ident =
2326-
Ast_helper.Exp.ident ~attrs:[] ~loc:Location.none
2327-
(Location.mknoloc lident)
2328-
in
2322+
let gen_tagged_template_call (lident_loc : Longident.t Location.loc) =
2323+
let ident = Ast_helper.Exp.ident ~attrs:[] ~loc:lident_loc.loc lident_loc in
23292324
let strings_array =
23302325
Ast_helper.Exp.array ~attrs:[] ~loc:Location.none strings
23312326
in
@@ -2334,7 +2329,7 @@ and parse_template_expr ?prefix p =
23342329
in
23352330
Ast_helper.Exp.apply
23362331
~attrs:[tagged_template_literal_attr]
2337-
~loc:(mk_loc start_pos end_pos) ident
2332+
~loc:lident_loc.loc ident
23382333
[(Nolabel, strings_array); (Nolabel, values_array)]
23392334
in
23402335

@@ -2374,7 +2369,7 @@ and parse_template_expr ?prefix p =
23742369
match prefix with
23752370
| Some {txt = Longident.Lident ("js" | "j" | "json"); _} | None ->
23762371
gen_interpolated_string ()
2377-
| Some {txt = lident} -> gen_tagged_template_call lident
2372+
| Some lident_loc -> gen_tagged_template_call lident_loc
23782373

23792374
(* Overparse: let f = a : int => a + 1, is it (a : int) => or (a): int =>
23802375
* Also overparse constraints:

0 commit comments

Comments
 (0)