google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.36k stars 1.14k forks source link

Can't use goog.reflect.object/objectProperty from es6 module. #4182

Open ribrdb opened 1 month ago

ribrdb commented 1 month ago

I see that objectProperty and object are available in closure-compiler/lib/reflect.js. However I do not see any way to use these from an es6 module. I tried adding these to goog.js and using it like this:

import * as goog from 'goog.js'
const x = goog.reflect.objectProperty(...)

However goog.js only seems to work with properties of goog itself, not two-levels deep. I end up with an ast like (GETPROPERTY objectProperty (NAME goog$reflect)), but the isPropertyRenameFunction method only allows one of these:

(NAME JSCompiler_renameProperty)
(GETPROP objectProperty (GETPROP reflect (NAME goog)))
(NAME goog$reflect$objectProperty)
lauraharker commented 1 month ago

From our team's triage meeting - we don't have bandwidth to investigate right now but if you can find a solution besides @closurePrimitive would be happy to review

ribrdb commented 1 week ago

It appears that adding JSCompiler_renameProperty to base.js or to an externs file allows it to work from an es6 module. I think this will be sufficient for our use, but maybe this should be documented somewhere? Perhaps https://github.com/google/closure-compiler/wiki/Type-Based-Property-Renaming