@cadence-app/compiler 0.1.0

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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +54 -0
  3. package/dist/build.d.ts +31 -0
  4. package/dist/build.js +437 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +180 -0
  7. package/dist/dev-server.d.ts +16 -0
  8. package/dist/dev-server.js +81 -0
  9. package/dist/engine-budget.d.ts +9 -0
  10. package/dist/engine-budget.js +8 -0
  11. package/dist/hash.d.ts +2 -0
  12. package/dist/hash.js +12 -0
  13. package/dist/host/browser-mock-host.d.ts +1 -0
  14. package/dist/host/browser-mock-host.js +175 -0
  15. package/dist/host/dev-client.d.ts +1 -0
  16. package/dist/host/dev-client.js +6 -0
  17. package/dist/host/engine-entry.d.ts +1 -0
  18. package/dist/host/engine-entry.js +199 -0
  19. package/dist/index.d.ts +23 -0
  20. package/dist/index.js +14 -0
  21. package/dist/manifest.d.ts +47 -0
  22. package/dist/manifest.js +202 -0
  23. package/dist/publish/credentials.d.ts +17 -0
  24. package/dist/publish/credentials.js +87 -0
  25. package/dist/publish/distribution-client.d.ts +45 -0
  26. package/dist/publish/distribution-client.js +113 -0
  27. package/dist/publish/publish-bundle.d.ts +27 -0
  28. package/dist/publish/publish-bundle.js +44 -0
  29. package/dist/publish/publish-errors.d.ts +41 -0
  30. package/dist/publish/publish-errors.js +60 -0
  31. package/dist/publish/read-secret.d.ts +7 -0
  32. package/dist/publish/read-secret.js +30 -0
  33. package/dist/style/compile-style.d.ts +13 -0
  34. package/dist/style/compile-style.js +135 -0
  35. package/dist/style/theme-sheet.d.ts +6 -0
  36. package/dist/style/theme-sheet.js +8 -0
  37. package/dist/template/ast.d.ts +47 -0
  38. package/dist/template/ast.js +1 -0
  39. package/dist/template/codegen.d.ts +8 -0
  40. package/dist/template/codegen.js +220 -0
  41. package/dist/template/entities.d.ts +12 -0
  42. package/dist/template/entities.js +103 -0
  43. package/dist/template/expression.d.ts +16 -0
  44. package/dist/template/expression.js +196 -0
  45. package/dist/template/parser.d.ts +10 -0
  46. package/dist/template/parser.js +437 -0
  47. package/package.json +62 -0
