Skip to content

Commit

Permalink
feat: improve ast parser
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterAlfredLee committed Jul 5, 2021
1 parent beec2af commit 17850c2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ast-parse/astParse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ export type ParsingResultOccurrence = {
type: ParserType
}

export type ParsingResult = {
[name: string]: ParsingResultOccurrence[]
}

export function astParseRoot (rootDir: string) {
const resolvedPaths : string[] = globby.sync(rootDir)
const parsingResults: any = {}
const parsingResults: ParsingResult = {}
resolvedPaths.forEach(filePath => {
// skip files in node_modules
if (filePath.indexOf('/node_modules/') >= 0) {
Expand Down Expand Up @@ -84,15 +88,15 @@ export function astParseRoot (rootDir: string) {
}

// parse the file
const parsingResult = parser.astParse(fileInfo)
const parsingResult: ParsingResultOccurrence[] | null = parser.astParse(fileInfo)
if (!parsingResult) {
continue
}

if (!parsingResults[parser.parserType]) {
parsingResults[parser.parserType] = []
}
parsingResults[parser.parserType].push(parsingResult)
parsingResults[parser.parserType].push.apply(parsingResults[parser.parserType], parsingResult)
}
})

Expand Down

0 comments on commit 17850c2

Please sign in to comment.