From cedd98f9406abcc56610c5f85ce78d51d014e6a0 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Tue, 27 Jul 2021 22:23:58 +0800 Subject: [PATCH] fix do not warn about missing props for bindings --- src/compiler/compile/render_dom/index.ts | 14 ++++++++------ .../Foo.svelte | 8 ++++++++ .../_config.js | 9 +++++++++ .../main.svelte | 8 ++++++++ 4 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 test/runtime/samples/dev-warning-missing-data-component-bind/Foo.svelte create mode 100644 test/runtime/samples/dev-warning-missing-data-component-bind/_config.js create mode 100644 test/runtime/samples/dev-warning-missing-data-component-bind/main.svelte diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index 535983cfd08e..6a443019516d 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -180,12 +180,14 @@ export default function dom( if (expected.length) { dev_props_check = b` - const { ctx: #ctx } = this.$$; - const props = ${options.customElement ? x`this.attributes` : x`options.props || {}`}; - ${expected.map(prop => b` - if (${renderer.reference(prop.name)} === undefined && !('${prop.export_name}' in props)) { - @_console.warn("<${component.tag}> was created without expected prop '${prop.export_name}'"); - }`)} + const { ctx: #ctx, on_mount: #on_mount, bound: #bound, props: #props } = this.$$; + #on_mount.push(function () { + const props = ${options.customElement ? x`this.attributes` : x`options.props || {}`}; + ${expected.map(prop => b` + if (${renderer.reference(prop.name)} === undefined && !('${prop.export_name}' in props || #bound[#props['${prop.export_name}']])) { + @_console.warn("<${component.tag}> was created without expected prop '${prop.export_name}'"); + }`)} + }); `; } diff --git a/test/runtime/samples/dev-warning-missing-data-component-bind/Foo.svelte b/test/runtime/samples/dev-warning-missing-data-component-bind/Foo.svelte new file mode 100644 index 000000000000..60278c4845e2 --- /dev/null +++ b/test/runtime/samples/dev-warning-missing-data-component-bind/Foo.svelte @@ -0,0 +1,8 @@ + + +
{w} {x} {y}
\ No newline at end of file diff --git a/test/runtime/samples/dev-warning-missing-data-component-bind/_config.js b/test/runtime/samples/dev-warning-missing-data-component-bind/_config.js new file mode 100644 index 000000000000..ececa00a8c40 --- /dev/null +++ b/test/runtime/samples/dev-warning-missing-data-component-bind/_config.js @@ -0,0 +1,9 @@ +export default { + compileOptions: { + dev: true + }, + + warnings: [ + " was created without expected prop 'y'" + ] +}; diff --git a/test/runtime/samples/dev-warning-missing-data-component-bind/main.svelte b/test/runtime/samples/dev-warning-missing-data-component-bind/main.svelte new file mode 100644 index 000000000000..eab3c8336fc7 --- /dev/null +++ b/test/runtime/samples/dev-warning-missing-data-component-bind/main.svelte @@ -0,0 +1,8 @@ + + + \ No newline at end of file