Skip to content

fix: enusre dev validation in dynamic component works as intended #11985

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

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/neat-jokes-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: enusre dev validation in dynamic component works as intended
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,9 @@ function serialize_inline_component(node, component_name, context) {
/** @type {import('estree').Identifier | import('estree').MemberExpression | null} */
let bind_this = null;

/**
* @type {import("estree").ExpressionStatement[]}
*/
const binding_initializers = [];

/**
Expand Down Expand Up @@ -920,6 +923,8 @@ function serialize_inline_component(node, component_name, context) {
};
}

const statements = [...snippet_declarations];

if (node.type === 'SvelteComponent') {
const prev = fn;

Expand All @@ -930,6 +935,7 @@ function serialize_inline_component(node, component_name, context) {
b.arrow(
[b.id(component_name)],
b.block([
...binding_initializers,
b.stmt(
context.state.options.dev
? b.call('$.validate_dynamic_component', b.thunk(prev(node_id)))
Expand All @@ -939,10 +945,10 @@ function serialize_inline_component(node, component_name, context) {
)
);
};
} else {
statements.push(...binding_initializers);
}

const statements = [...snippet_declarations, ...binding_initializers];

if (Object.keys(custom_css_props).length > 0) {
context.state.template.push(
context.state.metadata.namespace === 'svg'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
export let div;
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test } from '../../test';

export default test({
compileOptions: {
dev: true
},

test({ assert, component, target }) {
// Shouldn't error
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import Test from './Test.svelte'
let div
</script>

<svelte:component this={Test} bind:div />
Loading