awv3
Version:
⚡ AWV3 embedded CAD
16 lines (13 loc) • 511 B
JavaScript
import Ast from './ast';
import NameVariable from './namevariable';
import VariableDef from './variabledef';
export default class Module extends Ast {
static _fields = ['body'];
unparse() {
let variables = new Set();
for (let node of this.walk())
if (node instanceof NameVariable) variables.add(node);
const stmts = variables.size !== 0 ? [new VariableDef([...variables])] : [];
return stmts.concat(this.body).map(stmt => stmt.unparse()).join(' ');
}
}