what-compiler 0.14.0 → 0.15.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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +181 -2
  3. package/babel.d.ts +78 -2
  4. package/dist/babel/auto-selector.min.js +94 -0
  5. package/dist/babel/common.min.js +2053 -0
  6. package/dist/babel/dev-metadata.min.js +106 -0
  7. package/dist/babel/dom.min.js +1669 -0
  8. package/dist/babel/jsx-root.min.js +13 -0
  9. package/dist/babel/lists.min.js +492 -0
  10. package/dist/babel/nesting.min.js +328 -0
  11. package/dist/babel/reactivity.min.js +1218 -0
  12. package/dist/babel/server-actions.min.js +85 -0
  13. package/dist/babel/ssr.min.js +496 -0
  14. package/dist/babel/types.min.js +9 -0
  15. package/dist/babel-plugin.min.js +101 -1
  16. package/dist/file-router.min.js +368 -12
  17. package/dist/framework-files.min.js +62 -0
  18. package/dist/hot.min.js +315 -0
  19. package/dist/index.min.js +13 -414
  20. package/dist/release.min.js +78 -0
  21. package/dist/runtime.min.js +9 -1
  22. package/dist/tables/import-changes.min.js +272 -0
  23. package/dist/tables/markup-rules.min.js +213 -0
  24. package/dist/vite-plugin.min.js +432 -399
  25. package/file-router.d.ts +3 -1
  26. package/index.d.ts +1 -1
  27. package/package.json +11 -2
  28. package/runtime.d.ts +2 -1
  29. package/src/babel/auto-selector.js +248 -0
  30. package/src/babel/common.js +3800 -0
  31. package/src/babel/dev-metadata.js +167 -0
  32. package/src/babel/dom.js +3386 -0
  33. package/src/babel/jsx-root.js +27 -0
  34. package/src/babel/lists.js +704 -0
  35. package/src/babel/nesting.js +260 -0
  36. package/src/babel/reactivity.js +1998 -0
  37. package/src/babel/server-actions.js +144 -0
  38. package/src/babel/ssr.js +870 -0
  39. package/src/babel/types.js +10 -0
  40. package/src/babel-plugin.js +185 -3598
  41. package/src/file-router.js +58 -38
  42. package/src/framework-files.js +106 -0
  43. package/src/hot.js +523 -0
  44. package/src/release.js +127 -0
  45. package/src/runtime.js +7 -7
  46. package/src/tables/import-changes.js +157 -0
  47. package/src/tables/markup-rules.js +388 -0
  48. package/src/vite-plugin.js +460 -175
  49. package/vite.d.ts +47 -3
  50. package/src/error-overlay.js +0 -428
