Skip to content

Commit

Permalink
fix do not warn about missing props for bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Jul 27, 2021
1 parent 4d677d5 commit cedd98f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/compiler/compile/render_dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,14 @@ export default function dom(

if (expected.length) {
dev_props_check = b`
const { ctx: #ctx } = this.$$;
const props = ${options.customElement ? x`this.attributes` : x`options.props || {}`};
${expected.map(prop => b`
if (${renderer.reference(prop.name)} === undefined && !('${prop.export_name}' in props)) {
@_console.warn("<${component.tag}> was created without expected prop '${prop.export_name}'");
}`)}
const { ctx: #ctx, on_mount: #on_mount, bound: #bound, props: #props } = this.$$;
#on_mount.push(function () {
const props = ${options.customElement ? x`this.attributes` : x`options.props || {}`};
${expected.map(prop => b`
if (${renderer.reference(prop.name)} === undefined && !('${prop.export_name}' in props || #bound[#props['${prop.export_name}']])) {
@_console.warn("<${component.tag}> was created without expected prop '${prop.export_name}'");
}`)}
});
`;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
export let w;
export let x;
export let y;
export let z = undefined;
</script>

<div>{w} {x} {y}</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
compileOptions: {
dev: true
},

warnings: [
"<Foo> was created without expected prop 'y'"
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import Foo from './Foo.svelte';
let x = undefined;
let w = 'w';
</script>

<Foo bind:w bind:x />

0 comments on commit cedd98f

Please sign in to comment.