typescript 4.7.0-dev.20220425 → 4.7.0-dev.20220428

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220425";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220428";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -9066,6 +9066,7 @@ var ts;
9066
9066
  This_syntax_requires_an_imported_helper_named_1_with_2_parameters_which_is_not_compatible_with_the_one_in_0_Consider_upgrading_your_version_of_0: diag(2807, ts.DiagnosticCategory.Error, "This_syntax_requires_an_imported_helper_named_1_with_2_parameters_which_is_not_compatible_with_the_o_2807", "This syntax requires an imported helper named '{1}' with {2} parameters, which is not compatible with the one in '{0}'. Consider upgrading your version of '{0}'."),
9067
9067
  A_get_accessor_must_be_at_least_as_accessible_as_the_setter: diag(2808, ts.DiagnosticCategory.Error, "A_get_accessor_must_be_at_least_as_accessible_as_the_setter_2808", "A get accessor must be at least as accessible as the setter"),
9068
9068
  Declaration_or_statement_expected_This_follows_a_block_of_statements_so_if_you_intended_to_write_a_destructuring_assignment_you_might_need_to_wrap_the_the_whole_assignment_in_parentheses: diag(2809, ts.DiagnosticCategory.Error, "Declaration_or_statement_expected_This_follows_a_block_of_statements_so_if_you_intended_to_write_a_d_2809", "Declaration or statement expected. This '=' follows a block of statements, so if you intended to write a destructuring assignment, you might need to wrap the the whole assignment in parentheses."),
9069
+ Expected_1_argument_but_got_0_new_Promise_needs_a_JSDoc_hint_to_produce_a_resolve_that_can_be_called_without_arguments: diag(2810, ts.DiagnosticCategory.Error, "Expected_1_argument_but_got_0_new_Promise_needs_a_JSDoc_hint_to_produce_a_resolve_that_can_be_called_2810", "Expected 1 argument, but got 0. 'new Promise()' needs a JSDoc hint to produce a 'resolve' that can be called without arguments."),
9069
9070
  Initializer_for_property_0: diag(2811, ts.DiagnosticCategory.Error, "Initializer_for_property_0_2811", "Initializer for property '{0}'"),
9070
9071
  Property_0_does_not_exist_on_type_1_Try_changing_the_lib_compiler_option_to_include_dom: diag(2812, ts.DiagnosticCategory.Error, "Property_0_does_not_exist_on_type_1_Try_changing_the_lib_compiler_option_to_include_dom_2812", "Property '{0}' does not exist on type '{1}'. Try changing the 'lib' compiler option to include 'dom'."),
9071
9072
  Class_declaration_cannot_implement_overload_list_for_0: diag(2813, ts.DiagnosticCategory.Error, "Class_declaration_cannot_implement_overload_list_for_0_2813", "Class declaration cannot implement overload list for '{0}'."),
@@ -38156,7 +38157,8 @@ var ts;
38156
38157
  if (!comment) {
38157
38158
  comment = parseTrailingTagComments(start, getNodePos(), indent, indentText);
38158
38159
  }
38159
- return finishNode(factory.createJSDocCallbackTag(tagName, typeExpression, fullName, comment), start);
38160
+ var end = comment !== undefined ? getNodePos() : typeExpression.end;
38161
+ return finishNode(factory.createJSDocCallbackTag(tagName, typeExpression, fullName, comment), start, end);
38160
38162
  }
38161
38163
  function escapedTextsEqual(a, b) {
38162
38164
  while (!ts.isIdentifier(a) || !ts.isIdentifier(b)) {
@@ -48530,6 +48532,7 @@ var ts;
48530
48532
  var keyofConstraintType = keyofStringsOnly ? stringType : stringNumberSymbolType;
48531
48533
  var numberOrBigIntType = getUnionType([numberType, bigintType]);
48532
48534
  var templateConstraintType = getUnionType([stringType, numberType, booleanType, bigintType, nullType, undefinedType]);
48535
+ var numericStringType = getTemplateLiteralType(["", ""], [numberType]); // The `${number}` type
48533
48536
  var restrictiveMapper = makeFunctionTypeMapper(function (t) { return t.flags & 262144 /* TypeParameter */ ? getRestrictiveTypeParameter(t) : t; });
48534
48537
  var permissiveMapper = makeFunctionTypeMapper(function (t) { return t.flags & 262144 /* TypeParameter */ ? wildcardType : t; });
48535
48538
  var uniqueLiteralType = createIntrinsicType(131072 /* Never */, "never"); // `uniqueLiteralType` is a special `never` flagged by union reduction to behave as a literal
@@ -51511,7 +51514,7 @@ var ts;
51511
51514
  }
51512
51515
  }
51513
51516
  function getExportSymbolOfValueSymbolIfExported(symbol) {
51514
- return getMergedSymbol(symbol && (symbol.flags & 1048576 /* ExportValue */) !== 0 ? symbol.exportSymbol : symbol);
51517
+ return getMergedSymbol(symbol && (symbol.flags & 1048576 /* ExportValue */) !== 0 && symbol.exportSymbol || symbol);
51515
51518
  }
51516
51519
  function symbolIsValue(symbol) {
51517
51520
  return !!(symbol.flags & 111551 /* Value */ || symbol.flags & 2097152 /* Alias */ && resolveAlias(symbol).flags & 111551 /* Value */ && !getTypeOnlyAliasDeclaration(symbol));
@@ -58914,7 +58917,7 @@ var ts;
58914
58917
  var typeVariable = getHomomorphicTypeVariable(type);
58915
58918
  if (typeVariable && !type.declaration.nameType) {
58916
58919
  var constraint = getConstraintOfTypeParameter(typeVariable);
58917
- if (constraint && (isArrayType(constraint) || isTupleType(constraint))) {
58920
+ if (constraint && isArrayOrTupleType(constraint)) {
58918
58921
  return instantiateType(type, prependTypeMapping(typeVariable, constraint, type.mapper));
58919
58922
  }
58920
58923
  }
@@ -59276,10 +59279,10 @@ var ts;
59276
59279
  }
59277
59280
  function isApplicableIndexType(source, target) {
59278
59281
  // A 'string' index signature applies to types assignable to 'string' or 'number', and a 'number' index
59279
- // signature applies to types assignable to 'number' and numeric string literal types.
59282
+ // signature applies to types assignable to 'number', `${number}` and numeric string literal types.
59280
59283
  return isTypeAssignableTo(source, target) ||
59281
59284
  target === stringType && isTypeAssignableTo(source, numberType) ||
59282
- target === numberType && !!(source.flags & 128 /* StringLiteral */) && ts.isNumericLiteralName(source.value);
59285
+ target === numberType && (source === numericStringType || !!(source.flags & 128 /* StringLiteral */) && ts.isNumericLiteralName(source.value));
59283
59286
  }
59284
59287
  function getIndexInfosOfStructuredType(type) {
59285
59288
  if (type.flags & 3670016 /* StructuredType */) {
@@ -60295,6 +60298,20 @@ var ts;
60295
60298
  constraints = ts.append(constraints, constraint);
60296
60299
  }
60297
60300
  }
60301
+ // Given a homomorphic mapped type { [K in keyof T]: XXX }, where T is constrained to an array or tuple type, in the
60302
+ // template type XXX, K has an added constraint of number | `${number}`.
60303
+ else if (type.flags & 262144 /* TypeParameter */ && parent.kind === 195 /* MappedType */ && node === parent.type) {
60304
+ var mappedType = getTypeFromTypeNode(parent);
60305
+ if (getTypeParameterFromMappedType(mappedType) === getActualTypeVariable(type)) {
60306
+ var typeParameter = getHomomorphicTypeVariable(mappedType);
60307
+ if (typeParameter) {
60308
+ var constraint = getConstraintOfTypeParameter(typeParameter);
60309
+ if (constraint && everyType(constraint, isArrayOrTupleType)) {
60310
+ constraints = ts.append(constraints, getUnionType([numberType, numericStringType]));
60311
+ }
60312
+ }
60313
+ }
60314
+ }
60298
60315
  node = parent;
60299
60316
  }
60300
60317
  return constraints ? getSubstitutionType(type, getIntersectionType(ts.append(constraints, type))) : type;
@@ -61262,7 +61279,7 @@ var ts;
61262
61279
  while (i > 0) {
61263
61280
  i--;
61264
61281
  var t = types[i];
61265
- var remove = t.flags & 4 /* String */ && includes & 128 /* StringLiteral */ ||
61282
+ var remove = t.flags & 4 /* String */ && includes & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ||
61266
61283
  t.flags & 8 /* Number */ && includes & 256 /* NumberLiteral */ ||
61267
61284
  t.flags & 64 /* BigInt */ && includes & 2048 /* BigIntLiteral */ ||
61268
61285
  t.flags & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */;
@@ -61421,7 +61438,7 @@ var ts;
61421
61438
  if (!strictNullChecks && includes & 98304 /* Nullable */) {
61422
61439
  return includes & 32768 /* Undefined */ ? undefinedType : nullType;
61423
61440
  }
61424
- if (includes & 4 /* String */ && includes & 128 /* StringLiteral */ ||
61441
+ if (includes & 4 /* String */ && includes & (128 /* StringLiteral */ | 134217728 /* TemplateLiteral */ | 268435456 /* StringMapping */) ||
61425
61442
  includes & 8 /* Number */ && includes & 256 /* NumberLiteral */ ||
61426
61443
  includes & 64 /* BigInt */ && includes & 2048 /* BigIntLiteral */ ||
61427
61444
  includes & 4096 /* ESSymbol */ && includes & 8192 /* UniqueESSymbol */) {
@@ -63305,7 +63322,7 @@ var ts;
63305
63322
  if (!type.declaration.nameType) {
63306
63323
  var constraint = void 0;
63307
63324
  if (isArrayType(t) || t.flags & 1 /* Any */ && findResolutionCycleStartIndex(typeVariable, 4 /* ImmediateBaseConstraint */) < 0 &&
63308
- (constraint = getConstraintOfTypeParameter(typeVariable)) && everyType(constraint, ts.or(isArrayType, isTupleType))) {
63325
+ (constraint = getConstraintOfTypeParameter(typeVariable)) && everyType(constraint, isArrayOrTupleType)) {
63309
63326
  return instantiateMappedArrayType(t, type, prependTypeMapping(typeVariable, t, mapper));
63310
63327
  }
63311
63328
  if (isGenericTupleType(t)) {
@@ -64743,7 +64760,7 @@ var ts;
64743
64760
  }
64744
64761
  return false;
64745
64762
  }
64746
- return isTupleType(target) || isArrayType(target);
64763
+ return isArrayOrTupleType(target);
64747
64764
  }
64748
64765
  if (isReadonlyArrayType(source) && isMutableArrayOrTuple(target)) {
64749
64766
  if (reportErrors) {
@@ -64873,7 +64890,7 @@ var ts;
64873
64890
  // We suppress recursive intersection property checks because they can generate lots of work when relating
64874
64891
  // recursive intersections that are structurally similar but not exactly identical. See #37854.
64875
64892
  if (result_7 && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
64876
- isNonGenericObjectType(target) && !isArrayType(target) && !isTupleType(target) && source.flags & 2097152 /* Intersection */ && getApparentType(source).flags & 3670016 /* StructuredType */ && !ts.some(source.types, function (t) { return !!(ts.getObjectFlags(t) & 262144 /* NonInferrableType */); }))) {
64893
+ isNonGenericObjectType(target) && !isArrayOrTupleType(target) && source.flags & 2097152 /* Intersection */ && getApparentType(source).flags & 3670016 /* StructuredType */ && !ts.some(source.types, function (t) { return !!(ts.getObjectFlags(t) & 262144 /* NonInferrableType */); }))) {
64877
64894
  inPropertyCheck = true;
64878
64895
  result_7 &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
64879
64896
  inPropertyCheck = false;
@@ -65861,7 +65878,7 @@ var ts;
65861
65878
  return varianceResult;
65862
65879
  }
65863
65880
  }
65864
- else if (isReadonlyArrayType(target) ? isArrayType(source) || isTupleType(source) : isArrayType(target) && isTupleType(source) && !source.target.readonly) {
65881
+ else if (isReadonlyArrayType(target) ? isArrayOrTupleType(source) : isArrayType(target) && isTupleType(source) && !source.target.readonly) {
65865
65882
  if (relation !== identityRelation) {
65866
65883
  return isRelatedTo(getIndexTypeOfType(source, numberType) || anyType, getIndexTypeOfType(target, numberType) || anyType, 3 /* Both */, reportErrors);
65867
65884
  }
@@ -66237,7 +66254,7 @@ var ts;
66237
66254
  }
66238
66255
  var result = -1 /* True */;
66239
66256
  if (isTupleType(target)) {
66240
- if (isArrayType(source) || isTupleType(source)) {
66257
+ if (isArrayOrTupleType(source)) {
66241
66258
  if (!target.target.readonly && (isReadonlyArrayType(source) || isTupleType(source) && source.target.readonly)) {
66242
66259
  return 0 /* False */;
66243
66260
  }
@@ -67198,6 +67215,9 @@ var ts;
67198
67215
  function isReadonlyArrayType(type) {
67199
67216
  return !!(ts.getObjectFlags(type) & 4 /* Reference */) && type.target === globalReadonlyArrayType;
67200
67217
  }
67218
+ function isArrayOrTupleType(type) {
67219
+ return isArrayType(type) || isTupleType(type);
67220
+ }
67201
67221
  function isMutableArrayOrTuple(type) {
67202
67222
  return isArrayType(type) && !isReadonlyArrayType(type) || isTupleType(type) && !type.target.readonly;
67203
67223
  }
@@ -67649,7 +67669,7 @@ var ts;
67649
67669
  else if (type.flags & 2097152 /* Intersection */) {
67650
67670
  result = getIntersectionType(ts.sameMap(type.types, getWidenedType));
67651
67671
  }
67652
- else if (isArrayType(type) || isTupleType(type)) {
67672
+ else if (isArrayOrTupleType(type)) {
67653
67673
  result = createTypeReference(type.target, ts.sameMap(getTypeArguments(type), getWidenedType));
67654
67674
  }
67655
67675
  if (result && context === undefined) {
@@ -67686,7 +67706,7 @@ var ts;
67686
67706
  }
67687
67707
  }
67688
67708
  }
67689
- if (isArrayType(type) || isTupleType(type)) {
67709
+ if (isArrayOrTupleType(type)) {
67690
67710
  for (var _b = 0, _c = getTypeArguments(type); _b < _c.length; _b++) {
67691
67711
  var t = _c[_b];
67692
67712
  if (reportWideningErrorsInType(t)) {
@@ -68747,7 +68767,7 @@ var ts;
68747
68767
  }
68748
68768
  // Infer from the members of source and target only if the two types are possibly related
68749
68769
  if (!typesDefinitelyUnrelated(source, target)) {
68750
- if (isArrayType(source) || isTupleType(source)) {
68770
+ if (isArrayOrTupleType(source)) {
68751
68771
  if (isTupleType(target)) {
68752
68772
  var sourceArity = getTypeReferenceArity(source);
68753
68773
  var targetArity = getTypeReferenceArity(target);
@@ -75768,8 +75788,14 @@ var ts;
75768
75788
  var parameterRange = hasRestParameter ? min
75769
75789
  : min < max ? min + "-" + max
75770
75790
  : min;
75771
- var error = hasRestParameter ? ts.Diagnostics.Expected_at_least_0_arguments_but_got_1
75772
- : parameterRange === 1 && args.length === 0 && isPromiseResolveArityError(node) ? ts.Diagnostics.Expected_0_arguments_but_got_1_Did_you_forget_to_include_void_in_your_type_argument_to_Promise
75791
+ var isVoidPromiseError = !hasRestParameter && parameterRange === 1 && args.length === 0 && isPromiseResolveArityError(node);
75792
+ if (isVoidPromiseError && ts.isInJSFile(node)) {
75793
+ return getDiagnosticForCallNode(node, ts.Diagnostics.Expected_1_argument_but_got_0_new_Promise_needs_a_JSDoc_hint_to_produce_a_resolve_that_can_be_called_without_arguments);
75794
+ }
75795
+ var error = hasRestParameter
75796
+ ? ts.Diagnostics.Expected_at_least_0_arguments_but_got_1
75797
+ : isVoidPromiseError
75798
+ ? ts.Diagnostics.Expected_0_arguments_but_got_1_Did_you_forget_to_include_void_in_your_type_argument_to_Promise
75773
75799
  : ts.Diagnostics.Expected_0_arguments_but_got_1;
75774
75800
  if (min < args.length && args.length < max) {
75775
75801
  // between min and max, but with no matching overload
@@ -108692,6 +108718,8 @@ var ts;
108692
108718
  var varDecl = factory.createVariableDeclaration(newId, /*exclamationToken*/ undefined, resolver.createTypeOfExpression(input.expression, input, declarationEmitNodeBuilderFlags, symbolTracker), /*initializer*/ undefined);
108693
108719
  errorFallbackNode = undefined;
108694
108720
  var statement = factory.createVariableStatement(needsDeclare ? [factory.createModifier(135 /* DeclareKeyword */)] : [], factory.createVariableDeclarationList([varDecl], 2 /* Const */));
108721
+ preserveJsDoc(statement, input);
108722
+ ts.removeAllComments(input);
108695
108723
  return [statement, factory.updateExportAssignment(input, input.decorators, input.modifiers, newId)];
108696
108724
  }
108697
108725
  }
@@ -125076,7 +125104,7 @@ var ts;
125076
125104
  if (!state.watch || !state.lastCachedPackageJsonLookups)
125077
125105
  return;
125078
125106
  ts.mutateMap(getOrCreateValueMapFromConfigFileMap(state.allWatchedPackageJsonFiles, resolvedPath), new ts.Map(state.lastCachedPackageJsonLookups.get(resolvedPath)), {
125079
- createNewValue: function (path, _input) { return state.watchFile(path, function () { return invalidateProjectAndScheduleBuilds(state, resolvedPath, ts.ConfigFileProgramReloadLevel.Full); }, ts.PollingInterval.High, parsed === null || parsed === void 0 ? void 0 : parsed.watchOptions, ts.WatchType.PackageJson, resolved); },
125107
+ createNewValue: function (path, _input) { return state.watchFile(path, function () { return invalidateProjectAndScheduleBuilds(state, resolvedPath, ts.ConfigFileProgramReloadLevel.None); }, ts.PollingInterval.High, parsed === null || parsed === void 0 ? void 0 : parsed.watchOptions, ts.WatchType.PackageJson, resolved); },
125080
125108
  onDeleteValue: ts.closeFileWatcher,
125081
125109
  });
125082
125110
  }
@@ -125821,6 +125849,17 @@ var ts;
125821
125849
  SymbolDisplayPartKind[SymbolDisplayPartKind["linkName"] = 23] = "linkName";
125822
125850
  SymbolDisplayPartKind[SymbolDisplayPartKind["linkText"] = 24] = "linkText";
125823
125851
  })(SymbolDisplayPartKind = ts.SymbolDisplayPartKind || (ts.SymbolDisplayPartKind = {}));
125852
+ // Do not change existing values, as they exist in telemetry.
125853
+ var CompletionInfoFlags;
125854
+ (function (CompletionInfoFlags) {
125855
+ CompletionInfoFlags[CompletionInfoFlags["None"] = 0] = "None";
125856
+ CompletionInfoFlags[CompletionInfoFlags["MayIncludeAutoImports"] = 1] = "MayIncludeAutoImports";
125857
+ CompletionInfoFlags[CompletionInfoFlags["IsImportStatementCompletion"] = 2] = "IsImportStatementCompletion";
125858
+ CompletionInfoFlags[CompletionInfoFlags["IsContinuation"] = 4] = "IsContinuation";
125859
+ CompletionInfoFlags[CompletionInfoFlags["ResolvedModuleSpecifiers"] = 8] = "ResolvedModuleSpecifiers";
125860
+ CompletionInfoFlags[CompletionInfoFlags["ResolvedModuleSpecifiersBeyondLimit"] = 16] = "ResolvedModuleSpecifiersBeyondLimit";
125861
+ CompletionInfoFlags[CompletionInfoFlags["MayIncludeMethodSnippets"] = 32] = "MayIncludeMethodSnippets";
125862
+ })(CompletionInfoFlags = ts.CompletionInfoFlags || (ts.CompletionInfoFlags = {}));
125824
125863
  var OutliningSpanKind;
125825
125864
  (function (OutliningSpanKind) {
125826
125865
  /** Single or multi-line comments */
@@ -127833,6 +127872,14 @@ var ts;
127833
127872
  return __assign(__assign({}, createModuleSpecifierResolutionHost(program, host)), { getCommonSourceDirectory: function () { return program.getCommonSourceDirectory(); } });
127834
127873
  }
127835
127874
  ts.getModuleSpecifierResolverHost = getModuleSpecifierResolverHost;
127875
+ function moduleResolutionRespectsExports(moduleResolution) {
127876
+ return moduleResolution >= ts.ModuleResolutionKind.Node12 && moduleResolution <= ts.ModuleResolutionKind.NodeNext;
127877
+ }
127878
+ ts.moduleResolutionRespectsExports = moduleResolutionRespectsExports;
127879
+ function moduleResolutionUsesNodeModules(moduleResolution) {
127880
+ return moduleResolution === ts.ModuleResolutionKind.NodeJs || moduleResolution >= ts.ModuleResolutionKind.Node12 && moduleResolution <= ts.ModuleResolutionKind.NodeNext;
127881
+ }
127882
+ ts.moduleResolutionUsesNodeModules = moduleResolutionUsesNodeModules;
127836
127883
  function makeImportIfNecessary(defaultImport, namedImports, moduleSpecifier, quotePreference) {
127837
127884
  return defaultImport || namedImports && namedImports.length ? makeImport(defaultImport, namedImports, moduleSpecifier, quotePreference) : undefined;
127838
127885
  }
@@ -129436,8 +129483,8 @@ var ts;
129436
129483
  if (from === to)
129437
129484
  return false;
129438
129485
  var cachedResult = moduleSpecifierCache === null || moduleSpecifierCache === void 0 ? void 0 : moduleSpecifierCache.get(from.path, to.path, preferences, {});
129439
- if ((cachedResult === null || cachedResult === void 0 ? void 0 : cachedResult.isAutoImportable) !== undefined) {
129440
- return cachedResult.isAutoImportable;
129486
+ if ((cachedResult === null || cachedResult === void 0 ? void 0 : cachedResult.isBlockedByPackageJsonDependencies) !== undefined) {
129487
+ return !cachedResult.isBlockedByPackageJsonDependencies;
129441
129488
  }
129442
129489
  var getCanonicalFileName = ts.hostGetCanonicalFileName(moduleSpecifierResolutionHost);
129443
129490
  var globalTypingsCache = (_a = moduleSpecifierResolutionHost.getGlobalTypingsCacheLocation) === null || _a === void 0 ? void 0 : _a.call(moduleSpecifierResolutionHost);
@@ -129451,7 +129498,7 @@ var ts;
129451
129498
  });
129452
129499
  if (packageJsonFilter) {
129453
129500
  var isAutoImportable = hasImportablePath && packageJsonFilter.allowsImportingSourceFile(to, moduleSpecifierResolutionHost);
129454
- moduleSpecifierCache === null || moduleSpecifierCache === void 0 ? void 0 : moduleSpecifierCache.setIsAutoImportable(from.path, to.path, preferences, {}, isAutoImportable);
129501
+ moduleSpecifierCache === null || moduleSpecifierCache === void 0 ? void 0 : moduleSpecifierCache.setBlockedByPackageJsonDependencies(from.path, to.path, preferences, {}, !isAutoImportable);
129455
129502
  return isAutoImportable;
129456
129503
  }
129457
129504
  return hasImportablePath;
@@ -131730,15 +131777,26 @@ var ts;
131730
131777
  var _a, _b, _c;
131731
131778
  var start = ts.timestamp();
131732
131779
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
131733
- var resolutionLimitExceeded = false;
131780
+ // Under `--moduleResolution nodenext`, we have to resolve module specifiers up front, because
131781
+ // package.json exports can mean we *can't* resolve a module specifier (that doesn't include a
131782
+ // relative path into node_modules), and we want to filter those completions out entirely.
131783
+ // Import statement completions always need specifier resolution because the module specifier is
131784
+ // part of their `insertText`, not the `codeActions` creating edits away from the cursor.
131785
+ var needsFullResolution = isForImportStatementCompletion || ts.moduleResolutionRespectsExports(ts.getEmitModuleResolutionKind(program.getCompilerOptions()));
131786
+ var skippedAny = false;
131734
131787
  var ambientCount = 0;
131735
131788
  var resolvedCount = 0;
131736
131789
  var resolvedFromCacheCount = 0;
131737
131790
  var cacheAttemptCount = 0;
131738
- var result = cb({ tryResolve: tryResolve, resolutionLimitExceeded: function () { return resolutionLimitExceeded; } });
131791
+ var result = cb({
131792
+ tryResolve: tryResolve,
131793
+ skippedAny: function () { return skippedAny; },
131794
+ resolvedAny: function () { return resolvedCount > 0; },
131795
+ resolvedBeyondLimit: function () { return resolvedCount > Completions.moduleSpecifierResolutionLimit; },
131796
+ });
131739
131797
  var hitRateMessage = cacheAttemptCount ? " (" + (resolvedFromCacheCount / cacheAttemptCount * 100).toFixed(1) + "% hit rate)" : "";
131740
131798
  (_a = host.log) === null || _a === void 0 ? void 0 : _a.call(host, logPrefix + ": resolved " + resolvedCount + " module specifiers, plus " + ambientCount + " ambient and " + resolvedFromCacheCount + " from cache" + hitRateMessage);
131741
- (_b = host.log) === null || _b === void 0 ? void 0 : _b.call(host, logPrefix + ": response is " + (resolutionLimitExceeded ? "incomplete" : "complete"));
131799
+ (_b = host.log) === null || _b === void 0 ? void 0 : _b.call(host, logPrefix + ": response is " + (skippedAny ? "incomplete" : "complete"));
131742
131800
  (_c = host.log) === null || _c === void 0 ? void 0 : _c.call(host, logPrefix + ": " + (ts.timestamp() - start));
131743
131801
  return result;
131744
131802
  function tryResolve(exportInfo, symbolName, isFromAmbientModule) {
@@ -131747,22 +131805,22 @@ var ts;
131747
131805
  if (result_1) {
131748
131806
  ambientCount++;
131749
131807
  }
131750
- return result_1;
131808
+ return result_1 || "failed";
131751
131809
  }
131752
- var shouldResolveModuleSpecifier = isForImportStatementCompletion || preferences.allowIncompleteCompletions && resolvedCount < Completions.moduleSpecifierResolutionLimit;
131810
+ var shouldResolveModuleSpecifier = needsFullResolution || preferences.allowIncompleteCompletions && resolvedCount < Completions.moduleSpecifierResolutionLimit;
131753
131811
  var shouldGetModuleSpecifierFromCache = !shouldResolveModuleSpecifier && preferences.allowIncompleteCompletions && cacheAttemptCount < Completions.moduleSpecifierResolutionCacheAttemptLimit;
131754
131812
  var result = (shouldResolveModuleSpecifier || shouldGetModuleSpecifierFromCache)
131755
131813
  ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
131756
131814
  : undefined;
131757
131815
  if (!shouldResolveModuleSpecifier && !shouldGetModuleSpecifierFromCache || shouldGetModuleSpecifierFromCache && !result) {
131758
- resolutionLimitExceeded = true;
131816
+ skippedAny = true;
131759
131817
  }
131760
131818
  resolvedCount += (result === null || result === void 0 ? void 0 : result.computedWithoutCacheCount) || 0;
131761
- resolvedFromCacheCount += exportInfo.length - resolvedCount;
131819
+ resolvedFromCacheCount += exportInfo.length - ((result === null || result === void 0 ? void 0 : result.computedWithoutCacheCount) || 0);
131762
131820
  if (shouldGetModuleSpecifierFromCache) {
131763
131821
  cacheAttemptCount++;
131764
131822
  }
131765
- return result;
131823
+ return result || (needsFullResolution ? "failed" : "skipped");
131766
131824
  }
131767
131825
  }
131768
131826
  function getCompletionsAtPosition(host, program, log, sourceFile, position, preferences, triggerCharacter, completionKind, cancellationToken, formatContext) {
@@ -131860,6 +131918,7 @@ var ts;
131860
131918
  var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, program, file, location.getStart(), preferences,
131861
131919
  /*isForImportStatementCompletion*/ false, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
131862
131920
  var entries = ts.mapDefined(previousResponse.entries, function (entry) {
131921
+ var _a;
131863
131922
  if (!entry.hasAction || !entry.source || !entry.data || completionEntryDataIsResolved(entry.data)) {
131864
131923
  // Not an auto import or already resolved; keep as is
131865
131924
  return entry;
@@ -131871,8 +131930,12 @@ var ts;
131871
131930
  var origin = ts.Debug.checkDefined(getAutoImportSymbolFromCompletionEntryData(entry.name, entry.data, program, host)).origin;
131872
131931
  var info = exportMap.get(file.path, entry.data.exportMapKey);
131873
131932
  var result = info && context.tryResolve(info, entry.name, !ts.isExternalModuleNameRelative(ts.stripQuotes(origin.moduleSymbol.name)));
131874
- if (!result)
131933
+ if (result === "skipped")
131875
131934
  return entry;
131935
+ if (!result || result === "failed") {
131936
+ (_a = host.log) === null || _a === void 0 ? void 0 : _a.call(host, "Unexpected failure resolving auto import for '" + entry.name + "' from '" + entry.source + "'");
131937
+ return undefined;
131938
+ }
131876
131939
  var newOrigin = __assign(__assign({}, origin), { kind: 32 /* ResolvedExport */, moduleSpecifier: result.moduleSpecifier });
131877
131940
  // Mutating for performance... feels sketchy but nobody else uses the cache,
131878
131941
  // so why bother allocating a bunch of new objects?
@@ -131881,12 +131944,13 @@ var ts;
131881
131944
  entry.sourceDisplay = [ts.textPart(newOrigin.moduleSpecifier)];
131882
131945
  return entry;
131883
131946
  });
131884
- if (!context.resolutionLimitExceeded()) {
131947
+ if (!context.skippedAny()) {
131885
131948
  previousResponse.isIncomplete = undefined;
131886
131949
  }
131887
131950
  return entries;
131888
131951
  });
131889
131952
  previousResponse.entries = newEntries;
131953
+ previousResponse.flags = (previousResponse.flags || 0) | 4 /* IsContinuation */;
131890
131954
  return previousResponse;
131891
131955
  }
131892
131956
  function jsdocCompletionInfo(entries) {
@@ -131968,12 +132032,13 @@ var ts;
131968
132032
  ts.insertSorted(entries, createCompletionEntryForLiteral(sourceFile, preferences, literal), compareCompletionEntries, /*allowDuplicates*/ true);
131969
132033
  }
131970
132034
  return {
132035
+ flags: completionData.flags,
131971
132036
  isGlobalCompletion: isInSnippetScope,
131972
132037
  isIncomplete: preferences.allowIncompleteCompletions && hasUnresolvedAutoImports ? true : undefined,
131973
132038
  isMemberCompletion: isMemberCompletionKind(completionKind),
131974
132039
  isNewIdentifierLocation: isNewIdentifierLocation,
131975
132040
  optionalReplacementSpan: getOptionalReplacementSpan(location),
131976
- entries: entries
132041
+ entries: entries,
131977
132042
  };
131978
132043
  }
131979
132044
  function isUncheckedFile(sourceFile, compilerOptions) {
@@ -133030,6 +133095,7 @@ var ts;
133030
133095
  var location = ts.getTouchingPropertyName(sourceFile, position);
133031
133096
  var keywordFilters = 0 /* None */;
133032
133097
  var isNewIdentifierLocation = false;
133098
+ var flags = 0 /* None */;
133033
133099
  if (contextToken) {
133034
133100
  var importStatementCompletion = getImportStatementCompletionInfo(contextToken);
133035
133101
  isNewIdentifierLocation = importStatementCompletion.isNewIdentifierLocation;
@@ -133049,6 +133115,7 @@ var ts;
133049
133115
  // is not backward compatible with older clients, the language service defaults to disabling it, allowing newer clients
133050
133116
  // to opt in with the `includeCompletionsForImportStatements` user preference.
133051
133117
  importCompletionNode = importStatementCompletion.replacementNode;
133118
+ flags |= 2 /* IsImportStatementCompletion */;
133052
133119
  }
133053
133120
  // Bail out if this is a known invalid completion location
133054
133121
  if (!importCompletionNode && isCompletionListBlocker(contextToken)) {
@@ -133241,6 +133308,7 @@ var ts;
133241
133308
  isRightOfOpenTag: isRightOfOpenTag,
133242
133309
  importCompletionNode: importCompletionNode,
133243
133310
  hasUnresolvedAutoImports: hasUnresolvedAutoImports,
133311
+ flags: flags,
133244
133312
  };
133245
133313
  function isTagWithTypeExpression(tag) {
133246
133314
  switch (tag.kind) {
@@ -133650,6 +133718,7 @@ var ts;
133650
133718
  // Asking for completion details for an item that is not an auto-import
133651
133719
  return;
133652
133720
  }
133721
+ flags |= 1 /* MayIncludeAutoImports */;
133653
133722
  // import { type | -> token text should be blank
133654
133723
  var isAfterTypeOnlyImportSpecifierModifier = previousToken === contextToken
133655
133724
  && importCompletionNode
@@ -133680,16 +133749,36 @@ var ts;
133680
133749
  return true;
133681
133750
  return charactersFuzzyMatchInString(symbolName, lowerCaseTokenText);
133682
133751
  }, function (info, symbolName, isFromAmbientModule, exportMapKey) {
133752
+ var _a;
133683
133753
  if (detailsEntryId && !ts.some(info, function (i) { return detailsEntryId.source === ts.stripQuotes(i.moduleSymbol.name); })) {
133684
133754
  return;
133685
133755
  }
133686
- var defaultExportInfo = ts.find(info, isImportableExportInfo);
133687
- if (!defaultExportInfo) {
133756
+ // Do a relatively cheap check to bail early if all re-exports are non-importable
133757
+ // due to file location or package.json dependency filtering. For non-node12+
133758
+ // module resolution modes, getting past this point guarantees that we'll be
133759
+ // able to generate a suitable module specifier, so we can safely show a completion,
133760
+ // even if we defer computing the module specifier.
133761
+ var firstImportableExportInfo = ts.find(info, isImportableExportInfo);
133762
+ if (!firstImportableExportInfo) {
133763
+ return;
133764
+ }
133765
+ // In node12+, module specifier resolution can fail due to modules being blocked
133766
+ // by package.json `exports`. If that happens, don't show a completion item.
133767
+ // N.B. in this resolution mode we always try to resolve module specifiers here,
133768
+ // because we have to know now if it's going to fail so we can omit the completion
133769
+ // from the list.
133770
+ var result = context.tryResolve(info, symbolName, isFromAmbientModule) || {};
133771
+ if (result === "failed")
133688
133772
  return;
133773
+ // If we skipped resolving module specifiers, our selection of which ExportInfo
133774
+ // to use here is arbitrary, since the info shown in the completion list derived from
133775
+ // it should be identical regardless of which one is used. During the subsequent
133776
+ // `CompletionEntryDetails` request, we'll get all the ExportInfos again and pick
133777
+ // the best one based on the module specifier it produces.
133778
+ var exportInfo = firstImportableExportInfo, moduleSpecifier;
133779
+ if (result !== "skipped") {
133780
+ (_a = result.exportInfo, exportInfo = _a === void 0 ? firstImportableExportInfo : _a, moduleSpecifier = result.moduleSpecifier);
133689
133781
  }
133690
- // If we don't need to resolve module specifiers, we can use any re-export that is importable at all
133691
- // (We need to ensure that at least one is importable to show a completion.)
133692
- var _a = context.tryResolve(info, symbolName, isFromAmbientModule) || {}, _b = _a.exportInfo, exportInfo = _b === void 0 ? defaultExportInfo : _b, moduleSpecifier = _a.moduleSpecifier;
133693
133782
  var isDefaultExport = exportInfo.exportKind === 1 /* Default */;
133694
133783
  var symbol = isDefaultExport && ts.getLocalSymbolForExportDefault(exportInfo.symbol) || exportInfo.symbol;
133695
133784
  pushAutoImportSymbol(symbol, {
@@ -133704,7 +133793,9 @@ var ts;
133704
133793
  isFromPackageJson: exportInfo.isFromPackageJson,
133705
133794
  });
133706
133795
  });
133707
- hasUnresolvedAutoImports = context.resolutionLimitExceeded();
133796
+ hasUnresolvedAutoImports = context.skippedAny();
133797
+ flags |= context.resolvedAny() ? 8 /* ResolvedModuleSpecifiers */ : 0;
133798
+ flags |= context.resolvedBeyondLimit() ? 16 /* ResolvedModuleSpecifiersBeyondLimit */ : 0;
133708
133799
  });
133709
133800
  function isImportableExportInfo(info) {
133710
133801
  var moduleFile = ts.tryCast(info.moduleSymbol.valueDeclaration, ts.isSourceFile);
@@ -133752,6 +133843,7 @@ var ts;
133752
133843
  return;
133753
133844
  }
133754
133845
  var origin = __assign({ kind: 128 /* ObjectLiteralMethod */ }, entryProps);
133846
+ flags |= 32 /* MayIncludeMethodSnippets */;
133755
133847
  symbolToOriginInfoMap[symbols.length] = origin;
133756
133848
  symbols.push(member);
133757
133849
  });
@@ -133948,7 +134040,7 @@ var ts;
133948
134040
  // through type declaration or inference.
133949
134041
  // Also proceed if rootDeclaration is a parameter and if its containing function expression/arrow function is contextually typed -
133950
134042
  // type of parameter will flow in from the contextual type of the function
133951
- var canGetType = ts.hasInitializer(rootDeclaration) || ts.hasType(rootDeclaration) || rootDeclaration.parent.parent.kind === 244 /* ForOfStatement */;
134043
+ var canGetType = ts.hasInitializer(rootDeclaration) || !!ts.getEffectiveTypeAnnotationNode(rootDeclaration) || rootDeclaration.parent.parent.kind === 244 /* ForOfStatement */;
133952
134044
  if (!canGetType && rootDeclaration.kind === 164 /* Parameter */) {
133953
134045
  if (ts.isExpression(rootDeclaration.parent)) {
133954
134046
  canGetType = !!typeChecker.getContextualType(rootDeclaration.parent);
@@ -135223,6 +135315,8 @@ var ts;
135223
135315
  return highlightSpans(getAsyncAndAwaitOccurrences(node));
135224
135316
  case 125 /* YieldKeyword */:
135225
135317
  return highlightSpans(getYieldOccurrences(node));
135318
+ case 101 /* InKeyword */:
135319
+ return undefined;
135226
135320
  default:
135227
135321
  return ts.isModifierKind(node.kind) && (ts.isDeclaration(node.parent) || ts.isVariableStatement(node.parent))
135228
135322
  ? highlightSpans(getModifierOccurrences(node.kind, node.parent))
@@ -152945,6 +153039,7 @@ var ts;
152945
153039
  var compilerOptions = program.getCompilerOptions();
152946
153040
  var moduleSpecifierResolutionHost = ts.createModuleSpecifierResolutionHost(program, host);
152947
153041
  var getChecker = ts.memoizeOne(function (isFromPackageJson) { return isFromPackageJson ? host.getPackageJsonAutoImportProvider().getTypeChecker() : program.getTypeChecker(); });
153042
+ var rejectNodeModulesRelativePaths = ts.moduleResolutionUsesNodeModules(ts.getEmitModuleResolutionKind(compilerOptions));
152948
153043
  var getModuleSpecifiers = fromCacheOnly
152949
153044
  ? function (moduleSymbol) { return ({ moduleSpecifiers: ts.moduleSpecifiers.tryGetModuleSpecifiersFromCache(moduleSymbol, sourceFile, moduleSpecifierResolutionHost, preferences), computedWithoutCache: false }); }
152950
153045
  : function (moduleSymbol, checker) { return ts.moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences); };
@@ -152955,19 +153050,19 @@ var ts;
152955
153050
  var importedSymbolHasValueMeaning = !!(exportInfo.targetFlags & 111551 /* Value */);
152956
153051
  var addAsTypeOnly = getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ true, exportInfo.symbol, exportInfo.targetFlags, checker, compilerOptions);
152957
153052
  computedWithoutCacheCount += computedWithoutCache ? 1 : 0;
152958
- return moduleSpecifiers === null || moduleSpecifiers === void 0 ? void 0 : moduleSpecifiers.map(function (moduleSpecifier) {
152959
- // `position` should only be undefined at a missing jsx namespace, in which case we shouldn't be looking for pure types.
152960
- return !importedSymbolHasValueMeaning && isJs && position !== undefined
152961
- ? { kind: 1 /* JsdocTypeImport */, moduleSpecifier: moduleSpecifier, position: position, exportInfo: exportInfo, isReExport: i > 0 }
152962
- : {
152963
- kind: 3 /* AddNew */,
152964
- moduleSpecifier: moduleSpecifier,
152965
- importKind: getImportKind(sourceFile, exportInfo.exportKind, compilerOptions),
152966
- useRequire: useRequire,
152967
- addAsTypeOnly: addAsTypeOnly,
152968
- exportInfo: exportInfo,
152969
- isReExport: i > 0,
152970
- };
153053
+ return ts.mapDefined(moduleSpecifiers, function (moduleSpecifier) {
153054
+ return rejectNodeModulesRelativePaths && ts.pathContainsNodeModules(moduleSpecifier) ? undefined :
153055
+ // `position` should only be undefined at a missing jsx namespace, in which case we shouldn't be looking for pure types.
153056
+ !importedSymbolHasValueMeaning && isJs && position !== undefined ? { kind: 1 /* JsdocTypeImport */, moduleSpecifier: moduleSpecifier, position: position, exportInfo: exportInfo, isReExport: i > 0 } :
153057
+ {
153058
+ kind: 3 /* AddNew */,
153059
+ moduleSpecifier: moduleSpecifier,
153060
+ importKind: getImportKind(sourceFile, exportInfo.exportKind, compilerOptions),
153061
+ useRequire: useRequire,
153062
+ addAsTypeOnly: addAsTypeOnly,
153063
+ exportInfo: exportInfo,
153064
+ isReExport: i > 0,
153065
+ };
152971
153066
  });
152972
153067
  });
152973
153068
  return { computedWithoutCacheCount: computedWithoutCacheCount, fixes: fixes };
@@ -158540,6 +158635,7 @@ var ts;
158540
158635
  var fixName = "addVoidToPromise";
158541
158636
  var fixId = "addVoidToPromise";
158542
158637
  var errorCodes = [
158638
+ ts.Diagnostics.Expected_1_argument_but_got_0_new_Promise_needs_a_JSDoc_hint_to_produce_a_resolve_that_can_be_called_without_arguments.code,
158543
158639
  ts.Diagnostics.Expected_0_arguments_but_got_1_Did_you_forget_to_include_void_in_your_type_argument_to_Promise.code
158544
158640
  ];
158545
158641
  codefix.registerCodeFix({
@@ -174106,7 +174202,7 @@ var ts;
174106
174202
  return cache.get(toFileName);
174107
174203
  },
174108
174204
  set: function (fromFileName, toFileName, preferences, options, modulePaths, moduleSpecifiers) {
174109
- ensureCache(fromFileName, preferences, options).set(toFileName, createInfo(modulePaths, moduleSpecifiers, /*isAutoImportable*/ true));
174205
+ ensureCache(fromFileName, preferences, options).set(toFileName, createInfo(modulePaths, moduleSpecifiers, /*isBlockedByPackageJsonDependencies*/ false));
174110
174206
  // If any module specifiers were generated based off paths in node_modules,
174111
174207
  // a package.json file in that package was read and is an input to the cached.
174112
174208
  // Instead of watching each individual package.json file, set up a wildcard
@@ -174132,17 +174228,17 @@ var ts;
174132
174228
  info.modulePaths = modulePaths;
174133
174229
  }
174134
174230
  else {
174135
- cache.set(toFileName, createInfo(modulePaths, /*moduleSpecifiers*/ undefined, /*isAutoImportable*/ undefined));
174231
+ cache.set(toFileName, createInfo(modulePaths, /*moduleSpecifiers*/ undefined, /*isBlockedByPackageJsonDependencies*/ undefined));
174136
174232
  }
174137
174233
  },
174138
- setIsAutoImportable: function (fromFileName, toFileName, preferences, options, isAutoImportable) {
174234
+ setBlockedByPackageJsonDependencies: function (fromFileName, toFileName, preferences, options, isBlockedByPackageJsonDependencies) {
174139
174235
  var cache = ensureCache(fromFileName, preferences, options);
174140
174236
  var info = cache.get(toFileName);
174141
174237
  if (info) {
174142
- info.isAutoImportable = isAutoImportable;
174238
+ info.isBlockedByPackageJsonDependencies = isBlockedByPackageJsonDependencies;
174143
174239
  }
174144
174240
  else {
174145
- cache.set(toFileName, createInfo(/*modulePaths*/ undefined, /*moduleSpecifiers*/ undefined, isAutoImportable));
174241
+ cache.set(toFileName, createInfo(/*modulePaths*/ undefined, /*moduleSpecifiers*/ undefined, isBlockedByPackageJsonDependencies));
174146
174242
  }
174147
174243
  },
174148
174244
  clear: function () {
@@ -174170,8 +174266,8 @@ var ts;
174170
174266
  function key(fromFileName, preferences, options) {
174171
174267
  return fromFileName + "," + preferences.importModuleSpecifierEnding + "," + preferences.importModuleSpecifierPreference + "," + options.overrideImportMode;
174172
174268
  }
174173
- function createInfo(modulePaths, moduleSpecifiers, isAutoImportable) {
174174
- return { modulePaths: modulePaths, moduleSpecifiers: moduleSpecifiers, isAutoImportable: isAutoImportable };
174269
+ function createInfo(modulePaths, moduleSpecifiers, isBlockedByPackageJsonDependencies) {
174270
+ return { modulePaths: modulePaths, moduleSpecifiers: moduleSpecifiers, isBlockedByPackageJsonDependencies: isBlockedByPackageJsonDependencies };
174175
174271
  }
174176
174272
  }
174177
174273
  server.createModuleSpecifierCache = createModuleSpecifierCache;
@@ -6435,7 +6435,18 @@ declare namespace ts {
6435
6435
  argumentIndex: number;
6436
6436
  argumentCount: number;
6437
6437
  }
6438
+ enum CompletionInfoFlags {
6439
+ None = 0,
6440
+ MayIncludeAutoImports = 1,
6441
+ IsImportStatementCompletion = 2,
6442
+ IsContinuation = 4,
6443
+ ResolvedModuleSpecifiers = 8,
6444
+ ResolvedModuleSpecifiersBeyondLimit = 16,
6445
+ MayIncludeMethodSnippets = 32
6446
+ }
6438
6447
  interface CompletionInfo {
6448
+ /** For performance telemetry. */
6449
+ flags?: CompletionInfoFlags;
6439
6450
  /** Not true for all global completions. This will be true if the enclosing scope matches a few syntax kinds. See `isSnippetScope`. */
6440
6451
  isGlobalCompletion: boolean;
6441
6452
  isMemberCompletion: boolean;