typescript 4.5.4 → 4.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = "4.5.4";
297
+ ts.version = "4.5.5";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -16033,7 +16033,7 @@ var ts;
16033
16033
  }
16034
16034
  ts.getExternalModuleImportEqualsDeclarationExpression = getExternalModuleImportEqualsDeclarationExpression;
16035
16035
  function getExternalModuleRequireArgument(node) {
16036
- return isRequireVariableDeclaration(node) && getLeftmostAccessExpression(node.initializer).arguments[0];
16036
+ return isVariableDeclarationInitializedToBareOrAccessedRequire(node) && getLeftmostAccessExpression(node.initializer).arguments[0];
16037
16037
  }
16038
16038
  ts.getExternalModuleRequireArgument = getExternalModuleRequireArgument;
16039
16039
  function isInternalModuleImportEqualsDeclaration(node) {
@@ -16091,17 +16091,29 @@ var ts;
16091
16091
  * Returns true if the node is a VariableDeclaration initialized to a require call (see `isRequireCall`).
16092
16092
  * This function does not test if the node is in a JavaScript file or not.
16093
16093
  */
16094
- function isRequireVariableDeclaration(node) {
16094
+ function isVariableDeclarationInitializedToRequire(node) {
16095
+ return isVariableDeclarationInitializedWithRequireHelper(node, /*allowAccessedRequire*/ false);
16096
+ }
16097
+ ts.isVariableDeclarationInitializedToRequire = isVariableDeclarationInitializedToRequire;
16098
+ /**
16099
+ * Like {@link isVariableDeclarationInitializedToRequire} but allows things like `require("...").foo.bar` or `require("...")["baz"]`.
16100
+ */
16101
+ function isVariableDeclarationInitializedToBareOrAccessedRequire(node) {
16102
+ return isVariableDeclarationInitializedWithRequireHelper(node, /*allowAccessedRequire*/ true);
16103
+ }
16104
+ ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire;
16105
+ function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) {
16095
16106
  if (node.kind === 202 /* BindingElement */) {
16096
16107
  node = node.parent.parent;
16097
16108
  }
16098
- return ts.isVariableDeclaration(node) && !!node.initializer && isRequireCall(getLeftmostAccessExpression(node.initializer), /*requireStringLiteralLikeArgument*/ true);
16109
+ return ts.isVariableDeclaration(node) &&
16110
+ !!node.initializer &&
16111
+ isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true);
16099
16112
  }
16100
- ts.isRequireVariableDeclaration = isRequireVariableDeclaration;
16101
16113
  function isRequireVariableStatement(node) {
16102
16114
  return ts.isVariableStatement(node)
16103
16115
  && node.declarationList.declarations.length > 0
16104
- && ts.every(node.declarationList.declarations, function (decl) { return isRequireVariableDeclaration(decl); });
16116
+ && ts.every(node.declarationList.declarations, function (decl) { return isVariableDeclarationInitializedToRequire(decl); });
16105
16117
  }
16106
16118
  ts.isRequireVariableStatement = isRequireVariableStatement;
16107
16119
  function isSingleOrDoubleQuote(charCode) {
@@ -46258,7 +46270,7 @@ var ts;
46258
46270
  checkStrictModeEvalOrArguments(node, node.name);
46259
46271
  }
46260
46272
  if (!ts.isBindingPattern(node.name)) {
46261
- if (ts.isInJSFile(node) && ts.isRequireVariableDeclaration(node) && !ts.getJSDocTypeTag(node)) {
46273
+ if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node)) {
46262
46274
  declareSymbolAndAddToSymbolTable(node, 2097152 /* Alias */, 2097152 /* AliasExcludes */);
46263
46275
  }
46264
46276
  else if (ts.isBlockOrCatchScoped(node)) {
@@ -49037,7 +49049,7 @@ var ts;
49037
49049
  && isAliasableOrJsExpression(node.parent.right)
49038
49050
  || node.kind === 295 /* ShorthandPropertyAssignment */
49039
49051
  || node.kind === 294 /* PropertyAssignment */ && isAliasableOrJsExpression(node.initializer)
49040
- || ts.isRequireVariableDeclaration(node);
49052
+ || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node);
49041
49053
  }
