Skip to content

Commit cd5dc8a

Browse files
committed
Fix for Hello ${world} (template in template)
1 parent 1fd2962 commit cd5dc8a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

plugins/pretokenise.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,16 @@
152152
let tp = "?";
153153
if (tk.type.label=="`") { // template string
154154
// acorn splits these up into tokens, so we have to work through to the end, then just include the full text
155-
let tk2, hasTemplate = false;
155+
let tk2, hasTemplate = false, nesting=0;
156156
do {
157157
tk2 = t.getToken();
158-
if (tk2.type.label=="${")
158+
if (tk2.type.label=="${") {
159159
hasTemplate = true;
160-
} while (tk2.type.label!="`");
160+
nesting++;
161+
}
162+
if (tk2.type.label=="{") nesting++;
163+
if (tk2.type.label=="}") nesting--;
164+
} while (nesting>0 || tk2.type.label!="`");
161165
tkEnd = tk2.end;
162166
tkStr = code.substring(tk.start, tkEnd);
163167
tp = hasTemplate ? "TEMPLATEDSTRING" : "STRING"; // if we don't have any templates, treat as a normal string (https://github.com/espruino/Espruino/issues/2577)

0 commit comments

Comments
 (0)