typescript 4.6.0-dev.20220125 → 4.6.0-dev.20220129

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.
package/lib/tsserver.js CHANGED
@@ -100,7 +100,7 @@ var ts;
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-dev.20220125";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220129";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -7855,7 +7855,7 @@ var ts;
7855
7855
  }
7856
7856
  })(ts || (ts = {}));
7857
7857
  // <auto-generated />
7858
- // generated from './diagnosticInformationMap.generated.ts' by 'src/compiler'
7858
+ // generated from './diagnosticMessages.json' in 'src/compiler'
7859
7859
  /* @internal */
7860
7860
  var ts;
7861
7861
  (function (ts) {
@@ -9443,9 +9443,8 @@ var ts;
9443
9443
  Remove_variable_statement: diag(90010, ts.DiagnosticCategory.Message, "Remove_variable_statement_90010", "Remove variable statement"),
9444
9444
  Remove_template_tag: diag(90011, ts.DiagnosticCategory.Message, "Remove_template_tag_90011", "Remove template tag"),
9445
9445
  Remove_type_parameters: diag(90012, ts.DiagnosticCategory.Message, "Remove_type_parameters_90012", "Remove type parameters"),
9446
- Import_0_from_module_1: diag(90013, ts.DiagnosticCategory.Message, "Import_0_from_module_1_90013", "Import '{0}' from module \"{1}\""),
9446
+ Import_0_from_1: diag(90013, ts.DiagnosticCategory.Message, "Import_0_from_1_90013", "Import '{0}' from \"{1}\""),
9447
9447
  Change_0_to_1: diag(90014, ts.DiagnosticCategory.Message, "Change_0_to_1_90014", "Change '{0}' to '{1}'"),
9448
- 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}\""),
9449
9448
  Declare_property_0: diag(90016, ts.DiagnosticCategory.Message, "Declare_property_0_90016", "Declare property '{0}'"),
9450
9449
  Add_index_signature_for_property_0: diag(90017, ts.DiagnosticCategory.Message, "Add_index_signature_for_property_0_90017", "Add index signature for property '{0}'"),
9451
9450
  Disable_checking_for_this_file: diag(90018, ts.DiagnosticCategory.Message, "Disable_checking_for_this_file_90018", "Disable checking for this file"),
@@ -9462,8 +9461,6 @@ var ts;
9462
9461
  Add_async_modifier_to_containing_function: diag(90029, ts.DiagnosticCategory.Message, "Add_async_modifier_to_containing_function_90029", "Add async modifier to containing function"),
9463
9462
  Replace_infer_0_with_unknown: diag(90030, ts.DiagnosticCategory.Message, "Replace_infer_0_with_unknown_90030", "Replace 'infer {0}' with 'unknown'"),
9464
9463
  Replace_all_unused_infer_with_unknown: diag(90031, ts.DiagnosticCategory.Message, "Replace_all_unused_infer_with_unknown_90031", "Replace all unused 'infer' with 'unknown'"),
9465
- Import_default_0_from_module_1: diag(90032, ts.DiagnosticCategory.Message, "Import_default_0_from_module_1_90032", "Import default '{0}' from module \"{1}\""),
9466
- 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}\""),
9467
9464
  Add_parameter_name: diag(90034, ts.DiagnosticCategory.Message, "Add_parameter_name_90034", "Add parameter name"),
9468
9465
  Declare_private_property_0: diag(90035, ts.DiagnosticCategory.Message, "Declare_private_property_0_90035", "Declare private property '{0}'"),
9469
9466
  Replace_0_with_Promise_1: diag(90036, ts.DiagnosticCategory.Message, "Replace_0_with_Promise_1_90036", "Replace '{0}' with 'Promise<{1}>'"),
@@ -9473,6 +9470,10 @@ var ts;
9473
9470
  Remove_unused_declarations_for_Colon_0: diag(90041, ts.DiagnosticCategory.Message, "Remove_unused_declarations_for_Colon_0_90041", "Remove unused declarations for: '{0}'"),
9474
9471
  Declare_a_private_field_named_0: diag(90053, ts.DiagnosticCategory.Message, "Declare_a_private_field_named_0_90053", "Declare a private field named '{0}'."),
9475
9472
  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}'"),
9473
+ 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}\""),
9474
+ 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}\""),
9475
+ Add_import_from_0: diag(90057, ts.DiagnosticCategory.Message, "Add_import_from_0_90057", "Add import from \"{0}\""),
9476
+ Update_import_from_0: diag(90058, ts.DiagnosticCategory.Message, "Update_import_from_0_90058", "Update import from \"{0}\""),
9476
9477
  Convert_function_to_an_ES2015_class: diag(95001, ts.DiagnosticCategory.Message, "Convert_function_to_an_ES2015_class_95001", "Convert function to an ES2015 class"),
9477
9478
  Convert_0_to_1_in_0: diag(95003, ts.DiagnosticCategory.Message, "Convert_0_to_1_in_0_95003", "Convert '{0}' to '{1} in {0}'"),
9478
9479
  Extract_to_0_in_1: diag(95004, ts.DiagnosticCategory.Message, "Extract_to_0_in_1_95004", "Extract to {0} in {1}"),
@@ -14063,10 +14064,13 @@ var ts;
14063
14064
  function packageIdIsEqual(a, b) {
14064
14065
  return a === b || !!a && !!b && a.name === b.name && a.subModuleName === b.subModuleName && a.version === b.version;
14065
14066
  }
14066
- function packageIdToString(_a) {
14067
- var name = _a.name, subModuleName = _a.subModuleName, version = _a.version;
14068
- var fullName = subModuleName ? name + "/" + subModuleName : name;
14069
- return fullName + "@" + version;
14067
+ function packageIdToPackageName(_a) {
14068
+ var name = _a.name, subModuleName = _a.subModuleName;
14069
+ return subModuleName ? name + "/" + subModuleName : name;
14070
+ }
14071
+ ts.packageIdToPackageName = packageIdToPackageName;
14072
+ function packageIdToString(packageId) {
14073
+ return packageIdToPackageName(packageId) + "@" + packageId.version;
14070
14074
  }
14071
14075
  ts.packageIdToString = packageIdToString;
14072
14076
  function typeDirectiveIsEqualTo(oldResolution, newResolution) {
@@ -14899,6 +14903,15 @@ var ts;
14899
14903
  };
14900
14904
  }
14901
14905
  ts.createDiagnosticForFileFromMessageChain = createDiagnosticForFileFromMessageChain;
14906
+ function createDiagnosticMessageChainFromDiagnostic(diagnostic) {
14907
+ return typeof diagnostic.messageText === "string" ? {
14908
+ code: diagnostic.code,
14909
+ category: diagnostic.category,
14910
+ messageText: diagnostic.messageText,
14911
+ next: diagnostic.next,
14912
+ } : diagnostic.messageText;
14913
+ }
14914
+ ts.createDiagnosticMessageChainFromDiagnostic = createDiagnosticMessageChainFromDiagnostic;
14902
14915
  function createDiagnosticForRange(sourceFile, range, message) {
14903
14916
  return {
14904
14917
  file: sourceFile,
@@ -15067,7 +15080,8 @@ var ts;
15067
15080
  node.kind === 212 /* FunctionExpression */ ||
15068
15081
  node.kind === 213 /* ArrowFunction */ ||
15069
15082
  node.kind === 211 /* ParenthesizedExpression */ ||
15070
- node.kind === 253 /* VariableDeclaration */) ?
15083
+ node.kind === 253 /* VariableDeclaration */ ||
15084
+ node.kind === 274 /* ExportSpecifier */) ?
15071
15085
  ts.concatenate(ts.getTrailingCommentRanges(text, node.pos), ts.getLeadingCommentRanges(text, node.pos)) :
15072
15086
  ts.getLeadingCommentRanges(text, node.pos);
15073
15087
  // True if the comment starts with '/**' but not if it is '/**/'
@@ -20858,6 +20872,59 @@ var ts;
20858
20872
  return !!(type.flags & 262144 /* TypeParameter */ && type.isThisType);
20859
20873
  }
20860
20874
  ts.isThisTypeParameter = isThisTypeParameter;
20875
+ function getNodeModulePathParts(fullPath) {
20876
+ // If fullPath can't be valid module file within node_modules, returns undefined.
20877
+ // Example of expected pattern: /base/path/node_modules/[@scope/otherpackage/@otherscope/node_modules/]package/[subdirectory/]file.js
20878
+ // Returns indices: ^ ^ ^ ^
20879
+ var topLevelNodeModulesIndex = 0;
20880
+ var topLevelPackageNameIndex = 0;
20881
+ var packageRootIndex = 0;
20882
+ var fileNameIndex = 0;
20883
+ var States;
20884
+ (function (States) {
20885
+ States[States["BeforeNodeModules"] = 0] = "BeforeNodeModules";
20886
+ States[States["NodeModules"] = 1] = "NodeModules";
20887
+ States[States["Scope"] = 2] = "Scope";
20888
+ States[States["PackageContent"] = 3] = "PackageContent";
20889
+ })(States || (States = {}));
20890
+ var partStart = 0;
20891
+ var partEnd = 0;
20892
+ var state = 0 /* BeforeNodeModules */;
20893
+ while (partEnd >= 0) {
20894
+ partStart = partEnd;
20895
+ partEnd = fullPath.indexOf("/", partStart + 1);
20896
+ switch (state) {
20897
+ case 0 /* BeforeNodeModules */:
20898
+ if (fullPath.indexOf(ts.nodeModulesPathPart, partStart) === partStart) {
20899
+ topLevelNodeModulesIndex = partStart;
20900
+ topLevelPackageNameIndex = partEnd;
20901
+ state = 1 /* NodeModules */;
20902
+ }
20903
+ break;
20904
+ case 1 /* NodeModules */:
20905
+ case 2 /* Scope */:
20906
+ if (state === 1 /* NodeModules */ && fullPath.charAt(partStart + 1) === "@") {
20907
+ state = 2 /* Scope */;
20908
+ }
20909
+ else {
20910
+ packageRootIndex = partEnd;
20911
+ state = 3 /* PackageContent */;
20912
+ }
20913
+ break;
20914
+ case 3 /* PackageContent */:
20915
+ if (fullPath.indexOf(ts.nodeModulesPathPart, partStart) === partStart) {
20916
+ state = 1 /* NodeModules */;
20917
+ }
20918
+ else {
20919
+ state = 3 /* PackageContent */;
20920
+ }
20921
+ break;
20922
+ }
20923
+ }
20924
+ fileNameIndex = partStart;
20925
+ return state > 1 /* NodeModules */ ? { topLevelNodeModulesIndex: topLevelNodeModulesIndex, topLevelPackageNameIndex: topLevelPackageNameIndex, packageRootIndex: packageRootIndex, fileNameIndex: fileNameIndex } : undefined;
20926
+ }
20927
+ ts.getNodeModulePathParts = getNodeModulePathParts;
20861
20928
  })(ts || (ts = {}));
20862
20929
  /* @internal */
20863
20930
  var ts;
@@ -36218,7 +36285,8 @@ var ts;
36218
36285
  return finishNode(node, pos);
36219
36286
  }
36220
36287
  function parseExportSpecifier() {
36221
- return parseImportOrExportSpecifier(274 /* ExportSpecifier */);
36288
+ var hasJSDoc = hasPrecedingJSDocComment();
36289
+ return withJSDoc(parseImportOrExportSpecifier(274 /* ExportSpecifier */), hasJSDoc);
36222
36290
  }
36223
36291
  function parseImportSpecifier() {
36224
36292
  return parseImportOrExportSpecifier(269 /* ImportSpecifier */);
@@ -43423,14 +43491,12 @@ var ts;
43423
43491
  }
43424
43492
  var binder = createBinder();
43425
43493
  function bindSourceFile(file, options) {
43426
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("bind" /* Bind */, "bindSourceFile", { path: file.path }, /*separateBeginAndEnd*/ true);
43427
43494
  ts.performance.mark("beforeBind");
43428
43495
  ts.perfLogger.logStartBindFile("" + file.fileName);
43429
43496
  binder(file, options);
43430
43497
  ts.perfLogger.logStopBindFile();
43431
43498
  ts.performance.mark("afterBind");
43432
43499
  ts.performance.measure("Bind", "beforeBind", "afterBind");
43433
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
43434
43500
  }
43435
43501
  ts.bindSourceFile = bindSourceFile;
