-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Improve error message if
this
attribute of `<svelte:component…
…>` is not valid (#7551) * add test * improve error message if this attribute of <svelte:component> is not SvelteComponent * add more tests * improve validation * simplify test Co-authored-by: Tan Li Hau <[email protected]>
- Loading branch information
1 parent
be70a89
commit 01a9116
Showing
15 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/runtime/samples/component-not-constructor-dev/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
skip_if_ssr: true, | ||
skip_if_hydrate_from_ssr: true, | ||
compileOptions: { | ||
dev: true | ||
}, | ||
error: 'this={...} of <svelte:component> should specify a Svelte component.' | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/runtime/samples/component-not-constructor-dev/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script> | ||
let banana = {}; | ||
</script> | ||
|
||
<svelte:component this={banana} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div>Sub</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
skip_if_ssr: true, | ||
skip_if_hydrate_from_ssr: true, | ||
props: { | ||
selected: false | ||
}, | ||
error: 'component is not a constructor' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script> | ||
import Sub from './Sub.svelte'; | ||
export let selected; | ||
let banana = {}; | ||
let component = banana; | ||
$: selected ? component = Sub : component = banana; | ||
</script> | ||
|
||
<svelte:component this={component} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div>Sub</div> |
19 changes: 19 additions & 0 deletions
19
test/runtime/samples/component-not-constructor2-dev/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default { | ||
compileOptions: { | ||
dev: true | ||
}, | ||
props: { | ||
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.equal(err.message, 'this={...} of <svelte:component> should specify a Svelte component.'); | ||
} | ||
} | ||
}; |
14 changes: 14 additions & 0 deletions
14
test/runtime/samples/component-not-constructor2-dev/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<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} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div>Sub</div> |
16 changes: 16 additions & 0 deletions
16
test/runtime/samples/component-not-constructor2/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export default { | ||
props: { | ||
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.equal(err.message, 'component is not a constructor'); | ||
} | ||
} | ||
}; |
14 changes: 14 additions & 0 deletions
14
test/runtime/samples/component-not-constructor2/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<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} /> |