Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More robust definition cache for ImportDeclaration #2279

Merged
merged 6 commits into from
Sep 5, 2019
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions scripts/babel/proptypes-from-ts-props/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,15 +811,16 @@ const typeDefinitionExtractors = {
return [];
}

if (importedDefinitionsCache.has(resolvedPath)) {
return importedDefinitionsCache.get(resolvedPath);
const cacheKey = `${sourceFilename}_${resolvedPath}`
if (importedDefinitionsCache.has(cacheKey)) {
return importedDefinitionsCache.get(cacheKey);
}

// to support circular dependencies, create & pre-cache the array of imported dependencies
// this array is directly mutated after parsing the subsequent files, supporting
// the circular nature as values settle into the correct locations
const importedDefinitions = [];
importedDefinitionsCache.set(resolvedPath, importedDefinitions);
importedDefinitionsCache.set(cacheKey, importedDefinitions);

// load & parse the imported file
const ast = parse(fs.readFileSync(resolvedPath).toString());
Expand Down