Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: smaller destructor chunk #8763

Merged
merged 5 commits into from
Jun 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update fixtures
  • Loading branch information
gtm-nayan committed Jun 20, 2023
commit 77cf4512e91d376f3fd532215c7a0facfe3a5126
10 changes: 5 additions & 5 deletions packages/svelte/src/compiler/compile/render_dom/Block.js
Original file line number Diff line number Diff line change
@@ -381,17 +381,17 @@ export default class Block {
if (this.chunks.destroy.length === 0) {
properties.destroy = noop;
} else {
const a = [];
const dispose_elements = [];
// Coalesce if blocks with the same condition
const b = flatten(this.chunks.destroy).filter(
const others = flatten(this.chunks.destroy).filter(
/** @param {import('estree').Node} node */
(node) => {
if (
node.type === 'IfStatement' &&
node.test.type === 'Identifier' &&
node.test.name === 'detaching'
) {
a.push(node.consequent);
dispose_elements.push(node.consequent);
return false;
} else {
return true;
@@ -400,8 +400,8 @@ export default class Block {
);

properties.destroy = x`function #destroy(detaching) {
if (detaching) { ${a} }
${b}
${dispose_elements.length ? b`if (detaching) { ${dispose_elements} }` : null}
${others}
}`;
}
if (!this.renderer.component.compile_options.dev) {
Original file line number Diff line number Diff line change
@@ -36,7 +36,10 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(button);
if (detaching) {
detach(button);
}

mounted = false;
dispose();
}
5 changes: 4 additions & 1 deletion packages/svelte/test/js/samples/action/expected.js
Original file line number Diff line number Diff line change
@@ -35,7 +35,10 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(a);
if (detaching) {
detach(a);
}

mounted = false;
dispose();
}
5 changes: 4 additions & 1 deletion packages/svelte/test/js/samples/bind-open/expected.js
Original file line number Diff line number Diff line change
@@ -37,7 +37,10 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(details);
if (detaching) {
detach(details);
}

mounted = false;
dispose();
}
Original file line number Diff line number Diff line change
@@ -29,7 +29,10 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(div);
if (detaching) {
detach(div);
}

div_resize_listener();
}
};
Original file line number Diff line number Diff line change
@@ -46,9 +46,12 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(input0);
if (detaching) detach(t);
if (detaching) detach(input1);
if (detaching) {
detach(input0);
detach(t);
detach(input1);
}

mounted = false;
run_all(dispose);
}
Original file line number Diff line number Diff line change
@@ -52,9 +52,12 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(p);
if (detaching) detach(t1);
if (detaching) detach(input);
if (detaching) {
detach(p);
detach(t1);
detach(input);
}

mounted = false;
dispose();
}
Original file line number Diff line number Diff line change
@@ -75,7 +75,9 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d: function destroy(detaching) {
if (detaching) detach_dev(p);
if (detaching) {
detach_dev(p);
}
}
};

@@ -197,4 +199,4 @@ class Component extends SvelteComponentDev {
}

export default Component;
export { moduleLiveBinding, moduleConstantProps };
export { moduleLiveBinding, moduleConstantProps };
Original file line number Diff line number Diff line change
@@ -81,8 +81,11 @@ function create_fragment(ctx) {
current = false;
},
d(detaching) {
if (detaching) detach(div);
if (detaching) detach(t);
if (detaching) {
detach(div);
detach(t);
}

destroy_component(component, detaching);
}
};
Original file line number Diff line number Diff line change
@@ -38,7 +38,9 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(p);
if (detaching) {
detach(p);
}
}
};
}
@@ -60,4 +62,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
Original file line number Diff line number Diff line change
@@ -74,11 +74,14 @@ function create_fragment(ctx) {
current = false;
},
d(detaching) {
if (detaching) {
detach(t0);
detach(t1);
detach(input);
}

destroy_component(foo, detaching);
if (detaching) detach(t0);
destroy_component(bar, detaching);
if (detaching) detach(t1);
if (detaching) detach(input);
mounted = false;
dispose();
}
Original file line number Diff line number Diff line change
@@ -34,7 +34,9 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(h1);
if (detaching) {
detach(h1);
}
}
};
}
Original file line number Diff line number Diff line change
@@ -50,9 +50,12 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(h1);
if (detaching) detach(t1);
if (detaching) detach(button);
if (detaching) {
detach(h1);
detach(t1);
detach(button);
}

