mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Don’t auto-import undefined (#35504)
This commit is contained in:
@@ -854,9 +854,9 @@ namespace FourSlash {
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(actual.hasAction, hasAction);
|
||||
assert.equal(actual.isRecommended, isRecommended);
|
||||
assert.equal(actual.source, source);
|
||||
assert.equal(actual.hasAction, hasAction, `Expected 'hasAction' value '${actual.hasAction}' to equal '${hasAction}'`);
|
||||
assert.equal(actual.isRecommended, isRecommended, `Expected 'isRecommended' value '${actual.source}' to equal '${isRecommended}'`);
|
||||
assert.equal(actual.source, source, `Expected 'source' value '${actual.source}' to equal '${source}'`);
|
||||
assert.equal(actual.sortText, sortText || ts.Completions.SortText.LocationPriority, this.messageAtLastKnownMarker(`Actual entry: ${JSON.stringify(actual)}`));
|
||||
|
||||
if (text !== undefined) {
|
||||
|
||||
@@ -117,12 +117,12 @@ namespace ts.Completions {
|
||||
// If the symbol/moduleSymbol was a merged symbol, it will have a new identity
|
||||
// in the checker, even though the symbols to merge are the same (guaranteed by
|
||||
// cache invalidation in synchronizeHostData).
|
||||
if (suggestion.symbol.declarations) {
|
||||
if (suggestion.symbol.declarations?.length) {
|
||||
suggestion.symbol = checker.getMergedSymbol(suggestion.origin.isDefaultExport
|
||||
? suggestion.symbol.declarations[0].localSymbol || suggestion.symbol.declarations[0].symbol
|
||||
? suggestion.symbol.declarations[0].localSymbol ?? suggestion.symbol.declarations[0].symbol
|
||||
: suggestion.symbol.declarations[0].symbol);
|
||||
}
|
||||
if (suggestion.origin.moduleSymbol.declarations) {
|
||||
if (suggestion.origin.moduleSymbol.declarations?.length) {
|
||||
suggestion.origin.moduleSymbol = checker.getMergedSymbol(suggestion.origin.moduleSymbol.declarations[0].symbol);
|
||||
}
|
||||
});
|
||||
@@ -1624,6 +1624,9 @@ namespace ts.Completions {
|
||||
if (isDefaultExport) {
|
||||
symbol = getLocalSymbolForExportDefault(symbol) || symbol;
|
||||
}
|
||||
if (typeChecker.isUndefinedSymbol(symbol)) {
|
||||
return;
|
||||
}
|
||||
addToSeen(resultSymbolIds, getSymbolId(symbol));
|
||||
const origin: SymbolOriginInfoExport = { kind: SymbolOriginInfoKind.Export, moduleSymbol, isDefaultExport };
|
||||
results.push({
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/// <reference path="../fourslash.ts" />
|
||||
|
||||
// @Filename: /tsconfig.json
|
||||
////{ "compilerOptions": { "module": "esnext" } }
|
||||
|
||||
// @Filename: /undefined.ts
|
||||
////export = undefined;
|
||||
|
||||
// @Filename: /undefinedAlias.ts
|
||||
////const x = undefined;
|
||||
////export = x;
|
||||
|
||||
// @Filename: /index.ts
|
||||
//// /**/
|
||||
|
||||
// Would throw error if undefined appears twice
|
||||
goTo.marker("");
|
||||
verify.completions({
|
||||
includes: [{
|
||||
name: "x",
|
||||
hasAction: true,
|
||||
sortText: completion.SortText.AutoImportSuggestions,
|
||||
source: "/undefinedAlias"
|
||||
}],
|
||||
preferences: {
|
||||
includeCompletionsForModuleExports: true,
|
||||
includeInsertTextCompletions: true
|
||||
}
|
||||
});
|
||||
|
||||
// Do it again for cache test
|
||||
verify.completions({
|
||||
includes: [{
|
||||
name: "x",
|
||||
hasAction: true,
|
||||
sortText: completion.SortText.AutoImportSuggestions,
|
||||
source: "/undefinedAlias"
|
||||
}],
|
||||
preferences: {
|
||||
includeCompletionsForModuleExports: true,
|
||||
includeInsertTextCompletions: true
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user