| 
									
										
										
										
											2025-09-18 20:46:16 +08:00
										 |  |  | it("should load only used exports", async () => { | 
					
						
							|  |  |  | 	await import("../statical-dynamic-import/dir1/a").then(({ default: defaultValue, usedExports }) => { | 
					
						
							|  |  |  | 		expect(defaultValue).toBe(3); | 
					
						
							|  |  |  | 		expect(usedExports).toEqual(["default", "usedExports"]); | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it("should get warning on using 'webpackExports' with statically analyze-able dynamic import", async () => { | 
					
						
							|  |  |  | 	await import(/* webpackExports: ["default"] */"../statical-dynamic-import/dir1/a?2").then(({ a }) => { | 
					
						
							|  |  |  | 		expect(a).toBe(1); | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it("should not tree-shake default export for exportsType=default module", async () => { | 
					
						
							|  |  |  | 	await import("../statical-dynamic-import/dir2/json/object.json").then(({ default: defaultValue }) => { | 
					
						
							|  |  |  | 		expect(defaultValue).toEqual({ a: 1 }); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	await import("../statical-dynamic-import/dir2/json/array.json").then(({ default: defaultValue }) => { | 
					
						
							|  |  |  | 		expect(defaultValue).toEqual(["a"]); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	await import("../statical-dynamic-import/dir2/json/primitive.json").then(({ default: defaultValue }) => { | 
					
						
							|  |  |  | 		expect(defaultValue).toBe("a"); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	await import("../statical-dynamic-import/dir2/a").then(({ default: defaultValue }) => { | 
					
						
							|  |  |  | 		expect(defaultValue).toEqual({ a: 1, b: 2 }); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it("should not tree-shake default export for exportsType=default context module", async () => { | 
					
						
							|  |  |  | 	const dir = "json"; | 
					
						
							|  |  |  | 	await import(`../statical-dynamic-import/dir3/${dir}/object.json`).then(({ default: defaultValue }) => { | 
					
						
							|  |  |  | 		expect(defaultValue).toEqual({ a: 1 }); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	await import(`../statical-dynamic-import/dir3/${dir}/array.json`).then(({ default: defaultValue }) => { | 
					
						
							|  |  |  | 		expect(defaultValue).toEqual(["a"]); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	await import(`../statical-dynamic-import/dir3/${dir}/primitive.json`).then(({ default: defaultValue }) => { | 
					
						
							|  |  |  | 		expect(defaultValue).toBe("a"); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	const file = "a"; | 
					
						
							|  |  |  | 	await import(`../statical-dynamic-import/dir3/${file}`).then(({ default: defaultValue }) => { | 
					
						
							|  |  |  | 		expect(defaultValue).toEqual({ a: 1, b: 2 }); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it("should walk with correct order", async () => { | 
					
						
							|  |  |  | 	var r; | 
					
						
							|  |  |  | 	await import(`./dir1/a${r = require, ".js"}`).then(({ a, usedExports }) => { | 
					
						
							|  |  |  | 		expect(r("./required").value).toBe(42); | 
					
						
							|  |  |  | 		expect(a).toBe(1); | 
					
						
							|  |  |  | 		expect(usedExports).toEqual(["a", "usedExports"]); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | it("should analyze arguments in call member chain", async () => { | 
					
						
							| 
									
										
										
										
											2025-09-24 01:52:59 +08:00
										 |  |  | 	await import("../statical-dynamic-import/dir4/lib?2").then(({ b }) => { | 
					
						
							| 
									
										
										
										
											2025-09-18 20:46:16 +08:00
										 |  |  | 		b.f((async () => { | 
					
						
							| 
									
										
										
										
											2025-09-24 01:52:59 +08:00
										 |  |  | 			await import("../statical-dynamic-import/dir4/a?2").then(({ a, usedExports }) => { | 
					
						
							| 
									
										
										
										
											2025-09-18 20:46:16 +08:00
										 |  |  | 				expect(a).toBe(1); | 
					
						
							|  |  |  | 				expect(usedExports).toEqual(["a", "usedExports"]); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		})()); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2025-09-24 01:52:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | it("should static analyze dynamic import variable destructuring assignment", async () => { | 
					
						
							|  |  |  | 	await import("../statical-dynamic-import/dir1/a?3").then(m => { | 
					
						
							|  |  |  | 		const { default: def, usedExports } = m; | 
					
						
							|  |  |  | 		expect(def).toBe(3); | 
					
						
							|  |  |  | 		expect(usedExports).toEqual(["default", "usedExports"]); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2025-09-30 00:43:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | it("expect support of \"deep\" tree-shaking for destructuring assignment dynamic import", async () => { | 
					
						
							|  |  |  | 	await import("../statical-dynamic-import-destructuring/lib").then(({ a: { aaa, usedExports: usedExportsA }, b: { bbb, usedExports: usedExportsB } }) => { | 
					
						
							|  |  |  | 		expect(aaa).toBe(1); | 
					
						
							|  |  |  | 		expect(bbb).toBe(2); | 
					
						
							|  |  |  | 		expect(usedExportsA).toEqual(["aaa", "usedExports"]); | 
					
						
							|  |  |  | 		expect(usedExportsB).toEqual(["bbb", "usedExports"]); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	await import("../statical-dynamic-import-destructuring/lib?2").then(m => { | 
					
						
							|  |  |  | 		const { a: { aaa, usedExports: usedExportsA }, b: { bbb, usedExports: usedExportsB } } = m; | 
					
						
							|  |  |  | 		expect(aaa).toBe(1); | 
					
						
							|  |  |  | 		expect(bbb).toBe(2); | 
					
						
							|  |  |  | 		expect(usedExportsA).toEqual(["aaa", "usedExports"]); | 
					
						
							|  |  |  | 		expect(usedExportsB).toEqual(["bbb", "usedExports"]); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); |