@@ -0,0 +1,113 @@
1
+ import { normalizeRemoteUrl } from "./credentials.js";
2
+ import { AppNotFoundError, InvalidTokenError, PublishRejectedError, RemoteUnreachableError, VersionConflictError, } from "./publish-errors.js";
3
+ const APPS_PAGE_SIZE = 100;
4
+ const HTTP_UNAUTHORIZED = 401;
5
+ const HTTP_FORBIDDEN = 403;
6
+ const HTTP_CONFLICT = 409;
7
+ /**
8
+ * Le serveur de distribution, vu du CLI. Une méthode par intention, et des
9
+ * erreurs typées : aucun appelant n'a à lire un code HTTP.
10
+ */
11
+ export class DistributionClient {
12
+ constructor(options) {
13
+ this.remoteUrl = normalizeRemoteUrl(options.remoteUrl);
14
+ this.token = options.token;
15
+ this.fetch = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
16
+ }
17
+ remoteUrl;
18
+ token;
19
+ fetch;
20
+ /** Lève si le serveur refuse le jeton ; se tait s'il l'accepte. */
21
+ async verifyToken() {
22
+ const response = await this.send('/api/v1/access-tokens', { method: 'GET' });
23
+ if (!response.ok) {
24
+ throw new InvalidTokenError(response.status);
25
+ }
26
+ }
27
+ /**
28
+ * L'application dont le slug est celui du manifeste. Le serveur ne l'expose
29
+ * pas par slug : on parcourt les pages du tenant et on compare.
30
+ */
31
+ async findAppBySlug(slug) {
32
+ for (let page = 0;; page += 1) {
33
+ const response = await this.send(`/api/v1/apps?page=${page}&size=${APPS_PAGE_SIZE}`, {
34
+ method: 'GET',
35
+ });
36
+ if (!response.ok) {
37
+ throw this.rejectionFor(response.status, await readBody(response));
38
+ }
39
+ const body = (await response.json());
40
+ const match = (body.items ?? []).find((app) => app.slug === slug);
41
+ if (match !== undefined) {
42
+ return match;
43
+ }
44
+ const totalPages = body.totalPages ?? 0;
45
+ if (page + 1 >= totalPages) {
46
+ throw new AppNotFoundError(slug);
47
+ }
48
+ }
49
+ }
50
+ /** Envoie l'archive comme nouvelle version de l'application. */
51
+ async publishVersion(input) {
52
+ const form = new FormData();
53
+ form.append('version', input.version);
54
+ form.append('package', new Blob([input.archive], { type: 'application/zip' }), input.filename);
55
+ const response = await this.send(`/api/v1/apps/${input.appId}/versions`, {
56
+ method: 'POST',
57
+ body: form,
58
+ });
59
+ if (response.status === HTTP_CONFLICT) {
60
+ throw new VersionConflictError(input.version);
61
+ }
62
+ if (!response.ok) {
63
+ throw this.rejectionFor(response.status, await readBody(response));
64
+ }
65
+ return parsePublishedVersion(await readBody(response), input.version);
66
+ }
67
+ async send(pathname, init) {
68
+ const url = `${this.remoteUrl}${pathname}`;
69
+ try {
70
+ return await this.fetch(url, {
71
+ ...init,
72
+ headers: { ...(init.headers ?? {}), authorization: `Bearer ${this.token}` },
73
+ });
74
+ }
75
+ catch (error) {
76
+ throw new RemoteUnreachableError(url, error);
77
+ }
78
+ }
79
+ rejectionFor(status, body) {
80
+ if (status === HTTP_UNAUTHORIZED || status === HTTP_FORBIDDEN) {
81
+ return new InvalidTokenError(status);
82
+ }
83
+ return new PublishRejectedError(status, body);
84
+ }
85
+ }
86
+ /**
87
+ * Le corps d'une réponse acceptée est indicatif : le serveur peut ne rien
88
+ * renvoyer d'exploitable sans que la publication ait échoué.
89
+ */
90
+ function parsePublishedVersion(body, fallbackVersion) {
91
+ try {
92
+ const parsed = JSON.parse(body);
93
+ return {
94
+ versionString: asText(parsed['versionString']) ?? fallbackVersion,
95
+ status: asText(parsed['status']),
96
+ createdAt: asText(parsed['createdAt']),
97
+ };
98
+ }
99
+ catch {
100
+ return { versionString: fallbackVersion, status: null, createdAt: null };
101
+ }
102
+ }
103
+ function asText(value) {
104
+ return typeof value === 'string' && value !== '' ? value : null;
105
+ }
106
+ async function readBody(response) {
107
+ try {
108
+ return (await response.text()).trim();
109
+ }
110
+ catch {
111
+ return '';
112
+ }
113
+ }
@@ -0,0 +1,27 @@
1
+ import type { Credentials } from './credentials.js';
2
+ import { DistributionClient } from './distribution-client.js';
3
+ import type { PublishedVersion } from './distribution-client.js';
4
+ /** Ce qu'une publication réussie a réellement envoyé, et où. */
5
+ export interface PublishReport {
6
+ readonly remoteUrl: string;
7
+ readonly appId: string;
8
+ readonly slug: string;
9
+ readonly archivePath: string;
10
+ readonly archiveBytes: number;
11
+ readonly published: PublishedVersion;
12
+ }
13
+ export interface PublishOptions {
14
+ readonly miniappDir: string;
15
+ /** Publier cette application-ci, au lieu de résoudre le slug du manifeste. */
16
+ readonly appId?: string;
17
+ /** Identifiants explicites, sinon ceux de `mini login`. */
18
+ readonly credentials?: Credentials;
19
+ /** Fabrique du client : les tests en fournissent un sans réseau. */
20
+ readonly createClient?: (credentials: Credentials) => DistributionClient;
21
+ }
22
+ /**
23
+ * Compile puis publie. La compilation n'est pas optionnelle : publier une
24
+ * archive plus vieille que les sources est le genre d'erreur qu'on ne
25
+ * découvre que sur l'appareil de quelqu'un d'autre.
26
+ */
27
+ export declare function publishMiniApp(options: PublishOptions): Promise<PublishReport>;
@@ -0,0 +1,44 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { buildMiniApp } from "../build.js";
4
+ import { readCredentials } from "./credentials.js";
5
+ import { DistributionClient } from "./distribution-client.js";
6
+ import { NotAuthenticatedError } from "./publish-errors.js";
7
+ /**
8
+ * Compile puis publie. La compilation n'est pas optionnelle : publier une
9
+ * archive plus vieille que les sources est le genre d'erreur qu'on ne
10
+ * découvre que sur l'appareil de quelqu'un d'autre.
11
+ */
12
+ export async function publishMiniApp(options) {
13
+ const credentials = options.credentials ?? (await readCredentials());
14
+ if (credentials === null) {
15
+ throw new NotAuthenticatedError();
16
+ }
17
+ const summary = await buildMiniApp({
18
+ miniappDir: options.miniappDir,
19
+ minify: true,
20
+ zip: true,
21
+ });
22
+ if (summary.zipFile === null) {
23
+ throw new Error("la compilation n'a produit aucune archive — publication impossible");
24
+ }
25
+ const archivePath = path.join(summary.outDir, summary.zipFile);
26
+ const archive = await readFile(archivePath);
27
+ const client = options.createClient?.(credentials) ?? new DistributionClient(credentials);
28
+ const slug = summary.manifest.name;
29
+ const appId = options.appId ?? (await client.findAppBySlug(slug)).id;
30
+ const published = await client.publishVersion({
31
+ appId,
32
+ version: summary.manifest.version,
33
+ archive,
34
+ filename: summary.zipFile,
35
+ });
36
+ return {
37
+ remoteUrl: credentials.remoteUrl,
38
+ appId,
39
+ slug,
40
+ archivePath,
41
+ archiveBytes: archive.byteLength,
42
+ published,
43
+ };
44
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Erreurs de publication, typées par cause : le CLI choisit son message et son
3
+ * code de sortie sur le type, jamais en inspectant une chaîne.
4
+ */
5
+ /** Aucun identifiant enregistré, ou effacé depuis. */
6
+ export declare class NotAuthenticatedError extends Error {
7
+ readonly name = "NotAuthenticatedError";
8
+ constructor();
9
+ }
10
+ /** Le serveur a refusé le jeton : expiré, révoqué, ou jamais valide. */
11
+ export declare class InvalidTokenError extends Error {
12
+ readonly status: number;
13
+ readonly name = "InvalidTokenError";
14
+ constructor(status: number);
15
+ }
16
+ /** Le slug du manifeste ne correspond à aucune application du tenant. */
17
+ export declare class AppNotFoundError extends Error {
18
+ readonly slug: string;
19
+ readonly name = "AppNotFoundError";
20
+ constructor(slug: string);
21
+ }
22
+ /** Cette version existe déjà : republier exigerait de l'écraser. */
23
+ export declare class VersionConflictError extends Error {
24
+ readonly version: string;
25
+ readonly name = "VersionConflictError";
26
+ constructor(version: string);
27
+ }
28
+ /** Le serveur a refusé la publication pour une raison qu'il explique lui-même. */
29
+ export declare class PublishRejectedError extends Error {
30
+ readonly status: number;
31
+ readonly body: string;
32
+ readonly name = "PublishRejectedError";
33
+ constructor(status: number, body: string);
34
+ }
35
+ /** Le serveur est injoignable, ou a coupé la connexion. */
36
+ export declare class RemoteUnreachableError extends Error {
37
+ readonly url: string;
38
+ readonly cause: unknown;
39
+ readonly name = "RemoteUnreachableError";
40
+ constructor(url: string, cause: unknown);
41
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Erreurs de publication, typées par cause : le CLI choisit son message et son
3
+ * code de sortie sur le type, jamais en inspectant une chaîne.
4
+ */
5
+ /** Aucun identifiant enregistré, ou effacé depuis. */
6
+ export class NotAuthenticatedError extends Error {
7
+ name = 'NotAuthenticatedError';
8
+ constructor() {
9
+ super("aucun identifiant enregistré — lancer « mini login » d'abord");
10
+ }
11
+ }
12
+ /** Le serveur a refusé le jeton : expiré, révoqué, ou jamais valide. */
13
+ export class InvalidTokenError extends Error {
14
+ status;
15
+ name = 'InvalidTokenError';
16
+ constructor(status) {
17
+ super(`le serveur a refusé le jeton (HTTP ${status}) — en générer un nouveau et relancer « mini login »`);
18
+ this.status = status;
19
+ }
20
+ }
21
+ /** Le slug du manifeste ne correspond à aucune application du tenant. */
22
+ export class AppNotFoundError extends Error {
23
+ slug;
24
+ name = 'AppNotFoundError';
25
+ constructor(slug) {
26
+ super(`aucune application « ${slug} » sur ce serveur — créer l'application, ou publier avec --app-id <uuid>`);
27
+ this.slug = slug;
28
+ }
29
+ }
30
+ /** Cette version existe déjà : republier exigerait de l'écraser. */
31
+ export class VersionConflictError extends Error {
32
+ version;
33
+ name = 'VersionConflictError';
34
+ constructor(version) {
35
+ super(`la version ${version} existe déjà sur ce serveur — incrémenter « version » dans manifest.json`);
36
+ this.version = version;
37
+ }
38
+ }
39
+ /** Le serveur a refusé la publication pour une raison qu'il explique lui-même. */
40
+ export class PublishRejectedError extends Error {
41
+ status;
42
+ body;
43
+ name = 'PublishRejectedError';
44
+ constructor(status, body) {
45
+ super(`le serveur a refusé la publication (HTTP ${status})${body === '' ? '' : ` : ${body}`}`);
46
+ this.status = status;
47
+ this.body = body;
48
+ }
49
+ }
50
+ /** Le serveur est injoignable, ou a coupé la connexion. */
51
+ export class RemoteUnreachableError extends Error {
52
+ url;
53
+ cause;
54
+ name = 'RemoteUnreachableError';
55
+ constructor(url, cause) {
56
+ super(`serveur injoignable à ${url} : ${cause instanceof Error ? cause.message : String(cause)}`);
57
+ this.url = url;
58
+ this.cause = cause;
59
+ }
60
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Lit un secret sur l'entrée standard sans l'afficher.
3
+ *
4
+ * L'écho n'est coupé que sur un vrai terminal : dans un tube ou en CI, il n'y
5
+ * a rien à cacher et forcer le mode brut ferait échouer la lecture.
6
+ */
7
+ export declare function readSecret(prompt: string): Promise<string>;
@@ -0,0 +1,30 @@
1
+ import { createInterface } from 'node:readline';
2
+ /**
3
+ * Lit un secret sur l'entrée standard sans l'afficher.
4
+ *
5
+ * L'écho n'est coupé que sur un vrai terminal : dans un tube ou en CI, il n'y
6
+ * a rien à cacher et forcer le mode brut ferait échouer la lecture.
7
+ */
8
+ export async function readSecret(prompt) {
9
+ const input = process.stdin;
10
+ const output = process.stdout;
11
+ const hideable = input.isTTY === true;
12
+ output.write(prompt);
13
+ if (hideable) {
14
+ input.setRawMode(true);
15
+ }
16
+ const reader = createInterface({ input, terminal: false });
17
+ try {
18
+ for await (const line of reader) {
19
+ return line.trim();
20
+ }
21
+ return '';
22
+ }
23
+ finally {
24
+ reader.close();
25
+ if (hideable) {
26
+ input.setRawMode(false);
27
+ output.write('\n');
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,13 @@
1
+ export declare class StyleCompileError extends Error {
2
+ constructor(unit: string, cause: string);
3
+ }
4
+ export interface CompileStyleOptions {
5
+ readonly unitName: string;
6
+ readonly loadPaths?: readonly string[];
7
+ }
8
+ /**
9
+ * SCSS → CSS (dart-sass), puis scoping par attribut sur le dernier composé de
10
+ * chaque sélecteur, puis conversion `rpx` → `calc(n / 750 * 100vw)`. Tout se
11
+ * joue au build : le runtime ne fait qu'injecter la feuille résultante.
12
+ */
13
+ export declare function compileStyle(scssSource: string, styleId: string, options: CompileStyleOptions): Promise<string>;
@@ -0,0 +1,135 @@
1
+ import postcss from 'postcss';
2
+ import selectorParser from 'postcss-selector-parser';
3
+ import * as sass from 'sass';
4
+ import { scopeAttributeFor } from '@cadence-app/runtime';
5
+ export class StyleCompileError extends Error {
6
+ constructor(unit, cause) {
7
+ super(`Failed to compile style for '${unit}': ${cause}`);
8
+ this.name = 'StyleCompileError';
9
+ }
10
+ }
11
+ /**
12
+ * SCSS → CSS (dart-sass), puis scoping par attribut sur le dernier composé de
13
+ * chaque sélecteur, puis conversion `rpx` → `calc(n / 750 * 100vw)`. Tout se
14
+ * joue au build : le runtime ne fait qu'injecter la feuille résultante.
15
+ */
16
+ export async function compileStyle(scssSource, styleId, options) {
17
+ let css;
18
+ try {
19
+ css = sass.compileString(scssSource, {
20
+ style: 'expanded',
21
+ loadPaths: [...(options.loadPaths ?? [])],
22
+ }).css;
23
+ }
24
+ catch (error) {
25
+ throw new StyleCompileError(options.unitName, error instanceof Error ? error.message : String(error));
26
+ }
27
+ const result = await postcss([
28
+ scopeSelectorsPlugin(scopeAttributeFor(styleId)),
29
+ rpxToViewportPlugin(options.unitName),
30
+ ]).process(css, { from: undefined });
31
+ return result.css;
32
+ }
33
+ function scopeSelectorsPlugin(scopeAttr) {
34
+ const transformSelectors = selectorParser((selectors) => {
35
+ selectors.each((selector) => {
36
+ const attribute = selectorParser.attribute({
37
+ attribute: scopeAttr,
38
+ value: undefined,
39
+ raws: {},
40
+ });
41
+ const target = findScopeInsertionPoint(selector);
42
+ if (target === null) {
43
+ selector.append(attribute);
44
+ }
45
+ else {
46
+ selector.insertBefore(target, attribute);
47
+ }
48
+ });
49
+ });
50
+ return {
51
+ postcssPlugin: 'cadence-scope-selectors',
52
+ /**
53
+ * Parcours unique plutôt qu'un visiteur `Rule` : PostCSS re-visite une
54
+ * règle dont une déclaration a été modifiée, et le plugin `rpx` en modifie
55
+ * dans la même passe. Un visiteur `Rule` scopait donc deux fois toute règle
56
+ * portant du `rpx`, rendant la spécificité dépendante de l'unité employée.
57
+ */
58
+ Once(root) {
59
+ root.walkRules((rule) => {
60
+ if (isInsideKeyframes(rule)) {
61
+ return;
62
+ }
63
+ rule.selector = transformSelectors.processSync(rule.selector);
64
+ });
65
+ },
66
+ };
67
+ }
68
+ /**
69
+ * Point d'insertion de l'attribut de scope : avant le premier pseudo-élément
70
+ * du dernier composé (`.a::after` → `.a[scope]::after`), sinon fin du
71
+ * sélecteur.
72
+ */
73
+ function findScopeInsertionPoint(selector) {
74
+ const nodes = selector.nodes;
75
+ let lastCompoundStart = 0;
76
+ for (let i = nodes.length - 1; i >= 0; i -= 1) {
77
+ if (nodes[i]?.type === 'combinator') {
78
+ lastCompoundStart = i + 1;
79
+ break;
80
+ }
81
+ }
82
+ for (let i = lastCompoundStart; i < nodes.length; i += 1) {
83
+ const node = nodes[i];
84
+ if (node !== undefined && isPseudoElement(node)) {
85
+ return node;
86
+ }
87
+ }
88
+ return null;
89
+ }
90
+ function isPseudoElement(node) {
91
+ return node.type === 'pseudo' && node.value.startsWith('::');
92
+ }
93
+ function isInsideKeyframes(rule) {
94
+ let parent = rule.parent;
95
+ while (parent !== undefined && parent.type !== 'root') {
96
+ if (parent.type === 'atrule' && 'name' in parent && String(parent.name).endsWith('keyframes')) {
97
+ return true;
98
+ }
99
+ parent = parent.parent;
100
+ }
101
+ return false;
102
+ }
103
+ /* Le signe fait partie du nombre. Sans lui, `-20rpx` produisait `-calc(…)`,
104
+ que tout navigateur écarte en silence — la déclaration disparaissait. */
105
+ const RPX_VALUE_PATTERN = /(-?\d*\.?\d+)rpx/g;
106
+ const RPX_BASE_WIDTH = 750;
107
+ /* Au-delà, `rpx` cesse de croître (ADR-020). Sous cette largeur — tout
108
+ téléphone en portrait — `min()` rend `100vw` et la formule est celle d'avant. */
109
+ const RPX_VIEWPORT_CAP_PX = 600;
110
+ function rpxToViewportPlugin(unitName) {
111
+ return {
112
+ postcssPlugin: 'cadence-rpx',
113
+ /**
114
+ * `rpx` **est** une fraction de la largeur du viewport. Le convertir dans
115
+ * une condition donnerait `(max-width: 80vw)` — « le viewport est plus
116
+ * étroit que 80 % de lui-même », jamais vrai. Ce n'est donc pas un
117
+ * visiteur qui manquait ici, c'est un refus : une requête toujours fausse
118
+ * se diagnostique moins bien qu'une erreur de build.
119
+ */
120
+ AtRule(atRule) {
121
+ if (!atRule.params.includes('rpx')) {
122
+ return;
123
+ }
124
+ throw new StyleCompileError(unitName, `'rpx' has no meaning in an @${atRule.name} condition ` +
125
+ `(@${atRule.name} ${atRule.params}) — it is a fraction of the viewport width, ` +
126
+ 'so the query would compare the viewport to itself; use px');
127
+ },
128
+ Declaration(declaration) {
129
+ if (!declaration.value.includes('rpx')) {
130
+ return;
131
+ }
132
+ declaration.value = declaration.value.replace(RPX_VALUE_PATTERN, (_match, amount) => `calc(${amount} / ${RPX_BASE_WIDTH} * min(100vw, ${RPX_VIEWPORT_CAP_PX}px))`);
133
+ },
134
+ };
135
+ }
@@ -0,0 +1,6 @@
1
+ import type { TokenTree } from '@cadence-app/theme';
2
+ /**
3
+ * Feuille de tokens d'un mini-programme : preset embarqué, surchargé par ce que
4
+ * le manifest déclare, résolu et aplati une fois pour toutes au build (§9).
5
+ */
6
+ export declare function buildThemeSheet(overrides: TokenTree | undefined): string;
@@ -0,0 +1,8 @@
1
+ import { basePreset, mergePreset, themeSheetFor } from '@cadence-app/theme';
2
+ /**
3
+ * Feuille de tokens d'un mini-programme : preset embarqué, surchargé par ce que
4
+ * le manifest déclare, résolu et aplati une fois pour toutes au build (§9).
5
+ */
6
+ export function buildThemeSheet(overrides) {
7
+ return themeSheetFor(overrides === undefined ? basePreset : mergePreset(basePreset, overrides));
8
+ }
@@ -0,0 +1,47 @@
1
+ export interface ElementNode {
2
+ readonly kind: 'element';
3
+ readonly tag: string;
4
+ readonly attrs: Readonly<Record<string, string>>;
5
+ readonly bindings: Readonly<Record<string, string>>;
6
+ readonly events: Readonly<Record<string, string>>;
7
+ readonly children: readonly TemplateNode[];
8
+ readonly slotTarget: string | null;
9
+ }
10
+ export interface TextNode {
11
+ readonly kind: 'text';
12
+ readonly text: string;
13
+ }
14
+ export interface InterpolationNode {
15
+ readonly kind: 'interpolation';
16
+ readonly expression: string;
17
+ }
18
+ export interface IfBranchNode {
19
+ readonly condition: string | null;
20
+ readonly children: readonly TemplateNode[];
21
+ }
22
+ export interface IfNode {
23
+ readonly kind: 'if';
24
+ readonly branches: readonly IfBranchNode[];
25
+ }
26
+ export interface ForNode {
27
+ readonly kind: 'for';
28
+ readonly itemName: string;
29
+ readonly itemsExpression: string;
30
+ readonly trackExpression: string;
31
+ readonly children: readonly TemplateNode[];
32
+ }
33
+ export interface SwitchCaseNode {
34
+ readonly match: string | null;
35
+ readonly children: readonly TemplateNode[];
36
+ }
37
+ export interface SwitchNode {
38
+ readonly kind: 'switch';
39
+ readonly expression: string;
40
+ readonly cases: readonly SwitchCaseNode[];
41
+ }
42
+ export interface SlotNode {
43
+ readonly kind: 'slot';
44
+ readonly name: string | null;
45
+ readonly fallback: readonly TemplateNode[];
46
+ }
47
+ export type TemplateNode = ElementNode | TextNode | InterpolationNode | IfNode | ForNode | SwitchNode | SlotNode;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { TemplateNode } from './ast.js';
2
+ /**
3
+ * Génère le corps d'une fonction de rendu `(rt, rc, ctx) => void` appelant la
4
+ * table d'instructions du runtime. Aucune analyse de template ne subsiste au
5
+ * runtime : chaque liaison est une fermeture prête à être enveloppée dans un
6
+ * effect.
7
+ */
8
+ export declare function generateRenderFunction(nodes: readonly TemplateNode[]): string;