marko/compiler/ast/Return.js
2015-12-31 13:32:46 -07:00

27 lines
560 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');
}
var argument = this.argument;
if (argument) {
codegen.write('return ');
codegen.generateCode(argument);
} else {
codegen.write('return');
}
}
}
module.exports = Return;