esc-rs
v0.2.0
Published
> [!WARNING] > Based on swc which use [compat-data](https://github.com/babel/babel/blob/main/packages/babel-compat-data/data/plugins.json) from babel, maybe not as same as [caniuse](https://caniuse.com/), check this [issue](https://github.com/babel/babel/
Downloads
79
Readme
esc-rs
[!WARNING] Based on swc which use compat-data from babel, maybe not as same as caniuse, check this issue for more details.
usage
pnpm i esc-rs -D
Detect features with browserlist
import { detect } from 'esc-rs'
const result = detect({
filename: 'input.js',
code: 'const a = 1 ?? false',
browserslist: 'IE 11',
})
// result
// {
// features: {
// nullishCoalescing: true,
// ...
// }
// }
Will output <feature>: true
if <feature>
not support in current browserslist
.
If want to report code frame info
const result = detect({
filename: 'input.js',
code: 'const a = 1 ?? false',
browserslist: 'IE 11',
})
for (const detail of result.details) {
console.log(`Reason: ${detail.feature}`, code.slice(detail.s, detail.e))
}
detect
options
filename
: stringcode
: stringbrowserslist
: string
output
output.details
feature
: not support feature-name based on currentbrowserlists
. e.g.nullishCoalescing
s
: start char pose
: end char posls
: start locle
: end loc
lookup
options
unstable. Currently
details.{feature|s|e}
is required.
filename
: stringdetails
feature
: not support feature-name based on currentbrowserlists
. e.g.nullishCoalescing
s
: start char pose
: end char posls
: start locle
: end loc
output
ls
: start locle
: end locsource
: original filename
[!WARNING] Currently unable to check polyfill features, e.g.
Async iterators
. In swc it will injectcore-js
polyfills instead of transform