define doesn't seem to trigger code elimination?
See original GitHub issueUsing this command npx tsup ./x.ts --define.process.platform \"linux\" --minify
and the following file.
const _platform = process.platform;
const _linux = (_platform === 'linux');
const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
const _netbsd = (_platform === 'netbsd');
const _sunos = (_platform === 'sunos');
if (_platform === 'linux') console.log('linux');
// The following should be removed?
if (_windows) console.log('windows');
if (_freebsd || _darwin) console.log('freebsd or mac?');
We end up with this.
var o="linux";var n=o==="darwin",s=o==="win32",e=o==="freebsd";o==="linux"&&console.log("linux");s&&console.log("windows");(e||n)&&console.log("freebsd or mac?");
I was expecting the following since all of the vars could be resolved to true/false
and then can be removed resulting in only the linux code.
console.log("linux");
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Dead-code elimination - Wikipedia
In compiler theory, dead-code elimination is a compiler optimization to remove code which does not affect the program results. Removing such code has ......
Read more >Why can't dead code detection be fully solved by a compiler?
"Unconditional dead code can be detected and removed by advanced compilers." This does not seem likely. Code deadness can depend on the outcome ......
Read more >Debugging - Definition - The Economic Times
Definition: Debugging is the process of detecting and removing of existing and potential errors (also called as 'bugs') in a software code that...
Read more >25.3.1 Trigger Syntax and Examples - MySQL :: Developer Zone
Trigger names exist in the schema namespace, meaning that all triggers must have unique names within a schema. Triggers in different schemas can...
Read more >Error codes in Device Manager in Windows - Microsoft Support
From Start, search for device manager and select Device Manager from the results. Right-click the device in the list. Select Uninstall from the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You should inline the expression:
Yeah, I guess it’s more complex than it seems for minifiers to implement optimizations like that.