mirror of https://github.com/sveltejs/svelte
`$inspect` rune (#9705)
* feat: add $log rune * fix issues * fix issues * tune * avoid static state reference validation * work around unfortunate browser behavior * call it ExpectedError * cleanup * Fix docs * tweaks * tweaks * lint * repl, dev: true * repl dev mode * Update sites/svelte-5-preview/src/lib/Repl.svelte * squelch static-state-reference warning * simplify * remove redundant code * Update packages/svelte/src/main/ambient.d.ts Co-authored-by: Rich Harris <richard.a.harris@gmail.com> * Update packages/svelte/src/main/ambient.d.ts Co-authored-by: Rich Harris <richard.a.harris@gmail.com> * Update packages/svelte/src/main/ambient.d.ts Co-authored-by: Rich Harris <richard.a.harris@gmail.com> * only pause/trace on change * Update packages/svelte/src/main/ambient.d.ts * Update .changeset/chatty-hotels-grin.md * Update sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md Co-authored-by: Rich Harris <richard.a.harris@gmail.com> * $log.break and $log.trace no-op during SSR * Update sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md Co-authored-by: Rich Harris <richard.a.harris@gmail.com> * update test * improve break experience * fix ts * remove unnecessary if (DEV) checks - log runes are removed in prod * ensure hoisting doesnt mess up source maps * check visited for cyclical values * rename $log to $inspect, remove children * custom inspect function * implement custom inspect functions * changeset * update docs * only fire on change * lint * make inspect take a single argument * ugh eslint * document console.trace trick * demos * fix site --------- Co-authored-by: Dominic Gannaway <dg@domgan.com> Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com> Co-authored-by: Rich Harris <rich.harris@vercel.com> Co-authored-by: Dominic Gannaway <trueadm@users.noreply.github.com>pull/9713/head
parent
3e3ae925f3
commit
bde42d5676
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
feat: $inspect rune
|
@ -0,0 +1,39 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
/**
|
||||
* @type {any[]}
|
||||
*/
|
||||
let log;
|
||||
/**
|
||||
* @type {typeof console.log}}
|
||||
*/
|
||||
let original_log;
|
||||
|
||||
export default test({
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
before_test() {
|
||||
log = [];
|
||||
original_log = console.log;
|
||||
console.log = (...v) => {
|
||||
log.push(...v);
|
||||
};
|
||||
},
|
||||
after_test() {
|
||||
console.log = original_log;
|
||||
},
|
||||
async test({ assert, target }) {
|
||||
assert.deepEqual(log, []);
|
||||
|
||||
const [b1, b2] = target.querySelectorAll('button');
|
||||
b1.click();
|
||||
b2.click();
|
||||
await Promise.resolve();
|
||||
|
||||
assert.ok(
|
||||
log[0].stack.startsWith('Error:') && log[0].stack.includes('HTMLButtonElement.on_click')
|
||||
);
|
||||
assert.deepEqual(log[1], 1);
|
||||
}
|
||||
});
|
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
let x = $state(0);
|
||||
let y = $state(0);
|
||||
|
||||
$inspect(x, (x, type) => {
|
||||
if (type === 'update') console.log(new Error(), x);
|
||||
});
|
||||
</script>
|
||||
|
||||
<button on:click={() => x++}>{x}</button>
|
||||
<button on:click={() => y++}>{y}</button>
|
@ -0,0 +1,34 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
/**
|
||||
* @type {any[]}
|
||||
*/
|
||||
let log;
|
||||
/**
|
||||
* @type {typeof console.log}}
|
||||
*/
|
||||
let original_log;
|
||||
|
||||
export default test({
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
before_test() {
|
||||
log = [];
|
||||
original_log = console.log;
|
||||
console.log = (...v) => {
|
||||
log.push(...v);
|
||||
};
|
||||
},
|
||||
after_test() {
|
||||
console.log = original_log;
|
||||
},
|
||||
async test({ assert, target, component }) {
|
||||
const [b1, b2] = target.querySelectorAll('button');
|
||||
b1.click();
|
||||
b2.click();
|
||||
await Promise.resolve();
|
||||
|
||||
assert.deepEqual(log, [0, 'init', 1, 'update']);
|
||||
}
|
||||
});
|
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
let x = $state(0);
|
||||
let y = $state(0);
|
||||
|
||||
$inspect(x);
|
||||
</script>
|
||||
|
||||
<button on:click={() => x++}>{x}</button>
|
||||
<button on:click={() => y++}>{y}</button>
|
Loading…
Reference in new issue