Skip to content

Commit bb15368

Browse files
authored
Merge pull request #2881 from sveltejs/gh-2878
dont create unknown prop warnings for $$scope etc, or if component has $$props
2 parents e291893 + dda69db commit bb15368

File tree

11 files changed

+45
-6
lines changed

11 files changed

+45
-6
lines changed

src/compile/render-dom/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,11 @@ export default function dom(
397397
});
398398

399399
let unknown_props_check;
400-
if (component.compile_options.dev && writable_props.length) {
400+
if (component.compile_options.dev && !component.var_lookup.has('$$props') && writable_props.length) {
401401
unknown_props_check = deindent`
402402
const writable_props = [${writable_props.map(prop => `'${prop.export_name}'`).join(', ')}];
403403
Object.keys($$props).forEach(key => {
404-
if (!writable_props.includes(key)) console.warn(\`<${component.tag}> was created with unknown prop '\${key}'\`);
404+
if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(\`<${component.tag}> was created with unknown prop '\${key}'\`);
405405
});
406406
`;
407407
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function instance($$self, $$props, $$invalidate) {
6767

6868
const writable_props = ['name'];
6969
Object.keys($$props).forEach(key => {
70-
if (!writable_props.includes(key)) console.warn(`<Component> was created with unknown prop '${key}'`);
70+
if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(`<Component> was created with unknown prop '${key}'`);
7171
});
7272

7373
$$self.$set = $$props => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function instance($$self, $$props, $$invalidate) {
153153

154154
const writable_props = ['things', 'foo', 'bar', 'baz'];
155155
Object.keys($$props).forEach(key => {
156-
if (!writable_props.includes(key)) console.warn(`<Component> was created with unknown prop '${key}'`);
156+
if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(`<Component> was created with unknown prop '${key}'`);
157157
});
158158

159159
$$self.$set = $$props => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function instance($$self, $$props, $$invalidate) {
153153

154154
const writable_props = ['things', 'foo'];
155155
Object.keys($$props).forEach(key => {
156-
if (!writable_props.includes(key)) console.warn(`<Component> was created with unknown prop '${key}'`);
156+
if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(`<Component> was created with unknown prop '${key}'`);
157157
});
158158

159159
$$self.$set = $$props => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function instance($$self, $$props, $$invalidate) {
6767

6868
const writable_props = ['foo'];
6969
Object.keys($$props).forEach(key => {
70-
if (!writable_props.includes(key)) console.warn(`<Component> was created with unknown prop '${key}'`);
70+
if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(`<Component> was created with unknown prop '${key}'`);
7171
});
7272

7373
$$self.$set = $$props => {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
export let foo = undefined;
3+
4+
</script>
5+
6+
<div>{foo}</div>
7+
<div>{JSON.stringify($$props)}</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
compileOptions: {
3+
dev: true
4+
},
5+
6+
warnings: []
7+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
import Foo from './Foo.svelte';
3+
</script>
4+
5+
<Foo fo="sho"/>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
export let answer;
3+
</script>
4+
5+
<h1>{answer}</h1>
6+
<div><slot></slot></div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
compileOptions: {
3+
dev: true
4+
},
5+
6+
warnings: []
7+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
import Foo from './Foo.svelte';
3+
</script>
4+
5+
<Foo answer={42}>
6+
bar
7+
</Foo>

0 commit comments

Comments
 (0)