pull/18603/merge
Liam O'Dea 7 days ago committed by GitHub
commit 8ddc9d771c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
perf: O(1) membership in `{@const}` topological sort (`sort_const_tags`)

@ -87,9 +87,12 @@ function sort_const_tags(nodes, state) {
/** @type {AST.ConstTag[]} */
const sorted = [];
/** @type {Set<AST.ConstTag>} */
const seen = new Set();
/** @param {Tag} tag */
function add(tag) {
if (sorted.includes(tag.node)) {
if (seen.has(tag.node)) {
return;
}
@ -98,6 +101,7 @@ function sort_const_tags(nodes, state) {
if (dep_tag) add(dep_tag);
}
seen.add(tag.node);
sorted.push(tag.node);
}

@ -0,0 +1,13 @@
import { test } from '../../test';
// sum is declared before left/right; sort_const_tags must emit deps first.
// Also exercises multi-parent membership (sum → left and sum → right).
export default test({
html: '<p>23</p>',
async test({ component, target, assert }) {
component.n = 1;
assert.htmlEqual(target.innerHTML, '<p>5</p>');
}
});

@ -0,0 +1,10 @@
<script>
export let n = 10;
</script>
{#if true}
{@const sum = left + right}
{@const left = n + 1}
{@const right = n + 2}
<p>{sum}</p>
{/if}
Loading…
Cancel
Save