How to use the edge-parser.EdgeBuffer function in edge-parser

To help you get started, we’ve selected a few edge-parser 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 edge-js / edge / src / Tags / Component.ts View on Github external
token.children.forEach((child, index) => {
      let slotName: string = `'main'`
      let slotProps: string | null = null

      /**
       * Update the slot name and props when a new slot is detected
       */
      if (isBlockToken(child, 'slot')) {
        [slotName, slotProps] = getSlotNameAndProps(child, parser)
      }

      /**
       * Create a new slot with buffer to process the childs
       */
      if (!slots[slotName]) {
        slots[slotName] = { buffer: new EdgeBuffer(`slot_${index}`), props: slotProps }

        /**
         * Only start the frame, when there are props in use for a given slot.
         */
        if (slotProps) {
          slots[slotName].buffer.writeStatement('ctx.newFrame();')
          slots[slotName].buffer.writeStatement(`ctx.setOnFrame('${slotProps}', ${slotProps});`)
        }
      }

      /**
       * We must process slot of a component by ourselves (instead of making slot tag)
       * process it. This way, we can disallow slots appearing outside the component
       * tag
       */
      if (isBlockToken(child, 'slot')) {
github edge-js / edge / src / Compiler / index.ts View on Github external
/**
     * Resolve the template and Presenter using the given loader
     */
    const { template, Presenter } = this._loader.resolve(absPath, loadPresenter)

    /**
     * Convert template to AST. The AST will have the layout actions merged (if layout)
     * is used.
     */
    const templateTokens = this._templateContentToTokens(template, parser, absPath)

    /**
     * Finally process the ast
     */
    const buffer = new EdgeBuffer()
    templateTokens.forEach((token) => parser.processLexerToken(token, buffer))

    const payload = {
      template: buffer.flush(wrapAsFunction),
      Presenter,
    }

    this._cacheManager.set(absPath, payload)
    return payload
  }
}