add compiletimejs
This commit is contained in:
parent
48b0833401
commit
55a699c7fd
25
src/plugins/compile-time-js.ts
Normal file
25
src/plugins/compile-time-js.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { Plugin } from "..";
|
||||||
|
|
||||||
|
export default class CompileTimeJS extends Plugin {
|
||||||
|
name = "compile-time-js";
|
||||||
|
rewriteTriggers = ["html", "*"]
|
||||||
|
longLasting = false;
|
||||||
|
build = undefined;
|
||||||
|
|
||||||
|
async rewriteFile(file: string, filePath: string): Promise<string> {
|
||||||
|
let input = file;
|
||||||
|
const regex = /{&(.+)&}/gm;
|
||||||
|
|
||||||
|
let m;
|
||||||
|
|
||||||
|
while ((m = regex.exec(file)) !== null) {
|
||||||
|
if (m.index === regex.lastIndex) {
|
||||||
|
regex.lastIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
input = file.slice(0, m.index) + eval(m[1]) + file.slice(m.index + m[0].length);
|
||||||
|
}
|
||||||
|
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue