typescript 5.1.0-dev.20230404 → 5.1.0-dev.20230406

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.20230404`;
38
+ version = `${versionMajorMinor}.0-dev.20230406`;
39
39
  Comparison = /* @__PURE__ */ ((Comparison3) => {
40
40
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
41
41
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -31763,6 +31763,12 @@ ${lanes.join("\n")}
31763
31763
  if (languageVariant === 1 /* JSX */) {
31764
31764
  return parseJsxElementOrSelfClosingElementOrFragment(
31765
31765
  /*inExpressionContext*/
31766
+ true,
31767
+ /*topInvalidNodePosition*/
31768
+ void 0,
31769
+ /*openingTag*/
31770
+ void 0,
31771
+ /*mustBeUnary*/
31766
31772
  true
31767
31773
  );
31768
31774
  }
@@ -31867,7 +31873,7 @@ ${lanes.join("\n")}
31867
31873
  true
31868
31874
  )), pos);
31869
31875
  }
31870
- function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext, topInvalidNodePosition, openingTag) {
31876
+ function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext, topInvalidNodePosition, openingTag, mustBeUnary = false) {
31871
31877
  const pos = getNodePos();
31872
31878
  const opening = parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext);
31873
31879
  let result;
@@ -31905,7 +31911,7 @@ ${lanes.join("\n")}
31905
31911
  Debug.assert(opening.kind === 283 /* JsxSelfClosingElement */);
31906
31912
  result = opening;
31907
31913
  }
31908
- if (inExpressionContext && token() === 29 /* LessThanToken */) {
31914
+ if (!mustBeUnary && inExpressionContext && token() === 29 /* LessThanToken */) {
31909
31915
  const topBadPos = typeof topInvalidNodePosition === "undefined" ? result.pos : topInvalidNodePosition;
31910
31916
  const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(
31911
31917
  /*inExpressionContext*/
@@ -31938,7 +31944,7 @@ ${lanes.join("\n")}
31938
31944
  parseErrorAtRange(openingTag, Diagnostics.JSX_fragment_has_no_corresponding_closing_tag);
31939
31945
  } else {
31940
31946
  const tag = openingTag.tagName;
31941
- const start = skipTrivia(sourceText, tag.pos);
31947
+ const start = Math.min(skipTrivia(sourceText, tag.pos), tag.end);
31942
31948
  parseErrorAt(start, tag.end, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTag.tagName));
31943
31949
  }
31944
31950
  return void 0;
@@ -82801,6 +82807,14 @@ ${lanes.join("\n")}
82801
82807
  const symbol = getSymbolAtLocation(node);
82802
82808
  return symbol ? getDeclaredTypeOfSymbol(symbol) : errorType;
82803
82809
  }
82810
+ if (isBindingElement(node)) {
82811
+ return getTypeForVariableLikeDeclaration(
82812
+ node,
82813
+ /*includeOptionality*/
82814
+ true,
82815
+ 0 /* Normal */
82816
+ ) || errorType;
82817
+ }
82804
82818
  if (isDeclaration(node)) {
82805
82819
  const symbol = getSymbolOfDeclaration(node);
82806
82820
  return symbol ? getTypeOfSymbol(symbol) : errorType;
@@ -92334,11 +92348,12 @@ ${lanes.join("\n")}
92334
92348
  return visitEachChild(node, visitor, context);
92335
92349
  }
92336
92350
  function visitArrayAssignmentElement(node) {
92337
- Debug.assertNode(node, isArrayBindingOrAssignmentElement);
92338
- if (isSpreadElement(node))
92339
- return visitAssignmentRestElement(node);
92340
- if (!isOmittedExpression(node))
92341
- return visitAssignmentElement(node);
92351
+ if (isArrayBindingOrAssignmentElement(node)) {
92352
+ if (isSpreadElement(node))
92353
+ return visitAssignmentRestElement(node);
92354
+ if (!isOmittedExpression(node))
92355
+ return visitAssignmentElement(node);
92356
+ }
92342
92357
  return visitEachChild(node, visitor, context);
92343
92358
  }
92344
92359
  function visitAssignmentProperty(node) {
@@ -118504,9 +118519,6 @@ ${lanes.join("\n")}
118504
118519
  if (moduleKind === 2 /* AMD */ || moduleKind === 3 /* UMD */ || moduleKind === 4 /* System */) {
118505
118520
  createDiagnosticForOptionName(Diagnostics.Option_verbatimModuleSyntax_cannot_be_used_when_module_is_set_to_UMD_AMD_or_System, "verbatimModuleSyntax");
118506
118521
  }
118507
- if (options.isolatedModules) {
118508
- createRedundantOptionDiagnostic("isolatedModules", "verbatimModuleSyntax");
118509
- }
118510
118522
  if (options.preserveValueImports) {
118511
118523
  createRedundantOptionDiagnostic("preserveValueImports", "verbatimModuleSyntax");
118512
118524
  }
@@ -121203,7 +121215,7 @@ ${lanes.join("\n")}
121203
121215
  return {
121204
121216
  dir: rootDir,
121205
121217
  dirPath: rootPath,
121206
- nonRecursive: false
121218
+ nonRecursive: true
121207
121219
  };
121208
121220
  }
121209
121221
  }
@@ -121651,7 +121663,7 @@ ${lanes.join("\n")}
121651
121663
  customFailedLookupPaths.set(failedLookupLocationPath, refCount + 1);
121652
121664
  }
121653
121665
  if (dirPath === rootPath) {
121654
- Debug.assert(!nonRecursive);
121666
+ Debug.assert(nonRecursive);
121655
121667
  setAtRoot = true;
121656
121668
  } else {
121657
121669
  setDirectoryWatcher(dir, dirPath, nonRecursive);
@@ -148111,6 +148123,7 @@ ${lanes.join("\n")}
148111
148123
  return void 0;
148112
148124
  }
148113
148125
  const compilerOptions = program.getCompilerOptions();
148126
+ const checker = program.getTypeChecker();
148114
148127
  const incompleteCompletionsCache = preferences.allowIncompleteCompletions ? (_a2 = host.getIncompleteCompletionsCache) == null ? void 0 : _a2.call(host) : void 0;
148115
148128
  if (incompleteCompletionsCache && completionKind === 3 /* TriggerForIncompleteCompletions */ && previousToken && isIdentifier(previousToken)) {
148116
148129
  const incompleteContinuation = continuePreviousIncompleteResponse(incompleteCompletionsCache, sourceFile, previousToken, program, host, preferences, cancellationToken, position);
@@ -148151,9 +148164,31 @@ ${lanes.join("\n")}
148151
148164
  }
148152
148165
  return response;
148153
148166
  case 1 /* JsDocTagName */:
148154
- return jsdocCompletionInfo(ts_JsDoc_exports.getJSDocTagNameCompletions());
148167
+ return jsdocCompletionInfo([
148168
+ ...ts_JsDoc_exports.getJSDocTagNameCompletions(),
148169
+ ...getJSDocParameterCompletions(
148170
+ sourceFile,
148171
+ position,
148172
+ checker,
148173
+ compilerOptions,
148174
+ preferences,
148175
+ /*tagNameOnly*/
148176
+ true
148177
+ )
148178
+ ]);
148155
148179
  case 2 /* JsDocTag */:
148156
- return jsdocCompletionInfo(ts_JsDoc_exports.getJSDocTagCompletions());
148180
+ return jsdocCompletionInfo([
148181
+ ...ts_JsDoc_exports.getJSDocTagCompletions(),
148182
+ ...getJSDocParameterCompletions(
148183
+ sourceFile,
148184
+ position,
148185
+ checker,
148186
+ compilerOptions,
148187
+ preferences,
148188
+ /*tagNameOnly*/
148189
+ false
148190
+ )
148191
+ ]);
148157
148192
  case 3 /* JsDocParameterName */:
148158
148193
  return jsdocCompletionInfo(ts_JsDoc_exports.getJSDocParameterNameCompletions(completionData.tag));
148159
148194
  case 4 /* Keywords */:
@@ -148241,6 +148276,264 @@ ${lanes.join("\n")}
148241
148276
  function jsdocCompletionInfo(entries) {
148242
148277
  return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries };
148243
148278
  }
148279
+ function getJSDocParameterCompletions(sourceFile, position, checker, options, preferences, tagNameOnly) {
148280
+ const currentToken = getTokenAtPosition(sourceFile, position);
148281
+ if (!isJSDocTag(currentToken) && !isJSDoc(currentToken)) {
148282
+ return [];
148283
+ }
148284
+ const jsDoc = isJSDoc(currentToken) ? currentToken : currentToken.parent;
148285
+ if (!isJSDoc(jsDoc)) {
148286
+ return [];
148287
+ }
148288
+ const func = jsDoc.parent;
148289
+ if (!isFunctionLike(func)) {
148290
+ return [];
148291
+ }
148292
+ const isJs = isSourceFileJS(sourceFile);
148293
+ const isSnippet = preferences.includeCompletionsWithSnippetText || void 0;
148294
+ const paramTagCount = countWhere(jsDoc.tags, (tag) => isJSDocParameterTag(tag) && tag.getEnd() <= position);
148295
+ return mapDefined(func.parameters, (param) => {
148296
+ if (getJSDocParameterTags(param).length) {
148297
+ return void 0;
148298
+ }
148299
+ if (isIdentifier(param.name)) {
148300
+ const tabstopCounter = { tabstop: 1 };
148301
+ const paramName = param.name.text;
148302
+ let displayText = getJSDocParamAnnotation(
148303
+ paramName,
148304
+ param.initializer,
148305
+ param.dotDotDotToken,
148306
+ isJs,
148307
+ /*isObject*/
148308
+ false,
148309
+ /*isSnippet*/
148310
+ false,
148311
+ checker,
148312
+ options,
148313
+ preferences
148314
+ );
148315
+ let snippetText = isSnippet ? getJSDocParamAnnotation(
148316
+ paramName,
148317
+ param.initializer,
148318
+ param.dotDotDotToken,
148319
+ isJs,
148320
+ /*isObject*/
148321
+ false,
148322
+ /*isSnippet*/
148323
+ true,
148324
+ checker,
148325
+ options,
148326
+ preferences,
148327
+ tabstopCounter
148328
+ ) : void 0;
148329
+ if (tagNameOnly) {
148330
+ displayText = displayText.slice(1);
148331
+ if (snippetText)
148332
+ snippetText = snippetText.slice(1);
148333
+ }
148334
+ return {
148335
+ name: displayText,
148336
+ kind: "parameter" /* parameterElement */,
148337
+ sortText: SortText.LocationPriority,
148338
+ insertText: isSnippet ? snippetText : void 0,
148339
+ isSnippet
148340
+ };
148341
+ } else if (param.parent.parameters.indexOf(param) === paramTagCount) {
148342
+ const paramPath = `param${paramTagCount}`;
148343
+ const displayTextResult = generateJSDocParamTagsForDestructuring(
148344
+ paramPath,
148345
+ param.name,
148346
+ param.initializer,
148347
+ param.dotDotDotToken,
148348
+ isJs,
148349
+ /*isSnippet*/
148350
+ false,
148351
+ checker,
148352
+ options,
148353
+ preferences
148354
+ );
148355
+ const snippetTextResult = isSnippet ? generateJSDocParamTagsForDestructuring(
148356
+ paramPath,
148357
+ param.name,
148358
+ param.initializer,
148359
+ param.dotDotDotToken,
148360
+ isJs,
148361
+ /*isSnippet*/
148362
+ true,
148363
+ checker,
148364
+ options,
148365
+ preferences
148366
+ ) : void 0;
148367
+ let displayText = displayTextResult.join(getNewLineCharacter(options) + "* ");
148368
+ let snippetText = snippetTextResult == null ? void 0 : snippetTextResult.join(getNewLineCharacter(options) + "* ");
148369
+ if (tagNameOnly) {
148370
+ displayText = displayText.slice(1);
148371
+ if (snippetText)
148372
+ snippetText = snippetText.slice(1);
148373
+ }
148374
+ return {
148375
+ name: displayText,
148376
+ kind: "parameter" /* parameterElement */,
148377
+ sortText: SortText.LocationPriority,
148378
+ insertText: isSnippet ? snippetText : void 0,
148379
+ isSnippet
148380
+ };
148381
+ }
148382
+ });
148383
+ }
148384
+ function generateJSDocParamTagsForDestructuring(path, pattern, initializer, dotDotDotToken, isJs, isSnippet, checker, options, preferences) {
148385
+ if (!isJs) {
148386
+ return [
148387
+ getJSDocParamAnnotation(
148388
+ path,
148389
+ initializer,
148390
+ dotDotDotToken,
148391
+ isJs,
148392
+ /*isObject*/
148393
+ false,
148394
+ isSnippet,
148395
+ checker,
148396
+ options,
148397
+ preferences,
148398
+ { tabstop: 1 }
148399
+ )
148400
+ ];
148401
+ }
148402
+ return patternWorker(path, pattern, initializer, dotDotDotToken, { tabstop: 1 });
148403
+ function patternWorker(path2, pattern2, initializer2, dotDotDotToken2, counter) {
148404
+ if (isObjectBindingPattern(pattern2) && !dotDotDotToken2) {
148405
+ const oldTabstop = counter.tabstop;
148406
+ const childCounter = { tabstop: oldTabstop };
148407
+ const rootParam = getJSDocParamAnnotation(
148408
+ path2,
148409
+ initializer2,
148410
+ dotDotDotToken2,
148411
+ isJs,
148412
+ /*isObject*/
148413
+ true,
148414
+ isSnippet,
148415
+ checker,
148416
+ options,
148417
+ preferences,
148418
+ childCounter
148419
+ );
148420
+ let childTags = [];
148421
+ for (const element of pattern2.elements) {
148422
+ const elementTags = elementWorker(path2, element, childCounter);
148423
+ if (!elementTags) {
148424
+ childTags = void 0;
148425
+ break;
148426
+ } else {
148427
+ childTags.push(...elementTags);
148428
+ }
148429
+ }
148430
+ if (childTags) {
148431
+ counter.tabstop = childCounter.tabstop;
148432
+ return [rootParam, ...childTags];
148433
+ }
148434
+ }
148435
+ return [
148436
+ getJSDocParamAnnotation(
148437
+ path2,
148438
+ initializer2,
148439
+ dotDotDotToken2,
148440
+ isJs,
148441
+ /*isObject*/
148442
+ false,
148443
+ isSnippet,
148444
+ checker,
148445
+ options,
148446
+ preferences,
148447
+ counter
148448
+ )
148449
+ ];
148450
+ }
148451
+ function elementWorker(path2, element, counter) {
148452
+ if (!element.propertyName && isIdentifier(element.name) || isIdentifier(element.name)) {
148453
+ const propertyName = element.propertyName ? tryGetTextOfPropertyName(element.propertyName) : element.name.text;
148454
+ if (!propertyName) {
148455
+ return void 0;
148456
+ }
148457
+ const paramName = `${path2}.${propertyName}`;
148458
+ return [
148459
+ getJSDocParamAnnotation(
148460
+ paramName,
148461
+ element.initializer,
148462
+ element.dotDotDotToken,
148463
+ isJs,
148464
+ /*isObject*/
148465
+ false,
148466
+ isSnippet,
148467
+ checker,
148468
+ options,
148469
+ preferences,
148470
+ counter
148471
+ )
148472
+ ];
148473
+ } else if (element.propertyName) {
148474
+ const propertyName = tryGetTextOfPropertyName(element.propertyName);
148475
+ return propertyName && patternWorker(`${path2}.${propertyName}`, element.name, element.initializer, element.dotDotDotToken, counter);
148476
+ }
148477
+ return void 0;
148478
+ }
148479
+ }
148480
+ function getJSDocParamAnnotation(paramName, initializer, dotDotDotToken, isJs, isObject, isSnippet, checker, options, preferences, tabstopCounter) {
148481
+ if (isSnippet) {
148482
+ Debug.assertIsDefined(tabstopCounter);
148483
+ }
148484
+ if (initializer) {
148485
+ paramName = getJSDocParamNameWithInitializer(paramName, initializer);
148486
+ }
148487
+ if (isSnippet) {
148488
+ paramName = escapeSnippetText(paramName);
148489
+ }
148490
+ if (isJs) {
148491
+ let type = "*";
148492
+ if (isObject) {
148493
+ Debug.assert(!dotDotDotToken, `Cannot annotate a rest parameter with type 'Object'.`);
148494
+ type = "Object";
148495
+ } else {
148496
+ if (initializer) {
148497
+ const inferredType = checker.getTypeAtLocation(initializer.parent);
148498
+ if (!(inferredType.flags & (1 /* Any */ | 16384 /* Void */))) {
148499
+ const sourceFile = initializer.getSourceFile();
148500
+ const quotePreference = getQuotePreference(sourceFile, preferences);
148501
+ const builderFlags = quotePreference === 0 /* Single */ ? 268435456 /* UseSingleQuotesForStringLiteralType */ : 0 /* None */;
148502
+ const typeNode = checker.typeToTypeNode(inferredType, findAncestor(initializer, isFunctionLike), builderFlags);
148503
+ if (typeNode) {
148504
+ const printer = isSnippet ? createSnippetPrinter({
148505
+ removeComments: true,
148506
+ module: options.module,
148507
+ target: options.target
148508
+ }) : createPrinter({
148509
+ removeComments: true,
148510
+ module: options.module,
148511
+ target: options.target
148512
+ });
148513
+ setEmitFlags(typeNode, 1 /* SingleLine */);
148514
+ type = printer.printNode(4 /* Unspecified */, typeNode, sourceFile);
148515
+ }
148516
+ }
148517
+ }
148518
+ if (isSnippet && type === "*") {
148519
+ type = `\${${tabstopCounter.tabstop++}:${type}}`;
148520
+ }
148521
+ }
148522
+ const dotDotDot = !isObject && dotDotDotToken ? "..." : "";
148523
+ const description2 = isSnippet ? `\${${tabstopCounter.tabstop++}}` : "";
148524
+ return `@param {${dotDotDot}${type}} ${paramName} ${description2}`;
148525
+ } else {
148526
+ const description2 = isSnippet ? `\${${tabstopCounter.tabstop++}}` : "";
148527
+ return `@param ${paramName} ${description2}`;
148528
+ }
148529
+ }
148530
+ function getJSDocParamNameWithInitializer(paramName, initializer) {
148531
+ const initializerText = initializer.getText().trim();
148532
+ if (initializerText.includes("\n") || initializerText.length > 80) {
148533
+ return `[${paramName}]`;
148534
+ }
148535
+ return `[${paramName}=${initializerText}]`;
148536
+ }
148244
148537
  function keywordToCompletionEntry(keyword) {
148245
148538
  return {
148246
148539
  name: tokenToString(keyword),