Skip to content

Commit

Permalink
refactor: use the same variable functions definition everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
ludofischer committed Jun 7, 2022
1 parent e707fc2 commit 858a8b7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/postcss-normalize-positions/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const verticalValue = new Map([
['top', '0'],
]);
const mathFunctions = new Set(['calc', 'min', 'max', 'clamp']);

const variableFunctions = new Set(['var', 'env', 'constant']);
/**
* @param {valueParser.Node} node
* @return {boolean}
Expand All @@ -31,7 +31,7 @@ function isVariableFunctionNode(node) {
return false;
}

return ['var', 'env'].includes(node.value.toLowerCase());
return variableFunctions.has(node.value.toLowerCase());
}

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/postcss-normalize-positions/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ test(
passthroughCSS('background-position: env(--foo)')
);

test(
'should pass through with constant',
passthroughCSS('background-position: constant(--foo)')
);

test(
'should normalize when property in uppercase',
processCSS('BACKGROUND-POSITION: center', 'BACKGROUND-POSITION: 50%')
Expand Down
3 changes: 2 additions & 1 deletion packages/postcss-normalize-repeat-style/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function isCommaNode(node) {
return node.type === 'div' && node.value === ',';
}

const variableFunctions = new Set(['var', 'env', 'constant']);
/**
* @param {valueParser.Node} node
* @return {boolean}
Expand All @@ -30,7 +31,7 @@ function isVariableFunctionNode(node) {
return false;
}

return ['var', 'env'].includes(node.value.toLowerCase());
return variableFunctions.has(node.value.toLowerCase());
}

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/postcss-normalize-repeat-style/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ test(
passthroughCSS('background-position: env(--foo)')
);

test(
'should pass through with constant',
passthroughCSS('background-position: constant(--foo)')
);

test(
'should normalize background position with var and multiple background',
processCSS(
Expand Down

0 comments on commit 858a8b7

Please sign in to comment.