Skip to content

Commit cbb4df8

Browse files
Fix regression in template literal string scanning. (rescript-lang#394)
The scanner underwent extensive refactoring, it appears that bug was introduced in 5acbbdc Upon encountering a $ character, the routine that scans template literal tokens, shouldn't consume two characters. Example: ``` `$${dollarAmountInt}` ``` Seeing a `$` doens't imply that the next character (here also a `$`) should be consumed.
1 parent 6155500 commit cbb4df8

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

syntax/src/res_scanner.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ let scanTemplateLiteralToken scanner =
472472
in
473473
Token.TemplatePart contents
474474
| _ ->
475-
next2 scanner;
475+
next scanner;
476476
scan())
477477
| '\\' ->
478478
(match peek scanner with

syntax/tests/parsing/grammar/expressions/es6template.res

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ let s = json`null`
4545

4646
let x = `foo\`bar\$\\foo`
4747
let x = `foo\`bar\$\\foo${a} \` ${b} \` xx`
48+
49+
let thisIsFine = `$something`
50+
let thisIsAlsoFine = `fine\$`
51+
let isThisFine = `shouldBeFine$`
52+
53+
`$${dollarAmountInt}`
54+
`\$${dollarAmountInt}`

syntax/tests/parsing/grammar/expressions/expected/es6template.res.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@ let s =
3636
let s = {js|$dollar without $braces $interpolation|js}
3737
let s = {json|null|json}
3838
let x = {js|foo`bar$\foo|js}
39-
let x = ((({js|foo`bar$\foo|js} ^ a) ^ {js| ` |js}) ^ b) ^ {js| ` xx|js}
39+
let x = ((({js|foo`bar$\foo|js} ^ a) ^ {js| ` |js}) ^ b) ^ {js| ` xx|js}
40+
let thisIsFine = {js|$something|js}
41+
let thisIsAlsoFine = {js|fine$|js}
42+
let isThisFine = {js|shouldBeFine$|js}
43+
;;{js|$|js} ^ dollarAmountInt
44+
;;{js|$|js} ^ dollarAmountInt

0 commit comments

Comments
 (0)