@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,220 @@
1
+ import { rewriteExpression } from "./expression.js";
2
+ const DEFAULT_SLOT_NAME = 'default';
3
+ /**
4
+ * Génère le corps d'une fonction de rendu `(rt, rc, ctx) => void` appelant la
5
+ * table d'instructions du runtime. Aucune analyse de template ne subsiste au
6
+ * runtime : chaque liaison est une fermeture prête à être enveloppée dans un
7
+ * effect.
8
+ */
9
+ export function generateRenderFunction(nodes) {
10
+ const writer = new CodeWriter();
11
+ writer.line('function render(rt, rc, ctx) {');
12
+ writer.indent();
13
+ const scope = { signalLocals: new Set(), rawLocals: new Set() };
14
+ emitNodes(writer, nodes, 'rc', scope, new RcNamer());
15
+ writer.dedent();
16
+ writer.line('}');
17
+ return writer.toString();
18
+ }
19
+ class RcNamer {
20
+ next = 0;
21
+ fresh() {
22
+ this.next += 1;
23
+ return `rc${this.next}`;
24
+ }
25
+ }
26
+ class CodeWriter {
27
+ lines = [];
28
+ level = 0;
29
+ line(text) {
30
+ this.lines.push(`${' '.repeat(this.level)}${text}`);
31
+ }
32
+ indent() {
33
+ this.level += 1;
34
+ }
35
+ dedent() {
36
+ this.level -= 1;
37
+ }
38
+ toString() {
39
+ return this.lines.join('\n');
40
+ }
41
+ }
42
+ function emitNodes(writer, nodes, rcVar, scope, namer) {
43
+ for (const node of nodes) {
44
+ emitNode(writer, node, rcVar, scope, namer);
45
+ }
46
+ }
47
+ function emitNode(writer, node, rcVar, scope, namer) {
48
+ switch (node.kind) {
49
+ case 'text':
50
+ writer.line(`rt.text(${rcVar}, ${JSON.stringify(node.text)});`);
51
+ return;
52
+ case 'interpolation':
53
+ writer.line(`rt.bindText(${rcVar}, () => (${rewriteExpression(node.expression, scope)}));`);
54
+ return;
55
+ case 'element':
56
+ emitElement(writer, node, rcVar, scope, namer);
57
+ return;
58
+ case 'if':
59
+ emitIf(writer, node, rcVar, scope, namer);
60
+ return;
61
+ case 'for':
62
+ emitFor(writer, node, rcVar, scope, namer);
63
+ return;
64
+ case 'switch':
65
+ emitSwitch(writer, node, rcVar, scope, namer);
66
+ return;
67
+ case 'slot':
68
+ emitSlot(writer, node, rcVar, scope, namer);
69
+ return;
70
+ default:
71
+ assertNever(node);
72
+ }
73
+ }
74
+ function emitElement(writer, node, rcVar, scope, namer) {
75
+ const defaultChildren = node.children.filter((child) => !(child.kind === 'element' && child.slotTarget !== null));
76
+ const namedSlotChildren = node.children.filter((child) => child.kind === 'element' && child.slotTarget !== null);
77
+ writer.line(`rt.node(${rcVar}, ${JSON.stringify(node.tag)}, {`);
78
+ writer.indent();
79
+ emitStaticAttrs(writer, node);
80
+ emitBindings(writer, node, scope);
81
+ emitEvents(writer, node, scope);
82
+ if (defaultChildren.length > 0) {
83
+ const childRc = namer.fresh();
84
+ writer.line(`children: (${childRc}) => {`);
85
+ writer.indent();
86
+ emitNodes(writer, defaultChildren, childRc, scope, namer);
87
+ writer.dedent();
88
+ writer.line('},');
89
+ }
90
+ if (namedSlotChildren.length > 0) {
91
+ writer.line('slots: {');
92
+ writer.indent();
93
+ for (const slotChild of namedSlotChildren) {
94
+ const slotRc = namer.fresh();
95
+ writer.line(`${JSON.stringify(slotChild.slotTarget)}: (${slotRc}) => {`);
96
+ writer.indent();
97
+ emitNode(writer, { ...slotChild, slotTarget: null }, slotRc, scope, namer);
98
+ writer.dedent();
99
+ writer.line('},');
100
+ }
101
+ writer.dedent();
102
+ writer.line('},');
103
+ }
104
+ writer.dedent();
105
+ writer.line('});');
106
+ }
107
+ function emitStaticAttrs(writer, node) {
108
+ const entries = Object.entries(node.attrs);
109
+ if (entries.length === 0) {
110
+ return;
111
+ }
112
+ const attrsBody = entries
113
+ .map(([name, value]) => `${JSON.stringify(name)}: ${JSON.stringify(value)}`)
114
+ .join(', ');
115
+ writer.line(`attrs: { ${attrsBody} },`);
116
+ }
117
+ function emitBindings(writer, node, scope) {
118
+ const entries = Object.entries(node.bindings);
119
+ if (entries.length === 0) {
120
+ return;
121
+ }
122
+ writer.line('bind: {');
123
+ writer.indent();
124
+ for (const [name, expression] of entries) {
125
+ writer.line(`${JSON.stringify(name)}: () => (${rewriteExpression(expression, scope)}),`);
126
+ }
127
+ writer.dedent();
128
+ writer.line('},');
129
+ }
130
+ function emitEvents(writer, node, scope) {
131
+ const entries = Object.entries(node.events);
132
+ if (entries.length === 0) {
133
+ return;
134
+ }
135
+ const handlerScope = {
136
+ signalLocals: scope.signalLocals,
137
+ rawLocals: new Set([...scope.rawLocals, '$event']),
138
+ };
139
+ writer.line('on: {');
140
+ writer.indent();
141
+ for (const [name, statement] of entries) {
142
+ writer.line(`${JSON.stringify(name)}: ($event) => { ${rewriteExpression(statement, handlerScope)}; },`);
143
+ }
144
+ writer.dedent();
145
+ writer.line('},');
146
+ }
147
+ function emitIf(writer, node, rcVar, scope, namer) {
148
+ writer.line(`rt.ifBlock(${rcVar}, [`);
149
+ writer.indent();
150
+ for (const branch of node.branches) {
151
+ const branchRc = namer.fresh();
152
+ if (branch.condition === null) {
153
+ writer.line(`{ render: (${branchRc}) => {`);
154
+ }
155
+ else {
156
+ writer.line(`{ when: () => (${rewriteExpression(branch.condition, scope)}), render: (${branchRc}) => {`);
157
+ }
158
+ writer.indent();
159
+ emitNodes(writer, branch.children, branchRc, scope, namer);
160
+ writer.dedent();
161
+ writer.line('} },');
162
+ }
163
+ writer.dedent();
164
+ writer.line(']);');
165
+ }
166
+ function emitFor(writer, node, rcVar, scope, namer) {
167
+ const itemRc = namer.fresh();
168
+ const trackScope = {
169
+ signalLocals: scope.signalLocals,
170
+ rawLocals: new Set([...scope.rawLocals, node.itemName]),
171
+ };
172
+ const childScope = {
173
+ signalLocals: new Set([...scope.signalLocals, node.itemName, '$index']),
174
+ rawLocals: scope.rawLocals,
175
+ };
176
+ writer.line(`rt.forBlock(${rcVar}, () => (${rewriteExpression(node.itemsExpression, scope)}),`);
177
+ writer.indent();
178
+ writer.line(`(${node.itemName}) => (${rewriteExpression(node.trackExpression, trackScope)}),`);
179
+ writer.line(`(${itemRc}, ${node.itemName}, $index) => {`);
180
+ writer.indent();
181
+ emitNodes(writer, node.children, itemRc, childScope, namer);
182
+ writer.dedent();
183
+ writer.line('});');
184
+ writer.dedent();
185
+ }
186
+ function emitSwitch(writer, node, rcVar, scope, namer) {
187
+ writer.line(`rt.switchBlock(${rcVar}, () => (${rewriteExpression(node.expression, scope)}), [`);
188
+ writer.indent();
189
+ for (const switchCase of node.cases) {
190
+ const caseRc = namer.fresh();
191
+ if (switchCase.match === null) {
192
+ writer.line(`{ render: (${caseRc}) => {`);
193
+ }
194
+ else {
195
+ writer.line(`{ match: () => (${rewriteExpression(switchCase.match, scope)}), render: (${caseRc}) => {`);
196
+ }
197
+ writer.indent();
198
+ emitNodes(writer, switchCase.children, caseRc, scope, namer);
199
+ writer.dedent();
200
+ writer.line('} },');
201
+ }
202
+ writer.dedent();
203
+ writer.line(']);');
204
+ }
205
+ function emitSlot(writer, node, rcVar, scope, namer) {
206
+ const name = node.name ?? DEFAULT_SLOT_NAME;
207
+ if (node.fallback.length === 0) {
208
+ writer.line(`rt.slot(${rcVar}, ${JSON.stringify(name)});`);
209
+ return;
210
+ }
211
+ const fallbackRc = namer.fresh();
212
+ writer.line(`rt.slot(${rcVar}, ${JSON.stringify(name)}, (${fallbackRc}) => {`);
213
+ writer.indent();
214
+ emitNodes(writer, node.fallback, fallbackRc, scope, namer);
215
+ writer.dedent();
216
+ writer.line('});');
217
+ }
218
+ function assertNever(value) {
219
+ throw new Error(`Unhandled template node: ${JSON.stringify(value)}`);
220
+ }
@@ -0,0 +1,12 @@
1
+ export declare class UnknownHtmlEntityError extends Error {
2
+ constructor(entity: string);
3
+ }
4
+ export declare class InvalidCharacterReferenceError extends Error {
5
+ constructor(reference: string);
6
+ }
7
+ /**
8
+ * Décode les entités d'un fragment de texte ou d'une valeur d'attribut déjà
9
+ * découpés par le parser. Appliqué après le découpage, jamais avant : un `<`
10
+ * décodé trop tôt serait relu comme l'ouverture d'une balise.
11
+ */
12
+ export declare function decodeHtmlEntities(raw: string): string;
@@ -0,0 +1,103 @@
1
+ export class UnknownHtmlEntityError extends Error {
2
+ constructor(entity) {
3
+ super(`unknown HTML entity '${entity}': write the character directly, or use a numeric reference such as 'é'`);
4
+ this.name = 'UnknownHtmlEntityError';
5
+ }
6
+ }
7
+ export class InvalidCharacterReferenceError extends Error {
8
+ constructor(reference) {
9
+ super(`invalid character reference '${reference}': it does not denote a Unicode code point`);
10
+ this.name = 'InvalidCharacterReferenceError';
11
+ }
12
+ }
13
+ /**
14
+ * Entités nommées reconnues. Volontairement une liste courte plutôt que les
15
+ * ~2200 entités HTML5 : elle couvre la typographie courante (française
16
+ * comprise), et toute autre s'écrit soit au caractère, soit en référence
17
+ * numérique — que ce décodeur accepte intégralement.
18
+ */
19
+ const NAMED_ENTITIES = {
20
+ lt: '<',
21
+ gt: '>',
22
+ amp: '&',
23
+ quot: '"',
24
+ apos: "'",
25
+ nbsp: ' ',
26
+ ensp: ' ',
27
+ emsp: ' ',
28
+ thinsp: ' ',
29
+ shy: '­',
30
+ hellip: '…',
31
+ mdash: '—',
32
+ ndash: '–',
33
+ lsquo: '‘',
34
+ rsquo: '’',
35
+ ldquo: '“',
36
+ rdquo: '”',
37
+ laquo: '«',
38
+ raquo: '»',
39
+ bull: '•',
40
+ middot: '·',
41
+ dagger: '†',
42
+ copy: '©',
43
+ reg: '®',
44
+ trade: '™',
45
+ deg: '°',
46
+ plusmn: '±',
47
+ times: '×',
48
+ divide: '÷',
49
+ minus: '−',
50
+ ne: '≠',
51
+ le: '≤',
52
+ ge: '≥',
53
+ frac12: '½',
54
+ frac14: '¼',
55
+ frac34: '¾',
56
+ sup2: '²',
57
+ sup3: '³',
58
+ euro: '€',
59
+ pound: '£',
60
+ yen: '¥',
61
+ cent: '¢',
62
+ sect: '§',
63
+ para: '¶',
64
+ micro: 'µ',
65
+ larr: '←',
66
+ rarr: '→',
67
+ uarr: '↑',
68
+ darr: '↓',
69
+ harr: '↔',
70
+ };
71
+ const ENTITY_PATTERN = /&(#[Xx][0-9A-Fa-f]+|#[0-9]+|[A-Za-z][A-Za-z0-9]*);/g;
72
+ const MAX_CODE_POINT = 0x10ffff;
73
+ const SURROGATE_RANGE_START = 0xd800;
74
+ const SURROGATE_RANGE_END = 0xdfff;
75
+ /**
76
+ * Décode les entités d'un fragment de texte ou d'une valeur d'attribut déjà
77
+ * découpés par le parser. Appliqué après le découpage, jamais avant : un `&lt;`
78
+ * décodé trop tôt serait relu comme l'ouverture d'une balise.
79
+ */
80
+ export function decodeHtmlEntities(raw) {
81
+ if (!raw.includes('&')) {
82
+ return raw;
83
+ }
84
+ return raw.replace(ENTITY_PATTERN, (match, body) => body.startsWith('#') ? decodeCharacterReference(match, body) : decodeNamedEntity(match, body));
85
+ }
86
+ function decodeNamedEntity(match, name) {
87
+ const decoded = NAMED_ENTITIES[name];
88
+ if (decoded === undefined) {
89
+ throw new UnknownHtmlEntityError(match);
90
+ }
91
+ return decoded;
92
+ }
93
+ function decodeCharacterReference(match, body) {
94
+ const isHexadecimal = body[1] === 'x' || body[1] === 'X';
95
+ const digits = body.slice(isHexadecimal ? 2 : 1);
96
+ const codePoint = Number.parseInt(digits, isHexadecimal ? 16 : 10);
97
+ if (Number.isNaN(codePoint) ||
98
+ codePoint > MAX_CODE_POINT ||
99
+ (codePoint >= SURROGATE_RANGE_START && codePoint <= SURROGATE_RANGE_END)) {
100
+ throw new InvalidCharacterReferenceError(match);
101
+ }
102
+ return String.fromCodePoint(codePoint);
103
+ }
@@ -0,0 +1,16 @@
1
+ export declare class ExpressionError extends Error {
2
+ constructor(message: string, expression: string);
3
+ }
4
+ export interface ExpressionScope {
5
+ /** Locals lus comme signaux : `p` devient `p()`. Variables de boucle et `$index`. */
6
+ readonly signalLocals: ReadonlySet<string>;
7
+ /** Locals émis tels quels : `$event` dans un handler, item brut dans `track`. */
8
+ readonly rawLocals: ReadonlySet<string>;
9
+ }
10
+ export declare const EMPTY_SCOPE: ExpressionScope;
11
+ /**
12
+ * Préfixe par `ctx.` chaque identifiant racine d'une expression de template,
13
+ * en respectant accès membres, littéraux, clés d'objet et locals de blocs.
14
+ * Exécuté au build uniquement : le runtime ne voit que des fermetures JS.
15
+ */
16
+ export declare function rewriteExpression(source: string, scope?: ExpressionScope): string;
@@ -0,0 +1,196 @@
1
+ export class ExpressionError extends Error {
2
+ constructor(message, expression) {
3
+ super(`${message} in template expression: ${expression}`);
4
+ this.name = 'ExpressionError';
5
+ }
6
+ }
7
+ export const EMPTY_SCOPE = {
8
+ signalLocals: new Set(),
9
+ rawLocals: new Set(),
10
+ };
11
+ const JS_KEYWORDS = new Set([
12
+ 'true',
13
+ 'false',
14
+ 'null',
15
+ 'undefined',
16
+ 'typeof',
17
+ 'instanceof',
18
+ 'in',
19
+ 'void',
20
+ ]);
21
+ const TEMPLATE_GLOBALS = new Set([
22
+ 'Math',
23
+ 'JSON',
24
+ 'Number',
25
+ 'String',
26
+ 'Boolean',
27
+ 'Array',
28
+ 'Object',
29
+ 'Infinity',
30
+ 'NaN',
31
+ 'parseInt',
32
+ 'parseFloat',
33
+ 'isNaN',
34
+ 'isFinite',
35
+ 'encodeURIComponent',
36
+ 'decodeURIComponent',
37
+ ]);
38
+ const IDENTIFIER_START = /[A-Za-z_$]/;
39
+ const IDENTIFIER_PART = /[A-Za-z0-9_$]/;
40
+ const DIGIT = /[0-9]/;
41
+ /**
42
+ * Préfixe par `ctx.` chaque identifiant racine d'une expression de template,
43
+ * en respectant accès membres, littéraux, clés d'objet et locals de blocs.
44
+ * Exécuté au build uniquement : le runtime ne voit que des fermetures JS.
45
+ */
46
+ export function rewriteExpression(source, scope = EMPTY_SCOPE) {
47
+ return new ExpressionRewriter(source, scope).rewrite();
48
+ }
49
+ class ExpressionRewriter {
50
+ source;
51
+ scope;
52
+ position = 0;
53
+ output = '';
54
+ previousSignificantChar = '';
55
+ openBrackets = [];
56
+ constructor(source, scope) {
57
+ this.source = source;
58
+ this.scope = scope;
59
+ }
60
+ rewrite() {
61
+ while (this.position < this.source.length) {
62
+ const char = this.source[this.position];
63
+ if (char === "'" || char === '"') {
64
+ this.copyStringLiteral(char);
65
+ }
66
+ else if (char === '`') {
67
+ this.copyTemplateLiteral();
68
+ }
69
+ else if (char === '=' && this.source[this.position + 1] === '>') {
70
+ throw new ExpressionError('arrow functions are not supported: move the logic to a computed in logic.ts', this.source);
71
+ }
72
+ else if (DIGIT.test(char)) {
73
+ this.copyNumberLiteral();
74
+ }
75
+ else if (IDENTIFIER_START.test(char)) {
76
+ this.rewriteIdentifier();
77
+ }
78
+ else {
79
+ this.copyChar(char);
80
+ }
81
+ }
82
+ return this.output;
83
+ }
84
+ copyChar(char) {
85
+ this.output += char;
86
+ if (!/\s/.test(char)) {
87
+ this.previousSignificantChar = char;
88
+ }
89
+ if (char === '{' || char === '[' || char === '(') {
90
+ this.openBrackets.push(char);
91
+ }
92
+ else if (char === '}' || char === ']' || char === ')') {
93
+ this.openBrackets.pop();
94
+ }
95
+ this.position += 1;
96
+ }
97
+ copyStringLiteral(quote) {
98
+ const start = this.position;
99
+ this.position += 1;
100
+ while (this.position < this.source.length && this.source[this.position] !== quote) {
101
+ this.position += this.source[this.position] === '\\' ? 2 : 1;
102
+ }
103
+ if (this.position >= this.source.length) {
104
+ throw new ExpressionError('unterminated string literal', this.source);
105
+ }
106
+ this.position += 1;
107
+ this.output += this.source.slice(start, this.position);
108
+ this.previousSignificantChar = quote;
109
+ }
110
+ copyTemplateLiteral() {
111
+ const start = this.position;
112
+ this.position += 1;
113
+ while (this.position < this.source.length && this.source[this.position] !== '`') {
114
+ if (this.source[this.position] === '$' && this.source[this.position + 1] === '{') {
115
+ throw new ExpressionError('template literal interpolation is not supported: compose strings in logic.ts', this.source);
116
+ }
117
+ this.position += this.source[this.position] === '\\' ? 2 : 1;
118
+ }
119
+ if (this.position >= this.source.length) {
120
+ throw new ExpressionError('unterminated template literal', this.source);
121
+ }
122
+ this.position += 1;
123
+ this.output += this.source.slice(start, this.position);
124
+ this.previousSignificantChar = '`';
125
+ }
126
+ copyNumberLiteral() {
127
+ const start = this.position;
128
+ while (this.position < this.source.length &&
129
+ /[0-9a-fA-FxXoObBeE._]/.test(this.source[this.position])) {
130
+ this.position += 1;
131
+ }
132
+ this.output += this.source.slice(start, this.position);
133
+ this.previousSignificantChar = this.source[this.position - 1];
134
+ }
135
+ rewriteIdentifier() {
136
+ const start = this.position;
137
+ while (this.position < this.source.length &&
138
+ IDENTIFIER_PART.test(this.source[this.position])) {
139
+ this.position += 1;
140
+ }
141
+ const name = this.source.slice(start, this.position);
142
+ this.output += this.resolveIdentifier(name);
143
+ this.previousSignificantChar = name[name.length - 1];
144
+ }
145
+ resolveIdentifier(name) {
146
+ if (this.isMemberAccess()) {
147
+ return name;
148
+ }
149
+ if (JS_KEYWORDS.has(name) || TEMPLATE_GLOBALS.has(name)) {
150
+ return name;
151
+ }
152
+ if (this.isObjectKeyPosition()) {
153
+ return this.isShorthandProperty() ? `${name}: ${this.resolveValueIdentifier(name)}` : name;
154
+ }
155
+ return this.resolveValueIdentifier(name);
156
+ }
157
+ resolveValueIdentifier(name) {
158
+ if (this.scope.rawLocals.has(name)) {
159
+ return name;
160
+ }
161
+ if (this.scope.signalLocals.has(name)) {
162
+ return `${name}()`;
163
+ }
164
+ return `ctx.${name}`;
165
+ }
166
+ isMemberAccess() {
167
+ return this.previousSignificantChar === '.';
168
+ }
169
+ isObjectKeyPosition() {
170
+ if (!this.isAtObjectMemberStart()) {
171
+ return false;
172
+ }
173
+ const next = this.nextSignificantChar();
174
+ return next === ':' || this.isShorthandProperty();
175
+ }
176
+ isShorthandProperty() {
177
+ if (!this.isAtObjectMemberStart()) {
178
+ return false;
179
+ }
180
+ const next = this.nextSignificantChar();
181
+ return next === ',' || next === '}';
182
+ }
183
+ isAtObjectMemberStart() {
184
+ if (this.openBrackets[this.openBrackets.length - 1] !== '{') {
185
+ return false;
186
+ }
187
+ return this.previousSignificantChar === '{' || this.previousSignificantChar === ',';
188
+ }
189
+ nextSignificantChar() {
190
+ let lookahead = this.position;
191
+ while (lookahead < this.source.length && /\s/.test(this.source[lookahead])) {
192
+ lookahead += 1;
193
+ }
194
+ return this.source[lookahead] ?? '';
195
+ }
196
+ }
@@ -0,0 +1,10 @@
1
+ import type { TemplateNode } from './ast.js';
2
+ export declare class TemplateParseError extends Error {
3
+ /** Où le parseur a buté, en coordonnées d'éditeur : la première ligne est 1. */
4
+ readonly line: number;
5
+ readonly column: number;
6
+ /** Le motif seul, sans la position que le message répète. */
7
+ readonly reason: string;
8
+ constructor(message: string, line: number, column: number);
9
+ }
10
+ export declare function parseTemplate(source: string): TemplateNode[];