remove missing prop warning false positives - fixes #1902

pull/1907/head
Rich Harris 6 years ago
parent 4fbc0c0f52
commit 7440fa54e9

@ -131,10 +131,10 @@ export default function dom(
if (expected.length) { if (expected.length) {
dev_props_check = deindent` dev_props_check = deindent`
const { ctx } = this.$$; const { ctx } = this.$$;
const props = ${options.customElement ? `this.attributes` : `options.props || {}`};
${expected.map(name => deindent` ${expected.map(name => deindent`
if (ctx.${name} === undefined && !('${name}' in props)) {
if (ctx.${name} === undefined${options.customElement && ` && !('${name}' in this.attributes)`}) { console.warn("<${component.tag}> was created without expected prop '${name}'");
console.warn("<${component.tag}> was created without expected data property '${name}'");
}`)} }`)}
`; `;
} }

@ -12,7 +12,7 @@ export default function (target) {
target.innerHTML = '<my-app foo=yes />'; target.innerHTML = '<my-app foo=yes />';
assert.equal(warnings.length, 1); assert.equal(warnings.length, 1);
assert.equal(warnings[0], `<my-app> was created without expected data property 'bar'`); assert.equal(warnings[0], `<my-app> was created without expected prop 'bar'`);
console.warn = warn; console.warn = warn;
} }

@ -70,8 +70,9 @@ class SvelteComponent extends SvelteComponentDev {
init(this, options, instance, create_fragment, safe_not_equal); init(this, options, instance, create_fragment, safe_not_equal);
const { ctx } = this.$$; const { ctx } = this.$$;
if (ctx.name === undefined) { const props = options.props || {};
console.warn("<SvelteComponent> was created without expected data property 'name'"); if (ctx.name === undefined && !('name' in props)) {
console.warn("<SvelteComponent> was created without expected prop 'name'");
} }
} }

@ -158,17 +158,18 @@ class SvelteComponent extends SvelteComponentDev {
init(this, options, instance, create_fragment, safe_not_equal); init(this, options, instance, create_fragment, safe_not_equal);
const { ctx } = this.$$; const { ctx } = this.$$;
if (ctx.things === undefined) { const props = options.props || {};
console.warn("<SvelteComponent> was created without expected data property 'things'"); if (ctx.things === undefined && !('things' in props)) {
console.warn("<SvelteComponent> was created without expected prop 'things'");
} }
if (ctx.foo === undefined) { if (ctx.foo === undefined && !('foo' in props)) {
console.warn("<SvelteComponent> was created without expected data property 'foo'"); console.warn("<SvelteComponent> was created without expected prop 'foo'");
} }
if (ctx.bar === undefined) { if (ctx.bar === undefined && !('bar' in props)) {
console.warn("<SvelteComponent> was created without expected data property 'bar'"); console.warn("<SvelteComponent> was created without expected prop 'bar'");
} }
if (ctx.baz === undefined) { if (ctx.baz === undefined && !('baz' in props)) {
console.warn("<SvelteComponent> was created without expected data property 'baz'"); console.warn("<SvelteComponent> was created without expected prop 'baz'");
} }
} }

@ -156,11 +156,12 @@ class SvelteComponent extends SvelteComponentDev {
init(this, options, instance, create_fragment, safe_not_equal); init(this, options, instance, create_fragment, safe_not_equal);
const { ctx } = this.$$; const { ctx } = this.$$;
if (ctx.things === undefined) { const props = options.props || {};
console.warn("<SvelteComponent> was created without expected data property 'things'"); if (ctx.things === undefined && !('things' in props)) {
console.warn("<SvelteComponent> was created without expected prop 'things'");
} }
if (ctx.foo === undefined) { if (ctx.foo === undefined && !('foo' in props)) {
console.warn("<SvelteComponent> was created without expected data property 'foo'"); console.warn("<SvelteComponent> was created without expected prop 'foo'");
} }
} }

@ -76,8 +76,9 @@ class SvelteComponent extends SvelteComponentDev {
init(this, options, instance, create_fragment, safe_not_equal); init(this, options, instance, create_fragment, safe_not_equal);
const { ctx } = this.$$; const { ctx } = this.$$;
if (ctx.foo === undefined) { const props = options.props || {};
console.warn("<SvelteComponent> was created without expected data property 'foo'"); if (ctx.foo === undefined && !('foo' in props)) {
console.warn("<SvelteComponent> was created without expected prop 'foo'");
} }
} }

@ -4,6 +4,6 @@ export default {
}, },
warnings: [ warnings: [
`<Main$> was created without expected data property 'value'` `<Main$> was created without expected prop 'value'`
] ]
}; };

@ -0,0 +1,9 @@
export default {
compileOptions: {
dev: true
},
warnings: [
`<Foo$> was created without expected prop 'y'`
]
};

@ -0,0 +1,5 @@
<script>
import Foo from './Foo.html';
</script>
<Foo x={undefined}/>

@ -4,7 +4,7 @@ export default {
}, },
warnings: [ warnings: [
`<Main$> was created without expected data property 'foo'`, `<Main$> was created without expected prop 'foo'`,
`<Main$> was created without expected data property 'bar'` `<Main$> was created without expected prop 'bar'`
] ]
}; };

Loading…
Cancel
Save