pull/8434/head
baseballyama 3 years ago
parent aadda27bea
commit 1ed69fa0f2

@ -63,7 +63,7 @@ export default function (node: Element, renderer: Renderer, options: RenderOptio
const attr_name = node.namespace === namespaces.foreign ? attribute.name : fix_attribute_casing(attribute.name); const attr_name = node.namespace === namespaces.foreign ? attribute.name : fix_attribute_casing(attribute.name);
const name = attribute.name.toLowerCase(); const name = attribute.name.toLowerCase();
if (name === 'value' && node.name.toLowerCase() === 'textarea') { if (name === 'value' && node.name.toLowerCase() === 'textarea') {
node_contents = get_attribute_value(attribute, true); node_contents = get_attribute_value(attribute);
} else if (attribute.is_true) { } else if (attribute.is_true) {
args.push(x`{ ${attr_name}: true }`); args.push(x`{ ${attr_name}: true }`);
} else if ( } else if (
@ -90,7 +90,7 @@ export default function (node: Element, renderer: Renderer, options: RenderOptio
const name = attribute.name.toLowerCase(); const name = attribute.name.toLowerCase();
const attr_name = node.namespace === namespaces.foreign ? attribute.name : fix_attribute_casing(attribute.name); const attr_name = node.namespace === namespaces.foreign ? attribute.name : fix_attribute_casing(attribute.name);
if (name === 'value' && node.name.toLowerCase() === 'textarea') { if (name === 'value' && node.name.toLowerCase() === 'textarea') {
node_contents = get_attribute_value(attribute, true); node_contents = get_attribute_value(attribute);
} else if (attribute.is_true) { } else if (attribute.is_true) {
renderer.add_string(` ${attr_name}`); renderer.add_string(` ${attr_name}`);
} else if ( } else if (

@ -16,13 +16,16 @@ export function get_class_attribute_value(attribute: Attribute): ESTreeExpressio
return get_attribute_value(attribute); return get_attribute_value(attribute);
} }
/**
* For value attribute of textarea, it will render as child node of `<textarea>` element. export function get_attribute_value(attribute: Attribute): ESTreeExpression {
* Therefore, we need to escape as content (not attribute).
*/
export function get_attribute_value(attribute: Attribute, is_textarea_value = false): ESTreeExpression {
if (attribute.chunks.length === 0) return x`""`; if (attribute.chunks.length === 0) return x`""`;
/**
* For value attribute of textarea, it will render as child node of `<textarea>` element.
* Therefore, we need to escape as content (not attribute).
*/
const is_textarea_value = attribute.parent.name.toLowerCase() === 'textarea' && attribute.name.toLowerCase() === 'value';
return attribute.chunks return attribute.chunks
.map((chunk) => { .map((chunk) => {
return chunk.type === 'Text' return chunk.type === 'Text'

Loading…
Cancel
Save