From 4116b9d8b12548a0512f4245ad7996fd11ed024c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 18 Nov 2017 14:07:21 -0500 Subject: [PATCH 1/3] use + // + if (node.name === 'option' && !valueAttribute) { + node.attributes.push({ + type: 'Attribute', + name: 'value', + value: node.children + }); + } + // special case — in a case like this... // // `? - const dependencies = block.findDependencies(value.value); + const dependencies = block.findDependencies(valueAttribute.value); state.selectBindingDependencies = dependencies; dependencies.forEach((prop: string) => { generator.indirectDependencies.set(prop, new Set()); diff --git a/src/generators/server-side-rendering/preprocess.ts b/src/generators/server-side-rendering/preprocess.ts index a8a790f754..afddae077c 100644 --- a/src/generators/server-side-rendering/preprocess.ts +++ b/src/generators/server-side-rendering/preprocess.ts @@ -69,6 +69,19 @@ const preprocessors = { if (slot && isChildOfComponent(node, generator)) { node.slotted = true; } + + // Treat these the same way: + // + // + const valueAttribute = node.attributes.find((attribute: Node) => attribute.name === 'value'); + + if (node.name === 'option' && !valueAttribute) { + node.attributes.push({ + type: 'Attribute', + name: 'value', + value: node.children + }); + } } if (node.children.length) { diff --git a/test/runtime/samples/binding-select-implicit-option-value/_config.js b/test/runtime/samples/binding-select-implicit-option-value/_config.js new file mode 100644 index 0000000000..40a7364797 --- /dev/null +++ b/test/runtime/samples/binding-select-implicit-option-value/_config.js @@ -0,0 +1,40 @@ +export default { + data: { + values: [1, 2, 3], + foo: 2 + }, + + html: ` + + +

foo: 2

+ `, + + test(assert, component, target, window) { + const select = target.querySelector('select'); + const options = [...target.querySelectorAll('option')]; + + assert.ok(options[1].selected); + assert.equal(component.get('foo'), 2); + + const change = new window.Event('change'); + + options[2].selected = true; + select.dispatchEvent(change); + + assert.equal(component.get('foo'), 3); + assert.htmlEqual( target.innerHTML, ` + + +

foo: 3

+ ` ); + } +}; diff --git a/test/runtime/samples/binding-select-implicit-option-value/main.html b/test/runtime/samples/binding-select-implicit-option-value/main.html new file mode 100644 index 0000000000..ec5cc84a8d --- /dev/null +++ b/test/runtime/samples/binding-select-implicit-option-value/main.html @@ -0,0 +1,7 @@ + + +

foo: {{foo}}

\ No newline at end of file From cd97521daa76d4d2370ba72c830891266732fa4b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 18 Nov 2017 14:13:31 -0500 Subject: [PATCH 2/3] update tests --- .../_config.js | 6 +++--- .../samples/binding-select-initial-value/_config.js | 6 +++--- test/runtime/samples/binding-select-late/_config.js | 6 +++--- test/runtime/samples/binding-select/_config.js | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/test/runtime/samples/binding-select-initial-value-undefined/_config.js b/test/runtime/samples/binding-select-initial-value-undefined/_config.js index d5944ae815..f625000edb 100644 --- a/test/runtime/samples/binding-select-initial-value-undefined/_config.js +++ b/test/runtime/samples/binding-select-initial-value-undefined/_config.js @@ -5,9 +5,9 @@ export default {

selected: a

selected: a

diff --git a/test/runtime/samples/binding-select-initial-value/_config.js b/test/runtime/samples/binding-select-initial-value/_config.js index 99a7129262..7338af165f 100644 --- a/test/runtime/samples/binding-select-initial-value/_config.js +++ b/test/runtime/samples/binding-select-initial-value/_config.js @@ -3,9 +3,9 @@ export default {

selected: b

selected: b

diff --git a/test/runtime/samples/binding-select-late/_config.js b/test/runtime/samples/binding-select-late/_config.js index 2fffa0e4ed..04b94613fc 100644 --- a/test/runtime/samples/binding-select-late/_config.js +++ b/test/runtime/samples/binding-select-late/_config.js @@ -22,9 +22,9 @@ export default { assert.htmlEqual( target.innerHTML, `

selected: two

` ); diff --git a/test/runtime/samples/binding-select/_config.js b/test/runtime/samples/binding-select/_config.js index 7fce00f327..8c8eced7bc 100644 --- a/test/runtime/samples/binding-select/_config.js +++ b/test/runtime/samples/binding-select/_config.js @@ -3,9 +3,9 @@ export default {

selected: one

selected: one

@@ -32,9 +32,9 @@ export default {

selected: two

selected: two

From 481f7bc37c07f9d583d3903362644133b32a8e25 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 18 Nov 2017 14:17:07 -0500 Subject: [PATCH 3/3] remove unused code --- src/generators/dom/visitors/Element/Element.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/generators/dom/visitors/Element/Element.ts b/src/generators/dom/visitors/Element/Element.ts index 6c7a307fab..f678dec9e8 100644 --- a/src/generators/dom/visitors/Element/Element.ts +++ b/src/generators/dom/visitors/Element/Element.ts @@ -190,19 +190,6 @@ export default function visitElement( visitAttributesAndAddProps(); } - // special case – bound