marko/compiler/ast/Macro.js
Patrick Steele-Idem 8c96302550 Fixes #197 - Better attribute code generation
Use attr helper and handle attribute escaping
Also improved AST and added walking capability
2016-01-07 16:05:26 -07:00

38 lines
911 B
JavaScript

'use strict';
var Node = require('./Node');
var ok = require('assert').ok;
class Macro extends Node {
constructor(def) {
super('Macro');
this.name = def.name;
this.params = def.params;
this.body = this.makeContainer(def.body);
if (this.params == null) {
this.params = [];
} else {
ok(Array.isArray(this.params), '"params" should be an array');
}
}
generateCode(codegen) {
var name = this.name;
var params = this.params || [];
var body = this.body;
var builder = codegen.builder;
var macroDef = codegen.context.registerMacro(name, params);
var functionName = macroDef.functionName;
return builder.functionDeclaration(functionName, macroDef.params, body);
}
walk(walker) {
this.body = walker.walk(this.body);
}
}
module.exports = Macro;