ligershark / WebOptimizer

A bundler and minifier for ASP.NET Core
Apache License 2.0
753 stars 113 forks source link

JavaScript module not minified when importing both default and named export #257

Closed limsbeheer closed 1 year ago

limsbeheer commented 1 year ago

Setup

In a Windows .NET 7.0 webapplication there are two JavaScript modules:

sub.js:

export default () => console.log('default');

export const foo = () => console.log('foo');

main.js:

import bar, { foo } from './sub.js';

bar(), foo();

In Index.cshtml the main module is called:

...
<script type="module" async="async">
    import '/js/main.js';
</script>
...

Both files are minified with WebOptimizer version 3.0.372 in Program.cs:

...
builder.Services.AddWebOptimizer(pipeline => pipeline.MinifyJsFiles("/js/main.js", "/js/sub.js"));
...

Result

sub.js is correctly minified:

export default()=>console.log("default");export const foo=()=>console.log("foo")

main.js is not minified and errors are displayed:

/* input(1,11-12): run-time error JS1332: Expected "from": ,
input(1,11-12): run-time error JS1333: Expected string literal: ,
input(1,11): run-time error JS1004: Expected ';'
input(1,11-12): run-time error JS1195: Expected expression: ,
input(1,25): run-time error JS1004: Expected ';'
input(1,1-11): run-time error JS1328: Import statement must include module name: import bar */
import bar, { foo } from './sub.js';

bar(),
    foo();

With property IgnoreAllErrors = true the incorrectly minified response is visible:

import bar from;foo;from;bar();foo()

The import statement with both default and named export gets corrupted.

limsbeheer commented 1 year ago

Is a NUglify issue.