From a2fd36f86c90263c7b6984384482e956d81c4905 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 26 Apr 2017 11:41:31 -0400 Subject: [PATCH 1/5] Provide second argument to validator.error with bind:checked errors --- src/validate/html/validateElement.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/validate/html/validateElement.js b/src/validate/html/validateElement.js index beca2086ec..cda56ec730 100644 --- a/src/validate/html/validateElement.js +++ b/src/validate/html/validateElement.js @@ -25,7 +25,7 @@ export default function validateElement ( validator, node ) { } if ( getType( validator, node ) !== 'checkbox' ) { - validator.error( `'checked' binding can only be used with ` ); + validator.error( `'checked' binding can only be used with `, attribute.start ); } } @@ -99,4 +99,4 @@ function getType ( validator, node ) { function list ( items, conjunction = 'or' ) { if ( items.length === 1 ) return items[0]; return `${items.slice( 0, -1 ).join( ', ' )} ${conjunction} ${items[ items.length - 1 ]}`; -} \ No newline at end of file +} From f74941b2939246d3f0685992feb5babcca539aed Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 27 Apr 2017 22:58:53 -0400 Subject: [PATCH 2/5] fix simple if blocks with top-level or conditions (#532) --- src/generators/dom/visitors/IfBlock.js | 4 ++-- test/js/samples/if-block-simple/expected.js | 4 ++-- .../samples/use-elements-as-anchors/expected.js | 12 ++++++------ test/runtime/samples/if-block-or/_config.js | 15 +++++++++++++++ test/runtime/samples/if-block-or/main.html | 3 +++ 5 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 test/runtime/samples/if-block-or/_config.js create mode 100644 test/runtime/samples/if-block-or/main.html diff --git a/src/generators/dom/visitors/IfBlock.js b/src/generators/dom/visitors/IfBlock.js index e6c3d9952a..94be3a4081 100644 --- a/src/generators/dom/visitors/IfBlock.js +++ b/src/generators/dom/visitors/IfBlock.js @@ -68,7 +68,7 @@ export default function visitIfBlock ( generator, block, state, node ) { function simple ( generator, block, state, node, branch, dynamic, { name, anchor, params } ) { block.builders.create.addBlock( deindent` - var ${name} = ${branch.condition} && ${branch.block}( ${params}, ${block.component} ); + var ${name} = (${branch.condition}) && ${branch.block}( ${params}, ${block.component} ); ` ); const isToplevel = !state.parentNode; @@ -154,4 +154,4 @@ function compound ( generator, block, state, node, branches, dynamic, { name, an } ` ); } -} \ No newline at end of file +} diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index c31e4ae914..c53da20d04 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -3,7 +3,7 @@ import { appendNode, assign, createComment, createElement, createText, detachNod function create_main_fragment ( state, component ) { var if_block_anchor = createComment(); - var if_block = state.foo && create_if_block( state, component ); + var if_block = (state.foo) && create_if_block( state, component ); return { mount: function ( target, anchor ) { @@ -90,4 +90,4 @@ SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = functio this._torndown = true; }; -export default SvelteComponent; \ No newline at end of file +export default SvelteComponent; diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 792dac264e..a7685adbaf 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -3,7 +3,7 @@ import { appendNode, assign, createComment, createElement, createText, detachNod function create_main_fragment ( state, component ) { var div = createElement( 'div' ); - var if_block = state.a && create_if_block( state, component ); + var if_block = (state.a) && create_if_block( state, component ); if ( if_block ) if_block.mount( div, null ); var text = createText( "\n\n\t" ); @@ -13,13 +13,13 @@ function create_main_fragment ( state, component ) { appendNode( createText( "this can be used as an anchor" ), p ); appendNode( createText( "\n\n\t" ), div ); - var if_block_1 = state.b && create_if_block_1( state, component ); + var if_block_1 = (state.b) && create_if_block_1( state, component ); if ( if_block_1 ) if_block_1.mount( div, null ); var text_3 = createText( "\n\n\t" ); appendNode( text_3, div ); - var if_block_2 = state.c && create_if_block_2( state, component ); + var if_block_2 = (state.c) && create_if_block_2( state, component ); if ( if_block_2 ) if_block_2.mount( div, null ); var text_4 = createText( "\n\n\t" ); @@ -29,7 +29,7 @@ function create_main_fragment ( state, component ) { appendNode( createText( "so can this" ), p_1 ); appendNode( createText( "\n\n\t" ), div ); - var if_block_3 = state.d && create_if_block_3( state, component ); + var if_block_3 = (state.d) && create_if_block_3( state, component ); if ( if_block_3 ) if_block_3.mount( div, null ); var text_7 = createText( "\n\n\t" ); @@ -37,7 +37,7 @@ function create_main_fragment ( state, component ) { var text_8 = createText( "\n\n" ); var if_block_4_anchor = createComment(); - var if_block_4 = state.e && create_if_block_4( state, component ); + var if_block_4 = (state.e) && create_if_block_4( state, component ); return { mount: function ( target, anchor ) { @@ -240,4 +240,4 @@ SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = functio this._torndown = true; }; -export default SvelteComponent; \ No newline at end of file +export default SvelteComponent; diff --git a/test/runtime/samples/if-block-or/_config.js b/test/runtime/samples/if-block-or/_config.js new file mode 100644 index 0000000000..ffecd6ca86 --- /dev/null +++ b/test/runtime/samples/if-block-or/_config.js @@ -0,0 +1,15 @@ +export default { + data: { + a: true, + b: false + }, + + html: '

i am visible

', + + test ( assert, component, target ) { + component.set({ a: false }); + assert.htmlEqual( target.innerHTML, '' ); + component.set({ b: true }); + assert.htmlEqual( target.innerHTML, '

i am visible

' ); + } +}; diff --git a/test/runtime/samples/if-block-or/main.html b/test/runtime/samples/if-block-or/main.html new file mode 100644 index 0000000000..68d6158688 --- /dev/null +++ b/test/runtime/samples/if-block-or/main.html @@ -0,0 +1,3 @@ +{{#if a || b}} +

i am visible

+{{/if}} From a5dce59735c16ac060dc289be0b27cf01f548c5c Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 29 Apr 2017 22:51:10 -0400 Subject: [PATCH 3/5] fix parsing of expressions wrapped in parentheses (#534) --- src/parse/read/expression.js | 2 +- .../samples/paren-wrapped-expressions/_config.js | 16 ++++++++++++++++ .../samples/paren-wrapped-expressions/main.html | 8 ++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/paren-wrapped-expressions/_config.js create mode 100644 test/runtime/samples/paren-wrapped-expressions/main.html diff --git a/src/parse/read/expression.js b/src/parse/read/expression.js index 7aa34b9bdc..384e56fd91 100644 --- a/src/parse/read/expression.js +++ b/src/parse/read/expression.js @@ -34,7 +34,7 @@ export default function readExpression ( parser ) { parser.index = start; try { - const node = parseExpressionAt( parser.template, parser.index ); + const node = parseExpressionAt( parser.template, parser.index, { preserveParens: true } ); parser.index = node.end; return node; diff --git a/test/runtime/samples/paren-wrapped-expressions/_config.js b/test/runtime/samples/paren-wrapped-expressions/_config.js new file mode 100644 index 0000000000..4b784625ce --- /dev/null +++ b/test/runtime/samples/paren-wrapped-expressions/_config.js @@ -0,0 +1,16 @@ +export default { + data: { + a: 'foo', + b: true, + c: [ 1, 2, 3 ], + }, + + html: ` + foo + + true + 1 + 2 + 3 + ` +}; diff --git a/test/runtime/samples/paren-wrapped-expressions/main.html b/test/runtime/samples/paren-wrapped-expressions/main.html new file mode 100644 index 0000000000..ec4b4152c4 --- /dev/null +++ b/test/runtime/samples/paren-wrapped-expressions/main.html @@ -0,0 +1,8 @@ +{{ (a) }} + +{{#if (b) }} + true +{{/if}} +{{#each (c) as x}} + {{x}} +{{/each}} From 5e042c4c8e7f02de621607829a7a9a88fa0ab444 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sun, 30 Apr 2017 08:01:18 -0400 Subject: [PATCH 4/5] add test --- test/validator/samples/binding-input-checked/errors.json | 8 ++++++++ test/validator/samples/binding-input-checked/input.html | 1 + 2 files changed, 9 insertions(+) create mode 100644 test/validator/samples/binding-input-checked/errors.json create mode 100644 test/validator/samples/binding-input-checked/input.html diff --git a/test/validator/samples/binding-input-checked/errors.json b/test/validator/samples/binding-input-checked/errors.json new file mode 100644 index 0000000000..05747dc96c --- /dev/null +++ b/test/validator/samples/binding-input-checked/errors.json @@ -0,0 +1,8 @@ +[{ + "message": "'checked' binding can only be used with ", + "loc": { + "line": 1, + "column": 7 + }, + "pos": 7 +}] \ No newline at end of file diff --git a/test/validator/samples/binding-input-checked/input.html b/test/validator/samples/binding-input-checked/input.html new file mode 100644 index 0000000000..9990d3c596 --- /dev/null +++ b/test/validator/samples/binding-input-checked/input.html @@ -0,0 +1 @@ + \ No newline at end of file From a2ce4a4628eb376f81cb86ff9496598fed873c85 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sun, 30 Apr 2017 08:27:09 -0400 Subject: [PATCH 5/5] -> v1.18.2 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13228e0d42..4fba2b61fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Svelte changelog +## 1.18.2 + +* Parenthesize if-block conditions ([#532](https://github.com/sveltejs/svelte/issues/532)) +* Fix parsing of parenthesized expressions ([#534](https://github.com/sveltejs/svelte/issues/534)) +* Fix error on `bind:checked` that doesn't belong to a checkbox input ([#529](https://github.com/sveltejs/svelte/pull/529)) + ## 1.18.1 * Allow `destroy()` in event handlers ([#523](https://github.com/sveltejs/svelte/issues/523)) diff --git a/package.json b/package.json index 0509466da6..fbca94f2f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "1.18.1", + "version": "1.18.2", "description": "The magical disappearing UI framework", "main": "compiler/svelte.js", "files": [