marko/compiler/ast/ForEach.js
Patrick Steele-Idem 069b3e5ba9 Initial commit for marko v3 with htmljs-parser
Work-in-progress. Lots of failing tests.
2015-11-24 14:30:32 -07:00

31 lines
767 B
JavaScript

'use strict';
var ok = require('assert').ok;
var Node = require('./Node');
class ForEach extends Node {
constructor(def) {
super('ForEach');
this.varName = def.varName;
this.target = def.target;
this.body = this.makeContainer(def.body);
ok(this.varName, '"varName" is required');
ok(this.target, '"target" is required');
}
generateCode(generator) {
var varName = this.varName;
var target = this.target;
var builder = generator.builder;
generator.addStaticVar('forEach', '__helpers.f');
return builder.functionCall('forEach', [
target,
builder.functionDeclaration(null, [varName], this.body)
]);
}
}
module.exports = ForEach;