Skip to content

Commit

Permalink
Fix: Ignore calc-size from detection (#230)
Browse files Browse the repository at this point in the history
* Add failing test

* Ensure Regex ignores calc-size
  • Loading branch information
Antonio-Laguna authored Jan 7, 2025
1 parent bbedb09 commit cac6f39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { parser } = require('../parser.js');
const reducer = require('./reducer.js');
const stringifier = require('./stringifier.js');

const MATCH_CALC = /((?:-(moz|webkit)-)?calc)/i;
const MATCH_CALC = /((?:-(moz|webkit)-)?calc(?!-))/i;

/**
* @param {string} value
Expand Down
17 changes: 17 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ function testCss(fixture, expected, opts = {}) {
};
}

function testCssDoesNotThrow(fixture, expected, opts = {}) {
return async () => {
const result = await postcss(reduceCalc(opts)).process(
fixture,
postcssOpts
);
assert.strictEqual(result.css, expected);
const warnings = result.warnings();
assert.strictEqual(warnings.length, 0);
};
}

function testThrows(fixture, expected, warning, opts = {}) {
fixture = `foo{bar:${fixture}}`;
expected = `foo{bar:${expected}}`;
Expand Down Expand Up @@ -970,6 +982,11 @@ test(
testValue('calc(1px + 2unknown)', 'calc(1px + 2unknown)')
);

test(
'calc-size should be ignored',
testCssDoesNotThrow('.foo{block-size: calc-size(auto, size)}', '.foo{block-size: calc-size(auto, size)}')
);

test(
'error with parsing',
testThrows(
Expand Down

0 comments on commit cac6f39

Please sign in to comment.