| 
									
										
										
										
											2017-01-09 02:11:26 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-09 02:11:26 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-24 21:23:24 +08:00
										 |  |  | const path = require("path"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 10:52:49 +08:00
										 |  |  | const BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); | 
					
						
							| 
									
										
										
										
											2017-01-08 11:39:06 +08:00
										 |  |  | const UnsupportedFeatureWarning = require("./UnsupportedFeatureWarning"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const ConstDependency = require("./dependencies/ConstDependency"); | 
					
						
							| 
									
										
										
										
											2017-01-08 10:52:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 02:05:29 +08:00
										 |  |  | exports.getModulePath = (context, pathToModule) => { | 
					
						
							| 
									
										
										
										
											2018-07-23 20:53:50 +08:00
										 |  |  | 	let moduleJsPath = path.relative(context, pathToModule); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 	if (!/^[A-Z]:/i.test(moduleJsPath)) { | 
					
						
							| 
									
										
										
										
											2017-02-24 21:23:24 +08:00
										 |  |  | 		moduleJsPath = "./" + moduleJsPath.replace(/\\/g, "/"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-25 02:05:29 +08:00
										 |  |  | 	return moduleJsPath; | 
					
						
							| 
									
										
										
										
											2017-02-24 21:23:24 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 16:24:29 +08:00
										 |  |  | exports.toConstantDependency = (parser, value) => { | 
					
						
							| 
									
										
										
										
											2017-01-09 18:04:28 +08:00
										 |  |  | 	return function constDependency(expr) { | 
					
						
							| 
									
										
										
										
											2018-07-23 20:53:50 +08:00
										 |  |  | 		const dep = new ConstDependency(value, expr.range, false); | 
					
						
							| 
									
										
										
										
											2017-12-13 18:14:00 +08:00
										 |  |  | 		dep.loc = expr.loc; | 
					
						
							| 
									
										
										
										
											2017-12-16 00:08:49 +08:00
										 |  |  | 		parser.state.current.addDependency(dep); | 
					
						
							| 
									
										
										
										
											2017-12-13 18:14:00 +08:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 16:24:29 +08:00
										 |  |  | exports.toConstantDependencyWithWebpackRequire = (parser, value) => { | 
					
						
							| 
									
										
										
										
											2017-12-13 18:14:00 +08:00
										 |  |  | 	return function constDependencyWithWebpackRequire(expr) { | 
					
						
							| 
									
										
										
										
											2018-07-23 20:53:50 +08:00
										 |  |  | 		const dep = new ConstDependency(value, expr.range, true); | 
					
						
							| 
									
										
										
										
											2017-01-08 10:52:49 +08:00
										 |  |  | 		dep.loc = expr.loc; | 
					
						
							| 
									
										
										
										
											2017-12-16 00:08:49 +08:00
										 |  |  | 		parser.state.current.addDependency(dep); | 
					
						
							| 
									
										
										
										
											2017-01-08 10:52:49 +08:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2017-01-08 11:53:14 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 16:24:29 +08:00
										 |  |  | exports.evaluateToString = value => { | 
					
						
							| 
									
										
										
										
											2017-01-09 18:04:28 +08:00
										 |  |  | 	return function stringExpression(expr) { | 
					
						
							| 
									
										
										
										
											2017-01-08 11:53:14 +08:00
										 |  |  | 		return new BasicEvaluatedExpression().setString(value).setRange(expr.range); | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2017-01-08 10:52:49 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-01-08 11:39:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 16:24:29 +08:00
										 |  |  | exports.evaluateToBoolean = value => { | 
					
						
							| 
									
										
										
										
											2017-01-09 18:04:28 +08:00
										 |  |  | 	return function booleanExpression(expr) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		return new BasicEvaluatedExpression() | 
					
						
							|  |  |  | 			.setBoolean(value) | 
					
						
							|  |  |  | 			.setRange(expr.range); | 
					
						
							| 
									
										
										
										
											2017-01-08 13:57:17 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 16:24:29 +08:00
										 |  |  | exports.evaluateToIdentifier = (identifier, truthy) => { | 
					
						
							| 
									
										
										
										
											2017-06-02 19:24:47 +08:00
										 |  |  | 	return function identifierExpression(expr) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		let evex = new BasicEvaluatedExpression() | 
					
						
							|  |  |  | 			.setIdentifier(identifier) | 
					
						
							|  |  |  | 			.setRange(expr.range); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 		if (truthy === true) { | 
					
						
							|  |  |  | 			evex = evex.setTruthy(); | 
					
						
							|  |  |  | 		} else if (truthy === false) { | 
					
						
							|  |  |  | 			evex = evex.setFalsy(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-06-02 19:24:47 +08:00
										 |  |  | 		return evex; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 16:24:29 +08:00
										 |  |  | exports.expressionIsUnsupported = (parser, message) => { | 
					
						
							| 
									
										
										
										
											2017-01-08 11:39:06 +08:00
										 |  |  | 	return function unsupportedExpression(expr) { | 
					
						
							| 
									
										
										
										
											2018-07-23 20:53:50 +08:00
										 |  |  | 		const dep = new ConstDependency("(void 0)", expr.range, false); | 
					
						
							| 
									
										
										
										
											2017-01-08 11:39:06 +08:00
										 |  |  | 		dep.loc = expr.loc; | 
					
						
							| 
									
										
										
										
											2017-12-16 00:08:49 +08:00
										 |  |  | 		parser.state.current.addDependency(dep); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!parser.state.module) return; | 
					
						
							|  |  |  | 		parser.state.module.warnings.push( | 
					
						
							| 
									
										
										
										
											2018-06-04 16:10:23 +08:00
										 |  |  | 			new UnsupportedFeatureWarning(parser.state.module, message, expr.loc) | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-01-08 11:39:06 +08:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-01-09 17:34:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 16:24:29 +08:00
										 |  |  | exports.skipTraversal = () => true; | 
					
						
							| 
									
										
										
										
											2017-01-11 20:11:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 16:24:29 +08:00
										 |  |  | exports.approve = () => true; |