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
We have next.js project, which recently switched to SWC as the preferred optimiser lib. The components we use in that project originate from an internal component lib which still uses terser for the same purpose.
Now we discovered some very strange behaviour with one of our components, but only when used in the next.js project.
After digging into it a bit, we discovered that the problem seems to be SWC wrongly resolving a boolean construct, when it was beforehand optimised by terser.
In addition to the example I put in below, I made the example executable in a Fiddle: https://jsfiddle.net/nk1x74th/1/ I hope this helps...
Input code
// this the original code, just for comparisonfunctionLimit(min,max){varlength=Math.abs(min-max);functionreachedMin(n){returnn<min;}functionreachedMax(n){returnn>max;}functionreachedAny(n){returnreachedMin(n)||reachedMax(n);}functionconstrain(n){if(!reachedAny(n))returnn;returnreachedMin(n) ? min : max;}functionremoveOffset(n){if(!length)returnn;returnn-length*Math.ceil((n-max)/length);}varself={length: length,max: max,min: min,constrain: constrain,reachedAny: reachedAny,reachedMax: reachedMax,reachedMin: reachedMin,removeOffset: removeOffset};returnself;}console.log("The result should be 0. And it is:",Limit(0,3).constrain(-1))// this is the same code after being optimised by terser (with default settings)console.log("The result should be 0. And it is:",function(n,e){varr=Math.abs(n-e);functiont(e){returne<n}functionu(n){returnn>e}functionc(n){returnt(n)||u(n)}return{length:r,max:e,min:n,constrain:function(r){returnc(r)?t(r)?n:e:r},reachedAny:c,reachedMax:u,reachedMin:t,removeOffset:function(n){returnr?n-r*Math.ceil((n-e)/r):n}}}(0,3).constrain(-1));
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Describe the bug
We have next.js project, which recently switched to SWC as the preferred optimiser lib. The components we use in that project originate from an internal component lib which still uses terser for the same purpose.
Now we discovered some very strange behaviour with one of our components, but only when used in the next.js project.
After digging into it a bit, we discovered that the problem seems to be SWC wrongly resolving a boolean construct, when it was beforehand optimised by terser.
In addition to the example I put in below, I made the example executable in a Fiddle: https://jsfiddle.net/nk1x74th/1/ I hope this helps...
Input code
Config
Playground link
https://play.swc.rs/?version=1.3.32&code=H4sIAAAAAAAAA5VTS1LjMBDd%2BxQ9rGxKiaHYyUCKPSk2cwHhtGNRdouSZD6V%2BO4jxbJlD8mCjdRS%2F9%2FrznOwtTTuQFBa7iWJBkq1QwZvnbFQKe2e7bvQ0ihKqo5KKxXBs2ylTVtJDFrxlcEhAfgQGhqkva3hAbbC1mvxarwNrE5GReKMpggaRVnjbisppcEf3J%2FtNAHBPTi3wv31Z33E1xmfR5%2Fkos8Tff%2FwWZZwPC7j%2FwxVKjJWi3nFsoL0zyJFNlVUXM618f0Bv1Rxqz7wpaoM2v8yDfBeSOFxDvhfD%2FiXKJs0HfGHPKhja54yg03lCBuyDAY83Oz053xPlYaXJO6P4TVBwqPIQlEjKHwmL3RbHzjKS50PGeVRF5Hhi5dvyHcVoPA9FUmf%2BJpUg%2BtG7dOrv27GNZqusWBq1TU7eEW4WcMT7UBakIZfsTDYN%2BwuW0e6V7dZliR52JWwLka0eFoV%2BKyRQL1b52rQRf0Gi9qg%2Fn36cQZSYpgdPDv6YdokWmFWTFNiU2cR2sV76idF52ZmVNAjRkU5U%2FjBOh69aT%2F8HALzmnm6kXmaiUV6p8r0FKN08sb6gzhy3bMZ5SWbcdyxGamWLViMHU9x9YZW%2Bno%2BwK7xXGec%2Br4%2FR03xD2P53tXGBAAA&config=H4sIAAAAAAAAA3VUy5LjIAz8F8457B5ma2s%2BYG%2FzDRQxwmEGIxcSTlwp%2F%2FsIP3CczN6gaQlJ3XBXn9So97vqTSJIZUVjZHNT7wqazlCTfM%2FqJDSBOGWYTopNaoELg97kKCASLIcn1fno3VjyNNj1CYjKWgJyB5Fl40wg4ZmU8Epb1BkxgIkve21I%2B8jQQtpDGwzB9AR6MKlGlNtM8oTxAGUGq%2FuE%2FQMarWePUZJtmAVjdYO2dmF9gob9ADtFcgglkhRWK5lBC%2BfctmV2CxMGE7Lhmgtu8xjkxhp3QU%2BsXY70BB0qXaClyZXlnU7AOcWN84k%2BHubwBSB1BkMUTQd75Iw70eHIdD%2BwfHQiIo8VFYH3qiK00pz23tUOS9WQ2O%2FTSmBzA6XDZk%2B%2BgoeGyFvQ4JxMuwbT1XNz2ZPx2AO6upWpGbdrsGz15qcjWizwAv6TqvhRjhXvDF%2BeMRq7M4aXFB3wBe0LLINgfAaTuPfWP6M5WpAxg304yFS21aYiPqMO5aVtcxZDSIxuA56rfeVBdia2xZZ3xdgHGCAcFf2vH37A5JKhCLxacTMe%2FN01M%2BIj%2F%2FvXCkxTqQBtXisQteav4Y%2Ba9u9gacDTx8qTbr8iXqN8HxCHOW7%2BVORGJZi8KOdvmwWm6Rs4TwuUpwQAAA%3D%3D
Expected behavior
The SWC optimisation should not break the logic of the contrain method, even if the code was beforehand optimised by another optimiser.
Actual behavior
constrain:function(r){return c(r)?t(r)?n:e:r}
gets transformed toconstrain:function(t){return t>e?t<n?n:e:t}
which has not the same logic as beforeVersion
1.3.32
Additional context
No response
The text was updated successfully, but these errors were encountered: