From 402106330530965ff5a1a5f05fc6529403486328 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Wed, 8 Jul 2020 01:50:35 +0800 Subject: [PATCH] spread condition for input element (#5004) --- CHANGELOG.md | 1 + .../render_dom/wrappers/Element/Attribute.ts | 177 +++++++++++------- .../wrappers/Element/SpreadAttribute.ts | 3 + .../render_dom/wrappers/Element/index.ts | 27 +-- .../InputOne.svelte | 18 ++ .../InputTwo.svelte | 19 ++ .../spread-element-input-value/_config.js | 62 ++++++ .../spread-element-input-value/main.svelte | 9 + .../spread-element-input-value/utils.js | 6 + 9 files changed, 240 insertions(+), 82 deletions(-) create mode 100644 src/compiler/compile/render_dom/wrappers/Element/SpreadAttribute.ts create mode 100644 test/runtime/samples/spread-element-input-value/InputOne.svelte create mode 100644 test/runtime/samples/spread-element-input-value/InputTwo.svelte create mode 100644 test/runtime/samples/spread-element-input-value/_config.js create mode 100644 test/runtime/samples/spread-element-input-value/main.svelte create mode 100644 test/runtime/samples/spread-element-input-value/utils.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 0088e4b0b3..d6fcc626c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Support nullish coalescing (`??`) and optional chaining (`?.`) operators ([#1972](https://github.com/sveltejs/svelte/issues/1972)) * Support `import.meta` ([#4379](https://github.com/sveltejs/svelte/issues/4379)) +* Fix only setting `` values when they're changed when there are spread attributes ([#4418](https://github.com/sveltejs/svelte/issues/4418)) * Fix placement of `{@html}` when used at the root of a slot, at the root of a component, or in `` ([#5012](https://github.com/sveltejs/svelte/issues/5012), [#5071](https://github.com/sveltejs/svelte/pull/5071)) * Fix certain handling of two-way bound `contenteditable` elements ([#5018](https://github.com/sveltejs/svelte/issues/5018)) * Fix handling of `import`ed value that is used as a store and is also mutated ([#5019](https://github.com/sveltejs/svelte/issues/5019)) diff --git a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts index 86b67ca47e..ec281648b8 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts @@ -7,8 +7,9 @@ import { b, x } from 'code-red'; import Expression from '../../../nodes/shared/Expression'; import Text from '../../../nodes/Text'; import handle_select_value_binding from './handle_select_value_binding'; +import { Identifier, Node } from 'estree'; -export default class AttributeWrapper { +export class BaseAttributeWrapper { node: Attribute; parent: ElementWrapper; @@ -21,7 +22,29 @@ export default class AttributeWrapper { parent.not_static_content(); block.add_dependencies(node.dependencies); + } + } + + render(_block: Block) {} +} +export default class AttributeWrapper extends BaseAttributeWrapper { + node: Attribute; + parent: ElementWrapper; + metadata: any; + name: string; + property_name: string; + is_indirectly_bound_value: boolean; + is_src: boolean; + is_select_value_attribute: boolean; + is_input_value: boolean; + should_cache: boolean; + last: Identifier; + + constructor(parent: ElementWrapper, block: Block, node: Attribute) { + super(parent, block, node); + + if (node.dependencies.size > 0) { // special case —