Skip to content

Commit c2c4fd8

Browse files
committed
CR: use nameNotFoundMessage to decide whether to report errors in resolveName
1 parent 3b2c300 commit c2c4fd8

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/compiler/checker.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,7 @@ namespace ts {
18271827
* the nameNotFoundMessage argument is not undefined. Returns the resolved symbol, or undefined if no symbol with
18281828
* the given name can be found.
18291829
*
1830+
* @param nameNotFoundMessage If defined, we will report errors found during resolve.
18301831
* @param isUse If true, this will count towards --noUnusedLocals / --noUnusedParameters.
18311832
*/
18321833
function resolveName(
@@ -1837,9 +1838,8 @@ namespace ts {
18371838
nameArg: __String | Identifier | undefined,
18381839
isUse: boolean,
18391840
excludeGlobals = false,
1840-
getSpellingSuggestions = true,
1841-
reportErrors = true): Symbol | undefined {
1842-
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggestions, getSymbol, reportErrors);
1841+
getSpellingSuggestions = true): Symbol | undefined {
1842+
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggestions, getSymbol);
18431843
}
18441844

18451845
function resolveNameHelper(
@@ -1851,8 +1851,7 @@ namespace ts {
18511851
isUse: boolean,
18521852
excludeGlobals: boolean,
18531853
getSpellingSuggestions: boolean,
1854-
lookup: typeof getSymbol,
1855-
reportErrors = true): Symbol | undefined {
1854+
lookup: typeof getSymbol): Symbol | undefined {
18561855
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
18571856
let result: Symbol | undefined;
18581857
let lastLocation: Node | undefined;
@@ -2013,7 +2012,7 @@ namespace ts {
20132012
// TypeScript 1.0 spec (April 2014): 3.4.1
20142013
// The scope of a type parameter extends over the entire declaration with which the type
20152014
// parameter list is associated, with the exception of static member declarations in classes.
2016-
if (reportErrors) {
2015+
if (nameNotFoundMessage) {
20172016
error(errorLocation, Diagnostics.Static_members_cannot_reference_class_type_parameters);
20182017
}
20192018
return undefined;
@@ -2033,7 +2032,7 @@ namespace ts {
20332032
if (lastLocation === (location as ExpressionWithTypeArguments).expression && (location.parent as HeritageClause).token === SyntaxKind.ExtendsKeyword) {
20342033
const container = location.parent.parent;
20352034
if (isClassLike(container) && (result = lookup(getSymbolOfNode(container).members!, name, meaning & SymbolFlags.Type))) {
2036-
if (reportErrors && nameNotFoundMessage) {
2035+
if (nameNotFoundMessage) {
20372036
error(errorLocation, Diagnostics.Base_class_expressions_cannot_reference_class_type_parameters);
20382037
}
20392038
return undefined;
@@ -2053,7 +2052,7 @@ namespace ts {
20532052
if (isClassLike(grandparent) || grandparent.kind === SyntaxKind.InterfaceDeclaration) {
20542053
// A reference to this grandparent's type parameters would be an error
20552054
if (result = lookup(getSymbolOfNode(grandparent as ClassLikeDeclaration | InterfaceDeclaration).members!, name, meaning & SymbolFlags.Type)) {
2056-
if (reportErrors) {
2055+
if (nameNotFoundMessage) {
20572056
error(errorLocation, Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type);
20582057
}
20592058
return undefined;
@@ -2212,7 +2211,7 @@ namespace ts {
22122211
}
22132212

22142213
if (!result) {
2215-
if (reportErrors && nameNotFoundMessage) {
2214+
if (nameNotFoundMessage) {
22162215
addLazyDiagnostic(() => {
22172216
if (!errorLocation ||
22182217
!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg!) && // TODO: GH#18217
@@ -2265,12 +2264,12 @@ namespace ts {
22652264
}
22662265
return undefined;
22672266
}
2268-
else if (reportErrors && checkAndReportErrorForInvalidInitializer()) {
2267+
else if (nameNotFoundMessage && checkAndReportErrorForInvalidInitializer()) {
22692268
return undefined;
22702269
}
22712270

22722271
// Perform extra checks only if error reporting was requested
2273-
if (reportErrors && nameNotFoundMessage) {
2272+
if (nameNotFoundMessage) {
22742273
addLazyDiagnostic(() => {
22752274
// Only check for block-scoped variable if we have an error location and are looking for the
22762275
// name with variable meaning
@@ -43502,8 +43501,7 @@ namespace ts {
4350243501
/*nameArg*/ undefined,
4350343502
/*isUse*/ true,
4350443503
/*excludeGlobals*/ undefined,
43505-
/*getSpellingSuggestions*/ undefined,
43506-
/*reportErrors*/ false);
43504+
/*getSpellingSuggestions*/ undefined);
4350743505
}
4350843506

4350943507
function getReferencedValueDeclaration(referenceIn: Identifier): Declaration | undefined {

0 commit comments

Comments
 (0)