Don’t auto-import undefined (#35504)

This commit is contained in:
Andrew Branch
2019-12-05 14:47:51 -08:00
committed by GitHub
parent 27616dd523
commit f050750cc6
3 changed files with 52 additions and 6 deletions
+3 -3
View File
@@ -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) {
+6 -3
View File
@@ -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
}
});