Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
): Option {
let definitionHandle = this.lookupComponentHandle(name, referrer);
if (definitionHandle === null) {
return null;
}
let templateHandle = this.lookup('template-source', name, null);
if (templateHandle === null) {
throw new Error('BUG: missing dynamic layout');
}
// TODO: This whole thing probably should have a more first-class
// structure.
let template = unwrapTemplate(
this.customCompilableTemplate(templateHandle, name, source => {
let factory = createTemplate(source);
return factory.create();
})
);
return {
handle: definitionHandle,
capabilities: this.getCapabilities(definitionHandle),
compilable: template.asWrappedLayout(),
};
// let handle = this.resolver.lookupComponentHandle(name, referrer);
// if (handle === null) {
// return null;
appendTo(selector: string) {
let element = assertElement(document.querySelector(selector) as SimpleElement);
let self = new UpdatableRootReference(this);
let cursor = { element, nextSibling: null };
let handle = unwrapTemplate(this.template)
.asLayout()
.compile(this.syntax);
let templateIterator = renderJitMain(
this.runtime,
this.syntax,
self,
clientBuilder(this.runtime.env, cursor),
unwrapHandle(handle)
);
let result;
do {
result = templateIterator.next();
} while (!result.done);
this.element = firstElementChild(element)!;
getJitStaticLayout(
state: TestComponentDefinitionState,
resolver: JitRuntimeResolver
): CompilableProgram {
return unwrapTemplate(resolver.compilable(state.locator)).asLayout();
}
export function renderTemplate(
src: string,
{ runtime, syntax }: JitTestDelegateContext,
self: VersionedPathReference,
builder: ElementBuilder
): RenderResult {
let template = preprocess(src);
let handle = unwrapTemplate(template)
.asLayout()
.compile(syntax);
let iterator = renderJitMain(runtime, syntax, self, builder, unwrapHandle(handle));
return renderSync(runtime.env, iterator);
}
getJitStaticLayout(
state: TestComponentDefinitionState,
resolver: JitRuntimeResolver
): CompilableProgram {
return unwrapTemplate(resolver.compilable(state.locator)).asLayout();
}
getJitStaticLayout(
state: TestComponentDefinitionState,
resolver: TestJitRuntimeResolver
): CompilableProgram {
let { name } = state;
let handle = resolver.lookup('template-source', name)!;
return unwrapTemplate(
resolver.registry.customCompilableTemplate(handle, name, source =>
createTemplate(source).create()
)
).asLayout();
}
}
let templateHandle = this.resolver.lookup('template-source', name, null);
if (templateHandle === null) {
throw new Error(
`missing compile-time layout, but component ${name} didn't have the dynamicLayout capability`
);
}
let source = this.resolve(templateHandle);
if (source === null || typeof source !== 'string') {
throw new Error('UH OH');
}
let template = unwrapTemplate(this.registry.templateFromSource(source, name));
let compilable = capabilities.wrapped ? template.asWrappedLayout() : template.asLayout();
return {
handle: definitionHandle,
capabilities,
compilable,
};
}
async getTemplateIterator(
app: Application,
env: Environment,
builder: ElementBuilder,
dynamicScope: DynamicScope,
self: PathReference
): Promise {
let resolver = this.getResolver(app);
let context = this.getContext(resolver);
let runtime = CustomJitRuntime(resolver, context, app.env);
let mainLayout = unwrapTemplate(templateFactory(mainTemplate).create());
let handle = unwrapHandle(mainLayout.asLayout().compile(context));
return Promise.resolve(
renderJitMain(
runtime,
context,
self,
builder,
handle,
dynamicScope
)
);
}
constructor(name?: string, templateOrHandle?: Template | number, symbolTable?: ProgramSymbolTable) {
if (typeof templateOrHandle === 'number') {
this.handle = templateOrHandle;
this.symbolTable = symbolTable;
} else if (templateOrHandle !== undefined) {
this.template = unwrapTemplate(templateOrHandle);
}
this.state = {
name,
definition: this,
};
}
}
constructor(
name: string,
ComponentClass: ComponentFactory,
delegate: ManagerDelegate,
templateOrHandle: Template | number,
symbolTable?: ProgramSymbolTable
) {
if (typeof templateOrHandle === 'number') {
this.handle = templateOrHandle;
this.symbolTable = symbolTable;
} else {
this.template = unwrapTemplate(templateOrHandle);
}
this.state = {
name,
ComponentClass,
delegate,
definition: this
};
}
}