43436
43502
  function createBinder() {
@@ -43490,7 +43556,9 @@ var ts;
43490
43556
  ts.Debug.attachFlowNodeDebugInfo(unreachableFlow);
43491
43557
  ts.Debug.attachFlowNodeDebugInfo(reportedUnreachableFlow);
43492
43558
  if (!file.locals) {
43559
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("bind" /* Bind */, "bindSourceFile", { path: file.path }, /*separateBeginAndEnd*/ true);
43493
43560
  bind(file);
43561
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
43494
43562
  file.symbolCount = symbolCount;
43495
43563
  file.classifiableNames = classifiableNames;
43496
43564
  delayedBindJSDocTypedefTag();
@@ -47757,6 +47825,9 @@ var ts;
47757
47825
  suggestionDiagnostics.add(diagnostic);
47758
47826
  return diagnostic;
47759
47827
  }
47828
+ function isDeprecatedSymbol(symbol) {
47829
+ return !!(getDeclarationNodeFlagsFromSymbol(symbol) & 134217728 /* Deprecated */);
47830
+ }
47760
47831
  function addDeprecatedSuggestion(location, declarations, deprecatedEntity) {
47761
47832
  var diagnostic = ts.createDiagnosticForNode(location, ts.Diagnostics._0_is_deprecated, deprecatedEntity);
47762
47833
  return addDeprecatedSuggestionWorker(declarations, diagnostic);
@@ -48748,24 +48819,19 @@ var ts;
48748
48819
  error(errorLocation, ts.Diagnostics.Parameter_0_cannot_reference_identifier_1_declared_after_it, ts.declarationNameToString(associatedDeclarationForContainingInitializerOrBindingName.name), ts.declarationNameToString(errorLocation));
48749
48820
  }
48750
48821
  }
48751
- if (result && errorLocation && meaning & 111551 /* Value */ && result.flags & 2097152 /* Alias */) {
48752
- checkSymbolUsageInExpressionContext(result, name, errorLocation);
48822
+ if (result && errorLocation && meaning & 111551 /* Value */ && result.flags & 2097152 /* Alias */ && !(result.flags & 111551 /* Value */) && !ts.isValidTypeOnlyAliasUseSite(errorLocation)) {
48823
+ var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(result);
48824
+ if (typeOnlyDeclaration) {
48825
+ var message = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */
48826
+ ? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
48827
+ : ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
48828
+ var unescapedName = ts.unescapeLeadingUnderscores(name);
48829
+ addTypeOnlyDeclarationRelatedInfo(error(errorLocation, message, unescapedName), typeOnlyDeclaration, unescapedName);
48830
+ }
48753
48831
  }
48754
48832
  }
48755
48833
  return result;
48756
48834
  }
48757
- function checkSymbolUsageInExpressionContext(symbol, name, useSite) {
48758
- if (!ts.isValidTypeOnlyAliasUseSite(useSite)) {
48759
- var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(symbol);
48760
- if (typeOnlyDeclaration) {
48761
- var message = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */
48762
- ? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
48763
- : ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
48764
- var unescapedName = ts.unescapeLeadingUnderscores(name);
48765
- addTypeOnlyDeclarationRelatedInfo(error(useSite, message, unescapedName), typeOnlyDeclaration, unescapedName);
48766
- }
48767
- }
48768
- }
48769
48835
  function addTypeOnlyDeclarationRelatedInfo(diagnostic, typeOnlyDeclaration, unescapedName) {
48770
48836
  if (!typeOnlyDeclaration)
48771
48837
  return diagnostic;
@@ -52527,7 +52593,8 @@ var ts;
52527
52593
  includePrivateSymbol === null || includePrivateSymbol === void 0 ? void 0 : includePrivateSymbol(sym);
52528
52594
  }
52529
52595
  if (ts.isIdentifier(node)) {
52530
- var name = sym.flags & 262144 /* TypeParameter */ ? typeParameterToName(getDeclaredTypeOfSymbol(sym), context) : ts.factory.cloneNode(node);
52596
+ var type = getDeclaredTypeOfSymbol(sym);
52597
+ var name = sym.flags & 262144 /* TypeParameter */ && !isTypeSymbolAccessible(type.symbol, context.enclosingDeclaration) ? typeParameterToName(type, context) : ts.factory.cloneNode(node);
52531
52598
  name.symbol = sym; // for quickinfo, which uses identifier symbol information
52532
52599
  return { introducesError: introducesError, node: ts.setEmitFlags(ts.setOriginalNode(name, node), 16777216 /* NoAsciiEscaping */) };
52533
52600
  }
@@ -60543,7 +60610,7 @@ var ts;
60543
60610
  }
60544
60611
  var prop = getPropertyOfType(objectType, propName);
60545
60612
  if (prop) {
60546
- if (accessFlags & 64 /* ReportDeprecated */ && accessNode && prop.declarations && getDeclarationNodeFlagsFromSymbol(prop) & 134217728 /* Deprecated */ && isUncalledFunctionReference(accessNode, prop)) {
60613
+ if (accessFlags & 64 /* ReportDeprecated */ && accessNode && prop.declarations && isDeprecatedSymbol(prop) && isUncalledFunctionReference(accessNode, prop)) {
60547
60614
  var deprecatedNode = (_a = accessExpression === null || accessExpression === void 0 ? void 0 : accessExpression.argumentExpression) !== null && _a !== void 0 ? _a : (ts.isIndexedAccessTypeNode(accessNode) ? accessNode.indexType : accessNode);
60548
60615
  addDeprecatedSuggestion(deprecatedNode, prop.declarations, propName);
60549
60616
  }
@@ -69946,9 +70013,9 @@ var ts;
69946
70013
  markAliasReferenced(symbol, node);
69947
70014
  }
69948
70015
  var localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol);
69949
- var sourceSymbol = localOrExportSymbol.flags & 2097152 /* Alias */ ? resolveAlias(localOrExportSymbol) : localOrExportSymbol;
69950
- if (sourceSymbol.declarations && getDeclarationNodeFlagsFromSymbol(sourceSymbol) & 134217728 /* Deprecated */ && isUncalledFunctionReference(node, sourceSymbol)) {
69951
- addDeprecatedSuggestion(node, sourceSymbol.declarations, node.escapedText);
70016
+ var targetSymbol = checkDeprecatedAliasedSymbol(localOrExportSymbol, node);
70017
+ if (isDeprecatedSymbol(targetSymbol) && isUncalledFunctionReference(node, targetSymbol) && targetSymbol.declarations) {
70018
+ addDeprecatedSuggestion(node, targetSymbol.declarations, node.escapedText);
69952
70019
  }
69953
70020
  var declaration = localOrExportSymbol.valueDeclaration;
69954
70021
  if (declaration && localOrExportSymbol.flags & 32 /* Class */) {
@@ -72960,7 +73027,7 @@ var ts;
72960
73027
  }
72961
73028
  }
72962
73029
  else {
72963
- if (prop.declarations && getDeclarationNodeFlagsFromSymbol(prop) & 134217728 /* Deprecated */ && isUncalledFunctionReference(node, prop)) {
73030
+ if (isDeprecatedSymbol(prop) && isUncalledFunctionReference(node, prop) && prop.declarations) {
72964
73031
  addDeprecatedSuggestion(right, prop.declarations, right.escapedText);
72965
73032
  }
72966
73033
  checkPropertyNotUsedBeforeDeclaration(prop, node, right);
@@ -74419,7 +74486,7 @@ var ts;
74419
74486
  }
74420
74487
  var diags_3 = max > 1 ? allDiagnostics[minIndex] : ts.flatten(allDiagnostics);
74421
74488
  ts.Debug.assert(diags_3.length > 0, "No errors reported for 3 or fewer overload signatures");
74422
- 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);
74489
+ var chain = ts.chainDiagnosticMessages(ts.map(diags_3, ts.createDiagnosticMessageChainFromDiagnostic), ts.Diagnostics.No_overload_matches_this_call);
74423
74490
  // 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
74424
74491
  // arrays and the emptyArray singleton where possible, which is decidedly not what we want while we're still constructing this diagnostic
74425
74492
  var related = __spreadArray([], ts.flatMap(diags_3, function (d) { return d.relatedInformation; }), true);
@@ -82798,16 +82865,15 @@ var ts;
82798
82865
  return ts.nodeIsMissing(expr) ? 0 : evaluateEnumMember(expr, getSymbolOfNode(member.parent), identifier.escapedText);
82799
82866
  case 206 /* ElementAccessExpression */:
82800
82867
  case 205 /* PropertyAccessExpression */:
82801
- var ex = expr;
82802
- if (isConstantMemberAccess(ex)) {
82803
- var type = getTypeOfExpression(ex.expression);
82868
+ if (isConstantMemberAccess(expr)) {
82869
+ var type = getTypeOfExpression(expr.expression);
82804
82870
  if (type.symbol && type.symbol.flags & 384 /* Enum */) {
82805
82871
  var name = void 0;
82806
- if (ex.kind === 205 /* PropertyAccessExpression */) {
82807
- name = ex.name.escapedText;
82872
+ if (expr.kind === 205 /* PropertyAccessExpression */) {
82873
+ name = expr.name.escapedText;
82808
82874
  }
82809
82875
  else {
82810
- name = ts.escapeLeadingUnderscores(ts.cast(ex.argumentExpression, ts.isLiteralExpression).text);
82876
+ name = ts.escapeLeadingUnderscores(ts.cast(expr.argumentExpression, ts.isLiteralExpression).text);
82811
82877
  }
82812
82878
  return evaluateEnumMember(expr, type.symbol, name);
82813
82879
  }
@@ -82835,6 +82901,10 @@ var ts;
82835
82901
  }
82836
82902
  }
82837
82903
  function isConstantMemberAccess(node) {
82904
+ var type = getTypeOfExpression(node);
82905
+ if (type === errorType) {
82906
+ return false;
82907
+ }
82838
82908
  return node.kind === 79 /* Identifier */ ||
82839
82909
  node.kind === 205 /* PropertyAccessExpression */ && isConstantMemberAccess(node.expression) ||
82840
82910
  node.kind === 206 /* ElementAccessExpression */ && isConstantMemberAccess(node.expression) &&
@@ -83129,7 +83199,6 @@ var ts;
83129
83199
  return true;
83130
83200
  }
83131
83201
  function checkAliasSymbol(node) {
83132
- var _a;
83133
83202
  var symbol = getSymbolOfNode(node);
83134
83203
  var target = resolveAlias(symbol);
83135
83204
  if (target !== unknownSymbol) {
@@ -83185,10 +83254,45 @@ var ts;
83185
83254
  }
83186
83255
  }
83187
83256
  }
83188
- if (ts.isImportSpecifier(node) && ((_a = target.declarations) === null || _a === void 0 ? void 0 : _a.every(function (d) { return !!(ts.getCombinedNodeFlags(d) & 134217728 /* Deprecated */); }))) {
83189
- addDeprecatedSuggestion(node.name, target.declarations, symbol.escapedName);
83257
+ if (ts.isImportSpecifier(node)) {
83258
+ var targetSymbol = checkDeprecatedAliasedSymbol(symbol, node);
83259
+ if (isDeprecatedAliasedSymbol(targetSymbol) && targetSymbol.declarations) {
83260
+ addDeprecatedSuggestion(node, targetSymbol.declarations, targetSymbol.escapedName);
83261
+ }
83262
+ }
83263
+ }
83264
+ }
83265
+ function isDeprecatedAliasedSymbol(symbol) {
83266
+ return !!symbol.declarations && ts.every(symbol.declarations, function (d) { return !!(ts.getCombinedNodeFlags(d) & 134217728 /* Deprecated */); });
83267
+ }
83268
+ function checkDeprecatedAliasedSymbol(symbol, location) {
83269
+ if (!(symbol.flags & 2097152 /* Alias */))
83270
+ return symbol;
83271
+ var targetSymbol = resolveAlias(symbol);
83272
+ if (targetSymbol === unknownSymbol)
83273
+ return targetSymbol;
83274
+ while (symbol.flags & 2097152 /* Alias */) {
83275
+ var target = getImmediateAliasedSymbol(symbol);
83276
+ if (target) {
83277
+ if (target === targetSymbol)
83278
+ break;
83279
+ if (target.declarations && ts.length(target.declarations)) {
83280
+ if (isDeprecatedAliasedSymbol(target)) {
83281
+ addDeprecatedSuggestion(location, target.declarations, target.escapedName);
83282
+ break;
83283
+ }
83284
+ else {
83285
+ if (symbol === targetSymbol)
83286
+ break;
83287
+ symbol = target;
83288
+ }
83289
+ }
83290
+ }
83291
+ else {
83292
+ break;
83190
83293
  }
83191
83294
  }
83295
+ return targetSymbol;
83192
83296
  }
83193
83297
  function checkImportBinding(node) {
83194
83298
  checkCollisionsForDeclarationName(node, node.name);
@@ -85624,7 +85728,7 @@ var ts;
85624
85728
  if (quickResult !== undefined) {
85625
85729
  return quickResult;
85626
85730
  }
85627
- var lastStatic, lastDeclare, lastAsync, lastReadonly, lastOverride;
85731
+ var lastStatic, lastDeclare, lastAsync, lastOverride;
85628
85732
  var flags = 0 /* None */;
85629
85733
  for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) {
85630
85734
  var modifier = _a[_i];
@@ -85728,7 +85832,6 @@ var ts;
85728
85832
  return grammarErrorOnNode(modifier, ts.Diagnostics.readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature);
85729
85833
  }
