How to use the @glimmer/opcode-compiler.syntaxCompilationContext 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 / bundle-compiler / lib / bundle-compiler.ts View on Github external
let vmHandle:
      | number
      | { handle: number; errors: EncoderError[] }
      | undefined = this.compilerModuleLocatorResolver().getHandleByLocator(locator);
    if (vmHandle !== undefined) return vmHandle;

    // It's an error to try to compile a template that wasn't first added to the
    // bundle via the add() or addCompilableTemplate() methods.
    let compilableTemplate = expect(
      this.context.compilableTemplates.get(locator),
      `Can't compile a template that wasn't already added to the bundle (${locator.name} @ ${locator.module})`
    );

    // Compile the template, which writes opcodes to the heap and returns the VM
    // handle (the address of the compiled program in the heap).
    vmHandle = compilableTemplate.compile(syntaxCompilationContext(this.context, this.macros));

    if (typeof vmHandle !== 'number') {
      return vmHandle;
    }

    // Index the locator by VM handle and vice versa for easy lookups.
    this.compilerModuleLocatorResolver().setHandleByLocator(locator, vmHandle);

    return vmHandle;
  }
}