Skip to content

Commit 9f61bcd

Browse files
authored
Merge branch 'microsoft:main' into fix-issue-46815
2 parents 961f92f + b2af605 commit 9f61bcd

File tree

216 files changed

+79199
-78097
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

216 files changed

+79199
-78097
lines changed

.github/pr_owners.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ jessetrinity
1212
minestarks
1313
armanio123
1414
gabritto
15+
jakebailey
16+
DanielRosenwasser

package-lock.json

Lines changed: 11 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"browser-resolve": "^1.11.2",
6262
"browserify": "latest",
6363
"chai": "latest",
64-
"chalk": "latest",
64+
"chalk": "^4.1.2",
6565
"convert-source-map": "latest",
6666
"del": "5.1.0",
6767
"diff": "^4.0.2",

scripts/build/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const { Readable, Duplex } = require("stream");
2626
* @property {boolean} [hidePrompt]
2727
* @property {boolean} [waitForExit=true]
2828
*/
29-
function exec(cmd, args, options = {}) {
29+
async function exec(cmd, args, options = {}) {
3030
return /**@type {Promise<{exitCode: number}>}*/(new Promise((resolve, reject) => {
3131
const { ignoreExitCode, cancelToken = CancellationToken.none, waitForExit = true } = options;
3232
cancelToken.throwIfCancellationRequested();

src/compiler/checker.ts

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ namespace ts {
432432
getIndexInfosOfType,
433433
getSignaturesOfType,
434434
getIndexTypeOfType: (type, kind) => getIndexTypeOfType(type, kind === IndexKind.String ? stringType : numberType),
435+
getIndexType: type => getIndexType(type),
435436
getBaseTypes,
436437
getBaseTypeOfLiteralType,
437438
getWidenedType,
@@ -1781,8 +1782,9 @@ namespace ts {
17811782
nameNotFoundMessage: DiagnosticMessage | undefined,
17821783
nameArg: __String | Identifier | undefined,
17831784
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);
17861788
}
17871789

17881790
function resolveNameHelper(
@@ -1793,6 +1795,7 @@ namespace ts {
17931795
nameArg: __String | Identifier | undefined,
17941796
isUse: boolean,
17951797
excludeGlobals: boolean,
1798+
getSpellingSuggestions: boolean,
17961799
lookup: typeof getSymbol): Symbol | undefined {
17971800
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
17981801
let result: Symbol | undefined;
@@ -2122,7 +2125,7 @@ namespace ts {
21222125
}
21232126
}
21242127
if (!result) {
2125-
if (nameNotFoundMessage) {
2128+
if (nameNotFoundMessage && produceDiagnostics) {
21262129
if (!errorLocation ||
21272130
!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg!) && // TODO: GH#18217
21282131
!checkAndReportErrorForExtendingInterface(errorLocation) &&
@@ -2132,7 +2135,7 @@ namespace ts {
21322135
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
21332136
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
21342137
let suggestion: Symbol | undefined;
2135-
if (suggestionCount < maximumSuggestionCount) {
2138+
if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
21362139
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
21372140
const isGlobalScopeAugmentationDeclaration = suggestion?.valueDeclaration && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
21382141
if (isGlobalScopeAugmentationDeclaration) {
@@ -2172,7 +2175,7 @@ namespace ts {
21722175
}
21732176

21742177
// Perform extra checks only if error reporting was requested
2175-
if (nameNotFoundMessage) {
2178+
if (nameNotFoundMessage && produceDiagnostics) {
21762179
if (propertyWithInvalidInitializer && !(getEmitScriptTarget(compilerOptions) === ScriptTarget.ESNext && useDefineForClassFields)) {
21772180
// We have a match, but the reference occurred within a property initializer and the identifier also binds
21782181
// 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 {
1365713660

1365813661
function getGlobalSymbol(name: __String, meaning: SymbolFlags, diagnostic: DiagnosticMessage | undefined): Symbol | undefined {
1365913662
// 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);
1366113664
}
1366213665

1366313666
function getGlobalType(name: __String, arity: 0, reportErrors: true): ObjectType;
@@ -15344,10 +15347,6 @@ namespace ts {
1534415347
(type.flags & (TypeFlags.InstantiableNonPrimitive | TypeFlags.Index | TypeFlags.TemplateLiteral | TypeFlags.StringMapping) && !isPatternLiteralType(type) ? ObjectFlags.IsGenericIndexType : 0);
1534515348
}
1534615349

15347-
function isThisTypeParameter(type: Type): boolean {
15348-
return !!(type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType);
15349-
}
15350-
1535115350
function getSimplifiedType(type: Type, writing: boolean): Type {
1535215351
return type.flags & TypeFlags.IndexedAccess ? getSimplifiedIndexedAccessType(type as IndexedAccessType, writing) :
1535315352
type.flags & TypeFlags.Conditional ? getSimplifiedConditionalType(type as ConditionalType, writing) :
@@ -20872,7 +20871,7 @@ namespace ts {
2087220871
// flags for the string, number, boolean, "", 0, false, void, undefined, or null types respectively. Returns
2087320872
// no flags for all other types (including non-falsy literal types).
2087420873
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) :
2087620875
type.flags & TypeFlags.StringLiteral ? (type as StringLiteralType).value === "" ? TypeFlags.StringLiteral : 0 :
2087720876
type.flags & TypeFlags.NumberLiteral ? (type as NumberLiteralType).value === 0 ? TypeFlags.NumberLiteral : 0 :
2087820877
type.flags & TypeFlags.BigIntLiteral ? isZeroBigInt(type as BigIntLiteralType) ? TypeFlags.BigIntLiteral : 0 :
@@ -22544,6 +22543,11 @@ namespace ts {
2254422543
case "BigInt64Array":
2254522544
case "BigUint64Array":
2254622545
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
2254722551
default:
2254822552
if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) {
2254922553
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 {
2728027284
}
2728127285

2728227286
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));
2729227290
}
2729327291

2729427292
function checkJsxSelfClosingElementDeferred(node: JsxSelfClosingElement) {
@@ -28718,7 +28716,7 @@ namespace ts {
2871828716

2871928717
function getSuggestedSymbolForNonexistentSymbol(location: Node | undefined, outerName: __String, meaning: SymbolFlags): Symbol | undefined {
2872028718
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) => {
2872228720
Debug.assertEqual(outerName, name, "name should equal outerName");
2872328721
const symbol = getSymbol(symbols, name, meaning);
2872428722
// 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 {
4390943907
}
4391043908

4391143909
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+
4391243915
// 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
4391443916
// 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) {
4391643918
return;
4391743919
}
4391843920

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) {
4392543928
return;
4392643929
}
4392743930

0 commit comments

Comments
 (0)