-
Notifications
You must be signed in to change notification settings - Fork 34
fix: properly handle nested add and sub expression inside sub expression #70
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
Conversation
@@ -17,7 +17,7 @@ | |||
"scripts": { | |||
"prepublish": "npm run build", | |||
"build": "del-cli dist && cross-env BABEL_ENV=publish babel src --out-dir dist --ignore src/__tests__/**/*.js && jison src/parser.jison -o dist/parser.js", | |||
"pretest": "eslint src && npm run build", | |||
"pretest": "npm run build && eslint src", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eslint report about Can't resolve
dist/parser`` on first run because we don't have parser before (we create this file in build
script)
testValue, | ||
'calc(100% - calc(10px - 2vw))', | ||
'calc(100% - 10px + 2vw)', | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many tests included
return node; | ||
} | ||
|
||
export default reduce; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because previously it use CRLF
instead LF
as normal for projects
op === '-' && ["+", "-"].includes(right.operator) | ||
) { | ||
node.right.operator = flip(node.right.operator); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added
node.operator = '+'; | ||
} else { | ||
node.operator = left.operator; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid logic for simplify
else if (op === '-' && right.operator === '+') { | ||
node = Object.assign({ }, node); | ||
node.right.operator = '-'; | ||
return reduce(node, precision); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid logic for simplify
const {left, right, operator: op} = node; | ||
|
||
if (left.type === 'Function' || right.type === 'Function') | ||
return node; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad idea, because you can write calc(var(--foo) - calc(var(--bar) + var(--baz)))
. Previously we break this code 😞
Thanks for taking care of that @evilebottnawi ! Are you planning to release the fix to npm soon? |
@leimonio we are rewriting many places in postcss-calc, i think it was done and released in next week |
fixes #64