| 18 | write(fn: ModeWriter): void; |
| 19 | write(line: string): void; |
| 20 | write(arg: any) { |
| 21 | if (typeof arg === "function") { |
| 22 | (arg as ModeWriter)(this, { execution: "sync" }); |
| 23 | (arg as ModeWriter)(this, { execution: "async" }); |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | const content = arg as string; |
| 28 | const lines = content.split("\n").filter((x) => x); |
| 29 | const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length)); |
| 30 | const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x); |
| 31 | for (const line of dedented) { |
| 32 | this.content.push(line); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | compile(): any { |
| 37 | const F = Function; |