From 6b669ec28e18ad2595dc9120e6ef6f7f618b6e50 Mon Sep 17 00:00:00 2001 From: halfnelson Date: Wed, 9 Sep 2020 22:40:41 +1000 Subject: [PATCH 1/4] Allow unknown namespaced attributes to be emitted in their original case --- .../render_dom/wrappers/Element/Attribute.ts | 33 ++++++++++++++----- .../_config.js | 18 ++++++++++ .../main.svelte | 3 ++ 3 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 test/runtime/samples/attribute-casing-unknown-namespace/_config.js create mode 100644 test/runtime/samples/attribute-casing-unknown-namespace/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts index 258376c3755e..e470a1e0d8ad 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts @@ -8,6 +8,7 @@ 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'; +import { namespaces, valid_namespaces } from '../../../../utils/namespaces'; export class BaseAttributeWrapper { node: Attribute; @@ -65,17 +66,33 @@ export default class AttributeWrapper extends BaseAttributeWrapper { handle_select_value_binding(this, node.dependencies); } } + + const namespace = this.parent.node.namespace; + // some processing only applies to html namespace (and not MathML, SVG, or Svelte Native etc) + if (namespace && namespace != 'html' && namespace != namespaces.html) { + // attributes outside of the html namespaced may be case sensitive + // namespaces for which we don't have case corrections, are left in their original case (required for svelte-native) + this.name = (valid_namespaces.indexOf(namespace) >= 0) ? fix_attribute_casing(this.node.name) : this.node.name; + this.is_indirectly_bound_value = false; + this.metadata = null; + this.property_name = null; + this.is_select_value_attribute = false; + this.is_input_value = false; + } else { + this.name = fix_attribute_casing(this.node.name); + this.metadata = this.get_metadata(); + this.is_indirectly_bound_value = is_indirectly_bound_value(this); + this.property_name = this.is_indirectly_bound_value + ? '__value' + : this.metadata && this.metadata.property_name; + + this.is_select_value_attribute = this.name === 'value' && this.parent.node.name === 'select'; + this.is_input_value = this.name === 'value' && this.parent.node.name === 'input'; + } - this.name = fix_attribute_casing(this.node.name); - this.metadata = this.get_metadata(); - this.is_indirectly_bound_value = is_indirectly_bound_value(this); - this.property_name = this.is_indirectly_bound_value - ? '__value' - : this.metadata && this.metadata.property_name; this.is_src = this.name === 'src'; // TODO retire this exception in favour of https://github.com/sveltejs/svelte/issues/3750 - this.is_select_value_attribute = this.name === 'value' && this.parent.node.name === 'select'; - this.is_input_value = this.name === 'value' && this.parent.node.name === 'input'; this.should_cache = should_cache(this); + } render(block: Block) { diff --git a/test/runtime/samples/attribute-casing-unknown-namespace/_config.js b/test/runtime/samples/attribute-casing-unknown-namespace/_config.js new file mode 100644 index 000000000000..45ee778a49ba --- /dev/null +++ b/test/runtime/samples/attribute-casing-unknown-namespace/_config.js @@ -0,0 +1,18 @@ +// Test support for unknown namespaces preserving attribute case (eg svelte-native). + +export default { + html: ` + +