-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Svelte generates code referencing undefined variables like div_nodes #3631
Comments
I think this is a harmless bug, as the The proper solution here seems to me to be to not have a claim method at all if we're not compiling with |
Current shot at this: diff --git a/src/compiler/compile/render_dom/wrappers/Slot.ts b/src/compiler/compile/render_dom/wrappers/Slot.ts
index 1ab1b6ab..fb90afab 100644
--- a/src/compiler/compile/render_dom/wrappers/Slot.ts
+++ b/src/compiler/compile/render_dom/wrappers/Slot.ts
@@ -137,12 +137,12 @@ export default class SlotWrapper extends Wrapper {
block.render_listeners(`_${slot.name}`);
block.event_listeners = listeners;
- if (block.chunks.create) create.push(b`if (!${slot}) { ${block.chunks.create} }`);
- if (block.chunks.claim) claim.push(b`if (!${slot}) { ${block.chunks.claim} }`);
- if (block.chunks.hydrate) hydrate.push(b`if (!${slot}) { ${block.chunks.hydrate} }`);
- if (block.chunks.mount) mount.push(b`if (!${slot}) { ${block.chunks.mount} }`);
- if (block.chunks.update) update.push(b`if (!${slot}) { ${block.chunks.update} }`);
- if (block.chunks.destroy) destroy.push(b`if (!${slot}) { ${block.chunks.destroy} }`);
+ if (block.chunks.create.length) create.push(b`if (!${slot}) { ${block.chunks.create} }`);
+ if (block.chunks.claim.length) claim.push(b`if (!${slot}) { ${block.chunks.claim} }`);
+ if (block.chunks.hydrate.length) hydrate.push(b`if (!${slot}) { ${block.chunks.hydrate} }`);
+ if (block.chunks.mount.length) mount.push(b`if (!${slot}) { ${block.chunks.mount} }`);
+ if (block.chunks.update.length) update.push(b`if (!${slot}) { ${block.chunks.update} }`);
+ if (block.chunks.destroy.length) destroy.push(b`if (!${slot}) { ${block.chunks.destroy} }`);
block.chunks.create = create;
block.chunks.claim = claim;
@@ -155,9 +155,11 @@ export default class SlotWrapper extends Wrapper {
b`if (${slot}) ${slot}.c();`
);
- block.chunks.claim.push(
- b`if (${slot}) ${slot}.l(${parent_nodes});`
- );
+ if (renderer.options.hydratable) {
+ block.chunks.claim.push(
+ b`if (${slot}) ${slot}.l(${parent_nodes});`
+ );
+ }
block.chunks.mount.push(b`
if (${slot}) { Seems to address this particular issue, and doesn't break any tests. |
@Conduitry Do you know when
|
Judging by the test failures if I remove the |
It'd probably make sense to make it |
diff --git a/src/compiler/compile/render_dom/Block.ts b/src/compiler/compile/render_dom/Block.ts
index f73212f3..8ea90049 100644
--- a/src/compiler/compile/render_dom/Block.ts
+++ b/src/compiler/compile/render_dom/Block.ts
@@ -272,7 +272,7 @@ export default class Block {
}`;
}
- if (this.renderer.options.hydratable || this.chunks.claim.length > 0) {
+ if (this.renderer.options.hydratable || this.renderer.options.dev) {
if (this.chunks.claim.length === 0 && this.chunks.hydrate.length === 0) {
properties.claim = noop;
} else { still causes three js sample tests to fail (producing unexpected claim methods in blocks), and I'm not sure why. (Maybe something about |
Hi. I'm trying to use ESLint on the final IIFE
.js
that Svelte generates, in order to get theno-undef
lint (usage of undefined variable)..eslintrc.js
This gives me:
Offending code in
bundle.js
:Form.svelte
is just<form><slot /></form>
(I simplified it for the purpose of this report). If I add content to the default slot, or other HTML tags (children) to<form>
, the issue is still there. Searching forform_nodes
and_nodes
inbundle.js
gives me no results aside of the function above. If I changeForm.svelte
content to<div><slot /></form>
, I get warning about undefineddiv_nodes
.Are
<...>_nodes
in the code above intended to beundefined
? How can I set them? Or what else can I do to get the results I want (getting "... is not defined" errors at compile time, not runtime)?The text was updated successfully, but these errors were encountered: