Skip to content
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

Compile time calc() in CSS #1607

Closed
xPaw opened this issue Sep 15, 2021 · 3 comments · Fixed by #1731
Closed

Compile time calc() in CSS #1607

xPaw opened this issue Sep 15, 2021 · 3 comments · Fixed by #1731

Comments

@xPaw
Copy link

xPaw commented Sep 15, 2021

Example:

.test {
	max-width: calc(280px * 2 + 20px);
}

@media (max-width: 580px) {
	.test {
		max-width: calc(280px + 20px);
	}
}

Since these calculations have const values, it would be possible to just calculate it and output:

.test {
	max-width: 580px;
}

@media (max-width: 580px) {
	.test {
		max-width: 300px;
	}
}

Is this something esbuild could/should do as part of the minification?

@evanw
Copy link
Owner

evanw commented Sep 21, 2021

I agree that this would be nice to do, although not top priority. I have been slowly implementing more and more CSS minification cases over time so this is in scope. It's a pretty complex feature however, so maybe basic cases could be added first and then support for more cases could be added over time.

I assume the test cases and code for postcss-calc and the calc specification would be appropriate references. It looks like postcss-calc has correctness bugs though so care would have to be taken when choosing what specific simplifications to do in esbuild.

@yisibl
Copy link
Contributor

yisibl commented Dec 2, 2021

Sorry, please don't do this, for the specific reasons I have written here: #1821

@starikcetin
Copy link

Sorry, please don't do this, for the specific reasons I have written here: #1821

A percentage is not always a constant value, as its value depends on the context. On the other hand, 280px + 20px is always a constant value. Therefore your response is not a valid objection to the original request.

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 a pull request may close this issue.

4 participants