es6 and closure primitives

41 views
Skip to first unread message

Ryan Brown

unread,
Jul 15, 2024, 7:01:47 PM7/15/24
to Closure Compiler Discuss
I have been experimenting with converting closure library to es6.
However, I can't seem to figure out a way to do this and still have the closure primitives be recognized by the compiler.
For example, isPropertyRenameFunction seems to want one of these things
(NAME JSCompiler_renameProperty)
(GETPROP objectProperty (GETPROP reflect (NAME goog)))
(NAME goog$reflect$objectProperty)

I can't figure out how to get any of these from an es6 module.

If I write something like this:
var JSCompiler_renameProperty = function(x) {
    return x;
}
const fooieKey2 = JSCompiler_renameProperty("fooie");

I end up with a FUNCTION node for JSCompiler_renameProperty instead of a NAME node.

For object property I first tried this in goog/reflect/reflect.js

goog.declareModuleId('goog.reflect');
export function objectProperty(prop, object) {
 return prop;
}

Bug again I get a FUNCTION node.

I also tried putting this into goog.js and importing that into my test module:
export const reflect = {
  objectProperty(prop, object) {
    return prop;
  },
}

That seems to be closer, but now I get 
(GETPROPERTY objectProperty (NAME goog$reflect))


Is there some way I can get this to work?

John Lenz

unread,
Jul 16, 2024, 11:12:44 AM7/16/24
to closure-compiler
The compiler would need to be updated to recognize them as ES module definitions. 

The primitives would most likely need annotations (@closurePrimitive) for the compiler to find them and be more dynamic in how it looked for them.   Perhaps tagging or renaming the calls in one pass.





--

---
You received this message because you are subscribed to the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/closure-compiler-discuss/6e01bee1-dbfc-4b8e-a96b-09499ebc3b4bn%40googlegroups.com.

Ryan Brown

unread,
Jul 31, 2024, 12:58:20 PM7/31/24
to closure-comp...@googlegroups.com
So since you rejected supporting @closurePrimitive for the reflect methods, is there going to be some other way to use the reflection primitives from an es6 module?

Reply all
Reply to author
Forward
0 new messages