Skip to content

Commit 867476e

Browse files
authored
Reject internal tag on private decls, strip comments from private decls in dtsBundler (#58869)
1 parent 4935e14 commit 867476e

File tree

7 files changed

+55
-125
lines changed

7 files changed

+55
-125
lines changed

scripts/dtsBundler.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ console.log(`Bundling ${entrypoint} to ${output} and ${internalOutput}`);
3939
const newLineKind = ts.NewLineKind.LineFeed;
4040
const newLine = newLineKind === ts.NewLineKind.LineFeed ? "\n" : "\r\n";
4141

42+
/**
43+
* @param {ts.Node} node
44+
*/
45+
function removeAllComments(node) {
46+
/** @type {any} */ (ts).removeAllComments(node);
47+
}
48+
4249
/**
4350
* @param {ts.VariableDeclaration} node
4451
* @returns {ts.VariableStatement}
@@ -422,6 +429,15 @@ function emitAsNamespace(name, parent, moduleSymbol, needExportModifier) {
422429
if (ts.isInternalDeclaration(node)) {
423430
return undefined;
424431
}
432+
// TODO: remove after https://github.com/microsoft/TypeScript/pull/58187 is released
433+
if (ts.canHaveModifiers(node)) {
434+
for (const modifier of ts.getModifiers(node) ?? []) {
435+
if (modifier.kind === ts.SyntaxKind.PrivateKeyword) {
436+
removeAllComments(node);
437+
break;
438+
}
439+
}
440+
}
425441
return node;
426442
}, /*context*/ undefined);
427443

