How to use the @glimmer/opcode-compiler.unwrapTemplate function in @glimmer/opcode-compiler

To help you get started, we’ve selected a few @glimmer/opcode-compiler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / modes / jit / registry.ts View on Github external
): 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;
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / components / emberish-root-view.ts View on Github external
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)!;
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / components / basic.ts View on Github external
getJitStaticLayout(
    state: TestComponentDefinitionState,
    resolver: JitRuntimeResolver
  ): CompilableProgram {
    return unwrapTemplate(resolver.compilable(state.locator)).asLayout();
  }
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / modes / jit / render.ts View on Github external
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);
}
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / components / emberish-glimmer.ts View on Github external
getJitStaticLayout(
    state: TestComponentDefinitionState,
    resolver: JitRuntimeResolver
  ): CompilableProgram {
    return unwrapTemplate(resolver.compilable(state.locator)).asLayout();
  }
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / components / static-tagless.ts View on Github external
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();
  }
}
github glimmerjs / glimmer-vm / packages / @glimmer / integration-tests / lib / modes / jit / compilation-context.ts View on Github external
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,
    };
  }
github glimmerjs / glimmer.js / packages / @glimmer / application / src / loaders / runtime-compiler / loader.ts View on Github external
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
      )
    );
  }
github glimmerjs / glimmer.js / packages / @glimmer / application / src / components / component-managers / template-only.ts View on Github external
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,
    };
  }
}
github glimmerjs / glimmer.js / packages / @glimmer / application / src / components / component-managers / custom.ts View on Github external
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
    };
  }
}