Compare commits

...

4 commits

Author SHA1 Message Date
Nathan Shively-Sanders 8fd16baba1 suggest primitives instead of wrappers 2021-09-30 13:12:17 -07:00
Nathan Shively-Sanders a734b84ed0 Always suggest spelling corrections
Even for types. Based on #42126, but without the namespace-specific
error message.
2021-09-30 11:03:07 -07:00
Nathan Shively-Sanders fc1a2aa450 Merge branch 'main' into always-suggesting-spelling-correction 2021-09-30 08:49:09 -07:00
Nathan Shively-Sanders 5ffa9a1216 Add parameter comments for resolveName calls 2021-09-30 08:48:36 -07:00
13 changed files with 65 additions and 47 deletions

View file

@ -1757,9 +1757,8 @@ namespace ts {
nameNotFoundMessage: DiagnosticMessage | undefined,
nameArg: __String | Identifier | undefined,
isUse: boolean,
excludeGlobals = false,
issueSuggestions?: boolean): Symbol | undefined {
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol, issueSuggestions);
excludeGlobals = false): Symbol | undefined {
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol);
}
function resolveNameHelper(
@ -1770,7 +1769,7 @@ namespace ts {
nameArg: __String | Identifier | undefined,
isUse: boolean,
excludeGlobals: boolean,
lookup: typeof getSymbol, issueSuggestions?: boolean): Symbol | undefined {
lookup: typeof getSymbol): Symbol | undefined {
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
let result: Symbol | undefined;
let lastLocation: Node | undefined;
@ -2109,23 +2108,30 @@ namespace ts {
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
let suggestion: Symbol | undefined;
if (issueSuggestions && suggestionCount < maximumSuggestionCount) {
if (suggestionCount < maximumSuggestionCount) {
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
const isGlobalScopeAugmentationDeclaration = suggestion?.valueDeclaration && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
if (isGlobalScopeAugmentationDeclaration) {
suggestion = undefined;
}
if (suggestion) {
const suggestionName = symbolToString(suggestion);
let suggestionName = symbolToString(suggestion);
let elaborate = !!suggestion.valueDeclaration
if ((suggestionName === "String" || suggestionName === "Object" || suggestionName === "Number" || suggestionName === "BigInt" || suggestionName === "Symbol")
&& name !== suggestionName.toLowerCase()
&& name === (name as string).toLowerCase()) {
suggestionName = suggestionName.toLowerCase()
elaborate = false
}
const isUncheckedJS = isUncheckedJSSuggestion(originalLocation, suggestion, /*excludeClasses*/ false);
const message = isUncheckedJS ? Diagnostics.Could_not_find_name_0_Did_you_mean_1 : Diagnostics.Cannot_find_name_0_Did_you_mean_1;
const diagnostic = createError(errorLocation, message, diagnosticName(nameArg!), suggestionName);
addErrorOrSuggestion(!isUncheckedJS, diagnostic);
if (suggestion.valueDeclaration) {
if (elaborate) {
addRelatedInfo(
diagnostic,
createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics._0_is_declared_here, suggestionName)
createDiagnosticForNode(suggestion.valueDeclaration!, Diagnostics._0_is_declared_here, suggestionName)
);
}
}
@ -3187,7 +3193,7 @@ namespace ts {
function tryGetQualifiedNameAsValue(node: QualifiedName) {
let left: Identifier | QualifiedName = getFirstIdentifier(node);
let symbol = resolveName(left, left.escapedText, SymbolFlags.Value, undefined, left, /*isUse*/ true);
let symbol = resolveName(left, left.escapedText, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, left, /*isUse*/ true);
if (!symbol) {
return undefined;
}
@ -5995,7 +6001,7 @@ namespace ts {
}
function typeParameterShadowsNameInScope(escapedName: __String, context: NodeBuilderContext, type: TypeParameter) {
const result = resolveName(context.enclosingDeclaration, escapedName, SymbolFlags.Type, /*nameNotFoundArg*/ undefined, escapedName, /*isUse*/ false);
const result = resolveName(context.enclosingDeclaration, escapedName, SymbolFlags.Type, /*nameNotFoundMessage*/ undefined, escapedName, /*isUse*/ false);
if (result) {
if (result.flags & SymbolFlags.TypeParameter && result === type.symbol) {
return false;
@ -8201,7 +8207,7 @@ namespace ts {
const internalModuleReference = declaration.moduleReference as Identifier | QualifiedName;
const firstIdentifier = getFirstIdentifier(internalModuleReference);
const importSymbol = resolveName(declaration, firstIdentifier.escapedText, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace,
undefined, undefined, /*isUse*/ false);
/*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false);
if (importSymbol && visited) {
if (tryAddToSet(visited, getSymbolId(importSymbol))) {
buildVisibleNodeList(importSymbol.declarations);
@ -12450,7 +12456,7 @@ namespace ts {
const type = isJSDocParameterTag(param) ? (param.typeExpression && param.typeExpression.type) : param.type;
// Include parameter symbol instead of property symbol in the signature
if (paramSymbol && !!(paramSymbol.flags & SymbolFlags.Property) && !isBindingPattern(param.name)) {
const resolvedSymbol = resolveName(param, paramSymbol.escapedName, SymbolFlags.Value, undefined, undefined, /*isUse*/ false);
const resolvedSymbol = resolveName(param, paramSymbol.escapedName, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false);
paramSymbol = resolvedSymbol!;
}
if (i === 0 && paramSymbol.escapedName === InternalSymbolName.This) {
@ -21072,7 +21078,7 @@ namespace ts {
if (isIdentifier(param.name) &&
(isCallSignatureDeclaration(param.parent) || isMethodSignature(param.parent) || isFunctionTypeNode(param.parent)) &&
param.parent.parameters.indexOf(param) > -1 &&
(resolveName(param, param.name.escapedText, SymbolFlags.Type, undefined, param.name.escapedText, /*isUse*/ true) ||
(resolveName(param, param.name.escapedText, SymbolFlags.Type, /*nameNotFoundMessage*/ undefined, param.name.escapedText, /*isUse*/ true) ||
param.name.originalKeywordKind && isTypeNodeKind(param.name.originalKeywordKind))) {
const newName = "arg" + param.parent.parameters.indexOf(param);
errorOrSuggestion(noImplicitAny, declaration, Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1, newName, declarationNameToString(param.name));
@ -22397,8 +22403,7 @@ namespace ts {
getCannotFindNameDiagnosticForName(node),
node,
!isWriteOnlyAccess(node),
/*excludeGlobals*/ false,
/*issueSuggestions*/ true) || unknownSymbol;
/*excludeGlobals*/ false) || unknownSymbol;
}
return links.resolvedSymbol;
}
@ -25911,7 +25916,7 @@ namespace ts {
}
else if (isIdentifier(lhs.expression)) {
const id = lhs.expression;
const parentSymbol = resolveName(id, id.escapedText, SymbolFlags.Value, undefined, id.escapedText, /*isUse*/ true);
const parentSymbol = resolveName(id, id.escapedText, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, id.escapedText, /*isUse*/ true);
if (parentSymbol) {
const annotated = parentSymbol.valueDeclaration && getEffectiveTypeAnnotationNode(parentSymbol.valueDeclaration);
if (annotated) {
@ -25951,7 +25956,7 @@ namespace ts {
return false;
}
const name = ((declaration.left as AccessExpression).expression as Identifier).escapedText;
const symbol = resolveName(declaration.left, name, SymbolFlags.Value, undefined, undefined, /*isUse*/ true, /*excludeGlobals*/ true);
const symbol = resolveName(declaration.left, name, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ true, /*excludeGlobals*/ true);
return isThisInitializedDeclaration(symbol?.valueDeclaration);
}
@ -29529,7 +29534,7 @@ namespace ts {
function isPromiseResolveArityError(node: CallLikeExpression) {
if (!isCallExpression(node) || !isIdentifier(node.expression)) return false;
const symbol = resolveName(node.expression, node.expression.escapedText, SymbolFlags.Value, undefined, undefined, false);
const symbol = resolveName(node.expression, node.expression.escapedText, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, false);
const decl = symbol?.valueDeclaration;
if (!decl || !isParameter(decl) || !isFunctionExpressionOrArrowFunction(decl.parent) || !isNewExpression(decl.parent.parent) || !isIdentifier(decl.parent.parent.expression)) {
return false;
@ -33029,7 +33034,7 @@ namespace ts {
const propType = getTypeOfSymbol(prop);
if (propType.symbol && propType.symbol.flags & SymbolFlags.Class) {
const name = prop.escapedName;
const symbol = resolveName(prop.valueDeclaration, name, SymbolFlags.Type, undefined, name, /*isUse*/ false);
const symbol = resolveName(prop.valueDeclaration, name, SymbolFlags.Type, /*nameNotFoundMessage*/ undefined, name, /*isUse*/ false);
if (symbol?.declarations && symbol.declarations.some(isJSDocTypedefTag)) {
addDuplicateDeclarationErrorsForSymbols(symbol, Diagnostics.Duplicate_identifier_0, unescapeLeadingUnderscores(name), prop);
addDuplicateDeclarationErrorsForSymbols(prop, Diagnostics.Duplicate_identifier_0, unescapeLeadingUnderscores(name), symbol);

View file

@ -1,10 +1,13 @@
tests/cases/compiler/declarationEmitUnknownImport.ts(1,1): error TS2303: Circular definition of import alias 'Foo'.
tests/cases/compiler/declarationEmitUnknownImport.ts(1,14): error TS2304: Cannot find name 'SomeNonExistingName'.
tests/cases/compiler/declarationEmitUnknownImport.ts(1,14): error TS2503: Cannot find namespace 'SomeNonExistingName'.
tests/cases/compiler/declarationEmitUnknownImport.ts(1,14): error TS4000: Import declaration 'Foo' is using private name 'SomeNonExistingName'.
==== tests/cases/compiler/declarationEmitUnknownImport.ts (3 errors) ====
==== tests/cases/compiler/declarationEmitUnknownImport.ts (4 errors) ====
import Foo = SomeNonExistingName
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2303: Circular definition of import alias 'Foo'.
~~~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'SomeNonExistingName'.
~~~~~~~~~~~~~~~~~~~

View file

@ -1,3 +1,4 @@
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,1): error TS2303: Circular definition of import alias 'Foo'.
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,12): error TS1005: '=' expected.
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,12): error TS2304: Cannot find name 'From'.
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,12): error TS2503: Cannot find namespace 'From'.
@ -5,8 +6,10 @@ tests/cases/compiler/declarationEmitUnknownImport2.ts(1,12): error TS4000: Impor
tests/cases/compiler/declarationEmitUnknownImport2.ts(1,17): error TS1005: ';' expected.
==== tests/cases/compiler/declarationEmitUnknownImport2.ts (5 errors) ====
==== tests/cases/compiler/declarationEmitUnknownImport2.ts (6 errors) ====
import Foo From './Foo'; // Syntax error
~~~~~~~~~~~~~~~
!!! error TS2303: Circular definition of import alias 'Foo'.
~~~~
!!! error TS1005: '=' expected.
~~~~

View file

@ -1,5 +1,5 @@
tests/cases/compiler/extendArray.ts(7,19): error TS2304: Cannot find name '_element'.
tests/cases/compiler/extendArray.ts(7,32): error TS2304: Cannot find name '_element'.
tests/cases/compiler/extendArray.ts(7,19): error TS2552: Cannot find name '_element'. Did you mean 'Element'?
tests/cases/compiler/extendArray.ts(7,32): error TS2552: Cannot find name '_element'. Did you mean 'Element'?
==== tests/cases/compiler/extendArray.ts (2 errors) ====
@ -11,9 +11,11 @@ tests/cases/compiler/extendArray.ts(7,32): error TS2304: Cannot find name '_elem
interface Array {
collect(fn:(e:_element) => _element[]) : any[];
~~~~~~~~
!!! error TS2304: Cannot find name '_element'.
!!! error TS2552: Cannot find name '_element'. Did you mean 'Element'?
!!! related TS2728 /.ts/lib.dom.d.ts:4792:13: 'Element' is declared here.
~~~~~~~~
!!! error TS2304: Cannot find name '_element'.
!!! error TS2552: Cannot find name '_element'. Did you mean 'Element'?
!!! related TS2728 /.ts/lib.dom.d.ts:4792:13: 'Element' is declared here.
}
}

View file

@ -1,4 +1,4 @@
tests/cases/compiler/importedModuleAddToGlobal.ts(15,23): error TS2503: Cannot find namespace 'b'.
tests/cases/compiler/importedModuleAddToGlobal.ts(15,23): error TS2552: Cannot find name 'b'. Did you mean 'B'?
==== tests/cases/compiler/importedModuleAddToGlobal.ts (1 errors) ====
@ -18,5 +18,6 @@ tests/cases/compiler/importedModuleAddToGlobal.ts(15,23): error TS2503: Cannot f
import a = A;
function hello(): b.B { return null; }
~
!!! error TS2503: Cannot find namespace 'b'.
!!! error TS2552: Cannot find name 'b'. Did you mean 'B'?
!!! related TS2728 tests/cases/compiler/importedModuleAddToGlobal.ts:8:8: 'B' is declared here.
}

View file

@ -1,6 +1,6 @@
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(2,18): error TS2300: Duplicate identifier 'Point'.
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(3,16): error TS2300: Duplicate identifier 'Point'.
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(12,8): error TS2503: Cannot find namespace 'm'.
tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts(12,8): error TS2552: Cannot find name 'm'. Did you mean 'M'?
==== tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts (3 errors) ====
@ -21,7 +21,8 @@ tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedMo
var m = M2;
var p: m.Point; // Error
~
!!! error TS2503: Cannot find namespace 'm'.
!!! error TS2552: Cannot find name 'm'. Did you mean 'M'?
!!! related TS2728 tests/cases/conformance/internalModules/moduleDeclarations/invalidInstantiatedModule.ts:1:8: 'M' is declared here.

View file

@ -1,4 +1,4 @@
/a.js(3,15): error TS2304: Cannot find name 'sting'.
/a.js(3,15): error TS2552: Cannot find name 'sting'. Did you mean 'string'?
==== /a.js (1 errors) ====
@ -6,7 +6,7 @@
* @typedef MyType
* @property {sting} [x]
~~~~~
!!! error TS2304: Cannot find name 'sting'.
!!! error TS2552: Cannot find name 'sting'. Did you mean 'string'?
*/
/** @param {MyType} p */

View file

@ -1,4 +1,4 @@
tests/cases/compiler/test.tsx(9,17): error TS2304: Cannot find name 'createElement'.
tests/cases/compiler/test.tsx(9,17): error TS2552: Cannot find name 'createElement'. Did you mean 'frameElement'?
==== tests/cases/compiler/test.tsx (1 errors) ====
@ -12,7 +12,8 @@ tests/cases/compiler/test.tsx(9,17): error TS2304: Cannot find name 'createEleme
render() {
return <div />;
~~~
!!! error TS2304: Cannot find name 'createElement'.
!!! error TS2552: Cannot find name 'createElement'. Did you mean 'frameElement'?
!!! related TS2728 /.ts/lib.dom.d.ts:17075:13: 'frameElement' is declared here.
}
}

View file

@ -1,4 +1,4 @@
tests/cases/compiler/test.tsx(9,17): error TS2304: Cannot find name 'MyElement'.
tests/cases/compiler/test.tsx(9,17): error TS2552: Cannot find name 'MyElement'. Did you mean 'Element'?
==== tests/cases/compiler/test.tsx (1 errors) ====
@ -12,6 +12,7 @@ tests/cases/compiler/test.tsx(9,17): error TS2304: Cannot find name 'MyElement'.
render(createElement) {
return <div />;
~~~
!!! error TS2304: Cannot find name 'MyElement'.
!!! error TS2552: Cannot find name 'MyElement'. Did you mean 'Element'?
!!! related TS2728 /.ts/lib.dom.d.ts:4792:13: 'Element' is declared here.
}
}

View file

@ -1,11 +1,11 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(1,8): error TS2503: Cannot find namespace 'TypeModule1'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(1,8): error TS2552: Cannot find name 'TypeModule1'. Did you mean 'TypeModule2'?
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts(1,20): error TS1003: Identifier expected.
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnfinishedTypeNameBeforeKeyword1.ts (2 errors) ====
var x: TypeModule1.
~~~~~~~~~~~
!!! error TS2503: Cannot find namespace 'TypeModule1'.
!!! error TS2552: Cannot find name 'TypeModule1'. Did you mean 'TypeModule2'?
!!! error TS1003: Identifier expected.
module TypeModule2 {

View file

@ -1,5 +1,5 @@
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,23): error TS2304: Cannot find name 'IPromise'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,45): error TS2304: Cannot find name 'IPromise'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,23): error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,45): error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric1.ts(2,54): error TS1005: '>' expected.
@ -7,8 +7,8 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGener
interface IQService {
all(promises: IPromise < any > []): IPromise<
~~~~~~~~
!!! error TS2304: Cannot find name 'IPromise'.
!!! error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
~~~~~~~~
!!! error TS2304: Cannot find name 'IPromise'.
!!! error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
!!! error TS1005: '>' expected.

View file

@ -10,8 +10,8 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGener
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(4,37): error TS2693: 'any' only refers to a type, but is being used as a value here.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(4,41): error TS1005: ';' expected.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(4,43): error TS2693: 'any' only refers to a type, but is being used as a value here.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,23): error TS2304: Cannot find name 'IPromise'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,45): error TS2304: Cannot find name 'IPromise'.
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,23): error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,45): error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGeneric2.ts(8,54): error TS1005: '>' expected.
@ -49,8 +49,8 @@ tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserUnterminatedGener
interface IQService {
all(promises: IPromise < any > []): IPromise<
~~~~~~~~
!!! error TS2304: Cannot find name 'IPromise'.
!!! error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
~~~~~~~~
!!! error TS2304: Cannot find name 'IPromise'.
!!! error TS2552: Cannot find name 'IPromise'. Did you mean 'Promise'?
!!! error TS1005: '>' expected.

View file

@ -1,5 +1,5 @@
tests/cases/compiler/primaryExpressionMods.ts(7,8): error TS2709: Cannot use namespace 'M' as a type.
tests/cases/compiler/primaryExpressionMods.ts(11,8): error TS2503: Cannot find namespace 'm'.
tests/cases/compiler/primaryExpressionMods.ts(11,8): error TS2552: Cannot find name 'm'. Did you mean 'M'?
==== tests/cases/compiler/primaryExpressionMods.ts (2 errors) ====
@ -17,5 +17,6 @@ tests/cases/compiler/primaryExpressionMods.ts(11,8): error TS2503: Cannot find n
var x2 = m.a; // Same as M.a
var q: m.P; // Error
~
!!! error TS2503: Cannot find namespace 'm'.
!!! error TS2552: Cannot find name 'm'. Did you mean 'M'?
!!! related TS2728 tests/cases/compiler/primaryExpressionMods.ts:1:8: 'M' is declared here.