scripts/eslint/rules/jsdoc-format.cjs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = createRule({
1212
multipleJSDocError: `Declaration has multiple JSDoc comments.`,
1313
internalCommentOnParameterProperty: `@internal cannot appear on a JSDoc comment; use a declared property and an assignment in the constructor instead.`,
1414
internalCommentOnUnexported: `@internal should not appear on an unexported declaration.`,
15+
internalCommentOnPrivate: `@internal should not appear on a private declaration.`,
1516
},
1617
schema: [],
1718
type: "problem",
@@ -56,16 +57,9 @@ module.exports = createRule({
5657

5758
/** @type {(c: import("@typescript-eslint/utils").TSESTree.Comment, indexInComment: number) => import("@typescript-eslint/utils").TSESTree.SourceLocation} */
5859
const getAtInternalLoc = (c, indexInComment) => {
59-
const line = c.loc.start.line;
6060
return {
61-
start: {
62-
line,
63-
column: c.loc.start.column + indexInComment,
64-
},
65-
end: {
66-
line,
67-
column: c.loc.start.column + indexInComment + atInternal.length,
68-
},
61+
start: context.sourceCode.getLocFromIndex(c.range[0] + indexInComment),
62+
end: context.sourceCode.getLocFromIndex(c.range[0] + indexInComment + atInternal.length),
6963
};
7064
};
7165

@@ -113,6 +107,10 @@ module.exports = createRule({
113107
else if (!isExported(node)) {
114108
context.report({ messageId: "internalCommentOnUnexported", node: c, loc: getAtInternalLoc(c, indexInComment) });
115109
}
110+
// eslint-disable-next-line local/no-in-operator
111+
else if ("accessibility" in node && node.accessibility === "private") {
112+
context.report({ messageId: "internalCommentOnPrivate", node: c, loc: getAtInternalLoc(c, indexInComment) });
113+
}
116114
else if (i !== last) {
117115
context.report({ messageId: "internalCommentNotLastError", node: c, loc: getAtInternalLoc(c, indexInComment) });
118116
}

src/server/editorServices.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,16 +1302,12 @@ export class ProjectService {
13021302
/** @internal */
13031303
readonly watchFactory: WatchFactory<WatchType, Project | NormalizedPath>;
13041304

1305-
/** @internal */
13061305
private readonly sharedExtendedConfigFileWatchers = new Map<Path, SharedExtendedConfigFileWatcher<NormalizedPath>>();
1307-
/** @internal */
13081306
private readonly extendedConfigCache = new Map<string, ExtendedConfigCacheEntry>();
13091307

13101308
/** @internal */
13111309
readonly packageJsonCache: PackageJsonCache;
1312-
/** @internal */
13131310
private packageJsonFilesMap: Map<Path, PackageJsonWatcher> | undefined;
1314-
/** @internal */
13151311
private incompleteCompletionsCache: IncompleteCompletionsCache | undefined;
13161312
/** @internal */
13171313
readonly session: Session<unknown> | undefined;
@@ -1841,8 +1837,6 @@ export class ProjectService {
18411837

18421838
/**
18431839
* This is to watch whenever files are added or removed to the wildcard directories
1844-
*
1845-
* @internal
18461840
*/
18471841
private watchWildcardDirectory(directory: string, flags: WatchDirectoryFlags, configFileName: NormalizedPath, config: ParsedConfig) {
18481842
let watcher: FileWatcher | undefined = this.watchFactory.watchDirectory(
@@ -1941,7 +1935,6 @@ export class ProjectService {
19411935
return result;
19421936
}
19431937

1944-
/** @internal */
19451938
private delayUpdateProjectsFromParsedConfigOnConfigFileChange(canonicalConfigFilePath: NormalizedPath, loadReason: string) {
19461939
const configFileExistenceInfo = this.configFileExistenceInfoCache.get(canonicalConfigFilePath);
19471940
if (!configFileExistenceInfo?.config) return false;
@@ -1978,7 +1971,6 @@ export class ProjectService {
19781971
return scheduledAnyProjectUpdate;
19791972
}
19801973

1981-
/** @internal */
19821974
private onConfigFileChanged(configFileName: NormalizedPath, canonicalConfigFilePath: NormalizedPath, eventKind: FileWatcherEventKind) {
19831975
const configFileExistenceInfo = this.configFileExistenceInfoCache.get(canonicalConfigFilePath)!;
19841976
const project = this.getConfiguredProjectByCanonicalConfigFilePath(canonicalConfigFilePath);
@@ -2280,7 +2272,6 @@ export class ProjectService {
22802272
return exists;
22812273
}
22822274

2283-
/** @internal */
22842275
private createConfigFileWatcherForParsedConfig(configFileName: NormalizedPath, canonicalConfigFilePath: NormalizedPath, forProject: ConfiguredProject) {
22852276
const configFileExistenceInfo = this.configFileExistenceInfoCache.get(canonicalConfigFilePath)!;
22862277
// When watching config file for parsed config, remove the noopFileWatcher that can be created for open files impacted by config file and watch for real
@@ -2745,8 +2736,6 @@ export class ProjectService {
27452736

27462737
/**
27472738
* Read the config file of the project, and update the project root file names.
2748-
*
2749-
* @internal
27502739
*/
27512740
private loadConfiguredProject(project: ConfiguredProject, reason: string) {
27522741
tracing?.push(tracing.Phase.Session, "loadConfiguredProject", { configFilePath: project.canonicalConfigFilePath });
@@ -3031,7 +3020,6 @@ export class ProjectService {
30313020
return project.updateGraph();
30323021
}
30333022

3034-
/** @internal */
30353023
private reloadFileNamesOfParsedConfig(configFileName: NormalizedPath, config: ParsedConfig) {
30363024
if (config.updateLevel === undefined) return config.parsedCommandLine!.fileNames;
30373025
Debug.assert(config.updateLevel === ProgramUpdateLevel.RootNamesAndUpdate);
@@ -3085,7 +3073,6 @@ export class ProjectService {
30853073
updateWithTriggerFile(project, project.triggerFileForConfigFileDiag ?? project.getConfigFilePath(), /*isReload*/ true);
30863074
}
30873075

3088-
/** @internal */
30893076
private clearSemanticCache(project: Project) {
30903077
project.originalConfiguredProjects = undefined;
30913078
project.resolutionCache.clear();
@@ -3800,7 +3787,6 @@ export class ProjectService {
38003787
return this.getWatchOptionsFromProjectWatchOptions(project.getWatchOptions(), project.getCurrentDirectory());
38013788
}
38023789

3803-
/** @internal */
38043790
private getWatchOptionsFromProjectWatchOptions(projectOptions: WatchOptions | undefined, basePath: string) {
38053791
const hostWatchOptions = !this.hostConfiguration.beforeSubstitution ? this.hostConfiguration.watchOptions :
38063792
handleWatchOptionsConfigDirTemplateSubstitution(
@@ -5007,7 +4993,6 @@ export class ProjectService {
50074993

50084994
/**
50094995
* Performs the remaining steps of enabling a plugin after its module has been instantiated.
5010-
* @internal
50114996
*/
50124997
private endEnablePlugin(project: Project, { pluginConfigEntry, resolvedModule, errorLogs }: BeginEnablePluginResult) {
50134998
if (resolvedModule) {
@@ -5162,7 +5147,6 @@ export class ProjectService {
51625147
});
51635148
}
51645149

5165-
/** @internal */
51665150
private watchPackageJsonFile(file: string, path: Path, project: Project | WildcardWatcher) {
51675151
Debug.assert(project !== undefined);
51685152
let result = (this.packageJsonFilesMap ??= new Map()).get(path);
@@ -5204,7 +5188,6 @@ export class ProjectService {
52045188
(project.packageJsonWatches ??= new Set()).add(result);
52055189
}
52065190

5207-
/** @internal */
52085191
private onPackageJsonChange(result: PackageJsonWatcher) {
52095192
result.projects.forEach(project => (project as Project).onPackageJsonChange?.());
52105193
}

src/server/project.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
327327

328328
/** @internal */
329329
lastCachedUnresolvedImportsList: SortedReadonlyArray<string> | undefined;
330-
/** @internal */
331330
private hasAddedorRemovedFiles = false;
332-
/** @internal */
333331
private hasAddedOrRemovedSymlinks = false;
334332

335333
/** @internal */
@@ -390,7 +388,6 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
390388
/** @internal */
391389
typingFiles: SortedReadonlyArray<string> = emptyArray;
392390

393-
/** @internal */
394391
private typingWatchers: TypingWatchers | undefined;
395392

396393
/** @internal */
@@ -492,13 +489,9 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
492489
/** @internal */
493490
public readonly getCanonicalFileName: GetCanonicalFileName;
494491

495-
/** @internal */
496492
private exportMapCache: ExportInfoMap | undefined;
497-
/** @internal */
498493
private changedFilesForExportMapCache: Set<Path> | undefined;
499-
/** @internal */
500494
private moduleSpecifierCache = createModuleSpecifierCache(this);
501-
/** @internal */
502495
private symlinks: SymlinkCache | undefined;
503496
/** @internal */
504497
autoImportProviderHost: AutoImportProviderProject | false | undefined;
@@ -1418,13 +1411,11 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
14181411
}
14191412
}
14201413

1421-
/** @internal */
14221414
private closeWatchingTypingLocations() {
14231415
if (this.typingWatchers) clearMap(this.typingWatchers, closeFileWatcher);
14241416
this.typingWatchers = undefined;
14251417
}
14261418

1427-
/** @internal */
14281419
private onTypingInstallerWatchInvoke() {
14291420
this.typingWatchers!.isInvoked = true;
14301421
this.projectService.updateTypingsForProject({ projectName: this.getProjectName(), kind: ActionInvalidate });
@@ -1828,7 +1819,6 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
18281819
return this.filesToStringWorker(writeProjectFileNames, /*writeFileExplaination*/ true, /*writeFileVersionAndText*/ false);
18291820
}
18301821

1831-
/** @internal */
18321822
private filesToStringWorker(writeProjectFileNames: boolean, writeFileExplaination: boolean, writeFileVersionAndText: boolean) {
18331823
if (this.isInitialLoadPending()) return "\tFiles (0) InitialLoadPending\n";
18341824
if (!this.program) return "\tFiles (0) NoProgram\n";
@@ -2203,7 +2193,6 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
22032193
}
22042194
}
22052195

2206-
/** @internal */
22072196
private isDefaultProjectForOpenFiles(): boolean {
22082197
return !!forEachEntry(
22092198
this.projectService.openFiles,
@@ -2250,7 +2239,6 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
22502239
}
22512240
}
22522241

2253-
/** @internal */
22542242
private getCompilerOptionsForNoDtsResolutionProject() {
22552243
return {
22562244
...this.getCompilerOptions(),
@@ -2443,7 +2431,6 @@ export class AuxiliaryProject extends Project {
24432431
}
24442432

24452433
export class AutoImportProviderProject extends Project {
2446-
/** @internal */
24472434
private static readonly maxDependencies = 10;
24482435

24492436
/** @internal */
@@ -2781,7 +2768,6 @@ export class ConfiguredProject extends Project {
27812768
/** @internal */
27822769
sendLoadingProjectFinish = false;
27832770

2784-
/** @internal */
27852771
private compilerHost?: CompilerHost;
27862772

27872773
/** @internal */
@@ -2845,7 +2831,6 @@ export class ConfiguredProject extends Project {
28452831
this.releaseParsedConfig(asNormalizedPath(this.projectService.toCanonicalFileName(asNormalizedPath(normalizePath(fileName)))));
28462832
}
28472833

2848-
/** @internal */
28492834
private releaseParsedConfig(canonicalConfigFilePath: NormalizedPath) {
28502835
this.projectService.stopWatchingWildCards(canonicalConfigFilePath, this);
28512836
this.projectService.releaseParsedConfig(canonicalConfigFilePath, this);

src/server/scriptInfo.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,6 @@ export class ScriptInfo {
382382

383383
/**
384384
* Set to real path if path is different from info.path
385-
*
386-
* @internal
387385
*/
388386
private realpath: Path | undefined;
389387

src/typingsInstallerCore/typingsInstaller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ export abstract class TypingsInstaller {
113113
private readonly knownCachesSet = new Set<string>();
114114
private readonly projectWatchers = new Map<string, Set<string>>();
115115
private safeList: JsTyping.SafeList | undefined;
116-
/** @internal */
117116
private pendingRunRequests: PendingRequest[] = [];
118117

119118
private installRunCount = 1;

0 commit comments

Comments
 (0)