typescript 4.6.0-dev.20220126 → 4.6.0-dev.20220130

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.20220126";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220130";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -8049,7 +8049,7 @@ var ts;
8049
8049
  }
8050
8050
  })(ts || (ts = {}));
8051
8051
  // <auto-generated />
8052
- // generated from './diagnosticInformationMap.generated.ts' by 'src/compiler'
8052
+ // generated from './diagnosticMessages.json' in 'src/compiler'
8053
8053
  /* @internal */
8054
8054
  var ts;
8055
8055
  (function (ts) {
@@ -9637,9 +9637,8 @@ var ts;
9637
9637
  Remove_variable_statement: diag(90010, ts.DiagnosticCategory.Message, "Remove_variable_statement_90010", "Remove variable statement"),
9638
9638
  Remove_template_tag: diag(90011, ts.DiagnosticCategory.Message, "Remove_template_tag_90011", "Remove template tag"),
9639
9639
  Remove_type_parameters: diag(90012, ts.DiagnosticCategory.Message, "Remove_type_parameters_90012", "Remove type parameters"),
9640
- Import_0_from_module_1: diag(90013, ts.DiagnosticCategory.Message, "Import_0_from_module_1_90013", "Import '{0}' from module \"{1}\""),
9640
+ Import_0_from_1: diag(90013, ts.DiagnosticCategory.Message, "Import_0_from_1_90013", "Import '{0}' from \"{1}\""),
9641
9641
  Change_0_to_1: diag(90014, ts.DiagnosticCategory.Message, "Change_0_to_1_90014", "Change '{0}' to '{1}'"),
9642
- Add_0_to_existing_import_declaration_from_1: diag(90015, ts.DiagnosticCategory.Message, "Add_0_to_existing_import_declaration_from_1_90015", "Add '{0}' to existing import declaration from \"{1}\""),
9643
9642
  Declare_property_0: diag(90016, ts.DiagnosticCategory.Message, "Declare_property_0_90016", "Declare property '{0}'"),
9644
9643
  Add_index_signature_for_property_0: diag(90017, ts.DiagnosticCategory.Message, "Add_index_signature_for_property_0_90017", "Add index signature for property '{0}'"),
9645
9644
  Disable_checking_for_this_file: diag(90018, ts.DiagnosticCategory.Message, "Disable_checking_for_this_file_90018", "Disable checking for this file"),
@@ -9656,8 +9655,6 @@ var ts;
9656
9655
  Add_async_modifier_to_containing_function: diag(90029, ts.DiagnosticCategory.Message, "Add_async_modifier_to_containing_function_90029", "Add async modifier to containing function"),
9657
9656
  Replace_infer_0_with_unknown: diag(90030, ts.DiagnosticCategory.Message, "Replace_infer_0_with_unknown_90030", "Replace 'infer {0}' with 'unknown'"),
9658
9657
  Replace_all_unused_infer_with_unknown: diag(90031, ts.DiagnosticCategory.Message, "Replace_all_unused_infer_with_unknown_90031", "Replace all unused 'infer' with 'unknown'"),
9659
- Import_default_0_from_module_1: diag(90032, ts.DiagnosticCategory.Message, "Import_default_0_from_module_1_90032", "Import default '{0}' from module \"{1}\""),
9660
- Add_default_import_0_to_existing_import_declaration_from_1: diag(90033, ts.DiagnosticCategory.Message, "Add_default_import_0_to_existing_import_declaration_from_1_90033", "Add default import '{0}' to existing import declaration from \"{1}\""),
9661
9658
  Add_parameter_name: diag(90034, ts.DiagnosticCategory.Message, "Add_parameter_name_90034", "Add parameter name"),
9662
9659
  Declare_private_property_0: diag(90035, ts.DiagnosticCategory.Message, "Declare_private_property_0_90035", "Declare private property '{0}'"),
9663
9660
  Replace_0_with_Promise_1: diag(90036, ts.DiagnosticCategory.Message, "Replace_0_with_Promise_1_90036", "Replace '{0}' with 'Promise<{1}>'"),
@@ -9667,6 +9664,10 @@ var ts;
9667
9664
  Remove_unused_declarations_for_Colon_0: diag(90041, ts.DiagnosticCategory.Message, "Remove_unused_declarations_for_Colon_0_90041", "Remove unused declarations for: '{0}'"),
9668
9665
  Declare_a_private_field_named_0: diag(90053, ts.DiagnosticCategory.Message, "Declare_a_private_field_named_0_90053", "Declare a private field named '{0}'."),
9669
9666
  Includes_imports_of_types_referenced_by_0: diag(90054, ts.DiagnosticCategory.Message, "Includes_imports_of_types_referenced_by_0_90054", "Includes imports of types referenced by '{0}'"),
9667
+ Remove_type_from_import_declaration_from_0: diag(90055, ts.DiagnosticCategory.Message, "Remove_type_from_import_declaration_from_0_90055", "Remove 'type' from import declaration from \"{0}\""),
9668
+ Remove_type_from_import_of_0_from_1: diag(90056, ts.DiagnosticCategory.Message, "Remove_type_from_import_of_0_from_1_90056", "Remove 'type' from import of '{0}' from \"{1}\""),
9669
+ Add_import_from_0: diag(90057, ts.DiagnosticCategory.Message, "Add_import_from_0_90057", "Add import from \"{0}\""),
9670
+ Update_import_from_0: diag(90058, ts.DiagnosticCategory.Message, "Update_import_from_0_90058", "Update import from \"{0}\""),
9670
9671
  Convert_function_to_an_ES2015_class: diag(95001, ts.DiagnosticCategory.Message, "Convert_function_to_an_ES2015_class_95001", "Convert function to an ES2015 class"),
9671
9672
  Convert_0_to_1_in_0: diag(95003, ts.DiagnosticCategory.Message, "Convert_0_to_1_in_0_95003", "Convert '{0}' to '{1} in {0}'"),
9672
9673
  Extract_to_0_in_1: diag(95004, ts.DiagnosticCategory.Message, "Extract_to_0_in_1_95004", "Extract to {0} in {1}"),
@@ -15096,6 +15097,15 @@ var ts;
15096
15097
  };
15097
15098
  }
15098
15099
  ts.createDiagnosticForFileFromMessageChain = createDiagnosticForFileFromMessageChain;
15100
+ function createDiagnosticMessageChainFromDiagnostic(diagnostic) {
15101
+ return typeof diagnostic.messageText === "string" ? {
15102
+ code: diagnostic.code,
15103
+ category: diagnostic.category,
15104
+ messageText: diagnostic.messageText,
15105
+ next: diagnostic.next,
15106
+ } : diagnostic.messageText;
15107
+ }
15108
+ ts.createDiagnosticMessageChainFromDiagnostic = createDiagnosticMessageChainFromDiagnostic;
15099
15109
  function createDiagnosticForRange(sourceFile, range, message) {
15100
15110
  return {
15101
15111
  file: sourceFile,
@@ -21056,6 +21066,59 @@ var ts;
21056
21066
  return !!(type.flags & 262144 /* TypeParameter */ && type.isThisType);
21057
21067
  }
21058
21068
  ts.isThisTypeParameter = isThisTypeParameter;
21069
+ function getNodeModulePathParts(fullPath) {
21070
+ // If fullPath can't be valid module file within node_modules, returns undefined.
21071
+ // Example of expected pattern: /base/path/node_modules/[@scope/otherpackage/@otherscope/node_modules/]package/[subdirectory/]file.js
21072
+ // Returns indices: ^ ^ ^ ^
21073
+ var topLevelNodeModulesIndex = 0;
21074
+ var topLevelPackageNameIndex = 0;
21075
+ var packageRootIndex = 0;
21076
+ var fileNameIndex = 0;
21077
+ var States;
21078
+ (function (States) {
21079
+ States[States["BeforeNodeModules"] = 0] = "BeforeNodeModules";
21080
+ States[States["NodeModules"] = 1] = "NodeModules";
21081
+ States[States["Scope"] = 2] = "Scope";
21082
+ States[States["PackageContent"] = 3] = "PackageContent";
21083
+ })(States || (States = {}));
21084
+ var partStart = 0;
21085
+ var partEnd = 0;
21086
+ var state = 0 /* BeforeNodeModules */;
21087
+ while (partEnd >= 0) {
21088
+ partStart = partEnd;
21089
+ partEnd = fullPath.indexOf("/", partStart + 1);
21090
+ switch (state) {
21091
+ case 0 /* BeforeNodeModules */:
21092
+ if (fullPath.indexOf(ts.nodeModulesPathPart, partStart) === partStart) {
21093
+ topLevelNodeModulesIndex = partStart;
21094
+ topLevelPackageNameIndex = partEnd;
21095
+ state = 1 /* NodeModules */;
21096
+ }
21097
+ break;
21098
+ case 1 /* NodeModules */:
21099
+ case 2 /* Scope */:
21100
+ if (state === 1 /* NodeModules */ && fullPath.charAt(partStart + 1) === "@") {
21101
+ state = 2 /* Scope */;
21102
+ }
21103
+ else {
21104
+ packageRootIndex = partEnd;
21105
+ state = 3 /* PackageContent */;
21106
+ }
21107
+ break;
21108
+ case 3 /* PackageContent */:
21109
+ if (fullPath.indexOf(ts.nodeModulesPathPart, partStart) === partStart) {
21110
+ state = 1 /* NodeModules */;
21111
+ }
21112
+ else {
21113
+ state = 3 /* PackageContent */;
21114
+ }
21115
+ break;
21116
+ }
21117
+ }
21118
+ fileNameIndex = partStart;
21119
+ return state > 1 /* NodeModules */ ? { topLevelNodeModulesIndex: topLevelNodeModulesIndex, topLevelPackageNameIndex: topLevelPackageNameIndex, packageRootIndex: packageRootIndex, fileNameIndex: fileNameIndex } : undefined;
21120
+ }
21121
+ ts.getNodeModulePathParts = getNodeModulePathParts;
21059
21122
  })(ts || (ts = {}));
21060
21123
  /* @internal */
21061
21124
  var ts;
@@ -48950,24 +49013,19 @@ var ts;
48950
49013
  error(errorLocation, ts.Diagnostics.Parameter_0_cannot_reference_identifier_1_declared_after_it, ts.declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name), ts.declarationNameToString(errorLocation));
48951
49014
  }
48952
49015
  }
48953
- if (result && errorLocation && meaning & 111551 /* Value */ && result.flags & 2097152 /* Alias */) {
48954
- checkSymbolUsageInExpressionContext(result, name, errorLocation);
49016
+ if (result && errorLocation && meaning & 111551 /* Value */ && result.flags & 2097152 /* Alias */ && !(result.flags & 111551 /* Value */) && !ts.isValidTypeOnlyAliasUseSite(errorLocation)) {
49017
+ var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result);
49018
+ if (typeOnlyDeclaration) {
49019
+ var message = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */
49020
+ ? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
49021
+ : ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
49022
+ var unescapedName = ts.unescapeLeadingUnderscores(name);
49023
+ addTypeOnlyDeclarationRelatedInfo(error(errorLocation, message, unescapedName), typeOnlyDeclaration, unescapedName);
49024
+ }
48955
49025
  }
48956
49026
  }
48957
49027
  return result;
48958
49028
  }
48959
- function checkSymbolUsageInExpressionContext(symbol, name, useSite) {
48960
- if (!ts.isValidTypeOnlyAliasUseSite(useSite)) {
48961
- var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(symbol);
48962
- if (typeOnlyDeclaration) {
48963
- var message = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */
48964
- ? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
48965
- : ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
48966
- var unescapedName = ts.unescapeLeadingUnderscores(name);
48967
- addTypeOnlyDeclarationRelatedInfo(error(useSite, message, unescapedName), typeOnlyDeclaration, unescapedName);
48968
- }
48969
- }
48970
- }
48971
49029
  function addTypeOnlyDeclarationRelatedInfo(diagnostic, typeOnlyDeclaration, unescapedName) {
48972
49030
  if (!typeOnlyDeclaration)
48973
49031
  return diagnostic;
@@ -52729,7 +52787,8 @@ var ts;
52729
52787
  includePrivateSymbol === null || includePrivateSymbol === void 0 ? void 0 : includePrivateSymbol(sym);
52730
52788
  }
52731
52789
  if (ts.isIdentifier(node)) {
52732
- var name = sym.flags & 262144 /* TypeParameter */ ? typeParameterToName(getDeclaredTypeOfSymbol(sym), context) : ts.factory.cloneNode(node);
52790
+ var type = getDeclaredTypeOfSymbol(sym);
52791
+ var name = sym.flags & 262144 /* TypeParameter */ && !isTypeSymbolAccessible(type.symbol, context.enclosingDeclaration) ? typeParameterToName(type, context) : ts.factory.cloneNode(node);
52733
52792
  name.symbol = sym; // for quickinfo, which uses identifier symbol information
52734
52793
  return { introducesError: introducesError, node: ts.setEmitFlags(ts.setOriginalNode(name, node), 16777216 /* NoAsciiEscaping */) };
52735
52794
  }
@@ -74621,7 +74680,7 @@ var ts;
74621
74680
  }
74622
74681
  var diags_3 = max > 1 ? allDiagnostics[minIndex] : ts.flatten(allDiagnostics);
74623
74682
  ts.Debug.assert(diags_3.length > 0, "No errors reported for 3 or fewer overload signatures");
74624
- var chain = ts.chainDiagnosticMessages(ts.map(diags_3, function (d) { return typeof d.messageText === "string" ? d : d.messageText; }), ts.Diagnostics.No_overload_matches_this_call);
74683
+ var chain = ts.chainDiagnosticMessages(ts.map(diags_3, ts.createDiagnosticMessageChainFromDiagnostic), ts.Diagnostics.No_overload_matches_this_call);
74625
74684
  // The below is a spread to guarantee we get a new (mutable) array - our `flatMap` helper tries to do "smart" optimizations where it reuses input
74626
74685
  // arrays and the emptyArray singleton where possible, which is decidedly not what we want while we're still constructing this diagnostic
74627
74686
  var related = __spreadArray([], ts.flatMap(diags_3, function (d) { return d.relatedInformation; }), true);
@@ -83000,16 +83059,15 @@ var ts;
83000
83059
  return ts.nodeIsMissing(expr) ? 0 : evaluateEnumMember(expr, getSymbolOfNode(member.parent), identifier.escapedText);
83001
83060
  case 206 /* ElementAccessExpression */:
83002
83061
  case 205 /* PropertyAccessExpression */:
83003
- var ex = expr;
83004
- if (isConstantMemberAccess(ex)) {
83005
- var type = getTypeOfExpression(ex.expression);
83062
+ if (isConstantMemberAccess(expr)) {
83063
+ var type = getTypeOfExpression(expr.expression);
83006
83064
  if (type.symbol && type.symbol.flags & 384 /* Enum */) {
83007
83065
  var name = void 0;
83008
- if (ex.kind === 205 /* PropertyAccessExpression */) {
83009
- name = ex.name.escapedText;
83066
+ if (expr.kind === 205 /* PropertyAccessExpression */) {
83067
+ name = expr.name.escapedText;
83010
83068
  }
83011
83069
  else {
83012
- name = ts.escapeLeadingUnderscores(ts.cast(ex.argumentExpression, ts.isLiteralExpression).text);
83070
+ name = ts.escapeLeadingUnderscores(ts.cast(expr.argumentExpression, ts.isLiteralExpression).text);
83013
83071
  }
83014
83072
  return evaluateEnumMember(expr, type.symbol, name);
83015
83073
  }
@@ -83037,6 +83095,10 @@ var ts;
83037
83095
  }
83038
83096
  }
83039
83097
  function isConstantMemberAccess(node) {
83098
+ var type = getTypeOfExpression(node);
83099
+ if (type === errorType) {
83100
+ return false;
83101
+ }
83040
83102
  return node.kind === 79 /* Identifier */ ||
83041
83103
  node.kind === 205 /* PropertyAccessExpression */ && isConstantMemberAccess(node.expression) ||
83042
83104
  node.kind === 206 /* ElementAccessExpression */ && isConstantMemberAccess(node.expression) &&
@@ -85860,7 +85922,7 @@ var ts;
85860
85922
  if (quickResult !== undefined) {
85861
85923
  return quickResult;
85862
85924
  }
85863
- var lastStatic, lastDeclare, lastAsync, lastReadonly, lastOverride;
85925
+ var lastStatic, lastDeclare, lastAsync, lastOverride;
85864
85926
  var flags = 0 /* None */;
85865
85927
  for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) {
85866
85928
  var modifier = _a[_i];
@@ -85964,7 +86026,6 @@ var ts;
85964
86026
  return grammarErrorOnNode(modifier, ts.Diagnostics.readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature);
85965
86027
  }
85966
86028
  flags |= 64 /* Readonly */;
85967
- lastReadonly = modifier;
85968
86029
  break;
85969
86030
  case 93 /* ExportKeyword */:
85970
86031
  if (flags & 1 /* Export */) {
@@ -86077,18 +86138,12 @@ var ts;
86077
86138
  if (flags & 32 /* Static */) {
86078
86139
  return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static");
86079
86140
  }
86080
- if (flags & 128 /* Abstract */) {
86081
- return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "abstract"); // TODO: GH#18217
86082
- }
86083
86141
  if (flags & 16384 /* Override */) {
86084
86142
  return grammarErrorOnNode(lastOverride, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "override"); // TODO: GH#18217
86085
86143
  }
86086
- else if (flags & 256 /* Async */) {
86144
+ if (flags & 256 /* Async */) {
86087
86145
  return grammarErrorOnNode(lastAsync, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async");
86088
86146
  }
86089
- else if (flags & 64 /* Readonly */) {
86090
- return grammarErrorOnNode(lastReadonly, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "readonly");
86091
- }
86092
86147
  return false;
86093
86148
  }
86094
86149
  else if ((node.kind === 265 /* ImportDeclaration */ || node.kind === 264 /* ImportEqualsDeclaration */) && flags & 2 /* Ambient */) {
@@ -120229,7 +120284,7 @@ var ts;
120229
120284
  if (!host.fileExists || !host.readFile) {
120230
120285
  return undefined;
120231
120286
  }
120232
- var parts = getNodeModulePathParts(path);
120287
+ var parts = ts.getNodeModulePathParts(path);
120233
120288
  if (!parts) {
120234
120289
  return undefined;
120235
120290
  }
@@ -120352,58 +120407,6 @@ var ts;
120352
120407
  }
120353
120408
  }
120354
120409
  }
