Skip to content

Commit

Permalink
perf: selfClosingTags
Browse files Browse the repository at this point in the history
  • Loading branch information
laoer536 committed Jul 21, 2023
1 parent 7d364d9 commit 121262d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const selfClosingTags = [
'area',
'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'link',
'meta',
'param',
'source',
'track',
'wbr',
]
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { AtrulePrelude } from 'css-tree'
import { AtrulePlain, AtrulePreludePlain, ClassSelector, TypeSelector } from 'css-tree'
import { getPackageInfo, isPackageExists } from 'local-pkg'
import { templates } from './templates'
import { selfClosingTags } from './data'

export type StyleType = 'css' | 'less' | 'scss'

Expand Down Expand Up @@ -129,7 +130,9 @@ export function getDomStr(domTree: ReturnType<typeof getDomTree>, domType: 'vue'
const domName = getDomName(selector)
const selectorName = getSelectorName(selector.includes('.self') ? '.' + selector.split('.')[1] : selector)
if (keys.length === 0) {
return `<${domName} ${classAttribute}=${selectorName || `'${domName}'`}></${domName}>`
return `<${domName} ${classAttribute}=${selectorName || `'${domName}'`}${
selfClosingTags.includes(domName) ? '/>' : `></${domName}>`
}`
} else {
let result = `<${domName} ${classAttribute}=${selectorName || `'${domName}'`}>`
for (const selector of keys) {
Expand Down

0 comments on commit 121262d

Please sign in to comment.