Skip to content

Commit

Permalink
fix(vscode): attributify value starts with number
Browse files Browse the repository at this point in the history
  • Loading branch information
zhmushan committed Oct 29, 2022
1 parent f4954d2 commit 5188421
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/shared-common/src/index.ts
@@ -1,5 +1,5 @@
import type { UnoGenerator } from '@unocss/core'
import { e, isAttributifySelector, regexClassGroup } from '@unocss/core'
import { isAttributifySelector, regexClassGroup } from '@unocss/core'
import MagicString from 'magic-string'

// https://github.com/dsblv/string-replace-async/blob/main/index.js
Expand Down Expand Up @@ -78,7 +78,7 @@ export function getMatchedPositions(code: string, matched: string[], hasVariantG

// attributify values
attributify.forEach(([, name, value]) => {
const regex = new RegExp(`(${e(name)}=)(['"])[^\\2]*?${e(value)}[^\\2]*?\\2`, 'g')
const regex = new RegExp(`(${name}=)(['"])[^\\2]*?${value}[^\\2]*?\\2`, 'g')
Array.from(code.matchAll(regex))
.forEach((match) => {
const escaped = match[1]
Expand Down
7 changes: 6 additions & 1 deletion test/pos.test.ts
Expand Up @@ -15,7 +15,7 @@ describe('matched-positions', async () => {
],
})

expect(await match(uno, '<div border="b gray4"></div>'))
expect(await match(uno, '<div border="b gray4 2"></div>'))
.toMatchInlineSnapshot(`
[
[
Expand All @@ -28,6 +28,11 @@ describe('matched-positions', async () => {
20,
"[border=\\"gray4\\"]",
],
[
21,
22,
"[border=\\"2\\"]",
],
]
`)
})
Expand Down

0 comments on commit 5188421

Please sign in to comment.