31 lines
838 B
JavaScript
31 lines
838 B
JavaScript
"use strict";
|
|
function extractInputs(fragmentSource, out) {
|
|
let match;
|
|
const regex = /@in\s+([^;]+);/g;
|
|
while ((match = regex.exec(fragmentSource)) !== null) {
|
|
out.push(match[1]);
|
|
}
|
|
}
|
|
function compileInputs(fragments, template, sort = false) {
|
|
const results = [];
|
|
extractInputs(template, results);
|
|
fragments.forEach((fragment) => {
|
|
if (fragment.header) {
|
|
extractInputs(fragment.header, results);
|
|
}
|
|
});
|
|
const mainInput = results;
|
|
if (sort) {
|
|
mainInput.sort();
|
|
}
|
|
const finalString = mainInput.map((inValue, i) => ` @location(${i}) ${inValue},`).join("\n");
|
|
let cleanedString = template.replace(/@in\s+[^;]+;\s*/g, "");
|
|
cleanedString = cleanedString.replace("{{in}}", `
|
|
${finalString}
|
|
`);
|
|
return cleanedString;
|
|
}
|
|
|
|
export { compileInputs };
|
|
//# sourceMappingURL=compileInputs.mjs.map
|