Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to minify js file if class contains method named import or export #403

Open
mrzewnicki opened this issue Aug 2, 2024 · 6 comments

Comments

@mrzewnicki
Copy link

Hi,

Problem occurs during minification of js file from external library. We are aware the import and export words are reserved keyword but we aren't able to change it in every new version of library files.

Code to reproduce:

var result = Uglify.Js(@"class bug {
    export() { console.log('omg'); }
    import() { console.log('omg'); }
}");
Console.WriteLine(result.HasErrors);
Console.WriteLine(result.Code);
Console.WriteLine(string.Join(", ", result.Errors.Select(e => e.Message)));
Console.ReadLine();

Result:

True
class bug{export(){console.log("omg")}import(){console.log("omg")}}
Expected identifier: export, Expected identifier: import
@trullock
Copy link
Owner

trullock commented Aug 4, 2024

Looks like it doesnt support overwriding the export and import keywords. should be a simple fix

@aliakseirublevski
Copy link

aliakseirublevski commented Jan 29, 2025

Hello, @trullock

Are there any plans/thoughts to address this problem?

We're blocked with this issue while updating our DevExpress UI bundle to a newer version (24.*) - their code contain a couple of import/export statements which fail our minification pipelines.

@trullock
Copy link
Owner

trullock commented Jan 29, 2025

Everything is planned but i have no time, sorry.

PRs welcome

Tomorrow ill take a look and tell you how to fix it, we had this issue before with another keyword so the codebase has prior art for this case so should be easily extended

@trullock
Copy link
Owner

Its probably the same fix as this #353 see the PR/commit that fixed it.

Replicate that commit (with tests, in the same way) and see if that solves it for you

@aliakseirublevski
Copy link

aliakseirublevski commented Feb 5, 2025

Its probably the same fix as this #353 see the PR/commit that fixed it.

Replicate that commit (with tests, in the same way) and see if that solves it for you

Leaving here some details for the history:

After I added import/export keywords and checked minification on my testing script (it's actually quite huge dx.all.debug.js) and indeed it helped - compilation errors were gone.

However, a runtime syntax exception happened, caused by a problem described here: #410

I did changes in the script to remove the problem syntax, but another syntax error appeared: "Identifier 'u' has already been declared".

JS code on this line uses clouses to access variables, so potentially this can be caused by #405 or #365 but I didn't investigate this further.

So as for now, we see that we should consider other bundling/minification options.

I hope someone finds this info helpful.

@trullock
Copy link
Owner

trullock commented Feb 5, 2025

Submit a pr with the import export fix and we can go from there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants