ember-legacy-class-transform
Version:
The default blueprint for ember-cli addons.
35 lines (34 loc) • 1.35 kB
JavaScript
import { CompiledDynamicTemplate, CompiledStaticTemplate } from '../compiled/blocks';
import { debugSlice } from '../opcodes';
import { compileStatements } from './functions';
export default class CompilableTemplate {
constructor(statements, symbolTable) {
this.statements = statements;
this.symbolTable = symbolTable;
this.compiledStatic = null;
this.compiledDynamic = null;
}
compileStatic(env) {
let { compiledStatic } = this;
if (!compiledStatic) {
let builder = compileStatements(this.statements, this.symbolTable.meta, env);
builder.finalize();
let handle = builder.start;
if (false) {
let start = env.program.heap.size() - env.program.heap.sizeof(handle);
let end = start + env.program.heap.sizeof(handle);
debugSlice(env, start, end);
}
compiledStatic = this.compiledStatic = new CompiledStaticTemplate(handle);
}
return compiledStatic;
}
compileDynamic(env) {
let { compiledDynamic } = this;
if (!compiledDynamic) {
let staticBlock = this.compileStatic(env);
compiledDynamic = new CompiledDynamicTemplate(staticBlock.handle, this.symbolTable);
}
return compiledDynamic;
}
}