| 
									
										
										
										
											2018-01-08 22:31:54 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Florent Cailhol @ooflorent | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-08 22:31:54 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ConstDependency = require("./ConstDependency"); | 
					
						
							| 
									
										
										
										
											2019-12-06 17:19:41 +08:00
										 |  |  | const HarmonyExports = require("./HarmonyExports"); | 
					
						
							| 
									
										
										
										
											2018-01-08 22:31:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-17 02:24:34 +08:00
										 |  |  | /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */ | 
					
						
							|  |  |  | /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */ | 
					
						
							|  |  |  | /** @typedef {import("../javascript/JavascriptParser").Range} Range */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-08 22:31:54 +08:00
										 |  |  | class HarmonyTopLevelThisParserPlugin { | 
					
						
							| 
									
										
										
										
											2023-06-17 02:24:34 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {JavascriptParser} parser the parser | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-01-08 22:31:54 +08:00
										 |  |  | 	apply(parser) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		parser.hooks.expression | 
					
						
							|  |  |  | 			.for("this") | 
					
						
							|  |  |  | 			.tap("HarmonyTopLevelThisParserPlugin", node => { | 
					
						
							|  |  |  | 				if (!parser.scope.topLevelScope) return; | 
					
						
							| 
									
										
										
										
											2019-12-07 08:04:38 +08:00
										 |  |  | 				if (HarmonyExports.isEnabled(parser.state)) { | 
					
						
							| 
									
										
										
										
											2023-06-17 02:24:34 +08:00
										 |  |  | 					const dep = new ConstDependency( | 
					
						
							|  |  |  | 						"undefined", | 
					
						
							|  |  |  | 						/** @type {Range} */ (node.range), | 
					
						
							|  |  |  | 						null | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					dep.loc = /** @type {DependencyLocation} */ (node.loc); | 
					
						
							| 
									
										
										
										
											2019-10-30 13:40:40 +08:00
										 |  |  | 					parser.state.module.addPresentationalDependency(dep); | 
					
						
							| 
									
										
										
										
											2023-06-17 02:49:43 +08:00
										 |  |  | 					return true; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-08 22:31:54 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = HarmonyTopLevelThisParserPlugin; |