Skip to content

Commit

Permalink
fix(vscode): attributify value starts with number (#1811)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhmushan committed Oct 31, 2022
1 parent 8e1c7d1 commit 3de4429
Show file tree
Hide file tree
Showing 2 changed files with 13 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 { escapeRegExp, 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(`(${escapeRegExp(name)}=)(['"])[^\\2]*?${escapeRegExp(value)}[^\\2]*?\\2`, 'g')
Array.from(code.matchAll(regex))
.forEach((match) => {
const escaped = match[1]
Expand Down
12 changes: 11 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 [&_span]:white"></div>'))
.toMatchInlineSnapshot(`
[
[
Expand All @@ -28,6 +28,16 @@ describe('matched-positions', async () => {
20,
"[border=\\"gray4\\"]",
],
[
21,
22,
"[border=\\"2\\"]",
],
[
23,
37,
"[border=\\"[&_span]:white\\"]",
],
]
`)
})
Expand Down

0 comments on commit 3de4429

Please sign in to comment.