@typescript-eslint/typescript-estree
Advanced tools
Comparing version
@@ -13,6 +13,2 @@ import type { Program } from 'typescript'; | ||
export type ASTAndProgram = ASTAndDefiniteProgram | ASTAndNoProgram; | ||
/** | ||
* Compiler options required to avoid critical functionality issues | ||
*/ | ||
export declare const CORE_COMPILER_OPTIONS: ts.CompilerOptions; | ||
export declare const DEFAULT_EXTRA_FILE_EXTENSIONS: Set<string>; | ||
@@ -19,0 +15,0 @@ export declare function createDefaultCompilerOptionsFromExtra(parseSettings: ParseSettings): ts.CompilerOptions; |
@@ -39,3 +39,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DEFAULT_EXTRA_FILE_EXTENSIONS = exports.CORE_COMPILER_OPTIONS = void 0; | ||
exports.DEFAULT_EXTRA_FILE_EXTENSIONS = void 0; | ||
exports.createDefaultCompilerOptionsFromExtra = createDefaultCompilerOptionsFromExtra; | ||
@@ -47,20 +47,10 @@ exports.getCanonicalFileName = getCanonicalFileName; | ||
exports.createHash = createHash; | ||
const tsconfig_utils_1 = require("@typescript-eslint/tsconfig-utils"); | ||
const node_path_1 = __importDefault(require("node:path")); | ||
const ts = __importStar(require("typescript")); | ||
/** | ||
* Compiler options required to avoid critical functionality issues | ||
*/ | ||
exports.CORE_COMPILER_OPTIONS = { | ||
noEmit: true, // required to avoid parse from causing emit to occur | ||
/** | ||
* Flags required to make no-unused-vars work | ||
*/ | ||
noUnusedLocals: true, | ||
noUnusedParameters: true, | ||
}; | ||
/** | ||
* Default compiler options for program generation | ||
*/ | ||
const DEFAULT_COMPILER_OPTIONS = { | ||
...exports.CORE_COMPILER_OPTIONS, | ||
...tsconfig_utils_1.CORE_COMPILER_OPTIONS, | ||
allowJs: true, | ||
@@ -67,0 +57,0 @@ allowNonTsExtensions: true, |
@@ -41,6 +41,6 @@ "use strict"; | ||
exports.createProgramFromConfigFile = createProgramFromConfigFile; | ||
const tsconfig_utils_1 = require("@typescript-eslint/tsconfig-utils"); | ||
const debug_1 = __importDefault(require("debug")); | ||
const path = __importStar(require("node:path")); | ||
const ts = __importStar(require("typescript")); | ||
const getParsedConfigFile_1 = require("./getParsedConfigFile"); | ||
const shared_1 = require("./shared"); | ||
@@ -79,5 +79,5 @@ const log = (0, debug_1.default)('typescript-eslint:typescript-estree:create-program:useProvidedPrograms'); | ||
function createProgramFromConfigFile(configFile, projectDirectory) { | ||
const parsed = (0, getParsedConfigFile_1.getParsedConfigFile)(ts, configFile, projectDirectory); | ||
const parsed = (0, tsconfig_utils_1.getParsedConfigFile)(ts, configFile, projectDirectory); | ||
const host = ts.createCompilerHost(parsed.options, true); | ||
return ts.createProgram(parsed.fileNames, parsed.options, host); | ||
} |
import type { CacheDurationSeconds, DebugLevel, JSDocParsingMode, ProjectServiceOptions, SourceType } from '@typescript-eslint/types'; | ||
import type * as ts from 'typescript'; | ||
import type { TSESTree, TSESTreeToTSNode, TSNode, TSToken } from './ts-estree'; | ||
export type { ProjectServiceOptions } from '@typescript-eslint/types'; | ||
interface ParseOptions { | ||
@@ -207,2 +206,3 @@ /** | ||
export type ParserServices = ParserServicesWithoutTypeInformation | ParserServicesWithTypeInformation; | ||
export {}; | ||
//# sourceMappingURL=parser-options.d.ts.map |
@@ -42,7 +42,8 @@ "use strict"; | ||
exports.clearTSServerProjectService = clearTSServerProjectService; | ||
const project_service_1 = require("@typescript-eslint/project-service"); | ||
const debug_1 = __importDefault(require("debug")); | ||
const node_path_1 = __importDefault(require("node:path")); | ||
const ts = __importStar(require("typescript")); | ||
const createProjectService_1 = require("../create-program/createProjectService"); | ||
const shared_1 = require("../create-program/shared"); | ||
const validateDefaultProjectForFilesGlob_1 = require("../create-program/validateDefaultProjectForFilesGlob"); | ||
const source_files_1 = require("../source-files"); | ||
@@ -128,3 +129,6 @@ const ExpiringCache_1 = require("./ExpiringCache"); | ||
process.env.TYPESCRIPT_ESLINT_PROJECT_SERVICE === 'true') | ||
? (TSSERVER_PROJECT_SERVICE ??= (0, createProjectService_1.createProjectService)(tsestreeOptions.projectService, jsDocParsingMode, tsconfigRootDir)) | ||
? populateProjectService(tsestreeOptions.projectService, { | ||
jsDocParsingMode, | ||
tsconfigRootDir, | ||
}) | ||
: undefined, | ||
@@ -214,1 +218,10 @@ setExternalModuleIndicator: tsestreeOptions.sourceType === 'module' || | ||
} | ||
function populateProjectService(optionsRaw, settings) { | ||
const options = typeof optionsRaw === 'object' ? optionsRaw : {}; | ||
(0, validateDefaultProjectForFilesGlob_1.validateDefaultProjectForFilesGlob)(options.allowDefaultProject); | ||
TSSERVER_PROJECT_SERVICE ??= (0, project_service_1.createProjectService)({ | ||
options, | ||
...settings, | ||
}); | ||
return TSSERVER_PROJECT_SERVICE; | ||
} |
@@ -0,3 +1,3 @@ | ||
import type { ProjectServiceAndMetadata } from '@typescript-eslint/project-service'; | ||
import type * as ts from 'typescript'; | ||
import type { ProjectServiceSettings } from '../create-program/createProjectService'; | ||
import type { CanonicalPath } from '../create-program/shared'; | ||
@@ -99,3 +99,3 @@ import type { TSESTree } from '../ts-estree'; | ||
*/ | ||
projectService: ProjectServiceSettings | undefined; | ||
projectService: ProjectServiceAndMetadata | undefined; | ||
/** | ||
@@ -102,0 +102,0 @@ * Whether to add the `range` property to AST nodes. |
@@ -1,7 +0,7 @@ | ||
import type { ProjectServiceSettings } from './create-program/createProjectService'; | ||
import type { ProjectServiceAndMetadata as ProjectServiceAndMetadata } from '@typescript-eslint/project-service'; | ||
import type { ASTAndDefiniteProgram, ASTAndNoProgram, ASTAndProgram } from './create-program/shared'; | ||
import type { MutableParseSettings } from './parseSettings'; | ||
export declare function useProgramFromProjectService(settings: ProjectServiceSettings, parseSettings: Readonly<MutableParseSettings>, hasFullTypeInformation: boolean, defaultProjectMatchedFiles: Set<string>): ASTAndProgram | undefined; | ||
export declare function useProgramFromProjectService(settings: ProjectServiceSettings, parseSettings: Readonly<MutableParseSettings>, hasFullTypeInformation: true, defaultProjectMatchedFiles: Set<string>): ASTAndDefiniteProgram | undefined; | ||
export declare function useProgramFromProjectService(settings: ProjectServiceSettings, parseSettings: Readonly<MutableParseSettings>, hasFullTypeInformation: false, defaultProjectMatchedFiles: Set<string>): ASTAndNoProgram | undefined; | ||
export declare function useProgramFromProjectService(serviceAndSettings: ProjectServiceAndMetadata, parseSettings: Readonly<MutableParseSettings>, hasFullTypeInformation: boolean, defaultProjectMatchedFiles: Set<string>): ASTAndProgram | undefined; | ||
export declare function useProgramFromProjectService(serviceAndSettings: ProjectServiceAndMetadata, parseSettings: Readonly<MutableParseSettings>, hasFullTypeInformation: true, defaultProjectMatchedFiles: Set<string>): ASTAndDefiniteProgram | undefined; | ||
export declare function useProgramFromProjectService(serviceAndSettings: ProjectServiceAndMetadata, parseSettings: Readonly<MutableParseSettings>, hasFullTypeInformation: false, defaultProjectMatchedFiles: Set<string>): ASTAndNoProgram | undefined; | ||
//# sourceMappingURL=useProgramFromProjectService.d.ts.map |
@@ -67,3 +67,3 @@ "use strict"; | ||
}; | ||
function openClientFileFromProjectService(defaultProjectMatchedFiles, isDefaultProjectAllowed, filePathAbsolute, parseSettings, serviceSettings) { | ||
function openClientFileFromProjectService(defaultProjectMatchedFiles, isDefaultProjectAllowed, filePathAbsolute, parseSettings, serviceAndSettings) { | ||
const opened = openClientFileAndMaybeReload(); | ||
@@ -100,7 +100,7 @@ log('Result from attempting to open client file: %o', opened); | ||
if (defaultProjectMatchedFiles.size > | ||
serviceSettings.maximumDefaultProjectFileMatchCount) { | ||
serviceAndSettings.maximumDefaultProjectFileMatchCount) { | ||
const filePrintLimit = 20; | ||
const filesToPrint = [...defaultProjectMatchedFiles].slice(0, filePrintLimit); | ||
const truncatedFileCount = defaultProjectMatchedFiles.size - filesToPrint.length; | ||
throw new Error(`Too many files (>${serviceSettings.maximumDefaultProjectFileMatchCount}) have matched the default project.${validateDefaultProjectForFilesGlob_1.DEFAULT_PROJECT_FILES_ERROR_EXPLANATION} | ||
throw new Error(`Too many files (>${serviceAndSettings.maximumDefaultProjectFileMatchCount}) have matched the default project.${validateDefaultProjectForFilesGlob_1.DEFAULT_PROJECT_FILES_ERROR_EXPLANATION} | ||
Matching files: | ||
@@ -115,3 +115,3 @@ ${filesToPrint.map(file => `- ${file}`).join('\n')} | ||
function openClientFile() { | ||
return serviceSettings.service.openClientFile(filePathAbsolute, parseSettings.codeFullText, | ||
return serviceAndSettings.service.openClientFile(filePathAbsolute, parseSettings.codeFullText, | ||
/* scriptKind */ undefined, parseSettings.tsconfigRootDir); | ||
@@ -129,8 +129,8 @@ } | ||
!isDefaultProjectAllowed && | ||
performance.now() - serviceSettings.lastReloadTimestamp > | ||
performance.now() - serviceAndSettings.lastReloadTimestamp > | ||
RELOAD_THROTTLE_MS) { | ||
log('No config file found; reloading project service and retrying.'); | ||
serviceSettings.service.reloadProjects(); | ||
serviceAndSettings.service.reloadProjects(); | ||
opened = openClientFile(); | ||
serviceSettings.lastReloadTimestamp = performance.now(); | ||
serviceAndSettings.lastReloadTimestamp = performance.now(); | ||
} | ||
@@ -153,7 +153,7 @@ return opened; | ||
} | ||
function retrieveASTAndProgramFor(filePathAbsolute, parseSettings, serviceSettings) { | ||
function retrieveASTAndProgramFor(filePathAbsolute, parseSettings, serviceAndSettings) { | ||
log('Retrieving script info and then program for: %s', filePathAbsolute); | ||
const scriptInfo = serviceSettings.service.getScriptInfo(filePathAbsolute); | ||
const scriptInfo = serviceAndSettings.service.getScriptInfo(filePathAbsolute); | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
const program = serviceSettings.service | ||
const program = serviceAndSettings.service | ||
.getDefaultProjectForFile(scriptInfo.fileName, true) | ||
@@ -170,15 +170,15 @@ .getLanguageService(/*ensureSynchronized*/ true) | ||
} | ||
function useProgramFromProjectService(serviceSettings, parseSettings, hasFullTypeInformation, defaultProjectMatchedFiles) { | ||
function useProgramFromProjectService(serviceAndSettings, parseSettings, hasFullTypeInformation, defaultProjectMatchedFiles) { | ||
// NOTE: triggers a full project reload when changes are detected | ||
updateExtraFileExtensions(serviceSettings.service, parseSettings.extraFileExtensions); | ||
updateExtraFileExtensions(serviceAndSettings.service, parseSettings.extraFileExtensions); | ||
// We don't canonicalize the filename because it caused a performance regression. | ||
// See https://github.com/typescript-eslint/typescript-eslint/issues/8519 | ||
const filePathAbsolute = absolutify(parseSettings.filePath, serviceSettings); | ||
const filePathAbsolute = absolutify(parseSettings.filePath, serviceAndSettings); | ||
log('Opening project service file for: %s at absolute path %s', parseSettings.filePath, filePathAbsolute); | ||
const filePathRelative = node_path_1.default.relative(parseSettings.tsconfigRootDir, filePathAbsolute); | ||
const isDefaultProjectAllowed = filePathMatchedBy(filePathRelative, serviceSettings.allowDefaultProject); | ||
const isDefaultProjectAllowed = filePathMatchedBy(filePathRelative, serviceAndSettings.allowDefaultProject); | ||
// Type-aware linting is disabled for this file. | ||
// However, type-aware lint rules might still rely on its contents. | ||
if (!hasFullTypeInformation && !isDefaultProjectAllowed) { | ||
return createNoProgramWithProjectService(filePathAbsolute, parseSettings, serviceSettings.service); | ||
return createNoProgramWithProjectService(filePathAbsolute, parseSettings, serviceAndSettings.service); | ||
} | ||
@@ -191,10 +191,10 @@ // If type info was requested, we attempt to open it in the project service. | ||
const opened = hasFullTypeInformation && | ||
openClientFileFromProjectService(defaultProjectMatchedFiles, isDefaultProjectAllowed, filePathAbsolute, parseSettings, serviceSettings); | ||
openClientFileFromProjectService(defaultProjectMatchedFiles, isDefaultProjectAllowed, filePathAbsolute, parseSettings, serviceAndSettings); | ||
log('Opened project service file: %o', opened); | ||
return retrieveASTAndProgramFor(filePathAbsolute, parseSettings, serviceSettings); | ||
return retrieveASTAndProgramFor(filePathAbsolute, parseSettings, serviceAndSettings); | ||
} | ||
function absolutify(filePath, serviceSettings) { | ||
function absolutify(filePath, serviceAndSettings) { | ||
return node_path_1.default.isAbsolute(filePath) | ||
? filePath | ||
: node_path_1.default.join(serviceSettings.service.host.getCurrentDirectory(), filePath); | ||
: node_path_1.default.join(serviceAndSettings.service.host.getCurrentDirectory(), filePath); | ||
} | ||
@@ -201,0 +201,0 @@ function filePathMatchedBy(filePath, allowDefaultProject) { |
{ | ||
"name": "@typescript-eslint/typescript-estree", | ||
"version": "8.32.2-alpha.11", | ||
"version": "8.32.2-alpha.12", | ||
"description": "A parser that converts TypeScript source code into an ESTree compatible form", | ||
@@ -56,4 +56,6 @@ "files": [ | ||
"dependencies": { | ||
"@typescript-eslint/types": "8.32.2-alpha.11", | ||
"@typescript-eslint/visitor-keys": "8.32.2-alpha.11", | ||
"@typescript-eslint/project-service": "8.32.2-alpha.12", | ||
"@typescript-eslint/tsconfig-utils": "8.32.2-alpha.12", | ||
"@typescript-eslint/types": "8.32.2-alpha.12", | ||
"@typescript-eslint/visitor-keys": "8.32.2-alpha.12", | ||
"debug": "^4.3.4", | ||
@@ -60,0 +62,0 @@ "fast-glob": "^3.3.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
400899
-2.73%11
22.22%123
-4.65%7484
-2.96%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed