Skip to content

Commit fb28235

Browse files
authored
Simplify processMacros. NFC (#18322)
1 parent 54ddebb commit fb28235

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/parseTools.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ let currentlyParsedFilename = '';
1717
// {{{ code }}} will be replaced with |eval(code)|.
1818
// NOTE: Be careful with that ret check. If ret is |0|, |ret ? ret.toString() : ''| would result in ''!
1919
function processMacros(text) {
20-
return text.replace(/{{{([^}]|}(?!}))+}}}/g, (str) => {
21-
str = str.substr(3, str.length - 6);
20+
// The `?` here in makes the regex non-greedy so it matches with the closest
21+
// set of closing braces.
22+
// `[\s\S]` works like `.` but include newline.
23+
return text.replace(/{{{([\s\S]+?)}}}/g, (_, str) => {
2224
try {
2325
const ret = eval(str);
2426
return ret !== null ? ret.toString() : '';

0 commit comments

Comments
 (0)