0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

refactor(plugin-analyzer): code refactor (#11307)

* refactor(plugin-analyzer): code refactor

* chore: changeset

* chore: update

* chore: update

* chore: update
This commit is contained in:
Simon He 2024-06-21 21:18:52 +08:00 committed by GitHub
parent 04121f4530
commit 89b46b8e6e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -32,7 +32,7 @@ export function vitePluginAnalyzer(
): VitePlugin {
function hoistedScriptScanner() {
const uniqueHoistedIds = new Map<string, string>();
const pageScripts = new Map<
const pageScriptsMap = new Map<
string,
{
hoistedSet: Set<string>;
@ -54,20 +54,22 @@ export function vitePluginAnalyzer(
if (hoistedScripts.size) {
for (const parentInfo of getParentModuleInfos(from, this, isPropagatedAsset)) {
if (isPropagatedAsset(parentInfo.id)) {
if (!internals.propagatedScriptsMap.has(parentInfo.id)) {
internals.propagatedScriptsMap.set(parentInfo.id, new Set());
}
const propagatedScripts = internals.propagatedScriptsMap.get(parentInfo.id)!;
for (const hid of hoistedScripts) {
if (!internals.propagatedScriptsMap.has(parentInfo.id)) {
internals.propagatedScriptsMap.set(parentInfo.id, new Set());
}
internals.propagatedScriptsMap.get(parentInfo.id)?.add(hid);
propagatedScripts.add(hid);
}
} else if (moduleIsTopLevelPage(parentInfo)) {
if (!pageScriptsMap.has(parentInfo.id)) {
pageScriptsMap.set(parentInfo.id, {
hoistedSet: new Set(),
});
}
const pageScripts = pageScriptsMap.get(parentInfo.id)!;
for (const hid of hoistedScripts) {
if (!pageScripts.has(parentInfo.id)) {
pageScripts.set(parentInfo.id, {
hoistedSet: new Set(),
});
}
pageScripts.get(parentInfo.id)?.hoistedSet.add(hid);
pageScripts.hoistedSet.add(hid);
}
}
}
@ -83,7 +85,7 @@ export function vitePluginAnalyzer(
}
}
for (const [pageId, { hoistedSet }] of pageScripts) {
for (const [pageId, { hoistedSet }] of pageScriptsMap) {
const pageData = getPageDataByViteID(internals, pageId);
if (!pageData) continue;