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 check viewport-unit-variants #173

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions lib/Detector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FEATURES from '../data/features.js';
import { performFeatureCheck } from '../utils/util.js';
import { performFeatureCheck, stripUrls } from '../utils/util.js';

/**
* @typedef DetectorCallbackArgument
Expand All @@ -18,16 +18,6 @@ const PLUGIN_OPTION_COMMENT = 'doiuse-';
const DISABLE_FEATURE_COMMENT = `${PLUGIN_OPTION_COMMENT}disable`;
const ENABLE_FEATURE_COMMENT = `${PLUGIN_OPTION_COMMENT}enable`;

/**
* Strip the contents of url literals so they aren't matched
* by our naive substring matching.
* @param {string} input
* @return {string}
*/
function stripUrls(input) {
return input.replaceAll(/url\([^)]*\)/g, 'url()');
}

/**
* Detect the use of any of a given list of CSS features.
* ```
Expand Down
3 changes: 3 additions & 0 deletions test/cases/features/viewport-unit-variants.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ viewport-unit-variants: 20
/* vi/vb units */
width: 100vi;
width: 100vb;

/* should not trigger */
background-image: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik02LjU4NiA4TDQuMjkzIDUuNzA3YS45OTkuOTk5IDAgMTExLjQxNC0xLjQxNEw4IDYuNTg1bDIuMjkzLTIuMjkyYTEgMSAwIDAxMS40MTQgMS40MTNMOS40MTQgOGwyLjI5MyAyLjI5NGExIDEgMCAwMS0xLjQxNCAxLjQxNEw4IDkuNDEzbC0yLjI5MyAyLjI5M2ExIDEgMCAwMS0xLjQxNC0xLjQxNUw2LjU4NiA4eiIgZmlsbD0iIzI3MkIzNyIgZmlsbC1vcGFjaXR5PSIuMiIvPjwvc3ZnPg==")
}
12 changes: 11 additions & 1 deletion utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

/** @typedef {RegExp|string|((value:string) => boolean)} FeatureCheck */

/**
* Strip the contents of url literals so they aren't matched
* by our naive substring matching.
* @param {string} input
* @return {string}
*/
export function stripUrls(input) {
return input.replaceAll(/url\([^)]*\)/g, 'url()');
}

/**
* @param {string} browserKey
* @param {string[]} [versions]
Expand Down Expand Up @@ -39,7 +49,7 @@
}
// Fallthrough
default:
console.error(check);

Check warning on line 52 in utils/util.js

View workflow job for this annotation

GitHub Actions / node (16)

Unexpected console statement

Check warning on line 52 in utils/util.js

View workflow job for this annotation

GitHub Actions / node (18)

Unexpected console statement

Check warning on line 52 in utils/util.js

View workflow job for this annotation

GitHub Actions / node (20)

Unexpected console statement
throw new TypeError(`Unexpected feature check: ${check}`);
}
}
Expand Down Expand Up @@ -73,7 +83,7 @@
export function checkCSSLengthUnits(...units) {
const regexp = new RegExp(`(\\+-)?[\\d.]*\\.?\\d+(e(\\+-)?\\d+)?(${units.join('|')})`, 'i');
return (rule) => (
(rule.type === 'decl') ? performFeatureCheck(regexp, rule.value)
(rule.type === 'decl') ? performFeatureCheck(regexp, stripUrls(rule.value))
: ((rule.type === 'atrule') ? performFeatureCheck(regexp, rule.params)
: false));
}
Loading