Skip to content

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

Merged
merged 3 commits into from
Apr 3, 2019
Merged

fix: properly handle nested add and sub expression inside sub expression #70

merged 3 commits into from
Apr 3, 2019

Conversation

alexander-akait
Copy link
Collaborator

fixes #64

@@ -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",
Copy link
Collaborator Author

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)',
);
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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);
}
Copy link
Collaborator Author

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;
}
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

@alexander-akait alexander-akait Mar 27, 2019

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 😞

@alexander-akait alexander-akait merged commit b5bb24e into postcss:master Apr 3, 2019
@alexander-akait alexander-akait deleted the issue-64 branch April 3, 2019 11:56
@leimonio
Copy link

leimonio commented Apr 4, 2019

Thanks for taking care of that @evilebottnawi ! Are you planning to release the fix to npm soon?

@alexander-akait
Copy link
Collaborator Author

alexander-akait commented Apr 4, 2019

@leimonio we are rewriting many places in postcss-calc, i think it was done and released in next week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transformation removes of inner calc
3 participants