RFR: 8317621: --add-script should support JavaScript modules

Jonathan Gibbons jjg at openjdk.org
Tue May 14 17:33:10 UTC 2024


On Fri, 29 Mar 2024 09:39:18 GMT, Hannes Wallnöfer <hannesw at openjdk.org> wrote:

> Please review an enhancement to detect [JavaScript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) when added to `javadoc` with the `--add-script` option, which require a different `type` attribute in the HTML `<script>` element. The main method of detection is to scan the script content for `import` and `export` statements. The `*.mjs` extension is also recognized, although it is rarely used for browser modules. 
> 
> I have tested the recognition against scripts and modules in projects such as [Angular](https://github.com/angular/angular) and [Mermaid](https://github.com/mermaid-js/mermaid) and it worked quite well in detecting JavaScript modules.

generally great; some minor comments for your consideration

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java line 354:

> 352:             }
> 353:             return new JavaScriptFile(DocPath.create(file.getName()), isModule);
> 354:         }).collect(Collectors.toCollection(ArrayList::new));

stylistically, big lambdas like this are harder to read.  
Consider pulling the body of this code to a separate private local method, and then using a method reference in the lambda calls.

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java line 354:

> 352:             }
> 353:             return new JavaScriptFile(DocPath.create(file.getName()), isModule);
> 354:         }).collect(Collectors.toCollection(ArrayList::new));

I realize it is not a change in this PR, but is there a reason to use `Collectors.toCollection(ArrayList::new)` instead of `Collectors.toList()`

-------------

PR Review: https://git.openjdk.org/jdk/pull/18546#pullrequestreview-2056006489
PR Review Comment: https://git.openjdk.org/jdk/pull/18546#discussion_r1600403699
PR Review Comment: https://git.openjdk.org/jdk/pull/18546#discussion_r1600408077


More information about the javadoc-dev mailing list