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 authored and yyx990803 committed Jul 16, 2020
1 parent 7a60809 commit 469c5c0
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 @@ -171,13 +171,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 @@ -186,13 +188,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 469c5c0

Please sign in to comment.