Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vscode): attributify value starts with number #1811

Merged
merged 2 commits into from Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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\\"]",
zhmushan marked this conversation as resolved.
Show resolved Hide resolved
],
[
23,
37,
"[border=\\"[&_span]:white\\"]",
],
]
`)
})
Expand Down