Skip to content

Commit 048e467

Browse files
authored
(fix) (svelte2tsx) also transform element true attribute to lowercase (#511)
* also transform element true attribute to lowercase ex: <input readonly> * don't transform if attribute is transformed from directive and namespace
1 parent 41827f7 commit 048e467

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

packages/svelte2tsx/src/htmlxtojsx/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,12 @@ export function convertHtmlxToJsx(
354354
};
355355

356356
const handleAttribute = (attr: Node, parent: Node) => {
357+
let transformedFromDirectiveOrNamespace = false;
358+
357359
//if we are on an "element" we are case insensitive, lowercase to match our JSX
358360
if (parent.type == 'Element') {
359-
//skip Attribute shorthand, that is handled below
360361
const sapperNoScroll = attr.name === 'sapper:noscroll';
362+
//skip Attribute shorthand, that is handled below
361363
if (
362364
(attr.value !== true &&
363365
!(
@@ -380,11 +382,22 @@ export function convertHtmlxToJsx(
380382
}
381383

382384
str.overwrite(attr.start, attr.start + attr.name.length, name);
385+
386+
transformedFromDirectiveOrNamespace = true;
383387
}
384388
}
385389

386390
//we are a bare attribute
387-
if (attr.value === true) return;
391+
if (attr.value === true) {
392+
if (
393+
parent.type === 'Element' &&
394+
!transformedFromDirectiveOrNamespace &&
395+
parent.name !== '!DOCTYPE'
396+
) {
397+
str.overwrite(attr.start, attr.end, attr.name.toLowerCase());
398+
}
399+
return;
400+
}
388401

389402
if (attr.value.length == 0) return; //wut?
390403
//handle single value
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<><div contenteditable></div>
2+
<div contenteditable={contentEditable}></div>
3+
<div contenteditable={contenteditable}></div></>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div contentEditable></div>
2+
<div {contentEditable}></div>
3+
<div contentEditable={contenteditable}></div>

0 commit comments

Comments
 (0)