Skip to content

Commit eefe120

Browse files
authored
Merge pull request sveltejs#1907 from sveltejs/sveltejsgh-1902
remove missing prop warning false positives
2 parents 4fbc0c0 + 7440fa5 commit eefe120

File tree

11 files changed

+42
-23
lines changed

11 files changed

+42
-23
lines changed

src/compile/render-dom/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ export default function dom(
131131
if (expected.length) {
132132
dev_props_check = deindent`
133133
const { ctx } = this.$$;
134+
const props = ${options.customElement ? `this.attributes` : `options.props || {}`};
134135
${expected.map(name => deindent`
135-
136-
if (ctx.${name} === undefined${options.customElement && ` && !('${name}' in this.attributes)`}) {
137-
console.warn("<${component.tag}> was created without expected data property '${name}'");
136+
if (ctx.${name} === undefined && !('${name}' in props)) {
137+
console.warn("<${component.tag}> was created without expected prop '${name}'");
138138
}`)}
139139
`;
140140
}

test/custom-elements/samples/no-missing-prop-warnings/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function (target) {
1212
target.innerHTML = '<my-app foo=yes />';
1313

1414
assert.equal(warnings.length, 1);
15-
assert.equal(warnings[0], `<my-app> was created without expected data property 'bar'`);
15+
assert.equal(warnings[0], `<my-app> was created without expected prop 'bar'`);
1616

1717
console.warn = warn;
1818
}

test/js/samples/debug-empty/expected.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ class SvelteComponent extends SvelteComponentDev {
7070
init(this, options, instance, create_fragment, safe_not_equal);
7171

7272
const { ctx } = this.$$;
73-
if (ctx.name === undefined) {
74-
console.warn("<SvelteComponent> was created without expected data property 'name'");
73+
const props = options.props || {};
74+
if (ctx.name === undefined && !('name' in props)) {
75+
console.warn("<SvelteComponent> was created without expected prop 'name'");
7576
}
7677
}
7778

test/js/samples/debug-foo-bar-baz-things/expected.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,18 @@ class SvelteComponent extends SvelteComponentDev {
158158
init(this, options, instance, create_fragment, safe_not_equal);
159159

160160
const { ctx } = this.$$;
161-
if (ctx.things === undefined) {
162-
console.warn("<SvelteComponent> was created without expected data property 'things'");
161+
const props = options.props || {};
162+
if (ctx.things === undefined && !('things' in props)) {
163+
console.warn("<SvelteComponent> was created without expected prop 'things'");
163164
}
164-
if (ctx.foo === undefined) {
165-
console.warn("<SvelteComponent> was created without expected data property 'foo'");
165+
if (ctx.foo === undefined && !('foo' in props)) {
166+
console.warn("<SvelteComponent> was created without expected prop 'foo'");
166167
}
167-
if (ctx.bar === undefined) {
168-
console.warn("<SvelteComponent> was created without expected data property 'bar'");
168+
if (ctx.bar === undefined && !('bar' in props)) {
169+
console.warn("<SvelteComponent> was created without expected prop 'bar'");
169170
}
170-
if (ctx.baz === undefined) {
171-
console.warn("<SvelteComponent> was created without expected data property 'baz'");
171+
if (ctx.baz === undefined && !('baz' in props)) {
172+
console.warn("<SvelteComponent> was created without expected prop 'baz'");
172173
}
173174
}
174175

test/js/samples/debug-foo/expected.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,12 @@ class SvelteComponent extends SvelteComponentDev {
156156
init(this, options, instance, create_fragment, safe_not_equal);
157157

158158
const { ctx } = this.$$;
159-
if (ctx.things === undefined) {
160-
console.warn("<SvelteComponent> was created without expected data property 'things'");
159+
const props = options.props || {};
160+
if (ctx.things === undefined && !('things' in props)) {
161+
console.warn("<SvelteComponent> was created without expected prop 'things'");
161162
}
162-
if (ctx.foo === undefined) {
163-
console.warn("<SvelteComponent> was created without expected data property 'foo'");
163+
if (ctx.foo === undefined && !('foo' in props)) {
164+
console.warn("<SvelteComponent> was created without expected prop 'foo'");
164165
}
165166
}
166167

test/js/samples/dev-warning-missing-data-computed/expected.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ class SvelteComponent extends SvelteComponentDev {
7676
init(this, options, instance, create_fragment, safe_not_equal);
7777

7878
const { ctx } = this.$$;
79-
if (ctx.foo === undefined) {
80-
console.warn("<SvelteComponent> was created without expected data property 'foo'");
79+
const props = options.props || {};
80+
if (ctx.foo === undefined && !('foo' in props)) {
81+
console.warn("<SvelteComponent> was created without expected prop 'foo'");
8182
}
8283
}
8384

test/runtime/samples/dev-warning-missing-data-binding/_config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export default {
44
},
55

66
warnings: [
7-
`<Main$> was created without expected data property 'value'`
7+
`<Main$> was created without expected prop 'value'`
88
]
99
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>{x} {y}</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
compileOptions: {
3+
dev: true
4+
},
5+
6+
warnings: [
7+
`<Foo$> was created without expected prop 'y'`
8+
]
9+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
import Foo from './Foo.html';
3+
</script>
4+
5+
<Foo x={undefined}/>

test/runtime/samples/dev-warning-missing-data/_config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
},
55

66
warnings: [
7-
`<Main$> was created without expected data property 'foo'`,
8-
`<Main$> was created without expected data property 'bar'`
7+
`<Main$> was created without expected prop 'foo'`,
8+
`<Main$> was created without expected prop 'bar'`
99
]
1010
};

0 commit comments

Comments
 (0)