marko/compiler/ast/SelfInvokingFunction.js
2015-12-07 13:21:02 -07:00

32 lines
856 B
JavaScript

'use strict';
var Node = require('./Node');
class SelfInvokingFunction extends Node {
constructor(def) {
super('SelfInvokingFunction');
this.params = def.params;
this.args = def.args;
this.body = this.makeContainer(def.body);
}
generateCode(generator) {
var params = this.params || [];
var args = this.args || [];
var body = this.body;
var isStatement = this.statement;
generator.write('(');
var functionDeclaration = generator.builder.functionDeclaration(null, params, body);
var functionCall = generator.builder.functionCall(functionDeclaration, args);
generator.generateCode(functionCall);
generator.write(')');
if (isStatement) {
generator.write('\n');
}
}
}
module.exports = SelfInvokingFunction;