Skip to content

Commit

Permalink
feat: avoid duplicate class attribute in pug
Browse files Browse the repository at this point in the history
close #1525
  • Loading branch information
johnsoncodehk committed Jul 16, 2022
1 parent eedb660 commit 90e482f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/pug-language-service/src/baseParse.ts
Expand Up @@ -143,8 +143,11 @@ export function baseParse(pugCode: string) {
const noTitleAttrs = node.attrs.filter(attr => !attr.mustEscape && attr.name !== 'class');
const noTitleClassAttrs = node.attrs.filter(attr => !attr.mustEscape && attr.name === 'class');
const attrsBlock = attrsBlocks.get(getDocOffset(node.line, node.column)); // support attr auto-complete in spaces
const hasClassAttr = attrsBlock && attrsBlock.text.match(/\bclass\b\s*=/i);

addClassesOrStyles(noTitleClassAttrs, 'class');
if (!hasClassAttr) {
addClassesOrStyles(noTitleClassAttrs, 'class');
}

for (const attr of noTitleAttrs) {
codeGen.addText(' ');
Expand Down

0 comments on commit 90e482f

Please sign in to comment.