typebars 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
1
  {
2
- "name": "typebars",
3
- "version": "1.0.0",
4
- "license": "MIT",
5
- "description": "Typebars is a type-safe handlebars based template engine for generating object or content with static type checking",
6
- "author": {
7
- "email": "arthurtinseau@live.fr",
8
- "url": "https://github.com/atinseau/typebars",
9
- "name": "atinseau"
10
- },
11
- "main": "dist/index.js",
12
- "types": "dist/index.d.ts",
13
- "type": "module",
14
- "sideEffects": false,
15
- "files": [
16
- "dist",
17
- "README.md"
18
- ],
19
- "scripts": {
20
- "postinstall": "lefthook install",
21
- "build:bun": "bun build src/*.ts --outdir ./dist --production --minify --root src --sourcemap --splitting --target node --format esm --packages external --chunk-naming='chunk-[hash].js'",
22
- "build:tsc": "tsc --project tsconfig.build.json",
23
- "build": "bun --parallel build:bun build:tsc",
24
- "prepublishOnly": "bun run build",
25
- "check-types": "tsc --noEmit",
26
- "check": "biome check --write --unsafe",
27
- "test": "bun test"
28
- },
29
- "devDependencies": {
30
- "@biomejs/biome": "2.4.3",
31
- "@types/bun": "latest",
32
- "@types/json-schema": "7.0.15",
33
- "lefthook": "2.1.1"
34
- },
35
- "peerDependencies": {
36
- "typescript": "^5"
37
- },
38
- "dependencies": {
39
- "handlebars": "4.7.8",
40
- "json-schema-to-ts": "3.1.1"
41
- }
2
+ "name": "typebars",
3
+ "version": "1.0.1",
4
+ "license": "MIT",
5
+ "description": "Typebars is a type-safe handlebars based template engine for generating object or content with static type checking",
6
+ "author": {
7
+ "email": "arthurtinseau@live.fr",
8
+ "url": "https://github.com/atinseau/typebars",
9
+ "name": "atinseau"
10
+ },
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "type": "module",
14
+ "sideEffects": false,
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "postinstall": "lefthook install",
21
+ "build:bun": "bun build src/*.ts --outdir ./dist --production --minify --root src --sourcemap --splitting --target node --format esm --packages external --chunk-naming='chunk-[hash].js'",
22
+ "build:tsc": "tsc --project tsconfig.build.json",
23
+ "build": "bun --parallel build:bun build:tsc",
24
+ "prepublishOnly": "bun run build",
25
+ "check-types": "tsc --noEmit",
26
+ "check": "biome check --write --unsafe",
27
+ "test": "bun test"
28
+ },
29
+ "devDependencies": {
30
+ "@biomejs/biome": "2.4.3",
31
+ "@types/bun": "latest",
32
+ "@types/json-schema": "7.0.15",
33
+ "lefthook": "2.1.1"
34
+ },
35
+ "peerDependencies": {
36
+ "typescript": "^5"
37
+ },
38
+ "dependencies": {
39
+ "handlebars": "4.7.8",
40
+ "json-schema-to-ts": "3.1.1"
41
+ }
42
42
  }
