@mun-ui/compiler 0.0.0-stage → 0.2.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 (143) hide show
  1. package/LICENSE +21 -0
  2. package/dist/analysis.d.ts +11 -0
  3. package/dist/analysis.d.ts.map +1 -0
  4. package/dist/analysis.js +80 -0
  5. package/dist/analysis.js.map +1 -0
  6. package/dist/ast.d.ts +121 -0
  7. package/dist/ast.d.ts.map +1 -0
  8. package/dist/ast.js +1017 -0
  9. package/dist/ast.js.map +1 -0
  10. package/dist/builtins.d.ts +47 -0
  11. package/dist/builtins.d.ts.map +1 -0
  12. package/dist/builtins.js +259 -0
  13. package/dist/builtins.js.map +1 -0
  14. package/dist/collection-specialization.d.ts +2 -0
  15. package/dist/collection-specialization.d.ts.map +1 -0
  16. package/dist/collection-specialization.js +475 -0
  17. package/dist/collection-specialization.js.map +1 -0
  18. package/dist/diagnostics.d.ts +12 -0
  19. package/dist/diagnostics.d.ts.map +1 -0
  20. package/dist/diagnostics.js +182 -0
  21. package/dist/diagnostics.js.map +1 -0
  22. package/dist/effect-analysis.d.ts +54 -0
  23. package/dist/effect-analysis.d.ts.map +1 -0
  24. package/dist/effect-analysis.js +318 -0
  25. package/dist/effect-analysis.js.map +1 -0
  26. package/dist/execution-plan.d.ts +63 -0
  27. package/dist/execution-plan.d.ts.map +1 -0
  28. package/dist/execution-plan.js +223 -0
  29. package/dist/execution-plan.js.map +1 -0
  30. package/dist/gpu-island-ir.d.ts +85 -0
  31. package/dist/gpu-island-ir.d.ts.map +1 -0
  32. package/dist/gpu-island-ir.js +159 -0
  33. package/dist/gpu-island-ir.js.map +1 -0
  34. package/dist/gpu-region.d.ts +28 -0
  35. package/dist/gpu-region.d.ts.map +1 -0
  36. package/dist/gpu-region.js +136 -0
  37. package/dist/gpu-region.js.map +1 -0
  38. package/dist/index.d.ts +29 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +56 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/kernel-ir.d.ts +13 -0
  43. package/dist/kernel-ir.d.ts.map +1 -0
  44. package/dist/kernel-ir.js +221 -0
  45. package/dist/kernel-ir.js.map +1 -0
  46. package/dist/language-catalog.d.ts +26 -0
  47. package/dist/language-catalog.d.ts.map +1 -0
  48. package/dist/language-catalog.js +27 -0
  49. package/dist/language-catalog.js.map +1 -0
  50. package/dist/lifecycle.d.ts +8 -0
  51. package/dist/lifecycle.d.ts.map +1 -0
  52. package/dist/lifecycle.js +84 -0
  53. package/dist/lifecycle.js.map +1 -0
  54. package/dist/native-contract.d.ts +27 -0
  55. package/dist/native-contract.d.ts.map +1 -0
  56. package/dist/native-contract.js +163 -0
  57. package/dist/native-contract.js.map +1 -0
  58. package/dist/native-member-contract.d.ts +13 -0
  59. package/dist/native-member-contract.d.ts.map +1 -0
  60. package/dist/native-member-contract.js +10 -0
  61. package/dist/native-member-contract.js.map +1 -0
  62. package/dist/native-values.d.ts +40 -0
  63. package/dist/native-values.d.ts.map +1 -0
  64. package/dist/native-values.js +394 -0
  65. package/dist/native-values.js.map +1 -0
  66. package/dist/observable.d.ts +19 -0
  67. package/dist/observable.d.ts.map +1 -0
  68. package/dist/observable.js +203 -0
  69. package/dist/observable.js.map +1 -0
  70. package/dist/pipeline.d.ts +11 -0
  71. package/dist/pipeline.d.ts.map +1 -0
  72. package/dist/pipeline.js +2183 -0
  73. package/dist/pipeline.js.map +1 -0
  74. package/dist/resident-fusion.d.ts +102 -0
  75. package/dist/resident-fusion.d.ts.map +1 -0
  76. package/dist/resident-fusion.js +423 -0
  77. package/dist/resident-fusion.js.map +1 -0
  78. package/dist/resident-js.d.ts +7 -0
  79. package/dist/resident-js.d.ts.map +1 -0
  80. package/dist/resident-js.js +106 -0
  81. package/dist/resident-js.js.map +1 -0
  82. package/dist/resident-planner.d.ts +58 -0
  83. package/dist/resident-planner.d.ts.map +1 -0
  84. package/dist/resident-planner.js +101 -0
  85. package/dist/resident-planner.js.map +1 -0
  86. package/dist/resident-wasm.d.ts +56 -0
  87. package/dist/resident-wasm.d.ts.map +1 -0
  88. package/dist/resident-wasm.js +867 -0
  89. package/dist/resident-wasm.js.map +1 -0
  90. package/dist/scanner.d.ts +63 -0
  91. package/dist/scanner.d.ts.map +1 -0
  92. package/dist/scanner.js +755 -0
  93. package/dist/scanner.js.map +1 -0
  94. package/dist/semantic.d.ts +100 -0
  95. package/dist/semantic.d.ts.map +1 -0
  96. package/dist/semantic.js +669 -0
  97. package/dist/semantic.js.map +1 -0
  98. package/dist/shorthand.d.ts +16 -0
  99. package/dist/shorthand.d.ts.map +1 -0
  100. package/dist/shorthand.js +225 -0
  101. package/dist/shorthand.js.map +1 -0
  102. package/dist/source-map.d.ts +26 -0
  103. package/dist/source-map.d.ts.map +1 -0
  104. package/dist/source-map.js +228 -0
  105. package/dist/source-map.js.map +1 -0
  106. package/dist/specialization.d.ts +34 -0
  107. package/dist/specialization.d.ts.map +1 -0
  108. package/dist/specialization.js +1977 -0
  109. package/dist/specialization.js.map +1 -0
  110. package/dist/state-specialization.d.ts +3 -0
  111. package/dist/state-specialization.d.ts.map +1 -0
  112. package/dist/state-specialization.js +227 -0
  113. package/dist/state-specialization.js.map +1 -0
  114. package/dist/struct-state.d.ts +32 -0
  115. package/dist/struct-state.d.ts.map +1 -0
  116. package/dist/struct-state.js +170 -0
  117. package/dist/struct-state.js.map +1 -0
  118. package/dist/types.d.ts +70 -0
  119. package/dist/types.d.ts.map +1 -0
  120. package/dist/types.js +2 -0
  121. package/dist/types.js.map +1 -0
  122. package/dist/ui-ir.d.ts +151 -0
  123. package/dist/ui-ir.d.ts.map +1 -0
  124. package/dist/ui-ir.js +2685 -0
  125. package/dist/ui-ir.js.map +1 -0
  126. package/dist/value-types.d.ts +74 -0
  127. package/dist/value-types.d.ts.map +1 -0
  128. package/dist/value-types.js +246 -0
  129. package/dist/value-types.js.map +1 -0
  130. package/dist/vite.d.ts +33 -0
  131. package/dist/vite.d.ts.map +1 -0
  132. package/dist/vite.js +233 -0
  133. package/dist/vite.js.map +1 -0
  134. package/dist/vue-host.d.ts +25 -0
  135. package/dist/vue-host.d.ts.map +1 -0
  136. package/dist/vue-host.js +103 -0
  137. package/dist/vue-host.js.map +1 -0
  138. package/dist/web-analysis.d.ts +7 -0
  139. package/dist/web-analysis.d.ts.map +1 -0
  140. package/dist/web-analysis.js +81 -0
  141. package/dist/web-analysis.js.map +1 -0
  142. package/package.json +29 -3
  143. package/README.md +0 -3
