mirror of https://github.com/webpack/webpack.git
				
				
				
			fix: dead control flow with deep nested if (#19403)
This commit is contained in:
		
							parent
							
								
									44da94f433
								
							
						
					
					
						commit
						278fcb6da9
					
				|  | @ -2200,6 +2200,9 @@ class JavascriptParser extends Parser { | ||||||
| 			this.inExecutedPath(false, () => { | 			this.inExecutedPath(false, () => { | ||||||
| 				this.walkExpression(statement.test); | 				this.walkExpression(statement.test); | ||||||
| 				this.walkNestedStatement(statement.consequent); | 				this.walkNestedStatement(statement.consequent); | ||||||
|  | 			}); | ||||||
|  | 
 | ||||||
|  | 			this.inExecutedPath(true, () => { | ||||||
| 				if (statement.alternate) { | 				if (statement.alternate) { | ||||||
| 					this.walkNestedStatement(statement.alternate); | 					this.walkNestedStatement(statement.alternate); | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
|  | @ -4781,22 +4781,15 @@ exports[`StatsTestCases should print correct stats for track-returned 1`] = ` | ||||||
| ./used8.js X bytes [built] [code generated] | ./used8.js X bytes [built] [code generated] | ||||||
| ./used9.js X bytes [built] [code generated] | ./used9.js X bytes [built] [code generated] | ||||||
| ./used16.js X bytes [built] [code generated] | ./used16.js X bytes [built] [code generated] | ||||||
|  | ./used69.js X bytes [built] [code generated] | ||||||
| ./used17.js X bytes [built] [code generated] | ./used17.js X bytes [built] [code generated] | ||||||
| ./used18.js X bytes [built] [code generated] | ./used18.js X bytes [built] [code generated] | ||||||
| ./used19.js X bytes [built] [code generated] | ./used19.js X bytes [built] [code generated] | ||||||
| ./used48.js X bytes [built] [code generated] | ./used48.js X bytes [built] [code generated] | ||||||
| ./used35.js X bytes [built] [code generated] | ./used35.js X bytes [built] [code generated] | ||||||
| ./used10.js X bytes [built] [code generated] | ./used10.js X bytes [built] [code generated] | ||||||
| ./used11.js X bytes [built] [code generated] | + 56 modules | ||||||
| + 38 modules | webpack x.x.x compiled successfully in X ms" | ||||||
| 
 |  | ||||||
| WARNING in ./index.js 227:3-20 |  | ||||||
| Module not found: Error: Can't resolve 'fail47' in 'Xdir/track-returned' |  | ||||||
| 
 |  | ||||||
| 1 warning has detailed information that is not shown. |  | ||||||
| Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it. |  | ||||||
| 
 |  | ||||||
| webpack x.x.x compiled with 1 warning in X ms" |  | ||||||
| `; | `; | ||||||
| 
 | 
 | ||||||
| exports[`StatsTestCases should print correct stats for tree-shaking 1`] = ` | exports[`StatsTestCases should print correct stats for tree-shaking 1`] = ` | ||||||
|  |  | ||||||
|  | @ -224,7 +224,8 @@ it("should work correct for try catch and loops", () => { | ||||||
| 				require('./used16'); | 				require('./used16'); | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			require('fail47'); | 			// TODO potential improvement
 | ||||||
|  | 			require('./used69'); | ||||||
| 		} catch (e) { | 		} catch (e) { | ||||||
| 			require('./used17'); | 			require('./used17'); | ||||||
| 		} finally { | 		} finally { | ||||||
|  | @ -565,7 +566,7 @@ it("should work correct for try catch and loops", () => { | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	function test25() { | 	function test25a() { | ||||||
| 		try { | 		try { | ||||||
| 			return; | 			return; | ||||||
| 		} finally { | 		} finally { | ||||||
|  | @ -703,6 +704,16 @@ it("should work correct for try catch and loops", () => { | ||||||
| 		require("./used51"); | 		require("./used51"); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	function test36() { | ||||||
|  | 		test(); | ||||||
|  | 
 | ||||||
|  | 		throw 1; | ||||||
|  | 
 | ||||||
|  | 		function test() { | ||||||
|  | 			require("./used67") | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	for(let i = 0; i < 1; i++) | 	for(let i = 0; i < 1; i++) | ||||||
| 		if (rand()) | 		if (rand()) | ||||||
| 			require('./used1'); | 			require('./used1'); | ||||||
|  | @ -778,6 +789,410 @@ it("should work correct for if #4", () => { | ||||||
| 	} | 	} | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | it("should work correct for if #5", () => { | ||||||
|  | 	if (rand()) | ||||||
|  | 		return; | ||||||
|  | 	else if (rand()) | ||||||
|  | 		return; | ||||||
|  | 	else { | ||||||
|  | 		const test = 1; | ||||||
|  | 		require("./used52") | ||||||
|  | 	} | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #6", () => { | ||||||
|  | 	if (rand()) | ||||||
|  | 		return; | ||||||
|  | 	else { | ||||||
|  | 		const test = 1; | ||||||
|  | 		require("./used53") | ||||||
|  | 	} | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #7", () => { | ||||||
|  | 	if (rand()) | ||||||
|  | 		return; | ||||||
|  | 	else | ||||||
|  | 		return; | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #8", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		rand() | ||||||
|  | 	} else if (rand()) { | ||||||
|  | 		rand() | ||||||
|  | 	} else | ||||||
|  | 		return; | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #9", () => { | ||||||
|  | 	if (true) { | ||||||
|  | 		return; | ||||||
|  | 	} else if (rand()) { | ||||||
|  | 		require("fail"); | ||||||
|  | 	} else | ||||||
|  | 		require("fail"); | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #10", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		return; | ||||||
|  | 	} else if (true) { | ||||||
|  | 		return; | ||||||
|  | 	} else | ||||||
|  | 		require("fail"); | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #11", () => { | ||||||
|  | 	if (false) | ||||||
|  | 		return; | ||||||
|  | 	else if (rand()) { | ||||||
|  | 		return; | ||||||
|  | 	} else | ||||||
|  | 		return; | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #12", () => { | ||||||
|  | 	if (false) | ||||||
|  | 		return; | ||||||
|  | 	else if (false) { | ||||||
|  | 		return; | ||||||
|  | 	} else | ||||||
|  | 		return; | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #13", () => { | ||||||
|  | 	if (true) | ||||||
|  | 		return; | ||||||
|  | 	else if (true) { | ||||||
|  | 		return; | ||||||
|  | 	} else | ||||||
|  | 		return; | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #13", () => { | ||||||
|  | 	if (false) | ||||||
|  | 		return; | ||||||
|  | 	else if (false) { | ||||||
|  | 		return; | ||||||
|  | 	} else {} | ||||||
|  | 
 | ||||||
|  | 	require("./used54"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #14", () => { | ||||||
|  | 	if (fn()) | ||||||
|  | 		return; | ||||||
|  | 	else if (fn()) { | ||||||
|  | 		fn() | ||||||
|  | 		require("./used55"); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	require("./used56"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #15", () => { | ||||||
|  | 	if (true) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #16", () => { | ||||||
|  | 	if (true) return; | ||||||
|  | 
 | ||||||
|  | 	const test = 1; | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #17", () => { | ||||||
|  | 	if (false) return; | ||||||
|  | 
 | ||||||
|  | 	const test = 1; | ||||||
|  | 	require("./used57"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #18", () => { | ||||||
|  | 	if (rand()) return; | ||||||
|  | 
 | ||||||
|  | 	const test = 1; | ||||||
|  | 	require("./used58"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #19", () => { | ||||||
|  | 	if (!rand()) | ||||||
|  | 		// if reference flag is false ,then show the form and update the model with relative type list
 | ||||||
|  | 		return rand(); | ||||||
|  | 	else { | ||||||
|  | 		if (rand()) { | ||||||
|  | 			rand(); | ||||||
|  | 			require("./used59") | ||||||
|  | 			rand(); | ||||||
|  | 		} else { | ||||||
|  | 			rand(); | ||||||
|  | 			require("./used60"); | ||||||
|  | 			rand(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	require("./used61"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #20", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		return; | ||||||
|  | 	} else if (rand()) { | ||||||
|  | 		return; | ||||||
|  | 	} else if (rand()) { | ||||||
|  | 		return; | ||||||
|  | 	} else if (rand()) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	require("./used62"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #21", () => { | ||||||
|  | 	if (rand()) | ||||||
|  | 		return; | ||||||
|  | 	else if (rand()) | ||||||
|  | 		return; | ||||||
|  | 	else if (rand()) | ||||||
|  | 		return; | ||||||
|  | 	else if (rand()) | ||||||
|  | 		return; | ||||||
|  | 
 | ||||||
|  | 	require("./used63"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #22", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		if (true) { | ||||||
|  | 			return; | ||||||
|  | 		} else if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		require("fail"); | ||||||
|  | 	} else { | ||||||
|  | 		return; | ||||||
|  | 		require("fail"); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #23", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else if (true) { | ||||||
|  | 			return; | ||||||
|  | 		} else { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		require("fail"); | ||||||
|  | 	} else { | ||||||
|  | 		return; | ||||||
|  | 		require("fail"); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #24", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	require("./used64"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #25", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 	} else if (rand()) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	require("./used65"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #26", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 	} else if (rand()) { | ||||||
|  | 		return; | ||||||
|  | 	} else if (rand()) {} | ||||||
|  | 
 | ||||||
|  | 	require("./used66"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #22", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		// require("fail");
 | ||||||
|  | 	} else if (rand()) { | ||||||
|  | 		if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		// require("fail");
 | ||||||
|  | 	} else { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #23", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		if (rand()) | ||||||
|  | 			return; | ||||||
|  | 		else if (rand()) | ||||||
|  | 			return; | ||||||
|  | 		else | ||||||
|  | 			return; | ||||||
|  | 
 | ||||||
|  | 		require("fail"); | ||||||
|  | 	} else if (rand()) { | ||||||
|  | 		if (rand()) | ||||||
|  | 			return; | ||||||
|  | 		else | ||||||
|  | 			return; | ||||||
|  | 
 | ||||||
|  | 		require("fail"); | ||||||
|  | 	} else { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #24", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 	} else { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #25", () => { | ||||||
|  | 	if (rand()) | ||||||
|  | 		return; | ||||||
|  | 	else | ||||||
|  | 		if (rand()) | ||||||
|  | 			return; | ||||||
|  | 		else | ||||||
|  | 			return; | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #26", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		return; | ||||||
|  | 	} else | ||||||
|  | 		if (rand()) | ||||||
|  | 			return; | ||||||
|  | 		else | ||||||
|  | 			return; | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #27", () => { | ||||||
|  | 	if (rand()) | ||||||
|  | 		return; | ||||||
|  | 	else { | ||||||
|  | 		if (rand()) | ||||||
|  | 			return; | ||||||
|  | 		else | ||||||
|  | 			return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	require("fail"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #28", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else { | ||||||
|  | 			const test = 1; | ||||||
|  | 			require("./used68") | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		require("fail"); | ||||||
|  | 	} | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it("should work correct for if #29", () => { | ||||||
|  | 	if (rand()) { | ||||||
|  | 		return; | ||||||
|  | 		if (rand()) { | ||||||
|  | 			return; | ||||||
|  | 		} else { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		require("fail"); | ||||||
|  | 	} | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| it("should not include unused assets", (done) => { | it("should not include unused assets", (done) => { | ||||||
| 	let a, b; | 	let a, b; | ||||||
| 	(function() { | 	(function() { | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| module.exports = { | module.exports = { | ||||||
| 	validate(stats) { | 	validate(stats) { | ||||||
| 		expect(stats.compilation.modules.size).toBe(52); | 		expect(stats.compilation.modules.size).toBe(70); | ||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = 10; | ||||||
		Loading…
	
		Reference in New Issue