All files / builder/mini-program-compiler component-compiler.service.ts

100% Statements 17/17
100% Branches 2/2
100% Functions 5/5
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32  1x   1x 1x   1x 227x   226x   226x 226x       226x 226x       226x 1057x       226x 226x 226x      
import type { R3ComponentMetadata } from '@angular/compiler';
import { Inject, Injectable } from 'static-injector';
import { BuildPlatform } from '../platform/platform';
import { COMPONENT_META } from '../token/component.token';
import { ComponentContext, TemplateDefinition } from './parse-node';
 
@Injectable()
export class ComponentCompilerService {
  constructor(
    private buildPlatform: BuildPlatform,
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    @Inject(COMPONENT_META) private componentMeta: R3ComponentMetadata<any>,
    private componentContext: ComponentContext
  ) {}
 
  private collectionNode() {
    const nodes = this.componentMeta.template.nodes;
    const templateDefinition = new TemplateDefinition(
      nodes,
      this.componentContext
    );
    const list = templateDefinition.run();
    return list.map((item) => item.getNodeMeta());
  }
 
  compile() {
    const nodeList = this.collectionNode();
    const result = this.buildPlatform.templateTransform.compile(nodeList);
    return result;
  }
}