85730
85834
  flags |= 64 /* Readonly */;
85731
- lastReadonly = modifier;
85732
85835
  break;
85733
85836
  case 93 /* ExportKeyword */:
85734
85837
  if (flags & 1 /* Export */) {
@@ -85841,18 +85944,12 @@ var ts;
85841
85944
  if (flags & 32 /* Static */) {
85842
85945
  return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static");
85843
85946
  }
85844
- if (flags & 128 /* Abstract */) {
85845
- return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "abstract"); // TODO: GH#18217
85846
- }
85847
85947
  if (flags & 16384 /* Override */) {
85848
85948
  return grammarErrorOnNode(lastOverride, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "override"); // TODO: GH#18217
85849
85949
  }
85850
- else if (flags & 256 /* Async */) {
85950
+ if (flags & 256 /* Async */) {
85851
85951
  return grammarErrorOnNode(lastAsync, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async");
85852
85952
  }
85853
- else if (flags & 64 /* Readonly */) {
85854
- return grammarErrorOnNode(lastReadonly, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "readonly");
85855
- }
85856
85953
  return false;
85857
85954
  }
85858
85955
  else if ((node.kind === 265 /* ImportDeclaration */ || node.kind === 264 /* ImportEqualsDeclaration */) && flags & 2 /* Ambient */) {
@@ -115847,14 +115944,14 @@ var ts;
115847
115944
  redirectTargetsMap.add(fileFromPackageId.path, fileName);
115848
115945
  addFileToFilesByName(dupFile, path, redirectedPath);
115849
115946
  addFileIncludeReason(dupFile, reason);
115850
- sourceFileToPackageName.set(path, packageId.name);
115947
+ sourceFileToPackageName.set(path, ts.packageIdToPackageName(packageId));
115851
115948
  processingOtherFiles.push(dupFile);
115852
115949
  return dupFile;
115853
115950
  }
115854
115951
  else if (file) {
115855
115952
  // This is the first source file to have this packageId.
115856
115953
  packageIdToSourceFile.set(packageIdKey, file);
115857
- sourceFileToPackageName.set(path, packageId.name);
115954
+ sourceFileToPackageName.set(path, ts.packageIdToPackageName(packageId));
115858
115955
  }
115859
115956
  }
115860
115957
  addFileToFilesByName(file, path, redirectedPath);
@@ -119993,7 +120090,7 @@ var ts;
119993
120090
  if (!host.fileExists || !host.readFile) {
119994
120091
  return undefined;
119995
120092
  }
119996
- var parts = getNodeModulePathParts(path);
120093
+ var parts = ts.getNodeModulePathParts(path);
119997
120094
  if (!parts) {
119998
120095
  return undefined;
119999
120096
  }
@@ -120116,58 +120213,6 @@ var ts;
120116
120213
  }
120117
120214
  }
120118
120215
  }
120119
- function getNodeModulePathParts(fullPath) {
120120
- // If fullPath can't be valid module file within node_modules, returns undefined.
120121
- // Example of expected pattern: /base/path/node_modules/[@scope/otherpackage/@otherscope/node_modules/]package/[subdirectory/]file.js
120122
- // Returns indices: ^ ^ ^ ^
120123
- var topLevelNodeModulesIndex = 0;
120124
- var topLevelPackageNameIndex = 0;
120125
- var packageRootIndex = 0;
120126
- var fileNameIndex = 0;
120127
- var States;
120128
- (function (States) {
120129
- States[States["BeforeNodeModules"] = 0] = "BeforeNodeModules";
120130
- States[States["NodeModules"] = 1] = "NodeModules";
120131
- States[States["Scope"] = 2] = "Scope";
120132
- States[States["PackageContent"] = 3] = "PackageContent";
120133
- })(States || (States = {}));
120134
- var partStart = 0;
120135
- var partEnd = 0;
120136
- var state = 0 /* BeforeNodeModules */;
120137
- while (partEnd >= 0) {
120138
- partStart = partEnd;
120139
- partEnd = fullPath.indexOf("/", partStart + 1);
120140
- switch (state) {
120141
- case 0 /* BeforeNodeModules */:
120142
- if (fullPath.indexOf(ts.nodeModulesPathPart, partStart) === partStart) {
120143
- topLevelNodeModulesIndex = partStart;
120144
- topLevelPackageNameIndex = partEnd;
120145
- state = 1 /* NodeModules */;
120146
- }
120147
- break;
120148
- case 1 /* NodeModules */:
120149
- case 2 /* Scope */:
120150
- if (state === 1 /* NodeModules */ && fullPath.charAt(partStart + 1) === "@") {
120151
- state = 2 /* Scope */;
120152
- }
120153
- else {
120154
- packageRootIndex = partEnd;
120155
- state = 3 /* PackageContent */;
120156
- }
120157
- break;
120158
- case 3 /* PackageContent */:
120159
- if (fullPath.indexOf(ts.nodeModulesPathPart, partStart) === partStart) {
120160
- state = 1 /* NodeModules */;
120161
- }
120162
- else {
120163
- state = 3 /* PackageContent */;
120164
- }
120165
- break;
120166
- }
120167
- }
120168
- fileNameIndex = partStart;
120169
- return state > 1 /* NodeModules */ ? { topLevelNodeModulesIndex: topLevelNodeModulesIndex, topLevelPackageNameIndex: topLevelPackageNameIndex, packageRootIndex: packageRootIndex, fileNameIndex: fileNameIndex } : undefined;
120170
- }
120171
120216
  function getPathRelativeToRootDirs(path, rootDirs, getCanonicalFileName) {
120172
120217
  return ts.firstDefined(rootDirs, function (rootDir) {
120173
120218
  var relativePath = getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName);
@@ -126514,11 +126559,11 @@ var ts;
126514
126559
  return ts.isArray(valueOrArray) ? ts.first(valueOrArray) : valueOrArray;
126515
126560
  }
126516
126561
  ts.firstOrOnly = firstOrOnly;
126517
- function getNameForExportedSymbol(symbol, scriptTarget) {
126562
+ function getNameForExportedSymbol(symbol, scriptTarget, preferCapitalized) {
126518
126563
  if (!(symbol.flags & 33554432 /* Transient */) && (symbol.escapedName === "export=" /* ExportEquals */ || symbol.escapedName === "default" /* Default */)) {
126519
126564
  // Name of "export default foo;" is "foo". Name of "export default 0" is the filename converted to camelCase.
126520
126565
  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; })
126521
- || ts.codefix.moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget);
126566
+ || ts.codefix.moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget, !!preferCapitalized);
126522
126567
  }
126523
126568
  return symbol.name;
126524
126569
  }
@@ -126637,6 +126682,17 @@ var ts;
126637
126682
  var exportInfoId = 1;
126638
126683
  var exportInfo = ts.createMultiMap();
126639
126684
  var symbols = new ts.Map();
126685
+ /**
126686
+ * Key: node_modules package name (no @types).
126687
+ * Value: path to deepest node_modules folder seen that is
126688
+ * both visible to `usableByFileName` and contains the package.
126689
+ *
126690
+ * Later, we can see if a given SymbolExportInfo is shadowed by
126691
+ * a another installation of the same package in a deeper
126692
+ * node_modules folder by seeing if its path starts with the
126693
+ * value stored here.
126694
+ */
126695
+ var packages = new ts.Map();
126640
126696
  var usableByFileName;
126641
126697
  var cache = {
126642
126698
  isUsableByFile: function (importingFile) { return importingFile === usableByFileName; },
@@ -126646,11 +126702,32 @@ var ts;
126646
126702
  symbols.clear();
126647
126703
  usableByFileName = undefined;
126648
126704
  },
126649
- add: function (importingFile, symbol, symbolTableKey, moduleSymbol, moduleFile, exportKind, isFromPackageJson, scriptTarget, checker) {
126705
+ add: function (importingFile, symbol, symbolTableKey, moduleSymbol, moduleFile, exportKind, isFromPackageJson, checker) {
126650
126706
  if (importingFile !== usableByFileName) {
126651
126707
  cache.clear();
126652
126708
  usableByFileName = importingFile;
126653
126709
  }
126710
+ var packageName;
126711
+ if (moduleFile) {
126712
+ var nodeModulesPathParts = ts.getNodeModulePathParts(moduleFile.fileName);
126713
+ if (nodeModulesPathParts) {
126714
+ var topLevelNodeModulesIndex = nodeModulesPathParts.topLevelNodeModulesIndex, topLevelPackageNameIndex = nodeModulesPathParts.topLevelPackageNameIndex, packageRootIndex = nodeModulesPathParts.packageRootIndex;
126715
+ packageName = ts.unmangleScopedPackageName(ts.getPackageNameFromTypesPackageName(moduleFile.fileName.substring(topLevelPackageNameIndex + 1, packageRootIndex)));
126716
+ if (ts.startsWith(importingFile, moduleFile.path.substring(0, topLevelNodeModulesIndex))) {
126717
+ var prevDeepestNodeModulesPath = packages.get(packageName);
126718
+ var nodeModulesPath = moduleFile.fileName.substring(0, topLevelPackageNameIndex);
126719
+ if (prevDeepestNodeModulesPath) {
126720
+ var prevDeepestNodeModulesIndex = prevDeepestNodeModulesPath.indexOf(ts.nodeModulesPathPart);
126721
+ if (topLevelNodeModulesIndex > prevDeepestNodeModulesIndex) {
126722
+ packages.set(packageName, nodeModulesPath);
126723
+ }
126724
+ }
126725
+ else {
126726
+ packages.set(packageName, nodeModulesPath);
126727
+ }
126728
+ }
126729
+ }
126730
+ }
126654
126731
  var isDefault = exportKind === 1 /* Default */;
126655
126732
  var namedSymbol = isDefault && ts.getLocalSymbolForExportDefault(symbol) || symbol;
126656
126733
  // 1. A named export must be imported by its key in `moduleSymbol.exports` or `moduleSymbol.members`.
@@ -126662,7 +126739,7 @@ var ts;
126662
126739
  // get a better name.
126663
126740
  var importedName = exportKind === 0 /* Named */ || ts.isExternalModuleSymbol(namedSymbol)
126664
126741
  ? ts.unescapeLeadingUnderscores(symbolTableKey)
126665
- : ts.getNameForExportedSymbol(namedSymbol, scriptTarget);
126742
+ : ts.getNameForExportedSymbol(namedSymbol, /*scriptTarget*/ undefined);
126666
126743
  var moduleName = ts.stripQuotes(moduleSymbol.name);
126667
126744
  var id = exportInfoId++;
126668
126745
  var target = ts.skipAlias(symbol, checker);
@@ -126677,6 +126754,7 @@ var ts;
126677
126754
  moduleName: moduleName,
126678
126755
  moduleFile: moduleFile,
126679
126756
  moduleFileName: moduleFile === null || moduleFile === void 0 ? void 0 : moduleFile.fileName,
126757
+ packageName: packageName,
126680
126758
  exportKind: exportKind,
126681
126759
  targetFlags: target.flags,
126682
126760
  isFromPackageJson: isFromPackageJson,
@@ -126695,7 +126773,17 @@ var ts;
126695
126773
  return;
126696
126774
  exportInfo.forEach(function (info, key) {
126697
126775
  var _a = parseKey(key), symbolName = _a.symbolName, ambientModuleName = _a.ambientModuleName;
126698
- action(info.map(rehydrateCachedInfo), symbolName, !!ambientModuleName, key);
126776
+ var rehydrated = info.map(rehydrateCachedInfo);
126777
+ var filtered = rehydrated.filter(function (r, i) { return isNotShadowedByDeeperNodeModulesPackage(r, info[i].packageName); });
126778
+ if (filtered.length) {
126779
+ action(filtered, function (preferCapitalized) {
126780
+ var _a = rehydrated[0], symbol = _a.symbol, exportKind = _a.exportKind;
126781
+ var namedSymbol = exportKind === 1 /* Default */ && ts.getLocalSymbolForExportDefault(symbol) || symbol;
126782
+ return preferCapitalized
126783
+ ? ts.getNameForExportedSymbol(namedSymbol, /*scriptTarget*/ undefined, /*preferCapitalized*/ true)
126784
+ : symbolName;
126785
+ }, !!ambientModuleName, key);
126786
+ }
126699
126787
  });
126700
126788
  },
126701
126789
  releaseSymbols: function () {
@@ -126795,6 +126883,12 @@ var ts;
126795
126883
  }
126796
126884
  return true;
126797
126885
  }
126886
+ function isNotShadowedByDeeperNodeModulesPackage(info, packageName) {
126887
+ if (!packageName || !info.moduleFileName)
126888
+ return true;
126889
+ var packageDeepestNodeModulesPath = packages.get(packageName);
126890
+ return !packageDeepestNodeModulesPath || ts.startsWith(info.moduleFileName, packageDeepestNodeModulesPath);
126891
+ }
126798
126892
  }
126799
126893
  ts.createCacheableExportInfoMap = createCacheableExportInfoMap;
126800
126894
  function isImportableFile(program, from, to, preferences, packageJsonFilter, moduleSpecifierResolutionHost, moduleSpecifierCache) {
@@ -126877,7 +126971,6 @@ var ts;
126877
126971
  }
126878
126972
  (_d = host.log) === null || _d === void 0 ? void 0 : _d.call(host, "getExportInfoMap: cache miss or empty; calculating new results");
126879
126973
  var compilerOptions = program.getCompilerOptions();
126880
- var scriptTarget = ts.getEmitScriptTarget(compilerOptions);
126881
126974
  var moduleCount = 0;
126882
126975
  forEachExternalModuleToImportFrom(program, host, /*useAutoImportProvider*/ true, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
126883
126976
  if (++moduleCount % 100 === 0)
@@ -126888,11 +126981,11 @@ var ts;
126888
126981
  // Note: I think we shouldn't actually see resolved module symbols here, but weird merges
126889
126982
  // can cause it to happen: see 'completionsImport_mergedReExport.ts'
126890
126983
  if (defaultInfo && isImportableSymbol(defaultInfo.symbol, checker)) {
126891
- cache.add(importingFile.path, defaultInfo.symbol, defaultInfo.exportKind === 1 /* Default */ ? "default" /* Default */ : "export=" /* ExportEquals */, moduleSymbol, moduleFile, defaultInfo.exportKind, isFromPackageJson, scriptTarget, checker);
126984
+ cache.add(importingFile.path, defaultInfo.symbol, defaultInfo.exportKind === 1 /* Default */ ? "default" /* Default */ : "export=" /* ExportEquals */, moduleSymbol, moduleFile, defaultInfo.exportKind, isFromPackageJson, checker);
126892
126985
  }
126893
126986
  checker.forEachExportAndPropertyOfModule(moduleSymbol, function (exported, key) {
126894
126987
  if (exported !== (defaultInfo === null || defaultInfo === void 0 ? void 0 : defaultInfo.symbol) && isImportableSymbol(exported, checker) && ts.addToSeen(seenExports, key)) {
126895
- cache.add(importingFile.path, exported, key, moduleSymbol, moduleFile, 0 /* Named */, isFromPackageJson, scriptTarget, checker);
126988
+ cache.add(importingFile.path, exported, key, moduleSymbol, moduleFile, 0 /* Named */, isFromPackageJson, checker);
126896
126989
  }
126897
126990
  });
126898
126991
  });
@@ -128966,6 +129059,8 @@ var ts;
128966
129059
  CompletionSource["ThisProperty"] = "ThisProperty/";
128967
129060
  /** Auto-import that comes attached to a class member snippet */
128968
129061
  CompletionSource["ClassMemberSnippet"] = "ClassMemberSnippet/";
129062
+ /** A type-only import that needs to be promoted in order to be used at the completion location */
129063
+ CompletionSource["TypeOnlyAlias"] = "TypeOnlyAlias/";
128969
129064
  })(CompletionSource = Completions.CompletionSource || (Completions.CompletionSource = {}));
128970
129065
  var SymbolOriginInfoKind;
128971
129066
  (function (SymbolOriginInfoKind) {
@@ -128975,6 +129070,7 @@ var ts;
128975
129070
  SymbolOriginInfoKind[SymbolOriginInfoKind["Promise"] = 8] = "Promise";
128976
129071
  SymbolOriginInfoKind[SymbolOriginInfoKind["Nullable"] = 16] = "Nullable";
128977
129072
  SymbolOriginInfoKind[SymbolOriginInfoKind["ResolvedExport"] = 32] = "ResolvedExport";
129073
+ SymbolOriginInfoKind[SymbolOriginInfoKind["TypeOnlyAlias"] = 64] = "TypeOnlyAlias";
128978
129074
  SymbolOriginInfoKind[SymbolOriginInfoKind["SymbolMemberNoExport"] = 2] = "SymbolMemberNoExport";
128979
129075
  SymbolOriginInfoKind[SymbolOriginInfoKind["SymbolMemberExport"] = 6] = "SymbolMemberExport";
128980
129076
  })(SymbolOriginInfoKind || (SymbolOriginInfoKind = {}));
@@ -129002,6 +129098,9 @@ var ts;
129002
129098
  function originIsNullableMember(origin) {
129003
129099
  return !!(origin.kind & 16 /* Nullable */);
129004
129100
  }
129101
+ function originIsTypeOnlyAlias(origin) {
129102
+ return !!(origin && origin.kind & 64 /* TypeOnlyAlias */);
129103
+ }
129005
129104
  var KeywordCompletionFilters;
129006
129105
  (function (KeywordCompletionFilters) {
129007
129106
  KeywordCompletionFilters[KeywordCompletionFilters["None"] = 0] = "None";
@@ -129100,7 +129199,7 @@ var ts;
129100
129199
  }
129101
129200
  switch (completionData.kind) {
129102
129201
  case 0 /* Data */:
129103
- var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext);
129202
+ var response = completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext, position);
129104
129203
  if (response === null || response === void 0 ? void 0 : response.isIncomplete) {
129105
129204
  incompleteCompletionsCache === null || incompleteCompletionsCache === void 0 ? void 0 : incompleteCompletionsCache.set(response);
129106
129205
  }
@@ -129220,7 +129319,7 @@ var ts;
129220
129319
  // StringLiteralLike locations are handled separately in stringCompletions.ts
129221
129320
  return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
129222
129321
  }
129223
- function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext) {
129322
+ function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences, formatContext, position) {
129224
129323
  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;
129225
129324
  // Verify if the file is JSX language variant
129226
129325
  if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
@@ -129233,7 +129332,7 @@ var ts;
129233
129332
  if (isUncheckedFile(sourceFile, compilerOptions)) {
129234
129333
  var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
129235
129334
  /*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);
129236
- getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
129335
+ getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries);
129237
129336
  }
129238
129337
  else {
129239
129338
  if (!isNewIdentifierLocation && (!symbols || symbols.length === 0) && keywordFilters === 0 /* None */) {
@@ -129243,16 +129342,23 @@ var ts;
129243
129342
  /*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);
129244
129343
  }
129245
129344
  if (keywordFilters !== 0 /* None */) {
129246
- var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
129345
+ var entryNames_1 = new ts.Set(entries.map(function (e) { return e.name; }));
129247
129346
  for (var _i = 0, _a = getKeywordCompletions(keywordFilters, !insideJsDocTagTypeExpression && ts.isSourceFileJS(sourceFile)); _i < _a.length; _i++) {
129248
129347
  var keywordEntry = _a[_i];
129249
- if (!entryNames.has(keywordEntry.name)) {
129348
+ if (!entryNames_1.has(keywordEntry.name)) {
129250
129349
  ts.insertSorted(entries, keywordEntry, compareCompletionEntries, /*allowDuplicates*/ true);
129251
129350
  }
129252
129351
  }
129253
129352
  }
129254
- for (var _b = 0, literals_1 = literals; _b < literals_1.length; _b++) {
129255
- var literal = literals_1[_b];
129353
+ var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
129354
+ for (var _b = 0, _c = getContextualKeywords(contextToken, position); _b < _c.length; _b++) {
129355
+ var keywordEntry = _c[_b];
129356
+ if (!entryNames.has(keywordEntry.name)) {
129357
+ ts.insertSorted(entries, keywordEntry, compareCompletionEntries, /*allowDuplicates*/ true);
129358
+ }
129359
+ }
129360
+ for (var _d = 0, literals_1 = literals; _d < literals_1.length; _d++) {
129361
+ var literal = literals_1[_d];
129256
129362
  ts.insertSorted(entries, createCompletionEntryForLiteral(sourceFile, preferences, literal), compareCompletionEntries, /*allowDuplicates*/ true);
129257
129363
  }
129258
129364
  return {
@@ -129406,6 +129512,9 @@ var ts;
129406
129512
  isSnippet = preferences.includeCompletionsWithSnippetText ? true : undefined;
129407
129513
  }
129408
129514
  }
129515
+ if ((origin === null || origin === void 0 ? void 0 : origin.kind) === 64 /* TypeOnlyAlias */) {
129516
+ hasAction = true;
129517
+ }
129409
129518
  if (preferences.includeCompletionsWithClassMemberSnippets &&
129410
129519
  preferences.includeCompletionsWithInsertText &&
129411
129520
  completionKind === 3 /* MemberLike */ &&
@@ -129750,6 +129859,9 @@ var ts;
129750
129859
  if ((origin === null || origin === void 0 ? void 0 : origin.kind) === 1 /* ThisType */) {
129751
129860
  return CompletionSource.ThisProperty;
129752
129861
  }
129862
+ if ((origin === null || origin === void 0 ? void 0 : origin.kind) === 64 /* TypeOnlyAlias */) {
129863
+ return CompletionSource.TypeOnlyAlias;
129864
+ }
129753
129865
  }
129754
129866
  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) {
129755
129867
  var _a;
@@ -129777,7 +129889,7 @@ var ts;
129777
129889
  continue;
129778
129890
  }
129779
129891
  /** True for locals; false for globals, module exports from other files, `this.` completions. */
129780
- var shouldShadowLaterSymbols = !origin && !(symbol.parent === undefined && !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === location.getSourceFile(); }));
129892
+ var shouldShadowLaterSymbols = (!origin || originIsTypeOnlyAlias(origin)) && !(symbol.parent === undefined && !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === location.getSourceFile(); }));
129781
129893
  uniques.set(name, shouldShadowLaterSymbols);
129782
129894
  ts.insertSorted(entries, entry, compareCompletionEntries, /*allowDuplicates*/ true);
129783
129895
  }
@@ -129790,6 +129902,7 @@ var ts;
129790
129902
  add: function (name) { return uniques.set(name, true); },
129791
129903
  };
129792
129904
  function shouldIncludeSymbol(symbol, symbolToSortTextIdMap) {
129905
+ var allFlags = symbol.flags;
129793
129906
  if (!ts.isSourceFile(location)) {
129794
129907
  // export = /**/ here we want to get all meanings, so any symbol is ok
129795
129908
  if (ts.isExportAssignment(location.parent)) {
@@ -129815,11 +129928,10 @@ var ts;
129815
129928
  || symbolToSortTextIdMap[ts.getSymbolId(symbolOrigin)] === 11 /* LocationPriority */)) {
129816
129929
  return false;
129817
129930
  }
129818
- // Continue with origin symbol
129819
- symbol = symbolOrigin;
129931
+ allFlags |= ts.getCombinedLocalAndExportSymbolFlags(symbolOrigin);
129820
129932
  // import m = /**/ <-- It can only access namespace (if typing import = x. this would get member symbols and not namespace)
129821
129933
  if (ts.isInRightSideOfInternalImportEqualsDeclaration(location)) {
129822
- return !!(symbol.flags & 1920 /* Namespace */);
129934
+ return !!(allFlags & 1920 /* Namespace */);
129823
129935
  }
129824
129936
  if (isTypeOnlyLocation) {
129825
129937
  // It's a type, but you can reach it by namespace.type as well
@@ -129827,7 +129939,7 @@ var ts;
129827
129939
  }
129828
129940
  }
129829
129941
  // expressions are value space (which includes the value namespaces)
129830
- return !!(ts.getCombinedLocalAndExportSymbolFlags(symbol) & 111551 /* Value */);
129942
+ return !!(allFlags & 111551 /* Value */);
129831
129943
  }
129832
129944
  }
129833
129945
  Completions.getCompletionEntriesFromSymbols = getCompletionEntriesFromSymbols;
@@ -129961,8 +130073,7 @@ var ts;
129961
130073
  Completions.createCompletionDetails = createCompletionDetails;
129962
130074
  function getCompletionEntryCodeActionsAndSourceDisplay(name, location, contextToken, origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, data, source) {
129963
130075
  if (data === null || data === void 0 ? void 0 : data.moduleSpecifier) {
129964
- var _a = getRelevantTokens(position, sourceFile), contextToken_3 = _a.contextToken, previousToken_2 = _a.previousToken;
129965
- if (previousToken_2 && getImportStatementCompletionInfo(contextToken_3 || previousToken_2).replacementNode) {
130076
+ if (previousToken && getImportStatementCompletionInfo(contextToken || previousToken).replacementNode) {
129966
130077
  // Import statement completion: 'import c|'
129967
130078
  return { codeActions: undefined, sourceDisplay: [ts.textPart(data.moduleSpecifier)] };
129968
130079
  }
@@ -129980,13 +130091,19 @@ var ts;
129980
130091
  };
129981
130092
  }
129982
130093
  }
130094
+ if (originIsTypeOnlyAlias(origin)) {
130095
+ var codeAction_1 = ts.codefix.getPromoteTypeOnlyCompletionAction(sourceFile, origin.declaration.name, program, host, formatContext, preferences);
130096
+ ts.Debug.assertIsDefined(codeAction_1, "Expected to have a code action for promoting type-only alias");
130097
+ return { codeActions: [codeAction_1], sourceDisplay: undefined };
130098
+ }
129983
130099
  if (!origin || !(originIsExport(origin) || originIsResolvedExport(origin))) {
129984
130100
  return { codeActions: undefined, sourceDisplay: undefined };
129985
130101
  }
129986
130102
  var checker = origin.isFromPackageJson ? host.getPackageJsonAutoImportProvider().getTypeChecker() : program.getTypeChecker();
129987
130103
  var moduleSymbol = origin.moduleSymbol;
129988
130104
  var targetSymbol = checker.getMergedSymbol(ts.skipAlias(symbol.exportSymbol || symbol, checker));
129989
- 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;
130105
+ var isJsxOpeningTagName = (contextToken === null || contextToken === void 0 ? void 0 : contextToken.kind) === 29 /* LessThanToken */ && ts.isJsxOpeningLikeElement(contextToken.parent);
130106
+ 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;
129990
130107
  ts.Debug.assert(!(data === null || data === void 0 ? void 0 : data.moduleSpecifier) || moduleSpecifier === data.moduleSpecifier);
129991
130108
  return { sourceDisplay: [ts.textPart(moduleSpecifier)], codeActions: [codeAction] };
129992
130109
  }
@@ -130656,21 +130773,29 @@ var ts;
130656
130773
  var scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile;
130657
130774
  isInSnippetScope = isSnippetScope(scopeNode);
130658
130775
  var symbolMeanings = (isTypeOnlyLocation ? 0 /* None */ : 111551 /* Value */) | 788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */;
130776
+ var typeOnlyAliasNeedsPromotion = previousToken && !ts.isValidTypeOnlyAliasUseSite(previousToken);
130659
130777
  symbols = ts.concatenate(symbols, typeChecker.getSymbolsInScope(scopeNode, symbolMeanings));
130660
130778
  ts.Debug.assertEachIsDefined(symbols, "getSymbolsInScope() should all be defined");
130661
- for (var _i = 0, symbols_1 = symbols; _i < symbols_1.length; _i++) {
130662
- var symbol = symbols_1[_i];
130779
+ for (var i = 0; i < symbols.length; i++) {
130780
+ var symbol = symbols[i];
130663
130781
  if (!typeChecker.isArgumentsSymbol(symbol) &&
130664
130782
  !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === sourceFile; })) {
130665
130783
  symbolToSortTextIdMap[ts.getSymbolId(symbol)] = 15 /* GlobalsOrKeywords */;
130666
130784
  }
130785
+ if (typeOnlyAliasNeedsPromotion && !(symbol.flags & 111551 /* Value */)) {
130786
+ var typeOnlyAliasDeclaration = symbol.declarations && ts.find(symbol.declarations, ts.isTypeOnlyImportOrExportDeclaration);
130787
+ if (typeOnlyAliasDeclaration) {
130788
+ var origin = { kind: 64 /* TypeOnlyAlias */, declaration: typeOnlyAliasDeclaration };
130789
+ symbolToOriginInfoMap[i] = origin;
130790
+ }
130791
+ }
130667
130792
  }
130668
130793
  // Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions`
130669
130794
  if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== 303 /* SourceFile */) {
130670
130795
  var thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false);
130671
130796
  if (thisType && !isProbablyGlobalType(thisType, sourceFile, typeChecker)) {
130672
- for (var _a = 0, _b = getPropertiesForCompletion(thisType, typeChecker); _a < _b.length; _a++) {
130673
- var symbol = _b[_a];
130797
+ for (var _i = 0, _a = getPropertiesForCompletion(thisType, typeChecker); _i < _a.length; _i++) {
130798
+ var symbol = _a[_i];
130674
130799
  symbolToOriginInfoMap[symbols.length] = { kind: 1 /* ThisType */ };
130675
130800
  symbols.push(symbol);
130676
130801
  symbolToSortTextIdMap[ts.getSymbolId(symbol)] = 14 /* SuggestedClassMembers */;
@@ -130773,7 +130898,8 @@ var ts;
130773
130898
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
130774
130899
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
130775
130900
  resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, preferences, !!importCompletionNode, function (context) {
130776
- exportInfo.forEach(sourceFile.path, function (info, symbolName, isFromAmbientModule, exportMapKey) {
130901
+ exportInfo.forEach(sourceFile.path, function (info, getSymbolName, isFromAmbientModule, exportMapKey) {
130902
+ var symbolName = getSymbolName(/*preferCapitalized*/ isRightOfOpenTag);
130777
130903
  if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
130778
130904
  return;
130779
130905
  if (!detailsEntryId && ts.isStringANonContextualKeyword(symbolName))
@@ -130783,6 +130909,10 @@ var ts;
130783
130909
  return;
130784
130910
  if (isTypeOnlyLocation && !(info[0].targetFlags & (1536 /* Module */ | 788968 /* Type */)))
130785
130911
  return;
130912
+ // Do not try to auto-import something with a lowercase first letter for a JSX tag
130913
+ var firstChar = symbolName.charCodeAt(0);
130914
+ if (isRightOfOpenTag && (firstChar < 65 /* A */ || firstChar > 90 /* Z */))
130915
+ return;
130786
130916
  var isCompletionDetailsMatch = detailsEntryId && ts.some(info, function (i) { return detailsEntryId.source === ts.stripQuotes(i.moduleSymbol.name); });
130787
130917
  if (isCompletionDetailsMatch || !detailsEntryId && charactersFuzzyMatchInString(symbolName, lowerCaseTokenText)) {
130788
130918
  var defaultExportInfo = ts.find(info, isImportableExportInfo);
@@ -130859,16 +130989,19 @@ var ts;
130859
130989
  return true;
130860
130990
  }
130861
130991
  if (contextToken.kind === 31 /* GreaterThanToken */ && contextToken.parent) {
130992
+ // <Component<string> /**/ />
130993
+ // <Component<string> /**/ ><Component>
130994
+ // - contextToken: GreaterThanToken (before cursor)
130995
+ // - location: JsxSelfClosingElement or JsxOpeningElement
130996
+ // - contextToken.parent === location
130997
+ if (location === contextToken.parent && (location.kind === 279 /* JsxOpeningElement */ || location.kind === 278 /* JsxSelfClosingElement */)) {
130998
+ return false;
130999
+ }
130862
131000
  if (contextToken.parent.kind === 279 /* JsxOpeningElement */) {
130863
- // Two possibilities:
130864
- // 1. <div>/**/
130865
- // - contextToken: GreaterThanToken (before cursor)
130866
- // - location: JSXElement
130867
- // - different parents (JSXOpeningElement, JSXElement)
130868
- // 2. <Component<string> /**/>
130869
- // - contextToken: GreaterThanToken (before cursor)
130870
- // - location: GreaterThanToken (after cursor)
130871
- // - same parent (JSXOpeningElement)
131001
+ // <div>/**/
131002
+ // - contextToken: GreaterThanToken (before cursor)
131003
+ // - location: JSXElement
131004
+ // - different parents (JSXOpeningElement, JSXElement)
130872
131005
  return location.parent.kind !== 279 /* JsxOpeningElement */;
130873
131006
  }
130874
131007
  if (contextToken.parent.kind === 280 /* JsxClosingElement */ || contextToken.parent.kind === 278 /* JsxSelfClosingElement */) {
@@ -131775,6 +131908,34 @@ var ts;
131775
131908
  function keywordForNode(node) {
131776
131909
  return ts.isIdentifier(node) ? node.originalKeywordKind || 0 /* Unknown */ : node.kind;
131777
131910
  }
131911
+ function getContextualKeywords(contextToken, position) {
131912
+ var entries = [];
131913
+ /**
131914
+ * An `AssertClause` can come after an import declaration:
131915
+ * import * from "foo" |
131916
+ * import "foo" |
131917
+ * or after a re-export declaration that has a module specifier:
131918
+ * export { foo } from "foo" |
131919
+ * Source: https://tc39.es/proposal-import-assertions/
131920
+ */
131921
+ if (contextToken) {
131922
+ var file = contextToken.getSourceFile();
131923
+ var parent = contextToken.parent;
131924
+ var tokenLine = file.getLineAndCharacterOfPosition(contextToken.end).line;
131925
+ var currentLine = file.getLineAndCharacterOfPosition(position).line;
131926
+ if ((ts.isImportDeclaration(parent) || ts.isExportDeclaration(parent) && parent.moduleSpecifier)
131927
+ && contextToken === parent.moduleSpecifier
131928
+ && tokenLine === currentLine) {
131929
+ entries.push({
131930
+ name: ts.tokenToString(129 /* AssertKeyword */),
131931
+ kind: "keyword" /* keyword */,
131932
+ kindModifiers: "" /* none */,
131933
+ sortText: SortText.GlobalsOrKeywords,
131934
+ });
131935
+ }
131936
+ }
131937
+ return entries;
131938
+ }
131778
131939
  /** Get the corresponding JSDocTag node if the position is in a jsDoc comment */
131779
131940
  function getJsDocTagAtPosition(node, position) {
131780
131941
  return ts.findAncestor(node, function (n) {
@@ -132069,10 +132230,14 @@ var ts;
132069
132230
  /** True if symbol is a type or a module containing at least one type. */
132070
132231
  function symbolCanBeReferencedAtTypeLocation(symbol, checker, seenModules) {
132071
132232
  if (seenModules === void 0) { seenModules = new ts.Map(); }
132072
- var sym = ts.skipAlias(symbol.exportSymbol || symbol, checker);
132073
- return !!(sym.flags & 788968 /* Type */) || checker.isUnknownSymbol(sym) ||
132074
- !!(sym.flags & 1536 /* Module */) && ts.addToSeen(seenModules, ts.getSymbolId(sym)) &&
132075
- checker.getExportsOfModule(sym).some(function (e) { return symbolCanBeReferencedAtTypeLocation(e, checker, seenModules); });
132233
+ // Since an alias can be merged with a local declaration, we need to test both the alias and its target.
132234
+ // This code used to just test the result of `skipAlias`, but that would ignore any locally introduced meanings.
132235
+ return nonAliasCanBeReferencedAtTypeLocation(symbol) || nonAliasCanBeReferencedAtTypeLocation(ts.skipAlias(symbol.exportSymbol || symbol, checker));
132236
+ function nonAliasCanBeReferencedAtTypeLocation(symbol) {
132237
+ return !!(symbol.flags & 788968 /* Type */) || checker.isUnknownSymbol(symbol) ||
132238
+ !!(symbol.flags & 1536 /* Module */) && ts.addToSeen(seenModules, ts.getSymbolId(symbol)) &&
132239
+ checker.getExportsOfModule(symbol).some(function (e) { return symbolCanBeReferencedAtTypeLocation(e, checker, seenModules); });
132240
+ }
132076
132241
  }
132077
132242
  function isDeprecated(symbol, checker) {
132078
132243
  var declarations = ts.skipAlias(symbol, checker).declarations;
@@ -134326,8 +134491,8 @@ var ts;
134326
134491
  var sourceId = ts.getNodeId(sourceFile);
134327
134492
  var seenSymbols = this.sourceFileToSeenSymbols[sourceId] || (this.sourceFileToSeenSymbols[sourceId] = new ts.Set());
134328
134493
  var anyNewSymbols = false;
134329
- for (var _i = 0, symbols_2 = symbols; _i < symbols_2.length; _i++) {
134330
- var sym = symbols_2[_i];
134494
+ for (var _i = 0, symbols_1 = symbols; _i < symbols_1.length; _i++) {
134495
+ var sym = symbols_1[_i];
134331
134496
  anyNewSymbols = ts.tryAddToSet(seenSymbols, ts.getSymbolId(sym)) || anyNewSymbols;
134332
134497
  }
134333
134498
  return anyNewSymbols;
@@ -141287,6 +141452,8 @@ var ts;
141287
141452
  }
141288
141453
  if (flags & 16 /* Function */)
141289
141454
  return isLocalVariableOrFunction(symbol) ? "local function" /* localFunctionElement */ : "function" /* functionElement */;
141455
+ // FIXME: getter and setter use the same symbol. And it is rare to use only setter without getter, so in most cases the symbol always has getter flag.
141456
+ // So, even when the location is just on the declaration of setter, this function returns getter.
141290
141457
  if (flags & 32768 /* GetAccessor */)
141291
141458
  return "getter" /* memberGetAccessorElement */;
141292
141459
  if (flags & 65536 /* SetAccessor */)
@@ -141373,9 +141540,24 @@ var ts;
141373
141540
  }
141374
141541
  // Class at constructor site need to be shown as constructor apart from property,method, vars
141375
141542
  if (symbolKind !== "" /* unknown */ || symbolFlags & 32 /* Class */ || symbolFlags & 2097152 /* Alias */) {
141376
- // If it is accessor they are allowed only if location is at name of the accessor
141543
+ // If symbol is accessor, they are allowed only if location is at declaration identifier of the accessor
141377
141544
  if (symbolKind === "getter" /* memberGetAccessorElement */ || symbolKind === "setter" /* memberSetAccessorElement */) {
141378
- symbolKind = "property" /* memberVariableElement */;
141545
+ var declaration = ts.find(symbol.declarations, function (declaration) { return declaration.name === location; });
141546
+ if (declaration) {
141547
+ switch (declaration.kind) {
141548
+ case 171 /* GetAccessor */:
141549
+ symbolKind = "getter" /* memberGetAccessorElement */;
141550
+ break;
141551
+ case 172 /* SetAccessor */:
141552
+ symbolKind = "setter" /* memberSetAccessorElement */;
141553
+ break;
141554
+ default:
141555
+ ts.Debug.assertNever(declaration);
141556
+ }
141557
+ }
141558
+ else {
141559
+ symbolKind = "property" /* memberVariableElement */;
141560
+ }
141379
141561
  }
141380
141562
  var signature = void 0;
141381
141563
  type = isThisExpression ? typeChecker.getTypeAtLocation(location) : typeChecker.getTypeOfSymbolAtLocation(symbol, location);
@@ -141689,6 +141871,8 @@ var ts;
141689
141871
  }
141690
141872
  // For properties, variables and local vars: show the type
141691
141873
  if (symbolKind === "property" /* memberVariableElement */ ||
141874
+ symbolKind === "getter" /* memberGetAccessorElement */ ||
141875
+ symbolKind === "setter" /* memberSetAccessorElement */ ||
141692
141876
  symbolKind === "JSX attribute" /* jsxAttribute */ ||
141693
141877
  symbolFlags & 3 /* Variable */ ||
141694
141878
  symbolKind === "local var" /* localVariableElement */ ||
@@ -141759,7 +141943,7 @@ var ts;
141759
141943
  }
141760
141944
  }
141761
141945
  if (tags.length === 0 && !hasMultipleSignatures) {
141762
- tags = symbol.getJsDocTags(typeChecker);
141946
+ tags = symbol.getContextualJsDocTags(enclosingDeclaration, typeChecker);
141763
141947
  }
141764
141948
  if (documentation.length === 0 && documentationFromAlias) {
141765
141949
  documentation = documentationFromAlias;
@@ -145179,6 +145363,7 @@ var ts;
145179
145363
  ChangeTracker.prototype.delete = function (sourceFile, node) {
145180
145364
  this.deletedNodes.push({ sourceFile: sourceFile, node: node });
145181
145365
  };
145366
+ /** Stop! Consider using `delete` instead, which has logic for deleting nodes from delimited lists. */
145182
145367
  ChangeTracker.prototype.deleteNode = function (sourceFile, node, options) {
145183
145368
  if (options === void 0) { options = { leadingTriviaOption: LeadingTriviaOption.IncludeAll }; }
145184
145369
  this.deleteRange(sourceFile, getAdjustedRange(sourceFile, node, node, options));
@@ -145582,6 +145767,15 @@ var ts;
145582
145767
  ChangeTracker.prototype.insertExportModifier = function (sourceFile, node) {
145583
145768
  this.insertText(sourceFile, node.getStart(sourceFile), "export ");
145584
145769
  };
145770
+ ChangeTracker.prototype.insertImportSpecifierAtIndex = function (sourceFile, importSpecifier, namedImports, index) {
145771
+ var prevSpecifier = namedImports.elements[index - 1];
145772
+ if (prevSpecifier) {
145773
+ this.insertNodeInListAfter(sourceFile, prevSpecifier, importSpecifier);
145774
+ }
145775
+ else {
145776
+ this.insertNodeBefore(sourceFile, namedImports.elements[0], importSpecifier, !ts.positionsAreOnSameLine(namedImports.elements[0].getStart(), namedImports.parent.parent.getStart(), sourceFile));
145777
+ }
145778
+ };
145585
145779
  /**
145586
145780
  * This function should be used to insert nodes in lists when nodes don't carry separators as the part of the node range,
145587
145781
  * i.e. arguments in arguments lists, parameters in parameter lists etc.
@@ -149084,7 +149278,8 @@ var ts;
149084
149278
  ts.Diagnostics.Cannot_find_namespace_0.code,
149085
149279
  ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code,
149086
149280
  ts.Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here.code,
149087
- ts.Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer.code
149281
+ ts.Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer.code,
149282
+ ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type.code,
149088
149283
  ];
149089
149284
  codefix.registerCodeFix({
149090
149285
  errorCodes: errorCodes,
@@ -149093,9 +149288,10 @@ var ts;
149093
149288
  var info = getFixesInfo(context, errorCode, span.start, /*useAutoImportProvider*/ true);
149094
149289
  if (!info)
149095
149290
  return undefined;
149096
- var fixes = info.fixes, symbolName = info.symbolName;
149291
+ var fixes = info.fixes, symbolName = info.symbolName, errorIdentifierText = info.errorIdentifierText;
149097
149292
  var quotePreference = ts.getQuotePreference(sourceFile, preferences);
149098
- return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, program.getCompilerOptions()); });
149293
+ return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix,
149294
+ /*includeSymbolNameInDescription*/ symbolName !== errorIdentifierText, quotePreference, program.getCompilerOptions()); });
149099
149295
  },
149100
149296
  fixIds: [importFixId],
149101
149297
  getAllCodeActions: function (context) {
@@ -149130,11 +149326,11 @@ var ts;
149130
149326
  var symbolName = ts.getNameForExportedSymbol(exportedSymbol, ts.getEmitScriptTarget(compilerOptions));
149131
149327
  var checker = program.getTypeChecker();
149132
149328
  var symbol = checker.getMergedSymbol(ts.skipAlias(exportedSymbol, checker));
149133
- var exportInfos = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, host, program, preferences, useAutoImportProvider);
149329
+ var exportInfos = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, /*isJsxTagName*/ false, host, program, preferences, useAutoImportProvider);
149134
149330
  var useRequire = shouldUseRequire(sourceFile, program);
149135
149331
  var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
149136
149332
  if (fix) {
149137
- addImport({ fixes: [fix], symbolName: symbolName });
149333
+ addImport({ fixes: [fix], symbolName: symbolName, errorIdentifierText: undefined });
149138
149334
  }
149139
149335
  }
149140
149336
  function addImport(info) {
@@ -149189,6 +149385,9 @@ var ts;
149189
149385
  }
149190
149386
  break;
149191
149387
  }
149388
+ case 4 /* PromoteTypeOnly */:
149389
+ // Excluding from fix-all
149390
+ break;
149192
149391
  default:
149193
149392
  ts.Debug.assertNever(fix, "fix wasn't never - got kind " + fix.kind);
149194
149393
  }
@@ -149280,6 +149479,7 @@ var ts;
149280
149479
  ImportFixKind[ImportFixKind["JsdocTypeImport"] = 1] = "JsdocTypeImport";
149281
149480
  ImportFixKind[ImportFixKind["AddToExisting"] = 2] = "AddToExisting";
149282
149481
  ImportFixKind[ImportFixKind["AddNew"] = 3] = "AddNew";
149482
+ ImportFixKind[ImportFixKind["PromoteTypeOnly"] = 4] = "PromoteTypeOnly";
149283
149483
  })(ImportFixKind || (ImportFixKind = {}));
149284
149484
  // These should not be combined as bitflags, but are given powers of 2 values to
149285
149485
  // easily detect conflicts between `NotAllowed` and `Required` by giving them a unique sum.
@@ -149291,20 +149491,29 @@ var ts;
149291
149491
  AddAsTypeOnly[AddAsTypeOnly["Required"] = 2] = "Required";
149292
149492
  AddAsTypeOnly[AddAsTypeOnly["NotAllowed"] = 4] = "NotAllowed";
149293
149493
  })(AddAsTypeOnly || (AddAsTypeOnly = {}));
149294
- function getImportCompletionAction(targetSymbol, moduleSymbol, sourceFile, symbolName, host, program, formatContext, position, preferences) {
149494
+ function getImportCompletionAction(targetSymbol, moduleSymbol, sourceFile, symbolName, isJsxTagName, host, program, formatContext, position, preferences) {
149295
149495
  var compilerOptions = program.getCompilerOptions();
149296
149496
  var exportInfos = ts.pathIsBareSpecifier(ts.stripQuotes(moduleSymbol.name))
149297
149497
  ? [getSymbolExportInfoForSymbol(targetSymbol, moduleSymbol, program, host)]
149298
- : getAllReExportingModules(sourceFile, targetSymbol, moduleSymbol, symbolName, host, program, preferences, /*useAutoImportProvider*/ true);
149498
+ : getAllReExportingModules(sourceFile, targetSymbol, moduleSymbol, symbolName, isJsxTagName, host, program, preferences, /*useAutoImportProvider*/ true);
149299
149499
  var useRequire = shouldUseRequire(sourceFile, program);
149300
149500
  var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
149301
149501
  var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences));
149302
149502
  return {
149303
149503
  moduleSpecifier: fix.moduleSpecifier,
149304
- codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, ts.getQuotePreference(sourceFile, preferences), compilerOptions))
149504
+ codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix,
149505
+ /*includeSymbolNameInDescription*/ false, ts.getQuotePreference(sourceFile, preferences), compilerOptions))
149305
149506
  };
149306
149507
  }
149307
149508
  codefix.getImportCompletionAction = getImportCompletionAction;
149509
+ function getPromoteTypeOnlyCompletionAction(sourceFile, symbolToken, program, host, formatContext, preferences) {
149510
+ var compilerOptions = program.getCompilerOptions();
149511
+ var symbolName = getSymbolName(sourceFile, program.getTypeChecker(), symbolToken, compilerOptions);
149512
+ var fix = getTypeOnlyPromotionFix(sourceFile, symbolToken, symbolName, program);
149513
+ var includeSymbolNameInDescription = symbolName !== symbolToken.text;
149514
+ return fix && codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, includeSymbolNameInDescription, 1 /* Double */, compilerOptions));
149515
+ }
149516
+ codefix.getPromoteTypeOnlyCompletionAction = getPromoteTypeOnlyCompletionAction;
149308
149517
  function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
149309
149518
  ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
149310
149519
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
@@ -149334,7 +149543,7 @@ var ts;
149334
149543
  }
149335
149544
  }
149336
149545
  }
149337
- function getAllReExportingModules(importingFile, targetSymbol, exportingModuleSymbol, symbolName, host, program, preferences, useAutoImportProvider) {
149546
+ function getAllReExportingModules(importingFile, targetSymbol, exportingModuleSymbol, symbolName, isJsxTagName, host, program, preferences, useAutoImportProvider) {
149338
149547
  var result = [];
149339
149548
  var compilerOptions = program.getCompilerOptions();
149340
149549
  var getModuleSpecifierResolutionHost = ts.memoizeOne(function (isFromPackageJson) {
@@ -149347,7 +149556,7 @@ var ts;
149347
149556
  return;
149348
149557
  }
149349
149558
  var defaultInfo = ts.getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
149350
- if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions)) === symbolName) && ts.skipAlias(defaultInfo.symbol, checker) === targetSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
149559
+ if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions), isJsxTagName) === symbolName) && ts.skipAlias(defaultInfo.symbol, checker) === targetSymbol && isImportable(program, moduleFile, isFromPackageJson)) {
149351
149560
  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 });
149352
149561
  }
149353
149562
  for (var _i = 0, _a = checker.getExportsAndPropertiesOfModule(moduleSymbol); _i < _a.length; _i++) {
@@ -149585,9 +149794,21 @@ var ts;
149585
149794
  }
149586
149795
  function getFixesInfo(context, errorCode, pos, useAutoImportProvider) {
149587
149796
  var symbolToken = ts.getTokenAtPosition(context.sourceFile, pos);
149588
- var info = errorCode === ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code
149589
- ? getFixesInfoForUMDImport(context, symbolToken)
149590
- : ts.isIdentifier(symbolToken) ? getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider) : undefined;
149797
+ var info;
149798
+ if (errorCode === ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code) {
149799
+ info = getFixesInfoForUMDImport(context, symbolToken);
149800
+ }
149801
+ else if (!ts.isIdentifier(symbolToken)) {
149802
+ return undefined;
149803
+ }
149804
+ else if (errorCode === ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type.code) {
149805
+ var symbolName_1 = getSymbolName(context.sourceFile, context.program.getTypeChecker(), symbolToken, context.program.getCompilerOptions());
149806
+ var fix = getTypeOnlyPromotionFix(context.sourceFile, symbolToken, symbolName_1, context.program);
149807
+ return fix && { fixes: [fix], symbolName: symbolName_1, errorIdentifierText: symbolToken.text };
149808
+ }
149809
+ else {
149810
+ info = getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider);
149811
+ }
149591
149812
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(context.sourceFile, context.preferences, context.host);
149592
149813
  return info && __assign(__assign({}, info), { fixes: sortFixes(info.fixes, context.sourceFile, context.program, packageJsonImportFilter) });
149593
149814
  }
@@ -149628,6 +149849,7 @@ var ts;
149628
149849
  return 0 /* EqualTo */;
149629
149850
  }
149630
149851
  function getFixesInfoForUMDImport(_a, token) {
149852
+ var _b;
149631
149853
  var sourceFile = _a.sourceFile, program = _a.program, host = _a.host, preferences = _a.preferences;
149632
149854
  var checker = program.getTypeChecker();
149633
149855
  var umdSymbol = getUmdSymbol(token, checker);
@@ -149638,7 +149860,7 @@ var ts;
149638
149860
  var exportInfos = [{ symbol: umdSymbol, moduleSymbol: symbol, moduleFileName: undefined, exportKind: 3 /* UMD */, targetFlags: symbol.flags, isFromPackageJson: false }];
149639
149861
  var useRequire = shouldUseRequire(sourceFile, program);
149640
149862
  var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences);
149641
- return { fixes: fixes, symbolName: symbolName };
149863
+ return { fixes: fixes, symbolName: symbolName, errorIdentifierText: (_b = ts.tryCast(token, ts.isIdentifier)) === null || _b === void 0 ? void 0 : _b.text };
149642
149864
  }
149643
149865
  function getUmdSymbol(token, checker) {
149644
149866
  // try the identifier to see if it is the umd symbol
@@ -149704,12 +149926,22 @@ var ts;
149704
149926
  ts.Debug.assert(symbolName !== "default" /* Default */, "'default' isn't a legal identifier and couldn't occur here");
149705
149927
  var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(symbolToken);
149706
149928
  var useRequire = shouldUseRequire(sourceFile, program);
149707
- var exportInfos = getExportInfos(symbolName, ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
149929
+ var exportInfos = getExportInfos(symbolName, ts.isJSXTagName(symbolToken), ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
149708
149930
  var fixes = ts.arrayFrom(ts.flatMapIterator(exportInfos.entries(), function (_a) {
149709
149931
  var _ = _a[0], exportInfos = _a[1];
149710
149932
  return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences);
149711
149933
  }));
149712
- return { fixes: fixes, symbolName: symbolName };
149934
+ return { fixes: fixes, symbolName: symbolName, errorIdentifierText: symbolToken.text };
149935
+ }
149936
+ function getTypeOnlyPromotionFix(sourceFile, symbolToken, symbolName, program) {
149937
+ var checker = program.getTypeChecker();
149938
+ var symbol = checker.resolveName(symbolName, symbolToken, 111551 /* Value */, /*excludeGlobals*/ true);
149939
+ if (!symbol)
149940
+ return undefined;
149941
+ var typeOnlyAliasDeclaration = checker.getTypeOnlyAliasDeclaration(symbol);
149942
+ if (!typeOnlyAliasDeclaration || ts.getSourceFileOfNode(typeOnlyAliasDeclaration) !== sourceFile)
149943
+ return undefined;
149944
+ return { kind: 4 /* PromoteTypeOnly */, typeOnlyAliasDeclaration: typeOnlyAliasDeclaration };
149713
149945
  }
149714
149946
  function jsxModeNeedsExplicitImport(jsx) {
149715
149947
  return jsx === 2 /* React */ || jsx === 3 /* ReactNative */;
@@ -149718,14 +149950,20 @@ var ts;
149718
149950
  var parent = symbolToken.parent;
149719
149951
  if ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) && parent.tagName === symbolToken && jsxModeNeedsExplicitImport(compilerOptions.jsx)) {
149720
149952
  var jsxNamespace = checker.getJsxNamespace(sourceFile);
149721
- if (ts.isIntrinsicJsxName(symbolToken.text) || !checker.resolveName(jsxNamespace, parent, 111551 /* Value */, /*excludeGlobals*/ true)) {
149953
+ if (needsJsxNamespaceFix(jsxNamespace, symbolToken, checker)) {
149722
149954
  return jsxNamespace;
149723
149955
  }
149724
149956
  }
149725
149957
  return symbolToken.text;
149726
149958
  }
149959
+ function needsJsxNamespaceFix(jsxNamespace, symbolToken, checker) {
149960
+ if (ts.isIntrinsicJsxName(symbolToken.text))
149961
+ return true; // If we were triggered by a matching error code on an intrinsic, the error must have been about missing the JSX factory
149962
+ var namespaceSymbol = checker.resolveName(jsxNamespace, symbolToken, 111551 /* Value */, /*excludeGlobals*/ true);
149963
+ return !namespaceSymbol || ts.some(namespaceSymbol.declarations, ts.isTypeOnlyImportOrExportDeclaration) && !(namespaceSymbol.flags & 111551 /* Value */);
149964
+ }
149727
149965
  // Returns a map from an exported symbol's ID to a list of every way it's (re-)exported.
149728
- function getExportInfos(symbolName, currentTokenMeaning, cancellationToken, fromFile, program, useAutoImportProvider, host, preferences) {
149966
+ function getExportInfos(symbolName, isJsxTagName, currentTokenMeaning, cancellationToken, fromFile, program, useAutoImportProvider, host, preferences) {
149729
149967
  var _a;
149730
149968
  // For each original symbol, keep all re-exports of that symbol together so we can call `getCodeActionsForImport` on the whole group at once.
149731
149969
  // Maps symbol id to info for modules providing that symbol (original export + re-exports).
@@ -149748,7 +149986,7 @@ var ts;
149748
149986
  cancellationToken.throwIfCancellationRequested();
149749
149987
  var compilerOptions = program.getCompilerOptions();
149750
149988
  var defaultInfo = ts.getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
149751
- if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions)) === symbolName) && symbolHasMeaning(defaultInfo.symbolForMeaning, currentTokenMeaning)) {
149989
+ if (defaultInfo && (defaultInfo.name === symbolName || moduleSymbolToValidIdentifier(moduleSymbol, ts.getEmitScriptTarget(compilerOptions), isJsxTagName) === symbolName) && symbolHasMeaning(defaultInfo.symbolForMeaning, currentTokenMeaning)) {
149752
149990
  addSymbol(moduleSymbol, sourceFile, defaultInfo.symbol, defaultInfo.exportKind, program, isFromPackageJson);
149753
149991
  }
149754
149992
  // check exports with the same name
@@ -149788,14 +150026,14 @@ var ts;
149788
150026
  // allowSyntheticDefaultImports/esModuleInterop is enabled.
149789
150027
  return allowSyntheticDefaults ? 1 /* Default */ : 3 /* CommonJS */;
149790
150028
  }
149791
- function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
150029
+ function codeActionForFix(context, sourceFile, symbolName, fix, includeSymbolNameInDescription, quotePreference, compilerOptions) {
149792
150030
  var diag;
149793
150031
  var changes = ts.textChanges.ChangeTracker.with(context, function (tracker) {
149794
- diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference, compilerOptions);
150032
+ diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, includeSymbolNameInDescription, quotePreference, compilerOptions);
149795
150033
  });
149796
150034
  return codefix.createCodeFixAction(codefix.importFixName, changes, diag, importFixId, ts.Diagnostics.Add_all_missing_imports);
149797
150035
  }
149798
- function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
150036
+ function codeActionForFixWorker(changes, sourceFile, symbolName, fix, includeSymbolNameInDescription, quotePreference, compilerOptions) {
149799
150037
  switch (fix.kind) {
149800
150038
  case 0 /* UseNamespace */:
149801
150039
  addNamespaceQualifier(changes, sourceFile, fix);
@@ -149807,11 +150045,9 @@ var ts;
149807
150045
  var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly, moduleSpecifier = fix.moduleSpecifier;
149808
150046
  doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined, importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : ts.emptyArray, compilerOptions);
149809
150047
  var moduleSpecifierWithoutQuotes = ts.stripQuotes(moduleSpecifier);
149810
- return [
149811
- 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,
149812
- symbolName,
149813
- moduleSpecifierWithoutQuotes
149814
- ]; // you too!
150048
+ return includeSymbolNameInDescription
150049
+ ? [ts.Diagnostics.Import_0_from_1, symbolName, moduleSpecifierWithoutQuotes]
150050
+ : [ts.Diagnostics.Update_import_from_0, moduleSpecifierWithoutQuotes];
149815
150051
  }
149816
150052
  case 3 /* AddNew */: {
149817
150053
  var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier, addAsTypeOnly = fix.addAsTypeOnly, useRequire = fix.useRequire;
@@ -149820,12 +150056,84 @@ var ts;
149820
150056
  var namedImports = importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : undefined;
149821
150057
  var namespaceLikeImport = importKind === 2 /* Namespace */ || importKind === 3 /* CommonJS */ ? { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
149822
150058
  ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport), /*blankLineBetween*/ true);
149823
- return [importKind === 1 /* Default */ ? ts.Diagnostics.Import_default_0_from_module_1 : ts.Diagnostics.Import_0_from_module_1, symbolName, moduleSpecifier];
150059
+ return includeSymbolNameInDescription
150060
+ ? [ts.Diagnostics.Import_0_from_1, symbolName, moduleSpecifier]
150061
+ : [ts.Diagnostics.Add_import_from_0, moduleSpecifier];
150062
+ }
150063
+ case 4 /* PromoteTypeOnly */: {
150064
+ var typeOnlyAliasDeclaration = fix.typeOnlyAliasDeclaration;
150065
+ var promotedDeclaration = promoteFromTypeOnly(changes, typeOnlyAliasDeclaration, compilerOptions, sourceFile);
150066
+ return promotedDeclaration.kind === 269 /* ImportSpecifier */
150067
+ ? [ts.Diagnostics.Remove_type_from_import_of_0_from_1, symbolName, getModuleSpecifierText(promotedDeclaration.parent.parent)]
150068
+ : [ts.Diagnostics.Remove_type_from_import_declaration_from_0, getModuleSpecifierText(promotedDeclaration)];
149824
150069
  }
149825
150070
  default:
149826
150071
  return ts.Debug.assertNever(fix, "Unexpected fix kind " + fix.kind);
149827
150072
  }
149828
150073
  }
150074
+ function getModuleSpecifierText(promotedDeclaration) {
150075
+ var _a, _b;
150076
+ return promotedDeclaration.kind === 264 /* ImportEqualsDeclaration */
150077
+ ? ((_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()
150078
+ : ts.cast(promotedDeclaration.parent.moduleSpecifier, ts.isStringLiteral).text;
150079
+ }
150080
+ function promoteFromTypeOnly(changes, aliasDeclaration, compilerOptions, sourceFile) {
150081
+ // See comment in `doAddExistingFix` on constant with the same name.
150082
+ var convertExistingToTypeOnly = compilerOptions.preserveValueImports && compilerOptions.isolatedModules;
150083
+ switch (aliasDeclaration.kind) {
150084
+ case 269 /* ImportSpecifier */:
150085
+ if (aliasDeclaration.isTypeOnly) {
150086
+ if (aliasDeclaration.parent.elements.length > 1 && ts.OrganizeImports.importSpecifiersAreSorted(aliasDeclaration.parent.elements)) {
150087
+ changes.delete(sourceFile, aliasDeclaration);
150088
+ var newSpecifier = ts.factory.updateImportSpecifier(aliasDeclaration, /*isTypeOnly*/ false, aliasDeclaration.propertyName, aliasDeclaration.name);
150089
+ var insertionIndex = ts.OrganizeImports.getImportSpecifierInsertionIndex(aliasDeclaration.parent.elements, newSpecifier);
150090
+ changes.insertImportSpecifierAtIndex(sourceFile, newSpecifier, aliasDeclaration.parent, insertionIndex);
150091
+ }
150092
+ else {
150093
+ changes.deleteRange(sourceFile, aliasDeclaration.getFirstToken());
150094
+ }
150095
+ return aliasDeclaration;
150096
+ }
150097
+ else {
150098
+ ts.Debug.assert(aliasDeclaration.parent.parent.isTypeOnly);
150099
+ promoteImportClause(aliasDeclaration.parent.parent);
150100
+ return aliasDeclaration.parent.parent;
150101
+ }
150102
+ case 266 /* ImportClause */:
150103
+ promoteImportClause(aliasDeclaration);
150104
+ return aliasDeclaration;
150105
+ case 267 /* NamespaceImport */:
150106
+ promoteImportClause(aliasDeclaration.parent);
150107
+ return aliasDeclaration.parent;
150108
+ case 264 /* ImportEqualsDeclaration */:
150109
+ changes.deleteRange(sourceFile, aliasDeclaration.getChildAt(1));
150110
+ return aliasDeclaration;
150111
+ default:
150112
+ ts.Debug.failBadSyntaxKind(aliasDeclaration);
150113
+ }
150114
+ function promoteImportClause(importClause) {
150115
+ changes.delete(sourceFile, ts.getTypeKeywordOfTypeOnlyImport(importClause, sourceFile));
150116
+ if (convertExistingToTypeOnly) {
150117
+ var namedImports = ts.tryCast(importClause.namedBindings, ts.isNamedImports);
150118
+ if (namedImports && namedImports.elements.length > 1) {
150119
+ if (ts.OrganizeImports.importSpecifiersAreSorted(namedImports.elements) &&
150120
+ aliasDeclaration.kind === 269 /* ImportSpecifier */ &&
150121
+ namedImports.elements.indexOf(aliasDeclaration) !== 0) {
150122
+ // The import specifier being promoted will be the only non-type-only,
150123
+ // import in the NamedImports, so it should be moved to the front.
150124
+ changes.delete(sourceFile, aliasDeclaration);
150125
+ changes.insertImportSpecifierAtIndex(sourceFile, aliasDeclaration, namedImports, 0);
150126
+ }
150127
+ for (var _i = 0, _a = namedImports.elements; _i < _a.length; _i++) {
150128
+ var element = _a[_i];
150129
+ if (element !== aliasDeclaration && !element.isTypeOnly) {
150130
+ changes.insertModifierBefore(sourceFile, 151 /* TypeKeyword */, element);
150131
+ }
150132
+ }
150133
+ }
150134
+ }
150135
+ }
150136
+ }
149829
150137
  function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, compilerOptions) {
149830
150138
  var _a;
149831
150139
  if (clause.kind === 200 /* ObjectBindingPattern */) {
@@ -149863,13 +150171,7 @@ var ts;
149863
150171
  var insertionIndex = convertExistingToTypeOnly && !spec.isTypeOnly
149864
150172
  ? 0
149865
150173
  : ts.OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec);
149866
- var prevSpecifier = clause.namedBindings.elements[insertionIndex - 1];
149867
- if (prevSpecifier) {
149868
- changes.insertNodeInListAfter(sourceFile, prevSpecifier, spec);
149869
- }
149870
- else {
149871
- changes.insertNodeBefore(sourceFile, existingSpecifiers[0], spec, !ts.positionsAreOnSameLine(existingSpecifiers[0].getStart(), clause.parent.getStart(), sourceFile));
149872
- }
150174
+ changes.insertImportSpecifierAtIndex(sourceFile, spec, clause.namedBindings, insertionIndex);
149873
150175
  }
149874
150176
  }
