• Convenience function for attaching tracing information to content of type Generated, in form of {astNode, property?, index: undefined}, if condition is equal to true.

    If condition is satisfied, this method returns a helper function that takes the desired content and does the processing. The returned function will create and return a new CompositeGeneratorNode being initialized with the given tracing information and add some content, if provided. Otherwise, the returned function just returns undefined.

    Exception: if content is already a CompositeGeneratorNode containing no tracing information, that node is enriched with the given tracing information and returned, and no wrapping node is created.

    Type Parameters

    Parameters

    • condition: boolean

      a boolean value indicating whether to apply the provided tracing information to the desired content.

    • astNode: T

      the AstNode corresponding to the appended content

    • Optionalproperty: Properties<T>

      the value property name (string) corresponding to the appended content, if e.g. the content corresponds to some string or number property of astNode, is optional

    Returns ((content?: Generated | ((node: CompositeGeneratorNode) => void)) => CompositeGeneratorNode | undefined)

    a function behaving as described above, which in turn returns a CompositeGeneratorNode.

    new CompositeGeneratorNode().appendTemplate
    `Hello World!`
    .appendNewLine().appendTracedTemplate(entity)
    `Hello ${ traceToNodeIf(!!entity.name, entity, 'name')(entity.name) }`
    .appendNewLineIfNotEmpty()
  • Convenience function for attaching tracing information to content of type Generated, in form of {astNode, property, index}, if condition is equal to true.

    If condition is satisfied, this method returns a helper function that takes the desired content and does the processing. The returned function will create and return a new CompositeGeneratorNode being initialized with the given tracing information and add some content, if provided. Otherwise, the returned function just returns undefined.

    Exception: if content is already a CompositeGeneratorNode containing no tracing information, that node is enriched with the given tracing information and returned, and no wrapping node is created.

    Type Parameters

    Parameters

    • condition: boolean

      a boolean value indicating whether to apply the provided tracing information to the desired content.

    • astNode: T

      the AstNode corresponding to the appended content

    • property: Properties<T>

      the value property name (string) corresponding to the appended content, if e.g. the content corresponds to some string or number property of astNode

    • index: undefined | number

      the index of the value within a list property corresponding to the appended content, if the property contains a list of elements, is ignored otherwise

    Returns ((content?: Generated | ((node: CompositeGeneratorNode) => void)) => CompositeGeneratorNode | undefined)

    a function behaving as described above, which in turn returns a CompositeGeneratorNode.

    new CompositeGeneratorNode().appendTemplate
    `Hello World!`
    .appendNewLine().appendTracedTemplate(entity)
    `Hello ${ traceToNodeIf(!!entity.name, entity, 'name')(entity.name) }`
    .appendNewLineIfNotEmpty()
  • Convenience function for attaching tracing information to content of type Generated, in form of concrete coordinates, if condition is equal to true.

    If condition is satisfied, this method returns a helper function that takes the desired content and does the processing. The returned function will create and return a new CompositeGeneratorNode being initialized with the given tracing information and add some content, if provided. Otherwise, the returned function just returns undefined.

    Exception: if content is already a CompositeGeneratorNode containing no tracing information, that node is enriched with the given tracing information and returned, and no wrapping node is created.

    If sourceRegions is a function supplying the corresponding regions, it's only called if condition is satisfied.

    Parameters

    • condition: boolean

      a boolean value indicating whether to apply the provided tracing information to the desired content.

    • sourceRegion: undefined | SourceRegion | (() => SourceRegion | undefined)

      a text region within some file in form of concrete coordinates, if undefined no tracing will happen

    Returns ((content?: Generated | ((node: CompositeGeneratorNode) => void)) => CompositeGeneratorNode | undefined)

    a function behaving as described above, which in turn returns a CompositeGeneratorNode.

    new CompositeGeneratorNode().appendTemplate
    `Hello World!`
    .appendNewLine().appendTracedTemplate(entity.$cstNode)
    `Hello ${ traceToNodeIf(!!entity.name, () => findNodeForProperty(entity.$cstNode, 'name'))(entity.name) }`
    .appendNewLineIfNotEmpty()
  • Convenience function for attaching tracing information to content of type Generated, in form of a list of concrete coordinates, if condition is equal to true.

    If condition is satisfied, this method returns a helper function that takes the desired content and does the processing. The returned function will create and return a new CompositeGeneratorNode being initialized with the given tracing information and add some content, if provided. Otherwise, the returned function just returns undefined.

    Exception: if content is already a CompositeGeneratorNode containing no tracing information, that node is enriched with the given tracing information and returned, and no wrapping node is created.

    The list of regions in sourceRegions will later be reduced to the smallest encompassing region of all the contained source regions. If sourceRegions is a function supplying the corresponding regions, it's only called if condition is satisfied.

    Parameters

    • condition: boolean

      a boolean value indicating whether to apply the provided tracing information to the desired content.

    • sourceRegions: SourceRegion[] | (() => SourceRegion[])

      a list of text region within some file in form of concrete coordinates, if empty no tracing will happen

    Returns ((content?: Generated | ((node: CompositeGeneratorNode) => void)) => CompositeGeneratorNode | undefined)

    a function behaving as described above, which in turn returns a CompositeGeneratorNode.

    new CompositeGeneratorNode().appendTemplate
    `Hello World!`
    .appendNewLine().appendTracedTemplate(entity.$cstNode)
    `Hello ${ traceToNodeIf(!!entity.name, () => findNodesForProperty(entity.$cstNode, 'name'))(entity.name) }`
    .appendNewLineIfNotEmpty()