120355
- function getNodeModulePathParts(fullPath) {
120356
- // If fullPath can't be valid module file within node_modules, returns undefined.
120357
- // Example of expected pattern: /base/path/node_modules/[@scope/otherpackage/@otherscope/node_modules/]package/[subdirectory/]file.js
120358
- // Returns indices: ^ ^ ^ ^
120359
- var topLevelNodeModulesIndex = 0;
120360
- var topLevelPackageNameIndex = 0;
120361
- var packageRootIndex = 0;
120362
- var fileNameIndex = 0;
120363
- var States;
120364
- (function (States) {
120365
- States[States["BeforeNodeModules"] = 0] = "BeforeNodeModules";
120366
- States[States["NodeModules"] = 1] = "NodeModules";
120367
- States[States["Scope"] = 2] = "Scope";
120368
- States[States["PackageContent"] = 3] = "PackageContent";
120369
- })(States || (States = {}));
120370
- var partStart = 0;
120371
- var partEnd = 0;
120372
- var state = 0 /* BeforeNodeModules */;
120373
- while (partEnd >= 0) {
120374
- partStart = partEnd;
120375
- partEnd = fullPath.indexOf("/", partStart + 1);
120376
- switch (state) {
120377
- case 0 /* BeforeNodeModules */:
120378
- if (fullPath.indexOf(ts.nodeModulesPathPart, partStart) === partStart) {
120379
- topLevelNodeModulesIndex = partStart;
120380
- topLevelPackageNameIndex = partEnd;
120381
- state = 1 /* NodeModules */;
120382
- }
120383
- break;
120384
- case 1 /* NodeModules */:
120385
- case 2 /* Scope */:
120386
- if (state === 1 /* NodeModules */ && fullPath.charAt(partStart + 1) === "@") {
120387
- state = 2 /* Scope */;
120388
- }
120389
- else {
120390
- packageRootIndex = partEnd;
120391
- state = 3 /* PackageContent */;
120392
- }
120393
- break;
120394
- case 3 /* PackageContent */:
120395
- if (fullPath.indexOf(ts.nodeModulesPathPart, partStart) === partStart) {
120396
- state = 1 /* NodeModules */;
120397
- }
120398
- else {
120399
- state = 3 /* PackageContent */;
120400
- }
120401
- break;
120402
- }
120403
- }
120404
- fileNameIndex = partStart;
120405
- return state > 1 /* NodeModules */ ? { topLevelNodeModulesIndex: topLevelNodeModulesIndex, topLevelPackageNameIndex: topLevelPackageNameIndex, packageRootIndex: packageRootIndex, fileNameIndex: fileNameIndex } : undefined;
120406
- }
120407
120410
  function getPathRelativeToRootDirs(path, rootDirs, getCanonicalFileName) {
120408
120411
  return ts.firstDefined(rootDirs, function (rootDir) {
120409
120412
  var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
@@ -127167,11 +127170,11 @@ var ts;
127167
127170
  return ts.isArray(valueOrArray) ? ts.first(valueOrArray) : valueOrArray;
127168
127171
  }
127169
127172
  ts.firstOrOnly = firstOrOnly;
127170
- function getNameForExportedSymbol(symbol, scriptTarget) {
127173
+ function getNameForExportedSymbol(symbol, scriptTarget, preferCapitalized) {
127171
127174
  if (!(symbol.flags & 33554432 /* Transient */) && (symbol.escapedName === "export=" /* ExportEquals */ || symbol.escapedName === "default" /* Default */)) {
127172
127175
  // Name of "export default foo;" is "foo". Name of "export default 0" is the filename converted to camelCase.
127173
127176
  return ts.firstDefined(symbol.declarations, function (d) { var _a; return ts.isExportAssignment(d) ? (_a = ts.tryCast(ts.skipOuterExpressions(d.expression), ts.isIdentifier)) === null || _a === void 0 ? void 0 : _a.text : undefined; })
127174
- || ts.codefix.moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget);
127177
+ || ts.codefix.moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget, !!preferCapitalized);
127175
127178
  }
127176
127179
  return symbol.name;
127177
127180
  }
@@ -127290,6 +127293,17 @@ var ts;
127290
127293
  var exportInfoId = 1;
127291
127294
  var exportInfo = ts.createMultiMap();
127292
127295
  var symbols = new ts.Map();
127296
+ /**
127297
+ * Key: node_modules package name (no @types).
127298
+ * Value: path to deepest node_modules folder seen that is
127299
+ * both visible to `usableByFileName` and contains the package.
127300
+ *
127301
+ * Later, we can see if a given SymbolExportInfo is shadowed by
127302
+ * a another installation of the same package in a deeper
127303
+ * node_modules folder by seeing if its path starts with the
127304
+ * value stored here.
127305
+ */
127306
+ var packages = new ts.Map();
127293
127307
  var usableByFileName;
127294
127308
  var cache = {
127295
127309
  isUsableByFile: function (importingFile) { return importingFile === usableByFileName; },
@@ -127299,11 +127313,32 @@ var ts;
127299
127313
  symbols.clear();
127300
127314
  usableByFileName = undefined;
127301
127315
  },
127302
- add: function (importingFile, symbol, symbolTableKey, moduleSymbol, moduleFile, exportKind, isFromPackageJson, scriptTarget, checker) {
127316
+ add: function (importingFile, symbol, symbolTableKey, moduleSymbol, moduleFile, exportKind, isFromPackageJson, checker) {
127303
127317
  if (importingFile !== usableByFileName) {
127304
127318
  cache.clear();
127305
127319
  usableByFileName = importingFile;
127306
127320
  }
127321
+ var packageName;
127322
+ if (moduleFile) {
127323
+ var nodeModulesPathParts = ts.getNodeModulePathParts(moduleFile.fileName);
127324
+ if (nodeModulesPathParts) {
127325
+ var topLevelNodeModulesIndex = nodeModulesPathParts.topLevelNodeModulesIndex, topLevelPackageNameIndex = nodeModulesPathParts.topLevelPackageNameIndex, packageRootIndex = nodeModulesPathParts.packageRootIndex;
127326
+ packageName = ts.unmangleScopedPackageName(ts.getPackageNameFromTypesPackageName(moduleFile.fileName.substring(topLevelPackageNameIndex + 1, packageRootIndex)));
127327
+ if (ts.startsWith(importingFile, moduleFile.path.substring(0, topLevelNodeModulesIndex))) {
127328
+ var prevDeepestNodeModulesPath = packages.get(packageName);
127329
+ var nodeModulesPath = moduleFile.fileName.substring(0, topLevelPackageNameIndex);
127330
+ if (prevDeepestNodeModulesPath) {
127331
+ var prevDeepestNodeModulesIndex = prevDeepestNodeModulesPath.indexOf(ts.nodeModulesPathPart);
127332
+ if (topLevelNodeModulesIndex > prevDeepestNodeModulesIndex) {
127333
+ packages.set(packageName, nodeModulesPath);
127334
+ }
127335
+ }
127336
+ else {
127337
+ packages.set(packageName, nodeModulesPath);
127338
+ }
127339
+ }
127340
+ }
127341
+ }
127307
127342
  var isDefault = exportKind === 1 /* Default */;
127308
127343
  var namedSymbol = isDefault && ts.getLocalSymbolForExportDefault(symbol) || symbol;
127309
127344
  // 1. A named export must be imported by its key in `moduleSymbol.exports` or `moduleSymbol.members`.
@@ -127315,7 +127350,7 @@ var ts;
127315
127350
  // get a better name.
127316
127351
  var importedName = exportKind === 0 /* Named */ || ts.isExternalModuleSymbol(namedSymbol)
127317
127352
  ? ts.unescapeLeadingUnderscores(symbolTableKey)
127318
- : ts.getNameForExportedSymbol(namedSymbol, scriptTarget);
127353
+ : ts.getNameForExportedSymbol(namedSymbol, /*scriptTarget*/ undefined);
127319
127354
  var moduleName = ts.stripQuotes(moduleSymbol.name);
127320
127355
  var id = exportInfoId++;
127321
127356
  var target = ts.skipAlias(symbol, checker);
@@ -127330,6 +127365,7 @@ var ts;
127330
127365
  moduleName: moduleName,
127331
127366
  moduleFile: moduleFile,
127332
127367
  moduleFileName: moduleFile === null || moduleFile === void 0 ? void 0 : moduleFile.fileName,
127368
+ packageName: packageName,
127333
127369
  exportKind: exportKind,
127334
127370
  targetFlags: target.flags,
127335
127371
  isFromPackageJson: isFromPackageJson,
@@ -127348,7 +127384,17 @@ var ts;
127348
127384
  return;
127349
127385
  exportInfo.forEach(function (info, key) {
127350
127386
  var _a = parseKey(key), symbolName = _a.symbolName, ambientModuleName = _a.ambientModuleName;
127351
- action(info.map(rehydrateCachedInfo), symbolName, !!ambientModuleName, key);
127387
+ var rehydrated = info.map(rehydrateCachedInfo);
127388
+ var filtered = rehydrated.filter(function (r, i) { return isNotShadowedByDeeperNodeModulesPackage(r, info[i].packageName); });
127389
+ if (filtered.length) {
127390
+ action(filtered, function (preferCapitalized) {
127391
+ var _a = rehydrated[0], symbol = _a.symbol, exportKind = _a.exportKind;
127392
+ var namedSymbol = exportKind === 1 /* Default */ && ts.getLocalSymbolForExportDefault(symbol) || symbol;
127393
+ return preferCapitalized
127394
+ ? ts.getNameForExportedSymbol(namedSymbol, /*scriptTarget*/ undefined, /*preferCapitalized*/ true)
127395
+ : symbolName;
127396
+ }, !!ambientModuleName, key);
127397
+ }
127352
127398
  });
127353
127399
  },
127354
127400
  releaseSymbols: function () {
@@ -127448,6 +127494,12 @@ var ts;
127448
127494
  }
127449
127495
  return true;
127450
127496
  }
127497
+ function isNotShadowedByDeeperNodeModulesPackage(info, packageName) {
127498
+ if (!packageName || !info.moduleFileName)
127499
+ return true;
127500
+ var packageDeepestNodeModulesPath = packages.get(packageName);
127501
+ return !packageDeepestNodeModulesPath || ts.startsWith(info.moduleFileName, packageDeepestNodeModulesPath);
127502
+ }
127451
127503
  }
127452
127504
  ts.createCacheableExportInfoMap = createCacheableExportInfoMap;
127453
127505
  function isImportableFile(program, from, to, preferences, packageJsonFilter, moduleSpecifierResolutionHost, moduleSpecifierCache) {
@@ -127530,7 +127582,6 @@ var ts;
127530
127582
  }
127531
127583
  (_d = host.log) === null || _d === void 0 ? void 0 : _d.call(host, "getExportInfoMap: cache miss or empty; calculating new results");
127532
127584
  var compilerOptions = program.getCompilerOptions();
127533
- var scriptTarget = ts.getEmitScriptTarget(compilerOptions);
127534
127585
  var moduleCount = 0;
127535
127586
  forEachExternalModuleToImportFrom(program, host, /*useAutoImportProvider*/ true, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
127536
127587
  if (++moduleCount % 100 === 0)
@@ -127541,11 +127592,11 @@ var ts;
127541
127592
  // Note: I think we shouldn't actually see resolved module symbols here, but weird merges
127542
127593
  // can cause it to happen: see 'completionsImport_mergedReExport.ts'
127543
127594
  if (defaultInfo && isImportableSymbol(defaultInfo.symbol, checker)) {
127544
- cache.add(importingFile.path, defaultInfo.symbol, defaultInfo.exportKind === 1 /* Default */ ? "default" /* Default */ : "export=" /* ExportEquals */, moduleSymbol, moduleFile, defaultInfo.exportKind, isFromPackageJson, scriptTarget, checker);
127595
+ cache.add(importingFile.path, defaultInfo.symbol, defaultInfo.exportKind === 1 /* Default */ ? "default" /* Default */ : "export=" /* ExportEquals */, moduleSymbol, moduleFile, defaultInfo.exportKind, isFromPackageJson, checker);
127545
127596
  }
127546
127597
  checker.forEachExportAndPropertyOfModule(moduleSymbol, function (exported, key) {
127547
127598
  if (exported !== (defaultInfo === null || defaultInfo === void 0 ? void 0 : defaultInfo.symbol) && isImportableSymbol(exported, checker) && ts.addToSeen(seenExports, key)) {
127548
- cache.add(importingFile.path, exported, key, moduleSymbol, moduleFile, 0 /* Named */, isFromPackageJson, scriptTarget, checker);
127599
+ cache.add(importingFile.path, exported, key, moduleSymbol, moduleFile, 0 /* Named */, isFromPackageJson, checker);
127549
127600
  }
127550
127601
  });
127551
127602
  });
@@ -129619,6 +129670,8 @@ var ts;
129619
129670
  CompletionSource["ThisProperty"] = "ThisProperty/";
129620
129671
  /** Auto-import that comes attached to a class member snippet */
129621
129672
  CompletionSource["ClassMemberSnippet"] = "ClassMemberSnippet/";
129673
+ /** A type-only import that needs to be promoted in order to be used at the completion location */
129674
+ CompletionSource["TypeOnlyAlias"] = "TypeOnlyAlias/";
129622
129675
  })(CompletionSource = Completions.CompletionSource || (Completions.CompletionSource = {}));
129623
129676
  var SymbolOriginInfoKind;
129624
129677
  (function (SymbolOriginInfoKind) {
@@ -129628,6 +129681,7 @@ var ts;
129628
129681
  SymbolOriginInfoKind[SymbolOriginInfoKind["Promise"] = 8] = "Promise";
129629
129682
  SymbolOriginInfoKind[SymbolOriginInfoKind["Nullable"] = 16] = "Nullable";
129630
129683
  SymbolOriginInfoKind[SymbolOriginInfoKind["ResolvedExport"] = 32] = "ResolvedExport";
129684
+ SymbolOriginInfoKind[SymbolOriginInfoKind["TypeOnlyAlias"] = 64] = "TypeOnlyAlias";
129631
129685
  SymbolOriginInfoKind[SymbolOriginInfoKind["SymbolMemberNoExport"] = 2] = "SymbolMemberNoExport";
129632
129686
  SymbolOriginInfoKind[SymbolOriginInfoKind["SymbolMemberExport"] = 6] = "SymbolMemberExport";
129633
129687
  })(SymbolOriginInfoKind || (SymbolOriginInfoKind = {}));
@@ -129655,6 +129709,9 @@ var ts;
129655
129709
  function originIsNullableMember(origin) {
129656
129710
  return !!(origin.kind & 16 /* Nullable */);
129657
129711
  }
129712
+ function originIsTypeOnlyAlias(origin) {
129713
+ return !!(origin && origin.kind & 64 /* TypeOnlyAlias */);
129714
+ }
129658
129715
  var KeywordCompletionFilters;
129659
129716
  (function (KeywordCompletionFilters) {
129660
129717
  KeywordCompletionFilters[KeywordCompletionFilters["None"] = 0] = "None";
@@ -129753,7 +129810,7 @@ var ts;
129753
129810
  }
129754
129811
  switch (completionData.kind) {
129755
129812
  case 0 /* Data */:
129756
- var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext);
129813
+ var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext, position);
129757
129814
  if (response === null || response === void 0 ? void 0 : response.isIncomplete) {
129758
129815
  incompleteCompletionsCache === null || incompleteCompletionsCache === void 0 ? void 0 : incompleteCompletionsCache.set(response);
129759
129816
  }
@@ -129873,7 +129930,7 @@ var ts;
129873
129930
  // StringLiteralLike locations are handled separately in stringCompletions.ts
129874
129931
  return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
129875
129932
  }
129876
- function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext) {
129933
+ function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext, position) {
129877
129934
  var symbols = completionData.symbols, contextToken = completionData.contextToken, completionKind = completionData.completionKind, isInSnippetScope = completionData.isInSnippetScope, isNewIdentifierLocation = completionData.isNewIdentifierLocation, location = completionData.location, propertyAccessToConvert = completionData.propertyAccessToConvert, keywordFilters = completionData.keywordFilters, literals = completionData.literals, symbolToOriginInfoMap = completionData.symbolToOriginInfoMap, recommendedCompletion = completionData.recommendedCompletion, isJsxInitializer = completionData.isJsxInitializer, isTypeOnlyLocation = completionData.isTypeOnlyLocation, isJsxIdentifierExpected = completionData.isJsxIdentifierExpected, isRightOfOpenTag = completionData.isRightOfOpenTag, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
129878
129935
  // Verify if the file is JSX language variant
129879
129936
  if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
@@ -129886,7 +129943,7 @@ var ts;
129886
129943
  if (isUncheckedFile(sourceFile, compilerOptions)) {
129887
129944
  var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
129888
129945
  /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
129889
- getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
129946
+ getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries);
129890
129947
  }
129891
129948
  else {
129892
129949
  if (!isNewIdentifierLocation && (!symbols || symbols.length === 0) && keywordFilters === 0 /* None */) {
@@ -129896,16 +129953,23 @@ var ts;
129896
129953
  /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
129897
129954
  }
129898
129955
  if (keywordFilters !== 0 /* None */) {
129899
- var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
129956
+ var entryNames_1 = new ts.Set(entries.map(function (e) { return e.name; }));
129900
129957
  for (var _i = 0, _a = getKeywordCompletions(keywordFilters, !insideJsDocTagTypeExpression && ts.isSourceFileJS(sourceFile)); _i < _a.length; _i++) {
129901
129958
  var keywordEntry = _a[_i];
129902
- if (!entryNames.has(keywordEntry.name)) {
129959
+ if (!entryNames_1.has(keywordEntry.name)) {
129903
129960
  ts.insertSorted(entries, keywordEntry, compareCompletionEntries, /*allowDuplicates*/ true);
129904
129961
  }
129905
129962
  }
129906
129963
  }
129907
- for (var _b = 0, literals_1 = literals; _b < literals_1.length; _b++) {
129908
- var literal = literals_1[_b];
129964
+ var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
129965
+ for (var _b = 0, _c = getContextualKeywords(contextToken, position); _b < _c.length; _b++) {
129966
+ var keywordEntry = _c[_b];
129967
+ if (!entryNames.has(keywordEntry.name)) {
129968
+ ts.insertSorted(entries, keywordEntry, compareCompletionEntries, /*allowDuplicates*/ true);
129969
+ }
129970
+ }
129971
+ for (var _d = 0, literals_1 = literals; _d < literals_1.length; _d++) {
129972
+ var literal = literals_1[_d];
129909
129973
  ts.insertSorted(entries, createCompletionEntryForLiteral(sourceFile, preferences, literal), compareCompletionEntries, /*allowDuplicates*/ true);
129910
129974
  }
129911
129975
  return {
@@ -130059,6 +130123,9 @@ var ts;
130059
130123
  isSnippet = preferences.includeCompletionsWithSnippetText ? true : undefined;
130060
130124
  }
130061
130125
  }
130126
+ if ((origin === null || origin === void 0 ? void 0 : origin.kind) === 64 /* TypeOnlyAlias */) {
130127
+ hasAction = true;
130128
+ }
130062
130129
  if (preferences.includeCompletionsWithClassMemberSnippets &&
130063
130130
  preferences.includeCompletionsWithInsertText &&
130064
130131
  completionKind === 3 /* MemberLike */ &&
@@ -130403,6 +130470,9 @@ var ts;
130403
130470
  if ((origin === null || origin === void 0 ? void 0 : origin.kind) === 1 /* ThisType */) {
130404
130471
  return CompletionSource.ThisProperty;
130405
130472
  }
130473
+ if ((origin === null || origin === void 0 ? void 0 : origin.kind) === 64 /* TypeOnlyAlias */) {
130474
+ return CompletionSource.TypeOnlyAlias;
130475
+ }
130406
130476
  }
130407
130477
  function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, formatContext, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag) {
130408
130478
  var _a;
@@ -130430,7 +130500,7 @@ var ts;
130430
130500
  continue;
130431
130501
  }
130432
130502
  /** True for locals; false for globals, module exports from other files, `this.` completions. */
130433
- var shouldShadowLaterSymbols = !origin && !(symbol.parent === undefined && !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === location.getSourceFile(); }));
130503
+ var shouldShadowLaterSymbols = (!origin || originIsTypeOnlyAlias(origin)) && !(symbol.parent === undefined && !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === location.getSourceFile(); }));
130434
130504
  uniques.set(name, shouldShadowLaterSymbols);
130435
130505
  ts.insertSorted(entries, entry, compareCompletionEntries, /*allowDuplicates*/ true);
130436
130506
  }
@@ -130443,6 +130513,7 @@ var ts;
130443
130513
  add: function (name) { return uniques.set(name, true); },
130444
130514
  };
130445
130515
  function shouldIncludeSymbol(symbol, symbolToSortTextIdMap) {
130516
+ var allFlags = symbol.flags;
130446
130517
  if (!ts.isSourceFile(location)) {
130447
130518
  // export = /**/ here we want to get all meanings, so any symbol is ok
130448
130519
  if (ts.isExportAssignment(location.parent)) {
@@ -130468,11 +130539,10 @@ var ts;
130468
130539
  || symbolToSortTextIdMap[ts.getSymbolId(symbolOrigin)] === 11 /* LocationPriority */)) {
130469
130540
  return false;
130470
130541
  }
130471
- // Continue with origin symbol
130472
- symbol = symbolOrigin;
130542
+ allFlags |= ts.getCombinedLocalAndExportSymbolFlags(symbolOrigin);
130473
130543
  // import m = /**/ <-- It can only access namespace (if typing import = x. this would get member symbols and not namespace)
130474
130544
  if (ts.isInRightSideOfInternalImportEqualsDeclaration(location)) {
130475
- return !!(symbol.flags & 1920 /* Namespace */);
130545
+ return !!(allFlags & 1920 /* Namespace */);
130476
130546
  }
130477
130547
  if (isTypeOnlyLocation) {
130478
130548
  // It's a type, but you can reach it by namespace.type as well
@@ -130480,7 +130550,7 @@ var ts;
130480
130550
  }
130481
130551
  }
130482
130552
  // expressions are value space (which includes the value namespaces)
130483
- return !!(ts.getCombinedLocalAndExportSymbolFlags(symbol) & 111551 /* Value */);
130553
+ return !!(allFlags & 111551 /* Value */);
130484
130554
  }
130485
130555
  }
130486
130556
  Completions.getCompletionEntriesFromSymbols = getCompletionEntriesFromSymbols;
@@ -130614,8 +130684,7 @@ var ts;
130614
130684
  Completions.createCompletionDetails = createCompletionDetails;
130615
130685
  function getCompletionEntryCodeActionsAndSourceDisplay(name, location, contextToken, origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, data, source) {
130616
130686
  if (data === null || data === void 0 ? void 0 : data.moduleSpecifier) {
130617
- var _a = getRelevantTokens(position, sourceFile), contextToken_3 = _a.contextToken, previousToken_2 = _a.previousToken;
130618
- if (previousToken_2 && getImportStatementCompletionInfo(contextToken_3 || previousToken_2).replacementNode) {
130687
+ if (previousToken && getImportStatementCompletionInfo(contextToken || previousToken).replacementNode) {
130619
130688
  // Import statement completion: 'import c|'
130620
130689
  return { codeActions: undefined, sourceDisplay: [ts.textPart(data.moduleSpecifier)] };
130621
130690
  }
@@ -130633,13 +130702,19 @@ var ts;
130633
130702
  };
130634
130703
  }
130635
130704
  }
130705
+ if (originIsTypeOnlyAlias(origin)) {
130706
+ var codeAction_1 = ts.codefix.getPromoteTypeOnlyCompletionAction(sourceFile, origin.declaration.name, program, host, formatContext, preferences);
130707
+ ts.Debug.assertIsDefined(codeAction_1, "Expected to have a code action for promoting type-only alias");
130708
+ return { codeActions: [codeAction_1], sourceDisplay: undefined };
130709
+ }
130636
130710
  if (!origin || !(originIsExport(origin) || originIsResolvedExport(origin))) {
130637
130711
  return { codeActions: undefined, sourceDisplay: undefined };
130638
130712
  }
130639
130713
  var checker = origin.isFromPackageJson ? host.getPackageJsonAutoImportProvider().getTypeChecker() : program.getTypeChecker();
130640
130714
  var moduleSymbol = origin.moduleSymbol;
130641
130715
  var targetSymbol = checker.getMergedSymbol(ts.skipAlias(symbol.exportSymbol || symbol, checker));
130642
- var _b = ts.codefix.getImportCompletionAction(targetSymbol, moduleSymbol, sourceFile, ts.getNameForExportedSymbol(symbol, ts.getEmitScriptTarget(compilerOptions)), host, program, formatContext, previousToken && ts.isIdentifier(previousToken) ? previousToken.getStart(sourceFile) : position, preferences), moduleSpecifier = _b.moduleSpecifier, codeAction = _b.codeAction;
130716
+ var isJsxOpeningTagName = (contextToken === null || contextToken === void 0 ? void 0 : contextToken.kind) === 29 /* LessThanToken */ && ts.isJsxOpeningLikeElement(contextToken.parent);
130717
+ var _a = ts.codefix.getImportCompletionAction(targetSymbol, moduleSymbol, sourceFile, ts.getNameForExportedSymbol(symbol, ts.getEmitScriptTarget(compilerOptions), isJsxOpeningTagName), isJsxOpeningTagName, host, program, formatContext, previousToken && ts.isIdentifier(previousToken) ? previousToken.getStart(sourceFile) : position, preferences), moduleSpecifier = _a.moduleSpecifier, codeAction = _a.codeAction;
130643
130718
  ts.Debug.assert(!(data === null || data === void 0 ? void 0 : data.moduleSpecifier) || moduleSpecifier === data.moduleSpecifier);
130644
130719
  return { sourceDisplay: [ts.textPart(moduleSpecifier)], codeActions: [codeAction] };
130645
130720
  }
@@ -131309,21 +131384,29 @@ var ts;
131309
131384
  var scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile;
131310
131385
  isInSnippetScope = isSnippetScope(scopeNode);
131311
131386
  var symbolMeanings = (isTypeOnlyLocation ? 0 /* None */ : 111551 /* Value */) | 788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */;
131387
+ var typeOnlyAliasNeedsPromotion = previousToken && !ts.isValidTypeOnlyAliasUseSite(previousToken);
131312
131388
  symbols = ts.concatenate(symbols, typeChecker.getSymbolsInScope(scopeNode, symbolMeanings));
131313
131389
  ts.Debug.assertEachIsDefined(symbols, "getSymbolsInScope() should all be defined");
131314
- for (var _i = 0, symbols_1 = symbols; _i < symbols_1.length; _i++) {
131315
- var symbol = symbols_1[_i];
131390
+ for (var i = 0; i < symbols.length; i++) {
131391
+ var symbol = symbols[i];
131316
131392
  if (!typeChecker.isArgumentsSymbol(symbol) &&
131317
131393
  !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === sourceFile; })) {
131318
131394
  symbolToSortTextIdMap[ts.getSymbolId(symbol)] = 15 /* GlobalsOrKeywords */;
131319
131395
  }
131396
+ if (typeOnlyAliasNeedsPromotion && !(symbol.flags & 111551 /* Value */)) {
131397
+ var typeOnlyAliasDeclaration = symbol.declarations && ts.find(symbol.declarations, ts.isTypeOnlyImportOrExportDeclaration);
131398
+ if (typeOnlyAliasDeclaration) {
131399
+ var origin = { kind: 64 /* TypeOnlyAlias */, declaration: typeOnlyAliasDeclaration };
131400
+ symbolToOriginInfoMap[i] = origin;
131401
+ }
131402
+ }
131320
131403
  }
131321
131404
  // Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions`
131322
131405
  if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== 303 /* SourceFile */) {
131323
131406
  var thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false);
131324
131407
  if (thisType && !isProbablyGlobalType(thisType, sourceFile, typeChecker)) {
131325
- for (var _a = 0, _b = getPropertiesForCompletion(thisType, typeChecker); _a < _b.length; _a++) {
131326
- var symbol = _b[_a];
131408
+ for (var _i = 0, _a = getPropertiesForCompletion(thisType, typeChecker); _i < _a.length; _i++) {
131409
+ var symbol = _a[_i];
131327
131410
  symbolToOriginInfoMap[symbols.length] = { kind: 1 /* ThisType */ };
131328
131411
  symbols.push(symbol);
131329
131412
  symbolToSortTextIdMap[ts.getSymbolId(symbol)] = 14 /* SuggestedClassMembers */;
@@ -131426,7 +131509,8 @@ var ts;
131426
131509
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
131427
131510
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
131428
131511
  resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, preferences, !!importCompletionNode, function (context) {
131429
- exportInfo.forEach(sourceFile.path, function (info, symbolName, isFromAmbientModule, exportMapKey) {
131512
+ exportInfo.forEach(sourceFile.path, function (info, getSymbolName, isFromAmbientModule, exportMapKey) {
131513
+ var symbolName = getSymbolName(/*preferCapitalized*/ isRightOfOpenTag);
131430
131514
  if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
131431
131515
  return;
131432
131516
  if (!detailsEntryId && ts.isStringANonContextualKeyword(symbolName))
@@ -131436,6 +131520,10 @@ var ts;
131436
131520
  return;
131437
131521
  if (isTypeOnlyLocation && !(info[0].targetFlags & (1536 /* Module */ | 788968 /* Type */)))
131438
131522
  return;
131523
+ // Do not try to auto-import something with a lowercase first letter for a JSX tag
131524
+ var firstChar = symbolName.charCodeAt(0);
131525
+ if (isRightOfOpenTag && (firstChar < 65 /* A */ || firstChar > 90 /* Z */))
131526
+ return;
131439
131527
  var isCompletionDetailsMatch = detailsEntryId && ts.some(info, function (i) { return detailsEntryId.source === ts.stripQuotes(i.moduleSymbol.name); });
131440
131528
  if (isCompletionDetailsMatch || !detailsEntryId && charactersFuzzyMatchInString(symbolName, lowerCaseTokenText)) {
131441
131529
  var defaultExportInfo = ts.find(info, isImportableExportInfo);
@@ -131512,16 +131600,19 @@ var ts;
131512
131600
  return true;
131513
131601
  }
131514
131602
  if (contextToken.kind === 31 /* GreaterThanToken */ && contextToken.parent) {
131603
+ // <Component<string> /**/ />
131604
+ // <Component<string> /**/ ><Component>
131605
+ // - contextToken: GreaterThanToken (before cursor)
131606
+ // - location: JsxSelfClosingElement or JsxOpeningElement
131607
+ // - contextToken.parent === location
131608
+ if (location === contextToken.parent && (location.kind === 279 /* JsxOpeningElement */ || location.kind === 278 /* JsxSelfClosingElement */)) {
131609
+ return false;
131610
+ }
131515
131611
  if (contextToken.parent.kind === 279 /* JsxOpeningElement */) {
131516
- // Two possibilities:
131517
- // 1. <div>/**/
131518
- // - contextToken: GreaterThanToken (before cursor)
131519
- // - location: JSXElement
131520
- // - different parents (JSXOpeningElement, JSXElement)
131521
- // 2. <Component<string> /**/>
131522
- // - contextToken: GreaterThanToken (before cursor)
131523
- // - location: GreaterThanToken (after cursor)
131524
- // - same parent (JSXOpeningElement)
131612
+ // <div>/**/
131613
+ // - contextToken: GreaterThanToken (before cursor)
131614
+ // - location: JSXElement
131615
+ // - different parents (JSXOpeningElement, JSXElement)
131525
131616
  return location.parent.kind !== 279 /* JsxOpeningElement */;
131526
131617
  }
131527
131618
  if (contextToken.parent.kind === 280 /* JsxClosingElement */ || contextToken.parent.kind === 278 /* JsxSelfClosingElement */) {
@@ -132428,6 +132519,34 @@ var ts;
132428
132519
  function keywordForNode(node) {
132429
132520
  return ts.isIdentifier(node) ? node.originalKeywordKind || 0 /* Unknown */ : node.kind;
132430
132521
  }
132522
+ function getContextualKeywords(contextToken, position) {
132523
+ var entries = [];
132524
+ /**
132525
+ * An `AssertClause` can come after an import declaration:
132526
+ * import * from "foo" |
132527
+ * import "foo" |
132528
+ * or after a re-export declaration that has a module specifier:
132529
+ * export { foo } from "foo" |
132530
+ * Source: https://tc39.es/proposal-import-assertions/
132531
+ */
132532
+ if (contextToken) {
132533
+ var file = contextToken.getSourceFile();
132534
+ var parent = contextToken.parent;
132535
+ var tokenLine = file.getLineAndCharacterOfPosition(contextToken.end).line;
132536
+ var currentLine = file.getLineAndCharacterOfPosition(position).line;
132537
+ if ((ts.isImportDeclaration(parent) || ts.isExportDeclaration(parent) && parent.moduleSpecifier)
132538
+ && contextToken === parent.moduleSpecifier
132539
+ && tokenLine === currentLine) {
132540
+ entries.push({
132541
+ name: ts.tokenToString(129 /* AssertKeyword */),
132542
+ kind: "keyword" /* keyword */,
132543
+ kindModifiers: "" /* none */,
132544
+ sortText: SortText.GlobalsOrKeywords,
132545
+ });
132546
+ }
132547
+ }
132548
+ return entries;
132549
+ }
132431
132550
  /** Get the corresponding JSDocTag node if the position is in a jsDoc comment */
132432
132551
  function getJsDocTagAtPosition(node, position) {
132433
132552
  return ts.findAncestor(node, function (n) {
@@ -132722,10 +132841,14 @@ var ts;
132722
132841
  /** True if symbol is a type or a module containing at least one type. */
132723
132842
  function symbolCanBeReferencedAtTypeLocation(symbol, checker, seenModules) {
132724
132843
  if (seenModules === void 0) { seenModules = new ts.Map(); }
132725
- var sym = ts.skipAlias(symbol.exportSymbol || symbol, checker);
132726
- return !!(sym.flags & 788968 /* Type */) || checker.isUnknownSymbol(sym) ||
132727
- !!(sym.flags & 1536 /* Module */) && ts.addToSeen(seenModules, ts.getSymbolId(sym)) &&
132728
- checker.getExportsOfModule(sym).some(function (e) { return symbolCanBeReferencedAtTypeLocation(e, checker, seenModules); });
132844
+ // Since an alias can be merged with a local declaration, we need to test both the alias and its target.
132845
+ // This code used to just test the result of `skipAlias`, but that would ignore any locally introduced meanings.
132846
+ return nonAliasCanBeReferencedAtTypeLocation(symbol) || nonAliasCanBeReferencedAtTypeLocation(ts.skipAlias(symbol.exportSymbol || symbol, checker));
132847
+ function nonAliasCanBeReferencedAtTypeLocation(symbol) {
132848
+ return !!(symbol.flags & 788968 /* Type */) || checker.isUnknownSymbol(symbol) ||
132849
+ !!(symbol.flags & 1536 /* Module */) && ts.addToSeen(seenModules, ts.getSymbolId(symbol)) &&
132850
+ checker.getExportsOfModule(symbol).some(function (e) { return symbolCanBeReferencedAtTypeLocation(e, checker, seenModules); });
132851
+ }
132729
132852
  }
132730
132853
  function isDeprecated(symbol, checker) {
132731
132854
  var declarations = ts.skipAlias(symbol, checker).declarations;
@@ -134979,8 +135102,8 @@ var ts;
134979
135102
  var sourceId = ts.getNodeId(sourceFile);
134980
135103
  var seenSymbols = this.sourceFileToSeenSymbols[sourceId] || (this.sourceFileToSeenSymbols[sourceId] = new ts.Set());
134981
135104
  var anyNewSymbols = false;
134982
- for (var _i = 0, symbols_2 = symbols; _i < symbols_2.length; _i++) {
134983
- var sym = symbols_2[_i];
135105
+ for (var _i = 0, symbols_1 = symbols; _i < symbols_1.length; _i++) {
135106
+ var sym = symbols_1[_i];
134984
135107
  anyNewSymbols = ts.tryAddToSet(seenSymbols, ts.getSymbolId(sym)) || anyNewSymbols;
134985
135108
  }
134986
135109
  return anyNewSymbols;
@@ -145851,6 +145974,7 @@ var ts;
145851
145974
  ChangeTracker.prototype.delete = function (sourceFile, node) {
145852
145975
  this.deletedNodes.push({ sourceFile: sourceFile, node: node });
145853
145976
  };
145977
+ /** Stop! Consider using `delete` instead, which has logic for deleting nodes from delimited lists. */
145854
145978
  ChangeTracker.prototype.deleteNode = function (sourceFile, node, options) {
145855
145979
  if (options === void 0) { options = { leadingTriviaOption: LeadingTriviaOption.IncludeAll }; }
145856
145980
  this.deleteRange(sourceFile, getAdjustedRange(sourceFile, node, node, options));
@@ -146254,6 +146378,15 @@ var ts;
146254
146378
  ChangeTracker.prototype.insertExportModifier = function (sourceFile, node) {
146255
146379
  this.insertText(sourceFile, node.getStart(sourceFile), "export ");
146256
146380
  };
146381
+ ChangeTracker.prototype.insertImportSpecifierAtIndex = function (sourceFile, importSpecifier, namedImports, index) {
146382
+ var prevSpecifier = namedImports.elements[index - 1];
146383
+ if (prevSpecifier) {
146384
+ this.insertNodeInListAfter(sourceFile, prevSpecifier, importSpecifier);
146385
+ }
146386
+ else {
146387
+ this.insertNodeBefore(sourceFile, namedImports.elements[0], importSpecifier, !ts.positionsAreOnSameLine(namedImports.elements[0].getStart(), namedImports.parent.parent.getStart(), sourceFile));
146388
+ }
146389
+ };
146257
146390
  /**
146258
146391
  * This function should be used to insert nodes in lists when nodes don't carry separators as the part of the node range,
146259
146392
  * i.e. arguments in arguments lists, parameters in parameter lists etc.
@@ -149756,7 +149889,8 @@ var ts;
149756
149889
  ts.Diagnostics.Cannot_find_namespace_0.code,
149757
149890
  ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code,
149758
149891
  ts.Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here.code,
149759
- ts.Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer.code
149892
+ ts.Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer.code,
149893
+ ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type.code,
149760
149894
  ];
149761
149895
  codefix.registerCodeFix({
149762
149896
  errorCodes: errorCodes,
@@ -149765,9 +149899,10 @@ var ts;
149765
149899
  var info = getFixesInfo(context, errorCode, span.start, /*useAutoImportProvider*/ true);
149766
149900
  if (!info)
149767
149901
  return undefined;
149768
- var fixes = info.fixes, symbolName = info.symbolName;
149902
+ var fixes = info.fixes, symbolName = info.symbolName, errorIdentifierText = info.errorIdentifierText;
149769
149903
  var quotePreference = ts.getQuotePreference(sourceFile, preferences);
149770
- return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, program.getCompilerOptions()); });
149904
+ return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix,
149905
+ /*includeSymbolNameInDescription*/ symbolName !== errorIdentifierText, quotePreference, program.getCompilerOptions()); });
149771
149906
  },
149772
149907
  fixIds: [importFixId],
149773
149908
  getAllCodeActions: function (context) {
@@ -149802,11 +149937,11 @@ var ts;
149802
149937
  var symbolName = ts.getNameForExportedSymbol(exportedSymbol, ts.getEmitScriptTarget(compilerOptions));
149803
149938
  var checker = program.getTypeChecker();
149804
149939
  var symbol = checker.getMergedSymbol(ts.skipAlias(exportedSymbol, checker));
149805
- var exportInfos = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, host, program, preferences, useAutoImportProvider);
149940
+ var exportInfos = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, /*isJsxTagName*/ false, host, program, preferences, useAutoImportProvider);
149806
149941
  var useRequire = shouldUseRequire(sourceFile, program);
149807
149942
  var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
149808
149943
  if (fix) {
149809
- addImport({ fixes: [fix], symbolName: symbolName });
149944
+ addImport({ fixes: [fix], symbolName: symbolName, errorIdentifierText: undefined });
149810
149945
  }
149811
149946
  }
149812
149947
  function addImport(info) {
@@ -149861,6 +149996,9 @@ var ts;
149861
149996
  }
149862
149997
  break;
149863
149998
  }
149999
+ case 4 /* PromoteTypeOnly */:
150000
+ // Excluding from fix-all
150001
+ break;
149864
150002
  default:
149865
150003
  ts.Debug.assertNever(fix, "fix wasn't never - got kind " + fix.kind);
149866
150004
  }
@@ -149952,6 +150090,7 @@ var ts;
149952
150090
  ImportFixKind[ImportFixKind["JsdocTypeImport"] = 1] = "JsdocTypeImport";
149953
150091
  ImportFixKind[ImportFixKind["AddToExisting"] = 2] = "AddToExisting";
149954
150092
  ImportFixKind[ImportFixKind["AddNew"] = 3] = "AddNew";
150093
+ ImportFixKind[ImportFixKind["PromoteTypeOnly"] = 4] = "PromoteTypeOnly";
149955
150094
  })(ImportFixKind || (ImportFixKind = {}));
149956
150095
  // These should not be combined as bitflags, but are given powers of 2 values to
149957
150096
  // easily detect conflicts between `NotAllowed` and `Required` by giving them a unique sum.
@@ -149963,20 +150102,29 @@ var ts;
149963
150102
  AddAsTypeOnly[AddAsTypeOnly["Required"] = 2] = "Required";
149964
150103
  AddAsTypeOnly[AddAsTypeOnly["NotAllowed"] = 4] = "NotAllowed";
149965
150104
  })(AddAsTypeOnly || (AddAsTypeOnly = {}));
149966
- function getImportCompletionAction(targetSymbol, moduleSymbol, sourceFile, symbolName, host, program, formatContext, position, preferences) {
150105
+ function getImportCompletionAction(targetSymbol, moduleSymbol, sourceFile, symbolName, isJsxTagName, host, program, formatContext, position, preferences) {
149967
150106
  var compilerOptions = program.getCompilerOptions();
149968
150107
  var exportInfos = ts.pathIsBareSpecifier(ts.stripQuotes(moduleSymbol.name))
149969
150108
  ? [getSymbolExportInfoForSymbol(targetSymbol, moduleSymbol, program, host)]
149970
- : getAllReExportingModules(sourceFile, targetSymbol, moduleSymbol, symbolName, host, program, preferences, /*useAutoImportProvider*/ true);
150109
+ : getAllReExportingModules(sourceFile, targetSymbol, moduleSymbol, symbolName, isJsxTagName, host, program, preferences, /*useAutoImportProvider*/ true);
149971
150110
  var useRequire = shouldUseRequire(sourceFile, program);
149972
150111
  var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
149973
150112
  var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences));
149974
150113
  return {
149975
150114
  moduleSpecifier: fix.moduleSpecifier,
149976
- codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, ts.getQuotePreference(sourceFile, preferences), compilerOptions))
150115
+ codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix,
150116
+ /*includeSymbolNameInDescription*/ false, ts.getQuotePreference(sourceFile, preferences), compilerOptions))
149977
150117
  };
149978
150118
  }
149979
150119
  codefix.getImportCompletionAction = getImportCompletionAction;
150120
+ function getPromoteTypeOnlyCompletionAction(sourceFile, symbolToken, program, host, formatContext, preferences) {
150121
+ var compilerOptions = program.getCompilerOptions();
150122
+ var symbolName = getSymbolName(sourceFile, program.getTypeChecker(), symbolToken, compilerOptions);
150123
+ var fix = getTypeOnlyPromotionFix(sourceFile, symbolToken, symbolName, program);
150124
+ var includeSymbolNameInDescription = symbolName !== symbolToken.text;
150125
+ return fix && codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, includeSymbolNameInDescription, 1 /* Double */, compilerOptions));
150126
+ }
150127
+ codefix.getPromoteTypeOnlyCompletionAction = getPromoteTypeOnlyCompletionAction;
149980
150128
  function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
149981
150129
  ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
149982
150130
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
@@ -150006,7 +150154,7 @@ var ts;
150006
150154
  }
150007
150155
  }
150008
150156
  }
150009
- function getAllReExportingModules(importingFile, targetSymbol, exportingModuleSymbol, symbolName, host, program, preferences, useAutoImportProvider) {
150157
+ function getAllReExportingModules(importingFile, targetSymbol, exportingModuleSymbol, symbolName, isJsxTagName, host, program, preferences, useAutoImportProvider) {
150010
150158
  var result = [];
150011
150159
  var compilerOptions = program.getCompilerOptions();
150012
150160
  var getModuleSpecifierResolutionHost = ts.memoizeOne(function (isFromPackageJson) {
@@ -150019,7 +150167,7 @@ var ts;
150019
150167
  return;
150020
150168
  }
150021
150169
  var defaultInfo = ts.getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
150022
- if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions)) === symbolName) && ts.skipAlias(defaultInfo.symbol, checker) === targetSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
150170
+ if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions), isJsxTagName) === symbolName) && ts.skipAlias(defaultInfo.symbol, checker) === targetSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
150023
150171
  result.push({ symbol: defaultInfo.symbol, moduleSymbol: moduleSymbol, moduleFileName: moduleFile === null || moduleFile === void 0 ? void 0 : moduleFile.fileName, exportKind: defaultInfo.exportKind, targetFlags: ts.skipAlias(defaultInfo.symbol, checker).flags, isFromPackageJson: isFromPackageJson });
150024
150172
  }
150025
150173
  for (var _i = 0, _a = checker.getExportsAndPropertiesOfModule(moduleSymbol); _i < _a.length; _i++) {
@@ -150257,9 +150405,21 @@ var ts;
150257
150405
  }
150258
150406
  function getFixesInfo(context, errorCode, pos, useAutoImportProvider) {
150259
150407
  var symbolToken = ts.getTokenAtPosition(context.sourceFile, pos);
150260
- var info = errorCode === ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code
150261
- ? getFixesInfoForUMDImport(context, symbolToken)
150262
- : ts.isIdentifier(symbolToken) ? getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider) : undefined;
150408
+ var info;
150409
+ if (errorCode === ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code) {
150410
+ info = getFixesInfoForUMDImport(context, symbolToken);
150411
+ }
150412
+ else if (!ts.isIdentifier(symbolToken)) {
150413
+ return undefined;
150414
+ }
150415
+ else if (errorCode === ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type.code) {
150416
+ var symbolName_1 = getSymbolName(context.sourceFile, context.program.getTypeChecker(), symbolToken, context.program.getCompilerOptions());
150417
+ var fix = getTypeOnlyPromotionFix(context.sourceFile, symbolToken, symbolName_1, context.program);
150418
+ return fix && { fixes: [fix], symbolName: symbolName_1, errorIdentifierText: symbolToken.text };
150419
+ }
150420
+ else {
150421
+ info = getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider);
150422
+ }
150263
150423
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(context.sourceFile, context.preferences, context.host);
150264
150424
  return info && __assign(__assign({}, info), { fixes: sortFixes(info.fixes, context.sourceFile, context.program, packageJsonImportFilter) });
150265
150425
  }
@@ -150300,6 +150460,7 @@ var ts;
150300
150460
  return 0 /* EqualTo */;
150301
150461
  }
150302
150462
  function getFixesInfoForUMDImport(_a, token) {
150463
+ var _b;
150303
150464
  var sourceFile = _a.sourceFile, program = _a.program, host = _a.host, preferences = _a.preferences;
150304
150465
  var checker = program.getTypeChecker();
150305
150466
  var umdSymbol = getUmdSymbol(token, checker);
@@ -150310,7 +150471,7 @@ var ts;
150310
150471
  var exportInfos = [{ symbol: umdSymbol, moduleSymbol: symbol, moduleFileName: undefined, exportKind: 3 /* UMD */, targetFlags: symbol.flags, isFromPackageJson: false }];
150311
150472
  var useRequire = shouldUseRequire(sourceFile, program);
150312
150473
  var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences);
150313
- return { fixes: fixes, symbolName: symbolName };
150474
+ return { fixes: fixes, symbolName: symbolName, errorIdentifierText: (_b = ts.tryCast(token, ts.isIdentifier)) === null || _b === void 0 ? void 0 : _b.text };
150314
150475
  }
150315
150476
  function getUmdSymbol(token, checker) {
150316
150477
  // try the identifier to see if it is the umd symbol
@@ -150376,12 +150537,22 @@ var ts;
150376
150537
  ts.Debug.assert(symbolName !== "default" /* Default */, "'default' isn't a legal identifier and couldn't occur here");
150377
150538
  var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(symbolToken);
150378
150539
  var useRequire = shouldUseRequire(sourceFile, program);
150379
- var exportInfos = getExportInfos(symbolName, ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
150540
+ var exportInfos = getExportInfos(symbolName, ts.isJSXTagName(symbolToken), ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
150380
150541
  var fixes = ts.arrayFrom(ts.flatMapIterator(exportInfos.entries(), function (_a) {
150381
150542
  var _ = _a[0], exportInfos = _a[1];
150382
150543
  return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences);
150383
150544
  }));
150384
- return { fixes: fixes, symbolName: symbolName };
150545
+ return { fixes: fixes, symbolName: symbolName, errorIdentifierText: symbolToken.text };
150546
+ }
150547
+ function getTypeOnlyPromotionFix(sourceFile, symbolToken, symbolName, program) {
150548
+ var checker = program.getTypeChecker();
150549
+ var symbol = checker.resolveName(symbolName, symbolToken, 111551 /* Value */, /*excludeGlobals*/ true);
150550
+ if (!symbol)
150551
+ return undefined;
150552
+ var typeOnlyAliasDeclaration = checker.getTypeOnlyAliasDeclaration(symbol);
150553
+ if (!typeOnlyAliasDeclaration || ts.getSourceFileOfNode(typeOnlyAliasDeclaration) !== sourceFile)
150554
+ return undefined;
150555
+ return { kind: 4 /* PromoteTypeOnly */, typeOnlyAliasDeclaration: typeOnlyAliasDeclaration };
150385
150556
  }
150386
150557
  function jsxModeNeedsExplicitImport(jsx) {
150387
150558
  return jsx === 2 /* React */ || jsx === 3 /* ReactNative */;
@@ -150390,14 +150561,20 @@ var ts;
150390
150561
  var parent = symbolToken.parent;
150391
150562
  if ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) && parent.tagName === symbolToken && jsxModeNeedsExplicitImport(compilerOptions.jsx)) {
150392
150563
  var jsxNamespace = checker.getJsxNamespace(sourceFile);
150393
- if (ts.isIntrinsicJsxName(symbolToken.text) || !checker.resolveName(jsxNamespace, parent, 111551 /* Value */, /*excludeGlobals*/ true)) {
150564
+ if (needsJsxNamespaceFix(jsxNamespace, symbolToken, checker)) {
150394
150565
  return jsxNamespace;
150395
150566
  }
150396
150567
  }
150397
150568
  return symbolToken.text;
150398
150569
  }
150570
+ function needsJsxNamespaceFix(jsxNamespace, symbolToken, checker) {
150571
+ if (ts.isIntrinsicJsxName(symbolToken.text))
150572
+ return true; // If we were triggered by a matching error code on an intrinsic, the error must have been about missing the JSX factory
150573
+ var namespaceSymbol = checker.resolveName(jsxNamespace, symbolToken, 111551 /* Value */, /*excludeGlobals*/ true);
150574
+ return !namespaceSymbol || ts.some(namespaceSymbol.declarations, ts.isTypeOnlyImportOrExportDeclaration) && !(namespaceSymbol.flags & 111551 /* Value */);
150575
+ }
150399
150576
  // Returns a map from an exported symbol's ID to a list of every way it's (re-)exported.
150400
- function getExportInfos(symbolName, currentTokenMeaning, cancellationToken, fromFile, program, useAutoImportProvider, host, preferences) {
150577
+ function getExportInfos(symbolName, isJsxTagName, currentTokenMeaning, cancellationToken, fromFile, program, useAutoImportProvider, host, preferences) {
150401
150578
  var _a;
150402
150579
  // For each original symbol, keep all re-exports of that symbol together so we can call `getCodeActionsForImport` on the whole group at once.
150403
150580
  // Maps symbol id to info for modules providing that symbol (original export + re-exports).
@@ -150420,7 +150597,7 @@ var ts;
150420
150597
  cancellationToken.throwIfCancellationRequested();
150421
150598
  var compilerOptions = program.getCompilerOptions();
150422
150599
  var defaultInfo = ts.getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
150423
- if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions)) === symbolName) && symbolHasMeaning(defaultInfo.symbolForMeaning, currentTokenMeaning)) {
150600
+ if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions), isJsxTagName) === symbolName) && symbolHasMeaning(defaultInfo.symbolForMeaning, currentTokenMeaning)) {
150424
150601
  addSymbol(moduleSymbol, sourceFile, defaultInfo.symbol, defaultInfo.exportKind, program, isFromPackageJson);
150425
150602
  }
150426
150603
  // check exports with the same name
@@ -150460,14 +150637,14 @@ var ts;
150460
150637
  // allowSyntheticDefaultImports/esModuleInterop is enabled.
150461
150638
  return allowSyntheticDefaults ? 1 /* Default */ : 3 /* CommonJS */;
150462
150639
  }
150463
- function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
150640
+ function codeActionForFix(context, sourceFile, symbolName, fix, includeSymbolNameInDescription, quotePreference, compilerOptions) {
150464
150641
  var diag;
150465
150642
  var changes = ts.textChanges.ChangeTracker.with(context, function (tracker) {
150466
- diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference, compilerOptions);
150643
+ diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, includeSymbolNameInDescription, quotePreference, compilerOptions);
150467
150644
  });
150468
150645
  return codefix.createCodeFixAction(codefix.importFixName, changes, diag, importFixId, ts.Diagnostics.Add_all_missing_imports);
150469
150646
  }
150470
- function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
150647
+ function codeActionForFixWorker(changes, sourceFile, symbolName, fix, includeSymbolNameInDescription, quotePreference, compilerOptions) {
150471
150648
  switch (fix.kind) {
150472
150649
  case 0 /* UseNamespace */:
150473
150650
  addNamespaceQualifier(changes, sourceFile, fix);
@@ -150479,11 +150656,9 @@ var ts;
150479
150656
  var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly, moduleSpecifier = fix.moduleSpecifier;
150480
150657
  doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined, importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : ts.emptyArray, compilerOptions);
150481
150658
  var moduleSpecifierWithoutQuotes = ts.stripQuotes(moduleSpecifier);
150482
- return [
150483
- importKind === 1 /* Default */ ? ts.Diagnostics.Add_default_import_0_to_existing_import_declaration_from_1 : ts.Diagnostics.Add_0_to_existing_import_declaration_from_1,
150484
- symbolName,
150485
- moduleSpecifierWithoutQuotes
150486
- ]; // you too!
150659
+ return includeSymbolNameInDescription
150660
+ ? [ts.Diagnostics.Import_0_from_1, symbolName, moduleSpecifierWithoutQuotes]
150661
+ : [ts.Diagnostics.Update_import_from_0, moduleSpecifierWithoutQuotes];
150487
150662
  }
