marko/compiler/ast/Return.js
Patrick Steele-Idem c386da875e Fixes #349 - Inline Marko template compilation support
Also changed how JavaScript code is generated
2016-08-19 10:50:28 -06:00

36 lines
741 B
JavaScript

'use strict';
var Node = require('./Node');
class Return extends Node {
constructor(def) {
super('Return');
this.argument = def.argument;
}
generateCode(codegen) {
if (!codegen.inFunction) {
throw new Error('"return" not allowed outside a function body');
}
this.argument = codegen.generateCode(this.argument);
return this;
}
writeCode(writer) {
var argument = this.argument;
if (argument) {
writer.write('return ');
writer.write(argument);
} else {
writer.write('return');
}
}
walk(walker) {
this.argument = walker.walk(this.argument);
}
}
module.exports = Return;