mirror of https://github.com/sveltejs/svelte
commit
11b5259a4a
@ -1,5 +0,0 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: ensure tracking returns true, even if in unowned
|
||||
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: ignore typescript abstract methods
|
||||
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: correctly ssr component in `svelte:head` with `$props.id()` or `css='injected'`
|
||||
@ -1 +1 @@
|
||||
<!--[--><a href="/foo">foo</a><!--]-->
|
||||
<!--[--><a href="/foo">foo</a> <a href="/foo">foo</a><!--]-->
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ target, assert }) {
|
||||
// Test for https://github.com/sveltejs/svelte/issues/15237
|
||||
const [setValues, clearValue] = target.querySelectorAll('button');
|
||||
const [text1, text2, check1, check2] = target.querySelectorAll('input');
|
||||
|
||||
assert.equal(text1.value, '');
|
||||
assert.equal(text2.value, '');
|
||||
assert.equal(check1.checked, false);
|
||||
assert.equal(check2.checked, false);
|
||||
|
||||
flushSync(() => {
|
||||
setValues.click();
|
||||
});
|
||||
|
||||
assert.equal(text1.value, 'message');
|
||||
assert.equal(text2.value, 'message');
|
||||
assert.equal(check1.checked, true);
|
||||
assert.equal(check2.checked, true);
|
||||
|
||||
flushSync(() => {
|
||||
clearValue.click();
|
||||
});
|
||||
|
||||
assert.equal(text1.value, '');
|
||||
assert.equal(text2.value, '');
|
||||
assert.equal(check1.checked, false);
|
||||
assert.equal(check2.checked, false);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,22 @@
|
||||
<script>
|
||||
let value = $state();
|
||||
let checked = $state(false);
|
||||
|
||||
function setValues() {
|
||||
value = 'message';
|
||||
checked = true;
|
||||
}
|
||||
function clearValues() {
|
||||
value = null;
|
||||
checked = null;
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={setValues}>setValues</button>
|
||||
<button onclick={clearValues}>clearValues</button>
|
||||
|
||||
<input type="text" {value} />
|
||||
<input type="text" {value} {...{}} />
|
||||
|
||||
<input type="checkbox" {checked} />
|
||||
<input type="checkbox" {checked} {...{}} />
|
||||
@ -1,19 +1,24 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
mode: ['client', 'server'],
|
||||
mode: ['client'],
|
||||
async test({ assert, target }) {
|
||||
const my_element = /** @type HTMLElement & { object: { test: true }; } */ (
|
||||
target.querySelector('my-element')
|
||||
);
|
||||
const my_link = /** @type HTMLAnchorElement & { object: { test: true }; } */ (
|
||||
target.querySelector('a')
|
||||
);
|
||||
assert.equal(my_element.getAttribute('string'), 'test');
|
||||
assert.equal(my_element.hasAttribute('object'), false);
|
||||
assert.deepEqual(my_element.object, { test: true });
|
||||
|
||||
const my_link = /** @type HTMLAnchorElement & { object: { test: true }; } */ (
|
||||
target.querySelector('a')
|
||||
);
|
||||
assert.equal(my_link.getAttribute('string'), 'test');
|
||||
assert.equal(my_link.hasAttribute('object'), false);
|
||||
assert.deepEqual(my_link.object, { test: true });
|
||||
|
||||
const [value1, value2] = target.querySelectorAll('value-element');
|
||||
assert.equal(value1.shadowRoot?.innerHTML, '<span>test</span>');
|
||||
assert.equal(value2.shadowRoot?.innerHTML, '<span>test</span>');
|
||||
}
|
||||
});
|
||||
|
||||
@ -1,2 +1,22 @@
|
||||
<script module>
|
||||
customElements.define('value-element', class extends HTMLElement {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.attachShadow({ mode: 'open' });
|
||||
}
|
||||
|
||||
set value(v) {
|
||||
if (this.__value !== v) {
|
||||
this.__value = v;
|
||||
this.shadowRoot.innerHTML = `<span>${v}</span>`;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<my-element string="test" object={{ test: true }}></my-element>
|
||||
<a is="my-link" string="test" object={{ test: true }}></a>
|
||||
|
||||
<value-element value="test"></value-element>
|
||||
<value-element {...{value: "test"}}></value-element>
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
let [btn1, btn2] = target.querySelectorAll('button');
|
||||
|
||||
btn1?.click();
|
||||
flushSync();
|
||||
|
||||
btn2?.click();
|
||||
flushSync();
|
||||
|
||||
btn1?.click();
|
||||
flushSync();
|
||||
|
||||
btn1?.click();
|
||||
flushSync();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>linked.current</button>\n3\n<button>count</button>\n1`
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
<script>
|
||||
import { untrack } from 'svelte';
|
||||
|
||||
let count = $state(0);
|
||||
let state = $state({current: count});
|
||||
|
||||
let linked = $derived.by(() => {
|
||||
count;
|
||||
|
||||
untrack(() => state.current = count);
|
||||
return untrack(() => state);
|
||||
});
|
||||
|
||||
linked.current++;
|
||||
</script>
|
||||
|
||||
<button onclick={() => linked.current++}>linked.current</button> {linked.current}
|
||||
<button onclick={() => count++}>count</button> {count}
|
||||
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
let { linked3 = $bindable(), linked4 = $bindable() } = $props();
|
||||
</script>
|
||||
|
||||
<p>Binding</p>
|
||||
<button onclick={() => linked3.count++}>Increment Linked 1 ({linked3.count})</button>
|
||||
<button onclick={() => linked4.count++}>Increment Linked 2 ({linked4.count})</button>
|
||||
@ -0,0 +1,13 @@
|
||||
<script>
|
||||
import { getContext } from 'svelte';
|
||||
const linked1 = getContext('linked1');
|
||||
const linked2 = getContext('linked2');
|
||||
</script>
|
||||
|
||||
<p>Context</p>
|
||||
<button onclick={() => linked1.linked.current.count++}
|
||||
>Increment Linked 1 ({linked1.linked.current.count})</button
|
||||
>
|
||||
<button onclick={() => linked2.linked.current.count++}
|
||||
>Increment Linked 2 ({linked2.linked.current.count})</button
|
||||
>
|
||||
@ -0,0 +1,34 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
// Tests that ownership is widened with $derived (on class or on its own) that contains $state
|
||||
export default test({
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
|
||||
test({ assert, target, warnings }) {
|
||||
const [root, counter_context1, counter_context2, counter_binding1, counter_binding2] =
|
||||
target.querySelectorAll('button');
|
||||
|
||||
counter_context1.click();
|
||||
counter_context2.click();
|
||||
counter_binding1.click();
|
||||
counter_binding2.click();
|
||||
flushSync();
|
||||
|
||||
assert.equal(warnings.length, 0);
|
||||
|
||||
root.click();
|
||||
flushSync();
|
||||
counter_context1.click();
|
||||
counter_context2.click();
|
||||
counter_binding1.click();
|
||||
counter_binding2.click();
|
||||
flushSync();
|
||||
|
||||
assert.equal(warnings.length, 0);
|
||||
},
|
||||
|
||||
warnings: []
|
||||
});
|
||||
@ -0,0 +1,46 @@
|
||||
<script>
|
||||
import CounterBinding from './CounterBinding.svelte';
|
||||
import CounterContext from './CounterContext.svelte';
|
||||
import { setContext } from 'svelte';
|
||||
|
||||
let counter = $state({ count: 0 });
|
||||
|
||||
class Linked {
|
||||
#getter;
|
||||
linked = $derived.by(() => {
|
||||
const state = $state({ current: $state.snapshot(this.#getter()) });
|
||||
return state;
|
||||
});
|
||||
|
||||
constructor(fn) {
|
||||
this.#getter = fn;
|
||||
}
|
||||
}
|
||||
|
||||
const linked1 = $derived.by(() => {
|
||||
const state = $state({ current: $state.snapshot(counter) });
|
||||
return state;
|
||||
});
|
||||
const linked2 = new Linked(() => counter);
|
||||
|
||||
setContext('linked1', {
|
||||
get linked() {
|
||||
return linked1;
|
||||
}
|
||||
});
|
||||
setContext('linked2', linked2);
|
||||
|
||||
const linked3 = $derived.by(() => {
|
||||
const state = $state({ current: $state.snapshot(counter) });
|
||||
return state;
|
||||
});
|
||||
const linked4 = new Linked(() => counter);
|
||||
</script>
|
||||
|
||||
<p>Parent</p>
|
||||
<button onclick={() => counter.count++}>
|
||||
Increment Original ({counter.count})
|
||||
</button>
|
||||
|
||||
<CounterContext />
|
||||
<CounterBinding bind:linked3={linked3.current} bind:linked4={linked4.linked.current} />
|
||||
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
let id = $props.id();
|
||||
</script>
|
||||
|
||||
<p>{id}</p>
|
||||
@ -0,0 +1,59 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
test({ assert, target, variant }) {
|
||||
if (variant === 'dom') {
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>toggle</button>
|
||||
<h1>c1</h1>
|
||||
<p>c2</p>
|
||||
<p>c3</p>
|
||||
<p>c4</p>
|
||||
`
|
||||
);
|
||||
} else {
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>toggle</button>
|
||||
<h1>s1</h1>
|
||||
<p>s2</p>
|
||||
<p>s3</p>
|
||||
<p>s4</p>
|
||||
`
|
||||
);
|
||||
}
|
||||
|
||||
let button = target.querySelector('button');
|
||||
flushSync(() => button?.click());
|
||||
|
||||
if (variant === 'dom') {
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>toggle</button>
|
||||
<h1>c1</h1>
|
||||
<p>c2</p>
|
||||
<p>c3</p>
|
||||
<p>c4</p>
|
||||
<p>c5</p>
|
||||
`
|
||||
);
|
||||
} else {
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>toggle</button>
|
||||
<h1>s1</h1>
|
||||
<p>s2</p>
|
||||
<p>s3</p>
|
||||
<p>s4</p>
|
||||
<p>c1</p>
|
||||
`
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
import Child from './Child.svelte';
|
||||
|
||||
let id = $props.id();
|
||||
|
||||
let show = $state(false);
|
||||
</script>
|
||||
|
||||
<button onclick={() => show = !show}>toggle</button>
|
||||
|
||||
<h1>{id}</h1>
|
||||
|
||||
<Child />
|
||||
<Child />
|
||||
<Child />
|
||||
|
||||
{#if show}
|
||||
<Child />
|
||||
{/if}
|
||||
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
let id = $props.id();
|
||||
</script>
|
||||
|
||||
<meta name="id" content={id} />
|
||||
@ -0,0 +1,3 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({});
|
||||
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
import HeadNested from './HeadNested.svelte';
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<HeadNested />
|
||||
</svelte:head>
|
||||
|
||||
@ -0,0 +1 @@
|
||||
[]
|
||||
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
class Test{
|
||||
#der = $derived({test: 0});
|
||||
|
||||
set test(v){
|
||||
this.#der.test = 45;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"code": "constant_assignment",
|
||||
"message": "Cannot assign to derived state",
|
||||
"start": {
|
||||
"column": 3,
|
||||
"line": 6
|
||||
},
|
||||
"end": {
|
||||
"column": 29,
|
||||
"line": 6
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
class Test{
|
||||
der = $derived({ test: 0 });
|
||||
|
||||
set test(v){
|
||||
this["der"] = { test: 45 };
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"code": "constant_assignment",
|
||||
"message": "Cannot assign to derived state",
|
||||
"start": {
|
||||
"column": 3,
|
||||
"line": 6
|
||||
},
|
||||
"end": {
|
||||
"column": 27,
|
||||
"line": 6
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
class Test{
|
||||
#der = $derived({ test: 0 });
|
||||
|
||||
set test(v){
|
||||
this.#der = { test: 45 };
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1 @@
|
||||
[]
|
||||
@ -0,0 +1,13 @@
|
||||
<script>
|
||||
class Test {
|
||||
#deps = () => [];
|
||||
|
||||
deps = $derived.by(() => {
|
||||
return [];
|
||||
});
|
||||
|
||||
constructor(f = () => []) {
|
||||
this.#deps = f;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"code": "constant_assignment",
|
||||
"message": "Cannot assign to derived state",
|
||||
"start": {
|
||||
"column": 3,
|
||||
"line": 6
|
||||
},
|
||||
"end": {
|
||||
"column": 26,
|
||||
"line": 6
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
class Test{
|
||||
der = $derived({ test: 0 });
|
||||
|
||||
set test(v){
|
||||
this.der = { test: 45 };
|
||||
}
|
||||
}
|
||||
</script>
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue