@typescript-deploys/pr-build 4.6.0-pr-47550-2 → 4.6.0-pr-47552-4

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-insiders.20220121";
103
+ ts.version = ts.versionMajorMinor + ".0-insiders.20220122";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -9467,6 +9467,8 @@ var ts;
9467
9467
  Remove_unused_declarations_for_Colon_0: diag(90041, ts.DiagnosticCategory.Message, "Remove_unused_declarations_for_Colon_0_90041", "Remove unused declarations for: '{0}'"),
9468
9468
  Declare_a_private_field_named_0: diag(90053, ts.DiagnosticCategory.Message, "Declare_a_private_field_named_0_90053", "Declare a private field named '{0}'."),
9469
9469
  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}'"),
9470
+ 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}\""),
9471
+ 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}\""),
9470
9472
  Convert_function_to_an_ES2015_class: diag(95001, ts.DiagnosticCategory.Message, "Convert_function_to_an_ES2015_class_95001", "Convert function to an ES2015 class"),
9471
9473
  Convert_0_to_1_in_0: diag(95003, ts.DiagnosticCategory.Message, "Convert_0_to_1_in_0_95003", "Convert '{0}' to '{1} in {0}'"),
9472
9474
  Extract_to_0_in_1: diag(95004, ts.DiagnosticCategory.Message, "Extract_to_0_in_1_95004", "Extract to {0} in {1}"),
@@ -33366,7 +33368,7 @@ var ts;
33366
33368
  function parseInitializer() {
33367
33369
  return parseOptional(63 /* EqualsToken */) ? parseAssignmentExpressionOrHigher() : undefined;
33368
33370
  }
33369
- function parseAssignmentExpressionOrHigher(parsingConditionalTrueSide) {
33371
+ function parseAssignmentExpressionOrHigher() {
33370
33372
  // AssignmentExpression[in,yield]:
33371
33373
  // 1) ConditionalExpression[?in,?yield]
33372
33374
  // 2) LeftHandSideExpression = AssignmentExpression[?in,?yield]
@@ -33392,7 +33394,7 @@ var ts;
33392
33394
  // If we do successfully parse arrow-function, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is
33393
33395
  // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done
33394
33396
  // with AssignmentExpression if we see one.
33395
- var arrowExpression = tryParseParenthesizedArrowFunctionExpression(parsingConditionalTrueSide) || tryParseAsyncSimpleArrowFunctionExpression();
33397
+ var arrowExpression = tryParseParenthesizedArrowFunctionExpression() || tryParseAsyncSimpleArrowFunctionExpression();
33396
33398
  if (arrowExpression) {
33397
33399
  return arrowExpression;
33398
33400
  }
@@ -33411,7 +33413,7 @@ var ts;
33411
33413
  // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single
33412
33414
  // identifier and the current token is an arrow.
33413
33415
  if (expr.kind === 79 /* Identifier */ && token() === 38 /* EqualsGreaterThanToken */) {
33414
- return parseSimpleArrowFunctionExpression(pos, expr, /*asyncModifier*/ undefined, parsingConditionalTrueSide);
33416
+ return parseSimpleArrowFunctionExpression(pos, expr, /*asyncModifier*/ undefined);
33415
33417
  }
33416
33418
  // Now see if we might be in cases '2' or '3'.
33417
33419
  // If the expression was a LHS expression, and we have an assignment operator, then
@@ -33471,7 +33473,7 @@ var ts;
33471
33473
  return finishNode(factory.createYieldExpression(/*asteriskToken*/ undefined, /*expression*/ undefined), pos);
33472
33474
  }
33473
33475
  }
33474
- function parseSimpleArrowFunctionExpression(pos, identifier, asyncModifier, parsingConditionalTrueSide) {
33476
+ function parseSimpleArrowFunctionExpression(pos, identifier, asyncModifier) {
33475
33477
  ts.Debug.assert(token() === 38 /* EqualsGreaterThanToken */, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
33476
33478
  var parameter = factory.createParameterDeclaration(
33477
33479
  /*decorators*/ undefined,
@@ -33483,11 +33485,11 @@ var ts;
33483
33485
  finishNode(parameter, identifier.pos);
33484
33486
  var parameters = createNodeArray([parameter], parameter.pos, parameter.end);
33485
33487
  var equalsGreaterThanToken = parseExpectedToken(38 /* EqualsGreaterThanToken */);
33486
- var body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier, parsingConditionalTrueSide);
33488
+ var body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier);
33487
33489
  var node = factory.createArrowFunction(asyncModifier, /*typeParameters*/ undefined, parameters, /*type*/ undefined, equalsGreaterThanToken, body);
33488
33490
  return addJSDocComment(finishNode(node, pos));
33489
33491
  }
33490
- function tryParseParenthesizedArrowFunctionExpression(parsingConditionalTrueSide) {
33492
+ function tryParseParenthesizedArrowFunctionExpression() {
33491
33493
  var triState = isParenthesizedArrowFunctionExpression();
33492
33494
  if (triState === 0 /* False */) {
33493
33495
  // It's definitely not a parenthesized arrow function expression.
@@ -33498,8 +33500,8 @@ var ts;
33498
33500
  // it out, but don't allow any ambiguity, and return 'undefined' if this could be an
33499
33501
  // expression instead.
33500
33502
  return triState === 1 /* True */ ?
33501
- parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true, parsingConditionalTrueSide) :
33502
- tryParse(function () { return parsePossibleParenthesizedArrowFunctionExpression(parsingConditionalTrueSide); });
33503
+ parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true) :
33504
+ tryParse(parsePossibleParenthesizedArrowFunctionExpression);
33503
33505
  }
33504
33506
  // True -> We definitely expect a parenthesized arrow function here.
33505
33507
  // False -> There *cannot* be a parenthesized arrow function here.
@@ -33629,25 +33631,25 @@ var ts;
33629
33631
  return 2 /* Unknown */;
33630
33632
  }
33631
33633
  }
33632
- function parsePossibleParenthesizedArrowFunctionExpression(parsingConditionalTrueSide) {
33634
+ function parsePossibleParenthesizedArrowFunctionExpression() {
33633
33635
  var tokenPos = scanner.getTokenPos();
33634
33636
  if (notParenthesizedArrow === null || notParenthesizedArrow === void 0 ? void 0 : notParenthesizedArrow.has(tokenPos)) {
33635
33637
  return undefined;
33636
33638
  }
33637
- var result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false, parsingConditionalTrueSide);
33639
+ var result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false);
33638
33640
  if (!result) {
33639
33641
  (notParenthesizedArrow || (notParenthesizedArrow = new ts.Set())).add(tokenPos);
33640
33642
  }
33641
33643
  return result;
33642
33644
  }
33643
- function tryParseAsyncSimpleArrowFunctionExpression(parsingConditionalTrueSide) {
33645
+ function tryParseAsyncSimpleArrowFunctionExpression() {
33644
33646
  // We do a check here so that we won't be doing unnecessarily call to "lookAhead"
33645
33647
  if (token() === 131 /* AsyncKeyword */) {
33646
33648
  if (lookAhead(isUnParenthesizedAsyncArrowFunctionWorker) === 1 /* True */) {
33647
33649
  var pos = getNodePos();
33648
33650
  var asyncModifier = parseModifiersForArrowFunction();
33649
33651
  var expr = parseBinaryExpressionOrHigher(0 /* Lowest */);
33650
- return parseSimpleArrowFunctionExpression(pos, expr, asyncModifier, parsingConditionalTrueSide);
33652
+ return parseSimpleArrowFunctionExpression(pos, expr, asyncModifier);
33651
33653
  }
33652
33654
  }
33653
33655
  return undefined;
@@ -33671,7 +33673,7 @@ var ts;
33671
33673
  }
33672
33674
  return 0 /* False */;
33673
33675
  }
33674
- function parseParenthesizedArrowFunctionExpression(allowAmbiguity, parsingConditionalTrueSide) {
33676
+ function parseParenthesizedArrowFunctionExpression(allowAmbiguity) {
33675
33677
  var pos = getNodePos();
33676
33678
  var hasJSDoc = hasPrecedingJSDocComment();
33677
33679
  var modifiers = parseModifiersForArrowFunction();
@@ -33697,18 +33699,6 @@ var ts;
33697
33699
  return undefined;
33698
33700
  }
33699
33701
  }
33700
- // Given:
33701
- // x ? y => ({ y }) : z => ({ z })
33702
- // We try to parse the body of the first arrow function by looking at:
33703
- // ({ y }) : z => ({ z })
33704
- // This is a valid arrow function with "z" as the return type.
33705
- //
33706
- // But, if we're in the true side of a conditional expression, this colon
33707
- // terminates the true side, so cannot be the return type.
33708
- if (parsingConditionalTrueSide && token() === 58 /* ColonToken */) {
33709
- ts.Debug.assert(!allowAmbiguity);
33710
- return undefined;
33711
- }
33712
33702
  var type = parseReturnType(58 /* ColonToken */, /*isType*/ false);
33713
33703
  if (type && !allowAmbiguity && typeHasArrowFunctionBlockingParseError(type)) {
33714
33704
  return undefined;
@@ -33742,7 +33732,7 @@ var ts;
33742
33732
  var node = factory.createArrowFunction(modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body);
33743
33733
  return withJSDoc(finishNode(node, pos), hasJSDoc);
33744
33734
  }
33745
- function parseArrowFunctionExpressionBody(isAsync, parsingConditionalTrueSide) {
33735
+ function parseArrowFunctionExpressionBody(isAsync) {
33746
33736
  if (token() === 18 /* OpenBraceToken */) {
33747
33737
  return parseFunctionBlock(isAsync ? 2 /* Await */ : 0 /* None */);
33748
33738
  }
@@ -33770,8 +33760,8 @@ var ts;
33770
33760
  var savedTopLevel = topLevel;
33771
33761
  topLevel = false;
33772
33762
  var node = isAsync
33773
- ? doInAwaitContext(function () { return parseAssignmentExpressionOrHigher(parsingConditionalTrueSide); })
33774
- : doOutsideOfAwaitContext(function () { return parseAssignmentExpressionOrHigher(parsingConditionalTrueSide); });
33763
+ ? doInAwaitContext(parseAssignmentExpressionOrHigher)
33764
+ : doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher);
33775
33765
  topLevel = savedTopLevel;
33776
33766
  return node;
33777
33767
  }
@@ -33784,8 +33774,8 @@ var ts;
33784
33774
  // Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and
33785
33775
  // we do not that for the 'whenFalse' part.
33786
33776
  var colonToken;
33787
- return finishNode(factory.createConditionalExpression(leftOperand, questionToken, doOutsideOfContext(disallowInAndDecoratorContext, function () { return parseAssignmentExpressionOrHigher(/*parsingConditionalTrueSide*/ true); }), colonToken = parseExpectedToken(58 /* ColonToken */), ts.nodeIsPresent(colonToken)
33788
- ? parseAssignmentExpressionOrHigher(/*parsingConditionalTrueSide*/ false)
33777
+ return finishNode(factory.createConditionalExpression(leftOperand, questionToken, doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher), colonToken = parseExpectedToken(58 /* ColonToken */), ts.nodeIsPresent(colonToken)
33778
+ ? parseAssignmentExpressionOrHigher()
33789
33779
  : createMissingNode(79 /* Identifier */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(58 /* ColonToken */))), pos);
33790
33780
  }
33791
33781
  function parseBinaryExpressionOrHigher(precedence) {
@@ -128972,6 +128962,8 @@ var ts;
128972
128962
  CompletionSource["ThisProperty"] = "ThisProperty/";
128973
128963
  /** Auto-import that comes attached to a class member snippet */
128974
128964
  CompletionSource["ClassMemberSnippet"] = "ClassMemberSnippet/";
128965
+ /** A type-only import that needs to be promoted in order to be used at the completion location */
128966
+ CompletionSource["TypeOnlyAlias"] = "TypeOnlyAlias/";
128975
128967
  })(CompletionSource = Completions.CompletionSource || (Completions.CompletionSource = {}));
128976
128968
  var SymbolOriginInfoKind;
128977
128969
  (function (SymbolOriginInfoKind) {
@@ -128981,6 +128973,7 @@ var ts;
128981
128973
  SymbolOriginInfoKind[SymbolOriginInfoKind["Promise"] = 8] = "Promise";
128982
128974
  SymbolOriginInfoKind[SymbolOriginInfoKind["Nullable"] = 16] = "Nullable";
128983
128975
  SymbolOriginInfoKind[SymbolOriginInfoKind["ResolvedExport"] = 32] = "ResolvedExport";
128976
+ SymbolOriginInfoKind[SymbolOriginInfoKind["TypeOnlyAlias"] = 64] = "TypeOnlyAlias";
128984
128977
  SymbolOriginInfoKind[SymbolOriginInfoKind["SymbolMemberNoExport"] = 2] = "SymbolMemberNoExport";
128985
128978
  SymbolOriginInfoKind[SymbolOriginInfoKind["SymbolMemberExport"] = 6] = "SymbolMemberExport";
128986
128979
  })(SymbolOriginInfoKind || (SymbolOriginInfoKind = {}));
@@ -129008,6 +129001,9 @@ var ts;
129008
129001
  function originIsNullableMember(origin) {
129009
129002
  return !!(origin.kind & 16 /* Nullable */);
129010
129003
  }
129004
+ function originIsTypeOnlyAlias(origin) {
129005
+ return !!(origin && origin.kind & 64 /* TypeOnlyAlias */);
129006
+ }
129011
129007
  var KeywordCompletionFilters;
129012
129008
  (function (KeywordCompletionFilters) {
129013
129009
  KeywordCompletionFilters[KeywordCompletionFilters["None"] = 0] = "None";
@@ -129412,6 +129408,9 @@ var ts;
129412
129408
  isSnippet = preferences.includeCompletionsWithSnippetText ? true : undefined;
129413
129409
  }
129414
129410
  }
129411
+ if ((origin === null || origin === void 0 ? void 0 : origin.kind) === 64 /* TypeOnlyAlias */) {
129412
+ hasAction = true;
129413
+ }
129415
129414
  if (preferences.includeCompletionsWithClassMemberSnippets &&
129416
129415
  preferences.includeCompletionsWithInsertText &&
129417
129416
  completionKind === 3 /* MemberLike */ &&
@@ -129756,6 +129755,9 @@ var ts;
129756
129755
  if ((origin === null || origin === void 0 ? void 0 : origin.kind) === 1 /* ThisType */) {
129757
129756
  return CompletionSource.ThisProperty;
129758
129757
  }
129758
+ if ((origin === null || origin === void 0 ? void 0 : origin.kind) === 64 /* TypeOnlyAlias */) {
129759
+ return CompletionSource.TypeOnlyAlias;
129760
+ }
129759
129761
  }
129760
129762
  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) {
129761
129763
  var _a;
@@ -129783,7 +129785,7 @@ var ts;
129783
129785
  continue;
129784
129786
  }
129785
129787
  /** True for locals; false for globals, module exports from other files, `this.` completions. */
129786
- var shouldShadowLaterSymbols = !origin && !(symbol.parent === undefined && !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === location.getSourceFile(); }));
129788
+ var shouldShadowLaterSymbols = (!origin || originIsTypeOnlyAlias(origin)) && !(symbol.parent === undefined && !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === location.getSourceFile(); }));
129787
129789
  uniques.set(name, shouldShadowLaterSymbols);
129788
129790
  ts.insertSorted(entries, entry, compareCompletionEntries, /*allowDuplicates*/ true);
129789
129791
  }
@@ -129796,6 +129798,7 @@ var ts;
129796
129798
  add: function (name) { return uniques.set(name, true); },
129797
129799
  };
129798
129800
  function shouldIncludeSymbol(symbol, symbolToSortTextIdMap) {
129801
+ var allFlags = symbol.flags;
129799
129802
  if (!ts.isSourceFile(location)) {
129800
129803
  // export = /**/ here we want to get all meanings, so any symbol is ok
129801
129804
  if (ts.isExportAssignment(location.parent)) {
@@ -129821,11 +129824,10 @@ var ts;
129821
129824
  || symbolToSortTextIdMap[ts.getSymbolId(symbolOrigin)] === 11 /* LocationPriority */)) {
129822
129825
  return false;
129823
129826
  }
129824
- // Continue with origin symbol
129825
- symbol = symbolOrigin;
129827
+ allFlags |= ts.getCombinedLocalAndExportSymbolFlags(symbolOrigin);
129826
129828
  // import m = /**/ <-- It can only access namespace (if typing import = x. this would get member symbols and not namespace)
129827
129829
  if (ts.isInRightSideOfInternalImportEqualsDeclaration(location)) {
129828
- return !!(symbol.flags & 1920 /* Namespace */);
129830
+ return !!(allFlags & 1920 /* Namespace */);
129829
129831
  }
129830
129832
  if (isTypeOnlyLocation) {
129831
129833
  // It's a type, but you can reach it by namespace.type as well
@@ -129833,7 +129835,7 @@ var ts;
129833
129835
  }
129834
129836
  }
129835
129837
  // expressions are value space (which includes the value namespaces)
129836
- return !!(ts.getCombinedLocalAndExportSymbolFlags(symbol) & 111551 /* Value */);
129838
+ return !!(allFlags & 111551 /* Value */);
129837
129839
  }
129838
129840
  }
129839
129841
  Completions.getCompletionEntriesFromSymbols = getCompletionEntriesFromSymbols;
@@ -129986,6 +129988,11 @@ var ts;
129986
129988
  };
129987
129989
  }
129988
129990
  }
129991
+ if (originIsTypeOnlyAlias(origin)) {
129992
+ var codeAction_1 = ts.codefix.getPromoteTypeOnlyCompletionAction(sourceFile, origin.declaration.name, program, host, formatContext, preferences);
129993
+ ts.Debug.assertIsDefined(codeAction_1, "Expected to have a code action for promoting type-only alias");
129994
+ return { codeActions: [codeAction_1], sourceDisplay: undefined };
129995
+ }
129989
129996
  if (!origin || !(originIsExport(origin) || originIsResolvedExport(origin))) {
129990
129997
  return { codeActions: undefined, sourceDisplay: undefined };
129991
129998
  }
@@ -130662,21 +130669,29 @@ var ts;
130662
130669
  var scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile;
130663
130670
  isInSnippetScope = isSnippetScope(scopeNode);
130664
130671
  var symbolMeanings = (isTypeOnlyLocation ? 0 /* None */ : 111551 /* Value */) | 788968 /* Type */ | 1920 /* Namespace */ | 2097152 /* Alias */;
130672
+ var typeOnlyAliasNeedsPromotion = previousToken && !ts.isValidTypeOnlyAliasUseSite(previousToken);
130665
130673
  symbols = ts.concatenate(symbols, typeChecker.getSymbolsInScope(scopeNode, symbolMeanings));
130666
130674
  ts.Debug.assertEachIsDefined(symbols, "getSymbolsInScope() should all be defined");
130667
- for (var _i = 0, symbols_1 = symbols; _i < symbols_1.length; _i++) {
130668
- var symbol = symbols_1[_i];
130675
+ for (var i = 0; i < symbols.length; i++) {
130676
+ var symbol = symbols[i];
130669
130677
  if (!typeChecker.isArgumentsSymbol(symbol) &&
130670
130678
  !ts.some(symbol.declarations, function (d) { return d.getSourceFile() === sourceFile; })) {
130671
130679
  symbolToSortTextIdMap[ts.getSymbolId(symbol)] = 15 /* GlobalsOrKeywords */;
130672
130680
  }
130681
+ if (typeOnlyAliasNeedsPromotion && !(symbol.flags & 111551 /* Value */)) {
130682
+ var typeOnlyAliasDeclaration = symbol.declarations && ts.find(symbol.declarations, ts.isTypeOnlyImportOrExportDeclaration);
130683
+ if (typeOnlyAliasDeclaration) {
130684
+ var origin = { kind: 64 /* TypeOnlyAlias */, declaration: typeOnlyAliasDeclaration };
130685
+ symbolToOriginInfoMap[i] = origin;
130686
+ }
130687
+ }
130673
130688
  }
130674
130689
  // Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions`
130675
130690
  if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== 303 /* SourceFile */) {
130676
130691
  var thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false);
130677
130692
  if (thisType && !isProbablyGlobalType(thisType, sourceFile, typeChecker)) {
130678
- for (var _a = 0, _b = getPropertiesForCompletion(thisType, typeChecker); _a < _b.length; _a++) {
130679
- var symbol = _b[_a];
130693
+ for (var _i = 0, _a = getPropertiesForCompletion(thisType, typeChecker); _i < _a.length; _i++) {
130694
+ var symbol = _a[_i];
130680
130695
  symbolToOriginInfoMap[symbols.length] = { kind: 1 /* ThisType */ };
130681
130696
  symbols.push(symbol);
130682
130697
  symbolToSortTextIdMap[ts.getSymbolId(symbol)] = 14 /* SuggestedClassMembers */;
@@ -132075,10 +132090,14 @@ var ts;
132075
132090
  /** True if symbol is a type or a module containing at least one type. */
132076
132091
  function symbolCanBeReferencedAtTypeLocation(symbol, checker, seenModules) {
132077
132092
  if (seenModules === void 0) { seenModules = new ts.Map(); }
132078
- var sym = ts.skipAlias(symbol.exportSymbol || symbol, checker);
132079
- return !!(sym.flags & 788968 /* Type */) || checker.isUnknownSymbol(sym) ||
132080
- !!(sym.flags & 1536 /* Module */) && ts.addToSeen(seenModules, ts.getSymbolId(sym)) &&
132081
- checker.getExportsOfModule(sym).some(function (e) { return symbolCanBeReferencedAtTypeLocation(e, checker, seenModules); });
132093
+ // Since an alias can be merged with a local declaration, we need to test both the alias and its target.
132094
+ // This code used to just test the result of `skipAlias`, but that would ignore any locally introduced meanings.
132095
+ return nonAliasCanBeReferencedAtTypeLocation(symbol) || nonAliasCanBeReferencedAtTypeLocation(ts.skipAlias(symbol.exportSymbol || symbol, checker));
132096
+ function nonAliasCanBeReferencedAtTypeLocation(symbol) {
132097
+ return !!(symbol.flags & 788968 /* Type */) || checker.isUnknownSymbol(symbol) ||
132098
+ !!(symbol.flags & 1536 /* Module */) && ts.addToSeen(seenModules, ts.getSymbolId(symbol)) &&
132099
+ checker.getExportsOfModule(symbol).some(function (e) { return symbolCanBeReferencedAtTypeLocation(e, checker, seenModules); });
132100
+ }
132082
132101
  }
132083
132102
  function isDeprecated(symbol, checker) {
132084
132103
  var declarations = ts.skipAlias(symbol, checker).declarations;
@@ -134332,8 +134351,8 @@ var ts;
134332
134351
  var sourceId = ts.getNodeId(sourceFile);
134333
134352
  var seenSymbols = this.sourceFileToSeenSymbols[sourceId] || (this.sourceFileToSeenSymbols[sourceId] = new ts.Set());
134334
134353
  var anyNewSymbols = false;
134335
- for (var _i = 0, symbols_2 = symbols; _i < symbols_2.length; _i++) {
134336
- var sym = symbols_2[_i];
134354
+ for (var _i = 0, symbols_1 = symbols; _i < symbols_1.length; _i++) {
134355
+ var sym = symbols_1[_i];
134337
134356
  anyNewSymbols = ts.tryAddToSet(seenSymbols, ts.getSymbolId(sym)) || anyNewSymbols;
134338
134357
  }
134339
134358
  return anyNewSymbols;
@@ -145185,6 +145204,7 @@ var ts;
145185
145204
  ChangeTracker.prototype.delete = function (sourceFile, node) {
145186
145205
  this.deletedNodes.push({ sourceFile: sourceFile, node: node });
145187
145206
  };
145207
+ /** Stop! Consider using `delete` instead, which has logic for deleting nodes from delimited lists. */
145188
145208
  ChangeTracker.prototype.deleteNode = function (sourceFile, node, options) {
145189
145209
  if (options === void 0) { options = { leadingTriviaOption: LeadingTriviaOption.IncludeAll }; }
145190
145210
  this.deleteRange(sourceFile, getAdjustedRange(sourceFile, node, node, options));
@@ -145588,6 +145608,15 @@ var ts;
145588
145608
  ChangeTracker.prototype.insertExportModifier = function (sourceFile, node) {
145589
145609
  this.insertText(sourceFile, node.getStart(sourceFile), "export ");
145590
145610
  };
145611
+ ChangeTracker.prototype.insertImportSpecifierAtIndex = function (sourceFile, importSpecifier, namedImports, index) {
145612
+ var prevSpecifier = namedImports.elements[index - 1];
145613
+ if (prevSpecifier) {
145614
+ this.insertNodeInListAfter(sourceFile, prevSpecifier, importSpecifier);
145615
+ }
145616
+ else {
145617
+ this.insertNodeBefore(sourceFile, namedImports.elements[0], importSpecifier, !ts.positionsAreOnSameLine(namedImports.elements[0].getStart(), namedImports.parent.parent.getStart(), sourceFile));
145618
+ }
145619
+ };
145591
145620
  /**
145592
145621
  * This function should be used to insert nodes in lists when nodes don't carry separators as the part of the node range,
145593
145622
  * i.e. arguments in arguments lists, parameters in parameter lists etc.
@@ -149090,7 +149119,8 @@ var ts;
149090
149119
  ts.Diagnostics.Cannot_find_namespace_0.code,
149091
149120
  ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code,
149092
149121
  ts.Diagnostics._0_only_refers_to_a_type_but_is_being_used_as_a_value_here.code,
149093
- ts.Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer.code
149122
+ ts.Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer.code,
149123
+ ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type.code,
149094
149124
  ];
149095
149125
  codefix.registerCodeFix({
149096
149126
  errorCodes: errorCodes,
@@ -149195,6 +149225,9 @@ var ts;
149195
149225
  }
149196
149226
  break;
149197
149227
  }
149228
+ case 4 /* PromoteTypeOnly */:
149229
+ // Excluding from fix-all
149230
+ break;
149198
149231
  default:
149199
149232
  ts.Debug.assertNever(fix, "fix wasn't never - got kind " + fix.kind);
149200
149233
  }
@@ -149286,6 +149319,7 @@ var ts;
149286
149319
  ImportFixKind[ImportFixKind["JsdocTypeImport"] = 1] = "JsdocTypeImport";
149287
149320
  ImportFixKind[ImportFixKind["AddToExisting"] = 2] = "AddToExisting";
149288
149321
  ImportFixKind[ImportFixKind["AddNew"] = 3] = "AddNew";
149322
+ ImportFixKind[ImportFixKind["PromoteTypeOnly"] = 4] = "PromoteTypeOnly";
149289
149323
  })(ImportFixKind || (ImportFixKind = {}));
149290
149324
  // These should not be combined as bitflags, but are given powers of 2 values to
149291
149325
  // easily detect conflicts between `NotAllowed` and `Required` by giving them a unique sum.
@@ -149311,6 +149345,13 @@ var ts;
149311
149345
  };
149312
149346
  }
149313
149347
  codefix.getImportCompletionAction = getImportCompletionAction;
149348
+ function getPromoteTypeOnlyCompletionAction(sourceFile, symbolToken, program, host, formatContext, preferences) {
149349
+ var compilerOptions = program.getCompilerOptions();
149350
+ var symbolName = getSymbolName(sourceFile, program.getTypeChecker(), symbolToken, compilerOptions);
149351
+ var fix = getTypeOnlyPromotionFix(sourceFile, symbolToken, symbolName, program);
149352
+ return fix && codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, 1 /* Double */, compilerOptions));
149353
+ }
149354
+ codefix.getPromoteTypeOnlyCompletionAction = getPromoteTypeOnlyCompletionAction;
149314
149355
  function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
149315
149356
  ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
149316
149357
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
@@ -149591,9 +149632,18 @@ var ts;
149591
149632
  }
149592
149633
  function getFixesInfo(context, errorCode, pos, useAutoImportProvider) {
149593
149634
  var symbolToken = ts.getTokenAtPosition(context.sourceFile, pos);
149594
- var info = errorCode === ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code
149595
- ? getFixesInfoForUMDImport(context, symbolToken)
149596
- : ts.isIdentifier(symbolToken) ? getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider) : undefined;
149635
+ if (errorCode === ts.Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code) {
149636
+ return getFixesInfoForUMDImport(context, symbolToken);
149637
+ }
149638
+ if (!ts.isIdentifier(symbolToken)) {
149639
+ return undefined;
149640
+ }
149641
+ if (errorCode === ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type.code) {
149642
+ var symbolName_1 = getSymbolName(context.sourceFile, context.program.getTypeChecker(), symbolToken, context.program.getCompilerOptions());
149643
+ var fix = getTypeOnlyPromotionFix(context.sourceFile, symbolToken, symbolName_1, context.program);
149644
+ return fix && { fixes: [fix], symbolName: symbolName_1 };
149645
+ }
149646
+ var info = getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider);
149597
149647
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(context.sourceFile, context.preferences, context.host);
149598
149648
  return info && __assign(__assign({}, info), { fixes: sortFixes(info.fixes, context.sourceFile, context.program, packageJsonImportFilter) });
149599
149649
  }
@@ -149717,6 +149767,16 @@ var ts;
149717
149767
  }));
149718
149768
  return { fixes: fixes, symbolName: symbolName };
149719
149769
  }
149770
+ function getTypeOnlyPromotionFix(sourceFile, symbolToken, symbolName, program) {
149771
+ var checker = program.getTypeChecker();
149772
+ var symbol = checker.resolveName(symbolName, symbolToken, 111551 /* Value */, /*excludeGlobals*/ true);
149773
+ if (!symbol)
149774
+ return undefined;
149775
+ var typeOnlyAliasDeclaration = checker.getTypeOnlyAliasDeclaration(symbol);
149776
+ if (!typeOnlyAliasDeclaration || ts.getSourceFileOfNode(typeOnlyAliasDeclaration) !== sourceFile)
149777
+ return undefined;
149778
+ return { kind: 4 /* PromoteTypeOnly */, typeOnlyAliasDeclaration: typeOnlyAliasDeclaration };
149779
+ }
149720
149780
  function jsxModeNeedsExplicitImport(jsx) {
149721
149781
  return jsx === 2 /* React */ || jsx === 3 /* ReactNative */;
149722
149782
  }
@@ -149724,12 +149784,18 @@ var ts;
149724
149784
  var parent = symbolToken.parent;
149725
149785
  if ((ts.isJsxOpeningLikeElement(parent) || ts.isJsxClosingElement(parent)) && parent.tagName === symbolToken && jsxModeNeedsExplicitImport(compilerOptions.jsx)) {
149726
149786
  var jsxNamespace = checker.getJsxNamespace(sourceFile);
149727
- if (ts.isIntrinsicJsxName(symbolToken.text) || !checker.resolveName(jsxNamespace, parent, 111551 /* Value */, /*excludeGlobals*/ true)) {
149787
+ if (needsJsxNamespaceFix(jsxNamespace, symbolToken, checker)) {
149728
149788
  return jsxNamespace;
149729
149789
  }
149730
149790
  }
149731
149791
  return symbolToken.text;
149732
149792
  }
149793
+ function needsJsxNamespaceFix(jsxNamespace, symbolToken, checker) {
149794
+ if (ts.isIntrinsicJsxName(symbolToken.text))
149795
+ return true; // If we were triggered by a matching error code on an intrinsic, the error must have been about missing the JSX factory
149796
+ var namespaceSymbol = checker.resolveName(jsxNamespace, symbolToken, 111551 /* Value */, /*excludeGlobals*/ true);
149797
+ return !namespaceSymbol || ts.some(namespaceSymbol.declarations, ts.isTypeOnlyImportOrExportDeclaration) && !(namespaceSymbol.flags & 111551 /* Value */);
149798
+ }
149733
149799
  // Returns a map from an exported symbol's ID to a list of every way it's (re-)exported.
149734
149800
  function getExportInfos(symbolName, currentTokenMeaning, cancellationToken, fromFile, program, useAutoImportProvider, host, preferences) {
149735
149801
  var _a;
@@ -149828,10 +149894,80 @@ var ts;
149828
149894
  ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport), /*blankLineBetween*/ true);
149829
149895
  return [importKind === 1 /* Default */ ? ts.Diagnostics.Import_default_0_from_module_1 : ts.Diagnostics.Import_0_from_module_1, symbolName, moduleSpecifier];
149830
149896
  }
149897
+ case 4 /* PromoteTypeOnly */: {
149898
+ var typeOnlyAliasDeclaration = fix.typeOnlyAliasDeclaration;
149899
+ var promotedDeclaration = promoteFromTypeOnly(changes, typeOnlyAliasDeclaration, compilerOptions, sourceFile);
149900
+ return promotedDeclaration.kind === 269 /* ImportSpecifier */
149901
+ ? [ts.Diagnostics.Remove_type_from_import_of_0_from_1, symbolName, getModuleSpecifierText(promotedDeclaration.parent.parent)]
149902
+ : [ts.Diagnostics.Remove_type_from_import_declaration_from_0, getModuleSpecifierText(promotedDeclaration)];
149903
+ }
149831
149904
  default:
149832
149905
  return ts.Debug.assertNever(fix, "Unexpected fix kind " + fix.kind);
149833
149906
  }
149834
149907
  }
149908
+ function getModuleSpecifierText(promotedDeclaration) {
149909
+ var _a, _b;
149910
+ return promotedDeclaration.kind === 264 /* ImportEqualsDeclaration */
149911
+ ? ((_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()
149912
+ : ts.cast(promotedDeclaration.parent.moduleSpecifier, ts.isStringLiteral).text;
149913
+ }
149914
+ function promoteFromTypeOnly(changes, aliasDeclaration, compilerOptions, sourceFile) {
149915
+ // See comment in `doAddExistingFix` on constant with the same name.
149916
+ var convertExistingToTypeOnly = compilerOptions.preserveValueImports && compilerOptions.isolatedModules;
149917
+ switch (aliasDeclaration.kind) {
149918
+ case 269 /* ImportSpecifier */:
149919
+ if (aliasDeclaration.isTypeOnly) {
149920
+ if (aliasDeclaration.parent.elements.length > 1 && ts.OrganizeImports.importSpecifiersAreSorted(aliasDeclaration.parent.elements)) {
149921
+ changes.delete(sourceFile, aliasDeclaration);
149922
+ var newSpecifier = ts.factory.updateImportSpecifier(aliasDeclaration, /*isTypeOnly*/ false, aliasDeclaration.propertyName, aliasDeclaration.name);
149923
+ var insertionIndex = ts.OrganizeImports.getImportSpecifierInsertionIndex(aliasDeclaration.parent.elements, newSpecifier);
149924
+ changes.insertImportSpecifierAtIndex(sourceFile, newSpecifier, aliasDeclaration.parent, insertionIndex);
149925
+ }
149926
+ else {
149927
+ changes.deleteRange(sourceFile, aliasDeclaration.getFirstToken());
149928
+ }
149929
+ return aliasDeclaration;
149930
+ }
149931
+ else {
149932
+ ts.Debug.assert(aliasDeclaration.parent.parent.isTypeOnly);
149933
+ promoteImportClause(aliasDeclaration.parent.parent);
149934
+ return aliasDeclaration.parent.parent;
149935
+ }
149936
+ case 266 /* ImportClause */:
149937
+ promoteImportClause(aliasDeclaration);
149938
+ return aliasDeclaration;
149939
+ case 267 /* NamespaceImport */:
149940
+ promoteImportClause(aliasDeclaration.parent);
149941
+ return aliasDeclaration.parent;
149942
+ case 264 /* ImportEqualsDeclaration */:
149943
+ changes.deleteRange(sourceFile, aliasDeclaration.getChildAt(1));
149944
+ return aliasDeclaration;
149945
+ default:
149946
+ ts.Debug.failBadSyntaxKind(aliasDeclaration);
149947
+ }
149948
+ function promoteImportClause(importClause) {
149949
+ changes.delete(sourceFile, ts.getTypeKeywordOfTypeOnlyImport(importClause, sourceFile));
149950
+ if (convertExistingToTypeOnly) {
149951
+ var namedImports = ts.tryCast(importClause.namedBindings, ts.isNamedImports);
149952
+ if (namedImports && namedImports.elements.length > 1) {
149953
+ if (ts.OrganizeImports.importSpecifiersAreSorted(namedImports.elements) &&
149954
+ aliasDeclaration.kind === 269 /* ImportSpecifier */ &&
149955
+ namedImports.elements.indexOf(aliasDeclaration) !== 0) {
149956
+ // The import specifier being promoted will be the only non-type-only,
149957
+ // import in the NamedImports, so it should be moved to the front.
149958
+ changes.delete(sourceFile, aliasDeclaration);
149959
+ changes.insertImportSpecifierAtIndex(sourceFile, aliasDeclaration, namedImports, 0);
149960
+ }
149961
+ for (var _i = 0, _a = namedImports.elements; _i < _a.length; _i++) {
149962
+ var element = _a[_i];
149963
+ if (element !== aliasDeclaration && !element.isTypeOnly) {
149964
+ changes.insertModifierBefore(sourceFile, 151 /* TypeKeyword */, element);
149965
+ }
149966
+ }
149967
+ }
149968
+ }
149969
+ }
149970
+ }
149835
149971
  function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, compilerOptions) {
149836
149972
  var _a;
149837
149973
  if (clause.kind === 200 /* ObjectBindingPattern */) {
@@ -149869,13 +150005,7 @@ var ts;
149869
150005
  var insertionIndex = convertExistingToTypeOnly && !spec.isTypeOnly
149870
150006
  ? 0
149871
150007
  : ts.OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec);
149872
- var prevSpecifier = clause.namedBindings.elements[insertionIndex - 1];
149873
- if (prevSpecifier) {
149874
- changes.insertNodeInListAfter(sourceFile, prevSpecifier, spec);
149875
- }
149876
- else {
149877
- changes.insertNodeBefore(sourceFile, existingSpecifiers[0], spec, !ts.positionsAreOnSameLine(existingSpecifiers[0].getStart(), clause.parent.getStart(), sourceFile));
149878
- }
150008
+ changes.insertImportSpecifierAtIndex(sourceFile, spec, clause.namedBindings, insertionIndex);
149879
150009
  }
149880
150010
  }
149881
150011
  else if (existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) {
@@ -1720,19 +1720,23 @@ declare namespace ts {
1720
1720
  readonly parent: ImportClause & {
1721
1721
  readonly isTypeOnly: true;
1722
1722
  };
1723
- } | ImportSpecifier & {
1723
+ } | ImportSpecifier & ({
1724
+ readonly isTypeOnly: true;
1725
+ } | {
1724
1726
  readonly parent: NamedImports & {
1725
1727
  readonly parent: ImportClause & {
1726
1728
  readonly isTypeOnly: true;
1727
1729
  };
1728
1730
  };
1729
- } | ExportSpecifier & {
1731
+ }) | ExportSpecifier & ({
1732
+ readonly isTypeOnly: true;
1733
+ } | {
1730
1734
  readonly parent: NamedExports & {
1731
1735
  readonly parent: ExportDeclaration & {
1732
1736
  readonly isTypeOnly: true;
1733
1737
  };
1734
1738
  };
1735
- };
1739
+ });
1736
1740
  /**
1737
1741
  * This is either an `export =` or an `export default` declaration.
1738
1742
  * Unless `isExportEquals` is set, this node was parsed as an `export default`.