Skip to content

Commit

Permalink
Merge branch 'master' into gh-1834
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Aug 20, 2019
2 parents 97f3d56 + 63a7a37 commit fa222e7
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/compiler/compile/render_dom/wrappers/Element/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ function get_dom_updater(
return `${element.var}.checked = ${condition};`;
}

if (binding.node.name === 'value') {
return `@set_input_value(${element.var}, ${binding.snippet});`
}

return `${element.var}.${binding.node.name} = ${binding.snippet};`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile/render_ssr/handlers/Slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function(node: Slot, renderer: Renderer, options: RenderOptions)

const slot_data = get_slot_data(node.values, true);

const arg = slot_data.length > 0 ? `{ ${slot_data.join(', ')} }` : '';
const arg = slot_data.length > 0 ? `{ ${slot_data.join(', ')} }` : '{}';

renderer.append(`\${$$slots${prop} ? $$slots${prop}(${arg}) : \``);

Expand Down
6 changes: 6 additions & 0 deletions src/runtime/internal/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ export function set_data(text, data) {
if (text.data !== data) text.data = data;
}

export function set_input_value(input, value) {
if (value != null || input.value) {
input.value = value;
}
}

export function set_input_type(input, type) {
try {
input.type = type;
Expand Down
87 changes: 87 additions & 0 deletions test/js/samples/input-no-initial-value/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* generated by Svelte vX.Y.Z */
import {
SvelteComponent,
append,
attr,
detach,
element,
init,
insert,
listen,
noop,
run_all,
safe_not_equal,
set_input_value,
space
} from "svelte/internal";

function create_fragment(ctx) {
var form, input, t, button, dispose;

return {
c() {
form = element("form");
input = element("input");
t = space();
button = element("button");
button.textContent = "Store";
attr(input, "type", "text");
input.required = true;

dispose = [
listen(input, "input", ctx.input_input_handler),
listen(form, "submit", ctx.handleSubmit)
];
},

m(target, anchor) {
insert(target, form, anchor);
append(form, input);

set_input_value(input, ctx.test);

append(form, t);
append(form, button);
},

p(changed, ctx) {
if (changed.test && (input.value !== ctx.test)) set_input_value(input, ctx.test);
},

i: noop,
o: noop,

d(detaching) {
if (detaching) {
detach(form);
}

run_all(dispose);
}
};
}

function instance($$self, $$props, $$invalidate) {
let test = undefined;

function handleSubmit(event) {
event.preventDefault();
console.log('value', test);
}

function input_input_handler() {
test = this.value;
$$invalidate('test', test);
}

return { test, handleSubmit, input_input_handler };
}

class Component extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance, create_fragment, safe_not_equal, []);
}
}

export default Component;
13 changes: 13 additions & 0 deletions test/js/samples/input-no-initial-value/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
let test = undefined;
function handleSubmit(event) {
event.preventDefault();
console.log('value', test);
}
</script>

<form on:submit={handleSubmit}>
<input bind:value={test} type=text required>
<button>Store</button>
</form>
5 changes: 3 additions & 2 deletions test/js/samples/input-range/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
noop,
run_all,
safe_not_equal,
set_input_value,
to_number
} from "svelte/internal";

Expand All @@ -30,11 +31,11 @@ function create_fragment(ctx) {
m(target, anchor) {
insert(target, input, anchor);

input.value = ctx.value;
set_input_value(input, ctx.value);
},

p(changed, ctx) {
if (changed.value) input.value = ctx.value;
if (changed.value) set_input_value(input, ctx.value);
},

i: noop,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let thing;
</script>

<p>{thing}</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<slot></slot>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
html: `
<p>undefined</p>
`
};
10 changes: 10 additions & 0 deletions test/runtime/samples/component-slot-let-missing-prop/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
import Foo from './Foo.svelte';
import Bar from './Bar.svelte';
const things = { '1': 'one' };
</script>

<Foo let:id>
<Bar thing={things[id]}/>
</Foo>

0 comments on commit fa222e7

Please sign in to comment.