Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Analysis<K>

An Analysis performs book keeping and ensures internal consistency of the block objects referenced within a single template. It is designed to be used as part of an AST walk over a template.

  1. Call startElement() at the beginning of an new html element.
  2. Call [[addStyle addStyle(style, isDynamic)]] for all the styles used on the current html element.
  3. Call [[addExclusiveStyle addExclusiveStyle(alwaysPresent, ...style)]] for all the styles used that are mutually exclusive on the current html element.
  4. Call endElement() when done adding styles for the current element.

Type parameters

  • K: keyof TemplateTypes

Hierarchy

Index

Constructors

constructor

Properties

Private blocks

blocks: ObjectDictionary<Block>

A map from a local name for the block to the Block. The local name must be a legal CSS ident/class name but this is not validated here. See CLASS_NAME_IDENT for help validating a legal class name.

Private currentElement

currentElement: ElementAnalysis<any, any, any> | undefined

The current element, created when calling startElement. The current element is unset after calling endElement.

elements

elements: Map<string, ElementAnalysis<any, any, any>>

A per-element correlation of styles used. The current correlation is added to this list when endElement is called.

idGenerator

idGenerator: IdentGenerator

Optional parent

parent: Analyzer<K>

template

template: TemplateTypes[K]

Private validator

Template validator instance to verify blocks applied to an element.

Methods

addBlock

blockCount

  • blockCount(): number

blockDependencies

  • blockDependencies(): Set<Block>

elementCount

  • elementCount(): number

endElement

  • endElement<BooleanExpression, StringExpression, TernaryExpression>(element: ElementAnalysis<BooleanExpression, StringExpression, TernaryExpression>, endPosition?: SourcePosition): void
  • Finish an {ElementAnalysis} object returned from Analysis.startElement to the end location in source and save {Style} usage on the parent {Analysis}.

    Type parameters

    • BooleanExpression

    • StringExpression

    • TernaryExpression

    Parameters

    • element: ElementAnalysis<BooleanExpression, StringExpression, TernaryExpression>

      The {ElementAnalysis} we are finishing.

    • Optional endPosition: SourcePosition

      Optional. The location in code where this element tag is closed..

    Returns void

Private ensureFilename

  • ensureFilename(pos: SourcePosition | undefined): void
  • Given a {SourcePosition}, ensure that the file name is present. If not, add the template identifier.

    Parameters

    • pos: SourcePosition | undefined

    Returns void

forOptimizer

getBlock

  • getBlock(name: string): Block | undefined

getBlockName

  • getBlockName(block: Block): string | null
  • Returns the local name of the provided in this Analysis' template.

    Parameters

    • block: Block

      The block for which the local name should be returned.

    Returns string | null

    The local name of the given block.

getElement

  • getElement<BooleanExpression, StringExpression, TernaryExpression>(idx: number): ElementAnalysis<BooleanExpression, StringExpression, TernaryExpression>
  • Get the nth element discovered in this Analysis.

    Type parameters

    • BooleanExpression

    • StringExpression

    • TernaryExpression

    Parameters

    • idx: number

    Returns ElementAnalysis<BooleanExpression, StringExpression, TernaryExpression>

getElementById

  • getElementById<BooleanExpression, StringExpression, TernaryExpression>(id: string): ElementAnalysis<BooleanExpression, StringExpression, TernaryExpression> | undefined
  • Get an Element by ID.

    Type parameters

    • BooleanExpression

    • StringExpression

    • TernaryExpression

    Parameters

    • id: string

    Returns ElementAnalysis<BooleanExpression, StringExpression, TernaryExpression> | undefined

referencedBlocks

  • referencedBlocks(): Block[]

serialize

serializedName

  • serializedName(o: Style): string

startElement

  • startElement<BooleanExpression, StringExpression, TernaryExpression>(location: SourceLocation | SourcePosition, tagName?: undefined | string): ElementAnalysis<BooleanExpression, StringExpression, TernaryExpression>
  • Get a new {ElementAnalysis} object to track an individual element's {Style} consumption in this {Analysis}' template. Every {ElementAnalysis} returned from Analysis.startElement must be passed to Analysis.endElement before startElement is called again.

    Type parameters

    • BooleanExpression

    • StringExpression

    • TernaryExpression

    Parameters

    • location: SourceLocation | SourcePosition

      The {SourceLocation} of this element in the template.

    • Optional tagName: undefined | string

      Optional. The tag name of the element being represented by this {ElementAnalysis}.

    Returns ElementAnalysis<BooleanExpression, StringExpression, TernaryExpression>

    A new {ElementAnalysis}.

styleCount

  • styleCount(): number
  • Return the number of styles discovered in this Analysis' Template. TODO: This is slow. We can pre-compute this as elements are added.

    Returns number

stylesFound

  • stylesFound(dynamic?: undefined | true | false): IterableIterator<Style>

transitiveBlockDependencies

  • transitiveBlockDependencies(): Set<Block>

Static deserialize

Generated using TypeDoc