Skip to content

draft() can't resolve TypeScript helper functions defined in logic/logic.ts #147

@mttrbrts

Description

@mttrbrts

Reproduction

Repo: accordproject/cicero-template-library PR #484, template src/fixed-interests.

grammar.tem.md (excerpt):

and monthly payments of {{% monthlyPaymentFormula(loanAmount,rate,loanDuration) as "K0,0.00" %}}

logic/logic.ts (excerpt):

function monthlyPaymentFormula(loanAmount: number, rate: number, loanDuration: number): number {
    // ...
    return monthly;
}
class FixedInterestsLogic extends TemplateLogic<ITemplateModel> { ... }

Driver:

const t = await Template.fromDirectory('./src/fixed-interests');
await new TemplateArchiveProcessor(t).draft(data, 'markdown', {});

Observed

{
  nodeId: 'formula_d02c8642fa12d6ed08dea71f0af7a77b0c7893804d0b43b537eb18ea6f666463',
  code: ' monthlyPaymentFormula(loanAmount,rate,loanDuration) as "K0,0.00" ',
  errors: [{
    category: 1, code: 2304,
    renderedMessage: "Cannot find name 'monthlyPaymentFormula'.",
    id: 'err-2304-684-21'
  }]
}

The formula references a helper function defined in the template's logic/logic.ts, but TemplateArchiveProcessor.draft compiles the formula with a TypeScript context that doesn't include the template's user code. TemplateArchiveProcessor.trigger already does load the logic — only draft is affected.

Expected

draft() should compile inline formulas against the same TypeScript context as trigger(), so helper functions exported/defined alongside the TemplateLogic subclass are visible to formulas.

Versions

  • @accordproject/template-engine@3.0.1
  • @accordproject/cicero-core@0.26.0
  • @accordproject/concerto-core@4.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions