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

Adding --minfy causes unexpected "/js/jquery.tagcloud.js" in binding #8693

Closed
shadycuz opened this issue Jun 26, 2021 · 4 comments
Closed

Adding --minfy causes unexpected "/js/jquery.tagcloud.js" in binding #8693

shadycuz opened this issue Jun 26, 2021 · 4 comments

Comments

@shadycuz
Copy link

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

$ hugo version
hugo v0.84.1-4BD65E22 linux/amd64 BuildDate=2021-06-24T11:44:23Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

I think this is the latest release. It did not do this on 0.79.

The code from my partials/footer.html.

<!-- jquery.tagcloud.js -->
<script>
    // only load tagcloud.js in tag.html
    if($('#tag_cloud').length !== 0){
        async("/js/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                //size: {start: 1, end: 1, unit: 'em'},
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>

The cmd and err.

shadycuz-> hugo --gc --minify
Start building sites … 
hugo v0.84.1-4BD65E22 linux/amd64 BuildDate=2021-06-24T11:44:23Z VendorInfo=gohugoio
Page.URL is deprecated and will be removed in a future release. Use .Permalink or .RelPermalink. If what you want is the front matter URL value, use .Params.url
ERROR 2021/06/26 07:06:29 unexpected "/js/jquery.tagcloud.js" in binding on line 606 and column 23
    4:         async("/js/jquery.tagcloud.js",function(){
                     ^
ERROR 2021/06/26 07:06:29 unexpected "/js/jquery.tagcloud.js" in binding on line 736 and column 23
    4:         async("/js/jquery.tagcloud.js",function(){
                     ^
ERROR 2021/06/26 07:06:29 unexpected "/js/jquery.tagcloud.js" in binding on line 842 and column 23
    4:         async("/js/jquery.tagcloud.js",function(){
                     ^
ERROR 2021/06/26 07:06:29 unexpected "/js/jquery.tagcloud.js" in binding on line 691 and column 23
    4:         async("/js/jquery.tagcloud.js",function(){
                     ^
Total in 193 ms
Error: Error building site: failed to render pages: unexpected "/js/jquery.tagcloud.js" in binding on line 899 and column 23
    4:         async("/js/jquery.tagcloud.js",function(){
@pamubay
Copy link

pamubay commented Jun 26, 2021

This is upstream issue from tdewolff/minify.

minify failed if found js function named async.
Related issue in upstream JS: unable to parse if a function is named "async".

Already fixed in tdewolff/minify v2.9.17

Hugo still use tdewolff/minify v2.9.16

@bep bep closed this as completed in d9bdd37 Jun 26, 2021
@bep bep added this to the v0.85 milestone Jun 26, 2021
@earthboundkid
Copy link
Contributor

To be clear, your JS is technically okay, but they made async a keyword in later versions of JS, so naming a function async is an invitation for bugs that creep in when programs don't consider that async could be used as a normal variable name. I suggest the following edit to your footer to prevent future bugs:

<script>
    // only load tagcloud.js in tag.html
    if($('#tag_cloud').length !== 0){
        window.async("/js/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                //size: {start: 1, end: 1, unit: 'em'},
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>

window.whatever is technically the same as whatever, but window.async is less likely to hit unexpected bugs like this.

@robsonsobral
Copy link

Hi!

I just want to let you know that the minification of conditional chaining is still broken.

@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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 18, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants