Skip to content

Commit

Permalink
fix tag function location on compiler error
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnobip committed Jun 17, 2024
1 parent d2604ad commit 8d5d89a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#### :bug: Bug Fix

- Fix tag function location on compiler error. https://github.com/rescript-lang/rescript-compiler/pull/6816
- Fix encoding inside tagged template literals. https://github.com/rescript-lang/rescript-compiler/pull/6810
- Fix unhandled cases for exotic idents (allow to use exotic PascalCased identifiers for types). https://github.com/rescript-lang/rescript-compiler/pull/6777
- PPX v4: mark props type in externals as `@live` to avoid dead code warnings for prop fields in the editor tooling. https://github.com/rescript-lang/rescript-compiler/pull/6796
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

We've found a bug for you!
/.../fixtures/unknown_tagged_template_function.res:1:11-14

1 │ let res = tagg`| 5 × 10 = ${5} |`

The value tagg can't be found
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let res = tagg`| 5 × 10 = ${5} |`
13 changes: 4 additions & 9 deletions jscomp/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,6 @@ and parse_template_expr ?prefix p =
Some prefix
| _ -> Some "js"
in
let start_pos = p.Parser.start_pos in

let parse_parts p =
let rec aux acc =
Expand Down Expand Up @@ -2319,13 +2318,9 @@ and parse_template_expr ?prefix p =
let parts = parse_parts p in
let strings = List.map fst parts in
let values = Ext_list.filter_map parts snd in
let end_pos = p.Parser.end_pos in

let gen_tagged_template_call lident =
let ident =
Ast_helper.Exp.ident ~attrs:[] ~loc:Location.none
(Location.mknoloc lident)
in
let gen_tagged_template_call (lident_loc : Longident.t Location.loc) =
let ident = Ast_helper.Exp.ident ~attrs:[] ~loc:lident_loc.loc lident_loc in
let strings_array =
Ast_helper.Exp.array ~attrs:[] ~loc:Location.none strings
in
Expand All @@ -2334,7 +2329,7 @@ and parse_template_expr ?prefix p =
in
Ast_helper.Exp.apply
~attrs:[tagged_template_literal_attr]
~loc:(mk_loc start_pos end_pos) ident
~loc:lident_loc.loc ident
[(Nolabel, strings_array); (Nolabel, values_array)]
in

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

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

0 comments on commit 8d5d89a

Please sign in to comment.