Skip to content

Commit

Permalink
refactor: change dependencies type with Set
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Jun 1, 2020
1 parent 65afca8 commit b00e54a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/node/utils/cssUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,15 @@ export function getCssImportBoundaries(
return boundaries
}

export function recordCssImportChain(dependencies: string[], filePath: string) {
export function recordCssImportChain(
dependencies: Set<string>,
filePath: string
) {
const preImportees = cssImporteeMap.get(filePath)
const currentImportees = new Set(dependencies)
// if import code change, should removed unused previous importee
if (preImportees) {
for (const preImportee of preImportees) {
if (!currentImportees.has(preImportee)) {
if (!dependencies.has(preImportee)) {
const importers = cssImporterMap.get(preImportee)
if (importers) {
importers.delete(filePath)
Expand All @@ -174,13 +176,13 @@ export function recordCssImportChain(dependencies: string[], filePath: string) {
}
}

currentImportees.forEach((dependency) => {
dependencies.forEach((dependency) => {
if (cssImporterMap.has(dependency)) {
cssImporterMap.get(dependency)!.add(filePath)
} else {
cssImporterMap.set(dependency, new Set([filePath]))
}
})

cssImporteeMap.set(filePath, currentImportees)
cssImporteeMap.set(filePath, dependencies)
}

0 comments on commit b00e54a

Please sign in to comment.