MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / processMacros

Function processMacros

src/parseTools.mjs:64–78  ·  view source on GitHub ↗
(text, filename)

Source from the content-addressed store, hash-verified

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 ''!
64export 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
80function findIncludeFile(filename, currentDir) {
81 if (path.isAbsolute(filename)) {

Callers 2

getIncludeFileFunction · 0.90
preprocessFilesFunction · 0.90

Calls 4

pushCurrentFileFunction · 0.90
runInMacroContextFunction · 0.90
popCurrentFileFunction · 0.90
mangleUnsupportedSyntaxFunction · 0.85

Tested by

no test coverage detected