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

Cannot minify JavaScript file contains a bare Unicode escape identifier #9244

Closed
makenowjust opened this issue Dec 4, 2021 · 3 comments · Fixed by #9382
Closed

Cannot minify JavaScript file contains a bare Unicode escape identifier #9244

makenowjust opened this issue Dec 4, 2021 · 3 comments · Fixed by #9382
Labels

Comments

@makenowjust
Copy link

The following JavaScript source code seems odd, but it is completely legal. (See ECMA-262)

const _\u00bare_unicode_escape_identifier = 42;
console.log(_\u00bare_unicode_escape_identifier);

And, such a source code is generated by Scala.js.

When Hugo tries to minify a source containing a bare Unicode escape identifier, it shows the following error:

Start building sites …
hugo v0.89.4+extended darwin/amd64 BuildDate=unknown
Error: Error building site: MINIFY: failed to transform "index.js" (application/javascript): unexpected \u00BAre_unicode_identifier in var statement on line 3 and column 8
    3:   var _\u00BAre_unicode_identifier = 42;
              ^

Noting that the latest ESBuild supports minifying source codes with a bare Unicode escape identifier, I think this problem is solved if ESBuild is updated.

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.89.4+extended darwin/amd64 BuildDate=unknown

Does this issue reproduce with the latest release?

Yes

@pamubay
Copy link

pamubay commented Dec 4, 2021

Just tried minification using esbuild using js.Build function, it works. But it doesnt work if you are using minify or resources.Minify.

minify or resources.Minify minification function is handled by tdewolff/minify.

If you want to use esbuild to handle minification, you need to set it on js.Build options

{{- $jsOpts := dict "minify" true -}}
{{- $js := resources.Get "js/script.js" | js.Build $jsOpts }}
<script src="{{ $js.Permalink }}"></script>     

Hugo Version:

hugo v0.90.0-DEV-75A823A3+extended linux/amd64 BuildDate=2021-11-26T11:59:58+0700

@makenowjust
Copy link
Author

makenowjust commented Dec 4, 2021

Thanks for clarification.

I will use esbuild to minify, and will open a new issue on tdewolff/minify.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
2 participants