@@ -432,6 +432,7 @@ namespace ts {
432
432
getIndexInfosOfType,
433
433
getSignaturesOfType,
434
434
getIndexTypeOfType: (type, kind) => getIndexTypeOfType(type, kind === IndexKind.String ? stringType : numberType),
435
+ getIndexType: type => getIndexType(type),
435
436
getBaseTypes,
436
437
getBaseTypeOfLiteralType,
437
438
getWidenedType,
@@ -1781,8 +1782,9 @@ namespace ts {
1781
1782
nameNotFoundMessage: DiagnosticMessage | undefined,
1782
1783
nameArg: __String | Identifier | undefined,
1783
1784
isUse: boolean,
1784
- excludeGlobals = false): Symbol | undefined {
1785
- return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol);
1785
+ excludeGlobals = false,
1786
+ getSpellingSuggstions = true): Symbol | undefined {
1787
+ return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggstions, getSymbol);
1786
1788
}
1787
1789
1788
1790
function resolveNameHelper(
@@ -1793,6 +1795,7 @@ namespace ts {
1793
1795
nameArg: __String | Identifier | undefined,
1794
1796
isUse: boolean,
1795
1797
excludeGlobals: boolean,
1798
+ getSpellingSuggestions: boolean,
1796
1799
lookup: typeof getSymbol): Symbol | undefined {
1797
1800
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
1798
1801
let result: Symbol | undefined;
@@ -2122,7 +2125,7 @@ namespace ts {
2122
2125
}
2123
2126
}
2124
2127
if (!result) {
2125
- if (nameNotFoundMessage) {
2128
+ if (nameNotFoundMessage && produceDiagnostics ) {
2126
2129
if (!errorLocation ||
2127
2130
!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg!) && // TODO: GH#18217
2128
2131
!checkAndReportErrorForExtendingInterface(errorLocation) &&
@@ -2132,7 +2135,7 @@ namespace ts {
2132
2135
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
2133
2136
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
2134
2137
let suggestion: Symbol | undefined;
2135
- if (suggestionCount < maximumSuggestionCount) {
2138
+ if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
2136
2139
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
2137
2140
const isGlobalScopeAugmentationDeclaration = suggestion?.valueDeclaration && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
2138
2141
if (isGlobalScopeAugmentationDeclaration) {
@@ -2172,7 +2175,7 @@ namespace ts {
2172
2175
}
2173
2176
2174
2177
// Perform extra checks only if error reporting was requested
2175
- if (nameNotFoundMessage) {
2178
+ if (nameNotFoundMessage && produceDiagnostics ) {
2176
2179
if (propertyWithInvalidInitializer && !(getEmitScriptTarget(compilerOptions) === ScriptTarget.ESNext && useDefineForClassFields)) {
2177
2180
// We have a match, but the reference occurred within a property initializer and the identifier also binds
2178
2181
// to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
@@ -13657,7 +13660,7 @@ namespace ts {
13657
13660
13658
13661
function getGlobalSymbol(name: __String, meaning: SymbolFlags, diagnostic: DiagnosticMessage | undefined): Symbol | undefined {
13659
13662
// Don't track references for global symbols anyway, so value if `isReference` is arbitrary
13660
- return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false);
13663
+ return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false, /*excludeGlobals*/ false, /*getSpellingSuggestions*/ false );
13661
13664
}
13662
13665
13663
13666
function getGlobalType(name: __String, arity: 0, reportErrors: true): ObjectType;
@@ -15344,10 +15347,6 @@ namespace ts {
15344
15347
(type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) && !isPatternLiteralType(type) ? ObjectFlags.IsGenericIndexType : 0);
15345
15348
}
15346
15349
15347
- function isThisTypeParameter(type: Type): boolean {
15348
- return !!(type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType);
15349
- }
15350
-
15351
15350
function getSimplifiedType(type: Type, writing: boolean): Type {
15352
15351
return type.flags & TypeFlags.IndexedAccess ? getSimplifiedIndexedAccessType(type as IndexedAccessType, writing) :
15353
15352
type.flags & TypeFlags.Conditional ? getSimplifiedConditionalType(type as ConditionalType, writing) :
@@ -20872,7 +20871,7 @@ namespace ts {
20872
20871
// flags for the string, number, boolean, "", 0, false, void, undefined, or null types respectively. Returns
20873
20872
// no flags for all other types (including non-falsy literal types).
20874
20873
function getFalsyFlags(type: Type): TypeFlags {
20875
- return type.flags & TypeFlags.Union ? getFalsyFlagsOfTypes((type as UnionType).types) :
20874
+ return type.flags & TypeFlags.UnionOrIntersection ? getFalsyFlagsOfTypes((type as UnionType).types) :
20876
20875
type.flags & TypeFlags.StringLiteral ? (type as StringLiteralType).value === "" ? TypeFlags.StringLiteral : 0 :
20877
20876
type.flags & TypeFlags.NumberLiteral ? (type as NumberLiteralType).value === 0 ? TypeFlags.NumberLiteral : 0 :
20878
20877
type.flags & TypeFlags.BigIntLiteral ? isZeroBigInt(type as BigIntLiteralType) ? TypeFlags.BigIntLiteral : 0 :
@@ -22544,6 +22543,11 @@ namespace ts {
22544
22543
case "BigInt64Array":
22545
22544
case "BigUint64Array":
22546
22545
return Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_1_or_later;
22546
+ case "await":
22547
+ if (isCallExpression(node.parent)) {
22548
+ return Diagnostics.Cannot_find_name_0_Did_you_mean_to_write_this_in_an_async_function;
22549
+ }
22550
+ // falls through
22547
22551
default:
22548
22552
if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) {
22549
22553
return Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer;
@@ -27280,15 +27284,9 @@ namespace ts {
27280
27284
}
27281
27285
27282
27286
function isValidSpreadType(type: Type): boolean {
27283
- if (type.flags & TypeFlags.Instantiable) {
27284
- const constraint = getBaseConstraintOfType(type);
27285
- if (constraint !== undefined) {
27286
- return isValidSpreadType(constraint);
27287
- }
27288
- }
27289
- return !!(type.flags & (TypeFlags.Any | TypeFlags.NonPrimitive | TypeFlags.Object | TypeFlags.InstantiableNonPrimitive) ||
27290
- getFalsyFlags(type) & TypeFlags.DefinitelyFalsy && isValidSpreadType(removeDefinitelyFalsyTypes(type)) ||
27291
- type.flags & TypeFlags.UnionOrIntersection && every((type as UnionOrIntersectionType).types, isValidSpreadType));
27287
+ const t = removeDefinitelyFalsyTypes(mapType(type, getBaseConstraintOrType));
27288
+ return !!(t.flags & (TypeFlags.Any | TypeFlags.NonPrimitive | TypeFlags.Object | TypeFlags.InstantiableNonPrimitive) ||
27289
+ t.flags & TypeFlags.UnionOrIntersection && every((t as UnionOrIntersectionType).types, isValidSpreadType));
27292
27290
}
27293
27291
27294
27292
function checkJsxSelfClosingElementDeferred(node: JsxSelfClosingElement) {
@@ -28718,7 +28716,7 @@ namespace ts {
28718
28716
28719
28717
function getSuggestedSymbolForNonexistentSymbol(location: Node | undefined, outerName: __String, meaning: SymbolFlags): Symbol | undefined {
28720
28718
Debug.assert(outerName !== undefined, "outername should always be defined");
28721
- const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, (symbols, name, meaning) => {
28719
+ const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, /*getSpellingSuggestions*/ true, (symbols, name, meaning) => {
28722
28720
Debug.assertEqual(outerName, name, "name should equal outerName");
28723
28721
const symbol = getSymbol(symbols, name, meaning);
28724
28722
// Sometimes the symbol is found when location is a return type of a function: `typeof x` and `x` is declared in the body of the function
@@ -43909,19 +43907,24 @@ namespace ts {
43909
43907
}
43910
43908
43911
43909
function checkNumericLiteralValueSize(node: NumericLiteral) {
43910
+ // We should test against `getTextOfNode(node)` rather than `node.text`, because `node.text` for large numeric literals can contain "."
43911
+ // e.g. `node.text` for numeric literal `1100000000000000000000` is `1.1e21`.
43912
+ const isFractional = getTextOfNode(node).indexOf(".") !== -1;
43913
+ const isScientific = node.numericLiteralFlags & TokenFlags.Scientific;
43914
+
43912
43915
// Scientific notation (e.g. 2e54 and 1e00000000010) can't be converted to bigint
43913
- // Literals with 15 or fewer characters aren't long enough to reach past 2^53 - 1
43914
43916
// Fractional numbers (e.g. 9000000000000000.001) are inherently imprecise anyway
43915
- if (node.numericLiteralFlags & TokenFlags.Scientific || node.text.length <= 15 || node.text.indexOf(".") !== -1 ) {
43917
+ if (isFractional || isScientific ) {
43916
43918
return;
43917
43919
}
43918
43920
43919
- // We can't rely on the runtime to accurately store and compare extremely large numeric values
43920
- // Even for internal use, we use getTextOfNode: https://github.com/microsoft/TypeScript/issues/33298
43921
- // Thus, if the runtime claims a too-large number is lower than Number.MAX_SAFE_INTEGER,
43922
- // it's likely addition operations on it will fail too
43923
- const apparentValue = +getTextOfNode(node);
43924
- if (apparentValue <= 2 ** 53 - 1 && apparentValue + 1 > apparentValue) {
43921
+ // Here `node` is guaranteed to be a numeric literal representing an integer.
43922
+ // We need to judge whether the integer `node` represents is <= 2 ** 53 - 1, which can be accomplished by comparing to `value` defined below because:
43923
+ // 1) when `node` represents an integer <= 2 ** 53 - 1, `node.text` is its exact string representation and thus `value` precisely represents the integer.
43924
+ // 2) otherwise, although `node.text` may be imprecise string representation, its mathematical value and consequently `value` cannot be less than 2 ** 53,
43925
+ // thus the result of the predicate won't be affected.
43926
+ const value = +node.text;
43927
+ if (value <= 2 ** 53 - 1) {
43925
43928
return;
43926
43929
}
43927
43930
0 commit comments