UNPKG

awv3

Version:
16 lines (13 loc) 511 B
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(' '); } }