add dev mode missing prop check

pull/1864/head
Rich Harris 7 years ago
parent 93110e9c4b
commit db31d920a0

@ -102,7 +102,7 @@ export default function dom(
const body = []; const body = [];
const debug_name = `<${component.customElement ? component.tag : name}>`; const debug_name = `<${component.customElement ? component.customElement.tag : name}>`;
const not_equal = component.options.immutable ? `@not_equal` : `@safe_not_equal`; const not_equal = component.options.immutable ? `@not_equal` : `@safe_not_equal`;
let dev_props_check; let dev_props_check;
@ -141,7 +141,7 @@ export default function dom(
const state = this.$$.get(); const state = this.$$.get();
${expected.map(name => deindent` ${expected.map(name => deindent`
if (state.${name} === undefined) { if (state.${name} === undefined${component.customElement && ` && !('${name}' in this.attributes)`}) {
console.warn("${debug_name} was created without expected data property '${name}'"); console.warn("${debug_name} was created without expected data property '${name}'");
}`)} }`)}
`; `;
@ -184,6 +184,8 @@ export default function dom(
@init(this, { target: this.shadowRoot }, define, create_fragment, ${not_equal}); @init(this, { target: this.shadowRoot }, define, create_fragment, ${not_equal});
${dev_props_check}
if (options) { if (options) {
if (options.target) { if (options.target) {
@insert(options.target, this, options.anchor); @insert(options.target, this, options.anchor);

@ -1,7 +0,0 @@
<svelte:meta tag="my-counter"/>
<script>
export let count = 0;
</script>
<button on:click='{() => count += 1}'>count: {count}</button>

@ -1,10 +0,0 @@
<svelte:meta tag="my-app"/>
<script>
import Counter from './Counter.html';
export let count;
</script>
<Counter bind:count/>
<p>clicked {count} times</p>

@ -1,17 +0,0 @@
import * as assert from 'assert';
import './main.html';
export default async function (target) {
target.innerHTML = '<my-app/>';
const el = target.querySelector('my-app');
const counter = el.shadowRoot.querySelector('my-counter');
const button = counter.shadowRoot.querySelector('button');
assert.equal(counter.count, 0);
assert.equal(counter.shadowRoot.innerHTML, `<button>count: 0</button>`);
await button.dispatchEvent(new MouseEvent('click'));
assert.equal(counter.count, 1);
assert.equal(counter.shadowRoot.innerHTML, `<button>count: 1</button>`);
}
Loading…
Cancel
Save