49042
49054
  function isAliasableOrJsExpression(e) {
49043
49055
  return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e);
@@ -50008,7 +50020,7 @@ var ts;
50008
50020
  if (!sigs || !sigs.length) {
50009
50021
  sigs = getSignaturesOfStructuredType(type, 1 /* Construct */);
50010
50022
  }
50011
- if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */)) {
50023
+ if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */, /*skipObjectFunctionPropertyAugment*/ true)) {
50012
50024
  var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, reference);
50013
50025
  return cloneTypeAsModuleType(symbol, moduleType, referenceParent);
50014
50026
  }
@@ -80440,7 +80452,7 @@ var ts;
80440
80452
  }
80441
80453
  // For a commonjs `const x = require`, validate the alias and exit
80442
80454
  var symbol = getSymbolOfNode(node);
80443
- if (symbol.flags & 2097152 /* Alias */ && ts.isRequireVariableDeclaration(node)) {
80455
+ if (symbol.flags & 2097152 /* Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) {
80444
80456
  checkAliasSymbol(node);
80445
80457
  return;
80446
80458
  }
@@ -124537,7 +124549,7 @@ var ts;
124537
124549
  isWhiteSpaceOnlyJsxText(child);
124538
124550
  if (lookInPreviousChild) {
124539
124551
  // actual start of the node is past the position - previous token should be at the end of previous child
124540
- var candidate_1 = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i, sourceFile);
124552
+ var candidate_1 = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i, sourceFile, n.kind);
124541
124553
  return candidate_1 && findRightmostToken(candidate_1, sourceFile);
124542
124554
  }
124543
124555
  else {
@@ -124551,7 +124563,7 @@ var ts;
124551
124563
  // the only known case is when position is at the end of the file.
124552
124564
  // Try to find the rightmost token in the file without filtering.
124553
124565
  // Namely we are skipping the check: 'position < node.end'
124554
- var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
124566
+ var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile, n.kind);
124555
124567
  return candidate && findRightmostToken(candidate, sourceFile);
124556
124568
  }
124557
124569
  }
@@ -124567,17 +124579,19 @@ var ts;
124567
124579
  if (children.length === 0) {
124568
124580
  return n;
124569
124581
  }
124570
- var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
124582
+ var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile, n.kind);
124571
124583
  return candidate && findRightmostToken(candidate, sourceFile);
124572
124584
  }
124573
124585
  /**
124574
124586
  * Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
124575
124587
  */
124576
- function findRightmostChildNodeWithTokens(children, exclusiveStartPosition, sourceFile) {
124588
+ function findRightmostChildNodeWithTokens(children, exclusiveStartPosition, sourceFile, parentKind) {
124577
124589
  for (var i = exclusiveStartPosition - 1; i >= 0; i--) {
124578
124590
  var child = children[i];
124579
124591
  if (isWhiteSpaceOnlyJsxText(child)) {
124580
- ts.Debug.assert(i > 0, "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
124592
+ if (i === 0 && (parentKind === 11 /* JsxText */ || parentKind === 278 /* JsxSelfClosingElement */)) {
124593
+ ts.Debug.fail("`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
124594
+ }
124581
124595
  }
124582
124596
  else if (nodeHasTokens(children[i], sourceFile)) {
124583
124597
  return children[i];
@@ -128994,7 +129008,7 @@ var ts;
128994
129008
  return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
128995
129009
  }
128996
129010
  function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences) {
128997
- 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, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
129011
+ 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;
128998
129012
  // Verify if the file is JSX language variant
128999
129013
  if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
129000
129014
  var completionInfo = getJsxClosingTagCompletion(location, sourceFile);
@@ -129005,7 +129019,7 @@ var ts;
129005
129019
  var entries = [];
129006
129020
  if (isUncheckedFile(sourceFile, compilerOptions)) {
129007
129021
  var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
129008
- /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
129022
+ /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
129009
129023
  getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
129010
129024
  }
129011
129025
  else {
@@ -129013,7 +129027,7 @@ var ts;
129013
129027
  return undefined;
129014
129028
  }
129015
129029
  getCompletionEntriesFromSymbols(symbols, entries,
129016
- /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
129030
+ /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
129017
129031
  }
129018
129032
  if (keywordFilters !== 0 /* None */) {
129019
129033
  var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
@@ -129119,7 +129133,7 @@ var ts;
129119
129133
  function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
129120
129134
  return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
129121
129135
  }
129122
- function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind) {
129136
+ function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, isJsxIdentifierExpected, isRightOfOpenTag) {
129123
129137
  var _a, _b;
129124
129138
  var insertText;
129125
129139
  var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
@@ -129190,24 +129204,7 @@ var ts;
129190
129204
  source = CompletionSource.ClassMemberSnippet;
129191
129205
  }
129192
129206
  }
129193
- // Before offering up a JSX attribute snippet, ensure that we aren't potentially completing
129194
- // a tag name; this may appear as an attribute after the "<" when the tag has not yet been
129195
- // closed, as in:
129196
- //
129197
- // return <>
129198
- // foo <butto|
129199
- // </>
129200
- //
129201
- // We can detect this case by checking if both:
129202
- //
129203
- // 1. The location is "<", so we are completing immediately after it.
129204
- // 2. The "<" has the same position as its parent, so is not a binary expression.
129205
- var kind = ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, location);
129206
- if (kind === "JSX attribute" /* jsxAttribute */
129207
- && (location.kind !== 29 /* LessThanToken */ || location.pos !== location.parent.pos)
129208
- && preferences.includeCompletionsWithSnippetText
129209
- && preferences.jsxAttributeCompletionStyle
129210
- && preferences.jsxAttributeCompletionStyle !== "none") {
129207
+ if (isJsxIdentifierExpected && !isRightOfOpenTag && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
129211
129208
  var useBraces_1 = preferences.jsxAttributeCompletionStyle === "braces";
129212
129209
  var type = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
129213
129210
  // If is boolean like or undefined, don't return a snippet we want just to return the completion.
@@ -129245,7 +129242,7 @@ var ts;
129245
129242
  // entries (like JavaScript identifier entries).
129246
129243
  return {
129247
129244
  name: name,
129248
- kind: kind,
129245
+ kind: ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, location),
129249
129246
  kindModifiers: ts.SymbolDisplay.getSymbolModifiers(typeChecker, symbol),
129250
129247
  sortText: sortText,
129251
129248
  source: source,
@@ -129520,7 +129517,7 @@ var ts;
129520
129517
  return CompletionSource.ThisProperty;
129521
129518
  }
129522
129519
  }
129523
- function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
129520
+ function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag) {
129524
129521
  var _a;
129525
129522
  var start = ts.timestamp();
129526
129523
  var variableDeclaration = getVariableDeclaration(location);
@@ -129541,7 +129538,7 @@ var ts;
129541
129538
  var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
129542
129539
  var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
129543
129540
  var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
129544
- var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind);
129541
+ var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, isJsxIdentifierExpected, isRightOfOpenTag);
129545
129542
  if (!entry) {
129546
129543
  continue;
129547
129544
  }
@@ -130135,6 +130132,7 @@ var ts;
130135
130132
  symbolToSortTextIdMap: symbolToSortTextIdMap,
130136
130133
  isTypeOnlyLocation: isTypeOnlyLocation,
130137
130134
  isJsxIdentifierExpected: isJsxIdentifierExpected,
130135
+ isRightOfOpenTag: isRightOfOpenTag,
130138
130136
  importCompletionNode: importCompletionNode,
130139
130137
  hasUnresolvedAutoImports: hasUnresolvedAutoImports,
130140
130138
  };
@@ -133066,7 +133064,7 @@ var ts;
133066
133064
  ts.Debug.assert(parent.name === node);
133067
133065
  return true;
133068
133066
  case 202 /* BindingElement */:
133069
- return ts.isInJSFile(node) && ts.isRequireVariableDeclaration(parent);
133067
+ return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent);
133070
133068
  default:
133071
133069
  return false;
133072
133070
  }
@@ -134466,7 +134464,7 @@ var ts;
134466
134464
  // Use the parent symbol if the location is commonjs require syntax on javascript files only.
134467
134465
  if (ts.isInJSFile(referenceLocation)
134468
134466
  && referenceLocation.parent.kind === 202 /* BindingElement */
134469
- && ts.isRequireVariableDeclaration(referenceLocation.parent)) {
134467
+ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent)) {
134470
134468
  referenceSymbol = referenceLocation.parent.symbol;
134471
134469
  // The parent will not have a symbol if it's an ObjectBindingPattern (when destructuring is used). In
134472
134470
  // this case, just skip it, since the bound identifiers are not an alias of the import.
@@ -136173,7 +136171,7 @@ var ts;
136173
136171
  return declaration.parent.kind === 268 /* NamedImports */;
136174
136172
  case 202 /* BindingElement */:
136175
136173
  case 253 /* VariableDeclaration */:
136176
- return ts.isInJSFile(declaration) && ts.isRequireVariableDeclaration(declaration);
136174
+ return ts.isInJSFile(declaration) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(declaration);
136177
136175
  default:
136178
136176
  return false;
136179
136177
  }
@@ -137456,6 +137454,9 @@ var ts;
137456
137454
  // We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
137457
137455
  // Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
137458
137456
  function areSameModule(a, b) {
137457
+ if (!a.body || !b.body) {
137458
+ return a.body === b.body;
137459
+ }
137459
137460
  return a.body.kind === b.body.kind && (a.body.kind !== 260 /* ModuleDeclaration */ || areSameModule(a.body, b.body));
137460
137461
  }
137461
137462
  /** Merge source into target. Source should be thrown away after this is called. */
@@ -149205,7 +149206,7 @@ var ts;
149205
149206
  var importKind = getImportKind(importingFile, exportKind, compilerOptions);
149206
149207
  return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
149207
149208
  var i = ts.importFromModuleSpecifier(moduleSpecifier);
149208
- if (ts.isRequireVariableDeclaration(i.parent)) {
149209
+ if (ts.isVariableDeclarationInitializedToRequire(i.parent)) {
149209
149210
  return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
149210
149211
  }
149211
149212
  if (i.kind === 265 /* ImportDeclaration */ || i.kind === 264 /* ImportEqualsDeclaration */) {
@@ -157265,11 +157266,12 @@ var ts;
157265
157266
  var result = [];
157266
157267
  return visitor(selection) ? undefined : result;
157267
157268
  function visitor(node) {
157269
+ var _a;
157268
157270
  if (ts.isTypeReferenceNode(node)) {
157269
157271
  if (ts.isIdentifier(node.typeName)) {
157270
157272
  var symbol = checker.resolveName(node.typeName.text, node.typeName, 262144 /* TypeParameter */, /* excludeGlobals */ true);
157271
- if (symbol === null || symbol === void 0 ? void 0 : symbol.declarations) {
157272
- var declaration = ts.cast(ts.first(symbol.declarations), ts.isTypeParameterDeclaration);
157273
+ var declaration = ts.tryCast((_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a[0], ts.isTypeParameterDeclaration);
157274
+ if (declaration) {
157273
157275
  if (rangeContainsSkipTrivia(statement, declaration, file) && !rangeContainsSkipTrivia(selection, declaration, file)) {
157274
157276
  ts.pushIfUnique(result, declaration);
157275
157277
  }
package/lib/typescript.js CHANGED
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = "4.5.4";
297
+ ts.version = "4.5.5";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -16033,7 +16033,7 @@ var ts;
16033
16033
  }
16034
16034
  ts.getExternalModuleImportEqualsDeclarationExpression = getExternalModuleImportEqualsDeclarationExpression;
16035
16035
  function getExternalModuleRequireArgument(node) {
16036
- return isRequireVariableDeclaration(node) && getLeftmostAccessExpression(node.initializer).arguments[0];
16036
+ return isVariableDeclarationInitializedToBareOrAccessedRequire(node) && getLeftmostAccessExpression(node.initializer).arguments[0];
16037
16037
  }
16038
16038
  ts.getExternalModuleRequireArgument = getExternalModuleRequireArgument;
16039
16039
  function isInternalModuleImportEqualsDeclaration(node) {
@@ -16091,17 +16091,29 @@ var ts;
16091
16091
  * Returns true if the node is a VariableDeclaration initialized to a require call (see `isRequireCall`).
16092
16092
  * This function does not test if the node is in a JavaScript file or not.
16093
16093
  */
16094
- function isRequireVariableDeclaration(node) {
16094
+ function isVariableDeclarationInitializedToRequire(node) {
16095
+ return isVariableDeclarationInitializedWithRequireHelper(node, /*allowAccessedRequire*/ false);
16096
+ }
16097
+ ts.isVariableDeclarationInitializedToRequire = isVariableDeclarationInitializedToRequire;
16098
+ /**
16099
+ * Like {@link isVariableDeclarationInitializedToRequire} but allows things like `require("...").foo.bar` or `require("...")["baz"]`.
16100
+ */
16101
+ function isVariableDeclarationInitializedToBareOrAccessedRequire(node) {
16102
+ return isVariableDeclarationInitializedWithRequireHelper(node, /*allowAccessedRequire*/ true);
16103
+ }
16104
+ ts.isVariableDeclarationInitializedToBareOrAccessedRequire = isVariableDeclarationInitializedToBareOrAccessedRequire;
16105
+ function isVariableDeclarationInitializedWithRequireHelper(node, allowAccessedRequire) {
16095
16106
  if (node.kind === 202 /* BindingElement */) {
16096
16107
  node = node.parent.parent;
16097
16108
  }
16098
- return ts.isVariableDeclaration(node) && !!node.initializer && isRequireCall(getLeftmostAccessExpression(node.initializer), /*requireStringLiteralLikeArgument*/ true);
16109
+ return ts.isVariableDeclaration(node) &&
16110
+ !!node.initializer &&
16111
+ isRequireCall(allowAccessedRequire ? getLeftmostAccessExpression(node.initializer) : node.initializer, /*requireStringLiteralLikeArgument*/ true);
16099
16112
  }
16100
- ts.isRequireVariableDeclaration = isRequireVariableDeclaration;
16101
16113
  function isRequireVariableStatement(node) {
16102
16114
  return ts.isVariableStatement(node)
16103
16115
  && node.declarationList.declarations.length > 0
16104
- && ts.every(node.declarationList.declarations, function (decl) { return isRequireVariableDeclaration(decl); });
16116
+ && ts.every(node.declarationList.declarations, function (decl) { return isVariableDeclarationInitializedToRequire(decl); });
16105
16117
  }
16106
16118
  ts.isRequireVariableStatement = isRequireVariableStatement;
16107
16119
  function isSingleOrDoubleQuote(charCode) {
@@ -46258,7 +46270,7 @@ var ts;
46258
46270
  checkStrictModeEvalOrArguments(node, node.name);
46259
46271
  }
46260
46272
  if (!ts.isBindingPattern(node.name)) {
46261
- if (ts.isInJSFile(node) && ts.isRequireVariableDeclaration(node) && !ts.getJSDocTypeTag(node)) {
46273
+ if (ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node) && !ts.getJSDocTypeTag(node)) {
46262
46274
  declareSymbolAndAddToSymbolTable(node, 2097152 /* Alias */, 2097152 /* AliasExcludes */);
46263
46275
  }
46264
46276
  else if (ts.isBlockOrCatchScoped(node)) {
@@ -49037,7 +49049,7 @@ var ts;
49037
49049
  && isAliasableOrJsExpression(node.parent.right)
49038
49050
  || node.kind === 295 /* ShorthandPropertyAssignment */
49039
49051
  || node.kind === 294 /* PropertyAssignment */ && isAliasableOrJsExpression(node.initializer)
49040
- || ts.isRequireVariableDeclaration(node);
49052
+ || ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node);
49041
49053
  }
49042
49054
  function isAliasableOrJsExpression(e) {
49043
49055
  return ts.isAliasableExpression(e) || ts.isFunctionExpression(e) && isJSConstructor(e);
@@ -50008,7 +50020,7 @@ var ts;
50008
50020
  if (!sigs || !sigs.length) {
50009
50021
  sigs = getSignaturesOfStructuredType(type, 1 /* Construct */);
50010
50022
  }
50011
- if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */)) {
50023
+ if ((sigs && sigs.length) || getPropertyOfType(type, "default" /* Default */, /*skipObjectFunctionPropertyAugment*/ true)) {
50012
50024
  var moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol, reference);
50013
50025
  return cloneTypeAsModuleType(symbol, moduleType, referenceParent);
50014
50026
  }
@@ -80440,7 +80452,7 @@ var ts;
80440
80452
  }
80441
80453
  // For a commonjs `const x = require`, validate the alias and exit
80442
80454
  var symbol = getSymbolOfNode(node);
80443
- if (symbol.flags & 2097152 /* Alias */ && ts.isRequireVariableDeclaration(node)) {
80455
+ if (symbol.flags & 2097152 /* Alias */ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(node)) {
80444
80456
  checkAliasSymbol(node);
80445
80457
  return;
80446
80458
  }
@@ -124537,7 +124549,7 @@ var ts;
124537
124549
  isWhiteSpaceOnlyJsxText(child);
124538
124550
  if (lookInPreviousChild) {
124539
124551
  // actual start of the node is past the position - previous token should be at the end of previous child
124540
- var candidate_1 = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i, sourceFile);
124552
+ var candidate_1 = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ i, sourceFile, n.kind);
124541
124553
  return candidate_1 && findRightmostToken(candidate_1, sourceFile);
124542
124554
  }
124543
124555
  else {
@@ -124551,7 +124563,7 @@ var ts;
124551
124563
  // the only known case is when position is at the end of the file.
124552
124564
  // Try to find the rightmost token in the file without filtering.
124553
124565
  // Namely we are skipping the check: 'position < node.end'
124554
- var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
124566
+ var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile, n.kind);
124555
124567
  return candidate && findRightmostToken(candidate, sourceFile);
124556
124568
  }
124557
124569
  }
@@ -124567,17 +124579,19 @@ var ts;
124567
124579
  if (children.length === 0) {
124568
124580
  return n;
124569
124581
  }
124570
- var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
124582
+ var candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile, n.kind);
124571
124583
  return candidate && findRightmostToken(candidate, sourceFile);
124572
124584
  }
124573
124585
  /**
124574
124586
  * Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
124575
124587
  */
124576
- function findRightmostChildNodeWithTokens(children, exclusiveStartPosition, sourceFile) {
124588
+ function findRightmostChildNodeWithTokens(children, exclusiveStartPosition, sourceFile, parentKind) {
124577
124589
  for (var i = exclusiveStartPosition - 1; i >= 0; i--) {
124578
124590
  var child = children[i];
124579
124591
  if (isWhiteSpaceOnlyJsxText(child)) {
124580
- ts.Debug.assert(i > 0, "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
124592
+ if (i === 0 && (parentKind === 11 /* JsxText */ || parentKind === 278 /* JsxSelfClosingElement */)) {
124593
+ ts.Debug.fail("`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
124594
+ }
124581
124595
  }
124582
124596
  else if (nodeHasTokens(children[i], sourceFile)) {
124583
124597
  return children[i];
@@ -128994,7 +129008,7 @@ var ts;
128994
129008
  return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
128995
129009
  }
128996
129010
  function completionInfoFromData(sourceFile, host, program, compilerOptions, log, completionData, preferences) {
128997
- 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, importCompletionNode = completionData.importCompletionNode, insideJsDocTagTypeExpression = completionData.insideJsDocTagTypeExpression, symbolToSortTextIdMap = completionData.symbolToSortTextIdMap, hasUnresolvedAutoImports = completionData.hasUnresolvedAutoImports;
129011
+ 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;
128998
129012
  // Verify if the file is JSX language variant
128999
129013
  if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
129000
129014
  var completionInfo = getJsxClosingTagCompletion(location, sourceFile);
@@ -129005,7 +129019,7 @@ var ts;
129005
129019
  var entries = [];
129006
129020
  if (isUncheckedFile(sourceFile, compilerOptions)) {
129007
129021
  var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
129008
- /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
129022
+ /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
129009
129023
  getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
129010
129024
  }
129011
129025
  else {
@@ -129013,7 +129027,7 @@ var ts;
129013
129027
  return undefined;
129014
129028
  }
129015
129029
  getCompletionEntriesFromSymbols(symbols, entries,
129016
- /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
129030
+ /*replacementToken*/ undefined, contextToken, location, sourceFile, host, program, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag);
129017
129031
  }
129018
129032
  if (keywordFilters !== 0 /* None */) {
129019
129033
  var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
@@ -129119,7 +129133,7 @@ var ts;
129119
129133
  function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
129120
129134
  return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
129121
129135
  }
129122
- function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind) {
129136
+ function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences, completionKind, isJsxIdentifierExpected, isRightOfOpenTag) {
129123
129137
  var _a, _b;
129124
129138
  var insertText;
129125
129139
  var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
@@ -129190,24 +129204,7 @@ var ts;
129190
129204
  source = CompletionSource.ClassMemberSnippet;
129191
129205
  }
129192
129206
  }
129193
- // Before offering up a JSX attribute snippet, ensure that we aren't potentially completing
129194
- // a tag name; this may appear as an attribute after the "<" when the tag has not yet been
129195
- // closed, as in:
129196
- //
129197
- // return <>
129198
- // foo <butto|
129199
- // </>
129200
- //
129201
- // We can detect this case by checking if both:
129202
- //
129203
- // 1. The location is "<", so we are completing immediately after it.
129204
- // 2. The "<" has the same position as its parent, so is not a binary expression.
129205
- var kind = ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, location);
129206
- if (kind === "JSX attribute" /* jsxAttribute */
129207
- && (location.kind !== 29 /* LessThanToken */ || location.pos !== location.parent.pos)
129208
- && preferences.includeCompletionsWithSnippetText
129209
- && preferences.jsxAttributeCompletionStyle
129210
- && preferences.jsxAttributeCompletionStyle !== "none") {
129207
+ if (isJsxIdentifierExpected && !isRightOfOpenTag && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
129211
129208
  var useBraces_1 = preferences.jsxAttributeCompletionStyle === "braces";
129212
129209
  var type = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
129213
129210
  // If is boolean like or undefined, don't return a snippet we want just to return the completion.
@@ -129245,7 +129242,7 @@ var ts;
129245
129242
  // entries (like JavaScript identifier entries).
129246
129243
  return {
129247
129244
  name: name,
129248
- kind: kind,
129245
+ kind: ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, location),
129249
129246
  kindModifiers: ts.SymbolDisplay.getSymbolModifiers(typeChecker, symbol),
129250
129247
  sortText: sortText,
129251
129248
  source: source,
@@ -129520,7 +129517,7 @@ var ts;
129520
129517
  return CompletionSource.ThisProperty;
129521
129518
  }
129522
129519
  }
129523
- function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
129520
+ function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, host, program, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap, isJsxIdentifierExpected, isRightOfOpenTag) {
129524
129521
  var _a;
129525
129522
  var start = ts.timestamp();
129526
129523
  var variableDeclaration = getVariableDeclaration(location);
@@ -129541,7 +129538,7 @@ var ts;
129541
129538
  var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
129542
129539
  var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
129543
129540
  var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
129544
- var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind);
129541
+ var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, host, program, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences, kind, isJsxIdentifierExpected, isRightOfOpenTag);
129545
129542
  if (!entry) {
129546
129543
  continue;
129547
129544
  }
@@ -130135,6 +130132,7 @@ var ts;
130135
130132
  symbolToSortTextIdMap: symbolToSortTextIdMap,
130136
130133
  isTypeOnlyLocation: isTypeOnlyLocation,
130137
130134
  isJsxIdentifierExpected: isJsxIdentifierExpected,
130135
+ isRightOfOpenTag: isRightOfOpenTag,
130138
130136
  importCompletionNode: importCompletionNode,
130139
130137
  hasUnresolvedAutoImports: hasUnresolvedAutoImports,
130140
130138
  };
@@ -133066,7 +133064,7 @@ var ts;
133066
133064
  ts.Debug.assert(parent.name === node);
133067
133065
  return true;
133068
133066
  case 202 /* BindingElement */:
133069
- return ts.isInJSFile(node) && ts.isRequireVariableDeclaration(parent);
133067
+ return ts.isInJSFile(node) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(parent);
133070
133068
  default:
133071
133069
  return false;
133072
133070
  }
@@ -134466,7 +134464,7 @@ var ts;
134466
134464
  // Use the parent symbol if the location is commonjs require syntax on javascript files only.
134467
134465
  if (ts.isInJSFile(referenceLocation)
134468
134466
  && referenceLocation.parent.kind === 202 /* BindingElement */
134469
- && ts.isRequireVariableDeclaration(referenceLocation.parent)) {
134467
+ && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(referenceLocation.parent)) {
134470
134468
  referenceSymbol = referenceLocation.parent.symbol;
134471
134469
  // The parent will not have a symbol if it's an ObjectBindingPattern (when destructuring is used). In
134472
134470
  // this case, just skip it, since the bound identifiers are not an alias of the import.
@@ -136173,7 +136171,7 @@ var ts;
136173
136171
  return declaration.parent.kind === 268 /* NamedImports */;
136174
136172
  case 202 /* BindingElement */:
136175
136173
  case 253 /* VariableDeclaration */:
136176
- return ts.isInJSFile(declaration) && ts.isRequireVariableDeclaration(declaration);
136174
+ return ts.isInJSFile(declaration) && ts.isVariableDeclarationInitializedToBareOrAccessedRequire(declaration);
136177
136175
  default:
136178
136176
  return false;
136179
136177
  }
@@ -137456,6 +137454,9 @@ var ts;
137456
137454
  // We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes.
