transformer: engine support and lowering
When using OXC to build for a specific target, it would be helpful to be browserslist-compatible in terms of output and format. Two issues that I've discovered:
- Not all engines emitted via
browserslistare available, such asand_chr135(android chrome) - When setting two targets for the same engine, such as
['chrome135', 'chrome134'], the build will fail instead of combining requirements for both engines or accepting the lowest.
Originally via https://github.com/vitejs/rolldown-vite/issues/140
Not all engines emitted via browserslist are available, such as and_chr135 (android chrome)
This is due to not updating browserslist data for at least two months ... updated in https://github.com/oxc-project/oxc/pull/10625
When setting two targets for the same engine, such as ['chrome135', 'chrome134'], the build will fail instead of combining requirements for both engines or accepting the lowest.
I did some logging and testing in esbuild:
https://github.com/evanw/esbuild/blob/5959289d90667c5a4026e6fb32cc58bbed9fc88a/pkg/api/api_impl.go#L360
fmt.Println(targetEnv)
make esbuild && ./esbuild --target="chrome125,chrome120,es2015,es2022" test.js
"chrome120", "es2022"
make esbuild && ./esbuild --target="chrome120,chrome125,es2022,es2015" test.js
"chrome125", "es2015"
It resolves to the last value.
Testing in the playground:
--target=es2022,es2015 transforms: https://esbuild.github.io/try/#dAAwLjI0LjAALS10YXJnZXQ9ZXMyMDI0LGVzMjAxNQBhID8/IGI
--target=es2015,es2024 does not transform: https://esbuild.github.io/try/#dAAwLjI0LjAALS10YXJnZXQ9ZXMyMDE1LGVzMjAyNABhID8/IGI
So to our surprise, esbuild just picks the last value for the target.
I'm in favor of keeping the current behavior (report Error: 'chrome134' is already specified.) to remove the ambiguity.
And maybe report this to esbuild to surface the problem.
browserslist getting updated in Rolldown https://github.com/rolldown/rolldown/pull/4353
Closing the Error: 'chrome134' is already specified. as won't fix right now because I think it removes ambiguity.
Reposted my above comment to upstream issue.