Skip to content

Commit

Permalink
Merge pull request #3849 from AlbertLucianto/fix/file-input-binding-d…
Browse files Browse the repository at this point in the history
…eclared-last

fix input binding fails if type declared last
  • Loading branch information
Rich-Harris authored Nov 6, 2019
2 parents a0c934d + 15cc6f7 commit 70de6a2
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/compiler/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ export default class Element extends Node {
}
}

// Binding relies on Attribute, defer its evaluation
const order = ['Binding']; // everything else is -1
info.attributes.sort((a, b) => order.indexOf(a.type) - order.indexOf(b.type));

info.attributes.forEach(node => {
switch (node.type) {
case 'Action':
Expand Down
82 changes: 82 additions & 0 deletions test/js/samples/bindings-readonly-order/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {
SvelteComponent,
attr,
detach,
element,
init,
insert,
listen,
noop,
run_all,
safe_not_equal,
space
} from "svelte/internal";

function create_fragment(ctx) {
let input0;
let t;
let input1;
let dispose;

return {
c() {
input0 = element("input");
t = space();
input1 = element("input");
attr(input0, "type", "file");
attr(input1, "type", "file");

dispose = [
listen(input0, "change", ctx.input0_change_handler),
listen(input1, "change", ctx.input1_change_handler)
];
},
m(target, anchor) {
insert(target, input0, anchor);
insert(target, t, anchor);
insert(target, input1, anchor);
},
p: noop,
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(input0);
if (detaching) detach(t);
if (detaching) detach(input1);
run_all(dispose);
}
};
}

function instance($$self, $$props, $$invalidate) {
let { files } = $$props;

function input0_change_handler() {
files = this.files;
$$invalidate("files", files);
}

function input1_change_handler() {
files = this.files;
$$invalidate("files", files);
}

$$self.$set = $$props => {
if ("files" in $$props) $$invalidate("files", files = $$props.files);
};

return {
files,
input0_change_handler,
input1_change_handler
};
}

class Component extends SvelteComponent {
constructor(options) {
super();
init(this, options, instance, create_fragment, safe_not_equal, { files: 0 });
}
}

export default Component;
6 changes: 6 additions & 0 deletions test/js/samples/bindings-readonly-order/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
export let files;
</script>

<input type="file" bind:files>
<input bind:files type="file">

0 comments on commit 70de6a2

Please sign in to comment.