@@ -0,0 +1,755 @@
1
+ // These scanners run over the same source repeatedly during a transform. Keep
2
+ // the small lexical lookup tables module-scoped so hot paths do not allocate a
3
+ // Set for every slash or builder candidate.
4
+ const regexAfterKeywords = new Set([
5
+ "case", "delete", "do", "else", "in", "instanceof", "of", "return", "throw",
6
+ "typeof", "void", "yield", "await",
7
+ ]);
8
+ const rawHtmlAfterExpressionCharacters = ")]}";
9
+ const excludedBuilderNames = new Set(["if", "for", "while", "switch", "catch", "function"]);
10
+ const rawHtmlExpressionKeywords = new Set(["await", "case", "else", "return", "throw", "yield"]);
11
+ function isRawHtmlClosingTag(source, index) {
12
+ if (source[index - 1] !== "<" || !/[A-Za-z]/.test(source[index + 1] ?? ""))
13
+ return false;
14
+ let cursor = index + 2;
15
+ while (/[A-Za-z0-9:._-]/.test(source[cursor] ?? ""))
16
+ cursor += 1;
17
+ while (/\s/.test(source[cursor] ?? ""))
18
+ cursor += 1;
19
+ return source[cursor] === ">";
20
+ }
21
+ function syntaxError(message, offset) {
22
+ const error = new SyntaxError(message);
23
+ error.offset = offset;
24
+ return error;
25
+ }
26
+ function skipQuoted(source, index) {
27
+ const quote = source[index];
28
+ for (let cursor = index + 1; cursor < source.length; cursor += 1) {
29
+ if (source[cursor] === "\\") {
30
+ cursor += 1;
31
+ continue;
32
+ }
33
+ if (source[cursor] === quote)
34
+ return cursor + 1;
35
+ }
36
+ throw syntaxError(`Unclosed ${quote} string in Mün source`, index);
37
+ }
38
+ function skipTemplate(source, index) {
39
+ for (let cursor = index + 1; cursor < source.length; cursor += 1) {
40
+ if (source[cursor] === "\\") {
41
+ cursor += 1;
42
+ continue;
43
+ }
44
+ if (source[cursor] === "`")
45
+ return cursor + 1;
46
+ if (source[cursor] !== "$" || source[cursor + 1] !== "{")
47
+ continue;
48
+ cursor = matching(source, cursor + 1, "{", "}");
49
+ }
50
+ throw syntaxError("Unclosed template literal in Mün source", index);
51
+ }
52
+ function skipString(source, index) {
53
+ return source[index] === "`" ? skipTemplate(source, index) : skipQuoted(source, index);
54
+ }
55
+ function skipComment(source, index) {
56
+ if (source.startsWith("//", index)) {
57
+ const end = source.indexOf("\n", index + 2);
58
+ return end < 0 ? source.length : end;
59
+ }
60
+ const end = source.indexOf("*/", index + 2);
61
+ if (end < 0)
62
+ throw syntaxError("Unclosed block comment in Mün source", index);
63
+ return end + 2;
64
+ }
65
+ function regexCanStart(source, index) {
66
+ // A raw HTML closing tag (`</span>`) is encountered by several lightweight
67
+ // scanners that do not run the full HTML parser first. It looks like a
68
+ // regular expression after `<`, so exclude the exact closing-tag shape
69
+ // before applying JavaScript's slash heuristic.
70
+ if (isRawHtmlClosingTag(source, index))
71
+ return false;
72
+ for (let cursor = index - 1; cursor >= 0; cursor -= 1) {
73
+ if (/\s/.test(source[cursor]))
74
+ continue;
75
+ if ("([{=,:;!?&|+-*%^~<>".includes(source[cursor]))
76
+ return true;
77
+ if (/[A-Za-z_$]/.test(source[cursor])) {
78
+ const end = cursor + 1;
79
+ while (cursor >= 0 && /[A-Za-z0-9_$]/.test(source[cursor]))
80
+ cursor -= 1;
81
+ const word = source.slice(cursor + 1, end);
82
+ return regexAfterKeywords.has(word);
83
+ }
84
+ return false;
85
+ }
86
+ return true;
87
+ }
88
+ function skipRegex(source, index) {
89
+ let inClass = false;
90
+ for (let cursor = index + 1; cursor < source.length; cursor += 1) {
91
+ if (source[cursor] === "\\") {
92
+ cursor += 1;
93
+ continue;
94
+ }
95
+ if (source[cursor] === "[")
96
+ inClass = true;
97
+ if (source[cursor] === "]")
98
+ inClass = false;
99
+ if (source[cursor] === "/" && !inClass) {
100
+ cursor += 1;
101
+ while (/[A-Za-z]/.test(source[cursor] ?? ""))
102
+ cursor += 1;
103
+ return cursor;
104
+ }
105
+ if (source[cursor] === "\n" || source[cursor] === "\r") {
106
+ throw syntaxError("Unclosed regular expression in Mün source", index);
107
+ }
108
+ }
109
+ throw syntaxError("Unclosed regular expression in Mün source", index);
110
+ }
111
+ function skipTrivia(source, index) {
112
+ let cursor = index;
113
+ while (cursor < source.length) {
114
+ if (/\s/.test(source[cursor])) {
115
+ cursor += 1;
116
+ continue;
117
+ }
118
+ if (source.startsWith("//", cursor) || source.startsWith("/*", cursor)) {
119
+ cursor = skipComment(source, cursor);
120
+ continue;
121
+ }
122
+ break;
123
+ }
124
+ return cursor;
125
+ }
126
+ function matching(source, open, left, right) {
127
+ let depth = 0;
128
+ let steps = 0;
129
+ for (let cursor = open; cursor < source.length; cursor += 1) {
130
+ if (++steps > source.length + 1)
131
+ throw syntaxError(`Unable to scan ${left} block in Mün source`, open);
132
+ const character = source[cursor];
133
+ if (character === "\"" || character === "'" || character === "`") {
134
+ cursor = skipString(source, cursor) - 1;
135
+ continue;
136
+ }
137
+ if (character === "/" && (source[cursor + 1] === "/" || source[cursor + 1] === "*")) {
138
+ cursor = skipComment(source, cursor) - 1;
139
+ continue;
140
+ }
141
+ if (character === "/" && regexCanStart(source, cursor)) {
142
+ cursor = skipRegex(source, cursor) - 1;
143
+ continue;
144
+ }
145
+ if (character === left)
146
+ depth += 1;
147
+ if (character === right) {
148
+ depth -= 1;
149
+ if (depth === 0)
150
+ return cursor;
151
+ }
152
+ }
153
+ throw syntaxError(`Unclosed ${left} block in Mün source`, open);
154
+ }
155
+ const identifierPattern = /[A-Za-z_$][A-Za-z0-9_$]*/y;
156
+ const tagNamePattern = /[A-Za-z][A-Za-z0-9:._-]*/y;
157
+ function tagNameAt(source, start) {
158
+ tagNamePattern.lastIndex = start;
159
+ return tagNamePattern.exec(source)?.[0];
160
+ }
161
+ function identifierAt(source, start) {
162
+ identifierPattern.lastIndex = start;
163
+ const match = identifierPattern.exec(source);
164
+ return match ? { name: match[0], end: start + match[0].length } : undefined;
165
+ }
166
+ /**
167
+ * A less-than token is only a raw HTML opener in an expression-start
168
+ * position. Keeping this decision here prevents generic calls and ordinary
169
+ * comparisons from leaking into the HTML parser.
170
+ */
171
+ function isRawHtmlCandidate(source, start) {
172
+ if (source[start] !== "<" || source[start + 1] === "/" || source[start + 1] === "!")
173
+ return false;
174
+ if (!/^[A-Za-z]/.test(source[start + 1] ?? ""))
175
+ return false;
176
+ // `<T>(value)` and `<T extends U>(value)` are TypeScript generic calls or
177
+ // assertions. A real opening element continues with attributes/text or a
178
+ // closing tag, not an immediately following call parenthesis.
179
+ const possibleGenericClose = source.indexOf(">", start + 1);
180
+ if (possibleGenericClose >= 0) {
181
+ let afterClose = possibleGenericClose + 1;
182
+ while (afterClose < source.length && /\s/.test(source[afterClose]))
183
+ afterClose += 1;
184
+ if (source[afterClose] === "(")
185
+ return false;
186
+ const tagName = tagNameAt(source, start + 1);
187
+ const hasMatchingClosingTag = tagName ? source.indexOf(`</${tagName}`, possibleGenericClose + 1) !== -1 : false;
188
+ // TypeScript's angle-bracket assertion `<Foo>value` is still valid in
189
+ // `.ts` files. Prefer that interpretation for an uppercase type name
190
+ // when no matching closing tag exists. Actual `<Foo>...</Foo>` raw HTML
191
+ // remains unambiguous.
192
+ if (tagName && /^[A-Z]/.test(tagName)
193
+ && !hasMatchingClosingTag
194
+ && /[A-Za-z_$0-9('"`[!+~-]/.test(source[afterClose] ?? ""))
195
+ return false;
196
+ }
197
+ let cursor = start - 1;
198
+ while (cursor >= 0 && /\s/.test(source[cursor]))
199
+ cursor -= 1;
200
+ if (cursor < 0)
201
+ return true;
202
+ const startsNewLine = source.lastIndexOf("\n", start - 1) > cursor;
203
+ const openingName = tagNameAt(source, start + 1);
204
+ const openingClose = source.indexOf(">", start + 1);
205
+ if (startsNewLine && openingName && openingClose >= 0
206
+ && source.indexOf(`</${openingName}`, openingClose + 1) !== -1)
207
+ return true;
208
+ // A tag at the beginning of a new statement may follow a completed call,
209
+ // array, or object expression on the previous line.
210
+ if (startsNewLine && rawHtmlAfterExpressionCharacters.includes(source[cursor]))
211
+ return true;
212
+ if ("([{=,:;!?&|+-*%^~;".includes(source[cursor]))
213
+ return true;
214
+ if (!/[A-Za-z0-9_$.)\]]/.test(source[cursor]))
215
+ return true;
216
+ const end = cursor + 1;
217
+ while (cursor >= 0 && /[A-Za-z0-9_$]/.test(source[cursor]))
218
+ cursor -= 1;
219
+ const word = source.slice(cursor + 1, end);
220
+ return rawHtmlExpressionKeywords.has(word);
221
+ }
222
+ export function previousSignificantCharacter(source, index) {
223
+ for (let cursor = index - 1; cursor >= 0; cursor -= 1) {
224
+ if (!/\s/.test(source[cursor]))
225
+ return source[cursor];
226
+ }
227
+ return undefined;
228
+ }
229
+ /**
230
+ * Read only the immediately preceding identifier. Callers use this instead
231
+ * of materializing `source.slice(0, index).trimEnd()` for every candidate in
232
+ * a source-wide scan. The result is intentionally lexical and does not skip
233
+ * comments; it matches the old prefix check while keeping the work bounded
234
+ * by the size of one token.
235
+ */
236
+ export function previousWord(source, index) {
237
+ let cursor = index - 1;
238
+ while (cursor >= 0 && /\s/.test(source[cursor]))
239
+ cursor -= 1;
240
+ const end = cursor + 1;
241
+ while (cursor >= 0 && /[A-Za-z0-9_$]/.test(source[cursor]))
242
+ cursor -= 1;
243
+ return end > cursor + 1 ? source.slice(cursor + 1, end) : undefined;
244
+ }
245
+ function braceContext(source, index) {
246
+ const prefix = source.slice(Math.max(0, index - 160), index).trimEnd();
247
+ if (/\b(?:class|interface|enum|namespace)\s+[A-Za-z_$][A-Za-z0-9_$]*(?:\s+extends[^{]+)?$/.test(prefix))
248
+ return "class";
249
+ const previous = previousSignificantCharacter(source, index);
250
+ if (previous && "=(:,[".includes(previous))
251
+ return "object";
252
+ if (/\b(?:return|yield)\s*$/.test(prefix))
253
+ return "object";
254
+ if (/\btype\s+[A-Za-z_$][A-Za-z0-9_$]*(?:<[^>]*>)?\s*=\s*$/.test(prefix))
255
+ return "object";
256
+ return "block";
257
+ }
258
+ const bareClosureDeclarationWords = new Set(["class", "struct", "interface", "enum", "namespace", "extends", "implements", "type", "some", "any", "new", "in", "of", "else", "do", "try", "finally"]);
259
+ /**
260
+ * SwiftUI's `VStack { ... }` omits the empty argument list. Accept that form
261
+ * only for an uppercase name in expression position, so declarations
262
+ * (`class Model {`), type annotations (`var x: Foo {`) and `some View {`
263
+ * keep their meaning.
264
+ */
265
+ function isBareTrailingClosure(source, start, name) {
266
+ if (!/^[A-Z]/.test(name))
267
+ return false;
268
+ const previous = previousSignificantCharacter(source, start);
269
+ if (previous === ">" && source[source.lastIndexOf(">", start) - 1] !== "=")
270
+ return false;
271
+ if (previous === ":" || previous === "." || previous === "|" || previous === "&")
272
+ return false;
273
+ const word = previousWord(source, start);
274
+ return word === undefined || !bareClosureDeclarationWords.has(word) || previous !== word.at(-1);
275
+ }
276
+ function findBuilder(source, from = 0, uppercaseOnly = false) {
277
+ // Keep scanning all identifiers so lowercase user-defined builder helpers
278
+ // remain supported. lowerBuilder preserves a call-shaped block that the AST
279
+ // does not recognize as a closure instead of recursively lowering it.
280
+ const braces = [];
281
+ let parenDepth = 0;
282
+ let bracketDepth = 0;
283
+ let steps = 0;
284
+ for (let cursor = 0; cursor < source.length; cursor += 1) {
285
+ if (++steps > source.length + 1)
286
+ throw syntaxError("Unable to scan builder expressions in Mün source", from);
287
+ const character = source[cursor];
288
+ if (character === "\"" || character === "'" || character === "`") {
289
+ cursor = skipString(source, cursor) - 1;
290
+ continue;
291
+ }
292
+ if (character === "/" && (source[cursor + 1] === "/" || source[cursor + 1] === "*")) {
293
+ cursor = skipComment(source, cursor) - 1;
294
+ continue;
295
+ }
296
+ if (character === "/" && regexCanStart(source, cursor)) {
297
+ cursor = skipRegex(source, cursor) - 1;
298
+ continue;
299
+ }
300
+ if (character === "(") {
301
+ parenDepth += 1;
302
+ continue;
303
+ }
304
+ if (character === ")") {
305
+ parenDepth = Math.max(0, parenDepth - 1);
306
+ continue;
307
+ }
308
+ if (character === "[") {
309
+ bracketDepth += 1;
310
+ continue;
311
+ }
312
+ if (character === "]") {
313
+ bracketDepth = Math.max(0, bracketDepth - 1);
314
+ continue;
315
+ }
316
+ if (character === "{") {
317
+ braces.push({ context: braceContext(source, cursor), parenDepth, bracketDepth });
318
+ continue;
319
+ }
320
+ if (character === "}") {
321
+ braces.pop();
322
+ continue;
323
+ }
324
+ if (cursor < from)
325
+ continue;
326
+ const identifier = identifierAt(source, cursor);
327
+ if (!identifier)
328
+ continue;
329
+ const start = cursor;
330
+ cursor = identifier.end - 1;
331
+ if (excludedBuilderNames.has(identifier.name))
332
+ continue;
333
+ if (uppercaseOnly && !/^[A-Z]/.test(identifier.name))
334
+ continue;
335
+ const previous = previousSignificantCharacter(source, start);
336
+ const previousWordValue = previousWord(source, start);
337
+ const wordBeforeStar = previous === "*" ? previousWord(source, start - 2) : undefined;
338
+ if (previousWordValue === "function" || wordBeforeStar === "function")
339
+ continue;
340
+ const open = skipTrivia(source, identifier.end);
341
+ let close;
342
+ if (source[open] === "(")
343
+ close = matching(source, open, "(", ")");
344
+ else if (source[open] === "{" && isBareTrailingClosure(source, start, identifier.name))
345
+ close = open - 1;
346
+ else
347
+ continue;
348
+ const brace = skipTrivia(source, close + 1);
349
+ if (source[brace] !== "{")
350
+ continue;
351
+ // A call-shaped token at member position inside a class/object is a
352
+ // JavaScript/TypeScript method declaration, not Mun trailing-closure
353
+ // syntax. Property initializers (`field = Card() { ... }`) remain valid
354
+ // Mun expressions because their preceding token is `=`/`:`.
355
+ const frame = braces.at(-1);
356
+ const container = frame?.context;
357
+ const atMemberLevel = frame !== undefined
358
+ && parenDepth === frame.parenDepth
359
+ && bracketDepth === frame.bracketDepth;
360
+ const before = previousSignificantCharacter(source, start);
361
+ const memberPrefix = source.slice(Math.max(0, start - 120), start);
362
+ const followsMemberModifier = /\b(?:public|private|protected|static|abstract|override|async|get|set|readonly|declare|accessor)\s+$/.test(memberPrefix);
363
+ if (atMemberLevel && (container === "class" || container === "object")
364
+ && (before === undefined || "{,;}*".includes(before) || followsMemberModifier))
365
+ continue;
366
+ const braceClose = matching(source, brace, "{", "}");
367
+ return {
368
+ start,
369
+ open,
370
+ close,
371
+ brace,
372
+ end: braceClose + 1,
373
+ name: identifier.name,
374
+ argumentSource: source.slice(open + 1, close),
375
+ bodySource: source.slice(brace + 1, braceClose),
376
+ };
377
+ }
378
+ return undefined;
379
+ }
380
+ function skipHtmlTrivia(source, index) {
381
+ let cursor = index;
382
+ while (cursor < source.length && /\s/.test(source[cursor]))
383
+ cursor += 1;
384
+ return cursor;
385
+ }
386
+ function htmlNameAt(source, start) {
387
+ const match = /^[A-Za-z][A-Za-z0-9:._-]*/.exec(source.slice(start));
388
+ return match ? { name: match[0], end: start + match[0].length } : undefined;
389
+ }
390
+ function htmlAttributeNameAt(source, start) {
391
+ const match = /^[^\s=/>]+/.exec(source.slice(start));
392
+ return match ? { name: match[0], end: start + match[0].length } : undefined;
393
+ }
394
+ const identityExpression = source => source;
395
+ function decodeHtmlEntities(value) {
396
+ const named = {
397
+ amp: "&",
398
+ apos: "'",
399
+ gt: ">",
400
+ lt: "<",
401
+ quot: '"',
402
+ };
403
+ return value.replace(/&(#(?:x[0-9A-Fa-f]+|[0-9]+)|[A-Za-z][A-Za-z0-9]+);/g, (match, entity) => {
404
+ if (entity[0] === "#") {
405
+ const hexadecimal = entity[1]?.toLowerCase() === "x";
406
+ const digits = entity.slice(hexadecimal ? 2 : 1);
407
+ const codePoint = Number.parseInt(digits, hexadecimal ? 16 : 10);
408
+ if (!Number.isFinite(codePoint) || codePoint < 0 || codePoint > 0x10ffff)
409
+ return match;
410
+ try {
411
+ return String.fromCodePoint(codePoint);
412
+ }
413
+ catch {
414
+ return match;
415
+ }
416
+ }
417
+ return named[entity] ?? match;
418
+ });
419
+ }
420
+ function htmlAttributes(source, baseOffset = 0, lower = identityExpression) {
421
+ const attributes = [];
422
+ let cursor = 0;
423
+ while (cursor < source.length) {
424
+ cursor = skipHtmlTrivia(source, cursor);
425
+ if (cursor >= source.length)
426
+ break;
427
+ if (source[cursor] === "{") {
428
+ const end = matching(source, cursor, "{", "}");
429
+ const expression = source.slice(cursor + 1, end).trim();
430
+ if (!expression.startsWith("...") || expression.slice(3).trim().length === 0) {
431
+ throw syntaxError("Raw HTML attribute expressions must use {...value}", baseOffset + cursor);
432
+ }
433
+ attributes.push(`...(${lower(expression.slice(3).trim())})`);
434
+ cursor = end + 1;
435
+ continue;
436
+ }
437
+ const name = htmlAttributeNameAt(source, cursor);
438
+ if (!name)
439
+ throw syntaxError("Invalid raw HTML attribute", baseOffset + cursor);
440
+ cursor = skipHtmlTrivia(source, name.end);
441
+ let value = "true";
442
+ if (source[cursor] === "=") {
443
+ cursor = skipHtmlTrivia(source, cursor + 1);
444
+ if (source[cursor] === "\"" || source[cursor] === "'") {
445
+ const end = skipQuoted(source, cursor);
446
+ value = JSON.stringify(decodeHtmlEntities(source.slice(cursor + 1, end - 1)));
447
+ cursor = end;
448
+ }
449
+ else if (source[cursor] === "{") {
450
+ const end = matching(source, cursor, "{", "}");
451
+ value = lower(source.slice(cursor + 1, end));
452
+ cursor = end + 1;
453
+ }
454
+ else {
455
+ const match = /^[^\s/>]+/.exec(source.slice(cursor));
456
+ if (!match)
457
+ throw syntaxError(`Invalid value for raw HTML attribute ${name.name}`, baseOffset + cursor);
458
+ value = JSON.stringify(decodeHtmlEntities(match[0]));
459
+ cursor += match[0].length;
460
+ }
461
+ }
462
+ attributes.push(`${JSON.stringify(name.name)}: ${value}`);
463
+ }
464
+ return attributes.length === 0 ? "null" : `{ ${attributes.join(", ")} }`;
465
+ }
466
+ const voidHtmlElements = new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
467
+ function rawHtmlAt(source, start, lower = identityExpression, nested = false) {
468
+ if (!nested && !isRawHtmlCandidate(source, start))
469
+ return undefined;
470
+ const openingName = htmlNameAt(source, start + 1);
471
+ if (!openingName)
472
+ return undefined;
473
+ let cursor = openingName.end;
474
+ let braceDepth = 0;
475
+ let quote;
476
+ let close = -1;
477
+ for (; cursor < source.length; cursor += 1) {
478
+ const character = source[cursor];
479
+ if (quote) {
480
+ if (character === "\\") {
481
+ cursor += 1;
482
+ continue;
483
+ }
484
+ if (character === quote)
485
+ quote = undefined;
486
+ continue;
487
+ }
488
+ if (character === "\"" || character === "'") {
489
+ quote = character;
490
+ continue;
491
+ }
492
+ if (character === "{") {
493
+ braceDepth += 1;
494
+ continue;
495
+ }
496
+ if (character === "}") {
497
+ braceDepth -= 1;
498
+ continue;
499
+ }
500
+ if (character === ">" && braceDepth === 0) {
501
+ close = cursor;
502
+ break;
503
+ }
504
+ }
505
+ if (close < 0 || quote || braceDepth !== 0)
506
+ return undefined;
507
+ const opening = source.slice(openingName.end, close);
508
+ const trimmedOpening = opening.trimEnd();
509
+ const selfClosing = trimmedOpening.endsWith("/");
510
+ const attributeSource = selfClosing ? trimmedOpening.slice(0, -1) : opening;
511
+ const attributes = htmlAttributes(attributeSource, openingName.end, lower);
512
+ if (selfClosing || voidHtmlElements.has(openingName.name.toLowerCase()))
513
+ return { start, end: close + 1, code: `Element(${JSON.stringify(openingName.name)}, ${attributes})` };
514
+ const children = [];
515
+ cursor = close + 1;
516
+ while (cursor < source.length) {
517
+ if (source.startsWith("<!--", cursor)) {
518
+ const commentEnd = source.indexOf("-->", cursor + 4);
519
+ if (commentEnd < 0)
520
+ throw syntaxError("Unclosed raw HTML comment in Mün source", cursor);
521
+ cursor = commentEnd + 3;
522
+ continue;
523
+ }
524
+ if (source[cursor] === "<" && source[cursor + 1] === "/") {
525
+ const closing = /^<\/([A-Za-z][A-Za-z0-9:._-]*)([^>]*)>/.exec(source.slice(cursor));
526
+ if (!closing)
527
+ throw syntaxError("Unclosed raw HTML closing tag in Mün source", cursor);
528
+ if (closing[1] !== openingName.name)
529
+ throw syntaxError(`Mismatched raw HTML closing tag </${closing[1]}>; expected </${openingName.name}>`, cursor);
530
+ if (closing[2].trim().length > 0)
531
+ throw syntaxError("Raw HTML closing tags cannot have attributes", cursor);
532
+ const end = cursor + closing[0].length - 1;
533
+ return {
534
+ start,
535
+ end: end + 1,
536
+ code: `Element(${JSON.stringify(openingName.name)}, ${attributes}${children.length ? `, ${children.join(", ")}` : ""})`,
537
+ };
538
+ }
539
+ if (source[cursor] === "<") {
540
+ const nestedHtml = rawHtmlAt(source, cursor, lower, true);
541
+ if (!nestedHtml)
542
+ return undefined;
543
+ children.push(nestedHtml.code);
544
+ cursor = nestedHtml.end;
545
+ continue;
546
+ }
547
+ if (source[cursor] === "{") {
548
+ const end = matching(source, cursor, "{", "}");
549
+ const expression = source.slice(cursor + 1, end).trim();
550
+ if (expression)
551
+ children.push(lower(expression));
552
+ cursor = end + 1;
553
+ continue;
554
+ }
555
+ const nextTag = source.indexOf("<", cursor);
556
+ const nextExpression = source.indexOf("{", cursor);
557
+ const end = [nextTag, nextExpression].filter(value => value >= 0).sort((left, right) => left - right)[0] ?? source.length;
558
+ const text = source.slice(cursor, end);
559
+ if (text.length > 0)
560
+ children.push(JSON.stringify(decodeHtmlEntities(text)));
561
+ cursor = end;
562
+ }
563
+ return undefined;
564
+ }
565
+ function findRawHtml(source, from = 0, lower = identityExpression) {
566
+ for (let cursor = from; cursor < source.length; cursor += 1) {
567
+ if (source[cursor] === "\"" || source[cursor] === "'" || source[cursor] === "`") {
568
+ cursor = skipString(source, cursor) - 1;
569
+ continue;
570
+ }
571
+ if (source[cursor] === "/" && (source[cursor + 1] === "/" || source[cursor + 1] === "*")) {
572
+ cursor = skipComment(source, cursor) - 1;
573
+ continue;
574
+ }
575
+ if (source[cursor] === "/" && regexCanStart(source, cursor)) {
576
+ cursor = skipRegex(source, cursor) - 1;
577
+ continue;
578
+ }
579
+ if (source[cursor] !== "<")
580
+ continue;
581
+ const call = rawHtmlAt(source, cursor, lower);
582
+ if (call)
583
+ return call;
584
+ }
585
+ return undefined;
586
+ }
587
+ function validateRawHtmlSyntax(source) {
588
+ for (let cursor = 0; cursor < source.length; cursor += 1) {
589
+ if (source[cursor] === "\"" || source[cursor] === "'" || source[cursor] === "`") {
590
+ cursor = skipString(source, cursor) - 1;
591
+ continue;
592
+ }
593
+ if (source[cursor] === "/" && (source[cursor + 1] === "/" || source[cursor + 1] === "*")) {
594
+ cursor = skipComment(source, cursor) - 1;
595
+ continue;
596
+ }
597
+ if (source[cursor] === "/" && regexCanStart(source, cursor)) {
598
+ cursor = skipRegex(source, cursor) - 1;
599
+ continue;
600
+ }
601
+ if (!isRawHtmlCandidate(source, cursor))
602
+ continue;
603
+ const html = rawHtmlAt(source, cursor);
604
+ if (html) {
605
+ cursor = html.end - 1;
606
+ continue;
607
+ }
608
+ throw syntaxError("Unclosed raw HTML element in Mün source", cursor);
609
+ }
610
+ }
611
+ function splitTopLevel(source, separator = ",") {
612
+ const parts = [];
613
+ let start = 0;
614
+ let parens = 0;
615
+ let brackets = 0;
616
+ let braces = 0;
617
+ for (let cursor = 0; cursor < source.length; cursor += 1) {
618
+ const character = source[cursor];
619
+ if (character === "\"" || character === "'" || character === "`") {
620
+ cursor = skipString(source, cursor) - 1;
621
+ continue;
622
+ }
623
+ if (character === "/" && (source[cursor + 1] === "/" || source[cursor + 1] === "*")) {
624
+ cursor = skipComment(source, cursor) - 1;
625
+ continue;
626
+ }
627
+ if (character === "/" && regexCanStart(source, cursor)) {
628
+ cursor = skipRegex(source, cursor) - 1;
629
+ continue;
630
+ }
631
+ if (character === "<") {
632
+ const html = rawHtmlAt(source, cursor);
633
+ if (html) {
634
+ cursor = html.end - 1;
635
+ continue;
636
+ }
637
+ }
638
+ if (character === "(")
639
+ parens += 1;
640
+ else if (character === ")")
641
+ parens -= 1;
642
+ else if (character === "[")
643
+ brackets += 1;
644
+ else if (character === "]")
645
+ brackets -= 1;
646
+ else if (character === "{")
647
+ braces += 1;
648
+ else if (character === "}")
649
+ braces -= 1;
650
+ else if (character === separator && parens === 0 && brackets === 0 && braces === 0) {
651
+ parts.push(source.slice(start, cursor).trim());
652
+ start = cursor + 1;
653
+ }
654
+ }
655
+ const tail = source.slice(start).trim();
656
+ if (tail)
657
+ parts.push(tail);
658
+ return parts;
659
+ }
660
+ function splitStatements(source) {
661
+ const parts = [];
662
+ let start = 0;
663
+ let parens = 0;
664
+ let brackets = 0;
665
+ let braces = 0;
666
+ for (let cursor = 0; cursor < source.length; cursor += 1) {
667
+ const character = source[cursor];
668
+ if (character === "\"" || character === "'" || character === "`") {
669
+ cursor = skipString(source, cursor) - 1;
670
+ continue;
671
+ }
672
+ if (character === "/" && (source[cursor + 1] === "/" || source[cursor + 1] === "*")) {
673
+ cursor = skipComment(source, cursor) - 1;
674
+ continue;
675
+ }
676
+ if (character === "/" && regexCanStart(source, cursor)) {
677
+ cursor = skipRegex(source, cursor) - 1;
678
+ continue;
679
+ }
680
+ if (character === "<") {
681
+ const html = rawHtmlAt(source, cursor);
682
+ if (html) {
683
+ cursor = html.end - 1;
684
+ continue;
685
+ }
686
+ }
687
+ if (character === "(")
688
+ parens += 1;
689
+ else if (character === ")")
690
+ parens -= 1;
691
+ else if (character === "[")
692
+ brackets += 1;
693
+ else if (character === "]")
694
+ brackets -= 1;
695
+ else if (character === "{")
696
+ braces += 1;
697
+ else if (character === "}")
698
+ braces -= 1;
699
+ const boundary = character === ";" || (character === "\n" && parens === 0 && brackets === 0 && braces === 0);
700
+ if (boundary && parens === 0 && brackets === 0 && braces === 0) {
701
+ const part = source.slice(start, cursor).trim();
702
+ if (part)
703
+ parts.push(part);
704
+ start = cursor + 1;
705
+ }
706
+ }
707
+ const tail = source.slice(start).trim();
708
+ if (tail)
709
+ parts.push(tail);
710
+ return parts;
711
+ }
712
+ function topLevelColon(source) {
713
+ let parens = 0;
714
+ let brackets = 0;
715
+ let braces = 0;
716
+ let ternary = 0;
717
+ for (let cursor = 0; cursor < source.length; cursor += 1) {
718
+ const character = source[cursor];
719
+ if (character === "\"" || character === "'" || character === "`") {
720
+ cursor = skipString(source, cursor) - 1;
721
+ continue;
722
+ }
723
+ if (character === "/" && (source[cursor + 1] === "/" || source[cursor + 1] === "*")) {
724
+ cursor = skipComment(source, cursor) - 1;
725
+ continue;
726
+ }
727
+ if (character === "/" && regexCanStart(source, cursor)) {
728
+ cursor = skipRegex(source, cursor) - 1;
729
+ continue;
730
+ }
731
+ if (character === "(")
732
+ parens += 1;
733
+ else if (character === ")")
734
+ parens -= 1;
735
+ else if (character === "[")
736
+ brackets += 1;
737
+ else if (character === "]")
738
+ brackets -= 1;
739
+ else if (character === "{")
740
+ braces += 1;
741
+ else if (character === "}")
742
+ braces -= 1;
743
+ else if (parens === 0 && brackets === 0 && braces === 0 && character === "?" && source[cursor + 1] !== ".")
744
+ ternary += 1;
745
+ else if (character === ":" && parens === 0 && brackets === 0 && braces === 0) {
746
+ if (ternary > 0)
747
+ ternary -= 1;
748
+ else
749
+ return cursor;
750
+ }
751
+ }
752
+ return -1;
753
+ }
754
+ export { syntaxError, skipString, skipComment, regexCanStart, skipRegex, skipTrivia, matching, identifierAt, isRawHtmlCandidate, findBuilder, skipHtmlTrivia, htmlNameAt, htmlAttributeNameAt, htmlAttributes, rawHtmlAt, findRawHtml, validateRawHtmlSyntax, splitTopLevel, splitStatements, topLevelColon, };
755
+ //# sourceMappingURL=scanner.js.map