On Fri, 29 Mar 2024 09:39:18 GMT, Hannes Wallnöfer <hann...@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.

I tested module detection on the [Angular 
project](https://github.com/angular/angular) which contains roughly 1100 `.js` 
files and 50 `.mjs` files.

 - All but one `.mjs` files were recognized as modules, with one file requiring 
the pattern to be updated to match `export async function...`.
 - Of the `.js` files, 33 were recognized as modules, of which 3 were false 
positives caused by module source contained in a string literal such as [this 
file](https://github.com/angular/angular/blob/main/packages/compiler-cli/esbuild.config.js).
 - I did not check for false negatives in `.js` files because of the number of 
files to look at, but it matches my expectation that most of the source and 
test code would be non-modular.

In the meantime I also researched usage of the `.mjs` extension and it turns 
out that `.mjs` is mosty used in Node.js, with `.js` being preferred in browser 
because of problems with web server MIME type configuration.

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

PR Comment: https://git.openjdk.org/jdk/pull/18546#issuecomment-2069924607

Reply via email to