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

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 294 additions & 250 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 6 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 8 additions & 9 deletions
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 {

0 commit comments

Comments
 (0)