Skip to content

Commit

Permalink
fix check
Browse files Browse the repository at this point in the history
  • Loading branch information
Дмитрий Жук authored and clshortfuse committed Oct 4, 2023
1 parent d73ef35 commit e52a4a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
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
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 @@ import { agents } from 'caniuse-lite';

/** @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 @@ -72,7 +82,7 @@ export function checkAtRule(name, parameters) {
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));
}

0 comments on commit e52a4a4

Please sign in to comment.