From cb1a76b08c1766b7f68191583352d7a3ef7c5f04 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Mon, 27 May 2019 12:09:21 +0200 Subject: [PATCH] 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 +