Skip to content

Commit

Permalink
(fix) (svelte2tsx) also transform element true attribute to lowercase (
Browse files Browse the repository at this point in the history
…#511)

* also transform element true attribute to lowercase
    ex: <input readonly>

* don't transform if attribute is transformed from directive and namespace
  • Loading branch information
jasonlyu123 committed Sep 1, 2020
1 parent 41827f7 commit 048e467
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/svelte2tsx/src/htmlxtojsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,12 @@ export function convertHtmlxToJsx(
};

const handleAttribute = (attr: Node, parent: Node) => {
let transformedFromDirectiveOrNamespace = false;

//if we are on an "element" we are case insensitive, lowercase to match our JSX
if (parent.type == 'Element') {
//skip Attribute shorthand, that is handled below
const sapperNoScroll = attr.name === 'sapper:noscroll';
//skip Attribute shorthand, that is handled below
if (
(attr.value !== true &&
!(
Expand All @@ -380,11 +382,22 @@ export function convertHtmlxToJsx(
}

str.overwrite(attr.start, attr.start + attr.name.length, name);

transformedFromDirectiveOrNamespace = true;
}
}

//we are a bare attribute
if (attr.value === true) return;
if (attr.value === true) {
if (
parent.type === 'Element' &&
!transformedFromDirectiveOrNamespace &&
parent.name !== '!DOCTYPE'
) {
str.overwrite(attr.start, attr.end, attr.name.toLowerCase());
}
return;
}

if (attr.value.length == 0) return; //wut?
//handle single value
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<><div contenteditable></div>
<div contenteditable={contentEditable}></div>
<div contenteditable={contenteditable}></div></>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div contentEditable></div>
<div {contentEditable}></div>
<div contentEditable={contenteditable}></div>

0 comments on commit 048e467

Please sign in to comment.