@typescript-eslint/typescript-estree 8.72.1-alpha.1 → 8.72.1-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,5 +7,6 @@ export declare function useProvidedPrograms(programInstances: Iterable<ts.Progra
7
7
  *
8
8
  * @param configFile the path to the tsconfig.json file, relative to `projectDirectory`
9
9
  * @param projectDirectory the project directory to use as the CWD, defaults to `process.cwd()`
10
+ * @param jsDocParsingMode how much JSDoc to parse, defaults to TypeScript's default of parsing all JSDoc
10
11
  */
11
- export declare function createProgramFromConfigFile(configFile: string, projectDirectory?: string): ts.Program;
12
+ export declare function createProgramFromConfigFile(configFile: string, projectDirectory?: string, jsDocParsingMode?: ts.JSDocParsingMode): ts.Program;
@@ -73,10 +73,12 @@ function useProvidedPrograms(programInstances, parseSettings) {
73
73
  *
74
74
  * @param configFile the path to the tsconfig.json file, relative to `projectDirectory`
75
75
  * @param projectDirectory the project directory to use as the CWD, defaults to `process.cwd()`
76
+ * @param jsDocParsingMode how much JSDoc to parse, defaults to TypeScript's default of parsing all JSDoc
76
77
  */
77
- function createProgramFromConfigFile(configFile, projectDirectory) {
78
+ function createProgramFromConfigFile(configFile, projectDirectory, jsDocParsingMode) {
78
79
  const parsed = (0, tsconfig_utils_1.getParsedConfigFile)(ts, configFile, projectDirectory);
79
80
  const host = ts.createCompilerHost(parsed.options, true);
81
+ host.jsDocParsingMode = jsDocParsingMode;
80
82
  return ts.createProgram(parsed.fileNames, parsed.options, host);
81
83
  }
82
84
  //# sourceMappingURL=useProvidedPrograms.js.map
@@ -9,4 +9,4 @@ import type { ParseSettings } from './index';
9
9
  * cache file checks for rapid subsequent calls to fs.existsSync. See discussion
10
10
  * in https://github.com/typescript-eslint/typescript-eslint/issues/101.
11
11
  */
12
- export declare function getProjectConfigFiles(parseSettings: Pick<ParseSettings, 'filePath' | 'tsconfigMatchCache' | 'tsconfigRootDir'>, project: TSESTreeOptions['project']): string[] | null;
12
+ export declare function getProjectConfigFiles(parseSettings: Pick<ParseSettings, 'filePath' | 'tsconfigMatchCache' | 'tsconfigRootDir'>, project: TSESTreeOptions['project'], configFileNames?: readonly string[]): string[] | null;
@@ -50,7 +50,7 @@ const log = (0, debug_1.default)('typescript-eslint:typescript-estree:parseSetti
50
50
  * cache file checks for rapid subsequent calls to fs.existsSync. See discussion
51
51
  * in https://github.com/typescript-eslint/typescript-eslint/issues/101.
52
52
  */
53
- function getProjectConfigFiles(parseSettings, project) {
53
+ function getProjectConfigFiles(parseSettings, project, configFileNames = ['tsconfig.json']) {
54
54
  if (project !== true) {
55
55
  if (project == null || project === false) {
56
56
  return null;
@@ -65,9 +65,10 @@ function getProjectConfigFiles(parseSettings, project) {
65
65
  const checkedDirectories = [directory];
66
66
  do {
67
67
  log('Checking tsconfig.json path: %s', directory);
68
- const tsconfigPath = path.join(directory, 'tsconfig.json');
69
68
  const cached = parseSettings.tsconfigMatchCache.get(directory) ??
70
- (fs.existsSync(tsconfigPath) && tsconfigPath);
69
+ configFileNames
70
+ .map(configFileName => path.join(directory, configFileName))
71
+ .find(configFilePath => fs.existsSync(configFilePath));
71
72
  if (cached) {
72
73
  for (const directory of checkedDirectories) {
73
74
  parseSettings.tsconfigMatchCache.set(directory, cached);
package/dist/parser.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type * as ts from 'typescript';
1
+ import * as ts from 'typescript';
2
2
  import type { ParserServices, TSESTreeOptions } from './parser-options';
3
3
  import type { TSESTree } from './ts-estree';
4
4
  export declare function clearProgramCache(): void;
package/dist/parser.js CHANGED
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
@@ -9,15 +42,18 @@ exports.parse = parse;
9
42
  exports.clearParseAndGenerateServicesCalls = clearParseAndGenerateServicesCalls;
10
43
  exports.parseAndGenerateServices = parseAndGenerateServices;
11
44
  const debug_1 = __importDefault(require("debug"));
45
+ const ts = __importStar(require("typescript"));
12
46
  const ast_converter_1 = require("./ast-converter");
13
47
  const convert_1 = require("./convert");
14
48
  const createIsolatedProgram_1 = require("./create-program/createIsolatedProgram");
15
49
  const createProjectProgram_1 = require("./create-program/createProjectProgram");
16
50
  const createSourceFile_1 = require("./create-program/createSourceFile");
17
51
  const getWatchProgramsForProjects_1 = require("./create-program/getWatchProgramsForProjects");
52
+ const shared_1 = require("./create-program/shared");
18
53
  const useProvidedPrograms_1 = require("./create-program/useProvidedPrograms");
19
54
  const createParserServices_1 = require("./createParserServices");
20
55
  const createParseSettings_1 = require("./parseSettings/createParseSettings");
56
+ const getProjectConfigFiles_1 = require("./parseSettings/getProjectConfigFiles");
21
57
  const semantic_or_syntactic_errors_1 = require("./semantic-or-syntactic-errors");
22
58
  const useProgramFromProjectService_1 = require("./useProgramFromProjectService");
23
59
  const log = (0, debug_1.default)('typescript-eslint:typescript-estree:parser');
@@ -27,8 +63,71 @@ const log = (0, debug_1.default)('typescript-eslint:typescript-estree:parser');
27
63
  * clearProgramCache() is only intended to be used in testing to ensure the parser is clean between tests.
28
64
  */
29
65
  const existingPrograms = new Map();
66
+ /**
67
+ * Tsconfigs with project references, which single runs leave to the project service.
68
+ */
69
+ const configFilesWithReferences = new Set();
70
+ /**
71
+ * Directories' config files as the project service finds them, which unlike
72
+ * `parserOptions.project: true` includes jsconfig.json files.
73
+ */
74
+ const projectServiceConfigFileMatches = new Map();
30
75
  function clearProgramCache() {
31
76
  existingPrograms.clear();
77
+ configFilesWithReferences.clear();
78
+ projectServiceConfigFileMatches.clear();
79
+ }
80
+ /**
81
+ * Files don't change on disk during a single run, so the project service's
82
+ * bookkeeping for each opened file isn't needed. Instead, each file can come
83
+ * from a Program created once for its tsconfig, the same as with
84
+ * `parserOptions.project`. Anything less straightforward is left to the
85
+ * project service: default project files, extra file extensions, project
86
+ * references, and files not found in their tsconfig's Program.
87
+ */
88
+ function useSingleRunProgramForProjectService(parseSettings) {
89
+ if (parseSettings.extraFileExtensions.length ||
90
+ parseSettings.projectService?.allowDefaultProject?.length) {
91
+ return undefined;
92
+ }
93
+ let configFile;
94
+ try {
95
+ [configFile] =
96
+ (0, getProjectConfigFiles_1.getProjectConfigFiles)({
97
+ ...parseSettings,
98
+ tsconfigMatchCache: projectServiceConfigFileMatches,
99
+ }, true, ['tsconfig.json', 'jsconfig.json']) ?? [];
100
+ }
101
+ catch {
102
+ return undefined;
103
+ }
104
+ if (!configFile) {
105
+ return undefined;
106
+ }
107
+ const canonicalConfigFile = (0, shared_1.getCanonicalFileName)(configFile);
108
+ if (configFilesWithReferences.has(canonicalConfigFile)) {
109
+ return undefined;
110
+ }
111
+ let program = existingPrograms.get(canonicalConfigFile);
112
+ if (!program) {
113
+ // The project service loads referenced projects from their source files,
114
+ // while a Program would use their built declaration files.
115
+ // References aren't inherited through extends, so the raw file is enough.
116
+ const rawConfig = ts.readConfigFile(configFile, ts.sys.readFile).config;
117
+ if (rawConfig?.references?.length) {
118
+ configFilesWithReferences.add(canonicalConfigFile);
119
+ return undefined;
120
+ }
121
+ log('Creating single-run Program for project service: %s', configFile);
122
+ program = (0, useProvidedPrograms_1.createProgramFromConfigFile)(configFile, undefined, parseSettings.jsDocParsingMode);
123
+ existingPrograms.set(canonicalConfigFile, program);
124
+ }
125
+ const astAndProgram = (0, shared_1.getAstFromProgram)(program, parseSettings.filePath);
126
+ if (astAndProgram?.ast.text !== parseSettings.codeFullText) {
127
+ return undefined;
128
+ }
129
+ astAndProgram.program.getTypeChecker(); // ensure parent pointers are set in source files
130
+ return astAndProgram;
32
131
  }
33
132
  const defaultProjectMatchedFiles = new Set();
34
133
  function clearDefaultProjectMatchedFiles() {
@@ -41,6 +140,12 @@ function clearDefaultProjectMatchedFiles() {
41
140
  */
42
141
  function getProgramAndAST(parseSettings, hasFullTypeInformation) {
43
142
  if (parseSettings.projectService) {
143
+ if (parseSettings.singleRun && hasFullTypeInformation) {
144
+ const fromSingleRunProgram = useSingleRunProgramForProjectService(parseSettings);
145
+ if (fromSingleRunProgram) {
146
+ return fromSingleRunProgram;
147
+ }
148
+ }
44
149
  const fromProjectService = (0, useProgramFromProjectService_1.useProgramFromProjectService)(parseSettings.projectService, parseSettings, hasFullTypeInformation, defaultProjectMatchedFiles);
45
150
  if (fromProjectService) {
46
151
  return fromProjectService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/typescript-estree",
3
- "version": "8.72.1-alpha.1",
3
+ "version": "8.72.1-alpha.10",
4
4
  "description": "A parser that converts TypeScript source code into an ESTree compatible form",
5
5
  "files": [
6
6
  "dist",
@@ -43,10 +43,10 @@
43
43
  "syntax"
44
44
  ],
45
45
  "dependencies": {
46
- "@typescript-eslint/project-service": "8.72.1-alpha.1",
47
- "@typescript-eslint/tsconfig-utils": "8.72.1-alpha.1",
48
- "@typescript-eslint/types": "8.72.1-alpha.1",
49
- "@typescript-eslint/visitor-keys": "8.72.1-alpha.1",
46
+ "@typescript-eslint/project-service": "8.72.1-alpha.10",
47
+ "@typescript-eslint/tsconfig-utils": "8.72.1-alpha.10",
48
+ "@typescript-eslint/types": "8.72.1-alpha.10",
49
+ "@typescript-eslint/visitor-keys": "8.72.1-alpha.10",
50
50
  "debug": "^4.4.3",
51
51
  "minimatch": "^10.2.2",
52
52
  "semver": "^7.7.3",