(text, filename)
| 62 | // {{{ code }}} will be replaced with |eval(code)|. |
| 63 | // NOTE: Be careful with that ret check. If ret is |0|, |ret ? ret.toString() : ''| would result in ''! |
| 64 | export function processMacros(text, filename) { |
| 65 | // The `?` here in makes the regex non-greedy so it matches with the closest |
| 66 | // set of closing braces. |
| 67 | // `[\s\S]` works like `.` but include newline. |
| 68 | pushCurrentFile(filename); |
| 69 | try { |
| 70 | text = text.replace(/{{{([\s\S]+?)}}}/g, (_, str) => { |
| 71 | const ret = runInMacroContext(str, {filename: filename}); |
| 72 | return ret?.toString() ?? ''; |
| 73 | }); |
| 74 | return mangleUnsupportedSyntax(text); |
| 75 | } finally { |
| 76 | popCurrentFile(); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | function findIncludeFile(filename, currentDir) { |
| 81 | if (path.isAbsolute(filename)) { |
no test coverage detected