fix: remove buggy `validate_dynamic_component` check (#12960)

closes #12857
pull/12958/head
Rich Harris 4 months ago committed by GitHub
parent 01d32e53a9
commit 8c1d439a36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: remove buggy `validate_dynamic_component` check

@ -348,14 +348,7 @@ export function build_component(node, component_name, context, anchor = context.
b.thunk(/** @type {Expression} */ (context.visit(node.expression))),
b.arrow(
[b.id('$$anchor'), b.id(component_name)],
b.block([
...binding_initializers,
b.stmt(
dev
? b.call('$.validate_dynamic_component', b.thunk(prev(b.id('$$anchor'))))
: prev(b.id('$$anchor'))
)
])
b.block([...binding_initializers, b.stmt(prev(b.id('$$anchor')))])
)
);
};

@ -144,12 +144,7 @@ export {
setContext,
hasContext
} from './runtime.js';
export {
validate_binding,
validate_dynamic_component,
validate_each_keys,
validate_prop_bindings
} from './validate.js';
export { validate_binding, validate_each_keys, validate_prop_bindings } from './validate.js';
export { raf } from './timing.js';
export { proxy } from './proxy.js';
export { create_custom_element } from './dom/elements/custom-element.js';

@ -14,31 +14,6 @@ function is_void(tag) {
return void_element_names.test(tag) || tag.toLowerCase() === '!doctype';
}
/**
* @template Component
* @param {() => Component} component_fn
* @returns {Component}
*/
export function validate_dynamic_component(component_fn) {
try {
const instance = component_fn();
if (instance !== undefined && typeof instance !== 'object') {
e.svelte_component_invalid_this_value();
}
return instance;
} catch (err) {
const { message } = /** @type {Error} */ (err);
if (typeof message === 'string' && message.indexOf('is not a function') !== -1) {
e.svelte_component_invalid_this_value();
}
throw err;
}
}
/**
* @param {() => any} collection
* @param {(item: any, index: number) => string} key_fn

@ -1,12 +0,0 @@
import { test } from '../../test';
export default test({
mode: ['client'],
compileOptions: {
dev: true
},
error:
'svelte_component_invalid_this_value\nThe `this={...}` property of a `<svelte:component>` must be a Svelte component, if defined'
});

@ -1,5 +0,0 @@
<script>
let banana = {};
</script>
<svelte:component this={banana} />

@ -1,24 +0,0 @@
import { test } from '../../test';
export default test({
compileOptions: {
dev: true
},
get props() {
return { componentName: 'Sub' };
},
html: '<div>Sub</div>',
test({ assert, component, target }) {
component.componentName = 'Proxy';
assert.htmlEqual(target.innerHTML, '<div>Sub</div>');
try {
component.componentName = 'banana';
throw new Error('Expected an error');
} catch (err) {
assert.include(
/** @type {Error} */ (err).message,
'svelte_component_invalid_this_value\nThe `this={...}` property of a `<svelte:component>` must be a Svelte component, if defined'
);
}
}
});

@ -1,14 +0,0 @@
<script>
import Sub from './Sub.svelte';
export let componentName = 'Sub';
let proxy = new Proxy(Sub, {});
let banana = {};
let component;
$: {
if (componentName === 'Sub') component = Sub;
else if (componentName === 'Proxy') component = proxy;
else component = banana;
};
</script>
<svelte:component this={component} />
Loading…
Cancel
Save