add all of the testing
This commit is contained in:
parent
d5b4341487
commit
91f39a80a7
12 changed files with 485 additions and 69 deletions
|
|
@ -8,16 +8,23 @@ export default class CompileTimeJS extends Plugin {
|
|||
|
||||
async rewriteFile(file: string, filePath: string): Promise<string> {
|
||||
let input = file;
|
||||
const regex = /{&(.+)&}/gms;
|
||||
const regex = /\{\&([\s\S]*?)\&\}/gms;
|
||||
|
||||
let m;
|
||||
|
||||
while ((m = regex.exec(file)) !== null) {
|
||||
while ((m = regex.exec(input)) !== null) {
|
||||
if (m.index === regex.lastIndex) {
|
||||
regex.lastIndex++;
|
||||
}
|
||||
|
||||
input = file.slice(0, m.index) + eval(m[1]) + file.slice(m.index + m[0].length);
|
||||
const before = input.slice(0, m.index);
|
||||
const expr = m[1];
|
||||
const after = input.slice(m.index + m[0].length);
|
||||
|
||||
const result = eval(expr); // You can replace this with Function() for sandboxing
|
||||
input = before + result + after;
|
||||
|
||||
// Reset regex lastIndex since we changed the string
|
||||
regex.lastIndex = 0;
|
||||
}
|
||||
|
||||
return input;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue