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

Handle group/peer variants with quoted strings #10400

Merged
merged 7 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix CS
  • Loading branch information
thecrypticace committed Jan 23, 2023
commit 2a378246f0614a3480ea76d081af2a44f9579453
16 changes: 8 additions & 8 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,18 @@ export let variantPlugins = {

let [a, b] = fn('', extra)

let start = null;
let end = null;
let quotes = 0;
let start = null
let end = null
let quotes = 0

for (let i = 0; i < result.length; ++i) {
let c = result[i]
if (c === '&') {
start = i;
} else if (c === '\'' || c === '"') {
quotes += 1;
start = i
} else if (c === "'" || c === '"') {
quotes += 1
} else if (start !== null && c === ' ' && !quotes) {
end = i;
end = i
}
}

Expand All @@ -191,7 +191,7 @@ export let variantPlugins = {
// Basically this but can handle quotes:
// result.replace(/&(\S+)?/g, (_, pseudo = '') => a + pseudo + b)

result = result.slice(0, start) + a + result.slice(start+1, end) + b + result.slice(end)
result = result.slice(0, start) + a + result.slice(start + 1, end) + b + result.slice(end)

return result
},
Expand Down
22 changes: 9 additions & 13 deletions src/lib/generateRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,30 +152,26 @@ function applyVariant(variant, matches, context) {

// Retrieve "modifier"
{
let start = null;
let parens = 0;
let brackets = 0;
let start = null
let parens = 0
let brackets = 0

for (let i = 0; i < variant.length; i++) {
thecrypticace marked this conversation as resolved.
Show resolved Hide resolved
let c = variant[i]
if (c === '[') {
brackets++;
brackets++
} else if (c === ']') {
brackets--;
brackets--
} else if (c === '(') {
parens++;
parens++
} else if (c === ')') {
parens--;
parens--
} else if (parens === 0 && brackets === 0 && c === '/') {
start = i;
start = i
}
}

let match = start === null ? null : [
variant,
variant.slice(0, start),
variant.slice(start + 1),
]
let match = start === null ? null : [variant, variant.slice(0, start), variant.slice(start + 1)]

if (match && !context.variantMap.has(variant)) {
variant = match[1]
Expand Down
8 changes: 4 additions & 4 deletions tests/basic-usage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ crosscheck(({ stable, oxide }) => {
let result = await run(input, config)

oxide.expect(result.css).toMatchFormattedCss(css`
.group[href^="/"] .group-\[\[href\^\=\'\/\'\]\]\:hidden {
.group[href^='/'] .group-\[\[href\^\=\'\/\'\]\]\:hidden {
display: none;
}
`)
Expand All @@ -975,7 +975,7 @@ crosscheck(({ stable, oxide }) => {
.hidden {
display: none;
}
.group[href^="/"] .group-\[\[href\^\=\'\/\'\]\]\:hidden {
.group[href^='/'] .group-\[\[href\^\=\'\/\'\]\]\:hidden {
display: none;
}
`)
Expand All @@ -997,7 +997,7 @@ crosscheck(({ stable, oxide }) => {
let result = await run(input, config)

oxide.expect(result.css).toMatchFormattedCss(css`
.group[href^=" bar"] .group-\[\[href\^\=\'_bar\'\]\]\:hidden {
.group[href^=' bar'] .group-\[\[href\^\=\'_bar\'\]\]\:hidden {
display: none;
}
`)
Expand All @@ -1006,7 +1006,7 @@ crosscheck(({ stable, oxide }) => {
.hidden {
display: none;
}
.group[href^=" bar"] .group-\[\[href\^\=\'_bar\'\]\]\:hidden {
.group[href^=' bar'] .group-\[\[href\^\=\'_bar\'\]\]\:hidden {
display: none;
}
`)
Expand Down