Some code left uncompiled with specific browserlist config (boolean())
Describe the bug
When using cover 75% in RU as browserlist config, part of code left uncompiled. But with cover 74% in RU everything is fine.
As a workaround I use import { boolean as boo } from 'yup';
Input code
import { withFormik } from 'formik';
import { object, boolean } from 'yup';
const test = {
validationSchema: object({
// working
isAgent: boolean().required(),
}),
handleSubmit: () => {},
};
console.log(test);
export const DealRentModalWithFormik = withFormik({
validationSchema: object({
// skipped o_O
isAgent: boolean().required(),
}),
handleSubmit: () => {},
})(() => <span />);
Config
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "commonjs"
},
"minify": false,
"isModule": true,
"env": {
"targets": "cover 75% in RU"
}
}
Playground link (or link to the minimal reproduction)
https://play.swc.rs/?version=1.11.13&code=H4sIAAAAAAAAA62QsU7DMBCG9zzFbbWlqNlbUgkJsVWV6NAROfE1OWL7jOO0oCjvjpu2wMjActJvf777fGQ9hwgjnCm2zxwsdTDBMbCFxXGOi3VGd4irN6xjDhWzQeW%2Byc%2FBJyyr2fURIqZSwpgBnJQhrSKx29ctWrW6dRCXS4CigDOHjlwzR%2BofG3RxdW8v5DLg%2B0ABtZB5Qqa5tsppg%2FuhspRYIaHcwDjl2XQzSG%2BXhhtx8ZDpDD9m%2B6vcEyrzkoZsWStz%2BPlz%2BWsB4m%2FqfUfeowZ%2B3f2LvhTX8ND7tNpiI9dfJ1TbvJ0BAAA%3D&config=H4sIAAAAAAAAA1WOSwrDMAxE9zmFEXTXbSn0Dt0UegDjKsEh%2FiA5oSHk7rGd2E130szoaZZGCOhZwUMscYyLl8RIdY8KzzbIb1QgzB5ZkfYBrsUNnKxAI2Zl3Q0YnGOMRisHxkMz2up2PqOVM56Q%2BT%2BYotJ2Q73fyc1BB%2BM%2BYzaPyqlWqhdpxtme4ZcsHysdND%2FLeSqdNbTTiSapw8A7cEIS99tFaCte78xt1g2wo0klNAEAAA%3D%3D
SWC Info output
No response
Expected behavior
boolean() should be compiled
Actual behavior
boolean() left uncompiled
Version
1.11.13
Additional context
No response
Your reproduction seems to be wrong?
@kdy1 Seems fine 🤔
Do you mean the member property name should be renamed?
boolean is fine to be there if it’s a property of a member expression.
@kdy1 boolean() is import from yup and it should be transformed to (0, _yup.boolean)(), otherwise the result code is broken.
Sorry, I will try to describe issues better next time :[
Sorry, I was looking at the other boolean() call
As someone requested on Discord, I'm writing a guideline to fix this issue.
Guide
(1 and 2 are optional)
- Update the data of preset-env. You must update the
@babel/compat-dataandcore-js-compatnpm package. - Create a PR for 1.
These steps ensure the browserslist data is the latest, which may be required for the next step.
- Run
npx browserslistfrom your project to get the actual target browsers. - Add a test for the input using the target browsers from 4, to the
./crates/swc/tests/fixture/issues/10xxx/10266/input/ - Modify
.swcrcto haveenv.debug: true.
(See playground)
- Run the test with
cargo test --test projects 10266 -- --nocapture. It will give you the list of passes enabled bypreset-envmode. - Check each pass to see if the pass has something to do with reserved keywords. You can search for
reservedin the code of each pass. - Fix it to use the correct syntax context. See https://swc.rs/docs/contributing/es-commons/variable-management for the documentation for the syntax context.
- Create a PR for it
Thank you in advance!
@kdy1 I followed the instructions in your comment; however, in swc_ecma_compat_es3/reserved_words, specifically in visit_mut_ident, both boolean instances in the playground have ctxt: #2, so it might be something other than other reserved words that causes the problem. Am I right?
Yes, I think so.
But note that https://github.com/swc-project/swc/pull/10274 may have fixed this issue. You can run UPDATE cargo test --test projects 10266 to see if it's the case.
No, it didn't fix the issue.