-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Example JS, as put in the externs/modules/modules.js file:
/**
* @typedef {(string|number|boolean)}
*/
baz.structural;
Results in this stack trace:
Exception in thread "main" java.lang.UnsupportedOperationException
at com.google.javascript.rhino.jstype.Property.getScope(Property.java:185)
at jsinterop.generator.closure.visitor.AbstractClosureVisitor.acceptTypedef(AbstractClosureVisitor.java:175)
at jsinterop.generator.closure.visitor.AbstractClosureVisitor.accept(AbstractClosureVisitor.java:86)
at jsinterop.generator.closure.visitor.AbstractClosureVisitor.lambda$acceptProperties$1(AbstractClosureVisitor.java:247)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.TreeMap$KeySpliterator.forEachRemaining(TreeMap.java:2739)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
at jsinterop.generator.closure.visitor.AbstractClosureVisitor.acceptProperties(AbstractClosureVisitor.java:244)
at jsinterop.generator.closure.visitor.AbstractClosureVisitor.acceptModule(AbstractClosureVisitor.java:195)
at jsinterop.generator.closure.visitor.AbstractClosureVisitor.accept(AbstractClosureVisitor.java:84)
at jsinterop.generator.closure.visitor.AbstractClosureVisitor.accept(AbstractClosureVisitor.java:64)
at jsinterop.generator.closure.visitor.TypeCollector.accept(TypeCollector.java:41)
at jsinterop.generator.closure.ClosureJsInteropGenerator.generateJavaProgram(ClosureJsInteropGenerator.java:170)
at jsinterop.generator.closure.ClosureJsInteropGenerator.convert(ClosureJsInteropGenerator.java:68)
This is because the StaticTypedSlot instance passed here to AbstractClosureVisitor.acceptTypedef(...) is a closure Property, which throws when it is asked for its scope:
https://github.com/google/closure-compiler/blob/00ad3658b30221987fbbfe4a59db7e298d68cd72/src/com/google/javascript/rhino/jstype/Property.java#L183-L186
@Override
public StaticTypedScope getScope() {
throw new UnsupportedOperationException();
}
My workaround for now is to just remove these typedefs and hope they don't matter to the eventual compilation, but they are hard to avoid:
- https://github.com/google/closure-compiler/blob/master/contrib/externs/maps/google_maps_api_v3.js#L961-L964
- https://github.com/protocolbuffers/protobuf/blob/master/js/binary/constants.js#L92-L97
- https://github.com/google/closure-compiler/blob/master/contrib/externs/chrome_extensions.js#L547-L564
I explored options for a fix briefly, but I'm struggling to find examples in closure-compiler which show how to read a Property to see its type, without either just asking Property.getType() or having a valid "scope" for it.