-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.js
54 lines (49 loc) · 1.6 KB
/
generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";
let Context = require("./context");
module.exports = class Generator{
constructor( program, error, verbose ) {
this.program = program;
this.error = error;
this.verbose = verbose;
this.inScript = false;
this.INDENT = 4;
this.counter = 0;
}
log( message ) {
if(this.verbose) {
console.log(message);
}
}
// setScriptMode (isScriptMode){
// let lines = [];
// if(isScriptMode){
// // If we belong in a script tag, but we're not in one, we need to start one
// if(!this.inScript){
// // Note I'm not going to indent this tag at the same level, so I have to do it separately
// lines.push(`<script type='text/javascript'>`);
// lines.push(`'use strict';`);
// this.inScript = true;
// }
// }
// else{
// // Likewise, if this doesn't belong in a script tag, and we're in one, close it
// if(this.inScript){
// lines.push(`</script>`);
// this.inScript = false;
// }
// }
// return lines;
// }
// Takes an array of lines of code and fixes it in various ways
indent(lines){
lines = lines || [];
return lines.map(str => " ".repeat(this.INDENT) + str);
}
get builtinFunctions() {
return {};
}
init() {
let context = new Context(null, this.error, "document.getElementsByTagName('html')[0]");
return this.program.generate( this, context );
}
};