google / google/jsinterop-generator

Operating on non-externs?

Open
#44 5 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
85
Forks
24
PR merge metrics
No merged PRs in 30d

Description

I'm experimenting with taking [Closure-annotated](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler) JS (both hand-written and generated from TypeScript via [tsickle](https://github.com/angular/tsickle/)). I was surprised to discover that when the generator runs, it only emits jsinterop types that represent the provided externs - "actual" JS gets no java generated for it.

As an example, take a j2cl-based project with closure-compatible JS libraries that need to be used/consumed from Java. Feeding non-`@extern` js results in no output (and a chmod error in format_jarsrc), probably because `jsinterop.generator.closure.ClosureJsInteropGenerator#generateJarFile` removes non-extern files - removing that check results in the tool trying to also generate java for dependencies (like elemental2-core+promise, which effectively every library must depend on).

--

Going a bit further: It appears from poking around in the repo that I might just be thinking about this wrong or using the tool wrong, and that this isn't a real limitation. For example, `DependencyFileWriter` specifically calls out TypeScript rather than closure externs?
> This file makes the link between typescript type and java type and is used when a generated library is used as dependency of another generated library.

Are typescript .d.ts files intended to be supported, specifically those generated via tsickle? The sample I tried nearly works, at least with this one addition to `jsinterop.generator.closure.ClosureJsInteropGenerator#createCompilerOptions`:

```
options.setLanguageIn(ECMASCRIPT6_TYPED);
```
but even then the library I'm working with hits errors, whether operating tsc-generated .d.ts files, or ones emitted by tsickle (and for the record, I've been unable to get tsickle yet to emit actual externs, it only wants to provide either `.mjs` files with an empty externs.js, or `.js`+`.d.ts`. Perhaps it works better if you avoid bazel, but my goal was to stay within the ecosystem).

--

Are these use cases intended to be supported, or am I just doing it wrong?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.