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

Add limit for program size #7476

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2824,5 +2824,9 @@
"Unknown typing option '{0}'.": {
"category": "Error",
"code": 17010
},
"Too many files are included in the project. Consider add more folders to the `exclude` list.": {
"category": "Error",
"code": 17012
}
}
19 changes: 18 additions & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,24 @@ namespace ts {
}

if (!tryReuseStructureFromOldProgram()) {
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false));
let programSize = 0;
const maxProgramSize = 33554432; // 32 * 1024 * 1024 byte = 32 Mb
for (const name of rootNames) {
const path = toPath(name, currentDirectory, getCanonicalFileName);
if (programSize <= maxProgramSize) {
processRootFile(name, /*isDefaultLib*/ false);
if (hasJavaScriptFileExtension(path) && filesByName.get(path)) {
programSize += filesByName.get(path).text.length;
}
}
else {
// Add global diagnostics
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Too_many_files_are_included_in_the_project_Consider_add_more_folders_to_the_exclude_list));
// Keep a record of the file name, which can be used to compare project changes later
filesByName.set(path, undefined);
}
}

// Do not process the default library if:
// - The '--noLib' flag is used.
// - A 'no-default-lib' reference comment is encountered in
Expand Down