149875
150177
  else if (existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) {
@@ -149984,17 +150286,20 @@ var ts;
149984
150286
  var declarations = _a.declarations;
149985
150287
  return ts.some(declarations, function (decl) { return !!(ts.getMeaningFromDeclaration(decl) & meaning); });
149986
150288
  }
149987
- function moduleSymbolToValidIdentifier(moduleSymbol, target) {
149988
- return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target);
150289
+ function moduleSymbolToValidIdentifier(moduleSymbol, target, forceCapitalize) {
150290
+ return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target, forceCapitalize);
149989
150291
  }
149990
150292
  codefix.moduleSymbolToValidIdentifier = moduleSymbolToValidIdentifier;
149991
- function moduleSpecifierToValidIdentifier(moduleSpecifier, target) {
150293
+ function moduleSpecifierToValidIdentifier(moduleSpecifier, target, forceCapitalize) {
149992
150294
  var baseName = ts.getBaseFileName(ts.removeSuffix(moduleSpecifier, "/index"));
149993
150295
  var res = "";
149994
150296
  var lastCharWasValid = true;
149995
150297
  var firstCharCode = baseName.charCodeAt(0);
149996
150298
  if (ts.isIdentifierStart(firstCharCode, target)) {
149997
150299
  res += String.fromCharCode(firstCharCode);
150300
+ if (forceCapitalize) {
150301
+ res = res.toUpperCase();
150302
+ }
149998
150303
  }
149999
150304
  else {
150000
150305
  lastCharWasValid = false;
@@ -157613,14 +157918,22 @@ var ts;
157613
157918
  var result = [];
157614
157919
  return visitor(selection) ? undefined : result;
157615
157920
  function visitor(node) {
157616
- var _a;
157617
157921
  if (ts.isTypeReferenceNode(node)) {
157618
157922
  if (ts.isIdentifier(node.typeName)) {
157619
- var symbol = checker.resolveName(node.typeName.text, node.typeName, 262144 /* TypeParameter */, /* excludeGlobals */ true);
157620
- var declaration = ts.tryCast((_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a[0], ts.isTypeParameterDeclaration);
157621
- if (declaration) {
157622
- if (rangeContainsSkipTrivia(statement, declaration, file) && !rangeContainsSkipTrivia(selection, declaration, file)) {
157623
- ts.pushIfUnique(result, declaration);
157923
+ var typeName = node.typeName;
157924
+ var symbol = checker.resolveName(typeName.text, typeName, 262144 /* TypeParameter */, /* excludeGlobals */ true);
157925
+ for (var _i = 0, _a = (symbol === null || symbol === void 0 ? void 0 : symbol.declarations) || ts.emptyArray; _i < _a.length; _i++) {
157926
+ var decl = _a[_i];
157927
+ if (ts.isTypeParameterDeclaration(decl) && decl.getSourceFile() === file) {
157928
+ // skip extraction if the type node is in the range of the type parameter declaration.
157929
+ // function foo<T extends { a?: /**/T }>(): void;
157930
+ if (decl.name.escapedText === typeName.escapedText && rangeContainsSkipTrivia(decl, selection, file)) {
157931
+ return true;
157932
+ }
157933
+ if (rangeContainsSkipTrivia(statement, decl, file) && !rangeContainsSkipTrivia(selection, decl, file)) {
157934
+ ts.pushIfUnique(result, decl);
157935
+ break;
157936
+ }
157624
157937
  }
157625
157938
  }
157626
157939
  }
@@ -159963,13 +160276,11 @@ var ts;
159963
160276
  switch (context === null || context === void 0 ? void 0 : context.kind) {
159964
160277
  case 171 /* GetAccessor */:
159965
160278
  if (!this.contextualGetAccessorDocumentationComment) {
159966
- this.contextualGetAccessorDocumentationComment = ts.emptyArray;
159967
160279
  this.contextualGetAccessorDocumentationComment = getDocumentationComment(ts.filter(this.declarations, ts.isGetAccessor), checker);
159968
160280
  }
159969
160281
  return this.contextualGetAccessorDocumentationComment;
159970
160282
  case 172 /* SetAccessor */:
159971
160283
  if (!this.contextualSetAccessorDocumentationComment) {
159972
- this.contextualSetAccessorDocumentationComment = ts.emptyArray;
159973
160284
  this.contextualSetAccessorDocumentationComment = getDocumentationComment(ts.filter(this.declarations, ts.isSetAccessor), checker);
159974
160285
  }
159975
160286
  return this.contextualSetAccessorDocumentationComment;
@@ -159979,10 +160290,26 @@ var ts;
159979
160290
  };
159980
160291
  SymbolObject.prototype.getJsDocTags = function (checker) {
159981
160292
  if (this.tags === undefined) {
159982
- this.tags = ts.JsDoc.getJsDocTagsFromDeclarations(this.declarations, checker);
160293
+ this.tags = getJsDocTagsOfDeclarations(this.declarations, checker);
159983
160294
  }
159984
160295
  return this.tags;
159985
160296
  };
160297
+ SymbolObject.prototype.getContextualJsDocTags = function (context, checker) {
160298
+ switch (context === null || context === void 0 ? void 0 : context.kind) {
160299
+ case 171 /* GetAccessor */:
160300
+ if (!this.contextualGetAccessorTags) {
160301
+ this.contextualGetAccessorTags = getJsDocTagsOfDeclarations(ts.filter(this.declarations, ts.isGetAccessor), checker);
160302
+ }
160303
+ return this.contextualGetAccessorTags;
160304
+ case 172 /* SetAccessor */:
160305
+ if (!this.contextualSetAccessorTags) {
160306
+ this.contextualSetAccessorTags = getJsDocTagsOfDeclarations(ts.filter(this.declarations, ts.isSetAccessor), checker);
160307
+ }
160308
+ return this.contextualSetAccessorTags;
160309
+ default:
160310
+ return this.getJsDocTags(checker);
160311
+ }
160312
+ };
159986
160313
  return SymbolObject;
159987
160314
  }());
159988
160315
  var TokenObject = /** @class */ (function (_super) {
@@ -160152,10 +160479,7 @@ var ts;
160152
160479
  return this.documentationComment || (this.documentationComment = getDocumentationComment(ts.singleElementArray(this.declaration), this.checker));
160153
160480
  };
160154
160481
  SignatureObject.prototype.getJsDocTags = function () {
160155
- if (this.jsDocTags === undefined) {
160156
- this.jsDocTags = this.declaration ? getJsDocTagsOfSignature(this.declaration, this.checker) : [];
160157
- }
160158
- return this.jsDocTags;
160482
+ return this.jsDocTags || (this.jsDocTags = getJsDocTagsOfDeclarations(ts.singleElementArray(this.declaration), this.checker));
160159
160483
  };
160160
160484
  return SignatureObject;
160161
160485
  }());
@@ -160167,12 +160491,30 @@ var ts;
160167
160491
  function hasJSDocInheritDocTag(node) {
160168
160492
  return ts.getJSDocTags(node).some(function (tag) { return tag.tagName.text === "inheritDoc"; });
160169
160493
  }
160170
- function getJsDocTagsOfSignature(declaration, checker) {
160171
- var tags = ts.JsDoc.getJsDocTagsFromDeclarations([declaration], checker);
160172
- if (tags.length === 0 || hasJSDocInheritDocTag(declaration)) {
160173
- var inheritedTags = findBaseOfDeclaration(checker, declaration, function (symbol) { var _a; return ((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.length) === 1 ? symbol.getJsDocTags() : undefined; });
160174
- if (inheritedTags) {
160175
- tags = __spreadArray(__spreadArray([], inheritedTags, true), tags, true);
160494
+ function getJsDocTagsOfDeclarations(declarations, checker) {
160495
+ if (!declarations)
160496
+ return ts.emptyArray;
160497
+ var tags = ts.JsDoc.getJsDocTagsFromDeclarations(declarations, checker);
160498
+ if (checker && (tags.length === 0 || declarations.some(hasJSDocInheritDocTag))) {
160499
+ var seenSymbols_1 = new ts.Set();
160500
+ var _loop_22 = function (declaration) {
160501
+ var inheritedTags = findBaseOfDeclaration(checker, declaration, function (symbol) {
160502
+ var _a;
160503
+ if (!seenSymbols_1.has(symbol)) {
160504
+ seenSymbols_1.add(symbol);
160505
+ if (declaration.kind === 171 /* GetAccessor */ || declaration.kind === 172 /* SetAccessor */) {
160506
+ return symbol.getContextualJsDocTags(declaration, checker);
160507
+ }
160508
+ return ((_a = symbol.declarations) === null || _a === void 0 ? void 0 : _a.length) === 1 ? symbol.getJsDocTags() : undefined;
160509
+ }
160510
+ });
160511
+ if (inheritedTags) {
160512
+ tags = __spreadArray(__spreadArray([], inheritedTags, true), tags, true);
160513
+ }
160514
+ };
160515
+ for (var _i = 0, declarations_6 = declarations; _i < declarations_6.length; _i++) {
160516
+ var declaration = declarations_6[_i];
160517
+ _loop_22(declaration);
160176
160518
  }
160177
160519
  }
160178
160520
  return tags;
@@ -160182,18 +160524,24 @@ var ts;
160182
160524
  return ts.emptyArray;
160183
160525
  var doc = ts.JsDoc.getJsDocCommentsFromDeclarations(declarations, checker);
160184
160526
  if (checker && (doc.length === 0 || declarations.some(hasJSDocInheritDocTag))) {
160185
- var seenSymbols_1 = new ts.Set();
160186
- for (var _i = 0, declarations_6 = declarations; _i < declarations_6.length; _i++) {
160187
- var declaration = declarations_6[_i];
160527
+ var seenSymbols_2 = new ts.Set();
160528
+ var _loop_23 = function (declaration) {
160188
160529
  var inheritedDocs = findBaseOfDeclaration(checker, declaration, function (symbol) {
160189
- if (!seenSymbols_1.has(symbol)) {
160190
- seenSymbols_1.add(symbol);
160530
+ if (!seenSymbols_2.has(symbol)) {
160531
+ seenSymbols_2.add(symbol);
160532
+ if (declaration.kind === 171 /* GetAccessor */ || declaration.kind === 172 /* SetAccessor */) {
160533
+ return symbol.getContextualDocumentationComment(declaration, checker);
160534
+ }
160191
160535
  return symbol.getDocumentationComment(checker);
160192
160536
  }
160193
160537
  });
160194
160538
  // TODO: GH#16312 Return a ReadonlyArray, avoid copying inheritedDocs
160195
160539
  if (inheritedDocs)
160196
160540
  doc = doc.length === 0 ? inheritedDocs.slice() : inheritedDocs.concat(ts.lineBreakPart(), doc);
160541
+ };
160542
+ for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
160543
+ var declaration = declarations_7[_i];
160544
+ _loop_23(declaration);
160197
160545
  }
160198
160546
  }
160199
160547
  return doc;