Skip to content

Commit

Permalink
fix(Root): Fix processGenerator: closing tags must not have attribute…
Browse files Browse the repository at this point in the history
…s and tags must not have unnece
  • Loading branch information
eanorambuena committed Jul 22, 2024
1 parent 443c0c5 commit 1f280fd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
11 changes: 6 additions & 5 deletions dist/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ export function processGenerator(generator) {
if (/^[A-Z]/.test(match.slice(1, -1))) {
const name = element.split(' ')[0].slice(1);
const attributes = element.split(' ').slice(1);
return `<emmy-${name.toLowerCase()} ${attributes.join(' ')}>`;
const nameWithAttributes = `${name.toLowerCase()} ${attributes.join(' ')}`.trim();
return `<emmy-${nameWithAttributes}>`;
}
else if (/^[A-Z]/.test(match.slice(2, -2))) {
const name = element.split(' ')[0].slice(2);
const attributes = element.split(' ').slice(1);
return `</emmy-${name.toLowerCase()} ${attributes.join(' ')}>`;
return `</emmy-${name.toLocaleLowerCase()}>`;
}
return match;
});
return processedGenerator.replace(/<emmy-[^>]+\/>/g, match => {
const name = match.slice(6, -2);
return `<emmy-${name}></emmy-${name}>`;
const element = match.slice(6, -2);
const name = element.split(' ')[0];
return `<emmy-${element.trim()}></emmy-${name}>`;
});
}
export function parseCSS(cssString) {
Expand Down
11 changes: 6 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ export function processGenerator(generator: string): string {
if (/^[A-Z]/.test(match.slice(1, -1))) {
const name = element.split(' ')[0].slice(1)
const attributes = element.split(' ').slice(1)
return `<emmy-${name.toLowerCase()} ${attributes.join(' ')}>`
const nameWithAttributes = `${name.toLowerCase()} ${attributes.join(' ')}`.trim()
return `<emmy-${nameWithAttributes}>`
}
else if (/^[A-Z]/.test(match.slice(2, -2))) {
const name = element.split(' ')[0].slice(2)
const attributes = element.split(' ').slice(1)
return `</emmy-${name.toLowerCase()} ${attributes.join(' ')}>`
return `</emmy-${name.toLocaleLowerCase()}>`
}
return match
})
return processedGenerator.replace(/<emmy-[^>]+\/>/g, match => {
const name = match.slice(6, -2)
return `<emmy-${name}></emmy-${name}>`
const element = match.slice(6, -2)
const name = element.split(' ')[0]
return `<emmy-${element.trim()}></emmy-${name}>`
})
}

Expand Down
8 changes: 4 additions & 4 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { processGenerator, parseCSS, createInlineStyle, capitalizeFirstLetter, u

describe('processGenerator', () => {
it('should return a string', () => {
expect(processGenerator('<Div></Div>')).toBe('<emmy-div ></emmy-div >')
expect(processGenerator('<Div color="red"></Div>')).toBe('<emmy-div color="red"></emmy-div >')
expect(processGenerator('<Div />')).toBe('<emmy-div ></emmy-div >')
//expect(processGenerator('<Div color="red" />')).toBe('<emmy-div color="red" ></emmy-div >')
expect(processGenerator('<Div></Div>')).toBe('<emmy-div></emmy-div>')
expect(processGenerator('<Div color="red"></Div>')).toBe('<emmy-div color="red"></emmy-div>')
expect(processGenerator('<Div />')).toBe('<emmy-div></emmy-div>')
expect(processGenerator('<Div color="red" />')).toBe('<emmy-div color="red"></emmy-div>')
})
})

Expand Down

0 comments on commit 1f280fd

Please sign in to comment.