150488
150663
  case 3 /* AddNew */: {
150489
150664
  var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier, addAsTypeOnly = fix.addAsTypeOnly, useRequire = fix.useRequire;
@@ -150492,12 +150667,84 @@ var ts;
150492
150667
  var namedImports = importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : undefined;
150493
150668
  var namespaceLikeImport = importKind === 2 /* Namespace */ || importKind === 3 /* CommonJS */ ? { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
150494
150669
  ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport), /*blankLineBetween*/ true);
150495
- return [importKind === 1 /* Default */ ? ts.Diagnostics.Import_default_0_from_module_1 : ts.Diagnostics.Import_0_from_module_1, symbolName, moduleSpecifier];
150670
+ return includeSymbolNameInDescription
150671
+ ? [ts.Diagnostics.Import_0_from_1, symbolName, moduleSpecifier]
150672
+ : [ts.Diagnostics.Add_import_from_0, moduleSpecifier];
150673
+ }
150674
+ case 4 /* PromoteTypeOnly */: {
150675
+ var typeOnlyAliasDeclaration = fix.typeOnlyAliasDeclaration;
150676
+ var promotedDeclaration = promoteFromTypeOnly(changes, typeOnlyAliasDeclaration, compilerOptions, sourceFile);
150677
+ return promotedDeclaration.kind === 269 /* ImportSpecifier */
150678
+ ? [ts.Diagnostics.Remove_type_from_import_of_0_from_1, symbolName, getModuleSpecifierText(promotedDeclaration.parent.parent)]
150679
+ : [ts.Diagnostics.Remove_type_from_import_declaration_from_0, getModuleSpecifierText(promotedDeclaration)];
150496
150680
  }
150497
150681
  default:
150498
150682
  return ts.Debug.assertNever(fix, "Unexpected fix kind " + fix.kind);
150499
150683
  }
150500
150684
  }
150685
+ function getModuleSpecifierText(promotedDeclaration) {
150686
+ var _a, _b;
150687
+ return promotedDeclaration.kind === 264 /* ImportEqualsDeclaration */
150688
+ ? ((_b = ts.tryCast((_a = ts.tryCast(promotedDeclaration.moduleReference, ts.isExternalModuleReference)) === null || _a === void 0 ? void 0 : _a.expression, ts.isStringLiteralLike)) === null || _b === void 0 ? void 0 : _b.text) || promotedDeclaration.moduleReference.getText()
150689
+ : ts.cast(promotedDeclaration.parent.moduleSpecifier, ts.isStringLiteral).text;
150690
+ }
150691
+ function promoteFromTypeOnly(changes, aliasDeclaration, compilerOptions, sourceFile) {
150692
+ // See comment in `doAddExistingFix` on constant with the same name.
150693
+ var convertExistingToTypeOnly = compilerOptions.preserveValueImports && compilerOptions.isolatedModules;
150694
+ switch (aliasDeclaration.kind) {
150695
+ case 269 /* ImportSpecifier */:
150696
+ if (aliasDeclaration.isTypeOnly) {
150697
+ if (aliasDeclaration.parent.elements.length > 1 && ts.OrganizeImports.importSpecifiersAreSorted(aliasDeclaration.parent.elements)) {
150698
+ changes.delete(sourceFile, aliasDeclaration);
150699
+ var newSpecifier = ts.factory.updateImportSpecifier(aliasDeclaration, /*isTypeOnly*/ false, aliasDeclaration.propertyName, aliasDeclaration.name);
150700
+ var insertionIndex = ts.OrganizeImports.getImportSpecifierInsertionIndex(aliasDeclaration.parent.elements, newSpecifier);
150701
+ changes.insertImportSpecifierAtIndex(sourceFile, newSpecifier, aliasDeclaration.parent, insertionIndex);
150702
+ }
150703
+ else {
150704
+ changes.deleteRange(sourceFile, aliasDeclaration.getFirstToken());
150705
+ }
150706
+ return aliasDeclaration;
150707
+ }
150708
+ else {
150709
+ ts.Debug.assert(aliasDeclaration.parent.parent.isTypeOnly);
150710
+ promoteImportClause(aliasDeclaration.parent.parent);
150711
+ return aliasDeclaration.parent.parent;
150712
+ }
150713
+ case 266 /* ImportClause */:
150714
+ promoteImportClause(aliasDeclaration);
150715
+ return aliasDeclaration;
150716
+ case 267 /* NamespaceImport */:
150717
+ promoteImportClause(aliasDeclaration.parent);
150718
+ return aliasDeclaration.parent;
150719
+ case 264 /* ImportEqualsDeclaration */:
150720
+ changes.deleteRange(sourceFile, aliasDeclaration.getChildAt(1));
150721
+ return aliasDeclaration;
150722
+ default:
150723
+ ts.Debug.failBadSyntaxKind(aliasDeclaration);
150724
+ }
150725
+ function promoteImportClause(importClause) {
150726
+ changes.delete(sourceFile, ts.getTypeKeywordOfTypeOnlyImport(importClause, sourceFile));
150727
+ if (convertExistingToTypeOnly) {
150728
+ var namedImports = ts.tryCast(importClause.namedBindings, ts.isNamedImports);
150729
+ if (namedImports && namedImports.elements.length > 1) {
150730
+ if (ts.OrganizeImports.importSpecifiersAreSorted(namedImports.elements) &&
150731
+ aliasDeclaration.kind === 269 /* ImportSpecifier */ &&
150732
+ namedImports.elements.indexOf(aliasDeclaration) !== 0) {
150733
+ // The import specifier being promoted will be the only non-type-only,
150734
+ // import in the NamedImports, so it should be moved to the front.
150735
+ changes.delete(sourceFile, aliasDeclaration);
150736
+ changes.insertImportSpecifierAtIndex(sourceFile, aliasDeclaration, namedImports, 0);
150737
+ }
150738
+ for (var _i = 0, _a = namedImports.elements; _i < _a.length; _i++) {
150739
+ var element = _a[_i];
150740
+ if (element !== aliasDeclaration && !element.isTypeOnly) {
150741
+ changes.insertModifierBefore(sourceFile, 151 /* TypeKeyword */, element);
150742
+ }
150743
+ }
150744
+ }
150745
+ }
150746
+ }
150747
+ }
150501
150748
  function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, compilerOptions) {
150502
150749
  var _a;
150503
150750
  if (clause.kind === 200 /* ObjectBindingPattern */) {
@@ -150535,13 +150782,7 @@ var ts;
150535
150782
  var insertionIndex = convertExistingToTypeOnly && !spec.isTypeOnly
150536
150783
  ? 0
150537
150784
  : ts.OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec);
150538
- var prevSpecifier = clause.namedBindings.elements[insertionIndex - 1];
150539
- if (prevSpecifier) {
150540
- changes.insertNodeInListAfter(sourceFile, prevSpecifier, spec);
150541
- }
150542
- else {
150543
- changes.insertNodeBefore(sourceFile, existingSpecifiers[0], spec, !ts.positionsAreOnSameLine(existingSpecifiers[0].getStart(), clause.parent.getStart(), sourceFile));
150544
- }
150785
+ changes.insertImportSpecifierAtIndex(sourceFile, spec, clause.namedBindings, insertionIndex);
150545
150786
  }
150546
150787
  }
150547
150788
  else if (existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) {
@@ -150656,17 +150897,20 @@ var ts;
150656
150897
  var declarations = _a.declarations;
150657
150898
  return ts.some(declarations, function (decl) { return !!(ts.getMeaningFromDeclaration(decl) & meaning); });
150658
150899
  }
150659
- function moduleSymbolToValidIdentifier(moduleSymbol, target) {
150660
- return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target);
150900
+ function moduleSymbolToValidIdentifier(moduleSymbol, target, forceCapitalize) {
150901
+ return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target, forceCapitalize);
150661
150902
  }
150662
150903
  codefix.moduleSymbolToValidIdentifier = moduleSymbolToValidIdentifier;
150663
- function moduleSpecifierToValidIdentifier(moduleSpecifier, target) {
150904
+ function moduleSpecifierToValidIdentifier(moduleSpecifier, target, forceCapitalize) {
150664
150905
  var baseName = ts.getBaseFileName(ts.removeSuffix(moduleSpecifier, "/index"));
150665
150906
  var res = "";
150666
150907
  var lastCharWasValid = true;
150667
150908
  var firstCharCode = baseName.charCodeAt(0);
150668
150909
  if (ts.isIdentifierStart(firstCharCode, target)) {
150669
150910
  res += String.fromCharCode(firstCharCode);
150911
+ if (forceCapitalize) {
150912
+ res = res.toUpperCase();
150913
+ }
150670
150914
  }
150671
150915
  else {
150672
150916
  lastCharWasValid = false;
@@ -158285,14 +158529,22 @@ var ts;
158285
158529
  var result = [];
158286
158530
  return visitor(selection) ? undefined : result;
158287
158531
  function visitor(node) {
158288
- var _a;
158289
158532
  if (ts.isTypeReferenceNode(node)) {
158290
158533
  if (ts.isIdentifier(node.typeName)) {
158291
- var symbol = checker.resolveName(node.typeName.text, node.typeName, 262144 /* TypeParameter */, /* excludeGlobals */ true);
158292
- var declaration = ts.tryCast((_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a[0], ts.isTypeParameterDeclaration);
158293
- if (declaration) {
158294
- if (rangeContainsSkipTrivia(statement, declaration, file) && !rangeContainsSkipTrivia(selection, declaration, file)) {
158295
- ts.pushIfUnique(result, declaration);
158534
+ var typeName = node.typeName;
158535
+ var symbol = checker.resolveName(typeName.text, typeName, 262144 /* TypeParameter */, /* excludeGlobals */ true);
158536
+ for (var _i = 0, _a = (symbol === null || symbol === void 0 ? void 0 : symbol.declarations) || ts.emptyArray; _i < _a.length; _i++) {
158537
+ var decl = _a[_i];
158538
+ if (ts.isTypeParameterDeclaration(decl) && decl.getSourceFile() === file) {
158539
+ // skip extraction if the type node is in the range of the type parameter declaration.
158540
+ // function foo<T extends { a?: /**/T }>(): void;
158541
+ if (decl.name.escapedText === typeName.escapedText && rangeContainsSkipTrivia(decl, selection, file)) {
158542
+ return true;
158543
+ }
158544
+ if (rangeContainsSkipTrivia(statement, decl, file) && !rangeContainsSkipTrivia(selection, decl, file)) {
158545
+ ts.pushIfUnique(result, decl);
158546
+ break;
158547
+ }
158296
158548
  }
158297
158549
  }
158298
158550
  }