Skip to content

Commit

Permalink
fix: allFiles as set
Browse files Browse the repository at this point in the history
  • Loading branch information
darky authored and plantain-00 committed Mar 29, 2019
1 parent ba079ee commit 86e9011
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export async function lint(
const program = ts.createProgram(rootNames, compilerOptions, undefined, oldProgram)
const checker = program.getTypeChecker()

const allFiles = {} as {[file: string]: boolean}
const allFiles = new Set<string>()
const sourceFileInfos: SourceFileInfo[] = []
const typeCheckResult = await readCache(enableCache)
for (const sourceFile of program.getSourceFiles()) {
let file = sourceFile.fileName
if (!file.includes('node_modules') && (!files || files.includes(file))) {
file = path.relative(process.cwd(), file)
allFiles[file] = true
allFiles.add(file)
const hash = await getFileHash(file, enableCache)
const cache = typeCheckResult.cache[file]
sourceFileInfos.push({
Expand Down
16 changes: 8 additions & 8 deletions src/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path'

import { SourceFileInfo } from './interfaces'

export function collectDependencies(sourceFileInfos: SourceFileInfo[], allFiles: {[file: string]: boolean}) {
export function collectDependencies(sourceFileInfos: SourceFileInfo[], allFiles: Set<string>) {
const dependencies: [string, string][] = []
for (const { sourceFile, file } of sourceFileInfos) {
sourceFile.forEachChild(node => {
Expand All @@ -26,34 +26,34 @@ export function collectDependencies(sourceFileInfos: SourceFileInfo[], allFiles:
return dependencies
}

function resolveImport(moduleName: string, allFiles: {[file: string]: boolean}) {
function resolveImport(moduleName: string, allFiles: Set<string>) {
let resolveResult = moduleName + '.ts'
if (allFiles[resolveResult]) {
if (allFiles.has(resolveResult)) {
return resolveResult
}

resolveResult = moduleName + '.tsx'
if (allFiles[resolveResult]) {
if (allFiles.has(resolveResult)) {
return resolveResult
}

resolveResult = moduleName + '.d.ts'
if (allFiles[resolveResult]) {
if (allFiles.has(resolveResult)) {
return resolveResult
}

resolveResult = path.resolve(moduleName, 'index.ts')
if (allFiles[resolveResult]) {
if (allFiles.has(resolveResult)) {
return resolveResult
}

resolveResult = path.resolve(moduleName, 'index.tsx')
if (allFiles[resolveResult]) {
if (allFiles.has(resolveResult)) {
return resolveResult
}

resolveResult = path.resolve(moduleName, 'index.d.ts')
if (allFiles[resolveResult]) {
if (allFiles.has(resolveResult)) {
return resolveResult
}

Expand Down

0 comments on commit 86e9011

Please sign in to comment.