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

minimize and production setting for ~ of iteration code ReferenceError #452

Closed
webpack-bot opened this issue Sep 9, 2019 · 4 comments
Closed

Comments

@webpack-bot
Copy link

Bug report

What is the current behavior?
here is sample code.

function test() {
    try {
        const arr = [1];
        const arr2 = [1, 2];
        for (const x of arr) {
            console.log(x);
        }
        console.log(arr2);
        return true;
    } catch (err) {
        throw err;
    }
}

here is config

module.exports =
	{
		mode: 'production',
		optimization: {
			minimize: true
		},
		devtool: 'inline-source-map',
	};

ReferenceError: arr is not defined

seems like (try catch + for of) code is not working.

here is test repo
https://github.com/scarfunk/webpackbug-minimize

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

Other relevant information:
webpack version: 4.39.3
Node.js version: 11.6.0 - ~/.nvm/versions/node/v11.6.0/bin/node
Operating System: macOS 10.14.4
Additional tools:


This issue was moved from webpack/webpack#9674 by @sokra. Original issue was by @scarfunk.

@sokra
Copy link

sokra commented Sep 9, 2019

raw terser minimizes:

(function() {
    try {
        const arr = [1];
        for (const x of arr) {
        }
    } catch {
    }
})()

to

!function(){try{for(const c of arr);}catch{}}();

Using var arr instead of const arr works fine. Also moving the declaration out of the try block.

@scarfunk
Copy link

scarfunk commented Sep 9, 2019

thanks for moving

@fabiosantoscode
Copy link
Collaborator

Silly bug :/ I was fixing the catch scope and broke for loops inside try blocks.

@fabiosantoscode
Copy link
Collaborator

Thank you for the report.

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

No branches or pull requests

4 participants