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

Detect arbitrary variants with quotes #8687

Merged
merged 3 commits into from
Jun 20, 2022
Merged
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
Next Next commit
Refactor
thecrypticace committed Jun 20, 2022
commit 9fe47970c17eff6c2bcfa07147d2f75cf11a1b21
54 changes: 29 additions & 25 deletions src/lib/defaultExtractor.js
Original file line number Diff line number Diff line change
@@ -64,31 +64,35 @@ function* buildRegExps(context) {
]),
])

yield regex.pattern([
// Variants
'((?=((',
regex.any(
[
regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s"'`]+\]/, separator]),
regex.pattern([/[^\s"'`\[\\]+/, separator]),
],
true
),
')+))\\2)?',

// Important (optional)
/!?/,

variantGroupingEnabled
? regex.any([
// Or any of those things but grouped separated by commas
regex.pattern([/\(/, utility, regex.zeroOrMore([/,/, utility]), /\)/]),

// Arbitrary properties, constrained utilities, arbitrary values, etc…
utility,
])
: utility,
])
let variantPatterns = [
// Without quotes
regex.any([
regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s"'`]+\]/, separator]),
regex.pattern([/[^\s"'`\[\\]+/, separator]),
]),
]

for (const variantPattern of variantPatterns) {
yield regex.pattern([
// Variants
'((?=((',
variantPattern,
')+))\\2)?',

// Important (optional)
/!?/,

variantGroupingEnabled
? regex.any([
// Or any of those things but grouped separated by commas
regex.pattern([/\(/, utility, regex.zeroOrMore([/,/, utility]), /\)/]),

// Arbitrary properties, constrained utilities, arbitrary values, etc…
utility,
])
: utility,
])
}

// 5. Inner matches
yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g