EMIT EMAIL

JSX-Lite Template DSL Engine

Email Personalization • Deterministic Output • Type-Safe Evaluation

Overview

EMIT is a deterministic templating system designed for high-clarity email personalization using a familiar JSX-Lite syntax. It provides a type-safe environment for rendering complex, data-driven templates with absolute consistency. Templates follow a structured XML hierarchy with explicit line break definitions and pure expression evaluation.

Basic Structure

Templates utilize a structured XML hierarchy. The engine uses <Line> tags within the body to define explicit line breaks and ensure clean formatting.

<Email>
 <Subject>{expression}</Subject>
 <Body>
 <Line>{field}</Line>
 <Line>Static text combined with {field}</Line>
 </Body>
</Email>

Field Substitution

Data is mapped from a flat schema. Nested objects and computed method calls are not supported to maintain determinism.

  • {field_name}for direct injection.
  • Missing Fields:Automatically render as empty strings without throwing errors.
  • Booleans:Render as "true" or "false" strings.
  • Numbers:Can be used in arithmetic and numeric comparisons.

Supported Operators

The engine supports complex logic with proper mathematical operator precedence.

CategoryOperatorsExamples
String Comparison===, !=={name === "Alice" ? "Match" : "No"}
Numeric Comparison>, <, >=, <={age > 18 ? "Adult" : "Minor"}
Logical&&, ||, !{premium && active ? "Yes" : "No"}
Arithmetic+, -{count + 5}, {total - discount}

Ternary Operator

For conditional logic, use the ternary operator:

{condition ? "if true" : "if false"}

Language Rules & Constraints

Flat Schema: Field names must be top-level; nested paths (e.g., user.name) are prohibited.
Type Coercion: Numeric comparisons require numbers; string comparisons use strict equality (===).
Truthiness: false, 0, empty strings, null, and undefined are falsy. All other values (including "0") are truthy.
Null Handling: null and undefined render as empty strings.
Concatenation: Use the + operator for combining strings; template literals are not supported.
No Statements: No if/else statements or for loops; all branching must occur via ternary operators.
No Comments: Code comments are not permitted within template syntax.
No Functions: Custom functions and method calls are not supported.

Technical Constraints

Template Size Limit: 50KB maximum per template (DOS protection)
Expression Nesting Depth: Maximum 100 levels of nesting
Synchronous Only: All operations are synchronous; no async/await support
Pure Expressions: Only expressions allowed; no statements or control flow
Determinism: Same template + same data = identical output, every time

Implementation Example

Template:

<Email>
 <Subject>{industry === "SaaS" ? "Growing " + product : "Idea for " + company}</Subject>
 <Body>
 <Line>Hi {firstname},</Line>
 <Line>{employees > 50 ? "Scaling for teams." : "Growth for startups."}</Line>
 </Body>
</Email>

Sample Data:

{
 firstname: "Alice",
 industry: "SaaS",
 product: "CRM platform",
 company: "Acme",
 employees: 75
}

Resulting Output:

Subject: Growing CRM platform
Body: Hi Alice, Scaling for teams.

Operator Precedence (Highest to Lowest)

LevelOperators
1( ), field, string, number
2! (logical NOT), - (negation)
3> < >= <= === !==
4Logical AND &&
5Logical OR ||
6Additive +, -
7Ternary ? :

Key Features

JSX-Lite DSL

Familiar syntax without complexity

Deterministic Output

Same input always produces identical output

Type-Safe Evaluation

Schema validation prevents undefined errors

Proper Operator Precedence

Complex expressions evaluate correctly

Security Built-In

Template size limits and expression depth protection

Backwards Compatible

Works with existing templates

Real-World Use Case

A marketing team wants to send personalized outreach emails to 500 prospects. They create one template that adapts based on company size and industry. Using EMIT, they can:

  • Test the template with 10 sample records
  • See exactly what each recipient receives
  • Be confident in sending 500+ emails simultaneously
  • Track that each email is personalized correctly
  • Modify the template and re-send with zero duplicates or errors

Limitations

No nested objects: Schema must be flat (firstname, not user.firstname)
No loops: Cannot iterate over arrays or repeated structures
No async: All operations are synchronous
No comments: Comments within templates not supported
No string interpolation: Use + concatenation instead
No regular expressions: Only string equality and numeric comparisons