Skip to content

Commit

Permalink
fix: remove template strings from parsing regex (#249)
Browse files Browse the repository at this point in the history
fixes weird regex templated string issue
  • Loading branch information
michaellocher committed Jan 17, 2024
1 parent 31a98e0 commit 1c85e3c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/format-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ const CSS_INTEGER = '[-\\+]?\\d+%?';
const CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?';

// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
const CSS_UNIT = `(?:${CSS_NUMBER})|(?:${CSS_INTEGER})`;
const CSS_UNIT = '(?:' + CSS_NUMBER + ')|(?:' + CSS_INTEGER + ')';

// Actual matching.
// Parentheses and commas are optional, but not required.
// Whitespace can take the place of commas or opening paren
const PERMISSIVE_MATCH3 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`;
const PERMISSIVE_MATCH4 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`;
const PERMISSIVE_MATCH3 = '[\\s|\\(]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')\\s*\\)?';

Check failure on line 98 in src/format-input.ts

View workflow job for this annotation

GitHub Actions / build

Insert `⏎·`
const PERMISSIVE_MATCH4 =
'[\\s|\\(]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')\\s*\\)?';

Check failure on line 100 in src/format-input.ts

View workflow job for this annotation

GitHub Actions / build

Replace `·CSS_UNIT·+·')[,|\\s]+('·+·CSS_UNIT·+·')[,|\\s]+('·+·CSS_UNIT·+·')[,|\\s]+('·+·CSS_UNIT·+` with `⏎··CSS_UNIT·+⏎··')[,|\\s]+('·+⏎··CSS_UNIT·+⏎··')[,|\\s]+('·+⏎··CSS_UNIT·+⏎··')[,|\\s]+('·+⏎··CSS_UNIT·+⏎·`

const matchers = {
CSS_UNIT: new RegExp(CSS_UNIT),
Expand Down

0 comments on commit 1c85e3c

Please sign in to comment.