ReviewOS

also looking at this

stacks/stx

feat(dx): dev-mode warning for unbalanced template tags (#1769)

#1770
Merged glennmichael123 wants to merge feat/1769-tag-balance-dev-warning into main
4 files +277 -0
packages/stx/src/process.tsmodified+11-0
Changes to packages/stx/src/process.ts
@@ -60,6 +60,8 @@ import { processInlineAssets } from './inline-assets'
6060import { addCloakToConditionalDirectives, addCloakToUnresolvedExpressions, processJsonDirective, processMemoDirective, processOnceDirective, processRefAttributes } from './misc-directives'
6161import { validateClientScript } from './script-validation'
6262import { safeEvaluate } from './safe-evaluator'
63import { isProduction, isTest } from './env'
64import { warnUnbalancedTags } from './template-tag-balance'
6365import { deriveLayoutGroup } from 'stx-router/layout-metadata'
6466
6567// Re-export public API from extracted modules (preserves backwards compatibility)
@@ -299,6 +301,15 @@ export async function processDirectives(
299301 context.__onceStore = new Set<string>()
300302 }
301303
304 // #1769: dev-mode tag-balance heads-up for top-level views/layouts, on the
305 // RAW template before any processing auto-closes tags. @include'd partials
306 // are checked separately in the include pipeline. On by default in
307 // development; opt-in via `debug` elsewhere; off in prod + the test runner.
308 // Deduped + best-effort.
309 if ((options.debug || (!isProduction() && !isTest())) && filePath && filePath.endsWith('.stx')) {
310 warnUnbalancedTags(template, filePath)
311 }
312
302313 try {
303314 return await performanceMonitor.timeAsync('template-processing', async () => {
304315 let result = await processDirectivesInternal(template, context, filePath, options, dependencies)