Skip to content

Commit

Permalink
Merge pull request #1907 from sveltejs/gh-1902
Browse files Browse the repository at this point in the history
remove missing prop warning false positives
  • Loading branch information
Rich-Harris authored Dec 23, 2018
2 parents 4fbc0c0 + 7440fa5 commit eefe120
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/compile/render-dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ export default function dom(
if (expected.length) {
dev_props_check = deindent`
const { ctx } = this.$$;
const props = ${options.customElement ? `this.attributes` : `options.props || {}`};
${expected.map(name => deindent`
if (ctx.${name} === undefined${options.customElement && ` && !('${name}' in this.attributes)`}) {
console.warn("<${component.tag}> was created without expected data property '${name}'");
if (ctx.${name} === undefined && !('${name}' in props)) {
console.warn("<${component.tag}> was created without expected prop '${name}'");
}`)}
`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function (target) {
target.innerHTML = '<my-app foo=yes />';

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;
}
5 changes: 3 additions & 2 deletions test/js/samples/debug-empty/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ class SvelteComponent extends SvelteComponentDev {
init(this, options, instance, create_fragment, safe_not_equal);

const { ctx } = this.$$;
if (ctx.name === undefined) {
console.warn("<SvelteComponent> was created without expected data property 'name'");
const props = options.props || {};
if (ctx.name === undefined && !('name' in props)) {
console.warn("<SvelteComponent> was created without expected prop 'name'");
}
}

Expand Down
17 changes: 9 additions & 8 deletions test/js/samples/debug-foo-bar-baz-things/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,18 @@ class SvelteComponent extends SvelteComponentDev {
init(this, options, instance, create_fragment, safe_not_equal);

const { ctx } = this.$$;
if (ctx.things === undefined) {
console.warn("<SvelteComponent> was created without expected data property 'things'");
const props = options.props || {};
if (ctx.things === undefined && !('things' in props)) {
console.warn("<SvelteComponent> was created without expected prop 'things'");
}
if (ctx.foo === undefined) {
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'");
}
if (ctx.bar === undefined) {
console.warn("<SvelteComponent> was created without expected data property 'bar'");
if (ctx.bar === undefined && !('bar' in props)) {
console.warn("<SvelteComponent> was created without expected prop 'bar'");
}
if (ctx.baz === undefined) {
console.warn("<SvelteComponent> was created without expected data property 'baz'");
if (ctx.baz === undefined && !('baz' in props)) {
console.warn("<SvelteComponent> was created without expected prop 'baz'");
}
}

Expand Down
9 changes: 5 additions & 4 deletions test/js/samples/debug-foo/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,12 @@ class SvelteComponent extends SvelteComponentDev {
init(this, options, instance, create_fragment, safe_not_equal);

const { ctx } = this.$$;
if (ctx.things === undefined) {
console.warn("<SvelteComponent> was created without expected data property 'things'");
const props = options.props || {};
if (ctx.things === undefined && !('things' in props)) {
console.warn("<SvelteComponent> was created without expected prop 'things'");
}
if (ctx.foo === undefined) {
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'");
}
}

Expand Down
5 changes: 3 additions & 2 deletions test/js/samples/dev-warning-missing-data-computed/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ class SvelteComponent extends SvelteComponentDev {
init(this, options, instance, create_fragment, safe_not_equal);

const { ctx } = this.$$;
if (ctx.foo === undefined) {
console.warn("<SvelteComponent> was created without expected data property 'foo'");
const props = options.props || {};
if (ctx.foo === undefined && !('foo' in props)) {
console.warn("<SvelteComponent> was created without expected prop 'foo'");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export default {
},

warnings: [
`<Main$> was created without expected data property 'value'`
`<Main$> was created without expected prop 'value'`
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>{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,5 @@
<script>
import Foo from './Foo.html';
</script>

<Foo x={undefined}/>
4 changes: 2 additions & 2 deletions test/runtime/samples/dev-warning-missing-data/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
},

warnings: [
`<Main$> was created without expected data property 'foo'`,
`<Main$> was created without expected data property 'bar'`
`<Main$> was created without expected prop 'foo'`,
`<Main$> was created without expected prop 'bar'`
]
};

0 comments on commit eefe120

Please sign in to comment.