typescript 5.1.0-dev.20230403 → 5.1.0-dev.20230405

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.
@@ -35,7 +35,7 @@ var ts = (() => {
35
35
  "src/compiler/corePublic.ts"() {
36
36
  "use strict";
37
37
  versionMajorMinor = "5.1";
38
- version = `${versionMajorMinor}.0-dev.20230403`;
38
+ version = `${versionMajorMinor}.0-dev.20230405`;
39
39
  Comparison = /* @__PURE__ */ ((Comparison3) => {
40
40
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
41
41
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -82801,6 +82801,14 @@ ${lanes.join("\n")}
82801
82801
  const symbol = getSymbolAtLocation(node);
82802
82802
  return symbol ? getDeclaredTypeOfSymbol(symbol) : errorType;
82803
82803
  }
82804
+ if (isBindingElement(node)) {
82805
+ return getTypeForVariableLikeDeclaration(
82806
+ node,
82807
+ /*includeOptionality*/
82808
+ true,
82809
+ 0 /* Normal */
82810
+ ) || errorType;
82811
+ }
82804
82812
  if (isDeclaration(node)) {
82805
82813
  const symbol = getSymbolOfDeclaration(node);
82806
82814
  return symbol ? getTypeOfSymbol(symbol) : errorType;
@@ -148111,6 +148119,7 @@ ${lanes.join("\n")}
148111
148119
  return void 0;
148112
148120
  }
148113
148121
  const compilerOptions = program.getCompilerOptions();
148122
+ const checker = program.getTypeChecker();
148114
148123
  const incompleteCompletionsCache = preferences.allowIncompleteCompletions ? (_a2 = host.getIncompleteCompletionsCache) == null ? void 0 : _a2.call(host) : void 0;
148115
148124
  if (incompleteCompletionsCache && completionKind === 3 /* TriggerForIncompleteCompletions */ && previousToken && isIdentifier(previousToken)) {
148116
148125
  const incompleteContinuation = continuePreviousIncompleteResponse(incompleteCompletionsCache, sourceFile, previousToken, program, host, preferences, cancellationToken, position);
@@ -148151,9 +148160,31 @@ ${lanes.join("\n")}
148151
148160
  }
148152
148161
  return response;
148153
148162
  case 1 /* JsDocTagName */:
148154
- return jsdocCompletionInfo(ts_JsDoc_exports.getJSDocTagNameCompletions());
148163
+ return jsdocCompletionInfo([
148164
+ ...ts_JsDoc_exports.getJSDocTagNameCompletions(),
148165
+ ...getJSDocParameterCompletions(
148166
+ sourceFile,
148167
+ position,
148168
+ checker,
148169
+ compilerOptions,
148170
+ preferences,
148171
+ /*tagNameOnly*/
148172
+ true
148173
+ )
148174
+ ]);
148155
148175
  case 2 /* JsDocTag */:
148156
- return jsdocCompletionInfo(ts_JsDoc_exports.getJSDocTagCompletions());
148176
+ return jsdocCompletionInfo([
148177
+ ...ts_JsDoc_exports.getJSDocTagCompletions(),
148178
+ ...getJSDocParameterCompletions(
148179
+ sourceFile,
148180
+ position,
148181
+ checker,
148182
+ compilerOptions,
148183
+ preferences,
148184
+ /*tagNameOnly*/
148185
+ false
148186
+ )
148187
+ ]);
148157
148188
  case 3 /* JsDocParameterName */:
148158
148189
  return jsdocCompletionInfo(ts_JsDoc_exports.getJSDocParameterNameCompletions(completionData.tag));
148159
148190
  case 4 /* Keywords */:
@@ -148241,6 +148272,264 @@ ${lanes.join("\n")}
148241
148272
  function jsdocCompletionInfo(entries) {
148242
148273
  return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries };
148243
148274
  }
148275
+ function getJSDocParameterCompletions(sourceFile, position, checker, options, preferences, tagNameOnly) {
148276
+ const currentToken = getTokenAtPosition(sourceFile, position);
148277
+ if (!isJSDocTag(currentToken) && !isJSDoc(currentToken)) {
148278
+ return [];
148279
+ }
148280
+ const jsDoc = isJSDoc(currentToken) ? currentToken : currentToken.parent;
148281
+ if (!isJSDoc(jsDoc)) {
148282
+ return [];
148283
+ }
148284
+ const func = jsDoc.parent;
148285
+ if (!isFunctionLike(func)) {
148286
+ return [];
148287
+ }
148288
+ const isJs = isSourceFileJS(sourceFile);
148289
+ const isSnippet = preferences.includeCompletionsWithSnippetText || void 0;
148290
+ const paramTagCount = countWhere(jsDoc.tags, (tag) => isJSDocParameterTag(tag) && tag.getEnd() <= position);
148291
+ return mapDefined(func.parameters, (param) => {
148292
+ if (getJSDocParameterTags(param).length) {
148293
+ return void 0;
148294
+ }
148295
+ if (isIdentifier(param.name)) {
148296
+ const tabstopCounter = { tabstop: 1 };
148297
+ const paramName = param.name.text;
148298
+ let displayText = getJSDocParamAnnotation(
148299
+ paramName,
148300
+ param.initializer,
148301
+ param.dotDotDotToken,
148302
+ isJs,
148303
+ /*isObject*/
148304
+ false,
148305
+ /*isSnippet*/
148306
+ false,
148307
+ checker,
148308
+ options,
148309
+ preferences
148310
+ );
148311
+ let snippetText = isSnippet ? getJSDocParamAnnotation(
148312
+ paramName,
148313
+ param.initializer,
148314
+ param.dotDotDotToken,
148315
+ isJs,
148316
+ /*isObject*/
148317
+ false,
148318
+ /*isSnippet*/
148319
+ true,
148320
+ checker,
148321
+ options,
148322
+ preferences,
148323
+ tabstopCounter
148324
+ ) : void 0;
148325
+ if (tagNameOnly) {
148326
+ displayText = displayText.slice(1);
148327
+ if (snippetText)
148328
+ snippetText = snippetText.slice(1);
148329
+ }
148330
+ return {
148331
+ name: displayText,
148332
+ kind: "parameter" /* parameterElement */,
148333
+ sortText: SortText.LocationPriority,
148334
+ insertText: isSnippet ? snippetText : void 0,
148335
+ isSnippet
148336
+ };
148337
+ } else if (param.parent.parameters.indexOf(param) === paramTagCount) {
148338
+ const paramPath = `param${paramTagCount}`;
148339
+ const displayTextResult = generateJSDocParamTagsForDestructuring(
148340
+ paramPath,
148341
+ param.name,
148342
+ param.initializer,
148343
+ param.dotDotDotToken,
148344
+ isJs,
148345
+ /*isSnippet*/
148346
+ false,
148347
+ checker,
148348
+ options,
148349
+ preferences
148350
+ );
148351
+ const snippetTextResult = isSnippet ? generateJSDocParamTagsForDestructuring(
148352
+ paramPath,
148353
+ param.name,
148354
+ param.initializer,
148355
+ param.dotDotDotToken,
148356
+ isJs,
148357
+ /*isSnippet*/
148358
+ true,
148359
+ checker,
148360
+ options,
148361
+ preferences
148362
+ ) : void 0;
148363
+ let displayText = displayTextResult.join(getNewLineCharacter(options) + "* ");
148364
+ let snippetText = snippetTextResult == null ? void 0 : snippetTextResult.join(getNewLineCharacter(options) + "* ");
148365
+ if (tagNameOnly) {
148366
+ displayText = displayText.slice(1);
148367
+ if (snippetText)
148368
+ snippetText = snippetText.slice(1);
148369
+ }
148370
+ return {
148371
+ name: displayText,
148372
+ kind: "parameter" /* parameterElement */,
148373
+ sortText: SortText.LocationPriority,
148374
+ insertText: isSnippet ? snippetText : void 0,
148375
+ isSnippet
148376
+ };
148377
+ }
148378
+ });
148379
+ }
148380
+ function generateJSDocParamTagsForDestructuring(path, pattern, initializer, dotDotDotToken, isJs, isSnippet, checker, options, preferences) {
148381
+ if (!isJs) {
148382
+ return [
148383
+ getJSDocParamAnnotation(
148384
+ path,
148385
+ initializer,
148386
+ dotDotDotToken,
148387
+ isJs,
148388
+ /*isObject*/
148389
+ false,
148390
+ isSnippet,
148391
+ checker,
148392
+ options,
148393
+ preferences,
148394
+ { tabstop: 1 }
148395
+ )
148396
+ ];
148397
+ }
148398
+ return patternWorker(path, pattern, initializer, dotDotDotToken, { tabstop: 1 });
148399
+ function patternWorker(path2, pattern2, initializer2, dotDotDotToken2, counter) {
148400
+ if (isObjectBindingPattern(pattern2) && !dotDotDotToken2) {
148401
+ const oldTabstop = counter.tabstop;
148402
+ const childCounter = { tabstop: oldTabstop };
148403
+ const rootParam = getJSDocParamAnnotation(
148404
+ path2,
148405
+ initializer2,
148406
+ dotDotDotToken2,
148407
+ isJs,
148408
+ /*isObject*/
148409
+ true,
148410
+ isSnippet,
148411
+ checker,
148412
+ options,
148413
+ preferences,
148414
+ childCounter
148415
+ );
148416
+ let childTags = [];
148417
+ for (const element of pattern2.elements) {
148418
+ const elementTags = elementWorker(path2, element, childCounter);
148419
+ if (!elementTags) {
148420
+ childTags = void 0;
148421
+ break;
148422
+ } else {
148423
+ childTags.push(...elementTags);
148424
+ }
148425
+ }
148426
+ if (childTags) {
148427
+ counter.tabstop = childCounter.tabstop;
148428
+ return [rootParam, ...childTags];
148429
+ }
148430
+ }
148431
+ return [
148432
+ getJSDocParamAnnotation(
148433
+ path2,
148434
+ initializer2,
148435
+ dotDotDotToken2,
148436
+ isJs,
148437
+ /*isObject*/
148438
+ false,
148439
+ isSnippet,
148440
+ checker,
148441
+ options,
148442
+ preferences,
148443
+ counter
148444
+ )
148445
+ ];
148446
+ }
148447
+ function elementWorker(path2, element, counter) {
148448
+ if (!element.propertyName && isIdentifier(element.name) || isIdentifier(element.name)) {
148449
+ const propertyName = element.propertyName ? tryGetTextOfPropertyName(element.propertyName) : element.name.text;
148450
+ if (!propertyName) {
148451
+ return void 0;
148452
+ }
148453
+ const paramName = `${path2}.${propertyName}`;
148454
+ return [
148455
+ getJSDocParamAnnotation(
148456
+ paramName,
148457
+ element.initializer,
148458
+ element.dotDotDotToken,
148459
+ isJs,
148460
+ /*isObject*/
148461
+ false,
148462
+ isSnippet,
148463
+ checker,
148464
+ options,
148465
+ preferences,
148466
+ counter
148467
+ )
148468
+ ];
148469
+ } else if (element.propertyName) {
148470
+ const propertyName = tryGetTextOfPropertyName(element.propertyName);
148471
+ return propertyName && patternWorker(`${path2}.${propertyName}`, element.name, element.initializer, element.dotDotDotToken, counter);
148472
+ }
148473
+ return void 0;
148474
+ }
148475
+ }
148476
+ function getJSDocParamAnnotation(paramName, initializer, dotDotDotToken, isJs, isObject, isSnippet, checker, options, preferences, tabstopCounter) {
148477
+ if (isSnippet) {
148478
+ Debug.assertIsDefined(tabstopCounter);
148479
+ }
148480
+ if (initializer) {
148481
+ paramName = getJSDocParamNameWithInitializer(paramName, initializer);
148482
+ }
148483
+ if (isSnippet) {
148484
+ paramName = escapeSnippetText(paramName);
148485
+ }
148486
+ if (isJs) {
148487
+ let type = "*";
148488
+ if (isObject) {
148489
+ Debug.assert(!dotDotDotToken, `Cannot annotate a rest parameter with type 'Object'.`);
148490
+ type = "Object";
148491
+ } else {
148492
+ if (initializer) {
148493
+ const inferredType = checker.getTypeAtLocation(initializer.parent);
148494
+ if (!(inferredType.flags & (1 /* Any */ | 16384 /* Void */))) {
148495
+ const sourceFile = initializer.getSourceFile();
148496
+ const quotePreference = getQuotePreference(sourceFile, preferences);
148497
+ const builderFlags = quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : 0 /* None */;
148498
+ const typeNode = checker.typeToTypeNode(inferredType, findAncestor(initializer, isFunctionLike), builderFlags);
148499
+ if (typeNode) {
148500
+ const printer = isSnippet ? createSnippetPrinter({
148501
+ removeComments: true,
148502
+ module: options.module,
148503
+ target: options.target
148504
+ }) : createPrinter({
148505
+ removeComments: true,
148506
+ module: options.module,
148507
+ target: options.target
148508
+ });
148509
+ setEmitFlags(typeNode, 1 /* SingleLine */);
148510
+ type = printer.printNode(4 /* Unspecified */, typeNode, sourceFile);
148511
+ }
148512
+ }
148513
+ }
148514
+ if (isSnippet && type === "*") {
148515
+ type = `\${${tabstopCounter.tabstop++}:${type}}`;
148516
+ }
148517
+ }
148518
+ const dotDotDot = !isObject && dotDotDotToken ? "..." : "";
148519
+ const description2 = isSnippet ? `\${${tabstopCounter.tabstop++}}` : "";
148520
+ return `@param {${dotDotDot}${type}} ${paramName} ${description2}`;
148521
+ } else {
148522
+ const description2 = isSnippet ? `\${${tabstopCounter.tabstop++}}` : "";
148523
+ return `@param ${paramName} ${description2}`;
148524
+ }
148525
+ }
148526
+ function getJSDocParamNameWithInitializer(paramName, initializer) {
148527
+ const initializerText = initializer.getText().trim();
148528
+ if (initializerText.includes("\n") || initializerText.length > 80) {
148529
+ return `[${paramName}]`;
148530
+ }
148531
+ return `[${paramName}=${initializerText}]`;
148532
+ }
148244
148533
  function keywordToCompletionEntry(keyword) {
148245
148534
  return {
148246
148535
  name: tokenToString(keyword),
@@ -153387,7 +153676,7 @@ ${lanes.join("\n")}
153387
153676
  ((Core2) => {
153388
153677
  function getReferencedSymbolsForNode(position, node, program, sourceFiles, cancellationToken, options = {}, sourceFilesSet = new Set(sourceFiles.map((f) => f.fileName))) {
153389
153678
  var _a2, _b, _c;
153390
- node = getAdjustedNode(node, options);
153679
+ node = getAdjustedNode2(node, options);
153391
153680
  if (isSourceFile(node)) {
153392
153681
  const resolvedRef = ts_GoToDefinition_exports.getReferenceAtPosition(node, position, program);
153393
153682
  if (!(resolvedRef == null ? void 0 : resolvedRef.file)) {
@@ -153455,7 +153744,7 @@ ${lanes.join("\n")}
153455
153744
  return mergeReferences(program, moduleReferences, references, moduleReferencesOfExportTarget);
153456
153745
  }
153457
153746
  Core2.getReferencedSymbolsForNode = getReferencedSymbolsForNode;
153458
- function getAdjustedNode(node, options) {
153747
+ function getAdjustedNode2(node, options) {
153459
153748
  if (options.use === 1 /* References */) {
153460
153749
  node = getAdjustedReferenceLocation(node);
153461
153750
  } else if (options.use === 2 /* Rename */) {
@@ -153463,7 +153752,7 @@ ${lanes.join("\n")}
153463
153752
  }
153464
153753
  return node;
153465
153754
  }
153466
- Core2.getAdjustedNode = getAdjustedNode;
153755
+ Core2.getAdjustedNode = getAdjustedNode2;
153467
153756
  function getReferencesForFileName(fileName, program, sourceFiles, sourceFilesSet = new Set(sourceFiles.map((f) => f.fileName))) {
153468
153757
  var _a2, _b;
153469
153758
  const moduleSymbol = (_a2 = program.getSourceFile(fileName)) == null ? void 0 : _a2.symbol;
@@ -162566,8 +162855,11 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
162566
162855
  return isBinaryExpression(b.left) ? countBinaryExpressionParameters(b.left) + 1 : 2;
162567
162856
  }
162568
162857
  function tryGetParameterInfo(startingToken, position, sourceFile, checker) {
162569
- const info = getContextualSignatureLocationInfo(startingToken, sourceFile, position, checker);
162570
- if (!info)
162858
+ const node = getAdjustedNode(startingToken);
162859
+ if (node === void 0)
162860
+ return void 0;
162861
+ const info = getContextualSignatureLocationInfo(node, sourceFile, position, checker);
162862
+ if (info === void 0)
162571
162863
  return void 0;
162572
162864
  const { contextualType, argumentIndex, argumentCount, argumentsSpan } = info;
162573
162865
  const nonNullableContextualType = contextualType.getNonNullableType();
@@ -162580,16 +162872,23 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
162580
162872
  const invocation = { kind: 2 /* Contextual */, signature, node: startingToken, symbol: chooseBetterSymbol(symbol) };
162581
162873
  return { isTypeParameterList: false, invocation, argumentsSpan, argumentIndex, argumentCount };
162582
162874
  }
162583
- function getContextualSignatureLocationInfo(startingToken, sourceFile, position, checker) {
162584
- if (startingToken.kind !== 20 /* OpenParenToken */ && startingToken.kind !== 27 /* CommaToken */)
162585
- return void 0;
162586
- const { parent: parent2 } = startingToken;
162875
+ function getAdjustedNode(node) {
162876
+ switch (node.kind) {
162877
+ case 20 /* OpenParenToken */:
162878
+ case 27 /* CommaToken */:
162879
+ return node;
162880
+ default:
162881
+ return findAncestor(node.parent, (n) => isParameter(n) ? true : isBindingElement(n) || isObjectBindingPattern(n) || isArrayBindingPattern(n) ? false : "quit");
162882
+ }
162883
+ }
162884
+ function getContextualSignatureLocationInfo(node, sourceFile, position, checker) {
162885
+ const { parent: parent2 } = node;
162587
162886
  switch (parent2.kind) {
162588
162887
  case 215 /* ParenthesizedExpression */:
162589
162888
  case 172 /* MethodDeclaration */:
162590
162889
  case 216 /* FunctionExpression */:
162591
162890
  case 217 /* ArrowFunction */:
162592
- const info = getArgumentOrParameterListInfo(startingToken, position, sourceFile);
162891
+ const info = getArgumentOrParameterListInfo(node, position, sourceFile);
162593
162892
  if (!info)
162594
162893
  return void 0;
162595
162894
  const { argumentIndex, argumentCount, argumentsSpan } = info;
@@ -162598,7 +162897,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
162598
162897
  case 224 /* BinaryExpression */: {
162599
162898
  const highestBinary = getHighestBinary(parent2);
162600
162899
  const contextualType2 = checker.getContextualType(highestBinary);
162601
- const argumentIndex2 = startingToken.kind === 20 /* OpenParenToken */ ? 0 : countBinaryExpressionParameters(parent2) - 1;
162900
+ const argumentIndex2 = node.kind === 20 /* OpenParenToken */ ? 0 : countBinaryExpressionParameters(parent2) - 1;
162602
162901
  const argumentCount2 = countBinaryExpressionParameters(highestBinary);
162603
162902
  return contextualType2 && { contextualType: contextualType2, argumentIndex: argumentIndex2, argumentCount: argumentCount2, argumentsSpan: createTextSpanFromNode(parent2) };
162604
162903
  }