diff --git a/lib/tsc.js b/lib/tsc.js index 84ae01f8bd7..daf867a74dd 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -1138,15 +1138,18 @@ var ts; var current = files_2[_i]; var name_3 = ts.combinePaths(path, current); if (!ts.contains(exclude, getCanonicalPath(name_3))) { - var stat = _fs.statSync(name_3); - if (stat.isFile()) { - if (!extension || ts.fileExtensionIs(name_3, extension)) { - result.push(name_3); + try { + var stat = _fs.statSync(name_3); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name_3, extension)) { + result.push(name_3); + } + } + else if (stat.isDirectory()) { + directories.push(name_3); } } - else if (stat.isDirectory()) { - directories.push(name_3); - } + catch (e) { } } } for (var _a = 0, directories_1 = directories; _a < directories_1.length; _a++) { @@ -1924,7 +1927,8 @@ var ts; A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17007, category: ts.DiagnosticCategory.Error, key: "A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Con_17007", message: "A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." }, JSX_element_0_has_no_corresponding_closing_tag: { code: 17008, category: ts.DiagnosticCategory.Error, key: "JSX_element_0_has_no_corresponding_closing_tag_17008", message: "JSX element '{0}' has no corresponding closing tag." }, super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class: { code: 17009, category: ts.DiagnosticCategory.Error, key: "super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class_17009", message: "'super' must be called before accessing 'this' in the constructor of a derived class." }, - Unknown_typing_option_0: { code: 17010, category: ts.DiagnosticCategory.Error, key: "Unknown_typing_option_0_17010", message: "Unknown typing option '{0}'." } + Unknown_typing_option_0: { code: 17010, category: ts.DiagnosticCategory.Error, key: "Unknown_typing_option_0_17010", message: "Unknown typing option '{0}'." }, + Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configuration_to_limit_included_source_folders_The_likely_folder_to_exclude_is_0_To_disable_the_project_size_limit_set_the_disableSizeLimit_compiler_option_to_true: { code: 17012, category: ts.DiagnosticCategory.Error, key: "Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configur_17012", message: "Too many JavaScript files in the project. Consider specifying the 'exclude' setting in project configuration to limit included source folders. The likely folder to exclude is '{0}'. To disable the project size limit, set the 'disableSizeLimit' compiler option to 'true'." } }; })(ts || (ts = {})); var ts; @@ -5455,6 +5459,10 @@ var ts; return ts.forEach(ts.supportedJavascriptExtensions, function (extension) { return ts.fileExtensionIs(fileName, extension); }); } ts.hasJavaScriptFileExtension = hasJavaScriptFileExtension; + function hasTypeScriptFileExtension(fileName) { + return ts.forEach(ts.supportedTypeScriptExtensions, function (extension) { return ts.fileExtensionIs(fileName, extension); }); + } + ts.hasTypeScriptFileExtension = hasTypeScriptFileExtension; function getExpandedCharCodes(input) { var output = []; var length = input.length; @@ -32518,6 +32526,7 @@ var ts; ts.emitTime = 0; ts.ioReadTime = 0; ts.ioWriteTime = 0; + ts.maxProgramSizeForNonTsFiles = 20 * 1024 * 1024; var emptyArray = []; ts.version = "1.8.9"; function findConfigFile(searchPath, fileExists) { @@ -32795,6 +32804,8 @@ var ts; var diagnosticsProducingTypeChecker; var noDiagnosticsTypeChecker; var classifiableNames; + var programSizeLimitExceeded = -1; + var programSizeForNonTsFiles = 0; var skipDefaultLib = options.noLib; var supportedExtensions = ts.getSupportedExtensions(options); var start = new Date().getTime(); @@ -32829,7 +32840,8 @@ var ts; (oldOptions.target !== options.target) || (oldOptions.noLib !== options.noLib) || (oldOptions.jsx !== options.jsx) || - (oldOptions.allowJs !== options.allowJs)) { + (oldOptions.allowJs !== options.allowJs) || + (oldOptions.disableSizeLimit !== options.disableSizeLimit)) { oldProgram = undefined; } } @@ -32865,6 +32877,9 @@ var ts; verifyCompilerOptions(); ts.programTime += new Date().getTime() - start; return program; + function exceedProgramSizeLimit() { + return !options.disableSizeLimit && programSizeForNonTsFiles === programSizeLimitExceeded; + } function getCommonSourceDirectory() { if (typeof commonSourceDirectory === "undefined") { if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) { @@ -33338,7 +33353,7 @@ var ts; } } } - if (diagnostic) { + if (diagnostic && !exceedProgramSizeLimit()) { if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) { fileProcessingDiagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument))); } @@ -33363,6 +33378,10 @@ var ts; } return file_1; } + var isNonTsFile = !ts.hasTypeScriptFileExtension(fileName); + if (isNonTsFile && exceedProgramSizeLimit()) { + return undefined; + } var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); @@ -33371,6 +33390,19 @@ var ts; fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); + if (isNonTsFile && !options.disableSizeLimit && file && file.text) { + programSizeForNonTsFiles += file.text.length; + if (programSizeForNonTsFiles > ts.maxProgramSizeForNonTsFiles) { + var commonSourceDirectory_1 = getCommonSourceDirectory(); + var rootLevelDirectory = path.substring(0, Math.max(commonSourceDirectory_1.length, path.indexOf(ts.directorySeparator, commonSourceDirectory_1.length))); + if (rootLevelDirectory[rootLevelDirectory.length - 1] !== ts.directorySeparator) { + rootLevelDirectory += ts.directorySeparator; + } + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configuration_to_limit_included_source_folders_The_likely_folder_to_exclude_is_0_To_disable_the_project_size_limit_set_the_disableSizeLimit_compiler_option_to_true, rootLevelDirectory)); + programSizeForNonTsFiles = programSizeLimitExceeded; + return undefined; + } + } filesByName.set(path, file); if (file) { file.path = path; @@ -33916,6 +33948,10 @@ var ts; name: "noCustomAsyncPromise", type: "boolean", experimental: true + }, + { + name: "disableSizeLimit", + type: "boolean" } ]; var optionNameMapCache; @@ -34098,7 +34134,7 @@ var ts; exclude = json["exclude"]; } else { - exclude = ["node_modules"]; + exclude = ["node_modules", "bower_components"]; var outDir = json["compilerOptions"] && json["compilerOptions"]["outDir"]; if (outDir) { exclude.push(outDir); diff --git a/lib/tsserver.js b/lib/tsserver.js index 2a865876bc5..12235419388 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -1143,15 +1143,18 @@ var ts; var current = files_2[_i]; var name_3 = ts.combinePaths(path, current); if (!ts.contains(exclude, getCanonicalPath(name_3))) { - var stat = _fs.statSync(name_3); - if (stat.isFile()) { - if (!extension || ts.fileExtensionIs(name_3, extension)) { - result.push(name_3); + try { + var stat = _fs.statSync(name_3); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name_3, extension)) { + result.push(name_3); + } + } + else if (stat.isDirectory()) { + directories.push(name_3); } } - else if (stat.isDirectory()) { - directories.push(name_3); - } + catch (e) { } } } for (var _a = 0, directories_1 = directories; _a < directories_1.length; _a++) { @@ -1929,7 +1932,8 @@ var ts; A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17007, category: ts.DiagnosticCategory.Error, key: "A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Con_17007", message: "A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." }, JSX_element_0_has_no_corresponding_closing_tag: { code: 17008, category: ts.DiagnosticCategory.Error, key: "JSX_element_0_has_no_corresponding_closing_tag_17008", message: "JSX element '{0}' has no corresponding closing tag." }, super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class: { code: 17009, category: ts.DiagnosticCategory.Error, key: "super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class_17009", message: "'super' must be called before accessing 'this' in the constructor of a derived class." }, - Unknown_typing_option_0: { code: 17010, category: ts.DiagnosticCategory.Error, key: "Unknown_typing_option_0_17010", message: "Unknown typing option '{0}'." } + Unknown_typing_option_0: { code: 17010, category: ts.DiagnosticCategory.Error, key: "Unknown_typing_option_0_17010", message: "Unknown typing option '{0}'." }, + Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configuration_to_limit_included_source_folders_The_likely_folder_to_exclude_is_0_To_disable_the_project_size_limit_set_the_disableSizeLimit_compiler_option_to_true: { code: 17012, category: ts.DiagnosticCategory.Error, key: "Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configur_17012", message: "Too many JavaScript files in the project. Consider specifying the 'exclude' setting in project configuration to limit included source folders. The likely folder to exclude is '{0}'. To disable the project size limit, set the 'disableSizeLimit' compiler option to 'true'." } }; })(ts || (ts = {})); var ts; @@ -3708,6 +3712,10 @@ var ts; name: "noCustomAsyncPromise", type: "boolean", experimental: true + }, + { + name: "disableSizeLimit", + type: "boolean" } ]; var optionNameMapCache; @@ -3890,7 +3898,7 @@ var ts; exclude = json["exclude"]; } else { - exclude = ["node_modules"]; + exclude = ["node_modules", "bower_components"]; var outDir = json["compilerOptions"] && json["compilerOptions"]["outDir"]; if (outDir) { exclude.push(outDir); @@ -6076,6 +6084,10 @@ var ts; return ts.forEach(ts.supportedJavascriptExtensions, function (extension) { return ts.fileExtensionIs(fileName, extension); }); } ts.hasJavaScriptFileExtension = hasJavaScriptFileExtension; + function hasTypeScriptFileExtension(fileName) { + return ts.forEach(ts.supportedTypeScriptExtensions, function (extension) { return ts.fileExtensionIs(fileName, extension); }); + } + ts.hasTypeScriptFileExtension = hasTypeScriptFileExtension; function getExpandedCharCodes(input) { var output = []; var length = input.length; @@ -33139,6 +33151,7 @@ var ts; ts.emitTime = 0; ts.ioReadTime = 0; ts.ioWriteTime = 0; + ts.maxProgramSizeForNonTsFiles = 20 * 1024 * 1024; var emptyArray = []; ts.version = "1.8.9"; function findConfigFile(searchPath, fileExists) { @@ -33416,6 +33429,8 @@ var ts; var diagnosticsProducingTypeChecker; var noDiagnosticsTypeChecker; var classifiableNames; + var programSizeLimitExceeded = -1; + var programSizeForNonTsFiles = 0; var skipDefaultLib = options.noLib; var supportedExtensions = ts.getSupportedExtensions(options); var start = new Date().getTime(); @@ -33450,7 +33465,8 @@ var ts; (oldOptions.target !== options.target) || (oldOptions.noLib !== options.noLib) || (oldOptions.jsx !== options.jsx) || - (oldOptions.allowJs !== options.allowJs)) { + (oldOptions.allowJs !== options.allowJs) || + (oldOptions.disableSizeLimit !== options.disableSizeLimit)) { oldProgram = undefined; } } @@ -33486,6 +33502,9 @@ var ts; verifyCompilerOptions(); ts.programTime += new Date().getTime() - start; return program; + function exceedProgramSizeLimit() { + return !options.disableSizeLimit && programSizeForNonTsFiles === programSizeLimitExceeded; + } function getCommonSourceDirectory() { if (typeof commonSourceDirectory === "undefined") { if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) { @@ -33959,7 +33978,7 @@ var ts; } } } - if (diagnostic) { + if (diagnostic && !exceedProgramSizeLimit()) { if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) { fileProcessingDiagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument))); } @@ -33984,6 +34003,10 @@ var ts; } return file_1; } + var isNonTsFile = !ts.hasTypeScriptFileExtension(fileName); + if (isNonTsFile && exceedProgramSizeLimit()) { + return undefined; + } var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { fileProcessingDiagnostics.add(ts.createFileDiagnostic(refFile, refPos, refEnd - refPos, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); @@ -33992,6 +34015,19 @@ var ts; fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); + if (isNonTsFile && !options.disableSizeLimit && file && file.text) { + programSizeForNonTsFiles += file.text.length; + if (programSizeForNonTsFiles > ts.maxProgramSizeForNonTsFiles) { + var commonSourceDirectory_1 = getCommonSourceDirectory(); + var rootLevelDirectory = path.substring(0, Math.max(commonSourceDirectory_1.length, path.indexOf(ts.directorySeparator, commonSourceDirectory_1.length))); + if (rootLevelDirectory[rootLevelDirectory.length - 1] !== ts.directorySeparator) { + rootLevelDirectory += ts.directorySeparator; + } + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configuration_to_limit_included_source_folders_The_likely_folder_to_exclude_is_0_To_disable_the_project_size_limit_set_the_disableSizeLimit_compiler_option_to_true, rootLevelDirectory)); + programSizeForNonTsFiles = programSizeLimitExceeded; + return undefined; + } + } filesByName.set(path, file); if (file) { file.path = path; @@ -41003,7 +41039,8 @@ var ts; oldSettings.module !== newSettings.module || oldSettings.noResolve !== newSettings.noResolve || oldSettings.jsx !== newSettings.jsx || - oldSettings.allowJs !== newSettings.allowJs); + oldSettings.allowJs !== newSettings.allowJs || + oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit); var compilerHost = { getSourceFile: getOrCreateSourceFile, getCancellationToken: function () { return cancellationToken; }, @@ -46752,11 +46789,39 @@ var ts; } else { var project_1 = this.createProject(configFilename, projectOptions); + var programSizeForNonTsFiles = 0; + if (clientFileName) { + if (this.host.fileExists(clientFileName)) { + var currentClientFileInfo = this.openFile(clientFileName, true); + project_1.addRoot(currentClientFileInfo); + if (!ts.hasTypeScriptFileExtension(currentClientFileInfo.fileName) && currentClientFileInfo.content) { + programSizeForNonTsFiles += currentClientFileInfo.content.length; + } + } + else { + return { errorMsg: "specified file " + clientFileName + " not found" }; + } + } for (var _i = 0, _b = projectOptions.files; _i < _b.length; _i++) { var rootFilename = _b[_i]; + if (rootFilename === clientFileName) { + continue; + } if (this.host.fileExists(rootFilename)) { - var info = this.openFile(rootFilename, clientFileName == rootFilename); - project_1.addRoot(info); + if (projectOptions.compilerOptions.disableSizeLimit) { + var info = this.openFile(rootFilename, false); + project_1.addRoot(info); + } + else if (programSizeForNonTsFiles <= ts.maxProgramSizeForNonTsFiles) { + var info = this.openFile(rootFilename, false); + project_1.addRoot(info); + if (!ts.hasTypeScriptFileExtension(rootFilename)) { + programSizeForNonTsFiles += info.content.length; + } + } + else { + break; + } } else { return { errorMsg: "specified file " + rootFilename + " not found" }; @@ -46780,7 +46845,7 @@ var ts; return error; } else { - var oldFileNames_1 = project.compilerService.host.roots.map(function (info) { return info.fileName; }); + var oldFileNames_1 = project.projectOptions ? project.projectOptions.files : project.compilerService.host.roots.map(function (info) { return info.fileName; }); var newFileNames_1 = projectOptions.files; var fileNamesToRemove = oldFileNames_1.filter(function (f) { return newFileNames_1.indexOf(f) < 0; }); var fileNamesToAdd = newFileNames_1.filter(function (f) { return oldFileNames_1.indexOf(f) < 0; }); diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 2cf56d338f0..de2270a13ea 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -1478,6 +1478,7 @@ declare namespace ts { allowSyntheticDefaultImports?: boolean; allowJs?: boolean; noImplicitUseStrict?: boolean; + disableSizeLimit?: boolean; [option: string]: string | number | boolean; } interface TypingOptions { diff --git a/lib/typescript.js b/lib/typescript.js index 17f94f37bd7..a7424a7d6f0 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -2110,15 +2110,20 @@ var ts; var current = files_2[_i]; var name_3 = ts.combinePaths(path, current); if (!ts.contains(exclude, getCanonicalPath(name_3))) { - var stat = _fs.statSync(name_3); - if (stat.isFile()) { - if (!extension || ts.fileExtensionIs(name_3, extension)) { - result.push(name_3); + // fs.statSync would throw an exception if the file is a symlink + // whose linked file doesn't exist. + try { + var stat = _fs.statSync(name_3); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name_3, extension)) { + result.push(name_3); + } + } + else if (stat.isDirectory()) { + directories.push(name_3); } } - else if (stat.isDirectory()) { - directories.push(name_3); - } + catch (e) { } } } for (var _a = 0, directories_1 = directories; _a < directories_1.length; _a++) { @@ -2913,7 +2918,8 @@ var ts; A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17007, category: ts.DiagnosticCategory.Error, key: "A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Con_17007", message: "A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." }, JSX_element_0_has_no_corresponding_closing_tag: { code: 17008, category: ts.DiagnosticCategory.Error, key: "JSX_element_0_has_no_corresponding_closing_tag_17008", message: "JSX element '{0}' has no corresponding closing tag." }, super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class: { code: 17009, category: ts.DiagnosticCategory.Error, key: "super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class_17009", message: "'super' must be called before accessing 'this' in the constructor of a derived class." }, - Unknown_typing_option_0: { code: 17010, category: ts.DiagnosticCategory.Error, key: "Unknown_typing_option_0_17010", message: "Unknown typing option '{0}'." } + Unknown_typing_option_0: { code: 17010, category: ts.DiagnosticCategory.Error, key: "Unknown_typing_option_0_17010", message: "Unknown typing option '{0}'." }, + Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configuration_to_limit_included_source_folders_The_likely_folder_to_exclude_is_0_To_disable_the_project_size_limit_set_the_disableSizeLimit_compiler_option_to_true: { code: 17012, category: ts.DiagnosticCategory.Error, key: "Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configur_17012", message: "Too many JavaScript files in the project. Consider specifying the 'exclude' setting in project configuration to limit included source folders. The likely folder to exclude is '{0}'. To disable the project size limit, set the 'disableSizeLimit' compiler option to 'true'." } }; })(ts || (ts = {})); /// @@ -6854,6 +6860,10 @@ var ts; return ts.forEach(ts.supportedJavascriptExtensions, function (extension) { return ts.fileExtensionIs(fileName, extension); }); } ts.hasJavaScriptFileExtension = hasJavaScriptFileExtension; + function hasTypeScriptFileExtension(fileName) { + return ts.forEach(ts.supportedTypeScriptExtensions, function (extension) { return ts.fileExtensionIs(fileName, extension); }); + } + ts.hasTypeScriptFileExtension = hasTypeScriptFileExtension; /** * Replace each instance of non-ascii characters by one, two, three, or four escape sequences * representing the UTF-8 encoding of the character, and return the expanded char code list. @@ -39330,6 +39340,7 @@ var ts; /* @internal */ ts.emitTime = 0; /* @internal */ ts.ioReadTime = 0; /* @internal */ ts.ioWriteTime = 0; + /* @internal */ ts.maxProgramSizeForNonTsFiles = 20 * 1024 * 1024; /** The version of the TypeScript compiler release */ var emptyArray = []; ts.version = "1.8.9"; @@ -39624,6 +39635,8 @@ var ts; var diagnosticsProducingTypeChecker; var noDiagnosticsTypeChecker; var classifiableNames; + var programSizeLimitExceeded = -1; + var programSizeForNonTsFiles = 0; var skipDefaultLib = options.noLib; var supportedExtensions = ts.getSupportedExtensions(options); var start = new Date().getTime(); @@ -39665,7 +39678,8 @@ var ts; (oldOptions.target !== options.target) || (oldOptions.noLib !== options.noLib) || (oldOptions.jsx !== options.jsx) || - (oldOptions.allowJs !== options.allowJs)) { + (oldOptions.allowJs !== options.allowJs) || + (oldOptions.disableSizeLimit !== options.disableSizeLimit)) { oldProgram = undefined; } } @@ -39706,6 +39720,9 @@ var ts; verifyCompilerOptions(); ts.programTime += new Date().getTime() - start; return program; + function exceedProgramSizeLimit() { + return !options.disableSizeLimit && programSizeForNonTsFiles === programSizeLimitExceeded; + } function getCommonSourceDirectory() { if (typeof commonSourceDirectory === "undefined") { if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) { @@ -40237,7 +40254,7 @@ var ts; } } } - if (diagnostic) { + if (diagnostic && !exceedProgramSizeLimit()) { if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) { fileProcessingDiagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument))); } @@ -40265,6 +40282,10 @@ var ts; } return file_1; } + var isNonTsFile = !ts.hasTypeScriptFileExtension(fileName); + if (isNonTsFile && exceedProgramSizeLimit()) { + return undefined; + } // We haven't looked for this file, do so now and cache result var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { @@ -40274,6 +40295,24 @@ var ts; fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); + if (isNonTsFile && !options.disableSizeLimit && file && file.text) { + programSizeForNonTsFiles += file.text.length; + if (programSizeForNonTsFiles > ts.maxProgramSizeForNonTsFiles) { + // If the program size limit was reached when processing a file, this file is + // likely in the problematic folder than contains too many files. + // Normally the folder is one level down from the commonSourceDirectory, for example, + // if the commonSourceDirectory is "/src/", and the last processed path was "/src/node_modules/a/b.js", + // we should show in the error message "/src/node_modules/". + var commonSourceDirectory_1 = getCommonSourceDirectory(); + var rootLevelDirectory = path.substring(0, Math.max(commonSourceDirectory_1.length, path.indexOf(ts.directorySeparator, commonSourceDirectory_1.length))); + if (rootLevelDirectory[rootLevelDirectory.length - 1] !== ts.directorySeparator) { + rootLevelDirectory += ts.directorySeparator; + } + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configuration_to_limit_included_source_folders_The_likely_folder_to_exclude_is_0_To_disable_the_project_size_limit_set_the_disableSizeLimit_compiler_option_to_true, rootLevelDirectory)); + programSizeForNonTsFiles = programSizeLimitExceeded; + return undefined; + } + } filesByName.set(path, file); if (file) { file.path = path; @@ -40854,6 +40893,10 @@ var ts; name: "noCustomAsyncPromise", type: "boolean", experimental: true + }, + { + name: "disableSizeLimit", + type: "boolean" } ]; var optionNameMapCache; @@ -41064,7 +41107,7 @@ var ts; } else { // by default exclude node_modules, and any specificied output directory - exclude = ["node_modules"]; + exclude = ["node_modules", "bower_components"]; var outDir = json["compilerOptions"] && json["compilerOptions"]["outDir"]; if (outDir) { exclude.push(outDir); @@ -48838,7 +48881,8 @@ var ts; oldSettings.module !== newSettings.module || oldSettings.noResolve !== newSettings.noResolve || oldSettings.jsx !== newSettings.jsx || - oldSettings.allowJs !== newSettings.allowJs); + oldSettings.allowJs !== newSettings.allowJs || + oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit); // Now create a new compiler var compilerHost = { getSourceFile: getOrCreateSourceFile, diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index 6a733073f40..b70bdd45935 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -1478,6 +1478,7 @@ declare namespace ts { allowSyntheticDefaultImports?: boolean; allowJs?: boolean; noImplicitUseStrict?: boolean; + disableSizeLimit?: boolean; [option: string]: string | number | boolean; } interface TypingOptions { diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 17f94f37bd7..a7424a7d6f0 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -2110,15 +2110,20 @@ var ts; var current = files_2[_i]; var name_3 = ts.combinePaths(path, current); if (!ts.contains(exclude, getCanonicalPath(name_3))) { - var stat = _fs.statSync(name_3); - if (stat.isFile()) { - if (!extension || ts.fileExtensionIs(name_3, extension)) { - result.push(name_3); + // fs.statSync would throw an exception if the file is a symlink + // whose linked file doesn't exist. + try { + var stat = _fs.statSync(name_3); + if (stat.isFile()) { + if (!extension || ts.fileExtensionIs(name_3, extension)) { + result.push(name_3); + } + } + else if (stat.isDirectory()) { + directories.push(name_3); } } - else if (stat.isDirectory()) { - directories.push(name_3); - } + catch (e) { } } } for (var _a = 0, directories_1 = directories; _a < directories_1.length; _a++) { @@ -2913,7 +2918,8 @@ var ts; A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses: { code: 17007, category: ts.DiagnosticCategory.Error, key: "A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Con_17007", message: "A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses." }, JSX_element_0_has_no_corresponding_closing_tag: { code: 17008, category: ts.DiagnosticCategory.Error, key: "JSX_element_0_has_no_corresponding_closing_tag_17008", message: "JSX element '{0}' has no corresponding closing tag." }, super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class: { code: 17009, category: ts.DiagnosticCategory.Error, key: "super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class_17009", message: "'super' must be called before accessing 'this' in the constructor of a derived class." }, - Unknown_typing_option_0: { code: 17010, category: ts.DiagnosticCategory.Error, key: "Unknown_typing_option_0_17010", message: "Unknown typing option '{0}'." } + Unknown_typing_option_0: { code: 17010, category: ts.DiagnosticCategory.Error, key: "Unknown_typing_option_0_17010", message: "Unknown typing option '{0}'." }, + Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configuration_to_limit_included_source_folders_The_likely_folder_to_exclude_is_0_To_disable_the_project_size_limit_set_the_disableSizeLimit_compiler_option_to_true: { code: 17012, category: ts.DiagnosticCategory.Error, key: "Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configur_17012", message: "Too many JavaScript files in the project. Consider specifying the 'exclude' setting in project configuration to limit included source folders. The likely folder to exclude is '{0}'. To disable the project size limit, set the 'disableSizeLimit' compiler option to 'true'." } }; })(ts || (ts = {})); /// @@ -6854,6 +6860,10 @@ var ts; return ts.forEach(ts.supportedJavascriptExtensions, function (extension) { return ts.fileExtensionIs(fileName, extension); }); } ts.hasJavaScriptFileExtension = hasJavaScriptFileExtension; + function hasTypeScriptFileExtension(fileName) { + return ts.forEach(ts.supportedTypeScriptExtensions, function (extension) { return ts.fileExtensionIs(fileName, extension); }); + } + ts.hasTypeScriptFileExtension = hasTypeScriptFileExtension; /** * Replace each instance of non-ascii characters by one, two, three, or four escape sequences * representing the UTF-8 encoding of the character, and return the expanded char code list. @@ -39330,6 +39340,7 @@ var ts; /* @internal */ ts.emitTime = 0; /* @internal */ ts.ioReadTime = 0; /* @internal */ ts.ioWriteTime = 0; + /* @internal */ ts.maxProgramSizeForNonTsFiles = 20 * 1024 * 1024; /** The version of the TypeScript compiler release */ var emptyArray = []; ts.version = "1.8.9"; @@ -39624,6 +39635,8 @@ var ts; var diagnosticsProducingTypeChecker; var noDiagnosticsTypeChecker; var classifiableNames; + var programSizeLimitExceeded = -1; + var programSizeForNonTsFiles = 0; var skipDefaultLib = options.noLib; var supportedExtensions = ts.getSupportedExtensions(options); var start = new Date().getTime(); @@ -39665,7 +39678,8 @@ var ts; (oldOptions.target !== options.target) || (oldOptions.noLib !== options.noLib) || (oldOptions.jsx !== options.jsx) || - (oldOptions.allowJs !== options.allowJs)) { + (oldOptions.allowJs !== options.allowJs) || + (oldOptions.disableSizeLimit !== options.disableSizeLimit)) { oldProgram = undefined; } } @@ -39706,6 +39720,9 @@ var ts; verifyCompilerOptions(); ts.programTime += new Date().getTime() - start; return program; + function exceedProgramSizeLimit() { + return !options.disableSizeLimit && programSizeForNonTsFiles === programSizeLimitExceeded; + } function getCommonSourceDirectory() { if (typeof commonSourceDirectory === "undefined") { if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) { @@ -40237,7 +40254,7 @@ var ts; } } } - if (diagnostic) { + if (diagnostic && !exceedProgramSizeLimit()) { if (refFile !== undefined && refEnd !== undefined && refPos !== undefined) { fileProcessingDiagnostics.add(ts.createFileDiagnostic.apply(void 0, [refFile, refPos, refEnd - refPos, diagnostic].concat(diagnosticArgument))); } @@ -40265,6 +40282,10 @@ var ts; } return file_1; } + var isNonTsFile = !ts.hasTypeScriptFileExtension(fileName); + if (isNonTsFile && exceedProgramSizeLimit()) { + return undefined; + } // We haven't looked for this file, do so now and cache result var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { if (refFile !== undefined && refPos !== undefined && refEnd !== undefined) { @@ -40274,6 +40295,24 @@ var ts; fileProcessingDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); + if (isNonTsFile && !options.disableSizeLimit && file && file.text) { + programSizeForNonTsFiles += file.text.length; + if (programSizeForNonTsFiles > ts.maxProgramSizeForNonTsFiles) { + // If the program size limit was reached when processing a file, this file is + // likely in the problematic folder than contains too many files. + // Normally the folder is one level down from the commonSourceDirectory, for example, + // if the commonSourceDirectory is "/src/", and the last processed path was "/src/node_modules/a/b.js", + // we should show in the error message "/src/node_modules/". + var commonSourceDirectory_1 = getCommonSourceDirectory(); + var rootLevelDirectory = path.substring(0, Math.max(commonSourceDirectory_1.length, path.indexOf(ts.directorySeparator, commonSourceDirectory_1.length))); + if (rootLevelDirectory[rootLevelDirectory.length - 1] !== ts.directorySeparator) { + rootLevelDirectory += ts.directorySeparator; + } + programDiagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Too_many_JavaScript_files_in_the_project_Consider_specifying_the_exclude_setting_in_project_configuration_to_limit_included_source_folders_The_likely_folder_to_exclude_is_0_To_disable_the_project_size_limit_set_the_disableSizeLimit_compiler_option_to_true, rootLevelDirectory)); + programSizeForNonTsFiles = programSizeLimitExceeded; + return undefined; + } + } filesByName.set(path, file); if (file) { file.path = path; @@ -40854,6 +40893,10 @@ var ts; name: "noCustomAsyncPromise", type: "boolean", experimental: true + }, + { + name: "disableSizeLimit", + type: "boolean" } ]; var optionNameMapCache; @@ -41064,7 +41107,7 @@ var ts; } else { // by default exclude node_modules, and any specificied output directory - exclude = ["node_modules"]; + exclude = ["node_modules", "bower_components"]; var outDir = json["compilerOptions"] && json["compilerOptions"]["outDir"]; if (outDir) { exclude.push(outDir); @@ -48838,7 +48881,8 @@ var ts; oldSettings.module !== newSettings.module || oldSettings.noResolve !== newSettings.noResolve || oldSettings.jsx !== newSettings.jsx || - oldSettings.allowJs !== newSettings.allowJs); + oldSettings.allowJs !== newSettings.allowJs || + oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit); // Now create a new compiler var compilerHost = { getSourceFile: getOrCreateSourceFile,