Skip to content

Commit 7597f52

Browse files
committed
Merge branch 'master' into bug/42785
2 parents a687bae + aa67b16 commit 7597f52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+723
-389
lines changed

package-lock.json

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/binder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@ namespace ts {
32663266
if (node.name) {
32673267
setParent(node.name, node);
32683268
}
3269-
file.bindDiagnostics.push(createDiagnosticForNode(symbolExport.declarations[0], Diagnostics.Duplicate_identifier_0, symbolName(prototypeSymbol)));
3269+
file.bindDiagnostics.push(createDiagnosticForNode(symbolExport.declarations![0], Diagnostics.Duplicate_identifier_0, symbolName(prototypeSymbol)));
32703270
}
32713271
symbol.exports!.set(prototypeSymbol.escapedName, prototypeSymbol);
32723272
prototypeSymbol.parent = symbol;

src/compiler/builderState.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,17 @@ namespace ts {
166166

167167
// From ambient modules
168168
for (const ambientModule of program.getTypeChecker().getAmbientModules()) {
169-
if (ambientModule.declarations.length > 1) {
169+
if (ambientModule.declarations && ambientModule.declarations.length > 1) {
170170
addReferenceFromAmbientModule(ambientModule);
171171
}
172172
}
173173

174174
return referencedFiles;
175175

176176
function addReferenceFromAmbientModule(symbol: Symbol) {
177+
if (!symbol.declarations) {
178+
return;
179+
}
177180
// Add any file other than our own as reference
178181
for (const declaration of symbol.declarations) {
179182
const declarationSourceFile = getSourceFileOfNode(declaration);

src/compiler/checker.ts

+294-250
Large diffs are not rendered by default.

src/compiler/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ namespace ts {
292292
return -1;
293293
}
294294

295-
export function countWhere<T>(array: readonly T[], predicate: (x: T, i: number) => boolean): number {
295+
export function countWhere<T>(array: readonly T[] | undefined, predicate: (x: T, i: number) => boolean): number {
296296
let count = 0;
297297
if (array) {
298298
for (let i = 0; i < array.length; i++) {

src/compiler/moduleSpecifiers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ namespace ts.moduleSpecifiers {
385385
}
386386

387387
function tryGetModuleNameFromAmbientModule(moduleSymbol: Symbol, checker: TypeChecker): string | undefined {
388-
const decl = find(moduleSymbol.declarations,
388+
const decl = moduleSymbol.declarations?.find(
389389
d => isNonGlobalAmbientModule(d) && (!isExternalModuleAugmentation(d) || !isExternalModuleNameRelative(getTextOfIdentifierOrLiteral(d.name)))
390390
) as (ModuleDeclaration & { name: StringLiteral }) | undefined;
391391
if (decl) {

src/compiler/transformers/declarations.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,15 @@ namespace ts {
206206
}
207207

208208
function reportNonlocalAugmentation(containingFile: SourceFile, parentSymbol: Symbol, symbol: Symbol) {
209-
const primaryDeclaration = find(parentSymbol.declarations, d => getSourceFileOfNode(d) === containingFile)!;
209+
const primaryDeclaration = parentSymbol.declarations?.find(d => getSourceFileOfNode(d) === containingFile)!;
210210
const augmentingDeclarations = filter(symbol.declarations, d => getSourceFileOfNode(d) !== containingFile);
211-
for (const augmentations of augmentingDeclarations) {
212-
context.addDiagnostic(addRelatedInfo(
213-
createDiagnosticForNode(augmentations, Diagnostics.Declaration_augments_declaration_in_another_file_This_cannot_be_serialized),
214-
createDiagnosticForNode(primaryDeclaration, Diagnostics.This_is_the_declaration_being_augmented_Consider_moving_the_augmenting_declaration_into_the_same_file)
215-
));
211+
if (augmentingDeclarations) {
212+
for (const augmentations of augmentingDeclarations) {
213+
context.addDiagnostic(addRelatedInfo(
214+
createDiagnosticForNode(augmentations, Diagnostics.Declaration_augments_declaration_in_another_file_This_cannot_be_serialized),
215+
createDiagnosticForNode(primaryDeclaration, Diagnostics.This_is_the_declaration_being_augmented_Consider_moving_the_augmenting_declaration_into_the_same_file)
216+
));
217+
}
216218
}
217219
}
218220

src/compiler/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4165,6 +4165,7 @@ namespace ts {
41654165
/* @internal */ createSymbol(flags: SymbolFlags, name: __String): TransientSymbol;
41664166
/* @internal */ createIndexInfo(type: Type, isReadonly: boolean, declaration?: SignatureDeclaration): IndexInfo;
41674167
/* @internal */ isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult;
4168+
/* @internal */ tryFindAmbientModule(moduleName: string): Symbol | undefined;
41684169
/* @internal */ tryFindAmbientModuleWithoutAugmentations(moduleName: string): Symbol | undefined;
41694170

41704171
/* @internal */ getSymbolWalker(accept?: (symbol: Symbol) => boolean): SymbolWalker;
@@ -4713,7 +4714,7 @@ namespace ts {
47134714
export interface Symbol {
47144715
flags: SymbolFlags; // Symbol flags
47154716
escapedName: __String; // Name of symbol
4716-
declarations: Declaration[]; // Declarations associated with this symbol
4717+
declarations?: Declaration[]; // Declarations associated with this symbol
47174718
valueDeclaration: Declaration; // First value declaration of the symbol
47184719
members?: SymbolTable; // Class, interface or object literal instance members
47194720
exports?: SymbolTable; // Module exports

src/compiler/utilities.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ namespace ts {
767767
}
768768

769769
export function getNonAugmentationDeclaration(symbol: Symbol) {
770-
return find(symbol.declarations, d => !isExternalModuleAugmentation(d) && !(isModuleDeclaration(d) && isGlobalScopeAugmentation(d)));
770+
return symbol.declarations?.find(d => !isExternalModuleAugmentation(d) && !(isModuleDeclaration(d) && isGlobalScopeAugmentation(d)));
771771
}
772772

773773
export function isEffectiveExternalModule(node: SourceFile, compilerOptions: CompilerOptions) {
@@ -4888,15 +4888,15 @@ namespace ts {
48884888
}
48894889

48904890
export function getLocalSymbolForExportDefault(symbol: Symbol) {
4891-
if (!isExportDefaultSymbol(symbol)) return undefined;
4891+
if (!isExportDefaultSymbol(symbol) || !symbol.declarations) return undefined;
48924892
for (const decl of symbol.declarations) {
48934893
if (decl.localSymbol) return decl.localSymbol;
48944894
}
48954895
return undefined;
48964896
}
48974897

48984898
function isExportDefaultSymbol(symbol: Symbol): boolean {
4899-
return symbol && length(symbol.declarations) > 0 && hasSyntacticModifier(symbol.declarations[0], ModifierFlags.Default);
4899+
return symbol && length(symbol.declarations) > 0 && hasSyntacticModifier(symbol.declarations![0], ModifierFlags.Default);
49004900
}
49014901

49024902
/** Return ".ts", ".d.ts", or ".tsx", if that is the extension. */
@@ -5445,7 +5445,7 @@ namespace ts {
54455445
}
54465446

54475447
export function getClassLikeDeclarationOfSymbol(symbol: Symbol): ClassLikeDeclaration | undefined {
5448-
return find(symbol.declarations, isClassLike);
5448+
return symbol.declarations?.find(isClassLike);
54495449
}
54505450

54515451
export function getObjectFlags(type: Type): ObjectFlags {

src/harness/client.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ namespace ts.server {
205205
isNewIdentifierLocation: false,
206206
entries: response.body!.map<CompletionEntry>(entry => { // TODO: GH#18217
207207
if (entry.replacementSpan !== undefined) {
208-
const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, source, isRecommended } = entry;
208+
const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, source, data, isRecommended } = entry;
209209
// TODO: GH#241
210-
const res: CompletionEntry = { name, kind, kindModifiers, sortText, replacementSpan: this.decodeSpan(replacementSpan, fileName), hasAction, source, isRecommended };
210+
const res: CompletionEntry = { name, kind, kindModifiers, sortText, replacementSpan: this.decodeSpan(replacementSpan, fileName), hasAction, source, data: data as any, isRecommended };
211211
return res;
212212
}
213213

@@ -216,14 +216,13 @@ namespace ts.server {
216216
};
217217
}
218218

219-
getCompletionEntryDetails(fileName: string, position: number, entryName: string, _options: FormatCodeOptions | FormatCodeSettings | undefined, source: string | undefined): CompletionEntryDetails {
220-
const args: protocol.CompletionDetailsRequestArgs = { ...this.createFileLocationRequestArgs(fileName, position), entryNames: [{ name: entryName, source }] };
219+
getCompletionEntryDetails(fileName: string, position: number, entryName: string, _options: FormatCodeOptions | FormatCodeSettings | undefined, source: string | undefined, _preferences: UserPreferences | undefined, data: unknown): CompletionEntryDetails {
220+
const args: protocol.CompletionDetailsRequestArgs = { ...this.createFileLocationRequestArgs(fileName, position), entryNames: [{ name: entryName, source, data }] };
221221

222-
const request = this.processRequest<protocol.CompletionDetailsRequest>(CommandNames.CompletionDetails, args);
223-
const response = this.processResponse<protocol.CompletionDetailsResponse>(request);
224-
Debug.assert(response.body!.length === 1, "Unexpected length of completion details response body.");
225-
const convertedCodeActions = map(response.body![0].codeActions, ({ description, changes }) => ({ description, changes: this.convertChanges(changes, fileName) }));
226-
return { ...response.body![0], codeActions: convertedCodeActions };
222+
const request = this.processRequest<protocol.CompletionDetailsRequest>(CommandNames.CompletionDetailsFull, args);
223+
const response = this.processResponse<protocol.Response>(request);
224+
Debug.assert(response.body.length === 1, "Unexpected length of completion details response body.");
225+
return response.body[0];
227226
}
228227

229228
getCompletionEntrySymbol(_fileName: string, _position: number, _entryName: string): Symbol {

src/harness/fourslashImpl.ts

+21-11
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ namespace FourSlash {
399399
}
400400
const memo = Utils.memoize(
401401
(_version: number, _active: string, _caret: number, _selectEnd: number, _marker: string, ...args: any[]) => (ls[key] as Function)(...args),
402-
(...args) => args.join("|,|")
402+
(...args) => args.map(a => a && typeof a === "object" ? JSON.stringify(a) : a).join("|,|")
403403
);
404404
proxy[key] = (...args: any[]) => memo(
405405
target.languageServiceAdapterHost.getScriptInfo(target.activeFile.fileName)!.version,
@@ -867,7 +867,7 @@ namespace FourSlash {
867867
nameToEntries.set(entry.name, [entry]);
868868
}
869869
else {
870-
if (entries.some(e => e.source === entry.source)) {
870+
if (entries.some(e => e.source === entry.source && this.deepEqual(e.data, entry.data))) {
871871
this.raiseError(`Duplicate completions for ${entry.name}`);
872872
}
873873
entries.push(entry);
@@ -885,8 +885,8 @@ namespace FourSlash {
885885
const name = typeof include === "string" ? include : include.name;
886886
const found = nameToEntries.get(name);
887887
if (!found) throw this.raiseError(`Includes: completion '${name}' not found.`);
888-
assert(found.length === 1, `Must use 'exact' for multiple completions with same name: '${name}'`);
889-
this.verifyCompletionEntry(ts.first(found), include);
888+
if (!found.length) throw this.raiseError(`Includes: no completions with name '${name}' remain unmatched.`);
889+
this.verifyCompletionEntry(found.shift()!, include);
890890
}
891891
}
892892
if (options.excludes) {
@@ -933,7 +933,7 @@ namespace FourSlash {
933933
assert.equal(actual.sortText, expected.sortText || ts.Completions.SortText.LocationPriority, this.messageAtLastKnownMarker(`Actual entry: ${JSON.stringify(actual)}`));
934934

935935
if (expected.text !== undefined) {
936-
const actualDetails = ts.Debug.checkDefined(this.getCompletionEntryDetails(actual.name, actual.source), `No completion details available for name '${actual.name}' and source '${actual.source}'`);
936+
const actualDetails = ts.Debug.checkDefined(this.getCompletionEntryDetails(actual.name, actual.source, actual.data), `No completion details available for name '${actual.name}' and source '${actual.source}'`);
937937
assert.equal(ts.displayPartsToString(actualDetails.displayParts), expected.text, "Expected 'text' property to match 'displayParts' string");
938938
assert.equal(ts.displayPartsToString(actualDetails.documentation), expected.documentation || "", "Expected 'documentation' property to match 'documentation' display parts string");
939939
// TODO: GH#23587
@@ -1003,8 +1003,8 @@ namespace FourSlash {
10031003

10041004
private verifySymbol(symbol: ts.Symbol, declarationRanges: Range[]) {
10051005
const { declarations } = symbol;
1006-
if (declarations.length !== declarationRanges.length) {
1007-
this.raiseError(`Expected to get ${declarationRanges.length} declarations, got ${declarations.length}`);
1006+
if (declarations?.length !== declarationRanges.length) {
1007+
this.raiseError(`Expected to get ${declarationRanges.length} declarations, got ${declarations?.length}`);
10081008
}
10091009

10101010
ts.zipWith(declarations, declarationRanges, (decl, range) => {
@@ -1254,6 +1254,16 @@ namespace FourSlash {
12541254

12551255
}
12561256

1257+
private deepEqual(a: unknown, b: unknown) {
1258+
try {
1259+
this.assertObjectsEqual(a, b);
1260+
return true;
1261+
}
1262+
catch {
1263+
return false;
1264+
}
1265+
}
1266+
12571267
public verifyDisplayPartsOfReferencedSymbol(expected: ts.SymbolDisplayPart[]) {
12581268
const referencedSymbols = this.findReferencesAtCaret()!;
12591269

@@ -1281,11 +1291,11 @@ namespace FourSlash {
12811291
return this.languageService.getCompletionsAtPosition(this.activeFile.fileName, this.currentCaretPosition, options);
12821292
}
12831293

1284-
private getCompletionEntryDetails(entryName: string, source?: string, preferences?: ts.UserPreferences): ts.CompletionEntryDetails | undefined {
1294+
private getCompletionEntryDetails(entryName: string, source: string | undefined, data: ts.CompletionEntryData | undefined, preferences?: ts.UserPreferences): ts.CompletionEntryDetails | undefined {
12851295
if (preferences) {
12861296
this.configure(preferences);
12871297
}
1288-
return this.languageService.getCompletionEntryDetails(this.activeFile.fileName, this.currentCaretPosition, entryName, this.formatCodeSettings, source, preferences);
1298+
return this.languageService.getCompletionEntryDetails(this.activeFile.fileName, this.currentCaretPosition, entryName, this.formatCodeSettings, source, preferences, data);
12891299
}
12901300

12911301
private getReferencesAtCaret() {
@@ -2796,14 +2806,14 @@ namespace FourSlash {
27962806
public applyCodeActionFromCompletion(markerName: string, options: FourSlashInterface.VerifyCompletionActionOptions) {
27972807
this.goToMarker(markerName);
27982808

2799-
const details = this.getCompletionEntryDetails(options.name, options.source, options.preferences);
2809+
const details = this.getCompletionEntryDetails(options.name, options.source, options.data, options.preferences);
28002810
if (!details) {
28012811
const completions = this.getCompletionListAtCaret(options.preferences)?.entries;
28022812
const matchingName = completions?.filter(e => e.name === options.name);
28032813
const detailMessage = matchingName?.length
28042814
? `\n Found ${matchingName.length} with name '${options.name}' from source(s) ${matchingName.map(e => `'${e.source}'`).join(", ")}.`
28052815
: ` (In fact, there were no completions with name '${options.name}' at all.)`;
2806-
return this.raiseError(`No completions were found for the given name, source, and preferences.` + detailMessage);
2816+
return this.raiseError(`No completions were found for the given name, source/data, and preferences.` + detailMessage);
28072817
}
28082818
const codeActions = details.codeActions;
28092819
if (codeActions?.length !== 1) {

src/harness/fourslashInterfaceImpl.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,7 @@ namespace FourSlashInterface {
17011701
export interface VerifyCompletionActionOptions extends NewContentOptions {
17021702
name: string;
17031703
source?: string;
1704+
data?: ts.CompletionEntryData;
17041705
description: string;
17051706
preferences?: ts.UserPreferences;
17061707
}

0 commit comments

Comments
 (0)