mirror of https://github.com/webpack/webpack.git
				
				
				
			Merge pull request #9458 from yvanwangl/master
HookMap: replace .tap() with .for().tap()
This commit is contained in:
		
						commit
						a1f0789efc
					
				|  | @ -25,20 +25,16 @@ module.exports = class ResolverFactory extends Tapable { | ||||||
| 			let match; | 			let match; | ||||||
| 			match = /^resolve-options (.+)$/.exec(options.name); | 			match = /^resolve-options (.+)$/.exec(options.name); | ||||||
| 			if (match) { | 			if (match) { | ||||||
| 				this.hooks.resolveOptions.tap( | 				this.hooks.resolveOptions | ||||||
| 					match[1], | 					.for(match[1]) | ||||||
| 					options.fn.name || "unnamed compat plugin", | 					.tap(options.fn.name || "unnamed compat plugin", options.fn); | ||||||
| 					options.fn |  | ||||||
| 				); |  | ||||||
| 				return true; | 				return true; | ||||||
| 			} | 			} | ||||||
| 			match = /^resolver (.+)$/.exec(options.name); | 			match = /^resolver (.+)$/.exec(options.name); | ||||||
| 			if (match) { | 			if (match) { | ||||||
| 				this.hooks.resolver.tap( | 				this.hooks.resolver | ||||||
| 					match[1], | 					.for(match[1]) | ||||||
| 					options.fn.name || "unnamed compat plugin", | 					.tap(options.fn.name || "unnamed compat plugin", options.fn); | ||||||
| 					options.fn |  | ||||||
| 				); |  | ||||||
| 				return true; | 				return true; | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | @ -259,48 +259,48 @@ describe("Parser", () => { | ||||||
| 			const state = testCases[name][1]; | 			const state = testCases[name][1]; | ||||||
| 
 | 
 | ||||||
| 			const testParser = new Parser({}); | 			const testParser = new Parser({}); | ||||||
| 			testParser.hooks.canRename.tap("abc", "ParserTest", expr => true); | 			testParser.hooks.canRename.for("abc").tap("ParserTest", expr => true); | ||||||
| 			testParser.hooks.canRename.tap("ijk", "ParserTest", expr => true); | 			testParser.hooks.canRename.for("ijk").tap("ParserTest", expr => true); | ||||||
| 			testParser.hooks.call.tap("abc", "ParserTest", expr => { | 			testParser.hooks.call.for("abc").tap("ParserTest", expr => { | ||||||
| 				if (!testParser.state.abc) testParser.state.abc = []; | 				if (!testParser.state.abc) testParser.state.abc = []; | ||||||
| 				testParser.state.abc.push(testParser.parseString(expr.arguments[0])); | 				testParser.state.abc.push(testParser.parseString(expr.arguments[0])); | ||||||
| 				return true; | 				return true; | ||||||
| 			}); | 			}); | ||||||
| 			testParser.hooks.call.tap("cde.abc", "ParserTest", expr => { | 			testParser.hooks.call.for("cde.abc").tap("ParserTest", expr => { | ||||||
| 				if (!testParser.state.cdeabc) testParser.state.cdeabc = []; | 				if (!testParser.state.cdeabc) testParser.state.cdeabc = []; | ||||||
| 				testParser.state.cdeabc.push(testParser.parseString(expr.arguments[0])); | 				testParser.state.cdeabc.push(testParser.parseString(expr.arguments[0])); | ||||||
| 				return true; | 				return true; | ||||||
| 			}); | 			}); | ||||||
| 			testParser.hooks.call.tap("cde.ddd.abc", "ParserTest", expr => { | 			testParser.hooks.call.for("cde.ddd.abc").tap("ParserTest", expr => { | ||||||
| 				if (!testParser.state.cdedddabc) testParser.state.cdedddabc = []; | 				if (!testParser.state.cdedddabc) testParser.state.cdedddabc = []; | ||||||
| 				testParser.state.cdedddabc.push( | 				testParser.state.cdedddabc.push( | ||||||
| 					testParser.parseString(expr.arguments[0]) | 					testParser.parseString(expr.arguments[0]) | ||||||
| 				); | 				); | ||||||
| 				return true; | 				return true; | ||||||
| 			}); | 			}); | ||||||
| 			testParser.hooks.expression.tap("fgh", "ParserTest", expr => { | 			testParser.hooks.expression.for("fgh").tap("ParserTest", expr => { | ||||||
| 				if (!testParser.state.fgh) testParser.state.fgh = []; | 				if (!testParser.state.fgh) testParser.state.fgh = []; | ||||||
| 				testParser.state.fgh.push( | 				testParser.state.fgh.push( | ||||||
| 					Array.from(testParser.scope.definitions.asSet()).join(" ") | 					Array.from(testParser.scope.definitions.asSet()).join(" ") | ||||||
| 				); | 				); | ||||||
| 				return true; | 				return true; | ||||||
| 			}); | 			}); | ||||||
| 			testParser.hooks.expression.tap("fgh.sub", "ParserTest", expr => { | 			testParser.hooks.expression.for("fgh.sub").tap("ParserTest", expr => { | ||||||
| 				if (!testParser.state.fghsub) testParser.state.fghsub = []; | 				if (!testParser.state.fghsub) testParser.state.fghsub = []; | ||||||
| 				testParser.state.fghsub.push(testParser.scope.inTry ? "try" : "notry"); | 				testParser.state.fghsub.push(testParser.scope.inTry ? "try" : "notry"); | ||||||
| 				return true; | 				return true; | ||||||
| 			}); | 			}); | ||||||
| 			testParser.hooks.expression.tap("ijk.sub", "ParserTest", expr => { | 			testParser.hooks.expression.for("ijk.sub").tap("ParserTest", expr => { | ||||||
| 				if (!testParser.state.ijksub) testParser.state.ijksub = []; | 				if (!testParser.state.ijksub) testParser.state.ijksub = []; | ||||||
| 				testParser.state.ijksub.push("test"); | 				testParser.state.ijksub.push("test"); | ||||||
| 				return true; | 				return true; | ||||||
| 			}); | 			}); | ||||||
| 			testParser.hooks.expression.tap("memberExpr", "ParserTest", expr => { | 			testParser.hooks.expression.for("memberExpr").tap("ParserTest", expr => { | ||||||
| 				if (!testParser.state.expressions) testParser.state.expressions = []; | 				if (!testParser.state.expressions) testParser.state.expressions = []; | ||||||
| 				testParser.state.expressions.push(expr.name); | 				testParser.state.expressions.push(expr.name); | ||||||
| 				return true; | 				return true; | ||||||
| 			}); | 			}); | ||||||
| 			testParser.hooks.new.tap("xyz", "ParserTest", expr => { | 			testParser.hooks.new.for("xyz").tap("ParserTest", expr => { | ||||||
| 				if (!testParser.state.xyz) testParser.state.xyz = []; | 				if (!testParser.state.xyz) testParser.state.xyz = []; | ||||||
| 				testParser.state.xyz.push(testParser.parseString(expr.arguments[0])); | 				testParser.state.xyz.push(testParser.parseString(expr.arguments[0])); | ||||||
| 				return true; | 				return true; | ||||||
|  | @ -345,13 +345,19 @@ describe("Parser", () => { | ||||||
| 	describe("expression evaluation", () => { | 	describe("expression evaluation", () => { | ||||||
| 		function evaluateInParser(source) { | 		function evaluateInParser(source) { | ||||||
| 			const parser = new Parser(); | 			const parser = new Parser(); | ||||||
| 			parser.hooks.call.tap("test", "ParserTest", expr => { | 			parser.hooks.call.for("test").tap("ParserTest", expr => { | ||||||
| 				parser.state.result = parser.evaluateExpression(expr.arguments[0]); | 				parser.state.result = parser.evaluateExpression(expr.arguments[0]); | ||||||
| 			}); | 			}); | ||||||
| 			parser.hooks.evaluateIdentifier.tap("aString", "ParserTest", expr => | 			parser.hooks.evaluateIdentifier | ||||||
| 				new BasicEvaluatedExpression().setString("aString").setRange(expr.range) | 				.for("aString") | ||||||
|  | 				.tap("ParserTest", expr => | ||||||
|  | 					new BasicEvaluatedExpression() | ||||||
|  | 						.setString("aString") | ||||||
|  | 						.setRange(expr.range) | ||||||
| 				); | 				); | ||||||
| 			parser.hooks.evaluateIdentifier.tap("b.Number", "ParserTest", expr => | 			parser.hooks.evaluateIdentifier | ||||||
|  | 				.for("b.Number") | ||||||
|  | 				.tap("ParserTest", expr => | ||||||
| 					new BasicEvaluatedExpression().setNumber(123).setRange(expr.range) | 					new BasicEvaluatedExpression().setNumber(123).setRange(expr.range) | ||||||
| 				); | 				); | ||||||
| 			return parser.parse("test(" + source + ");").result; | 			return parser.parse("test(" + source + ");").result; | ||||||
|  | @ -585,7 +591,7 @@ describe("Parser", () => { | ||||||
| 			}; | 			}; | ||||||
| 
 | 
 | ||||||
| 			const parser = new Parser(); | 			const parser = new Parser(); | ||||||
| 			parser.hooks.call.tap("require", "ParserTest", expr => { | 			parser.hooks.call.for("require").tap("ParserTest", expr => { | ||||||
| 				const param = parser.evaluateExpression(expr.arguments[0]); | 				const param = parser.evaluateExpression(expr.arguments[0]); | ||||||
| 				parser.state.param = param.string; | 				parser.state.param = param.string; | ||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue