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

recover from unexpected brace at top-level #1876

Merged
merged 1 commit into from Dec 21, 2021

Conversation

sbfaulkner
Copy link
Contributor

When minifying, esbuild will currently truncate output when it encounters an unexpected } at the top-level of the css.

Given CSS like...

.red {
  color: red;
}
}
.blue {
  color: blue;
}
.green {
  color: green;
}

This produces...

bin/esbuild --loader=css --minify <rgb.css
▲ [WARNING] Expected end of file but found "}"

    <stdin>:4:0:
      4 │ }
        ╵ ^

1 warning
.red{color:red}

This PR attempts to recover from the situation (more like the best-effort recovery seen in other minification processors and/or css parsers), instead producing the following...

bin/esbuild --loader=css --minify <rgb.css
▲ [WARNING] Unexpected "}"

    <stdin>:4:0:
      4 │ }
        ╵ ^

1 warning
.red{color:red}.blue{color:#00f}.green{color:green}

@sbfaulkner
Copy link
Contributor Author

@evanw when you have time, is this the correct fix?

@evanw
Copy link
Owner

evanw commented Dec 21, 2021

Yeah, looks good to me. Thanks!

@evanw evanw merged commit 6082ad8 into evanw:master Dec 21, 2021
@sbfaulkner sbfaulkner deleted the unexpected-brace branch December 21, 2021 18:26
@evanw
Copy link
Owner

evanw commented Dec 21, 2021

Hmm actually when I run this in the browser, the result is different. Sorry for merging without checking first. In the browser, the red and green rules take effect but the blue rule doesn't. So esbuild should follow that behavior IMO. Still recover and continue but the rule starting with } is invalid. I'll change it to behave like that instead.

evanw added a commit that referenced this pull request Dec 21, 2021
@sbfaulkner sbfaulkner restored the unexpected-brace branch December 21, 2021 19:09
@sbfaulkner sbfaulkner deleted the unexpected-brace branch December 21, 2021 19:53
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.

None yet

2 participants