@@ -1,5 +0,0 @@
1
- import{e as V,f as X,g as Y,h as Z,j as _,k as $,m as w,o as B}from"./chunk-9mg6qfrs.js";import{s as K}from"./chunk-6c0pw73w.js";import M from"handlebars";function H(q,z,j){let A=V(q);if(X(A)){let J=A.body[0];return N(J.path,z,j)}let C=$(A);if(C)return N(C.path,z,j);if(_(A)){let J=Q(z,j),L=U(q,J);return w(L)}let G=Q(z,j);return U(q,G)}function N(q,z,j){if(Z(q))return z;if(q.type==="StringLiteral")return q.value;if(q.type==="NumberLiteral")return q.value;if(q.type==="BooleanLiteral")return q.value;if(q.type==="NullLiteral")return null;if(q.type==="UndefinedLiteral")return;let A=Y(q);if(A.length===0)throw new K(`Cannot resolve expression of type "${q.type}"`);let{cleanSegments:C,identifier:F}=B(A);if(F!==null&&j){let G=j[F];if(G)return O(G,C);return}if(F!==null&&!j)return;return O(z,C)}function O(q,z){let j=q;for(let A of z){if(j===null||j===void 0)return;if(typeof j!=="object")return;j=j[A]}return j}function Q(q,z){if(!z)return q;let j={...q};for(let[A,C]of Object.entries(z))for(let[F,G]of Object.entries(C))j[`${F}:${A}`]=G;return j}function U(q,z){try{return M.compile(q,{noEscape:!0,strict:!1})(z)}catch(j){let A=j instanceof Error?j.message:String(j);throw new K(A)}}
2
- export{H as c,O as d};
3
-
4
- //# debugId=4F7A13979718154664756E2164756E21
5
- //# sourceMappingURL=chunk-60gk3q7z.js.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/executor.ts"],
4
- "sourcesContent": [
5
- "import Handlebars from \"handlebars\";\nimport { TemplateRuntimeError } from \"./errors.ts\";\nimport {\n\tcoerceLiteral,\n\textractExpressionIdentifier,\n\textractPathSegments,\n\tgetEffectivelySingleBlock,\n\tgetEffectivelySingleExpression,\n\tisSingleExpression,\n\tisThisExpression,\n\tparse,\n} from \"./parser.ts\";\n\n// ─── Template Executor ───────────────────────────────────────────────────────\n// Exécute un template Handlebars avec des données réelles.\n//\n// Trois modes d'exécution :\n//\n// 1. **Expression unique** (`{{value}}` ou ` {{value}} `) → retourne la\n// valeur brute sans conversion en string. Cela permet de préserver le type\n// original (number, boolean, object, array, null).\n//\n// 2. **Bloc unique** (`{{#if x}}10{{else}}20{{/if}}` éventuellement entouré\n// de whitespace) → rendu via Handlebars puis coercion intelligente du\n// résultat (détection de littéraux number, boolean, null).\n//\n// 3. **Template mixte** (`Hello {{name}}`, texte + blocs multiples, …) →\n// délègue à Handlebars qui produit toujours une string.\n//\n// Cette distinction est la raison pour laquelle on ne peut pas simplement\n// appeler `Handlebars.compile()` dans tous les cas.\n//\n// ─── Template Identifiers ────────────────────────────────────────────────────\n// La syntaxe `{{key:N}}` permet de résoudre une variable depuis une source\n// de données spécifique, identifiée par un entier N. Le paramètre optionnel\n// `identifierData` fournit un mapping `{ [id]: { key: value, ... } }`.\n//\n// - `{{meetingId}}` → résolu dans `data` (comportement standard)\n// - `{{meetingId:1}}` → résolu dans `identifierData[1]`\n//\n// Pour le rendu Handlebars (templates mixtes / blocs), les données\n// identifiées sont aplaties dans l'objet de données sous la forme\n// `\"key:N\": value`, ce qui correspond à la façon dont Handlebars parse\n// naturellement `{{key:N}}` (un seul segment `\"key:N\"`).\n\n// ─── API publique ────────────────────────────────────────────────────────────\n\n/**\n * Exécute un template avec les données fournies et retourne le résultat.\n *\n * Le type de retour dépend de la structure du template :\n * - Expression unique `{{expr}}` → valeur brute (any)\n * - Bloc unique → valeur coercée (number, boolean, null ou string)\n * - Template mixte → `string`\n *\n * @param template - La chaîne de template\n * @param data - Les données de contexte principal\n * @param identifierData - (optionnel) Données par identifiant `{ [id]: { key: value } }`\n */\nexport function execute(\n\ttemplate: string,\n\tdata: Record<string, unknown>,\n\tidentifierData?: Record<number, Record<string, unknown>>,\n): unknown {\n\tconst ast = parse(template);\n\n\t// ── Cas 1 : expression unique stricte `{{expr}}` ─────────────────────\n\tif (isSingleExpression(ast)) {\n\t\tconst stmt = ast.body[0] as hbs.AST.MustacheStatement;\n\t\treturn resolveExpression(stmt.path, data, identifierData);\n\t}\n\n\t// ── Cas 1b : expression unique avec whitespace autour ` {{expr}} ` ──\n\tconst singleExpr = getEffectivelySingleExpression(ast);\n\tif (singleExpr) {\n\t\treturn resolveExpression(singleExpr.path, data, identifierData);\n\t}\n\n\t// ── Cas 2 : bloc unique (éventuellement entouré de whitespace) ────────\n\t// On rend via Handlebars puis on tente de coercer le résultat vers le\n\t// type littéral détecté (number, boolean, null).\n\tconst singleBlock = getEffectivelySingleBlock(ast);\n\tif (singleBlock) {\n\t\tconst merged = mergeDataWithIdentifiers(data, identifierData);\n\t\tconst raw = renderWithHandlebars(template, merged);\n\t\treturn coerceLiteral(raw);\n\t}\n\n\t// ── Cas 3 : template mixte → string ───────────────────────────────────\n\tconst merged = mergeDataWithIdentifiers(data, identifierData);\n\treturn renderWithHandlebars(template, merged);\n}\n\n// ─── Résolution directe d'expression ─────────────────────────────────────────\n// Utilisé uniquement pour les templates à expression unique, afin de\n// retourner la valeur brute sans passer par le moteur Handlebars.\n\n/**\n * Résout une expression AST en suivant le chemin dans les données.\n *\n * Si l'expression contient un identifiant (ex: `meetingId:1`), la résolution\n * se fait dans `identifierData[1]` au lieu de `data`.\n *\n * @param expr - L'expression AST à résoudre\n * @param data - Le contexte de données principal\n * @param identifierData - Données par identifiant (optionnel)\n * @returns La valeur brute pointée par l'expression\n */\nfunction resolveExpression(\n\texpr: hbs.AST.Expression,\n\tdata: Record<string, unknown>,\n\tidentifierData?: Record<number, Record<string, unknown>>,\n): unknown {\n\t// this / . → retourne le contexte entier\n\tif (isThisExpression(expr)) {\n\t\treturn data;\n\t}\n\n\t// Literals\n\tif (expr.type === \"StringLiteral\")\n\t\treturn (expr as hbs.AST.StringLiteral).value;\n\tif (expr.type === \"NumberLiteral\")\n\t\treturn (expr as hbs.AST.NumberLiteral).value;\n\tif (expr.type === \"BooleanLiteral\")\n\t\treturn (expr as hbs.AST.BooleanLiteral).value;\n\tif (expr.type === \"NullLiteral\") return null;\n\tif (expr.type === \"UndefinedLiteral\") return undefined;\n\n\t// PathExpression — navigation par segments dans l'objet data\n\tconst segments = extractPathSegments(expr);\n\tif (segments.length === 0) {\n\t\tthrow new TemplateRuntimeError(\n\t\t\t`Cannot resolve expression of type \"${expr.type}\"`,\n\t\t);\n\t}\n\n\t// Extraire l'identifiant éventuel du dernier segment\n\tconst { cleanSegments, identifier } = extractExpressionIdentifier(segments);\n\n\tif (identifier !== null && identifierData) {\n\t\tconst source = identifierData[identifier];\n\t\tif (source) {\n\t\t\treturn resolveDataPath(source, cleanSegments);\n\t\t}\n\t\t// La source n'existe pas → undefined (comme une clé manquante)\n\t\treturn undefined;\n\t}\n\n\tif (identifier !== null && !identifierData) {\n\t\t// Template utilise un identifiant mais aucune identifierData fournie\n\t\treturn undefined;\n\t}\n\n\treturn resolveDataPath(data, cleanSegments);\n}\n\n/**\n * Navigue dans un objet de données en suivant un chemin de segments.\n *\n * @param data - L'objet de données\n * @param segments - Les segments du chemin (ex: `[\"user\", \"address\", \"city\"]`)\n * @returns La valeur au bout du chemin, ou `undefined` si un segment\n * intermédiaire est null/undefined\n */\nexport function resolveDataPath(data: unknown, segments: string[]): unknown {\n\tlet current: unknown = data;\n\n\tfor (const segment of segments) {\n\t\tif (current === null || current === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (typeof current !== \"object\") {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tcurrent = (current as Record<string, unknown>)[segment];\n\t}\n\n\treturn current;\n}\n\n// ─── Fusion des données ──────────────────────────────────────────────────────\n// Pour le rendu Handlebars (templates mixtes, blocs), on ne peut pas\n// intercepter la résolution expression par expression. On fusionne donc\n// les données identifiées dans l'objet principal sous la forme `\"key:N\"`.\n//\n// Handlebars parse `{{meetingId:1}}` comme un PathExpression avec un seul\n// segment `\"meetingId:1\"`, donc il cherchera la clé `\"meetingId:1\"` dans\n// l'objet de données — ce qui correspond exactement à notre format aplati.\n\n/**\n * Fusionne les données principales avec les données identifiées.\n *\n * @param data - Données principales\n * @param identifierData - Données par identifiant\n * @returns Un objet fusionné où les données identifiées sont sous la forme `\"key:N\"`\n *\n * @example\n * ```\n * mergeDataWithIdentifiers(\n * { name: \"Alice\" },\n * { 1: { meetingId: \"val1\" }, 2: { meetingId: \"val2\" } }\n * )\n * // → { name: \"Alice\", \"meetingId:1\": \"val1\", \"meetingId:2\": \"val2\" }\n * ```\n */\nfunction mergeDataWithIdentifiers(\n\tdata: Record<string, unknown>,\n\tidentifierData?: Record<number, Record<string, unknown>>,\n): Record<string, unknown> {\n\tif (!identifierData) return data;\n\n\tconst merged: Record<string, unknown> = { ...data };\n\n\tfor (const [id, idData] of Object.entries(identifierData)) {\n\t\tfor (const [key, value] of Object.entries(idData)) {\n\t\t\tmerged[`${key}:${id}`] = value;\n\t\t}\n\t}\n\n\treturn merged;\n}\n\n// ─── Rendu Handlebars ────────────────────────────────────────────────────────\n// Pour les templates mixtes (texte + expressions, blocs), on délègue à\n// Handlebars qui gère nativement tous les helpers intégrés (#if, #each,\n// #with, #unless) et produit une string.\n\n/**\n * Compile et exécute un template via Handlebars.\n * Retourne toujours une string.\n *\n * @param template - La chaîne de template\n * @param data - Les données de contexte\n */\nfunction renderWithHandlebars(\n\ttemplate: string,\n\tdata: Record<string, unknown>,\n): string {\n\ttry {\n\t\tconst compiled = Handlebars.compile(template, {\n\t\t\t// Désactive le HTML-escaping par défaut — ce moteur n'est pas\n\t\t\t// spécifique au HTML, on veut les valeurs brutes.\n\t\t\tnoEscape: true,\n\t\t\t// Mode strict : lève une erreur si un chemin n'existe pas dans les données.\n\t\t\tstrict: false,\n\t\t});\n\n\t\treturn compiled(data);\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new TemplateRuntimeError(message);\n\t}\n}\n"
6
- ],
7
- "mappings": "uIAAA,oBA2DO,SAAS,CAAO,CACtB,EACA,EACA,EACU,CACV,IAAM,EAAM,EAAM,CAAQ,EAG1B,GAAI,EAAmB,CAAG,EAAG,CAC5B,IAAM,EAAO,EAAI,KAAK,GACtB,OAAO,EAAkB,EAAK,KAAM,EAAM,CAAc,EAIzD,IAAM,EAAa,EAA+B,CAAG,EACrD,GAAI,EACH,OAAO,EAAkB,EAAW,KAAM,EAAM,CAAc,EAO/D,GADoB,EAA0B,CAAG,EAChC,CAChB,IAAM,EAAS,EAAyB,EAAM,CAAc,EACtD,EAAM,EAAqB,EAAU,CAAM,EACjD,OAAO,EAAc,CAAG,EAIzB,IAAM,EAAS,EAAyB,EAAM,CAAc,EAC5D,OAAO,EAAqB,EAAU,CAAM,EAkB7C,SAAS,CAAiB,CACzB,EACA,EACA,EACU,CAEV,GAAI,EAAiB,CAAI,EACxB,OAAO,EAIR,GAAI,EAAK,OAAS,gBACjB,OAAQ,EAA+B,MACxC,GAAI,EAAK,OAAS,gBACjB,OAAQ,EAA+B,MACxC,GAAI,EAAK,OAAS,iBACjB,OAAQ,EAAgC,MACzC,GAAI,EAAK,OAAS,cAAe,OAAO,KACxC,GAAI,EAAK,OAAS,mBAAoB,OAGtC,IAAM,EAAW,EAAoB,CAAI,EACzC,GAAI,EAAS,SAAW,EACvB,MAAM,IAAI,EACT,sCAAsC,EAAK,OAC5C,EAID,IAAQ,gBAAe,cAAe,EAA4B,CAAQ,EAE1E,GAAI,IAAe,MAAQ,EAAgB,CAC1C,IAAM,EAAS,EAAe,GAC9B,GAAI,EACH,OAAO,EAAgB,EAAQ,CAAa,EAG7C,OAGD,GAAI,IAAe,MAAQ,CAAC,EAE3B,OAGD,OAAO,EAAgB,EAAM,CAAa,EAWpC,SAAS,CAAe,CAAC,EAAe,EAA6B,CAC3E,IAAI,EAAmB,EAEvB,QAAW,KAAW,EAAU,CAC/B,GAAI,IAAY,MAAQ,IAAY,OACnC,OAGD,GAAI,OAAO,IAAY,SACtB,OAGD,EAAW,EAAoC,GAGhD,OAAO,EA4BR,SAAS,CAAwB,CAChC,EACA,EAC0B,CAC1B,GAAI,CAAC,EAAgB,OAAO,EAE5B,IAAM,EAAkC,IAAK,CAAK,EAElD,QAAY,EAAI,KAAW,OAAO,QAAQ,CAAc,EACvD,QAAY,EAAK,KAAU,OAAO,QAAQ,CAAM,EAC/C,EAAO,GAAG,KAAO,KAAQ,EAI3B,OAAO,EAeR,SAAS,CAAoB,CAC5B,EACA,EACS,CACT,GAAI,CASH,OARiB,EAAW,QAAQ,EAAU,CAG7C,SAAU,GAEV,OAAQ,EACT,CAAC,EAEe,CAAI,EACnB,MAAO,EAAgB,CACxB,IAAM,EAAU,aAAiB,MAAQ,EAAM,QAAU,OAAO,CAAK,EACrE,MAAM,IAAI,EAAqB,CAAO",
8
- "debugId": "4F7A13979718154664756E2164756E21",
9
- "names": []
10
- }
@@ -1,7 +0,0 @@
1
- class f extends Error{constructor(b){super(b);this.name="TemplateError"}}class q extends f{loc;constructor(b,h){super(`Parse error: ${b}`);this.loc=h;this.name="TemplateParseError"}}class v extends f{diagnostics;constructor(b){let h=b.filter((j)=>j.severity==="error"),k=h.map((j)=>` • ${j.message}`).join(`
2
- `);super(`Static analysis failed with ${h.length} error(s):
3
- ${k}`);this.diagnostics=b;this.name="TemplateAnalysisError"}}class w extends f{constructor(b){super(`Runtime error: ${b}`);this.name="TemplateRuntimeError"}}
4
- export{f as p,q,v as r,w as s};
5
-
6
- //# debugId=7F986ADBFE9FCFEF64756E2164756E21
7
- //# sourceMappingURL=chunk-6c0pw73w.js.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/errors.ts"],
4
- "sourcesContent": [
5
- "import type { TemplateDiagnostic } from \"./types.ts\";\n\n// ─── Classe de base ──────────────────────────────────────────────────────────\n// Toutes les erreurs du moteur de template héritent de cette classe pour\n// permettre un `catch` ciblé : `catch (e) { if (e instanceof TemplateError) … }`\n\nexport class TemplateError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"TemplateError\";\n\t}\n}\n\n// ─── Erreur de parsing ───────────────────────────────────────────────────────\n// Levée quand Handlebars ne parvient pas à parser le template (syntaxe invalide).\n\nexport class TemplateParseError extends TemplateError {\n\tconstructor(\n\t\tmessage: string,\n\t\t/** Position approximative de l'erreur dans le source */\n\t\tpublic readonly loc?: { line: number; column: number },\n\t) {\n\t\tsuper(`Parse error: ${message}`);\n\t\tthis.name = \"TemplateParseError\";\n\t}\n}\n\n// ─── Erreur d'analyse statique ───────────────────────────────────────────────\n// Levée en mode strict quand l'analyse produit au moins une erreur.\n\nexport class TemplateAnalysisError extends TemplateError {\n\tconstructor(\n\t\t/** Liste complète des diagnostics (erreurs + warnings) */\n\t\tpublic readonly diagnostics: TemplateDiagnostic[],\n\t) {\n\t\tconst errors = diagnostics.filter((d) => d.severity === \"error\");\n\t\tconst summary = errors.map((d) => ` • ${d.message}`).join(\"\\n\");\n\t\tsuper(`Static analysis failed with ${errors.length} error(s):\\n${summary}`);\n\t\tthis.name = \"TemplateAnalysisError\";\n\t}\n}\n\n// ─── Erreur d'exécution ──────────────────────────────────────────────────────\n// Levée quand l'exécution du template échoue (accès à une propriété\n// inexistante en mode strict, type inattendu, etc.).\n\nexport class TemplateRuntimeError extends TemplateError {\n\tconstructor(message: string) {\n\t\tsuper(`Runtime error: ${message}`);\n\t\tthis.name = \"TemplateRuntimeError\";\n\t}\n}\n"
6
- ],
7
- "mappings": "AAMO,MAAM,UAAsB,KAAM,CACxC,WAAW,CAAC,EAAiB,CAC5B,MAAM,CAAO,EACb,KAAK,KAAO,gBAEd,CAKO,MAAM,UAA2B,CAAc,CAIpC,IAHjB,WAAW,CACV,EAEgB,EACf,CACD,MAAM,gBAAgB,GAAS,EAFf,WAGhB,KAAK,KAAO,qBAEd,CAKO,MAAM,UAA8B,CAAc,CAGvC,YAFjB,WAAW,CAEM,EACf,CACD,IAAM,EAAS,EAAY,OAAO,CAAC,IAAM,EAAE,WAAa,OAAO,EACzD,EAAU,EAAO,IAAI,CAAC,IAAM,OAAM,EAAE,SAAS,EAAE,KAAK;AAAA,CAAI,EAC9D,MAAM,+BAA+B,EAAO;AAAA,EAAqB,GAAS,EAJ1D,mBAKhB,KAAK,KAAO,wBAEd,CAMO,MAAM,UAA6B,CAAc,CACvD,WAAW,CAAC,EAAiB,CAC5B,MAAM,kBAAkB,GAAS,EACjC,KAAK,KAAO,uBAEd",
8
- "debugId": "7F986ADBFE9FCFEF64756E2164756E21",
9
- "names": []
10
- }
@@ -1,5 +0,0 @@
1
- import{q as J}from"./chunk-6c0pw73w.js";import Q from"handlebars";var V=/^(.+):(\d+)$/,W=/^-?\d+(\.\d+)?$/;function A(k){try{return Q.parse(k)}catch(q){let z=q instanceof Error?q.message:String(q),G=z.match(/line\s+(\d+).*?column\s+(\d+)/i),O=G?{line:parseInt(G[1]??"0",10),column:parseInt(G[2]??"0",10)}:void 0;throw new J(z,O)}}function C(k){let{body:q}=k;return q.length===1&&q[0]?.type==="MustacheStatement"}function D(k){if(k.type==="PathExpression")return k.parts;return[]}function F(k){if(k.type!=="PathExpression")return!1;let q=k;return q.original==="this"||q.original==="."}function K(k){return k.body.filter((q)=>!(q.type==="ContentStatement"&&q.value.trim()===""))}function P(k){let q=K(k);if(q.length===1&&q[0]?.type==="BlockStatement")return q[0];return null}function j(k){let q=K(k);if(q.length===1&&q[0]?.type==="MustacheStatement")return q[0];return null}function X(k){if(W.test(k))return"number";if(k==="true"||k==="false")return"boolean";if(k==="null")return"null";return null}function B(k){let q=k.trim(),z=X(q);if(z==="number")return Number(q);if(z==="boolean")return q==="true";if(z==="null")return null;return k}function Y(k){let q=k.match(V);if(q)return{key:q[1]??k,identifier:parseInt(q[2]??"0",10)};return{key:k,identifier:null}}function H(k){if(k.length===0)return{cleanSegments:[],identifier:null};let q=k[k.length-1],z=Y(q);if(z.identifier!==null)return{cleanSegments:[...k.slice(0,-1),z.key],identifier:z.identifier};return{cleanSegments:k,identifier:null}}
2
- export{A as e,C as f,D as g,F as h,K as i,P as j,j as k,X as l,B as m,Y as n,H as o};
3
-
4
- //# debugId=3EF6290B476C2E2064756E2164756E21
5
- //# sourceMappingURL=chunk-9mg6qfrs.js.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/parser.ts"],
4
- "sourcesContent": [
5
- "import Handlebars from \"handlebars\";\nimport { TemplateParseError } from \"./errors.ts\";\n\n// ─── Regex pour détecter un identifiant de template (ex: \"meetingId:1\") ──────\n// L'identifiant est toujours un entier positif ou zéro, séparé du nom de la\n// variable par un `:`. Le `:` et le nombre sont sur le **dernier** segment\n// du chemin (Handlebars split sur les `.`).\nconst IDENTIFIER_RE = /^(.+):(\\d+)$/;\n\n// ─── Template Parser ─────────────────────────────────────────────────────────\n// Wrapper mince autour du parser Handlebars. On centralise ici l'appel au\n// parser pour :\n// 1. Encapsuler les erreurs dans notre hiérarchie (`TemplateParseError`)\n// 2. Exposer des helpers d'introspection sur l'AST (ex: `isSingleExpression`)\n// 3. Isoler la dépendance directe à Handlebars du reste du code\n\n// ─── Regex pour détecter un littéral numérique (entier ou décimal, signé) ────\n// Conservateur volontairement : pas de notation scientifique (1e5), pas de\n// hex (0xFF), pas de séparateurs (1_000). On veut reconnaître uniquement ce\n// qu'un humain écrirait comme valeur numérique dans un template.\nconst NUMERIC_LITERAL_RE = /^-?\\d+(\\.\\d+)?$/;\n\n/**\n * Parse un template string et retourne l'AST Handlebars.\n *\n * @param template - La chaîne de template à parser (ex: `\"Hello {{name}}\"`)\n * @returns L'AST racine (`hbs.AST.Program`)\n * @throws {TemplateParseError} si la syntaxe du template est invalide\n */\nexport function parse(template: string): hbs.AST.Program {\n\ttry {\n\t\treturn Handlebars.parse(template);\n\t} catch (error: unknown) {\n\t\t// Handlebars lève une Error classique avec un message descriptif.\n\t\t// On la transforme en TemplateParseError pour un traitement uniforme.\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\n\t\t// Handlebars inclut parfois la position dans le message, on tente\n\t\t// de l'extraire pour enrichir notre erreur.\n\t\tconst locMatch = message.match(/line\\s+(\\d+).*?column\\s+(\\d+)/i);\n\t\tconst loc = locMatch\n\t\t\t? {\n\t\t\t\t\tline: parseInt(locMatch[1] ?? \"0\", 10),\n\t\t\t\t\tcolumn: parseInt(locMatch[2] ?? \"0\", 10),\n\t\t\t\t}\n\t\t\t: undefined;\n\n\t\tthrow new TemplateParseError(message, loc);\n\t}\n}\n\n/**\n * Détermine si l'AST représente un template constitué d'une seule expression\n * `{{expression}}` sans aucun contenu textuel autour.\n *\n * C'est important pour l'inférence de type de retour :\n * - Template `{{value}}` → retourne le type brut de `value` (number, object…)\n * - Template `Hello {{name}}` → retourne toujours `string` (concaténation)\n *\n * @param ast - L'AST parsé du template\n * @returns `true` si le template est une expression unique\n */\nexport function isSingleExpression(ast: hbs.AST.Program): boolean {\n\tconst { body } = ast;\n\n\t// Exactement un nœud, et c'est un MustacheStatement (pas un block, pas du texte)\n\treturn body.length === 1 && body[0]?.type === \"MustacheStatement\";\n}\n\n/**\n * Extrait les segments de chemin d'un `PathExpression` Handlebars.\n *\n * Handlebars décompose `user.address.city` en `{ parts: [\"user\", \"address\", \"city\"] }`.\n * Cette fonction extrait ces segments de manière sûre.\n *\n * @param expr - L'expression dont on veut le chemin\n * @returns Les segments du chemin, ou un tableau vide si l'expression n'est\n * pas un `PathExpression`\n */\nexport function extractPathSegments(expr: hbs.AST.Expression): string[] {\n\tif (expr.type === \"PathExpression\") {\n\t\treturn (expr as hbs.AST.PathExpression).parts;\n\t}\n\treturn [];\n}\n\n/**\n * Vérifie si une expression AST est un `PathExpression` pointant vers `this`\n * (utilisé à l'intérieur des blocs `{{#each}}`).\n */\nexport function isThisExpression(expr: hbs.AST.Expression): boolean {\n\tif (expr.type !== \"PathExpression\") return false;\n\tconst path = expr as hbs.AST.PathExpression;\n\treturn path.original === \"this\" || path.original === \".\";\n}\n\n// ─── Filtrage des nœuds significatifs ────────────────────────────────────────\n// Dans un AST Handlebars, le formatage (retours à la ligne, indentation)\n// produit des `ContentStatement` dont la valeur est purement du whitespace.\n// Ces nœuds n'ont aucun impact sémantique et doivent être ignorés lors de\n// l'inférence de type pour détecter les cas \"effectivement un seul bloc\" ou\n// \"effectivement une seule expression\".\n\n/**\n * Retourne les statements significatifs d'un Program en éliminant les\n * `ContentStatement` constitués uniquement de whitespace.\n */\nexport function getEffectiveBody(\n\tprogram: hbs.AST.Program,\n): hbs.AST.Statement[] {\n\treturn program.body.filter(\n\t\t(s) =>\n\t\t\t!(\n\t\t\t\ts.type === \"ContentStatement\" &&\n\t\t\t\t(s as hbs.AST.ContentStatement).value.trim() === \"\"\n\t\t\t),\n\t);\n}\n\n/**\n * Détermine si un Program est effectivement constitué d'un seul\n * `BlockStatement` (en ignorant le whitespace autour).\n *\n * Exemples reconnus :\n * ```\n * {{#if x}}...{{/if}}\n *\n * {{#each items}}...{{/each}}\n * ```\n *\n * @returns Le `BlockStatement` unique ou `null` si le programme contient\n * d'autres nœuds significatifs.\n */\nexport function getEffectivelySingleBlock(\n\tprogram: hbs.AST.Program,\n): hbs.AST.BlockStatement | null {\n\tconst effective = getEffectiveBody(program);\n\tif (effective.length === 1 && effective[0]?.type === \"BlockStatement\") {\n\t\treturn effective[0] as hbs.AST.BlockStatement;\n\t}\n\treturn null;\n}\n\n/**\n * Détermine si un Program est effectivement constitué d'une seule\n * `MustacheStatement` (en ignorant le whitespace autour).\n *\n * Exemple : ` {{age}} ` → true\n */\nexport function getEffectivelySingleExpression(\n\tprogram: hbs.AST.Program,\n): hbs.AST.MustacheStatement | null {\n\tconst effective = getEffectiveBody(program);\n\tif (effective.length === 1 && effective[0]?.type === \"MustacheStatement\") {\n\t\treturn effective[0] as hbs.AST.MustacheStatement;\n\t}\n\treturn null;\n}\n\n// ─── Détection de littéraux dans le contenu textuel ──────────────────────────\n// Quand un programme ne contient que des ContentStatements (pas d'expressions),\n// on essaie de détecter si le texte concaténé et trimé est un littéral typé\n// (nombre, booléen, null). Cela permet d'inférer correctement le type de\n// branches comme `{{#if x}} 42 {{/if}}`.\n\n/**\n * Tente de détecter le type d'un littéral textuel brut.\n *\n * @param text - Le texte trimé d'un ContentStatement ou d'un groupe de ContentStatements\n * @returns Le type JSON Schema détecté, ou `null` si c'est du texte libre (string).\n */\nexport function detectLiteralType(\n\ttext: string,\n): \"number\" | \"boolean\" | \"null\" | null {\n\tif (NUMERIC_LITERAL_RE.test(text)) return \"number\";\n\tif (text === \"true\" || text === \"false\") return \"boolean\";\n\tif (text === \"null\") return \"null\";\n\treturn null;\n}\n\n/**\n * Coerce une string brute issue du rendu Handlebars vers son type réel\n * si elle représente un littéral (number, boolean, null).\n * Retourne la string trimée sinon.\n */\nexport function coerceLiteral(raw: string): unknown {\n\tconst trimmed = raw.trim();\n\tconst type = detectLiteralType(trimmed);\n\tif (type === \"number\") return Number(trimmed);\n\tif (type === \"boolean\") return trimmed === \"true\";\n\tif (type === \"null\") return null;\n\t// Pas un littéral typé → on retourne la string brute sans la trimer,\n\t// car le whitespace peut être significatif (ex: résultat d'un #each).\n\treturn raw;\n}\n\n// ─── Template Identifier Parsing ─────────────────────────────────────────────\n// Syntaxe `{{key:N}}` où N est un entier positif ou zéro.\n// L'identifiant permet de résoudre une variable depuis une source de données\n// spécifique (ex: un nœud de workflow identifié par son numéro).\n\n/** Résultat du parsing d'un segment de chemin avec identifiant potentiel */\nexport interface ParsedIdentifier {\n\t/** Le nom de la variable, sans le suffixe `:N` */\n\tkey: string;\n\t/** L'identifiant numérique, ou `null` si absent */\n\tidentifier: number | null;\n}\n\n/**\n * Parse un segment de chemin individuel pour en extraire la clé et\n * l'identifiant optionnel.\n *\n * @param segment - Un segment de chemin brut (ex: `\"meetingId:1\"` ou `\"meetingId\"`)\n * @returns Un objet `{ key, identifier }`\n *\n * @example\n * ```\n * parseIdentifier(\"meetingId:1\") // → { key: \"meetingId\", identifier: 1 }\n * parseIdentifier(\"meetingId\") // → { key: \"meetingId\", identifier: null }\n * parseIdentifier(\"meetingId:0\") // → { key: \"meetingId\", identifier: 0 }\n * ```\n */\nexport function parseIdentifier(segment: string): ParsedIdentifier {\n\tconst match = segment.match(IDENTIFIER_RE);\n\tif (match) {\n\t\treturn {\n\t\t\tkey: match[1] ?? segment,\n\t\t\tidentifier: parseInt(match[2] ?? \"0\", 10),\n\t\t};\n\t}\n\treturn { key: segment, identifier: null };\n}\n\n/** Résultat de l'extraction de l'identifiant sur une expression complète */\nexport interface ExpressionIdentifier {\n\t/** Segments de chemin nettoyés (sans le suffixe `:N` sur le dernier) */\n\tcleanSegments: string[];\n\t/** L'identifiant numérique extrait du dernier segment, ou `null` */\n\tidentifier: number | null;\n}\n\n/**\n * Extrait l'identifiant d'une expression complète (tableau de segments).\n *\n * L'identifiant est toujours sur le **dernier** segment du chemin, car\n * Handlebars split sur les `.` avant le `:`.\n *\n * @param segments - Les segments bruts du chemin (ex: `[\"user\", \"name:1\"]`)\n * @returns Un objet `{ cleanSegments, identifier }`\n *\n * @example\n * ```\n * extractExpressionIdentifier([\"meetingId:1\"])\n * // → { cleanSegments: [\"meetingId\"], identifier: 1 }\n *\n * extractExpressionIdentifier([\"user\", \"name:1\"])\n * // → { cleanSegments: [\"user\", \"name\"], identifier: 1 }\n *\n * extractExpressionIdentifier([\"meetingId\"])\n * // → { cleanSegments: [\"meetingId\"], identifier: null }\n * ```\n */\nexport function extractExpressionIdentifier(\n\tsegments: string[],\n): ExpressionIdentifier {\n\tif (segments.length === 0) {\n\t\treturn { cleanSegments: [], identifier: null };\n\t}\n\n\tconst lastSegment = segments[segments.length - 1] as string;\n\tconst parsed = parseIdentifier(lastSegment);\n\n\tif (parsed.identifier !== null) {\n\t\tconst cleanSegments = [...segments.slice(0, -1), parsed.key];\n\t\treturn { cleanSegments, identifier: parsed.identifier };\n\t}\n\n\treturn { cleanSegments: segments, identifier: null };\n}\n"
6
- ],
7
- "mappings": "wCAAA,0BAOA,IAAM,EAAgB,eAahB,EAAqB,kBASpB,SAAS,CAAK,CAAC,EAAmC,CACxD,GAAI,CACH,OAAO,EAAW,MAAM,CAAQ,EAC/B,MAAO,EAAgB,CAGxB,IAAM,EAAU,aAAiB,MAAQ,EAAM,QAAU,OAAO,CAAK,EAI/D,EAAW,EAAQ,MAAM,gCAAgC,EACzD,EAAM,EACT,CACA,KAAM,SAAS,EAAS,IAAM,IAAK,EAAE,EACrC,OAAQ,SAAS,EAAS,IAAM,IAAK,EAAE,CACxC,EACC,OAEH,MAAM,IAAI,EAAmB,EAAS,CAAG,GAepC,SAAS,CAAkB,CAAC,EAA+B,CACjE,IAAQ,QAAS,EAGjB,OAAO,EAAK,SAAW,GAAK,EAAK,IAAI,OAAS,oBAaxC,SAAS,CAAmB,CAAC,EAAoC,CACvE,GAAI,EAAK,OAAS,iBACjB,OAAQ,EAAgC,MAEzC,MAAO,CAAC,EAOF,SAAS,CAAgB,CAAC,EAAmC,CACnE,GAAI,EAAK,OAAS,iBAAkB,MAAO,GAC3C,IAAM,EAAO,EACb,OAAO,EAAK,WAAa,QAAU,EAAK,WAAa,IAc/C,SAAS,CAAgB,CAC/B,EACsB,CACtB,OAAO,EAAQ,KAAK,OACnB,CAAC,IACA,EACC,EAAE,OAAS,oBACV,EAA+B,MAAM,KAAK,IAAM,GAEpD,EAiBM,SAAS,CAAyB,CACxC,EACgC,CAChC,IAAM,EAAY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- import{b as z}from"./chunk-yraqh2tz.js";import{d as _}from"./chunk-yczpjh73.js";import{g as F}from"./chunk-p3xzf1ew.js";import{j as q,k as V,l as C}from"./chunk-6955jpr7.js";import{n as U}from"./chunk-ggdfaqhe.js";import{D as E}from"./chunk-vka4e61h.js";import{Q as x,T as g,U as k}from"./chunk-fhvf5y4x.js";import P from"handlebars";var j=new Set(["+","-","*","/","%","**"]);function K(w){if(typeof w==="number")return w;if(typeof w==="string"){let B=Number(w);return Number.isNaN(B)?0:B}return 0}function L(w,B,G){switch(B){case"+":return w+G;case"-":return w-G;case"*":return w*G;case"/":return G===0?1/0:w/G;case"%":return G===0?NaN:w%G;case"**":return w**G}}class Z{static HELPER_NAMES=["add","subtract","sub","multiply","mul","divide","div","modulo","mod","pow","abs","ceil","floor","round","sqrt","min","max","math"];static HELPER_NAMES_SET=new Set(Z.HELPER_NAMES);static getDefinitions(){let w=new Map;return Z.registerBinaryOperators(w),Z.registerUnaryFunctions(w),Z.registerMinMax(w),Z.registerGenericMath(w),w}static registerBinaryOperators(w){let B={fn:(W,Y)=>K(W)+K(Y),params:[{name:"a",type:{type:"number"},description:"First operand"},{name:"b",type:{type:"number"},description:"Second operand"}],returnType:{type:"number"},description:"Adds two numbers: {{ add a b }}"};w.set("add",B);let G={fn:(W,Y)=>K(W)-K(Y),params:[{name:"a",type:{type:"number"},description:"Value to subtract from"},{name:"b",type:{type:"number"},description:"Value to subtract"}],returnType:{type:"number"},description:"Subtracts b from a: {{ subtract a b }}"};w.set("subtract",G),w.set("sub",G);let J={fn:(W,Y)=>K(W)*K(Y),params:[{name:"a",type:{type:"number"},description:"First factor"},{name:"b",type:{type:"number"},description:"Second factor"}],returnType:{type:"number"},description:"Multiplies two numbers: {{ multiply a b }}"};w.set("multiply",J),w.set("mul",J);let Q={fn:(W,Y)=>{let $=K(Y);return $===0?1/0:K(W)/$},params:[{name:"a",type:{type:"number"},description:"Dividend"},{name:"b",type:{type:"number"},description:"Divisor"}],returnType:{type:"number"},description:"Divides a by b: {{ divide a b }}. Returns Infinity if b is 0."};w.set("divide",Q),w.set("div",Q);let X={fn:(W,Y)=>{let $=K(Y);return $===0?NaN:K(W)%$},params:[{name:"a",type:{type:"number"},description:"Dividend"},{name:"b",type:{type:"number"},description:"Divisor"}],returnType:{type:"number"},description:"Returns the remainder of a divided by b: {{ modulo a b }}"};w.set("modulo",X),w.set("mod",X),w.set("pow",{fn:(W,Y)=>K(W)**K(Y),params:[{name:"base",type:{type:"number"},description:"The base"},{name:"exponent",type:{type:"number"},description:"The exponent"}],returnType:{type:"number"},description:"Raises base to the power of exponent: {{ pow base exponent }}"})}static registerUnaryFunctions(w){w.set("abs",{fn:(B)=>Math.abs(K(B)),params:[{name:"value",type:{type:"number"},description:"The number"}],returnType:{type:"number"},description:"Returns the absolute value: {{ abs value }}"}),w.set("ceil",{fn:(B)=>Math.ceil(K(B)),params:[{name:"value",type:{type:"number"},description:"The number to round up"}],returnType:{type:"number"},description:"Rounds up to the nearest integer: {{ ceil value }}"}),w.set("floor",{fn:(B)=>Math.floor(K(B)),params:[{name:"value",type:{type:"number"},description:"The number to round down"}],returnType:{type:"number"},description:"Rounds down to the nearest integer: {{ floor value }}"}),w.set("round",{fn:(B,G)=>{let J=K(B);if(G===void 0||G===null||typeof G==="object")return Math.round(J);let X=10**K(G);return Math.round(J*X)/X},params:[{name:"value",type:{type:"number"},description:"The number to round"},{name:"precision",type:{type:"number"},description:"Number of decimal places (default: 0)",optional:!0}],returnType:{type:"number"},description:"Rounds to the nearest integer or to a given precision: {{ round value }} or {{ round value 2 }}"}),w.set("sqrt",{fn:(B)=>Math.sqrt(K(B)),params:[{name:"value",type:{type:"number"},description:"The number"}],returnType:{type:"number"},description:"Returns the square root: {{ sqrt value }}"})}static registerMinMax(w){w.set("min",{fn:(B,G)=>Math.min(K(B),K(G)),params:[{name:"a",type:{type:"number"},description:"First number"},{name:"b",type:{type:"number"},description:"Second number"}],returnType:{type:"number"},description:"Returns the smaller of two numbers: {{ min a b }}"}),w.set("max",{fn:(B,G)=>Math.max(K(B),K(G)),params:[{name:"a",type:{type:"number"},description:"First number"},{name:"b",type:{type:"number"},description:"Second number"}],returnType:{type:"number"},description:"Returns the larger of two numbers: {{ max a b }}"})}static registerGenericMath(w){w.set("math",{fn:(B,G,J)=>{let Q=String(G);if(!j.has(Q))throw Error(`[math helper] Unknown operator "${Q}". Supported: ${[...j].join(", ")} `);return L(K(B),Q,K(J))},params:[{name:"a",type:{type:"number"},description:"Left operand"},{name:"operator",type:{type:"string",enum:["+","-","*","/","%","**"]},description:'Arithmetic operator: "+", "-", "*", "/", "%", "**"'},{name:"b",type:{type:"number"},description:"Right operand"}],returnType:{type:"number"},description:'Generic math helper with operator as parameter: {{ math a "+" b }}, {{ math a "/" b }}. Supported operators: +, -, *, /, %, **'})}static register(w){let B=Z.getDefinitions();for(let[G,J]of B)w.registerHelper(G,J)}static unregister(w){for(let B of Z.HELPER_NAMES)w.unregisterHelper(B)}static getHelperNames(){return Z.HELPER_NAMES}static isMathHelper(w){return Z.HELPER_NAMES_SET.has(w)}}class R{hbs;astCache;compilationCache;helpers=new Map;constructor(w={}){if(this.hbs=P.create(),this.astCache=new x(w.astCacheSize??256),this.compilationCache=new x(w.compilationCacheSize??256),Z.register(this),w.helpers)for(let B of w.helpers){let{name:G,...J}=B;this.registerHelper(G,J)}}compile(w){if(V(w)){let J={};for(let[Q,X]of Object.entries(w))J[Q]=this.compile(X);return z.fromObject(J,{helpers:this.helpers,hbs:this.hbs,compilationCache:this.compilationCache})}if(q(w))return z.fromLiteral(w,{helpers:this.helpers,hbs:this.hbs,compilationCache:this.compilationCache});let B=this.getCachedAst(w),G={helpers:this.helpers,hbs:this.hbs,compilationCache:this.compilationCache};return z.fromTemplate(B,w,G)}analyze(w,B,G){if(V(w))return g(Object.keys(w),(Q)=>this.analyze(w[Q],B,G));if(q(w))return{valid:!0,diagnostics:[],outputSchema:C(w)};let J=this.getCachedAst(w);return _(J,w,B,{identifierSchemas:G,helpers:this.helpers})}validate(w,B,G){let J=this.analyze(w,B,G);return{valid:J.valid,diagnostics:J.diagnostics}}isValidSyntax(w){if(V(w))return Object.values(w).every((B)=>this.isValidSyntax(B));if(q(w))return!0;try{return U(w),!0}catch{return!1}}execute(w,B,G){if(V(w)){let Q={};for(let[X,W]of Object.entries(w))Q[X]=this.execute(W,B,G);return Q}if(q(w))return w;if(G?.schema){let Q=this.getCachedAst(w),X=_(Q,w,G.schema,{identifierSchemas:G.identifierSchemas,helpers:this.helpers});if(!X.valid)throw new E(X.diagnostics)}let J=this.getCachedAst(w);return F(J,w,B,{identifierData:G?.identifierData,hbs:this.hbs,compilationCache:this.compilationCache})}analyzeAndExecute(w,B,G,J,Q){if(V(w))return k(Object.keys(w),($)=>this.analyzeAndExecute(w[$],B,G,J,Q));if(q(w))return{analysis:{valid:!0,diagnostics:[],outputSchema:C(w)},value:w};let X=this.getCachedAst(w),W=_(X,w,B,{identifierSchemas:J,helpers:this.helpers});if(!W.valid)return{analysis:W,value:void 0};let Y=F(X,w,G,{identifierData:Q,hbs:this.hbs,compilationCache:this.compilationCache});return{analysis:W,value:Y}}registerHelper(w,B){return this.helpers.set(w,B),this.hbs.registerHelper(w,B.fn),this.compilationCache.clear(),this}unregisterHelper(w){return this.helpers.delete(w),this.hbs.unregisterHelper(w),this.compilationCache.clear(),this}hasHelper(w){return this.helpers.has(w)}clearCaches(){this.astCache.clear(),this.compilationCache.clear()}getCachedAst(w){let B=this.astCache.get(w);if(!B)B=U(w),this.astCache.set(w,B);return B}}
2
- export{R as a};
3
-
4
- //# debugId=ACEF99364BF4CF0764756E2164756E21
5
- //# sourceMappingURL=chunk-a37yzqra.js.map
@@ -1,11 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/typebars.ts", "../src/helpers/math-helpers.ts"],
4
- "sourcesContent": [
5
- "import Handlebars from \"handlebars\";\nimport type { JSONSchema7 } from \"json-schema\";\nimport { analyzeFromAst } from \"./analyzer.ts\";\nimport {\n\tCompiledTemplate,\n\ttype CompiledTemplateOptions,\n} from \"./compiled-template.ts\";\nimport { TemplateAnalysisError } from \"./errors.ts\";\nimport { executeFromAst } from \"./executor.ts\";\nimport { MathHelpers } from \"./helpers/index.ts\";\nimport { parse } from \"./parser.ts\";\nimport type {\n\tAnalysisResult,\n\tExecuteOptions,\n\tHelperDefinition,\n\tTemplateEngineOptions,\n\tTemplateInput,\n\tValidationResult,\n} from \"./types.ts\";\nimport {\n\tinferPrimitiveSchema,\n\tisLiteralInput,\n\tisObjectInput,\n} from \"./types.ts\";\nimport {\n\taggregateObjectAnalysis,\n\taggregateObjectAnalysisAndExecution,\n\tLRUCache,\n} from \"./utils.ts\";\n\n// ─── Typebars ────────────────────────────────────────────────────────────────\n// Point d'entrée public du moteur de template. Orchestre les trois phases :\n//\n// 1. **Parsing** — transformation du template string en AST (via Handlebars)\n// 2. **Analyse** — validation statique + inférence du type de retour\n// 3. **Exécution** — rendu du template avec des données réelles\n//\n// ─── Architecture v2 ─────────────────────────────────────────────────────────\n// - **Cache LRU** pour les AST parsés et les templates Handlebars compilés\n// - **Environnement Handlebars isolé** par instance (custom helpers)\n// - **Pattern `compile()`** : parse-once / execute-many\n// - **Méthode `validate()`** : raccourci d'API sans `outputSchema`\n// - **`registerHelper()`** : helpers custom avec typage statique\n// - **`ExecuteOptions`** : options object pour `execute()`\n//\n// ─── Template Identifiers ────────────────────────────────────────────────────\n// La syntaxe `{{key:N}}` permet de référencer des variables provenant de\n// sources de données spécifiques, identifiées par un entier N.\n//\n// - `identifierSchemas` : mapping `{ [id]: JSONSchema7 }` pour l'analyse statique\n// - `identifierData` : mapping `{ [id]: Record<string, unknown> }` pour l'exécution\n//\n// Usage :\n// engine.execute(\"{{meetingId:1}}\", data, { identifierData: { 1: node1Data } });\n// engine.analyze(\"{{meetingId:1}}\", schema, { 1: node1Schema });\n\n// ─── Classe principale ──────────────────────────────────────────────────────\n\nexport class Typebars {\n\t/** Environnement Handlebars isolé — chaque engine a ses propres helpers */\n\tprivate readonly hbs: typeof Handlebars;\n\n\t/** Cache LRU des AST parsés (évite le re-parsing) */\n\tprivate readonly astCache: LRUCache<string, hbs.AST.Program>;\n\n\t/** Cache LRU des templates Handlebars compilés (évite la recompilation) */\n\tprivate readonly compilationCache: LRUCache<\n\t\tstring,\n\t\tHandlebarsTemplateDelegate\n\t>;\n\n\t/** Helpers custom enregistrés sur cette instance */\n\tprivate readonly helpers = new Map<string, HelperDefinition>();\n\n\tconstructor(options: TemplateEngineOptions = {}) {\n\t\tthis.hbs = Handlebars.create();\n\t\tthis.astCache = new LRUCache(options.astCacheSize ?? 256);\n\t\tthis.compilationCache = new LRUCache(options.compilationCacheSize ?? 256);\n\n\t\t// ── Built-in helpers (math) ──────────────────────────────────────────\n\t\tMathHelpers.register(this);\n\n\t\t// ── Helpers custom via options ───────────────────────────────────────\n\t\tif (options.helpers) {\n\t\t\tfor (const helper of options.helpers) {\n\t\t\t\tconst { name, ...definition } = helper;\n\t\t\t\tthis.registerHelper(name, definition);\n\t\t\t}\n\t\t}\n\t}\n\n\t// ─── Compilation ───────────────────────────────────────────────────────\n\n\t/**\n\t * Compile un template et retourne un `CompiledTemplate` prêt à être\n\t * exécuté ou analysé sans re-parsing.\n\t *\n\t * Accepte un `TemplateInput` : string, number, boolean, null ou objet.\n\t * Pour les objets, chaque propriété est compilée récursivement.\n\t *\n\t * @param template - Le template à compiler\n\t * @returns Un `CompiledTemplate` réutilisable\n\t */\n\tcompile(template: TemplateInput): CompiledTemplate {\n\t\tif (isObjectInput(template)) {\n\t\t\tconst children: Record<string, CompiledTemplate> = {};\n\t\t\tfor (const [key, value] of Object.entries(template)) {\n\t\t\t\tchildren[key] = this.compile(value);\n\t\t\t}\n\t\t\treturn CompiledTemplate.fromObject(children, {\n\t\t\t\thelpers: this.helpers,\n\t\t\t\thbs: this.hbs,\n\t\t\t\tcompilationCache: this.compilationCache,\n\t\t\t});\n\t\t}\n\t\tif (isLiteralInput(template)) {\n\t\t\treturn CompiledTemplate.fromLiteral(template, {\n\t\t\t\thelpers: this.helpers,\n\t\t\t\thbs: this.hbs,\n\t\t\t\tcompilationCache: this.compilationCache,\n\t\t\t});\n\t\t}\n\t\tconst ast = this.getCachedAst(template);\n\t\tconst options: CompiledTemplateOptions = {\n\t\t\thelpers: this.helpers,\n\t\t\thbs: this.hbs,\n\t\t\tcompilationCache: this.compilationCache,\n\t\t};\n\t\treturn CompiledTemplate.fromTemplate(ast, template, options);\n\t}\n\n\t// ─── Analyse statique ────────────────────────────────────────────────────\n\n\t/**\n\t * Analyse statiquement un template par rapport à un JSON Schema v7\n\t * décrivant le contexte disponible.\n\t *\n\t * Accepte un `TemplateInput` : string, number, boolean, null ou objet.\n\t * Pour les objets, chaque propriété est analysée récursivement et le\n\t * `outputSchema` reflète la structure de l'objet avec les types résolus.\n\t *\n\t * @param template - Le template à analyser\n\t * @param inputSchema - JSON Schema v7 décrivant les variables disponibles\n\t * @param identifierSchemas - (optionnel) Schemas par identifiant `{ [id]: JSONSchema7 }`\n\t */\n\tanalyze(\n\t\ttemplate: TemplateInput,\n\t\tinputSchema: JSONSchema7,\n\t\tidentifierSchemas?: Record<number, JSONSchema7>,\n\t): AnalysisResult {\n\t\tif (isObjectInput(template)) {\n\t\t\treturn aggregateObjectAnalysis(Object.keys(template), (key) =>\n\t\t\t\tthis.analyze(\n\t\t\t\t\ttemplate[key] as TemplateInput,\n\t\t\t\t\tinputSchema,\n\t\t\t\t\tidentifierSchemas,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tif (isLiteralInput(template)) {\n\t\t\treturn {\n\t\t\t\tvalid: true,\n\t\t\t\tdiagnostics: [],\n\t\t\t\toutputSchema: inferPrimitiveSchema(template),\n\t\t\t};\n\t\t}\n\t\tconst ast = this.getCachedAst(template);\n\t\treturn analyzeFromAst(ast, template, inputSchema, {\n\t\t\tidentifierSchemas,\n\t\t\thelpers: this.helpers,\n\t\t});\n\t}\n\n\t// ─── Validation ──────────────────────────────────────────────────────────\n\n\t/**\n\t * Valide un template contre un schema sans retourner le type de sortie.\n\t *\n\t * C'est un raccourci d'API pour `analyze()` qui ne retourne que `valid`\n\t * et `diagnostics`, sans `outputSchema`. L'analyse complète (y compris\n\t * l'inférence de type) est exécutée en interne — cette méthode ne\n\t * fournit pas de gain de performance, uniquement une API simplifiée.\n\t *\n\t * @param template - Le template à valider\n\t * @param inputSchema - JSON Schema v7 décrivant les variables disponibles\n\t * @param identifierSchemas - (optionnel) Schemas par identifiant\n\t */\n\tvalidate(\n\t\ttemplate: TemplateInput,\n\t\tinputSchema: JSONSchema7,\n\t\tidentifierSchemas?: Record<number, JSONSchema7>,\n\t): ValidationResult {\n\t\tconst analysis = this.analyze(template, inputSchema, identifierSchemas);\n\t\treturn {\n\t\t\tvalid: analysis.valid,\n\t\t\tdiagnostics: analysis.diagnostics,\n\t\t};\n\t}\n\n\t// ─── Validation syntaxique ───────────────────────────────────────────────\n\n\t/**\n\t * Vérifie uniquement que la syntaxe du template est valide (parsing).\n\t * Ne nécessite pas de schema — utile pour un feedback rapide dans un éditeur.\n\t *\n\t * Pour les objets, vérifie récursivement chaque propriété.\n\t *\n\t * @param template - Le template à valider\n\t * @returns `true` si le template est syntaxiquement correct\n\t */\n\tisValidSyntax(template: TemplateInput): boolean {\n\t\tif (isObjectInput(template)) {\n\t\t\treturn Object.values(template).every((v) => this.isValidSyntax(v));\n\t\t}\n\t\tif (isLiteralInput(template)) return true;\n\t\ttry {\n\t\t\tparse(template);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t// ─── Exécution ───────────────────────────────────────────────────────────\n\n\t/**\n\t * Exécute un template avec les données fournies.\n\t *\n\t * Accepte un `TemplateInput` : string, number, boolean, null ou objet.\n\t * Pour les objets, chaque propriété est exécutée récursivement et un\n\t * objet avec les valeurs résolues est retourné.\n\t *\n\t * Si un `schema` est fourni dans les options, l'analyse statique est\n\t * lancée avant l'exécution. Une `TemplateAnalysisError` est levée en\n\t * cas d'erreur.\n\t *\n\t * @param template - Le template à exécuter\n\t * @param data - Les données de contexte pour le rendu\n\t * @param options - Options d'exécution (schema, identifierData, identifierSchemas)\n\t * @returns Le résultat de l'exécution\n\t */\n\texecute(\n\t\ttemplate: TemplateInput,\n\t\tdata: Record<string, unknown>,\n\t\toptions?: ExecuteOptions,\n\t): unknown {\n\t\t// ── Objet template → exécution récursive ─────────────────────────────\n\t\tif (isObjectInput(template)) {\n\t\t\tconst result: Record<string, unknown> = {};\n\t\t\tfor (const [key, value] of Object.entries(template)) {\n\t\t\t\tresult[key] = this.execute(value, data, options);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t// ── Passthrough pour les valeurs littérales ───────────────────────────\n\t\tif (isLiteralInput(template)) return template;\n\n\t\t// ── Validation statique préalable ────────────────────────────────────\n\t\tif (options?.schema) {\n\t\t\tconst ast = this.getCachedAst(template);\n\t\t\tconst analysis = analyzeFromAst(ast, template, options.schema, {\n\t\t\t\tidentifierSchemas: options.identifierSchemas,\n\t\t\t\thelpers: this.helpers,\n\t\t\t});\n\t\t\tif (!analysis.valid) {\n\t\t\t\tthrow new TemplateAnalysisError(analysis.diagnostics);\n\t\t\t}\n\t\t}\n\n\t\t// ── Exécution ────────────────────────────────────────────────────────\n\t\tconst ast = this.getCachedAst(template);\n\t\treturn executeFromAst(ast, template, data, {\n\t\t\tidentifierData: options?.identifierData,\n\t\t\thbs: this.hbs,\n\t\t\tcompilationCache: this.compilationCache,\n\t\t});\n\t}\n\n\t// ─── Raccourcis combinés ─────────────────────────────────────────────────\n\n\t/**\n\t * Analyse un template et, si valide, l'exécute avec les données fournies.\n\t * Retourne à la fois le résultat d'analyse et la valeur exécutée.\n\t *\n\t * Pour les objets, chaque propriété est analysée et exécutée récursivement.\n\t * L'objet entier est considéré invalide si au moins une propriété l'est.\n\t *\n\t * @param template - Le template\n\t * @param inputSchema - JSON Schema v7 décrivant les variables disponibles\n\t * @param data - Les données de contexte pour le rendu\n\t * @param identifierSchemas - (optionnel) Schemas par identifiant\n\t * @param identifierData - (optionnel) Données par identifiant\n\t * @returns Un objet `{ analysis, value }` où `value` est `undefined` si\n\t * l'analyse a échoué.\n\t */\n\tanalyzeAndExecute(\n\t\ttemplate: TemplateInput,\n\t\tinputSchema: JSONSchema7,\n\t\tdata: Record<string, unknown>,\n\t\tidentifierSchemas?: Record<number, JSONSchema7>,\n\t\tidentifierData?: Record<number, Record<string, unknown>>,\n\t): { analysis: AnalysisResult; value: unknown } {\n\t\tif (isObjectInput(template)) {\n\t\t\treturn aggregateObjectAnalysisAndExecution(Object.keys(template), (key) =>\n\t\t\t\tthis.analyzeAndExecute(\n\t\t\t\t\ttemplate[key] as TemplateInput,\n\t\t\t\t\tinputSchema,\n\t\t\t\t\tdata,\n\t\t\t\t\tidentifierSchemas,\n\t\t\t\t\tidentifierData,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tif (isLiteralInput(template)) {\n\t\t\treturn {\n\t\t\t\tanalysis: {\n\t\t\t\t\tvalid: true,\n\t\t\t\t\tdiagnostics: [],\n\t\t\t\t\toutputSchema: inferPrimitiveSchema(template),\n\t\t\t\t},\n\t\t\t\tvalue: template,\n\t\t\t};\n\t\t}\n\n\t\tconst ast = this.getCachedAst(template);\n\t\tconst analysis = analyzeFromAst(ast, template, inputSchema, {\n\t\t\tidentifierSchemas,\n\t\t\thelpers: this.helpers,\n\t\t});\n\n\t\tif (!analysis.valid) {\n\t\t\treturn { analysis, value: undefined };\n\t\t}\n\n\t\tconst value = executeFromAst(ast, template, data, {\n\t\t\tidentifierData,\n\t\t\thbs: this.hbs,\n\t\t\tcompilationCache: this.compilationCache,\n\t\t});\n\t\treturn { analysis, value };\n\t}\n\n\t// ─── Gestion des helpers custom ────────────────────────────────────────\n\n\t/**\n\t * Enregistre un helper custom sur cette instance du moteur.\n\t *\n\t * Le helper est disponible à la fois pour l'exécution (via Handlebars)\n\t * et pour l'analyse statique (via son `returnType` déclaré).\n\t *\n\t * @param name - Nom du helper (ex: `\"uppercase\"`)\n\t * @param definition - Définition du helper (implémentation + type de retour)\n\t * @returns `this` pour permettre le chaînage\n\t */\n\tregisterHelper(name: string, definition: HelperDefinition): this {\n\t\tthis.helpers.set(name, definition);\n\t\tthis.hbs.registerHelper(name, definition.fn);\n\n\t\t// Invalider le cache de compilation car les helpers ont changé\n\t\tthis.compilationCache.clear();\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Supprime un helper custom de cette instance du moteur.\n\t *\n\t * @param name - Nom du helper à supprimer\n\t * @returns `this` pour permettre le chaînage\n\t */\n\tunregisterHelper(name: string): this {\n\t\tthis.helpers.delete(name);\n\t\tthis.hbs.unregisterHelper(name);\n\n\t\t// Invalider le cache de compilation\n\t\tthis.compilationCache.clear();\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Vérifie si un helper est enregistré sur cette instance.\n\t *\n\t * @param name - Nom du helper\n\t * @returns `true` si le helper est enregistré\n\t */\n\thasHelper(name: string): boolean {\n\t\treturn this.helpers.has(name);\n\t}\n\n\t// ─── Gestion du cache ──────────────────────────────────────────────────\n\n\t/**\n\t * Vide tous les caches internes (AST + compilation).\n\t *\n\t * Utile après un changement de configuration ou pour libérer la mémoire.\n\t */\n\tclearCaches(): void {\n\t\tthis.astCache.clear();\n\t\tthis.compilationCache.clear();\n\t}\n\n\t// ─── Internals ─────────────────────────────────────────────────────────\n\n\t/**\n\t * Récupère l'AST d'un template depuis le cache, ou le parse et le cache.\n\t */\n\tprivate getCachedAst(template: string): hbs.AST.Program {\n\t\tlet ast = this.astCache.get(template);\n\t\tif (!ast) {\n\t\t\tast = parse(template);\n\t\t\tthis.astCache.set(template, ast);\n\t\t}\n\t\treturn ast;\n\t}\n}\n",
6
- "import type { HelperDefinition } from \"../types.ts\";\n\n// ─── MathHelpers ─────────────────────────────────────────────────────────────\n// Classe regroupant tous les helpers mathématiques pour le moteur de template.\n//\n// Fournit deux types de helpers :\n//\n// 1. **Helpers nommés** — un helper par opération (`add`, `subtract`, `divide`, …)\n// Usage : `{ { add a b } } `, `{ { abs value } } `, `{ { round value 2 } } `\n//\n// 2. **Helper générique `math`** — un seul helper avec l'opérateur en paramètre\n// Usage : `{ { math a \"+\" b } } `, `{ { math a \"/\" b } } `, `{ { math a \"**\" b } } `\n//\n// ─── Enregistrement ──────────────────────────────────────────────────────────\n// Les MathHelpers sont pré-enregistrés automatiquement par le constructeur\n// de `Typebars`. Il est aussi possible de les enregistrer manuellement\n// sur n'importe quel objet implémentant `HelperRegistry` :\n//\n// MathHelpers.register(engine); // enregistre tous les helpers\n// MathHelpers.unregister(engine); // les supprime tous\n//\n// ─── Opérateurs supportés (helper `math`) ────────────────────────────────────\n// + Addition\n// - Subtraction\n// * Multiplication\n// / Division\n// % Modulo\n// ** Exponentiation\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Interface minimale pour l'enregistrement — évite le couplage avec Typebars */\ninterface HelperRegistry {\n\tregisterHelper(name: string, definition: HelperDefinition): unknown;\n\tunregisterHelper(name: string): unknown;\n}\n\n/** Opérateurs supportés par le helper générique `math` */\ntype MathOperator = \"+\" | \"-\" | \"*\" | \"/\" | \"%\" | \"**\";\n\nconst SUPPORTED_OPERATORS = new Set<string>([\"+\", \"-\", \"*\", \"/\", \"%\", \"**\"]);\n\n// ─── Utilitaires internes ────────────────────────────────────────────────────\n\n/**\n * Convertit une valeur inconnue en nombre. Retourne `0` si la conversion\n * échoue (string non numérique, objet, etc.).\n */\nfunction toNumber(value: unknown): number {\n\tif (typeof value === \"number\") return value;\n\tif (typeof value === \"string\") {\n\t\tconst n = Number(value);\n\t\treturn Number.isNaN(n) ? 0 : n;\n\t}\n\treturn 0;\n}\n\n/**\n * Applique un opérateur binaire sur deux opérandes.\n */\nfunction applyOperator(a: number, op: MathOperator, b: number): number {\n\tswitch (op) {\n\t\tcase \"+\":\n\t\t\treturn a + b;\n\t\tcase \"-\":\n\t\t\treturn a - b;\n\t\tcase \"*\":\n\t\t\treturn a * b;\n\t\tcase \"/\":\n\t\t\treturn b === 0 ? Infinity : a / b;\n\t\tcase \"%\":\n\t\t\treturn b === 0 ? NaN : a % b;\n\t\tcase \"**\":\n\t\t\treturn a ** b;\n\t}\n}\n\n// ─── Classe principale ──────────────────────────────────────────────────────\n\nexport class MathHelpers {\n\t// ─── Noms de tous les helpers enregistrés ─────────────────────────────\n\t// Utilisé par `register()` et `unregister()` pour itérer.\n\tprivate static readonly HELPER_NAMES: readonly string[] = [\n\t\t// Opérateurs binaires\n\t\t\"add\",\n\t\t\"subtract\",\n\t\t\"sub\",\n\t\t\"multiply\",\n\t\t\"mul\",\n\t\t\"divide\",\n\t\t\"div\",\n\t\t\"modulo\",\n\t\t\"mod\",\n\t\t\"pow\",\n\n\t\t// Fonctions unaires\n\t\t\"abs\",\n\t\t\"ceil\",\n\t\t\"floor\",\n\t\t\"round\",\n\t\t\"sqrt\",\n\n\t\t// Min / Max (binaires)\n\t\t\"min\",\n\t\t\"max\",\n\n\t\t// Helper générique\n\t\t\"math\",\n\t];\n\n\t/** Set dérivé de `HELPER_NAMES` pour un lookup O(1) dans `isMathHelper()` */\n\tprivate static readonly HELPER_NAMES_SET: ReadonlySet<string> = new Set(\n\t\tMathHelpers.HELPER_NAMES,\n\t);\n\n\t// ─── Définitions des helpers ─────────────────────────────────────────\n\n\t/** Retourne toutes les définitions sous forme de `Map<name, HelperDefinition>` */\n\tstatic getDefinitions(): Map<string, HelperDefinition> {\n\t\tconst defs = new Map<string, HelperDefinition>();\n\n\t\tMathHelpers.registerBinaryOperators(defs);\n\t\tMathHelpers.registerUnaryFunctions(defs);\n\t\tMathHelpers.registerMinMax(defs);\n\t\tMathHelpers.registerGenericMath(defs);\n\n\t\treturn defs;\n\t}\n\n\t// ── Opérateurs binaires ──────────────────────────────────────────\n\n\t/** Enregistre add, subtract/sub, multiply/mul, divide/div, modulo/mod, pow */\n\tprivate static registerBinaryOperators(\n\t\tdefs: Map<string, HelperDefinition>,\n\t): void {\n\t\t// add — Addition : {{ add a b }}\n\t\tconst addDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => toNumber(a) + toNumber(b),\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"First operand\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Second operand\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Adds two numbers: {{ add a b }}\",\n\t\t};\n\t\tdefs.set(\"add\", addDef);\n\n\t\t// subtract / sub — Soustraction : {{ subtract a b }} ou {{ sub a b }}\n\t\tconst subtractDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => toNumber(a) - toNumber(b),\n\t\t\tparams: [\n\t\t\t\t{\n\t\t\t\t\tname: \"a\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"Value to subtract from\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"b\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"Value to subtract\",\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Subtracts b from a: {{ subtract a b }}\",\n\t\t};\n\t\tdefs.set(\"subtract\", subtractDef);\n\t\tdefs.set(\"sub\", subtractDef);\n\n\t\t// multiply / mul — Multiplication : {{ multiply a b }} ou {{ mul a b }}\n\t\tconst multiplyDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => toNumber(a) * toNumber(b),\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"First factor\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Second factor\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Multiplies two numbers: {{ multiply a b }}\",\n\t\t};\n\t\tdefs.set(\"multiply\", multiplyDef);\n\t\tdefs.set(\"mul\", multiplyDef);\n\n\t\t// divide / div — Division : {{ divide a b }} ou {{ div a b }}\n\t\tconst divideDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => {\n\t\t\t\tconst divisor = toNumber(b);\n\t\t\t\treturn divisor === 0 ? Infinity : toNumber(a) / divisor;\n\t\t\t},\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"Dividend\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Divisor\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription:\n\t\t\t\t\"Divides a by b: {{ divide a b }}. Returns Infinity if b is 0.\",\n\t\t};\n\t\tdefs.set(\"divide\", divideDef);\n\t\tdefs.set(\"div\", divideDef);\n\n\t\t// modulo / mod — Modulo : {{ modulo a b }} ou {{ mod a b }}\n\t\tconst moduloDef: HelperDefinition = {\n\t\t\tfn: (a: unknown, b: unknown) => {\n\t\t\t\tconst divisor = toNumber(b);\n\t\t\t\treturn divisor === 0 ? NaN : toNumber(a) % divisor;\n\t\t\t},\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"Dividend\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Divisor\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Returns the remainder of a divided by b: {{ modulo a b }}\",\n\t\t};\n\t\tdefs.set(\"modulo\", moduloDef);\n\t\tdefs.set(\"mod\", moduloDef);\n\n\t\t// pow — Exponentiation : {{ pow base exponent }}\n\t\tdefs.set(\"pow\", {\n\t\t\tfn: (base: unknown, exponent: unknown) =>\n\t\t\t\ttoNumber(base) ** toNumber(exponent),\n\t\t\tparams: [\n\t\t\t\t{ name: \"base\", type: { type: \"number\" }, description: \"The base\" },\n\t\t\t\t{\n\t\t\t\t\tname: \"exponent\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"The exponent\",\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription:\n\t\t\t\t\"Raises base to the power of exponent: {{ pow base exponent }}\",\n\t\t});\n\t}\n\n\t// ── Fonctions unaires ────────────────────────────────────────────\n\n\t/** Enregistre abs, ceil, floor, round, sqrt */\n\tprivate static registerUnaryFunctions(\n\t\tdefs: Map<string, HelperDefinition>,\n\t): void {\n\t\t// abs — Valeur absolue : {{ abs value }}\n\t\tdefs.set(\"abs\", {\n\t\t\tfn: (value: unknown) => Math.abs(toNumber(value)),\n\t\t\tparams: [\n\t\t\t\t{ name: \"value\", type: { type: \"number\" }, description: \"The number\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Returns the absolute value: {{ abs value }}\",\n\t\t});\n\n\t\t// ceil — Arrondi supérieur : {{ ceil value }}\n\t\tdefs.set(\"ceil\", {\n\t\t\tfn: (value: unknown) => Math.ceil(toNumber(value)),\n\t\t\tparams: [\n\t\t\t\t{\n\t\t\t\t\tname: \"value\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"The number to round up\",\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Rounds up to the nearest integer: {{ ceil value }}\",\n\t\t});\n\n\t\t// floor — Arrondi inférieur : {{ floor value }}\n\t\tdefs.set(\"floor\", {\n\t\t\tfn: (value: unknown) => Math.floor(toNumber(value)),\n\t\t\tparams: [\n\t\t\t\t{\n\t\t\t\t\tname: \"value\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"The number to round down\",\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Rounds down to the nearest integer: {{ floor value }}\",\n\t\t});\n\n\t\t// round — Arrondi : {{ round value }} ou {{ round value precision }}\n\t\t// Avec précision : {{ round 3.14159 2 }} → 3.14\n\t\tdefs.set(\"round\", {\n\t\t\tfn: (value: unknown, precision: unknown) => {\n\t\t\t\tconst n = toNumber(value);\n\t\t\t\t// Si precision est un objet Handlebars options (pas un nombre),\n\t\t\t\t// c'est que le second paramètre n'a pas été fourni.\n\t\t\t\tif (\n\t\t\t\t\tprecision === undefined ||\n\t\t\t\t\tprecision === null ||\n\t\t\t\t\ttypeof precision === \"object\"\n\t\t\t\t) {\n\t\t\t\t\treturn Math.round(n);\n\t\t\t\t}\n\t\t\t\tconst p = toNumber(precision);\n\t\t\t\tconst factor = 10 ** p;\n\t\t\t\treturn Math.round(n * factor) / factor;\n\t\t\t},\n\t\t\tparams: [\n\t\t\t\t{\n\t\t\t\t\tname: \"value\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"The number to round\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"precision\",\n\t\t\t\t\ttype: { type: \"number\" },\n\t\t\t\t\tdescription: \"Number of decimal places (default: 0)\",\n\t\t\t\t\toptional: true,\n\t\t\t\t},\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription:\n\t\t\t\t\"Rounds to the nearest integer or to a given precision: {{ round value }} or {{ round value 2 }}\",\n\t\t});\n\n\t\t// sqrt — Racine carrée : {{ sqrt value }}\n\t\tdefs.set(\"sqrt\", {\n\t\t\tfn: (value: unknown) => Math.sqrt(toNumber(value)),\n\t\t\tparams: [\n\t\t\t\t{ name: \"value\", type: { type: \"number\" }, description: \"The number\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Returns the square root: {{ sqrt value }}\",\n\t\t});\n\t}\n\n\t// ── Min / Max ────────────────────────────────────────────────────\n\n\t/** Enregistre min et max */\n\tprivate static registerMinMax(defs: Map<string, HelperDefinition>): void {\n\t\t// min — Minimum : {{ min a b }}\n\t\tdefs.set(\"min\", {\n\t\t\tfn: (a: unknown, b: unknown) => Math.min(toNumber(a), toNumber(b)),\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"First number\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Second number\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Returns the smaller of two numbers: {{ min a b }}\",\n\t\t});\n\n\t\t// max — Maximum : {{ max a b }}\n\t\tdefs.set(\"max\", {\n\t\t\tfn: (a: unknown, b: unknown) => Math.max(toNumber(a), toNumber(b)),\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"First number\" },\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Second number\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription: \"Returns the larger of two numbers: {{ max a b }}\",\n\t\t});\n\t}\n\n\t// ── Helper générique ─────────────────────────────────────────────\n\n\t/** Enregistre le helper générique `math` avec opérateur en paramètre */\n\tprivate static registerGenericMath(\n\t\tdefs: Map<string, HelperDefinition>,\n\t): void {\n\t\t// Usage : {{ math a \"+\" b }}, {{ math a \"/\" b }}, {{ math a \"**\" b }}\n\t\tdefs.set(\"math\", {\n\t\t\tfn: (a: unknown, operator: unknown, b: unknown) => {\n\t\t\t\tconst op = String(operator);\n\t\t\t\tif (!SUPPORTED_OPERATORS.has(op)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`[math helper] Unknown operator \"${op}\". ` +\n\t\t\t\t\t\t\t`Supported: ${[...SUPPORTED_OPERATORS].join(\", \")} `,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn applyOperator(toNumber(a), op as MathOperator, toNumber(b));\n\t\t\t},\n\t\t\tparams: [\n\t\t\t\t{ name: \"a\", type: { type: \"number\" }, description: \"Left operand\" },\n\t\t\t\t{\n\t\t\t\t\tname: \"operator\",\n\t\t\t\t\ttype: { type: \"string\", enum: [\"+\", \"-\", \"*\", \"/\", \"%\", \"**\"] },\n\t\t\t\t\tdescription: 'Arithmetic operator: \"+\", \"-\", \"*\", \"/\", \"%\", \"**\"',\n\t\t\t\t},\n\t\t\t\t{ name: \"b\", type: { type: \"number\" }, description: \"Right operand\" },\n\t\t\t],\n\t\t\treturnType: { type: \"number\" },\n\t\t\tdescription:\n\t\t\t\t'Generic math helper with operator as parameter: {{ math a \"+\" b }}, {{ math a \"/\" b }}. ' +\n\t\t\t\t\"Supported operators: +, -, *, /, %, **\",\n\t\t});\n\t}\n\n\t// ─── Enregistrement / Désenregistrement ──────────────────────────────\n\n\t/**\n\t * Enregistre tous les helpers mathématiques sur un `Typebars`\n\t * (ou tout objet implémentant `HelperRegistry`).\n\t *\n\t * **Note :** les MathHelpers sont pré-enregistrés automatiquement par\n\t * le constructeur de `Typebars`. Cette méthode n'est utile que\n\t * si vous avez appelé `unregister()` et souhaitez les ré-activer,\n\t * ou si vous enregistrez sur un registre custom.\n\t *\n\t * @param registry - L'engine ou le registre cible\n\t *\n\t * @example\n\t * ```\n\t * const engine = new Typebars();\n\t * // Les math helpers sont déjà disponibles !\n\t * engine.analyzeAndExecute(\"{{ divide total count }}\", schema, data);\n\t * engine.analyzeAndExecute(\"{{ math price '*' quantity }}\", schema, data);\n\t * ```\n\t */\n\tstatic register(registry: HelperRegistry): void {\n\t\tconst defs = MathHelpers.getDefinitions();\n\t\tfor (const [name, def] of defs) {\n\t\t\tregistry.registerHelper(name, def);\n\t\t}\n\t}\n\n\t/**\n\t * Supprime tous les helpers mathématiques du registre.\n\t *\n\t * @param registry - L'engine ou le registre cible\n\t */\n\tstatic unregister(registry: HelperRegistry): void {\n\t\tfor (const name of MathHelpers.HELPER_NAMES) {\n\t\t\tregistry.unregisterHelper(name);\n\t\t}\n\t}\n\n\t/**\n\t * Retourne la liste des noms de tous les helpers mathématiques.\n\t * Utile pour vérifier si un helper donné fait partie du pack math.\n\t */\n\tstatic getHelperNames(): readonly string[] {\n\t\treturn MathHelpers.HELPER_NAMES;\n\t}\n\n\t/**\n\t * Vérifie si un nom de helper fait partie du pack mathématique.\n\t *\n\t * @param name - Le nom du helper à vérifier\n\t */\n\tstatic isMathHelper(name: string): boolean {\n\t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,EAAK,EAAU,EAAM,CACjD,iBACA,IAAK,KAAK,IACV,iBAAkB,KAAK,gBACxB,CAAC,EACD,MAAO,CAAE,WAAU,OAAM,EAe1B,cAAc,CAAC,EAAc,EAAoC,CAOhE,OANA,KAAK,QAAQ,IAAI,EAAM,CAAU,EACjC,KAAK,IAAI,eAAe,EAAM,EAAW,EAAE,EAG3C,KAAK,iBAAiB,MAAM,EAErB,KASR,gBAAgB,CAAC,EAAoB,CAOpC,OANA,KAAK,QAAQ,OAAO,CAAI,EACxB,KAAK,IAAI,iBAAiB,CAAI,EAG9B,KAAK,iBAAiB,MAAM,EAErB,KASR,SAAS,CAAC,EAAuB,CAChC,OAAO,KAAK,QAAQ,IAAI,CAAI,EAU7B,WAAW,EAAS,CACnB,KAAK,SAAS,MAAM,EACpB,KAAK,iBAAiB,MAAM,EAQrB,YAAY,CAAC,EAAmC,CACvD,IAAI,EAAM,KAAK,SAAS,IAAI,CAAQ,EACpC,GAAI,CAAC,EACJ,EAAM,EAAM,CAAQ,EACpB,KAAK,SAAS,IAAI,EAAU,CAAG,EAEhC,OAAO,EAET",
9
- "debugId": "ACEF99364BF4CF0764756E2164756E21",
10
- "names": []
11
- }
@@ -1,4 +0,0 @@
1
- import{j as u,k as v,l as S}from"./chunk-6955jpr7.js";import{n as M,p as b,q,r as C,s as k,t as D,v as W,y as E}from"./chunk-1gm6cf0e.js";import{D as Z,E as _,F as R,G as $,H as B}from"./chunk-ybh51hbe.js";import{J as X,K as N,L as Y}from"./chunk-8g0d6h85.js";import{M as T,O as P,P as V,Q as y}from"./chunk-4zv02svp.js";function o(j,w,A){if(v(j))return d(j,w,A);if(u(j))return{valid:!0,diagnostics:[],outputSchema:S(j)};let F=M(j);return n(F,j,w,{identifierSchemas:A})}function d(j,w,A){return y(Object.keys(j),(F)=>o(j[F],w,A))}function n(j,w,A,F){let z={root:A,current:A,diagnostics:[],template:w,identifierSchemas:F?.identifierSchemas,helpers:F?.helpers},G=J(j,z);return{valid:!z.diagnostics.some((I)=>I.severity==="error"),diagnostics:z.diagnostics,outputSchema:Y(G)}}function l(j,w){switch(j.type){case"ContentStatement":case"CommentStatement":return;case"MustacheStatement":return g(j,w);case"BlockStatement":return f(j,w);default:K(w,"UNANALYZABLE","warning",`Unsupported AST node type: "${j.type}"`,j);return}}function g(j,w){if(j.path.type==="SubExpression")return K(w,"UNANALYZABLE","warning","Sub-expressions are not statically analyzable",j),{};if(j.params.length>0||j.hash){let A=i(j.path),F=w.helpers?.get(A);if(F){let z=F.params;if(z){let G=z.filter((H)=>!H.optional).length;if(j.params.length<G)K(w,"MISSING_ARGUMENT","error",`Helper "${A}" expects at least ${G} argument(s), but got ${j.params.length}`,j,{helperName:A,expected:`${G} argument(s)`,actual:`${j.params.length} argument(s)`})}for(let G=0;G<j.params.length;G++){let H=O(j.params[G],w,j),I=z?.[G];if(H&&I?.type){let L=I.type;if(!p(H,L)){let h=I.name;K(w,"TYPE_MISMATCH","error",`Helper "${A}" parameter "${h}" expects ${Q(L)}, but got ${Q(H)}`,j,{helperName:A,expected:Q(L),actual:Q(H)})}}}return F.returnType??{type:"string"}}return K(w,"UNKNOWN_HELPER","warning",`Unknown inline helper "${A}" — cannot analyze statically`,j,{helperName:A}),{type:"string"}}return O(j.path,w,j)??{}}function p(j,w){if(!w.type||!j.type)return!0;let A=Array.isArray(w.type)?w.type:[w.type];return(Array.isArray(j.type)?j.type:[j.type]).some((z)=>A.some((G)=>z===G||G==="number"&&z==="integer"||G==="integer"&&z==="number"))}function J(j,w){let A=C(j);if(A.length===0)return{type:"string"};let F=D(j);if(F)return g(F,w);let z=k(j);if(z)return f(z,w);if(A.every((H)=>H.type==="ContentStatement")){let H=A.map((L)=>L.value).join("").trim();if(H==="")return{type:"string"};let I=W(H);if(I)return{type:I}}for(let H of j.body)l(H,w);return{type:"string"}}function f(j,w){let A=r(j);switch(A){case"if":case"unless":{let F=U(j);if(F)O(F,w,j);else K(w,"MISSING_ARGUMENT","error",R(A),j,{helperName:A});let z=J(j.program,w);if(j.inverse){let G=J(j.inverse,w);if(T(z,G))return z;return Y({oneOf:[z,G]})}return z}case"each":{let F=U(j);if(!F){K(w,"MISSING_ARGUMENT","error",R("each"),j,{helperName:"each"});let I=w.current;if(w.current={},J(j.program,w),w.current=I,j.inverse)J(j.inverse,w);return{type:"string"}}let z=O(F,w,j);if(!z){let I=w.current;if(w.current={},J(j.program,w),w.current=I,j.inverse)J(j.inverse,w);return{type:"string"}}let G=N(z,w.root);if(!G){K(w,"TYPE_MISMATCH","error",_("each","an array",Q(z)),j,{helperName:"each",expected:"array",actual:Q(z)});let I=w.current;if(w.current={},J(j.program,w),w.current=I,j.inverse)J(j.inverse,w);return{type:"string"}}let H=w.current;if(w.current=G,J(j.program,w),w.current=H,j.inverse)J(j.inverse,w);return{type:"string"}}case"with":{let F=U(j);if(!F){K(w,"MISSING_ARGUMENT","error",R("with"),j,{helperName:"with"});let I=w.current;w.current={};let L=J(j.program,w);if(w.current=I,j.inverse)J(j.inverse,w);return L}let z=O(F,w,j),G=w.current;w.current=z??{};let H=J(j.program,w);if(w.current=G,j.inverse)J(j.inverse,w);return H}default:{let F=w.helpers?.get(A);if(F){for(let z of j.params)O(z,w,j);if(J(j.program,w),j.inverse)J(j.inverse,w);return F.returnType??{type:"string"}}if(K(w,"UNKNOWN_HELPER","warning",$(A),j,{helperName:A}),J(j.program,w),j.inverse)J(j.inverse,w);return{type:"string"}}}}function O(j,w,A){if(q(j))return w.current;let F=b(j);if(F.length===0){if(j.type==="StringLiteral")return{type:"string"};if(j.type==="NumberLiteral")return{type:"number"};if(j.type==="BooleanLiteral")return{type:"boolean"};if(j.type==="NullLiteral")return{type:"null"};if(j.type==="UndefinedLiteral")return{};K(w,"UNANALYZABLE","warning",B(j.type),A??j);return}let{cleanSegments:z,identifier:G}=E(F);if(G!==null)return a(z,G,w,A??j);let H=X(w.current,z);if(H===void 0){let I=z.join("."),L=V(w.current);K(w,"UNKNOWN_PROPERTY","error",Z(I,L),A??j,{path:I,availableProperties:L});return}return H}function a(j,w,A,F){let z=j.join(".");if(!A.identifierSchemas){K(A,"MISSING_IDENTIFIER_SCHEMAS","error",`Property "${z}:${w}" uses an identifier but no identifier schemas were provided`,F,{path:`${z}:${w}`,identifier:w});return}let G=A.identifierSchemas[w];if(!G){K(A,"UNKNOWN_IDENTIFIER","error",`Property "${z}:${w}" references identifier ${w} but no schema exists for this identifier`,F,{path:`${z}:${w}`,identifier:w});return}let H=X(G,j);if(H===void 0){let I=V(G);K(A,"IDENTIFIER_PROPERTY_NOT_FOUND","error",`Property "${z}" does not exist in the schema for identifier ${w}`,F,{path:z,identifier:w,availableProperties:I});return}return H}function U(j){return j.params[0]}function r(j){if(j.path.type==="PathExpression")return j.path.original;return""}function i(j){if(j.type==="PathExpression")return j.original;return""}function K(j,w,A,F,z,G){let H={severity:A,code:w,message:F};if(z&&"loc"in z&&z.loc)H.loc={start:{line:z.loc.start.line,column:z.loc.start.column},end:{line:z.loc.end.line,column:z.loc.end.column}},H.source=P(j.template,H.loc);if(G)H.details=G;j.diagnostics.push(H)}function Q(j){if(j.type)return Array.isArray(j.type)?j.type.join(" | "):j.type;if(j.oneOf)return"oneOf(...)";if(j.anyOf)return"anyOf(...)";if(j.allOf)return"allOf(...)";if(j.enum)return"enum";return"unknown"}export{o as c,n as d,f as e};
2
-
3
- //# debugId=5BE61AD08B9B8A9B64756E2164756E21
4
- //# sourceMappingURL=chunk-awgj10qg.js.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/analyzer.ts"],
4
- "sourcesContent": [
5
- "import type { JSONSchema7 } from \"json-schema\";\nimport {\n\tcreateMissingArgumentMessage,\n\tcreatePropertyNotFoundMessage,\n\tcreateTypeMismatchMessage,\n\tcreateUnanalyzableMessage,\n\tcreateUnknownHelperMessage,\n} from \"./errors.ts\";\nimport {\n\tdetectLiteralType,\n\textractExpressionIdentifier,\n\textractPathSegments,\n\tgetEffectiveBody,\n\tgetEffectivelySingleBlock,\n\tgetEffectivelySingleExpression,\n\tisThisExpression,\n\tparse,\n} from \"./parser.ts\";\nimport {\n\tresolveArrayItems,\n\tresolveSchemaPath,\n\tsimplifySchema,\n} from \"./schema-resolver.ts\";\nimport type {\n\tAnalysisResult,\n\tDiagnosticCode,\n\tDiagnosticDetails,\n\tHelperDefinition,\n\tTemplateDiagnostic,\n\tTemplateInput,\n\tTemplateInputObject,\n} from \"./types.ts\";\nimport {\n\tinferPrimitiveSchema,\n\tisLiteralInput,\n\tisObjectInput,\n} from \"./types.ts\";\nimport {\n\taggregateObjectAnalysis,\n\tdeepEqual,\n\textractSourceSnippet,\n\tgetSchemaPropertyNames,\n} from \"./utils.ts\";\n\n// ─── Static Analyzer ─────────────────────────────────────────────────────────\n// Static analysis of a Handlebars template against a JSON Schema v7\n// describing the available context.\n//\n// Merged architecture (v2):\n// A single AST traversal performs both **validation** and **return type\n// inference** simultaneously. This eliminates duplication between the former\n// `validate*` and `infer*` functions and improves performance by avoiding\n// a double traversal.\n//\n// Context:\n// The analysis context uses a **save/restore** pattern instead of creating\n// new objects on each recursion (`{ ...ctx, current: X }`). This reduces\n// GC pressure for deeply nested templates.\n//\n// ─── Template Identifiers ────────────────────────────────────────────────────\n// The `{{key:N}}` syntax allows referencing a variable from a specific\n// schema, identified by an integer N. The optional `identifierSchemas`\n// parameter provides a mapping `{ [id]: JSONSchema7 }`.\n//\n// Resolution rules:\n// - `{{meetingId}}` → validated against `inputSchema` (standard behavior)\n// - `{{meetingId:1}}` → validated against `identifierSchemas[1]`\n// - `{{meetingId:1}}` without `identifierSchemas[1]` → error\n\n// ─── Internal Types ──────────────────────────────────────────────────────────\n\n/** Context passed recursively during AST traversal */\ninterface AnalysisContext {\n\t/** Root schema (for resolving $refs) */\n\troot: JSONSchema7;\n\t/** Current context schema (changes with #each, #with) — mutated via save/restore */\n\tcurrent: JSONSchema7;\n\t/** Diagnostics accumulator */\n\tdiagnostics: TemplateDiagnostic[];\n\t/** Full template source (for extracting error snippets) */\n\ttemplate: string;\n\t/** Schemas by template identifier (for the {{key:N}} syntax) */\n\tidentifierSchemas?: Record<number, JSONSchema7>;\n\t/** Registered custom helpers (for static analysis) */\n\thelpers?: Map<string, HelperDefinition>;\n}\n\n// ─── Public API ──────────────────────────────────────────────────────────────\n\n/**\n * Statically analyzes a template against a JSON Schema v7 describing the\n * available context.\n *\n * Backward-compatible version — parses the template internally.\n *\n * @param template - The template string (e.g. `\"Hello {{user.name}}\"`)\n * @param inputSchema - JSON Schema v7 describing the available variables\n * @param identifierSchemas - (optional) Schemas by identifier `{ [id]: JSONSchema7 }`\n * @returns An `AnalysisResult` containing validity, diagnostics, and the\n * inferred output schema.\n */\nexport function analyze(\n\ttemplate: TemplateInput,\n\tinputSchema: JSONSchema7,\n\tidentifierSchemas?: Record<number, JSONSchema7>,\n): AnalysisResult {\n\tif (isObjectInput(template)) {\n\t\treturn analyzeObjectTemplate(template, inputSchema, identifierSchemas);\n\t}\n\tif (isLiteralInput(template)) {\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\tdiagnostics: [],\n\t\t\toutputSchema: inferPrimitiveSchema(template),\n\t\t};\n\t}\n\tconst ast = parse(template);\n\treturn analyzeFromAst(ast, template, inputSchema, { identifierSchemas });\n}\n\n/**\n * Analyzes an object template recursively (standalone version).\n * Each property is analyzed individually, diagnostics are merged,\n * and the `outputSchema` reflects the object structure.\n */\nfunction analyzeObjectTemplate(\n\ttemplate: TemplateInputObject,\n\tinputSchema: JSONSchema7,\n\tidentifierSchemas?: Record<number, JSONSchema7>,\n): AnalysisResult {\n\treturn aggregateObjectAnalysis(Object.keys(template), (key) =>\n\t\tanalyze(template[key] as TemplateInput, inputSchema, identifierSchemas),\n\t);\n}\n\n/**\n * Statically analyzes a template from an already-parsed AST.\n *\n * This is the internal function used by `Typebars.compile()` and\n * `CompiledTemplate.analyze()` to avoid costly re-parsing.\n *\n * @param ast - The already-parsed Handlebars AST\n * @param template - The template source (for error snippets)\n * @param inputSchema - JSON Schema v7 describing the available variables\n * @param options - Additional options\n * @returns An `AnalysisResult`\n */\nexport function analyzeFromAst(\n\tast: hbs.AST.Program,\n\ttemplate: string,\n\tinputSchema: JSONSchema7,\n\toptions?: {\n\t\tidentifierSchemas?: Record<number, JSONSchema7>;\n\t\thelpers?: Map<string, HelperDefinition>;\n\t},\n): AnalysisResult {\n\tconst ctx: AnalysisContext = {\n\t\troot: inputSchema,\n\t\tcurrent: inputSchema,\n\t\tdiagnostics: [],\n\t\ttemplate,\n\t\tidentifierSchemas: options?.identifierSchemas,\n\t\thelpers: options?.helpers,\n\t};\n\n\t// Single pass: type inference + validation in one traversal.\n\tconst outputSchema = inferProgramType(ast, ctx);\n\n\tconst hasErrors = ctx.diagnostics.some((d) => d.severity === \"error\");\n\n\treturn {\n\t\tvalid: !hasErrors,\n\t\tdiagnostics: ctx.diagnostics,\n\t\toutputSchema: simplifySchema(outputSchema),\n\t};\n}\n\n// ─── Unified AST Traversal ───────────────────────────────────────────────────\n// A single set of functions handles both validation (emitting diagnostics)\n// and type inference (returning a JSONSchema7).\n//\n// Main functions:\n// - `inferProgramType` — entry point for a Program (template body or block)\n// - `processStatement` — dispatches a statement (validation side-effects)\n// - `processMustache` — handles a MustacheStatement (expression or inline helper)\n// - `inferBlockType` — handles a BlockStatement (if, each, with, custom…)\n\n/**\n * Dispatches the processing of an individual statement.\n *\n * Called by `inferProgramType` in the \"mixed template\" case to validate\n * each statement while ignoring the returned type (the result is always\n * `string` for a mixed template).\n *\n * @returns The inferred schema for this statement, or `undefined` for\n * statements with no semantics (ContentStatement, CommentStatement).\n */\nfunction processStatement(\n\tstmt: hbs.AST.Statement,\n\tctx: AnalysisContext,\n): JSONSchema7 | undefined {\n\tswitch (stmt.type) {\n\t\tcase \"ContentStatement\":\n\t\tcase \"CommentStatement\":\n\t\t\t// Static text or comment — nothing to validate, no type to infer\n\t\t\treturn undefined;\n\n\t\tcase \"MustacheStatement\":\n\t\t\treturn processMustache(stmt as hbs.AST.MustacheStatement, ctx);\n\n\t\tcase \"BlockStatement\":\n\t\t\treturn inferBlockType(stmt as hbs.AST.BlockStatement, ctx);\n\n\t\tdefault:\n\t\t\t// Unrecognized AST node — emit a warning rather than an error\n\t\t\t// to avoid blocking on future Handlebars extensions.\n\t\t\taddDiagnostic(\n\t\t\t\tctx,\n\t\t\t\t\"UNANALYZABLE\",\n\t\t\t\t\"warning\",\n\t\t\t\t`Unsupported AST node type: \"${stmt.type}\"`,\n\t\t\t\tstmt,\n\t\t\t);\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Processes a MustacheStatement `{{expression}}` or `{{helper arg}}`.\n *\n * Distinguishes two cases:\n * 1. **Simple expression** (`{{name}}`, `{{user.age}}`) — resolution in the schema\n * 2. **Inline helper** (`{{uppercase name}}`) — params > 0 or hash present\n *\n * @returns The inferred schema for this expression\n */\nfunction processMustache(\n\tstmt: hbs.AST.MustacheStatement,\n\tctx: AnalysisContext,\n): JSONSchema7 {\n\t// Sub-expressions (nested helpers) are not supported for static\n\t// analysis — emit a warning.\n\tif (stmt.path.type === \"SubExpression\") {\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"UNANALYZABLE\",\n\t\t\t\"warning\",\n\t\t\t\"Sub-expressions are not statically analyzable\",\n\t\t\tstmt,\n\t\t);\n\t\treturn {};\n\t}\n\n\t// ── Inline helper detection ──────────────────────────────────────────────\n\t// If the MustacheStatement has parameters or a hash, it's a helper call\n\t// (e.g. `{{uppercase name}}`), not a simple expression.\n\tif (stmt.params.length > 0 || stmt.hash) {\n\t\tconst helperName = getExpressionName(stmt.path);\n\n\t\t// Check if the helper is registered\n\t\tconst helper = ctx.helpers?.get(helperName);\n\t\tif (helper) {\n\t\t\tconst helperParams = helper.params;\n\n\t\t\t// ── Check the number of required parameters ──────────────\n\t\t\tif (helperParams) {\n\t\t\t\tconst requiredCount = helperParams.filter((p) => !p.optional).length;\n\t\t\t\tif (stmt.params.length < requiredCount) {\n\t\t\t\t\taddDiagnostic(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\"MISSING_ARGUMENT\",\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t`Helper \"${helperName}\" expects at least ${requiredCount} argument(s), but got ${stmt.params.length}`,\n\t\t\t\t\t\tstmt,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\thelperName,\n\t\t\t\t\t\t\texpected: `${requiredCount} argument(s)`,\n\t\t\t\t\t\t\tactual: `${stmt.params.length} argument(s)`,\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// ── Validate each parameter (existence + type) ───────────────\n\t\t\tfor (let i = 0; i < stmt.params.length; i++) {\n\t\t\t\tconst resolvedSchema = resolveExpressionWithDiagnostics(\n\t\t\t\t\tstmt.params[i] as hbs.AST.Expression,\n\t\t\t\t\tctx,\n\t\t\t\t\tstmt,\n\t\t\t\t);\n\n\t\t\t\t// Check type compatibility if the helper declares the\n\t\t\t\t// expected type for this parameter\n\t\t\t\tconst helperParam = helperParams?.[i];\n\t\t\t\tif (resolvedSchema && helperParam?.type) {\n\t\t\t\t\tconst expectedType = helperParam.type;\n\t\t\t\t\tif (!isParamTypeCompatible(resolvedSchema, expectedType)) {\n\t\t\t\t\t\tconst paramName = helperParam.name;\n\t\t\t\t\t\taddDiagnostic(\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\t\"TYPE_MISMATCH\",\n\t\t\t\t\t\t\t\"error\",\n\t\t\t\t\t\t\t`Helper \"${helperName}\" parameter \"${paramName}\" expects ${schemaTypeLabel(expectedType)}, but got ${schemaTypeLabel(resolvedSchema)}`,\n\t\t\t\t\t\t\tstmt,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\thelperName,\n\t\t\t\t\t\t\t\texpected: schemaTypeLabel(expectedType),\n\t\t\t\t\t\t\t\tactual: schemaTypeLabel(resolvedSchema),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn helper.returnType ?? { type: \"string\" };\n\t\t}\n\n\t\t// Unknown inline helper — warning\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"UNKNOWN_HELPER\",\n\t\t\t\"warning\",\n\t\t\t`Unknown inline helper \"${helperName}\" — cannot analyze statically`,\n\t\t\tstmt,\n\t\t\t{ helperName },\n\t\t);\n\t\treturn { type: \"string\" };\n\t}\n\n\t// ── Simple expression ────────────────────────────────────────────────────\n\treturn resolveExpressionWithDiagnostics(stmt.path, ctx, stmt) ?? {};\n}\n\n/**\n * Checks whether a resolved type is compatible with the type expected\n * by a helper parameter.\n *\n * Compatibility rules:\n * - If either schema has no `type`, validation is not possible → compatible\n * - `integer` is compatible with `number` (integer ⊂ number)\n * - For multiple types (e.g. `[\"string\", \"number\"]`), at least one resolved\n * type must match one expected type\n */\nfunction isParamTypeCompatible(\n\tresolved: JSONSchema7,\n\texpected: JSONSchema7,\n): boolean {\n\t// If either has no type info, we cannot validate\n\tif (!expected.type || !resolved.type) return true;\n\n\tconst expectedTypes = Array.isArray(expected.type)\n\t\t? expected.type\n\t\t: [expected.type];\n\tconst resolvedTypes = Array.isArray(resolved.type)\n\t\t? resolved.type\n\t\t: [resolved.type];\n\n\t// At least one resolved type must be compatible with one expected type\n\treturn resolvedTypes.some((rt) =>\n\t\texpectedTypes.some(\n\t\t\t(et) =>\n\t\t\t\trt === et ||\n\t\t\t\t// integer is a subtype of number\n\t\t\t\t(et === \"number\" && rt === \"integer\") ||\n\t\t\t\t(et === \"integer\" && rt === \"number\"),\n\t\t),\n\t);\n}\n\n/**\n * Infers the output type of a `Program` (template body or block body).\n *\n * Handles 4 cases, from most specific to most general:\n *\n * 1. **Single expression** `{{expr}}` → type of the expression\n * 2. **Single block** `{{#if}}…{{/if}}` → type of the block\n * 3. **Pure text content** → literal detection (number, boolean, null)\n * 4. **Mixed template** → always `string` (concatenation)\n *\n * Validation is performed alongside inference: each expression and block\n * is validated during processing.\n */\nfunction inferProgramType(\n\tprogram: hbs.AST.Program,\n\tctx: AnalysisContext,\n): JSONSchema7 {\n\tconst effective = getEffectiveBody(program);\n\n\t// No significant statements → empty string\n\tif (effective.length === 0) {\n\t\treturn { type: \"string\" };\n\t}\n\n\t// ── Case 1: single expression {{expr}} ─────────────────────────────────\n\tconst singleExpr = getEffectivelySingleExpression(program);\n\tif (singleExpr) {\n\t\treturn processMustache(singleExpr, ctx);\n\t}\n\n\t// ── Case 2: single block {{#if}}, {{#each}}, {{#with}}, … ──────────────\n\tconst singleBlock = getEffectivelySingleBlock(program);\n\tif (singleBlock) {\n\t\treturn inferBlockType(singleBlock, ctx);\n\t}\n\n\t// ── Case 3: only ContentStatements (no expressions) ────────────────────\n\t// If the concatenated (trimmed) text is a typed literal (number, boolean,\n\t// null), we infer the corresponding type.\n\tconst allContent = effective.every((s) => s.type === \"ContentStatement\");\n\tif (allContent) {\n\t\tconst text = effective\n\t\t\t.map((s) => (s as hbs.AST.ContentStatement).value)\n\t\t\t.join(\"\")\n\t\t\t.trim();\n\n\t\tif (text === \"\") return { type: \"string\" };\n\n\t\tconst literalType = detectLiteralType(text);\n\t\tif (literalType) return { type: literalType };\n\t}\n\n\t// ── Case 4: mixed template (text + expressions, multiple blocks…) ──────\n\t// Traverse all statements for validation (side-effects: diagnostics).\n\t// The result is always string (concatenation).\n\tfor (const stmt of program.body) {\n\t\tprocessStatement(stmt, ctx);\n\t}\n\treturn { type: \"string\" };\n}\n\n/**\n * Infers the output type of a BlockStatement and validates its content.\n *\n * Supports built-in helpers (`if`, `unless`, `each`, `with`) and custom\n * helpers registered via `Typebars.registerHelper()`.\n *\n * Uses the **save/restore** pattern for context: instead of creating a new\n * object `{ ...ctx, current: X }` on each recursion, we save `ctx.current`,\n * mutate it, process the body, then restore. This reduces GC pressure for\n * deeply nested templates.\n */\nfunction inferBlockType(\n\tstmt: hbs.AST.BlockStatement,\n\tctx: AnalysisContext,\n): JSONSchema7 {\n\tconst helperName = getBlockHelperName(stmt);\n\n\tswitch (helperName) {\n\t\t// ── if / unless ──────────────────────────────────────────────────────\n\t\t// Validate the condition argument, then infer types from both branches.\n\t\tcase \"if\":\n\t\tcase \"unless\": {\n\t\t\tconst arg = getBlockArgument(stmt);\n\t\t\tif (arg) {\n\t\t\t\tresolveExpressionWithDiagnostics(arg, ctx, stmt);\n\t\t\t} else {\n\t\t\t\taddDiagnostic(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"MISSING_ARGUMENT\",\n\t\t\t\t\t\"error\",\n\t\t\t\t\tcreateMissingArgumentMessage(helperName),\n\t\t\t\t\tstmt,\n\t\t\t\t\t{ helperName },\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Infer the type of the \"then\" branch\n\t\t\tconst thenType = inferProgramType(stmt.program, ctx);\n\n\t\t\tif (stmt.inverse) {\n\t\t\t\tconst elseType = inferProgramType(stmt.inverse, ctx);\n\t\t\t\t// If both branches have the same type → single type\n\t\t\t\tif (deepEqual(thenType, elseType)) return thenType;\n\t\t\t\t// Otherwise → union of both types\n\t\t\t\treturn simplifySchema({ oneOf: [thenType, elseType] });\n\t\t\t}\n\n\t\t\t// No else branch → the result is the type of the then branch\n\t\t\t// (conceptually optional, but Handlebars returns \"\" for falsy)\n\t\t\treturn thenType;\n\t\t}\n\n\t\t// ── each ─────────────────────────────────────────────────────────────\n\t\t// Resolve the collection schema, then validate the body with the item\n\t\t// schema as the new context.\n\t\tcase \"each\": {\n\t\t\tconst arg = getBlockArgument(stmt);\n\t\t\tif (!arg) {\n\t\t\t\taddDiagnostic(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"MISSING_ARGUMENT\",\n\t\t\t\t\t\"error\",\n\t\t\t\t\tcreateMissingArgumentMessage(\"each\"),\n\t\t\t\t\tstmt,\n\t\t\t\t\t{ helperName: \"each\" },\n\t\t\t\t);\n\t\t\t\t// Validate the body with an empty context (best-effort)\n\t\t\t\tconst saved = ctx.current;\n\t\t\t\tctx.current = {};\n\t\t\t\tinferProgramType(stmt.program, ctx);\n\t\t\t\tctx.current = saved;\n\t\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\t\t\t\treturn { type: \"string\" };\n\t\t\t}\n\n\t\t\tconst collectionSchema = resolveExpressionWithDiagnostics(arg, ctx, stmt);\n\t\t\tif (!collectionSchema) {\n\t\t\t\t// The path could not be resolved — diagnostic already emitted.\n\t\t\t\tconst saved = ctx.current;\n\t\t\t\tctx.current = {};\n\t\t\t\tinferProgramType(stmt.program, ctx);\n\t\t\t\tctx.current = saved;\n\t\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\t\t\t\treturn { type: \"string\" };\n\t\t\t}\n\n\t\t\t// Resolve the schema of the array elements\n\t\t\tconst itemSchema = resolveArrayItems(collectionSchema, ctx.root);\n\t\t\tif (!itemSchema) {\n\t\t\t\taddDiagnostic(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"TYPE_MISMATCH\",\n\t\t\t\t\t\"error\",\n\t\t\t\t\tcreateTypeMismatchMessage(\n\t\t\t\t\t\t\"each\",\n\t\t\t\t\t\t\"an array\",\n\t\t\t\t\t\tschemaTypeLabel(collectionSchema),\n\t\t\t\t\t),\n\t\t\t\t\tstmt,\n\t\t\t\t\t{\n\t\t\t\t\t\thelperName: \"each\",\n\t\t\t\t\t\texpected: \"array\",\n\t\t\t\t\t\tactual: schemaTypeLabel(collectionSchema),\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\t// Validate the body with an empty context (best-effort)\n\t\t\t\tconst saved = ctx.current;\n\t\t\t\tctx.current = {};\n\t\t\t\tinferProgramType(stmt.program, ctx);\n\t\t\t\tctx.current = saved;\n\t\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\t\t\t\treturn { type: \"string\" };\n\t\t\t}\n\n\t\t\t// Validate the body with the item schema as the new context\n\t\t\tconst saved = ctx.current;\n\t\t\tctx.current = itemSchema;\n\t\t\tinferProgramType(stmt.program, ctx);\n\t\t\tctx.current = saved;\n\n\t\t\t// The inverse branch ({{else}}) keeps the parent context\n\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\n\t\t\t// An each concatenates renders → always string\n\t\t\treturn { type: \"string\" };\n\t\t}\n\n\t\t// ── with ─────────────────────────────────────────────────────────────\n\t\t// Resolve the inner schema, then validate the body with it as the\n\t\t// new context.\n\t\tcase \"with\": {\n\t\t\tconst arg = getBlockArgument(stmt);\n\t\t\tif (!arg) {\n\t\t\t\taddDiagnostic(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"MISSING_ARGUMENT\",\n\t\t\t\t\t\"error\",\n\t\t\t\t\tcreateMissingArgumentMessage(\"with\"),\n\t\t\t\t\tstmt,\n\t\t\t\t\t{ helperName: \"with\" },\n\t\t\t\t);\n\t\t\t\t// Validate the body with an empty context\n\t\t\t\tconst saved = ctx.current;\n\t\t\t\tctx.current = {};\n\t\t\t\tconst result = inferProgramType(stmt.program, ctx);\n\t\t\t\tctx.current = saved;\n\t\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tconst innerSchema = resolveExpressionWithDiagnostics(arg, ctx, stmt);\n\n\t\t\tconst saved = ctx.current;\n\t\t\tctx.current = innerSchema ?? {};\n\t\t\tconst result = inferProgramType(stmt.program, ctx);\n\t\t\tctx.current = saved;\n\n\t\t\t// The inverse branch keeps the parent context\n\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\n\t\t\treturn result;\n\t\t}\n\n\t\t// ── Custom or unknown helper ─────────────────────────────────────────\n\t\tdefault: {\n\t\t\tconst helper = ctx.helpers?.get(helperName);\n\t\t\tif (helper) {\n\t\t\t\t// Registered custom helper — validate parameters\n\t\t\t\tfor (const param of stmt.params) {\n\t\t\t\t\tresolveExpressionWithDiagnostics(\n\t\t\t\t\t\tparam as hbs.AST.Expression,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tstmt,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// Validate the body with the current context\n\t\t\t\tinferProgramType(stmt.program, ctx);\n\t\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\t\t\t\treturn helper.returnType ?? { type: \"string\" };\n\t\t\t}\n\n\t\t\t// Unknown helper — warning\n\t\t\taddDiagnostic(\n\t\t\t\tctx,\n\t\t\t\t\"UNKNOWN_HELPER\",\n\t\t\t\t\"warning\",\n\t\t\t\tcreateUnknownHelperMessage(helperName),\n\t\t\t\tstmt,\n\t\t\t\t{ helperName },\n\t\t\t);\n\t\t\t// Still validate the body with the current context (best-effort)\n\t\t\tinferProgramType(stmt.program, ctx);\n\t\t\tif (stmt.inverse) inferProgramType(stmt.inverse, ctx);\n\t\t\treturn { type: \"string\" };\n\t\t}\n\t}\n}\n\n// ─── Expression Resolution ───────────────────────────────────────────────────\n\n/**\n * Resolves an AST expression to a sub-schema, emitting a diagnostic\n * if the path cannot be resolved.\n *\n * Handles the `{{key:N}}` syntax:\n * - If the expression has an identifier N → resolution in `identifierSchemas[N]`\n * - If identifier N has no associated schema → error\n * - If no identifier → resolution in `ctx.current` (standard behavior)\n *\n * @returns The resolved sub-schema, or `undefined` if the path is invalid.\n */\nfunction resolveExpressionWithDiagnostics(\n\texpr: hbs.AST.Expression,\n\tctx: AnalysisContext,\n\t/** Parent AST node (for diagnostic location) */\n\tparentNode?: hbs.AST.Node,\n): JSONSchema7 | undefined {\n\t// Handle `this` / `.` → return the current context\n\tif (isThisExpression(expr)) {\n\t\treturn ctx.current;\n\t}\n\n\tconst segments = extractPathSegments(expr);\n\tif (segments.length === 0) {\n\t\t// Expression that is not a PathExpression (e.g. literal, SubExpression)\n\t\tif (expr.type === \"StringLiteral\") return { type: \"string\" };\n\t\tif (expr.type === \"NumberLiteral\") return { type: \"number\" };\n\t\tif (expr.type === \"BooleanLiteral\") return { type: \"boolean\" };\n\t\tif (expr.type === \"NullLiteral\") return { type: \"null\" };\n\t\tif (expr.type === \"UndefinedLiteral\") return {};\n\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"UNANALYZABLE\",\n\t\t\t\"warning\",\n\t\t\tcreateUnanalyzableMessage(expr.type),\n\t\t\tparentNode ?? expr,\n\t\t);\n\t\treturn undefined;\n\t}\n\n\t// ── Identifier extraction ──────────────────────────────────────────────\n\tconst { cleanSegments, identifier } = extractExpressionIdentifier(segments);\n\n\tif (identifier !== null) {\n\t\t// The expression uses the {{key:N}} syntax — resolve from\n\t\t// the schema of identifier N.\n\t\treturn resolveWithIdentifier(\n\t\t\tcleanSegments,\n\t\t\tidentifier,\n\t\t\tctx,\n\t\t\tparentNode ?? expr,\n\t\t);\n\t}\n\n\t// ── Standard resolution (no identifier) ────────────────────────────────\n\tconst resolved = resolveSchemaPath(ctx.current, cleanSegments);\n\tif (resolved === undefined) {\n\t\tconst fullPath = cleanSegments.join(\".\");\n\t\tconst availableProperties = getSchemaPropertyNames(ctx.current);\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"UNKNOWN_PROPERTY\",\n\t\t\t\"error\",\n\t\t\tcreatePropertyNotFoundMessage(fullPath, availableProperties),\n\t\t\tparentNode ?? expr,\n\t\t\t{ path: fullPath, availableProperties },\n\t\t);\n\t\treturn undefined;\n\t}\n\n\treturn resolved;\n}\n\n/**\n * Resolves an expression with identifier `{{key:N}}` by looking up the\n * schema associated with identifier N.\n *\n * Emits an error diagnostic if:\n * - No `identifierSchemas` were provided\n * - Identifier N has no associated schema\n * - The property does not exist in the identifier's schema\n */\nfunction resolveWithIdentifier(\n\tcleanSegments: string[],\n\tidentifier: number,\n\tctx: AnalysisContext,\n\tnode: hbs.AST.Node,\n): JSONSchema7 | undefined {\n\tconst fullPath = cleanSegments.join(\".\");\n\n\t// No identifierSchemas provided at all\n\tif (!ctx.identifierSchemas) {\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"MISSING_IDENTIFIER_SCHEMAS\",\n\t\t\t\"error\",\n\t\t\t`Property \"${fullPath}:${identifier}\" uses an identifier but no identifier schemas were provided`,\n\t\t\tnode,\n\t\t\t{ path: `${fullPath}:${identifier}`, identifier },\n\t\t);\n\t\treturn undefined;\n\t}\n\n\t// The identifier does not exist in the provided schemas\n\tconst idSchema = ctx.identifierSchemas[identifier];\n\tif (!idSchema) {\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"UNKNOWN_IDENTIFIER\",\n\t\t\t\"error\",\n\t\t\t`Property \"${fullPath}:${identifier}\" references identifier ${identifier} but no schema exists for this identifier`,\n\t\t\tnode,\n\t\t\t{ path: `${fullPath}:${identifier}`, identifier },\n\t\t);\n\t\treturn undefined;\n\t}\n\n\t// Resolve the path within the identifier's schema\n\tconst resolved = resolveSchemaPath(idSchema, cleanSegments);\n\tif (resolved === undefined) {\n\t\tconst availableProperties = getSchemaPropertyNames(idSchema);\n\t\taddDiagnostic(\n\t\t\tctx,\n\t\t\t\"IDENTIFIER_PROPERTY_NOT_FOUND\",\n\t\t\t\"error\",\n\t\t\t`Property \"${fullPath}\" does not exist in the schema for identifier ${identifier}`,\n\t\t\tnode,\n\t\t\t{\n\t\t\t\tpath: fullPath,\n\t\t\t\tidentifier,\n\t\t\t\tavailableProperties,\n\t\t\t},\n\t\t);\n\t\treturn undefined;\n\t}\n\n\treturn resolved;\n}\n\n// ─── Utilities ───────────────────────────────────────────────────────────────\n\n/**\n * Extracts the first argument of a BlockStatement.\n *\n * In the Handlebars AST, for `{{#if active}}`:\n * - `stmt.path` → PathExpression(\"if\") ← the helper name\n * - `stmt.params[0]` → PathExpression(\"active\") ← the actual argument\n *\n * @returns The argument expression, or `undefined` if the block has no argument.\n */\nfunction getBlockArgument(\n\tstmt: hbs.AST.BlockStatement,\n): hbs.AST.Expression | undefined {\n\treturn stmt.params[0] as hbs.AST.Expression | undefined;\n}\n\n/**\n * Retrieves the helper name from a BlockStatement (e.g. \"if\", \"each\", \"with\").\n */\nfunction getBlockHelperName(stmt: hbs.AST.BlockStatement): string {\n\tif (stmt.path.type === \"PathExpression\") {\n\t\treturn (stmt.path as hbs.AST.PathExpression).original;\n\t}\n\treturn \"\";\n}\n\n/**\n * Retrieves the name of an expression (first segment of the PathExpression).\n * Used to identify inline helpers.\n */\nfunction getExpressionName(expr: hbs.AST.Expression): string {\n\tif (expr.type === \"PathExpression\") {\n\t\treturn (expr as hbs.AST.PathExpression).original;\n\t}\n\treturn \"\";\n}\n\n/**\n * Adds an enriched diagnostic to the analysis context.\n *\n * Each diagnostic includes:\n * - A machine-readable `code` for the frontend\n * - A human-readable `message` describing the problem\n * - A `source` snippet from the template (if the position is available)\n * - Structured `details` for debugging\n */\nfunction addDiagnostic(\n\tctx: AnalysisContext,\n\tcode: DiagnosticCode,\n\tseverity: \"error\" | \"warning\",\n\tmessage: string,\n\tnode?: hbs.AST.Node,\n\tdetails?: DiagnosticDetails,\n): void {\n\tconst diagnostic: TemplateDiagnostic = { severity, code, message };\n\n\t// Extract the position and source snippet if available\n\tif (node && \"loc\" in node && node.loc) {\n\t\tdiagnostic.loc = {\n\t\t\tstart: { line: node.loc.start.line, column: node.loc.start.column },\n\t\t\tend: { line: node.loc.end.line, column: node.loc.end.column },\n\t\t};\n\t\t// Extract the template fragment around the error\n\t\tdiagnostic.source = extractSourceSnippet(ctx.template, diagnostic.loc);\n\t}\n\n\tif (details) {\n\t\tdiagnostic.details = details;\n\t}\n\n\tctx.diagnostics.push(diagnostic);\n}\n\n/**\n * Returns a human-readable label for a schema's type (for error messages).\n */\nfunction schemaTypeLabel(schema: JSONSchema7): string {\n\tif (schema.type) {\n\t\treturn Array.isArray(schema.type) ? schema.type.join(\" | \") : schema.type;\n\t}\n\tif (schema.oneOf) return \"oneOf(...)\";\n\tif (schema.anyOf) return \"anyOf(...)\";\n\tif (schema.allOf) return \"allOf(...)\";\n\tif (schema.enum) return \"enum\";\n\treturn \"unknown\";\n}\n\n// ─── Export for Internal Use ─────────────────────────────────────────────────\n// `inferBlockType` is exported to allow targeted unit tests\n// on block type inference.\nexport { inferBlockType };\n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A,EACA,EACO,CACP,IAAM,EAAiC,CAAE,WAAU,OAAM,SAAQ,EAGjE,GAAI,GAAQ,QAAS,GAAQ,EAAK,IACjC,EAAW,IAAM,CAChB,MAAO,CAAE,KAAM,EAAK,IAAI,MAAM,KAAM,OAAQ,EAAK,IAAI,MAAM,MAAO,EAClE,IAAK,CAAE,KAAM,EAAK,IAAI,IAAI,KAAM,OAAQ,EAAK,IAAI,IAAI,MAAO,CAC7D,EAEA,EAAW,OAAS,EAAqB,EAAI,SAAU,EAAW,GAAG,EAGtE,GAAI,EACH,EAAW,QAAU,EAGtB,EAAI,YAAY,KAAK,CAAU,EAMhC,SAAS,CAAe,CAAC,EAA6B,CACrD,GAAI,EAAO,KACV,OAAO,MAAM,QAAQ,EAAO,IAAI,EAAI,EAAO,KAAK,KAAK,KAAK,EAAI,EAAO,KAEtE,GAAI,EAAO,MAAO,MAAO,aACzB,GAAI,EAAO,MAAO,MAAO,aACzB,GAAI,EAAO,MAAO,MAAO,aACzB,GAAI,EAAO,KAAM,MAAO,OACxB,MAAO",
8
- "debugId": "5BE61AD08B9B8A9B64756E2164756E21",
9
- "names": []
10
- }
@@ -1,7 +0,0 @@
1
- function P(w,G){if(w===G)return!0;if(w===null||G===null)return!1;if(typeof w!==typeof G)return!1;if(Array.isArray(w)){if(!Array.isArray(G))return!1;if(w.length!==G.length)return!1;for(let F=0;F<w.length;F++)if(!P(w[F],G[F]))return!1;return!0}if(typeof w==="object"){let F=w,H=G,I=Object.keys(F),J=Object.keys(H);if(I.length!==J.length)return!1;for(let M of I)if(!(M in H)||!P(F[M],H[M]))return!1;return!0}return!1}class Q{capacity;cache=new Map;constructor(w){this.capacity=w;if(w<1)throw Error("LRUCache capacity must be at least 1")}get(w){if(!this.cache.has(w))return;let G=this.cache.get(w);return this.cache.delete(w),this.cache.set(w,G),G}set(w,G){if(this.cache.has(w))this.cache.delete(w);else if(this.cache.size>=this.capacity){let F=this.cache.keys().next().value;if(F!==void 0)this.cache.delete(F)}this.cache.set(w,G)}has(w){return this.cache.has(w)}delete(w){return this.cache.delete(w)}clear(){this.cache.clear()}get size(){return this.cache.size}}function S(w,G){let F=w.split(`
2
- `),H=G.start.line-1,I=G.end.line-1;if(H<0||H>=F.length)return"";if(H===I)return(F[H]??"").trim();let J=Math.min(I,F.length-1);return F.slice(H,J+1).map((M)=>M.trimEnd()).join(`
3
- `).trim()}function T(w){let G=new Set;if(w.properties)for(let F of Object.keys(w.properties))G.add(F);for(let F of["allOf","anyOf","oneOf"]){let H=w[F];if(H)for(let I of H){if(typeof I==="boolean")continue;if(I.properties)for(let J of Object.keys(I.properties))G.add(J)}}return Array.from(G).sort()}function U(w,G){let F=[],H={},I=!0;for(let J of w){let M=G(J);if(!M.valid)I=!1;F.push(...M.diagnostics),H[J]=M.outputSchema}return{valid:I,diagnostics:F,outputSchema:{type:"object",properties:H,required:w}}}function W(w,G){let F=[],H={},I={},J=!0;for(let O of w){let N=G(O);if(!N.analysis.valid)J=!1;F.push(...N.analysis.diagnostics),H[O]=N.analysis.outputSchema,I[O]=N.value}return{analysis:{valid:J,diagnostics:F,outputSchema:{type:"object",properties:H,required:w}},value:J?I:void 0}}
4
- export{P,Q,S as R,T as S,U as T,W as U};
5
-
6
- //# debugId=7D2B6D65A23A9D4664756E2164756E21
7
- //# sourceMappingURL=chunk-fhvf5y4x.js.map
@@ -1,10 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/utils.ts"],
4
- "sourcesContent": [
5
- "import type { JSONSchema7 } from \"json-schema\";\nimport type { AnalysisResult, TemplateDiagnostic } from \"./types.ts\";\n\n// ─── Utilitaires ─────────────────────────────────────────────────────────────\n// Fonctions et classes utilitaires partagées par les différents modules\n// du moteur de template.\n\n// ─── Deep Equality ───────────────────────────────────────────────────────────\n// Comparaison structurelle profonde pour des valeurs JSON-compatibles.\n// Plus robuste que `JSON.stringify` car indépendant de l'ordre des clés\n// et sans allocation de strings intermédiaires.\n\n/**\n * Compare récursivement deux valeurs JSON-compatibles.\n *\n * @param a - Première valeur\n * @param b - Seconde valeur\n * @returns `true` si les deux valeurs sont structurellement identiques\n *\n * @example\n * ```\n * deepEqual({ a: 1, b: 2 }, { b: 2, a: 1 }) // → true\n * deepEqual([1, 2], [1, 2]) // → true\n * deepEqual({ a: 1 }, { a: 2 }) // → false\n * ```\n */\nexport function deepEqual(a: unknown, b: unknown): boolean {\n\t// Identité stricte (couvre primitives, même ref, NaN !== NaN volontaire)\n\tif (a === b) return true;\n\n\t// null est typeof \"object\" en JS — on le traite à part\n\tif (a === null || b === null) return false;\n\tif (typeof a !== typeof b) return false;\n\n\t// ── Tableaux ────────────────────────────────────────────────────────────\n\tif (Array.isArray(a)) {\n\t\tif (!Array.isArray(b)) return false;\n\t\tif (a.length !== b.length) return false;\n\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\tif (!deepEqual(a[i], b[i])) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// ── Objets ──────────────────────────────────────────────────────────────\n\tif (typeof a === \"object\") {\n\t\tconst objA = a as Record<string, unknown>;\n\t\tconst objB = b as Record<string, unknown>;\n\t\tconst keysA = Object.keys(objA);\n\t\tconst keysB = Object.keys(objB);\n\n\t\tif (keysA.length !== keysB.length) return false;\n\n\t\tfor (const key of keysA) {\n\t\t\tif (!(key in objB) || !deepEqual(objA[key], objB[key])) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// Primitives différentes (déjà couvert par a === b au début)\n\treturn false;\n}\n\n// ─── LRU Cache ───────────────────────────────────────────────────────────────\n// Cache à capacité fixe avec éviction LRU (Least Recently Used).\n// Utilise l'ordre d'insertion de `Map` pour tracker l'accès : l'entrée\n// la plus ancienne est toujours en première position.\n\n/**\n * Cache LRU simple à capacité fixe.\n *\n * @example\n * ```\n * const cache = new LRUCache<string, number>(2);\n * cache.set(\"a\", 1);\n * cache.set(\"b\", 2);\n * cache.get(\"a\"); // → 1 (marque \"a\" comme récemment utilisé)\n * cache.set(\"c\", 3); // évince \"b\" (le moins récemment utilisé)\n * cache.get(\"b\"); // → undefined\n * ```\n */\nexport class LRUCache<K, V> {\n\tprivate readonly cache = new Map<K, V>();\n\n\tconstructor(private readonly capacity: number) {\n\t\tif (capacity < 1) {\n\t\t\tthrow new Error(\"LRUCache capacity must be at least 1\");\n\t\t}\n\t}\n\n\t/**\n\t * Récupère une valeur du cache. Retourne `undefined` si absente.\n\t * Marque l'entrée comme récemment utilisée.\n\t */\n\tget(key: K): V | undefined {\n\t\tif (!this.cache.has(key)) return undefined;\n\n\t\t// Déplacer en fin de Map (= plus récent)\n\t\tconst value = this.cache.get(key) as V;\n\t\tthis.cache.delete(key);\n\t\tthis.cache.set(key, value);\n\t\treturn value;\n\t}\n\n\t/**\n\t * Insère ou met à jour une valeur dans le cache.\n\t * Si le cache est plein, évince l'entrée la moins récemment utilisée.\n\t */\n\tset(key: K, value: V): void {\n\t\tif (this.cache.has(key)) {\n\t\t\tthis.cache.delete(key);\n\t\t} else if (this.cache.size >= this.capacity) {\n\t\t\t// Évince la première entrée (la plus ancienne)\n\t\t\tconst oldestKey = this.cache.keys().next().value;\n\t\t\tif (oldestKey !== undefined) {\n\t\t\t\tthis.cache.delete(oldestKey);\n\t\t\t}\n\t\t}\n\t\tthis.cache.set(key, value);\n\t}\n\n\t/**\n\t * Vérifie si une clé existe dans le cache (sans modifier l'ordre LRU).\n\t */\n\thas(key: K): boolean {\n\t\treturn this.cache.has(key);\n\t}\n\n\t/**\n\t * Supprime une entrée du cache.\n\t * @returns `true` si l'entrée existait et a été supprimée\n\t */\n\tdelete(key: K): boolean {\n\t\treturn this.cache.delete(key);\n\t}\n\n\t/** Vide entièrement le cache. */\n\tclear(): void {\n\t\tthis.cache.clear();\n\t}\n\n\t/** Nombre d'entrées actuellement dans le cache. */\n\tget size(): number {\n\t\treturn this.cache.size;\n\t}\n}\n\n// ─── Extraction de snippet source ────────────────────────────────────────────\n// Utilisé pour enrichir les diagnostics avec le fragment de template\n// qui a causé l'erreur.\n\n/**\n * Extrait un fragment de template autour d'une position donnée.\n *\n * @param template - Le template source complet\n * @param loc - La position (ligne/colonne, 1-based) de l'erreur\n * @returns Le fragment de code correspondant (trimé)\n */\nexport function extractSourceSnippet(\n\ttemplate: string,\n\tloc: {\n\t\tstart: { line: number; column: number };\n\t\tend: { line: number; column: number };\n\t},\n): string {\n\tconst lines = template.split(\"\\n\");\n\tconst startLine = loc.start.line - 1; // 0-based\n\tconst endLine = loc.end.line - 1;\n\n\tif (startLine < 0 || startLine >= lines.length) return \"\";\n\n\tif (startLine === endLine) {\n\t\t// Même ligne — extraire la portion entre start.column et end.column\n\t\tconst line = lines[startLine] ?? \"\";\n\t\treturn line.trim();\n\t}\n\n\t// Multi-lignes — retourner les lignes concernées\n\tconst clampedEnd = Math.min(endLine, lines.length - 1);\n\treturn lines\n\t\t.slice(startLine, clampedEnd + 1)\n\t\t.map((l) => l.trimEnd())\n\t\t.join(\"\\n\")\n\t\t.trim();\n}\n\n// ─── Schema Properties ──────────────────────────────────────────────────────\n// Utilitaire pour lister les propriétés disponibles dans un schema,\n// utilisé pour enrichir les messages d'erreur (suggestions).\n\n/**\n * Liste les noms de propriétés déclarées dans un JSON Schema.\n * Retourne un tableau vide si le schema n'a pas de `properties`.\n */\nexport function getSchemaPropertyNames(schema: JSONSchema7): string[] {\n\tconst names = new Set<string>();\n\n\t// Propriétés directes\n\tif (schema.properties) {\n\t\tfor (const key of Object.keys(schema.properties)) {\n\t\t\tnames.add(key);\n\t\t}\n\t}\n\n\t// Propriétés dans les combinateurs\n\tfor (const combinator of [\"allOf\", \"anyOf\", \"oneOf\"] as const) {\n\t\tconst branches = schema[combinator];\n\t\tif (branches) {\n\t\t\tfor (const branch of branches) {\n\t\t\t\tif (typeof branch === \"boolean\") continue;\n\t\t\t\tif (branch.properties) {\n\t\t\t\t\tfor (const key of Object.keys(branch.properties)) {\n\t\t\t\t\t\tnames.add(key);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Array.from(names).sort();\n}\n\n// ─── Agrégation d'analyses d'objets ──────────────────────────────────────────\n// Factorise le pattern commun de récursion sur un objet template :\n// itérer les clés, analyser chaque entrée via un callback, accumuler\n// les diagnostics, construire le outputSchema objet.\n//\n// Utilisé par :\n// - `analyzer.ts` (analyzeObjectTemplate)\n// - `Typebars.analyzeObject()` (typebars.ts)\n// - `CompiledTemplate.analyze()` en mode objet (compiled-template.ts)\n\n/**\n * Agrège les résultats d'analyse d'un ensemble d'entrées nommées en un\n * seul `AnalysisResult` avec un `outputSchema` de type objet.\n *\n * @param keys - Les clés de l'objet à analyser\n * @param analyzeEntry - Callback qui analyse une entrée par sa clé\n * @returns Un `AnalysisResult` agrégé\n *\n * @example\n * ```\n * aggregateObjectAnalysis(\n * Object.keys(template),\n * (key) => analyze(template[key], inputSchema),\n * );\n * ```\n */\nexport function aggregateObjectAnalysis(\n\tkeys: string[],\n\tanalyzeEntry: (key: string) => AnalysisResult,\n): AnalysisResult {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst properties: Record<string, JSONSchema7> = {};\n\tlet allValid = true;\n\n\tfor (const key of keys) {\n\t\tconst child = analyzeEntry(key);\n\t\tif (!child.valid) allValid = false;\n\t\tallDiagnostics.push(...child.diagnostics);\n\t\tproperties[key] = child.outputSchema;\n\t}\n\n\treturn {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"object\",\n\t\t\tproperties,\n\t\t\trequired: keys,\n\t\t},\n\t};\n}\n\n/**\n * Agrège les résultats d'analyse **et** d'exécution d'un ensemble d'entrées\n * nommées. Retourne à la fois l'`AnalysisResult` agrégé et l'objet des\n * valeurs exécutées (ou `undefined` si au moins une entrée est invalide).\n *\n * @param keys - Les clés de l'objet\n * @param processEntry - Callback qui analyse et exécute une entrée par sa clé\n * @returns `{ analysis, value }` agrégés\n */\nexport function aggregateObjectAnalysisAndExecution(\n\tkeys: string[],\n\tprocessEntry: (key: string) => { analysis: AnalysisResult; value: unknown },\n): { analysis: AnalysisResult; value: unknown } {\n\tconst allDiagnostics: TemplateDiagnostic[] = [];\n\tconst properties: Record<string, JSONSchema7> = {};\n\tconst resultValues: Record<string, unknown> = {};\n\tlet allValid = true;\n\n\tfor (const key of keys) {\n\t\tconst child = processEntry(key);\n\t\tif (!child.analysis.valid) allValid = false;\n\t\tallDiagnostics.push(...child.analysis.diagnostics);\n\t\tproperties[key] = child.analysis.outputSchema;\n\t\tresultValues[key] = child.value;\n\t}\n\n\tconst analysis: AnalysisResult = {\n\t\tvalid: allValid,\n\t\tdiagnostics: allDiagnostics,\n\t\toutputSchema: {\n\t\t\ttype: \"object\",\n\t\t\tproperties,\n\t\t\trequired: keys,\n\t\t},\n\t};\n\n\treturn {\n\t\tanalysis,\n\t\tvalue: allValid ? resultValues : undefined,\n\t};\n}\n"
6
- ],
7
- "mappings": "AA0BO,SAAS,CAAS,CAAC,EAAY,EAAqB,CAE1D,GAAI,IAAM,EAAG,MAAO,GAGpB,GAAI,IAAM,MAAQ,IAAM,KAAM,MAAO,GACrC,GAAI,OAAO,IAAM,OAAO,EAAG,MAAO,GAGlC,GAAI,MAAM,QAAQ,CAAC,EAAG,CACrB,GAAI,CAAC,MAAM,QAAQ,CAAC,EAAG,MAAO,GAC9B,GAAI,EAAE,SAAW,EAAE,OAAQ,MAAO,GAClC,QAAS,EAAI,EAAG,EAAI,EAAE,OAAQ,IAC7B,GAAI,CAAC,EAAU,EAAE,GAAI,EAAE,EAAE,EAAG,MAAO,GAEpC,MAAO,GAIR,GAAI,OAAO,IAAM,SAAU,CAC1B,IAAM,EAAO,EACP,EAAO,EACP,EAAQ,OAAO,KAAK,CAAI,EACxB,EAAQ,OAAO,KAAK,CAAI,EAE9B,GAAI,EAAM,SAAW,EAAM,OAAQ,MAAO,GAE1C,QAAW,KAAO,EACjB,GAAI,EAAE,KAAO,IAAS,CAAC,EAAU,EAAK,GAAM,EAAK,EAAI,EAAG,MAAO,GAEhE,MA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23A9D4664756E2164756E21",
9
- "names": []
10
- }
@@ -1,5 +0,0 @@
1
- import{C as O}from"./chunk-vka4e61h.js";import{Q}from"./chunk-fhvf5y4x.js";import V from"handlebars";var Y=/^(.+):(\d+)$/,Z=/^-?\d+(\.\d+)?$/,K=new Q(128);function N(k){let q=K.get(k);if(q)return q;try{let z=V.parse(k);return K.set(k,z),z}catch(z){let G=z instanceof Error?z.message:String(z),J=G.match(/line\s+(\d+).*?column\s+(\d+)/i),X=J?{line:parseInt(J[1]??"0",10),column:parseInt(J[2]??"0",10)}:void 0;throw new O(G,X)}}function P(k){try{return V.parse(k)}catch(q){let z=q instanceof Error?q.message:String(q),G=z.match(/line\s+(\d+).*?column\s+(\d+)/i),J=G?{line:parseInt(G[1]??"0",10),column:parseInt(G[2]??"0",10)}:void 0;throw new O(z,J)}}function H(){K.clear()}function U(k){let{body:q}=k;return q.length===1&&q[0]?.type==="MustacheStatement"}function _(k){if(k.type==="PathExpression")return k.parts;return[]}function w(k){if(k.type!=="PathExpression")return!1;let q=k;return q.original==="this"||q.original==="."}function W(k){return k.body.filter((q)=>!(q.type==="ContentStatement"&&q.value.trim()===""))}function A(k){let q=W(k);if(q.length===1&&q[0]?.type==="BlockStatement")return q[0];return null}function C(k){let q=W(k);if(q.length===1&&q[0]?.type==="MustacheStatement")return q[0];return null}function S(k){return k.body.every((q)=>q.type==="ContentStatement"||q.type==="MustacheStatement"&&q.params.length===0&&!q.hash)}function $(k){if(Z.test(k))return"number";if(k==="true"||k==="false")return"boolean";if(k==="null")return"null";return null}function T(k){let q=k.trim(),z=$(q);if(z==="number")return Number(q);if(z==="boolean")return q==="true";if(z==="null")return null;return k}function D(k){let q=k.match(Y);if(q)return{key:q[1]??k,identifier:parseInt(q[2]??"0",10)};return{key:k,identifier:null}}function L(k){if(k.length===0)return{cleanSegments:[],identifier:null};let q=k[k.length-1],z=D(q);if(z.identifier!==null)return{cleanSegments:[...k.slice(0,-1),z.key],identifier:z.identifier};return{cleanSegments:k,identifier:null}}
2
- export{N as n,P as o,H as p,U as q,_ as r,w as s,W as t,A as u,C as v,S as w,$ as x,T as y,D as z,L as A};
3
-
4
- //# debugId=3C85E965B62779F664756E2164756E21
5
- //# sourceMappingURL=chunk-ggdfaqhe.js.map