Description
Currently, when compiling logic via TemplateArchiveProcessor, the template-engine evaluator supports two flavors of logic: one with a TemplateLogic instance and another with a plain JS function.
However, external execution environments (like the Web Worker Sandbox in template-playground) strictly require the compiled output to contain a class extending TemplateLogic so it can be instantiated dynamically.
Proposal
Instead of consumer applications having to manually regex-parse the compiled string (e.g. code.match(/class\s+(\w+)\s+extends\s+TemplateLogic/)) to validate the output, it would be much more robust to handle this validation directly within TemplateArchiveProcessor.
The compile method could either:
- Automatically throw a compilation error if a valid
TemplateLogic class definition isn't found.
- Accept a strict flag (e.g.,
requireTemplateLogic: true) that enforces this validation during the compilation step.
Context
This was brought up during the review of the Sandboxed Logic Execution pipeline for the Template Playground: accordproject/template-playground#932 (comment)
Description
Currently, when compiling logic via
TemplateArchiveProcessor, thetemplate-engineevaluator supports two flavors of logic: one with aTemplateLogicinstance and another with a plain JS function.However, external execution environments (like the Web Worker Sandbox in
template-playground) strictly require the compiled output to contain a class extendingTemplateLogicso it can be instantiated dynamically.Proposal
Instead of consumer applications having to manually regex-parse the compiled string (e.g.
code.match(/class\s+(\w+)\s+extends\s+TemplateLogic/)) to validate the output, it would be much more robust to handle this validation directly withinTemplateArchiveProcessor.The compile method could either:
TemplateLogicclass definition isn't found.requireTemplateLogic: true) that enforces this validation during the compilation step.Context
This was brought up during the review of the Sandboxed Logic Execution pipeline for the Template Playground: accordproject/template-playground#932 (comment)