Skip to content

Commit ef70680

Browse files
committed
performance fix
1 parent 6272113 commit ef70680

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

packages/editor/src/runtime/editor/languages/typescript/typeAcquisition.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,18 @@ const es6ImportOnly = RegExp(/import\s?\(?('|")(.*)('|")\)?;?/, "gm");
5353
* Grab any import/requires from inside the code and make a list of
5454
* its dependencies
5555
*/
56-
const parseFileForModuleReferences = (sourceCode: string) => {
56+
const parseFileForModuleReferences = (
57+
moduleName: string | undefined,
58+
sourceCode: string
59+
) => {
60+
if (moduleName === "react") {
61+
// speed up, hardcode
62+
return ["csstype", "prop-types", "scheduler/tracing"];
63+
}
64+
if (moduleName && isBuiltInModule(moduleName)) {
65+
// speed up
66+
return [];
67+
}
5768
const foundModules = new Set<string>();
5869
var match;
5970

@@ -531,7 +542,11 @@ const getDependenciesForModule = async (
531542
config: ATAConfig
532543
) => {
533544
// Get all the import/requires for the file
534-
const filteredModulesToLookAt = parseFileForModuleReferences(sourceCode);
545+
const filteredModulesToLookAt = parseFileForModuleReferences(
546+
moduleName,
547+
sourceCode
548+
);
549+
535550
const promises = filteredModulesToLookAt.map(async (name) => {
536551
// console.log(sourceCode);
537552
// Support grabbing the hard-coded node modules if needed
@@ -641,10 +656,13 @@ const getDependenciesForModule = async (
641656
}
642657
});
643658

644-
// Also support the <reference> comments
645-
promises.push(
646-
getReferenceDependencies(sourceCode, moduleName!, path!, config)
647-
);
659+
// speedup, exclude built-in
660+
if (!moduleName || !isBuiltInModule(moduleName)) {
661+
// Also support the <reference> comments
662+
promises.push(
663+
getReferenceDependencies(sourceCode, moduleName!, path!, config)
664+
);
665+
}
648666

649667
await Promise.all(promises);
650668
};

0 commit comments

Comments
 (0)