You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given the code above, you would expect babel to inject import "core-js/modules/es.array.to-sorted.js" since toSorted is not supported in those browser versions. However, with debug logging on, you can see:
Using targets:
{
"chrome": "87",
"safari": "14.1"
}
Using modules transform: false
Using plugins:
transform-duplicate-named-capturing-groups-regex { chrome < 126, safari < 17.4 }
transform-unicode-sets-regex { chrome < 112, safari < 17 }
bugfix/transform-v8-static-class-fields-redefine-readonly { chrome < 98, safari < 15 }
bugfix/transform-firefox-class-in-computed-class-key { safari < 16 }
bugfix/transform-safari-class-field-initializer-scope { safari < 16 }
proposal-class-static-block { chrome < 94, safari < 16.4 }
proposal-private-property-in-object { chrome < 91, safari < 15 }
syntax-class-properties
proposal-private-methods { safari < 15 }
syntax-numeric-separator
syntax-nullish-coalescing-operator
syntax-optional-chaining
syntax-json-strings
syntax-optional-catch-binding
syntax-async-generators
syntax-object-rest-spread
syntax-export-namespace-from
bugfix/transform-safari-id-destructuring-collision-in-function-expression { safari < 16.3 }
bugfix/transform-v8-spread-parameters-in-optional-chaining { chrome < 91 }
syntax-dynamic-import
syntax-top-level-await
syntax-import-meta
corejs3: `DEBUG` option
Using targets: {
"chrome": "87",
"safari": "14.1"
}
Using polyfills with `usage-global` method:
[/Volumes/Code/tinker/babel-bug-maybe/test2.js]
Based on your code and targets, the corejs3 polyfill did not add any polyfill.
c?.toSorted();
If you remove the optional chain, you instead see (truncated):
The corejs3 polyfill added the following polyfills:
es.array.to-sorted { "chrome":"87", "safari":"14.1" }
import "core-js/modules/es.array.to-sorted.js";
c.toSorted();
Similarly, if you force @babel/plugin-transform-optional-chaining, you get:
The corejs3 polyfill added the following polyfills:
es.array.to-sorted { "chrome":"87", "safari":"14.1" }
var _c;
import "core-js/modules/es.array.to-sorted.js";
(_c = c) === null || _c === void 0 ? void 0 : _c.toSorted();
It seems like whatever mechanism is detecting the usage of toSorted for polyfill purposes is unable to see it on that optional chain.
Hey @epmatsw! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.
If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.
💻
How are you using Babel?
babel-loader (webpack)
Input code
Configuration file name
.babelrc.json
Configuration
Current and expected behavior
Given the code above, you would expect babel to inject
import "core-js/modules/es.array.to-sorted.js"
since toSorted is not supported in those browser versions. However, with debug logging on, you can see:If you remove the optional chain, you instead see (truncated):
Similarly, if you force
@babel/plugin-transform-optional-chaining
, you get:It seems like whatever mechanism is detecting the usage of
toSorted
for polyfill purposes is unable to see it on that optional chain.Environment
System:
OS: macOS 15.0
Binaries:
Node: 22.9.0 - ~/.nvm/versions/node/v22.9.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v22.9.0/bin/yarn
npm: 10.8.3 - ~/.nvm/versions/node/v22.9.0/bin/npm
bun: 1.1.10 - ~/.bun/bin/bun
npmPackages:
@babel/cli: ^7 => 7.25.6
@babel/core: ^7 => 7.25.2
@babel/preset-env: ^7 => 7.25.4
Possible solution
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: