TooTallNate / node-bindings

Helper module for loading your native module's `.node` file
MIT License
412 stars 95 forks source link

Cannot minify easily because of a getter with side-effect #55

Open jaubourg opened 5 years ago

jaubourg commented 5 years ago

I was minifying a project with a package depending on node-bindings and the resulting code ended up throwing an exception regarding some path not being a string.

I pinpointed the problem in getRoot which led to the realization that getFileName was returning undefined. Finally, I spotted the culprit: dummy.stack (https://github.com/TooTallNate/node-bindings/blob/master/bindings.js#L168).

Most minifiers will remove code with no side effect, just like getting a property of an object while seemingly not having any use for it.

Since I use uglify-es, I'm able to set the pure_getters compress option to false, which instructs the minifier to be extra-conservative regarding object property accesses.

I dunno if this is something you'd like to "fix" but I thought people should know in case they encounter the same issue.

thisTom commented 5 years ago

I was minifying a project with a package depending on node-bindings and the resulting code ended up throwing an exception regarding some path not being a string.

I pinpointed the problem in getRoot which led to the realization that getFileName was returning undefined. Finally, I spotted the culprit: dummy.stack (https://github.com/TooTallNate/node-bindings/blob/master/bindings.js#L168).

Most minifiers will remove code with no side effect, just like getting a property of an object while seemingly not having any use for it.

Since I use uglify-es, I'm able to set the pure_getters compress option to false, which instructs the minifier to be extra-conservative regarding object property accesses.

I dunno if this is something you'd like to "fix" but I thought people should know in case they encounter the same issue.

thank you for this , this problem Trouble me whole week!