137457
137455
  // Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'!
137458
137456
  function areSameModule(a, b) {
137457
+ if (!a.body || !b.body) {
137458
+ return a.body === b.body;
137459
+ }
137459
137460
  return a.body.kind === b.body.kind && (a.body.kind !== 260 /* ModuleDeclaration */ || areSameModule(a.body, b.body));
137460
137461
  }
137461
137462
  /** Merge source into target. Source should be thrown away after this is called. */
@@ -149205,7 +149206,7 @@ var ts;
149205
149206
  var importKind = getImportKind(importingFile, exportKind, compilerOptions);
149206
149207
  return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
149207
149208
  var i = ts.importFromModuleSpecifier(moduleSpecifier);
149208
- if (ts.isRequireVariableDeclaration(i.parent)) {
149209
+ if (ts.isVariableDeclarationInitializedToRequire(i.parent)) {
149209
149210
  return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
149210
149211
  }
149211
149212
  if (i.kind === 265 /* ImportDeclaration */ || i.kind === 264 /* ImportEqualsDeclaration */) {
@@ -157265,11 +157266,12 @@ var ts;
157265
157266
  var result = [];
157266
157267
  return visitor(selection) ? undefined : result;
157267
157268
  function visitor(node) {
157269
+ var _a;
157268
157270
  if (ts.isTypeReferenceNode(node)) {
157269
157271
  if (ts.isIdentifier(node.typeName)) {
157270
157272
  var symbol = checker.resolveName(node.typeName.text, node.typeName, 262144 /* TypeParameter */, /* excludeGlobals */ true);
157271
- if (symbol === null || symbol === void 0 ? void 0 : symbol.declarations) {
157272
- var declaration = ts.cast(ts.first(symbol.declarations), ts.isTypeParameterDeclaration);
157273
+ var declaration = ts.tryCast((_a = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _a === void 0 ? void 0 : _a[0], ts.isTypeParameterDeclaration);
157274
+ if (declaration) {
157273
157275
  if (rangeContainsSkipTrivia(statement, declaration, file) && !rangeContainsSkipTrivia(selection, declaration, file)) {
157274
157276
  ts.pushIfUnique(result, declaration);
157275
157277
  }