mounted = false;
dispose();
}
6 changes: 4 additions & 2 deletions packages/svelte/test/js/samples/css-media-query/expected.js
Original file line number Diff line number Diff line change
@@ -30,7 +30,9 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(div);
if (detaching) {
detach(div);
}
}
};
}
@@ -42,4 +44,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
Original file line number Diff line number Diff line change
@@ -32,7 +32,9 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(div);
if (detaching) {
detach(div);
}
}
};
}
Original file line number Diff line number Diff line change
@@ -39,7 +39,9 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(h1);
if (detaching) {
detach(h1);
}
}
};
}
8 changes: 5 additions & 3 deletions packages/svelte/test/js/samples/data-attribute/expected.js
Original file line number Diff line number Diff line change
@@ -37,9 +37,11 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(div0);
if (detaching) detach(t);
if (detaching) detach(div1);
if (detaching) {
detach(div0);
detach(t);
detach(div1);
}
}
};
}
6 changes: 4 additions & 2 deletions packages/svelte/test/js/samples/debug-empty/expected.js
Original file line number Diff line number Diff line change
@@ -52,8 +52,10 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d: function destroy(detaching) {
if (detaching) detach_dev(h1);
if (detaching) detach_dev(t3);
if (detaching) {
detach_dev(h1);
detach_dev(t3);
}
}
};

Original file line number Diff line number Diff line change
@@ -68,8 +68,10 @@ function create_each_block(ctx) {
}
},
d: function destroy(detaching) {
if (detaching) detach_dev(span);
if (detaching) detach_dev(t1);
if (detaching) {
detach_dev(span);
detach_dev(t1);
}
}
};

@@ -152,9 +154,12 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d: function destroy(detaching) {
if (detaching) {
detach_dev(t0);
detach_dev(p);
}

destroy_each(each_blocks, detaching);
if (detaching) detach_dev(t0);
if (detaching) detach_dev(p);
}
};

13 changes: 9 additions & 4 deletions packages/svelte/test/js/samples/debug-foo/expected.js
Original file line number Diff line number Diff line change
@@ -62,8 +62,10 @@ function create_each_block(ctx) {
}
},
d: function destroy(detaching) {
if (detaching) detach_dev(span);
if (detaching) detach_dev(t1);
if (detaching) {
detach_dev(span);
detach_dev(t1);
}
}
};

@@ -146,9 +148,12 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d: function destroy(detaching) {
if (detaching) {
detach_dev(t0);
detach_dev(p);
}

destroy_each(each_blocks, detaching);
if (detaching) detach_dev(t0);
if (detaching) detach_dev(p);
}
};

Original file line number Diff line number Diff line change
@@ -47,8 +47,10 @@ function create_each_block(ctx) {
},
p: noop,
d: function destroy(detaching) {
if (detaching) detach_dev(t0);
if (detaching) detach_dev(t1);
if (detaching) {
detach_dev(t0);
detach_dev(t1);
}
}
};

@@ -119,8 +121,11 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d: function destroy(detaching) {
if (detaching) {
detach_dev(each_1_anchor);
}

destroy_each(each_blocks, detaching);
if (detaching) detach_dev(each_1_anchor);
}
};

Original file line number Diff line number Diff line change
@@ -40,7 +40,9 @@ function create_each_block(ctx) {
if (dirty & /*createElement*/ 1 && t_value !== (t_value = /*node*/ ctx[1] + "")) set_data(t, t_value);
},
d(detaching) {
if (detaching) detach(span);
if (detaching) {
detach(span);
}
}
};
}
@@ -98,8 +100,11 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d(detaching) {
if (detaching) {
detach(each_1_anchor);
}

destroy_each(each_blocks, detaching);
if (detaching) detach(each_1_anchor);
}
};
}
Original file line number Diff line number Diff line change
@@ -49,7 +49,9 @@ function create_fragment(ctx) {
i: noop,
o: noop,
d: function destroy(detaching) {
if (detaching) detach_dev(p);
if (detaching) {
detach_dev(p);
}
}
};

Loading