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:
parent
04121f4530
commit
89b46b8e6e
1 changed files with 14 additions and 12 deletions
|
@ -32,7 +32,7 @@ export function vitePluginAnalyzer(
|
||||||
): VitePlugin {
|
): VitePlugin {
|
||||||
function hoistedScriptScanner() {
|
function hoistedScriptScanner() {
|
||||||
const uniqueHoistedIds = new Map<string, string>();
|
const uniqueHoistedIds = new Map<string, string>();
|
||||||
const pageScripts = new Map<
|
const pageScriptsMap = new Map<
|
||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
hoistedSet: Set<string>;
|
hoistedSet: Set<string>;
|
||||||
|
@ -54,20 +54,22 @@ export function vitePluginAnalyzer(
|
||||||
if (hoistedScripts.size) {
|
if (hoistedScripts.size) {
|
||||||
for (const parentInfo of getParentModuleInfos(from, this, isPropagatedAsset)) {
|
for (const parentInfo of getParentModuleInfos(from, this, isPropagatedAsset)) {
|
||||||
if (isPropagatedAsset(parentInfo.id)) {
|
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) {
|
for (const hid of hoistedScripts) {
|
||||||
if (!internals.propagatedScriptsMap.has(parentInfo.id)) {
|
propagatedScripts.add(hid);
|
||||||
internals.propagatedScriptsMap.set(parentInfo.id, new Set());
|
|
||||||
}
|
|
||||||
internals.propagatedScriptsMap.get(parentInfo.id)?.add(hid);
|
|
||||||
}
|
}
|
||||||
} else if (moduleIsTopLevelPage(parentInfo)) {
|
} 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) {
|
for (const hid of hoistedScripts) {
|
||||||
if (!pageScripts.has(parentInfo.id)) {
|
pageScripts.hoistedSet.add(hid);
|
||||||
pageScripts.set(parentInfo.id, {
|
|
||||||
hoistedSet: new Set(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
pageScripts.get(parentInfo.id)?.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);
|
const pageData = getPageDataByViteID(internals, pageId);
|
||||||
if (!pageData) continue;
|
if (!pageData) continue;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue