closure-compiler
                                
                                 closure-compiler copied to clipboard
                                
                                    closure-compiler copied to clipboard
                            
                            
                            
                        Functions annotated with @nosideeffects are not removed when it is aliased
In the below example, Object.getOwnPropertyDescriptor is annotated with @nosideeffects in es5.js, but its calls are not removed.
let a = Object.getOwnPropertyDescriptor;
let b = Object.getOwnPropertyDescriptor(Object.prototype, 'hasOwnProperty');
let c = a(Object.prototype,'__proto__').get;
'use strict'; var a = Object.getOwnPropertyDescriptor; Object.getOwnPropertyDescriptor(Object.prototype, "hasOwnProperty"); a(Object.prototype, "__proto__");
Originally from https://groups.google.com/g/closure-compiler-discuss/c/1ibhiOqVzHo/m/Y5TIDPbpAQAJ.
@nreid260 Hi, I think this issue is not fixed in the version published in NPM.
It seems to be working in the closure-compiler-debugger, but can still be reproduced by using the latest NPM version (20210808.0.0)
Here are the precise files and compiler flags that I'm using. I'd appreciate if this issue is revisited.
a.js
let a = Object.getOwnPropertyDescriptor;
let b = Object.getOwnPropertyDescriptor(Object.prototype, 'hasOwnProperty');
let c = a(Object.prototype,'__proto__').get;
closure.conf
--compilation_level=ADVANCED
--js a.js
--js_output_file=out.js
--language_in=ECMASCRIPT_2020
--language_out=ECMASCRIPT_2020
--emit_use_strict=false
--assume_function_wrapper=true
command:
google-closure-compiler --flagfile=closure.conf
output:
let a=Object.getOwnPropertyDescriptor;Object.getOwnPropertyDescriptor(Object.prototype,"hasOwnProperty");a(Object.prototype,"__proto__");
The expected output is an empty file, but as you can see, Object.getOwnPropertyDescriptor calls are not removed.
There was a delay in the NPM release that we didn't realize. This might be fixed now.
On my end, the issue persists on the current nightly version 20210901.0.0-nightly which was published only 6 hours ago, so I think something that might be fixed now cannot be a cause.
What externs are you using? Object.getOwnPropertyDescriptor needs to be defined in externs and annotated with @nosideeffects. The "canonical" externs do this, but I can't tell if those are part of your example.
Whatever externs that the NPM version feed by default. My understanding is that this includes "canonical" externs such as es3.js for example.
@nreid260 The issue persists on 20210906.0.0-nightly.
Friendly ping, this issue is still reproducible on [email protected].
It appears that the issue now coming from a somewhere else, which reminds me of https://github.com/google/closure-compiler/issues/2132. The inclusion of the externs es6_proxy.js seems to be the culprit. It contains a @record which has a property getOwnPropertyDescriptor. Mere existence of it prevents closure compiler from removing a code that has no side effect. JSCompiler Debugger repro