From cb1a76b08c1766b7f68191583352d7a3ef7c5f04 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Mon, 27 May 2019 12:09:21 +0200 Subject: [PATCH 1/2] dont create unknown prop warnings for $$scope etc, or if component has $$props - fixes #2878 --- src/compile/render-dom/index.ts | 4 ++-- .../dev-warning-unknown-props-with-$$props/Foo.svelte | 7 +++++++ .../dev-warning-unknown-props-with-$$props/_config.js | 7 +++++++ .../dev-warning-unknown-props-with-$$props/main.svelte | 5 +++++ .../dev-warning-unknown-props-with-$$scope/Foo.svelte | 6 ++++++ .../dev-warning-unknown-props-with-$$scope/_config.js | 7 +++++++ .../dev-warning-unknown-props-with-$$scope/main.svelte | 7 +++++++ 7 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 test/runtime/samples/dev-warning-unknown-props-with-$$props/Foo.svelte create mode 100644 test/runtime/samples/dev-warning-unknown-props-with-$$props/_config.js create mode 100644 test/runtime/samples/dev-warning-unknown-props-with-$$props/main.svelte create mode 100644 test/runtime/samples/dev-warning-unknown-props-with-$$scope/Foo.svelte create mode 100644 test/runtime/samples/dev-warning-unknown-props-with-$$scope/_config.js create mode 100644 test/runtime/samples/dev-warning-unknown-props-with-$$scope/main.svelte diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index 1432813e9d..2bf8935150 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -395,11 +395,11 @@ export default function dom( }); let unknown_props_check; - if (component.compile_options.dev && writable_props.length) { + if (component.compile_options.dev && !component.var_lookup.has('$$props') && writable_props.length) { unknown_props_check = deindent` const writable_props = [${writable_props.map(prop => `'${prop.export_name}'`).join(', ')}]; Object.keys($$props).forEach(key => { - if (!writable_props.includes(key)) console.warn(\`<${component.tag}> was created with unknown prop '\${key}'\`); + if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(\`<${component.tag}> was created with unknown prop '\${key}'\`); }); `; } diff --git a/test/runtime/samples/dev-warning-unknown-props-with-$$props/Foo.svelte b/test/runtime/samples/dev-warning-unknown-props-with-$$props/Foo.svelte new file mode 100644 index 0000000000..9e5c62339d --- /dev/null +++ b/test/runtime/samples/dev-warning-unknown-props-with-$$props/Foo.svelte @@ -0,0 +1,7 @@ + + +
{foo}
+
{JSON.stringify($$props)}
diff --git a/test/runtime/samples/dev-warning-unknown-props-with-$$props/_config.js b/test/runtime/samples/dev-warning-unknown-props-with-$$props/_config.js new file mode 100644 index 0000000000..62ad08624d --- /dev/null +++ b/test/runtime/samples/dev-warning-unknown-props-with-$$props/_config.js @@ -0,0 +1,7 @@ +export default { + compileOptions: { + dev: true + }, + + warnings: [] +}; diff --git a/test/runtime/samples/dev-warning-unknown-props-with-$$props/main.svelte b/test/runtime/samples/dev-warning-unknown-props-with-$$props/main.svelte new file mode 100644 index 0000000000..1566cf3e41 --- /dev/null +++ b/test/runtime/samples/dev-warning-unknown-props-with-$$props/main.svelte @@ -0,0 +1,5 @@ + + + diff --git a/test/runtime/samples/dev-warning-unknown-props-with-$$scope/Foo.svelte b/test/runtime/samples/dev-warning-unknown-props-with-$$scope/Foo.svelte new file mode 100644 index 0000000000..b9f7feec24 --- /dev/null +++ b/test/runtime/samples/dev-warning-unknown-props-with-$$scope/Foo.svelte @@ -0,0 +1,6 @@ + + +

{answer}

+
diff --git a/test/runtime/samples/dev-warning-unknown-props-with-$$scope/_config.js b/test/runtime/samples/dev-warning-unknown-props-with-$$scope/_config.js new file mode 100644 index 0000000000..62ad08624d --- /dev/null +++ b/test/runtime/samples/dev-warning-unknown-props-with-$$scope/_config.js @@ -0,0 +1,7 @@ +export default { + compileOptions: { + dev: true + }, + + warnings: [] +}; diff --git a/test/runtime/samples/dev-warning-unknown-props-with-$$scope/main.svelte b/test/runtime/samples/dev-warning-unknown-props-with-$$scope/main.svelte new file mode 100644 index 0000000000..a1656e86e0 --- /dev/null +++ b/test/runtime/samples/dev-warning-unknown-props-with-$$scope/main.svelte @@ -0,0 +1,7 @@ + + + + bar + From dda69dbad038354786c7eba5e2e24eff290f759f Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Mon, 27 May 2019 12:14:51 +0200 Subject: [PATCH 2/2] update tests --- test/js/samples/debug-empty/expected.js | 2 +- test/js/samples/debug-foo-bar-baz-things/expected.js | 2 +- test/js/samples/debug-foo/expected.js | 2 +- test/js/samples/dev-warning-missing-data-computed/expected.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/js/samples/debug-empty/expected.js b/test/js/samples/debug-empty/expected.js index c82cbeddd3..6f07993590 100644 --- a/test/js/samples/debug-empty/expected.js +++ b/test/js/samples/debug-empty/expected.js @@ -67,7 +67,7 @@ function instance($$self, $$props, $$invalidate) { const writable_props = ['name']; Object.keys($$props).forEach(key => { - if (!writable_props.includes(key)) console.warn(` was created with unknown prop '${key}'`); + if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(` was created with unknown prop '${key}'`); }); $$self.$set = $$props => { diff --git a/test/js/samples/debug-foo-bar-baz-things/expected.js b/test/js/samples/debug-foo-bar-baz-things/expected.js index 3e1571b890..eea35d5ba7 100644 --- a/test/js/samples/debug-foo-bar-baz-things/expected.js +++ b/test/js/samples/debug-foo-bar-baz-things/expected.js @@ -153,7 +153,7 @@ function instance($$self, $$props, $$invalidate) { const writable_props = ['things', 'foo', 'bar', 'baz']; Object.keys($$props).forEach(key => { - if (!writable_props.includes(key)) console.warn(` was created with unknown prop '${key}'`); + if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(` was created with unknown prop '${key}'`); }); $$self.$set = $$props => { diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js index 1af0fcaebe..5b931d9464 100644 --- a/test/js/samples/debug-foo/expected.js +++ b/test/js/samples/debug-foo/expected.js @@ -153,7 +153,7 @@ function instance($$self, $$props, $$invalidate) { const writable_props = ['things', 'foo']; Object.keys($$props).forEach(key => { - if (!writable_props.includes(key)) console.warn(` was created with unknown prop '${key}'`); + if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(` was created with unknown prop '${key}'`); }); $$self.$set = $$props => { diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js index 0c193934c0..5c4b2ece1b 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -67,7 +67,7 @@ function instance($$self, $$props, $$invalidate) { const writable_props = ['foo']; Object.keys($$props).forEach(key => { - if (!writable_props.includes(key)) console.warn(` was created with unknown prop '${key}'`); + if (!writable_props.includes(key) && !key.startsWith('$$')) console.warn(` was created with unknown prop '${key}'`); }); $$self.$set = $$props => {