From 64094f631fafb752418db85a5d4bbabc03e54642 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 3 Aug 2019 13:55:43 -0400 Subject: [PATCH] set data- attributes like regular attributes (#3337) --- .../render_dom/wrappers/Element/Attribute.ts | 14 +------------- test/js/samples/bind-open/expected.js | 2 +- test/js/samples/do-use-dataset/expected.js | 7 ++++--- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts index a05898c437c7..3ced97dcf711 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts @@ -70,11 +70,6 @@ export default class AttributeWrapper { const is_legacy_input_type = element.renderer.component.compile_options.legacy && name === 'type' && this.parent.node.name === 'input'; - const is_dataset = /^data-/.test(name) && !element.renderer.component.compile_options.legacy && !element.node.namespace; - const camel_case_name = is_dataset ? name.replace('data-', '').replace(/(-\w)/g, (m) => { - return m[1].toUpperCase(); - }) : name; - if (this.node.is_dynamic) { let value; @@ -145,11 +140,6 @@ export default class AttributeWrapper { `${element.var}.${property_name} = ${init};` ); updater = `${element.var}.${property_name} = ${should_cache ? last : value};`; - } else if (is_dataset) { - block.builders.hydrate.add_line( - `${element.var}.dataset.${camel_case_name} = ${init};` - ); - updater = `${element.var}.dataset.${camel_case_name} = ${should_cache ? last : value};`; } else { block.builders.hydrate.add_line( `${method}(${element.var}, "${name}", ${init});` @@ -184,9 +174,7 @@ export default class AttributeWrapper { ? `@set_input_type(${element.var}, ${value});` : property_name ? `${element.var}.${property_name} = ${value};` - : is_dataset - ? `${element.var}.dataset.${camel_case_name} = ${value === true ? '""' : value};` - : `${method}(${element.var}, "${name}", ${value === true ? '""' : value});` + : `${method}(${element.var}, "${name}", ${value === true ? '""' : value});` ); block.builders.hydrate.add_line(statement); diff --git a/test/js/samples/bind-open/expected.js b/test/js/samples/bind-open/expected.js index 7c73c8ddac3c..7f739aec8b72 100644 --- a/test/js/samples/bind-open/expected.js +++ b/test/js/samples/bind-open/expected.js @@ -66,4 +66,4 @@ class Component extends SvelteComponent { } } -export default Component; +export default Component; \ No newline at end of file diff --git a/test/js/samples/do-use-dataset/expected.js b/test/js/samples/do-use-dataset/expected.js index 4a1ffc491360..12ba50e69f4e 100644 --- a/test/js/samples/do-use-dataset/expected.js +++ b/test/js/samples/do-use-dataset/expected.js @@ -1,6 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { SvelteComponent, + attr, detach, element, init, @@ -18,8 +19,8 @@ function create_fragment(ctx) { div0 = element("div"); t = space(); div1 = element("div"); - div0.dataset.foo = "bar"; - div1.dataset.foo = ctx.bar; + attr(div0, "data-foo", "bar"); + attr(div1, "data-foo", ctx.bar); }, m(target, anchor) { @@ -30,7 +31,7 @@ function create_fragment(ctx) { p(changed, ctx) { if (changed.bar) { - div1.dataset.foo = ctx.bar; + attr(div1, "data-foo", ctx.bar); } },