Skip to content

Conversation

@geclos
Copy link
Contributor

@geclos geclos commented Sep 23, 2025

This PR introduces a generic system for builtin variables that resolve at runtime, starting with $now which returns a Date instance.

Changes

  • Implemented a builtins object passed through the compilation pipeline
  • Modified mustache parsing to always treat expressions uniformly, removing special handling
  • Added error checking to prevent assignment to builtin variables
  • Updated $now to return a Date instance instead of ISO string, allowing method calls like $now.getTime()
  • Added comprehensive tests for builtin usage in expressions and error cases

Features

  • Builtin variables can be used anywhere in expressions: {{ time = $now }}, {{ $now.getTime() }}
  • Attempting to assign to builtins raises a compile-time error
  • System is extensible: add new builtins by updating SPECIAL_IDENTIFIERS and SPECIAL_RESOLVERS in constants.ts

All tests pass with 235/238 (3 todo remaining).

@geclos geclos force-pushed the feat/today_special_parameter branch 5 times, most recently from 5c10bde to bea595e Compare September 25, 2025 09:17
@geclos geclos changed the title Add special {{today}} parameter that returns current date in ISO format Add special {{now}} parameter that returns current date in ISO format Sep 25, 2025
@geclos geclos changed the title Add special {{now}} parameter that returns current date in ISO format Add special {{ $now }} parameter that returns current date in ISO format Sep 25, 2025
@geclos geclos force-pushed the feat/today_special_parameter branch from bea595e to c8a5b5b Compare September 25, 2025 09:22
@geclos geclos force-pushed the feat/today_special_parameter branch 2 times, most recently from 9bde3c2 to 7c9299b Compare September 25, 2025 10:05
@geclos geclos changed the title Add special {{ $now }} parameter that returns current date in ISO format Add flexible builtin variables system with $now Date instance Sep 25, 2025
- Modified resolveExpression in compile.ts to handle '@now' identifier
- Added test case for {{@now}} functionality
- {{@now}} is replaced at runtime with new Date().toISOString()
@geclos geclos force-pushed the feat/today_special_parameter branch from 7c9299b to 5ba4af2 Compare September 25, 2025 10:26
@geclos geclos merged commit 42535f2 into main Sep 25, 2025
2 checks passed
@geclos geclos deleted the feat/today_special_parameter branch September 25, 2025 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants