Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow unknown namespaced attributes to be emitted in their original case #5387

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"posttest": "agadoo internal/index.mjs",
"prepublishOnly": "npm run lint && PUBLISH=true npm test",
"tsd": "tsc -p src/compiler --emitDeclarationOnly && tsc -p src/runtime --emitDeclarationOnly",
"lint": "eslint '{src,test}/**/*.{ts,js}'"
"lint": "eslint \"{src,test}/**/*.{ts,js}\""
},
"repository": {
"type": "git",
Expand Down
32 changes: 24 additions & 8 deletions src/compiler/compile/render_dom/wrappers/Element/Attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { valid_namespaces } from '../../../../utils/namespaces';

export class BaseAttributeWrapper {
node: Attribute;
Expand Down Expand Up @@ -65,16 +66,31 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
handle_select_value_binding(this, node.dependencies);
}
}

const namespace = this.parent.node.namespace;

// some processing only applies to known namespaces
if (namespace && !valid_namespaces.includes(namespace)) {
// attributes outside of the valid namespace may be case sensitive (eg svelte native). We leave them in their current case
this.name = this.node.name;
this.metadata = this.get_metadata();
this.is_indirectly_bound_value = false;
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);
}

Expand Down
18 changes: 18 additions & 0 deletions test/runtime/samples/attribute-casing-unknown-namespace/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Test support for unknown namespaces preserving attribute case (eg svelte-native).

export default {
html: `
halfnelson marked this conversation as resolved.
Show resolved Hide resolved
<page xmlns="tns" horizontalAlignment="center">
<button textWrap="true" text="button">
</page>
`,
options: {
hydrate: false // Hydrations currently doesn't work, the case sensitivity is only handled for svg elements.
},

test({ assert, target }) {
const attr = sel => target.querySelector(sel).attributes[0].name;
assert.equal(attr('page'), 'horizontalAlignment');
assert.equal(attr('button'), 'textWrap');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<page horizontalAlignment="center" xmlns="tns">
<button textWrap="true" text="button">
</page>