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.
- package/LICENSE +21 -0
- package/README.md +181 -2
- package/babel.d.ts +78 -2
- package/dist/babel/auto-selector.min.js +94 -0
- package/dist/babel/common.min.js +2053 -0
- package/dist/babel/dev-metadata.min.js +106 -0
- package/dist/babel/dom.min.js +1669 -0
- package/dist/babel/jsx-root.min.js +13 -0
- package/dist/babel/lists.min.js +492 -0
- package/dist/babel/nesting.min.js +328 -0
- package/dist/babel/reactivity.min.js +1218 -0
- package/dist/babel/server-actions.min.js +85 -0
- package/dist/babel/ssr.min.js +496 -0
- package/dist/babel/types.min.js +9 -0
- package/dist/babel-plugin.min.js +101 -1
- package/dist/file-router.min.js +368 -12
- package/dist/framework-files.min.js +62 -0
- package/dist/hot.min.js +315 -0
- package/dist/index.min.js +13 -414
- package/dist/release.min.js +78 -0
- package/dist/runtime.min.js +9 -1
- package/dist/tables/import-changes.min.js +272 -0
- package/dist/tables/markup-rules.min.js +213 -0
- package/dist/vite-plugin.min.js +432 -399
- package/file-router.d.ts +3 -1
- package/index.d.ts +1 -1
- package/package.json +11 -2
- package/runtime.d.ts +2 -1
- package/src/babel/auto-selector.js +248 -0
- package/src/babel/common.js +3800 -0
- package/src/babel/dev-metadata.js +167 -0
- package/src/babel/dom.js +3386 -0
- package/src/babel/jsx-root.js +27 -0
- package/src/babel/lists.js +704 -0
- package/src/babel/nesting.js +260 -0
- package/src/babel/reactivity.js +1998 -0
- package/src/babel/server-actions.js +144 -0
- package/src/babel/ssr.js +870 -0
- package/src/babel/types.js +10 -0
- package/src/babel-plugin.js +185 -3598
- package/src/file-router.js +58 -38
- package/src/framework-files.js +106 -0
- package/src/hot.js +523 -0
- package/src/release.js +127 -0
- package/src/runtime.js +7 -7
- package/src/tables/import-changes.js +157 -0
- package/src/tables/markup-rules.js +388 -0
- package/src/vite-plugin.js +460 -175
- package/vite.d.ts +47 -3
- package/src/error-overlay.js +0 -428
package/vite.d.ts
CHANGED
|
@@ -1,21 +1,65 @@
|
|
|
1
1
|
// what-compiler/vite — Vite plugin that compiles What JSX and wires the
|
|
2
|
-
// file-router
|
|
2
|
+
// file-router and hot replacement (src/vite-plugin.js).
|
|
3
3
|
|
|
4
4
|
export interface WhatVitePluginOptions {
|
|
5
5
|
/** Files to process. Defaults to /\.[jt]sx$/. */
|
|
6
6
|
include?: RegExp | RegExp[];
|
|
7
|
-
/**
|
|
7
|
+
/** Additional files to skip unless compileDependencies matches them. */
|
|
8
8
|
exclude?: RegExp | RegExp[];
|
|
9
|
+
/**
|
|
10
|
+
* Additional dependency paths to compile as app source. Dependency JSX
|
|
11
|
+
* already qualifies when the package declares what-framework or what-core
|
|
12
|
+
* in dependencies or peerDependencies.
|
|
13
|
+
*/
|
|
14
|
+
compileDependencies?: RegExp | ((id: string) => boolean) | Array<RegExp | ((id: string) => boolean)>;
|
|
9
15
|
/** Emit source maps. Defaults to true. */
|
|
10
16
|
sourceMaps?: boolean;
|
|
11
17
|
/** Apply production optimizations. Defaults to NODE_ENV === 'production'. */
|
|
12
18
|
production?: boolean;
|
|
13
19
|
/** Pages directory, relative to project root. Defaults to 'src/pages'. */
|
|
14
20
|
pages?: string;
|
|
15
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Hot replacement in the dev server: a saved edit rebuilds the changed
|
|
23
|
+
* components in place and keeps module-scope signals and stores (README,
|
|
24
|
+
* "Hot replacement"). Defaults to enabled in dev, disabled in production.
|
|
25
|
+
*/
|
|
16
26
|
hot?: boolean;
|
|
17
27
|
/** Resolve the `production` exports condition during build. Defaults to true. */
|
|
18
28
|
prodBundles?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Compile modules Vite transforms for the server (SSR, or the 'ssr'
|
|
31
|
+
* environment) with what-compiler's server target, which what-server renders.
|
|
32
|
+
* Defaults to true. With false, a server transform whose output would build
|
|
33
|
+
* DOM is refused with ERR_COMPILED_JSX_IN_SSR.
|
|
34
|
+
*/
|
|
35
|
+
ssr?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* False compiles every server transform for the DOM, whatever `ssr` says,
|
|
38
|
+
* for a process that installs a DOM on purpose, such as a test runner
|
|
39
|
+
* applying SSR transforms. Defaults to true: server transforms use the
|
|
40
|
+
* server target, or with `ssr: false` one that would build DOM is refused.
|
|
41
|
+
*/
|
|
42
|
+
ssrGuard?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Rewrite `selected() === row.id` inside keyed `.map()` rows to a
|
|
45
|
+
* `createSelector` lookup, so a selection change re-runs two rows instead of
|
|
46
|
+
* every row. Defaults to true; false keeps every comparison as written.
|
|
47
|
+
*/
|
|
48
|
+
autoSelector?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Print the compiler's notes on correct code in development (what the
|
|
51
|
+
* auto-selector rewrote, that `<For>` and a keyed `.map()` compile alike).
|
|
52
|
+
* Warnings about code that misbehaves print either way. Defaults to false.
|
|
53
|
+
*/
|
|
54
|
+
verbose?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Compile client JSX so that `hydrate()` adopts server-rendered markup
|
|
57
|
+
* (what-compiler's `hydratable` option). `'auto'`, the default, does when
|
|
58
|
+
* the config says the project renders on the server: `appType: 'custom'`,
|
|
59
|
+
* an SSR build, or a client build with `build.ssrManifest`. Set `true` when
|
|
60
|
+
* the client build has none of these.
|
|
61
|
+
*/
|
|
62
|
+
hydratable?: boolean | 'auto';
|
|
19
63
|
}
|
|
20
64
|
|
|
21
65
|
// Structural Vite plugin shape — assignable to Vite's `PluginOption` without a
|
package/src/error-overlay.js
DELETED
|
@@ -1,428 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What Framework — Vite Error Overlay
|
|
3
|
-
*
|
|
4
|
-
* Custom error overlay injected during dev mode. Shows compiler transform errors
|
|
5
|
-
* and runtime signal errors with What Framework branding and helpful context.
|
|
6
|
-
*
|
|
7
|
-
* This is client-side code that Vite injects into the page during development.
|
|
8
|
-
*
|
|
9
|
-
* Architecture: The overlay HTML template and all helper functions are inlined as
|
|
10
|
-
* string literals into the custom element code. This avoids function-to-string
|
|
11
|
-
* serialization (which is fragile with minifiers and bundlers).
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
// CSS for the overlay — scoped to avoid style conflicts
|
|
15
|
-
const OVERLAY_STYLES = `
|
|
16
|
-
:host {
|
|
17
|
-
position: fixed;
|
|
18
|
-
inset: 0;
|
|
19
|
-
z-index: 99999;
|
|
20
|
-
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.backdrop {
|
|
24
|
-
position: fixed;
|
|
25
|
-
inset: 0;
|
|
26
|
-
background: rgba(0, 0, 0, 0.66);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.panel {
|
|
30
|
-
position: fixed;
|
|
31
|
-
inset: 2rem;
|
|
32
|
-
overflow: auto;
|
|
33
|
-
background: #1a1a2e;
|
|
34
|
-
border: 1px solid #2a2a4a;
|
|
35
|
-
border-radius: 12px;
|
|
36
|
-
box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
|
|
37
|
-
color: #e0e0e0;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.header {
|
|
41
|
-
display: flex;
|
|
42
|
-
align-items: center;
|
|
43
|
-
justify-content: space-between;
|
|
44
|
-
padding: 1rem 1.5rem;
|
|
45
|
-
border-bottom: 1px solid #2a2a4a;
|
|
46
|
-
background: #16163a;
|
|
47
|
-
border-radius: 12px 12px 0 0;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.header-left {
|
|
51
|
-
display: flex;
|
|
52
|
-
align-items: center;
|
|
53
|
-
gap: 0.75rem;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.header-right {
|
|
57
|
-
display: flex;
|
|
58
|
-
align-items: center;
|
|
59
|
-
gap: 0.5rem;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
.logo {
|
|
63
|
-
width: 28px;
|
|
64
|
-
height: 28px;
|
|
65
|
-
background: linear-gradient(135deg, #2563eb, #1d4ed8);
|
|
66
|
-
border-radius: 6px;
|
|
67
|
-
display: grid;
|
|
68
|
-
place-items: center;
|
|
69
|
-
font-weight: 800;
|
|
70
|
-
font-size: 14px;
|
|
71
|
-
color: #fff;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
.brand {
|
|
75
|
-
font-size: 14px;
|
|
76
|
-
font-weight: 600;
|
|
77
|
-
color: #a0a0c0;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
.tag {
|
|
81
|
-
font-size: 11px;
|
|
82
|
-
padding: 2px 8px;
|
|
83
|
-
border-radius: 4px;
|
|
84
|
-
font-weight: 600;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
.tag-error {
|
|
88
|
-
background: #3b1219;
|
|
89
|
-
color: #f87171;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
.tag-warning {
|
|
93
|
-
background: #3b2f19;
|
|
94
|
-
color: #fbbf24;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
.close-btn, .copy-btn {
|
|
98
|
-
background: none;
|
|
99
|
-
border: 1px solid #3a3a5a;
|
|
100
|
-
color: #a0a0c0;
|
|
101
|
-
border-radius: 6px;
|
|
102
|
-
padding: 4px 12px;
|
|
103
|
-
cursor: pointer;
|
|
104
|
-
font-family: inherit;
|
|
105
|
-
font-size: 12px;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
.close-btn:hover, .copy-btn:hover {
|
|
109
|
-
background: #2a2a4a;
|
|
110
|
-
color: #fff;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
.copy-btn.copied {
|
|
114
|
-
border-color: #22c55e;
|
|
115
|
-
color: #22c55e;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
.body {
|
|
119
|
-
padding: 1.5rem;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
.error-title {
|
|
123
|
-
font-size: 16px;
|
|
124
|
-
font-weight: 700;
|
|
125
|
-
color: #f87171;
|
|
126
|
-
margin: 0 0 0.5rem;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
.error-message {
|
|
130
|
-
font-size: 14px;
|
|
131
|
-
color: #e0e0e0;
|
|
132
|
-
margin: 0 0 1rem;
|
|
133
|
-
line-height: 1.6;
|
|
134
|
-
white-space: pre-wrap;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
.file-path {
|
|
138
|
-
display: inline-flex;
|
|
139
|
-
align-items: center;
|
|
140
|
-
gap: 0.5rem;
|
|
141
|
-
font-size: 12px;
|
|
142
|
-
color: #818cf8;
|
|
143
|
-
margin-bottom: 1rem;
|
|
144
|
-
padding: 0.25rem 0;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
.code-frame {
|
|
148
|
-
background: #0d0d1a;
|
|
149
|
-
border: 1px solid #2a2a4a;
|
|
150
|
-
border-radius: 8px;
|
|
151
|
-
overflow-x: auto;
|
|
152
|
-
margin-bottom: 1rem;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
.code-line {
|
|
156
|
-
display: flex;
|
|
157
|
-
padding: 0 1rem;
|
|
158
|
-
font-size: 13px;
|
|
159
|
-
line-height: 1.7;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
.code-line.highlight {
|
|
163
|
-
background: rgba(248, 113, 113, 0.1);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
.line-number {
|
|
167
|
-
color: #4a4a6a;
|
|
168
|
-
min-width: 3ch;
|
|
169
|
-
text-align: right;
|
|
170
|
-
margin-right: 1rem;
|
|
171
|
-
user-select: none;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
.line-content {
|
|
175
|
-
white-space: pre;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
.tip {
|
|
179
|
-
margin-top: 1rem;
|
|
180
|
-
padding: 0.75rem 1rem;
|
|
181
|
-
background: #1a2744;
|
|
182
|
-
border: 1px solid #1e3a5f;
|
|
183
|
-
border-radius: 8px;
|
|
184
|
-
font-size: 13px;
|
|
185
|
-
color: #93c5fd;
|
|
186
|
-
line-height: 1.5;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
.tip-label {
|
|
190
|
-
font-weight: 700;
|
|
191
|
-
color: #60a5fa;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
.stack {
|
|
195
|
-
margin-top: 1rem;
|
|
196
|
-
font-size: 12px;
|
|
197
|
-
color: #6a6a8a;
|
|
198
|
-
white-space: pre-wrap;
|
|
199
|
-
line-height: 1.5;
|
|
200
|
-
}
|
|
201
|
-
`;
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Client-side overlay component — injected as a custom element string literal.
|
|
205
|
-
* All helper functions are inlined directly to avoid function.toString() fragility.
|
|
206
|
-
*/
|
|
207
|
-
const OVERLAY_ELEMENT = `
|
|
208
|
-
class WhatErrorOverlay extends HTMLElement {
|
|
209
|
-
constructor(err) {
|
|
210
|
-
super();
|
|
211
|
-
this.root = this.attachShadow({ mode: 'open' });
|
|
212
|
-
this.root.innerHTML = '<style>${OVERLAY_STYLES}</style>';
|
|
213
|
-
this._err = err;
|
|
214
|
-
this.show(err);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// --- Inlined helper: escapeHTML ---
|
|
218
|
-
_escapeHTML(str) {
|
|
219
|
-
return String(str)
|
|
220
|
-
.replace(/&/g, '&')
|
|
221
|
-
.replace(/</g, '<')
|
|
222
|
-
.replace(/>/g, '>')
|
|
223
|
-
.replace(/"/g, '"');
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// --- Inlined helper: cleanStack ---
|
|
227
|
-
_cleanStack(stack) {
|
|
228
|
-
return stack
|
|
229
|
-
.split('\\n')
|
|
230
|
-
.filter(function(line) { return line.indexOf('node_modules') === -1; })
|
|
231
|
-
.slice(0, 10)
|
|
232
|
-
.join('\\n');
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// --- Inlined helper: getTip ---
|
|
236
|
-
_getTip(err) {
|
|
237
|
-
var msg = (err.message || '').toLowerCase();
|
|
238
|
-
|
|
239
|
-
if (msg.indexOf('infinite') !== -1 && msg.indexOf('effect') !== -1) {
|
|
240
|
-
return 'An effect is writing to a signal it also reads. Use untrack() to read without subscribing, or move the write to a different effect.';
|
|
241
|
-
}
|
|
242
|
-
if (msg.indexOf('jsx') !== -1 && msg.indexOf('unexpected') !== -1) {
|
|
243
|
-
return 'Make sure your vite.config includes the What compiler plugin: import what from "what-compiler/vite"';
|
|
244
|
-
}
|
|
245
|
-
if (msg.indexOf('not a function') !== -1 && msg.indexOf('signal') !== -1) {
|
|
246
|
-
return 'Signals are functions: call sig() to read, sig(value) to write. Check you are not destructuring a signal.';
|
|
247
|
-
}
|
|
248
|
-
if (msg.indexOf('hydrat') !== -1) {
|
|
249
|
-
return 'Hydration mismatches happen when SSR output differs from client render. Ensure server and client see the same initial state.';
|
|
250
|
-
}
|
|
251
|
-
// New tips for common mistakes
|
|
252
|
-
if (msg.indexOf('signal') !== -1 && msg.indexOf('without') !== -1 && msg.indexOf('call') !== -1) {
|
|
253
|
-
return 'Signals must be called to read their value. Use {count()} in JSX, not {count}. The parentheses trigger the reactive subscription.';
|
|
254
|
-
}
|
|
255
|
-
if (msg.indexOf('innerhtml') !== -1 && msg.indexOf('__html') !== -1) {
|
|
256
|
-
return 'Raw innerHTML is blocked for security. Use innerHTML={{ __html: trustedString }} or dangerouslySetInnerHTML={{ __html: trustedString }} instead.';
|
|
257
|
-
}
|
|
258
|
-
if ((msg.indexOf('innerhtml') !== -1 || msg.indexOf('xss') !== -1) && msg.indexOf('raw string') !== -1) {
|
|
259
|
-
return 'Raw innerHTML is a security risk (XSS). Wrap your HTML in an object: innerHTML={{ __html: yourString }}.';
|
|
260
|
-
}
|
|
261
|
-
if (msg.indexOf('cleanup') !== -1 && (msg.indexOf('effect') !== -1 || msg.indexOf('listener') !== -1)) {
|
|
262
|
-
return 'Effects that add event listeners or timers should return a cleanup function: effect(() => { el.addEventListener(...); return () => el.removeEventListener(...); })';
|
|
263
|
-
}
|
|
264
|
-
if (msg.indexOf('route') !== -1 && (msg.indexOf('not found') !== -1 || msg.indexOf('404') !== -1 || msg.indexOf('no match') !== -1)) {
|
|
265
|
-
return 'No route matched the current URL. Check that your route paths are correct and you have a catch-all or 404 route defined.';
|
|
266
|
-
}
|
|
267
|
-
if (msg.indexOf('key') !== -1 && (msg.indexOf('missing') !== -1 || msg.indexOf('list') !== -1 || msg.indexOf('each') !== -1)) {
|
|
268
|
-
return 'Lists need unique keys for efficient DOM updates. Add a key prop: items.map(item => <Item key={item.id} />)';
|
|
269
|
-
}
|
|
270
|
-
return '';
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// --- Build overlay HTML ---
|
|
274
|
-
_buildHTML(err) {
|
|
275
|
-
var isCompilerError = err._isCompilerError || err.plugin === 'vite-plugin-what';
|
|
276
|
-
var type = isCompilerError ? 'Compiler Error' : 'Runtime Error';
|
|
277
|
-
var tagClass = isCompilerError ? 'tag-error' : 'tag-warning';
|
|
278
|
-
|
|
279
|
-
var codeFrame = '';
|
|
280
|
-
var rawFrame = err.frame || err._frame;
|
|
281
|
-
if (rawFrame) {
|
|
282
|
-
var lines = rawFrame.split('\\n');
|
|
283
|
-
var frameLines = '';
|
|
284
|
-
for (var i = 0; i < lines.length; i++) {
|
|
285
|
-
var line = lines[i];
|
|
286
|
-
var isHighlight = line.trimStart().startsWith('>');
|
|
287
|
-
var cleaned = line.replace(/^\\s*>\\s?/, ' ').replace(/^\\s{2}/, '');
|
|
288
|
-
var match = cleaned.match(/^(\\s*\\d+)\\s*\\|(.*)$/);
|
|
289
|
-
if (match) {
|
|
290
|
-
frameLines += '<div class="code-line' + (isHighlight ? ' highlight' : '') + '"><span class="line-number">' + match[1].trim() + '</span><span class="line-content">' + this._escapeHTML(match[2]) + '</span></div>';
|
|
291
|
-
} else if (cleaned.trim().startsWith('|')) {
|
|
292
|
-
frameLines += '<div class="code-line highlight"><span class="line-number"></span><span class="line-content" style="color:#f87171">' + this._escapeHTML(cleaned.replace(/^\\s*\\|/, '')) + '</span></div>';
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (frameLines) {
|
|
296
|
-
codeFrame = '<div class="code-frame">' + frameLines + '</div>';
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
var filePath = err.id || (err.loc && err.loc.file) || '';
|
|
301
|
-
var lineNum = (err.loc && err.loc.line != null) ? err.loc.line : '';
|
|
302
|
-
var col = (err.loc && err.loc.column != null) ? err.loc.column : '';
|
|
303
|
-
var location = filePath
|
|
304
|
-
? '<div class="file-path">' + this._escapeHTML(filePath) + (lineNum ? ':' + lineNum : '') + (col ? ':' + col : '') + '</div>'
|
|
305
|
-
: '';
|
|
306
|
-
|
|
307
|
-
var tip = this._getTip(err);
|
|
308
|
-
var tipHTML = tip ? '<div class="tip"><span class="tip-label">Tip: </span>' + this._escapeHTML(tip) + '</div>' : '';
|
|
309
|
-
|
|
310
|
-
var stack = (err.stack && !isCompilerError)
|
|
311
|
-
? '<div class="stack">' + this._escapeHTML(this._cleanStack(err.stack)) + '</div>'
|
|
312
|
-
: '';
|
|
313
|
-
|
|
314
|
-
return '<div class="backdrop"></div>'
|
|
315
|
-
+ '<div class="panel">'
|
|
316
|
-
+ '<div class="header">'
|
|
317
|
-
+ '<div class="header-left">'
|
|
318
|
-
+ '<div class="logo">W</div>'
|
|
319
|
-
+ '<span class="brand">What Framework</span>'
|
|
320
|
-
+ '<span class="tag ' + tagClass + '">' + type + '</span>'
|
|
321
|
-
+ '</div>'
|
|
322
|
-
+ '<div class="header-right">'
|
|
323
|
-
+ '<button class="copy-btn">Copy Error</button>'
|
|
324
|
-
+ '<button class="close-btn">Dismiss (Esc)</button>'
|
|
325
|
-
+ '</div>'
|
|
326
|
-
+ '</div>'
|
|
327
|
-
+ '<div class="body">'
|
|
328
|
-
+ '<h2 class="error-title">' + this._escapeHTML(err.name || 'Error') + '</h2>'
|
|
329
|
-
+ location
|
|
330
|
-
+ '<pre class="error-message">' + this._escapeHTML(err.message || String(err)) + '</pre>'
|
|
331
|
-
+ codeFrame
|
|
332
|
-
+ tipHTML
|
|
333
|
-
+ stack
|
|
334
|
-
+ '</div>'
|
|
335
|
-
+ '</div>';
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
show(err) {
|
|
339
|
-
var template = document.createElement('template');
|
|
340
|
-
template.innerHTML = this._buildHTML(err);
|
|
341
|
-
this.root.appendChild(template.content.cloneNode(true));
|
|
342
|
-
|
|
343
|
-
// Close handlers
|
|
344
|
-
var self = this;
|
|
345
|
-
var closeBtn = this.root.querySelector('.close-btn');
|
|
346
|
-
if (closeBtn) closeBtn.addEventListener('click', function() { self.close(); });
|
|
347
|
-
var backdrop = this.root.querySelector('.backdrop');
|
|
348
|
-
if (backdrop) backdrop.addEventListener('click', function() { self.close(); });
|
|
349
|
-
document.addEventListener('keydown', this._onKey = function(e) {
|
|
350
|
-
if (e.key === 'Escape') self.close();
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
// Copy Error button
|
|
354
|
-
var copyBtn = this.root.querySelector('.copy-btn');
|
|
355
|
-
if (copyBtn) {
|
|
356
|
-
copyBtn.addEventListener('click', function() {
|
|
357
|
-
self._copyError(copyBtn);
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
_copyError(btn) {
|
|
363
|
-
var err = this._err;
|
|
364
|
-
var data = {
|
|
365
|
-
name: err.name || 'Error',
|
|
366
|
-
message: err.message || String(err),
|
|
367
|
-
file: err.id || (err.loc && err.loc.file) || null,
|
|
368
|
-
line: (err.loc && err.loc.line != null) ? err.loc.line : null,
|
|
369
|
-
column: (err.loc && err.loc.column != null) ? err.loc.column : null,
|
|
370
|
-
stack: err.stack ? this._cleanStack(err.stack) : null,
|
|
371
|
-
framework: 'What Framework',
|
|
372
|
-
timestamp: new Date().toISOString()
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
var text = JSON.stringify(data, null, 2);
|
|
376
|
-
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
377
|
-
navigator.clipboard.writeText(text).then(function() {
|
|
378
|
-
btn.textContent = 'Copied!';
|
|
379
|
-
btn.classList.add('copied');
|
|
380
|
-
setTimeout(function() {
|
|
381
|
-
btn.textContent = 'Copy Error';
|
|
382
|
-
btn.classList.remove('copied');
|
|
383
|
-
}, 2000);
|
|
384
|
-
}).catch(function() {
|
|
385
|
-
// Fallback: select text
|
|
386
|
-
prompt('Copy error details:', text);
|
|
387
|
-
});
|
|
388
|
-
} else {
|
|
389
|
-
prompt('Copy error details:', text);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
close() {
|
|
394
|
-
document.removeEventListener('keydown', this._onKey);
|
|
395
|
-
this.remove();
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
if (!customElements.get('what-error-overlay')) {
|
|
400
|
-
customElements.define('what-error-overlay', WhatErrorOverlay);
|
|
401
|
-
}
|
|
402
|
-
`;
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Generate the client-side error overlay injection script.
|
|
406
|
-
* Called by the Vite plugin to inject into the dev server.
|
|
407
|
-
*/
|
|
408
|
-
export function getErrorOverlayCode() {
|
|
409
|
-
return OVERLAY_ELEMENT;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Create the error overlay middleware for Vite's dev server.
|
|
414
|
-
* Intercepts Vite's error events and shows a custom What-branded overlay.
|
|
415
|
-
*/
|
|
416
|
-
export function setupErrorOverlay(server) {
|
|
417
|
-
// Listen for Vite errors and enrich with What Framework context
|
|
418
|
-
const origSend = server.ws.send.bind(server.ws);
|
|
419
|
-
server.ws.send = function (payload) {
|
|
420
|
-
if (payload?.type === 'error') {
|
|
421
|
-
// Tag compiler errors
|
|
422
|
-
if (payload.err?.plugin === 'vite-plugin-what') {
|
|
423
|
-
payload.err._isCompilerError = true;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
return origSend(payload);
|
|
427
|
-
};
|
|
428
|
-
}
|