Skip to content

Commit 93e16f6

Browse files
tsnobipcknitt
authored andcommitted
fix tag function location on compiler error
1 parent e2e1664 commit 93e16f6

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
# 11.1.3
1414

15+
#### :bug: Bug Fix
16+
17+
- Fix tag function location on compiler error. https://github.com/rescript-lang/rescript-compiler/pull/6816
18+
1519
# 11.1.3-rc.1
1620

1721
#### :bug: Bug Fix
Lines changed: 7 additions & 0 deletions
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let res = tagg`| 5 × 10 = ${5} |`

jscomp/syntax/src/res_core.ml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,6 @@ and parseTemplateExpr ?prefix p =
22672267
Some prefix
22682268
| _ -> Some "js"
22692269
in
2270-
let startPos = p.Parser.startPos in
22712270

22722271
let parseParts p =
22732272
let rec aux acc =
@@ -2300,13 +2299,9 @@ and parseTemplateExpr ?prefix p =
23002299
let parts = parseParts p in
23012300
let strings = List.map fst parts in
23022301
let values = Ext_list.filter_map parts snd in
2303-
let endPos = p.Parser.endPos in
23042302

2305-
let genTaggedTemplateCall lident =
2306-
let ident =
2307-
Ast_helper.Exp.ident ~attrs:[] ~loc:Location.none
2308-
(Location.mknoloc lident)
2309-
in
2303+
let genTaggedTemplateCall (lident_loc : Longident.t Location.loc) =
2304+
let ident = Ast_helper.Exp.ident ~attrs:[] ~loc:lident_loc.loc lident_loc in
23102305
let strings_array =
23112306
Ast_helper.Exp.array ~attrs:[] ~loc:Location.none strings
23122307
in
@@ -2315,7 +2310,7 @@ and parseTemplateExpr ?prefix p =
23152310
in
23162311
Ast_helper.Exp.apply
23172312
~attrs:[taggedTemplateLiteralAttr]
2318-
~loc:(mkLoc startPos endPos) ident
2313+
~loc:lident_loc.loc ident
23192314
[(Nolabel, strings_array); (Nolabel, values_array)]
23202315
in
23212316

@@ -2355,7 +2350,7 @@ and parseTemplateExpr ?prefix p =
23552350
match prefix with
23562351
| Some {txt = Longident.Lident ("js" | "j" | "json"); _} | None ->
23572352
genInterpolatedString ()
2358-
| Some {txt = lident} -> genTaggedTemplateCall lident
2353+
| Some lident_loc -> genTaggedTemplateCall lident_loc
23592354

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

0 commit comments

Comments
 (0)