@@ -0,0 +1,328 @@
1
+ // src/babel/nesting.js
2
+ import { VOID_ELEMENTS as m } from "../tables/markup-rules.min.js";
3
+ import { t as l } from "./types.min.js";
4
+ import { codedCompileError as S, isComponentElement as E, normalizeJsxText as y } from "./common.min.js";
5
+ var L = /* @__PURE__ */ new Set([
6
+ "address",
7
+ "article",
8
+ "aside",
9
+ "blockquote",
10
+ "center",
11
+ "details",
12
+ "dialog",
13
+ "dir",
14
+ "div",
15
+ "dl",
16
+ "fieldset",
17
+ "figcaption",
18
+ "figure",
19
+ "footer",
20
+ "form",
21
+ "h1",
22
+ "h2",
23
+ "h3",
24
+ "h4",
25
+ "h5",
26
+ "h6",
27
+ "header",
28
+ "hgroup",
29
+ "hr",
30
+ "listing",
31
+ "main",
32
+ "menu",
33
+ "nav",
34
+ "ol",
35
+ "p",
36
+ "plaintext",
37
+ "pre",
38
+ "search",
39
+ "section",
40
+ "summary",
41
+ "table",
42
+ "ul",
43
+ "xmp"
44
+ ]), b = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]), f = /* @__PURE__ */ new Set(["applet", "caption", "html", "table", "td", "th", "marquee", "object", "template"]), T = /* @__PURE__ */ new Set([
45
+ "applet",
46
+ "area",
47
+ "article",
48
+ "aside",
49
+ "base",
50
+ "basefont",
51
+ "bgsound",
52
+ "blockquote",
53
+ "body",
54
+ "br",
55
+ "button",
56
+ "caption",
57
+ "center",
58
+ "col",
59
+ "colgroup",
60
+ "dd",
61
+ "details",
62
+ "dir",
63
+ "dl",
64
+ "dt",
65
+ "embed",
66
+ "fieldset",
67
+ "figcaption",
68
+ "figure",
69
+ "footer",
70
+ "form",
71
+ "frame",
72
+ "frameset",
73
+ "h1",
74
+ "h2",
75
+ "h3",
76
+ "h4",
77
+ "h5",
78
+ "h6",
79
+ "head",
80
+ "header",
81
+ "hgroup",
82
+ "hr",
83
+ "html",
84
+ "iframe",
85
+ "img",
86
+ "input",
87
+ "keygen",
88
+ "li",
89
+ "link",
90
+ "listing",
91
+ "main",
92
+ "marquee",
93
+ "menu",
94
+ "meta",
95
+ "nav",
96
+ "noembed",
97
+ "noframes",
98
+ "noscript",
99
+ "object",
100
+ "ol",
101
+ "param",
102
+ "plaintext",
103
+ "pre",
104
+ "script",
105
+ "search",
106
+ "section",
107
+ "select",
108
+ "source",
109
+ "style",
110
+ "summary",
111
+ "table",
112
+ "tbody",
113
+ "td",
114
+ "template",
115
+ "textarea",
116
+ "tfoot",
117
+ "th",
118
+ "thead",
119
+ "title",
120
+ "tr",
121
+ "track",
122
+ "ul",
123
+ "wbr",
124
+ "xmp"
125
+ ]), N = /* @__PURE__ */ new Set(["textarea", "title", "style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext"]), u = {
126
+ table: /* @__PURE__ */ new Set(["caption", "colgroup", "thead", "tbody", "tfoot", "script", "template", "style"]),
127
+ thead: /* @__PURE__ */ new Set(["tr", "script", "template", "style"]),
128
+ tbody: /* @__PURE__ */ new Set(["tr", "script", "template", "style"]),
129
+ tfoot: /* @__PURE__ */ new Set(["tr", "script", "template", "style"]),
130
+ tr: /* @__PURE__ */ new Set(["td", "th", "script", "template", "style"]),
131
+ colgroup: /* @__PURE__ */ new Set(["col", "template"])
132
+ }, d = {
133
+ caption: "table",
134
+ colgroup: "table",
135
+ thead: "table",
136
+ tbody: "table",
137
+ tfoot: "table",
138
+ tr: "a table section (<tbody>, <thead> or <tfoot>)",
139
+ td: "<tr>",
140
+ th: "<tr>",
141
+ col: "<colgroup>"
142
+ };
143
+ function s(t, o, i, e, n) {
144
+ return S(
145
+ t,
146
+ o,
147
+ { code: "ERR_INVALID_HTML_NESTING" },
148
+ `<${i}> cannot contain <${e}>: ${n} The browser would build a different tree than this JSX describes. Run what_fix({ error: 'ERR_INVALID_HTML_NESTING' }) for the worked example.`
149
+ );
150
+ }
151
+ var _ = /* @__PURE__ */ new Set([
152
+ "b",
153
+ "big",
154
+ "blockquote",
155
+ "body",
156
+ "br",
157
+ "center",
158
+ "code",
159
+ "dd",
160
+ "div",
161
+ "dl",
162
+ "dt",
163
+ "em",
164
+ "embed",
165
+ "h1",
166
+ "h2",
167
+ "h3",
168
+ "h4",
169
+ "h5",
170
+ "h6",
171
+ "head",
172
+ "hr",
173
+ "i",
174
+ "img",
175
+ "li",
176
+ "listing",
177
+ "menu",
178
+ "meta",
179
+ "nobr",
180
+ "ol",
181
+ "p",
182
+ "pre",
183
+ "ruby",
184
+ "s",
185
+ "small",
186
+ "span",
187
+ "strong",
188
+ "strike",
189
+ "sub",
190
+ "sup",
191
+ "table",
192
+ "tt",
193
+ "u",
194
+ "ul",
195
+ "var"
196
+ ]), v = /* @__PURE__ */ new Set(["thead", "tbody", "tfoot"]);
197
+ function $(t) {
198
+ return t.openingElement.attributes.some((o) => l.isJSXAttribute(o) && l.isJSXIdentifier(o.name, { name: "type" }) && l.isStringLiteral(o.value) && o.value.value.toLowerCase() === "hidden");
199
+ }
200
+ function I(t) {
201
+ return t.openingElement.attributes.some((o) => l.isJSXAttribute(o) && l.isJSXIdentifier(o.name) && ["color", "face", "size"].includes(o.name.name.toLowerCase()) && (!o.value || l.isStringLiteral(o.value)));
202
+ }
203
+ function C(t) {
204
+ return [...t].filter((o) => o !== "script" && o !== "template" && o !== "style").map((o) => `<${o}>`).join(", ");
205
+ }
206
+ function A(t, o, i) {
207
+ let e = t.openingElement.name.name, n = o.length > 0 ? o[o.length - 1].tag : null;
208
+ if (n !== null) {
209
+ if (N.has(n)) throw s(t, i, n, e, `the parser reads the content of <${n}> as text, so the element becomes literal characters.`);
210
+ if (m.has(n)) throw s(t, i, n, e, `<${n}> is a void element and has no content.`);
211
+ let r = u[n];
212
+ if (r && !r.has(e) && !(e === "input" && n !== "colgroup" && $(t))) {
213
+ let a = e === "tr" && n === "table" ? "the parser inserts a <tbody> around the row. Write the <tbody> yourself." : (e === "td" || e === "th") && v.has(n) ? "the parser inserts a <tr> around the cell. Write the <tr> yourself." : `the parser moves it out of the table. <${n}> holds only ${C(r)}.`;
214
+ throw s(t, i, n, e, a);
215
+ }
216
+ if (d[e] && !u[n] && n !== "template")
217
+ throw s(t, i, n, e, `outside its table parent the parser drops the <${e}> tag. It belongs in ${d[e]}.`);
218
+ if (b.has(e) && b.has(n)) throw s(t, i, n, e, "a heading start tag closes the heading that is open.");
219
+ if (e === "option" && n === "option") throw s(t, i, n, e, "an <option> start tag closes the open <option>.");
220
+ if ((e === "rp" || e === "rt") && (n === "rb" || n === "rp" || n === "rt") && o.some((a) => a.tag === "ruby"))
221
+ throw s(t, i, n, e, `an <${e}> start tag inside a <ruby> closes the open <${n}>.`);
222
+ if (e === "optgroup" && (n === "option" || n === "optgroup")) throw s(t, i, n, e, `an <optgroup> start tag closes the open <${n}>.`);
223
+ }
224
+ if (L.has(e))
225
+ for (let r = o.length - 1; r >= 0; r--) {
226
+ let a = o[r].tag;
227
+ if (a === "p") throw s(t, i, "p", e, `<p> holds only phrasing content, and a <${e}> start tag closes it.`);
228
+ if (a === "button" || f.has(a) || e === "hr" && a === "select") break;
229
+ }
230
+ if (e === "nobr")
231
+ for (let r = o.length - 1; r >= 0; r--) {
232
+ let a = o[r].tag;
233
+ if (a === "nobr") throw s(t, i, "nobr", "nobr", "a <nobr> start tag closes the open <nobr>.");
234
+ if (f.has(a)) break;
235
+ }
236
+ if (e === "a")
237
+ for (let r = o.length - 1; r >= 0; r--) {
238
+ let a = o[r].tag;
239
+ if (a === "a") throw s(t, i, "a", "a", "a link cannot hold another link; the parser closes the outer one.");
240
+ if (a === "td" || a === "th" || a === "caption" || a === "object" || a === "applet" || a === "marquee" || a === "template") break;
241
+ }
242
+ if (e === "form")
243
+ for (let r = o.length - 1; r >= 0; r--) {
244
+ let a = o[r].tag;
245
+ if (a === "form") throw s(t, i, "form", "form", "the parser ignores a <form> start tag inside an open form.");
246
+ if (a === "template") break;
247
+ }
248
+ if (e === "button")
249
+ for (let r = o.length - 1; r >= 0; r--) {
250
+ let a = o[r].tag;
251
+ if (a === "button") throw s(t, i, "button", "button", "a <button> start tag closes the open button.");
252
+ if (f.has(a)) break;
253
+ }
254
+ if (e === "li" || e === "dd" || e === "dt")
255
+ for (let r = o.length - 1; r >= 0; r--) {
256
+ let a = o[r].tag;
257
+ if (e === "li" ? a === "li" : a === "dd" || a === "dt")
258
+ throw s(t, i, a, e, `a <${e}> start tag closes the open <${a}>; nest a list between them.`);
259
+ if (T.has(a) && a !== "address" && a !== "div" && a !== "p") break;
260
+ }
261
+ if (e === "select" && o.some((r) => r.tag === "select"))
262
+ throw s(t, i, "select", "select", "a <select> start tag inside a select closes it.");
263
+ if (e === "input" && o.some((r) => r.tag === "select"))
264
+ throw s(t, i, "select", "input", "an <input> start tag inside a select closes it, and the input is created after it.");
265
+ }
266
+ function g(t, o, i, e) {
267
+ if (i.length === 0) return;
268
+ let n = i[i.length - 1].tag;
269
+ if (!(!u[n] && !m.has(n)) && o)
270
+ throw s(t, e, n, "#text", m.has(n) ? `<${n}> is a void element and has no content.` : `the parser moves text out of <${n}> to before the table.`);
271
+ }
272
+ function p(t, o, i, e) {
273
+ if (l.isJSXText(t)) {
274
+ g(t, y(t.value), o, i);
275
+ return;
276
+ }
277
+ if (l.isJSXExpressionContainer(t)) {
278
+ i.ssr && h(t.expression, o, i, e);
279
+ return;
280
+ }
281
+ if (l.isJSXFragment(t)) {
282
+ t._whatChecked = !0;
283
+ for (let c of t.children) p(c, o, i, e);
284
+ return;
285
+ }
286
+ if (!l.isJSXElement(t)) return;
287
+ if (t._whatChecked = !0, E(t)) {
288
+ for (let c of t.children) p(c, [], i, []);
289
+ return;
290
+ }
291
+ let n = t.openingElement.name.name, r = t._whatNs === "html";
292
+ if (r) A(t, o, i);
293
+ else if (e.length > 0 && (_.has(n) || n === "font" && I(t)))
294
+ throw s(
295
+ t,
296
+ i,
297
+ e[e.length - 1],
298
+ n,
299
+ "an HTML element inside SVG or MathML content closes it, and the parser creates the element as HTML beside it. Wrap HTML in <foreignObject> (SVG) or <mtext> (MathML)."
300
+ );
301
+ let a = r ? [...o, { tag: n }] : [], w = r ? [] : [...e, n];
302
+ for (let c of t.children) p(c, a, i, w);
303
+ }
304
+ function h(t, o, i, e) {
305
+ if (l.isStringLiteral(t) || l.isNumericLiteral(t))
306
+ e.length === 0 && g(t, String(t.value), o, i);
307
+ else if (l.isJSXElement(t) || l.isJSXFragment(t))
308
+ p(t, o, i, e);
309
+ else if (l.isConditionalExpression(t))
310
+ h(t.consequent, o, i, e), h(t.alternate, o, i, e);
311
+ else if (l.isLogicalExpression(t))
312
+ h(t.left, o, i, e), h(t.right, o, i, e);
313
+ else if (l.isArrowFunctionExpression(t) && t.params.length === 0)
314
+ h(t.body, o, i, e);
315
+ else if (l.isCallExpression(t) && l.isMemberExpression(t.callee) && l.isIdentifier(t.callee.property, { name: "map" }) && l.isFunction(t.arguments[0])) {
316
+ let n = t.arguments[0];
317
+ if (l.isExpression(n.body)) h(n.body, o, i, e);
318
+ else for (let r of n.body.body) l.isReturnStatement(r) && r.argument && h(r.argument, o, i, e);
319
+ }
320
+ }
321
+ function O(t, o) {
322
+ if (t._whatChecked) return;
323
+ let i = t._whatNs;
324
+ p(t, [], o, i === "svg" || i === "math" ? [i] : []);
325
+ }
326
+ export {
327
+ O as validateNesting
328
+ };