-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56fcf43
commit be72969
Showing
3 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import path from "path/posix"; | ||
import { getProxiedObject } from "./helper.js"; | ||
|
||
const foundInLayout = (layoutClassList, className) => { | ||
for (const key in layoutClassList) { | ||
for (const layoutClassName in layoutClassList[key]) { | ||
if (layoutClassName === className) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
export const hoistClass = (classCache, hoistedClassCache) => { | ||
const layoutFilename = "__layout.svelte"; | ||
|
||
// no need for in loop here for filename? | ||
for (const filename in classCache) { | ||
const { dir, base } = path.parse(filename); | ||
|
||
const currentComponentClassList = classCache[filename]; | ||
|
||
if (base === layoutFilename) { | ||
hoistedClassCache[dir][base] = currentComponentClassList; | ||
continue; | ||
} | ||
|
||
const layoutClassList = hoistedClassCache[dir][layoutFilename]; | ||
|
||
if (!layoutClassList) { | ||
hoistedClassCache[dir][base] = currentComponentClassList; | ||
continue; | ||
} | ||
|
||
const filteredClassList = getProxiedObject(); | ||
|
||
for (const original in currentComponentClassList) { | ||
for (const minified in currentComponentClassList[original]) { | ||
if (!foundInLayout(layoutClassList, minified)) { | ||
filteredClassList[original][minified] = true; | ||
} | ||
} | ||
} | ||
|
||
hoistedClassCache[dir][base] = filteredClassList; | ||
} | ||
}; | ||
|
||
export const hoistDeclaration = ( | ||
filename, | ||
hoistedClassCache, | ||
declarationCache | ||
) => { | ||
const { dir, base } = path.parse(filename); | ||
const hoistedDeclarationCache = getProxiedObject(); | ||
const currentComponentCache = hoistedClassCache[dir][base]; | ||
// This is hell | ||
for (const original in currentComponentCache) { | ||
for (const minified of Object.keys(currentComponentCache[original])) { | ||
for (const mediaQuery in declarationCache) { | ||
for (const decl in declarationCache[mediaQuery]) { | ||
if (minified === declarationCache[mediaQuery][decl]) { | ||
hoistedDeclarationCache[mediaQuery][decl] = minified; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return hoistedDeclarationCache; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters