typescript 5.2.0-dev.20230720 → 5.2.0-dev.20230722

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.2";
38
- version = `${versionMajorMinor}.0-dev.20230720`;
38
+ version = `${versionMajorMinor}.0-dev.20230722`;
39
39
  Comparison = /* @__PURE__ */ ((Comparison3) => {
40
40
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
41
41
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -19225,6 +19225,18 @@ ${lanes.join("\n")}
19225
19225
  function intrinsicTagNameToString(node) {
19226
19226
  return isIdentifier(node) ? idText(node) : getTextOfJsxNamespacedName(node);
19227
19227
  }
19228
+ function isTypeUsableAsPropertyName(type) {
19229
+ return !!(type.flags & 8576 /* StringOrNumberLiteralOrUnique */);
19230
+ }
19231
+ function getPropertyNameFromType(type) {
19232
+ if (type.flags & 8192 /* UniqueESSymbol */) {
19233
+ return type.escapedName;
19234
+ }
19235
+ if (type.flags & (128 /* StringLiteral */ | 256 /* NumberLiteral */)) {
19236
+ return escapeLeadingUnderscores("" + type.value);
19237
+ }
19238
+ return Debug.fail();
19239
+ }
19228
19240
  var resolvingEmptyArray, externalHelpersModuleNameText, defaultMaximumTruncationLength, noTruncationMaximumTruncationLength, stringWriter, GetLiteralTextFlags, fullTripleSlashReferencePathRegEx, fullTripleSlashReferenceTypeReferenceDirectiveRegEx, fullTripleSlashLibReferenceRegEx, fullTripleSlashAMDReferencePathRegEx, fullTripleSlashAMDModuleRegEx, defaultLibReferenceRegEx, AssignmentKind, FunctionFlags, Associativity, OperatorPrecedence, templateSubstitutionRegExp, doubleQuoteEscapedCharsRegExp, singleQuoteEscapedCharsRegExp, backtickQuoteEscapedCharsRegExp, escapedCharsMap, nonAsciiCharacters, jsxDoubleQuoteEscapedCharsRegExp, jsxSingleQuoteEscapedCharsRegExp, jsxEscapedCharsMap, indentStrings, base64Digits, carriageReturnLineFeed, lineFeed, objectAllocator, objectAllocatorPatchers, localizedDiagnosticMessages, reservedCharacterPattern, wildcardCharCodes, commonPackageFolders, implicitExcludePathRegexPattern, filesMatcher, directoriesMatcher, excludeMatcher, wildcardMatchers, supportedTSExtensions, supportedTSExtensionsFlat, supportedTSExtensionsWithJson, supportedTSExtensionsForExtractExtension, supportedJSExtensions, supportedJSExtensionsFlat, allSupportedExtensions, allSupportedExtensionsWithJson, supportedDeclarationExtensions, supportedTSImplementationExtensions, extensionsNotSupportingExtensionlessResolution, ModuleSpecifierEnding, extensionsToRemove, emptyFileSystemEntries;
19229
19241
  var init_utilities = __esm({
19230
19242
  "src/compiler/utilities.ts"() {
@@ -33182,10 +33194,14 @@ ${lanes.join("\n")}
33182
33194
  case 124 /* ProtectedKeyword */:
33183
33195
  case 125 /* PublicKeyword */:
33184
33196
  case 148 /* ReadonlyKeyword */:
33197
+ const previousToken = token();
33185
33198
  nextToken();
33186
33199
  if (scanner2.hasPrecedingLineBreak()) {
33187
33200
  return false;
33188
33201
  }
33202
+ if (previousToken === 138 /* DeclareKeyword */ && token() === 156 /* TypeKeyword */) {
33203
+ return true;
33204
+ }
33189
33205
  continue;
33190
33206
  case 162 /* GlobalKeyword */:
33191
33207
  nextToken();
@@ -33550,14 +33566,14 @@ ${lanes.join("\n")}
33550
33566
  function parseObjectBindingPattern() {
33551
33567
  const pos = getNodePos();
33552
33568
  parseExpected(19 /* OpenBraceToken */);
33553
- const elements = parseDelimitedList(9 /* ObjectBindingElements */, parseObjectBindingElement);
33569
+ const elements = allowInAnd(() => parseDelimitedList(9 /* ObjectBindingElements */, parseObjectBindingElement));
33554
33570
  parseExpected(20 /* CloseBraceToken */);
33555
33571
  return finishNode(factory2.createObjectBindingPattern(elements), pos);
33556
33572
  }
33557
33573
  function parseArrayBindingPattern() {
33558
33574
  const pos = getNodePos();
33559
33575
  parseExpected(23 /* OpenBracketToken */);
33560
- const elements = parseDelimitedList(10 /* ArrayBindingElements */, parseArrayBindingElement);
33576
+ const elements = allowInAnd(() => parseDelimitedList(10 /* ArrayBindingElements */, parseArrayBindingElement));
33561
33577
  parseExpected(24 /* CloseBracketToken */);
33562
33578
  return finishNode(factory2.createArrayBindingPattern(elements), pos);
33563
33579
  }
@@ -34075,6 +34091,9 @@ ${lanes.join("\n")}
34075
34091
  }
34076
34092
  function parseTypeAliasDeclaration(pos, hasJSDoc, modifiers) {
34077
34093
  parseExpected(156 /* TypeKeyword */);
34094
+ if (scanner2.hasPrecedingLineBreak()) {
34095
+ parseErrorAtCurrentToken(Diagnostics.Line_break_not_permitted_here);
34096
+ }
34078
34097
  const name = parseIdentifier();
34079
34098
  const typeParameters = parseTypeParameters();
34080
34099
  parseExpected(64 /* EqualsToken */);
@@ -35858,7 +35877,7 @@ ${lanes.join("\n")}
35858
35877
  })(IncrementalParser || (IncrementalParser = {}));
35859
35878
  namedArgRegExCache = /* @__PURE__ */ new Map();
35860
35879
  tripleSlashXMLCommentStartRegEx = /^\/\/\/\s*<(\S+)\s.*?\/>/im;
35861
- singleLinePragmaRegEx = /^\/\/\/?\s*@(\S+)\s*(.*)\s*$/im;
35880
+ singleLinePragmaRegEx = /^\/\/\/?\s*@([^\s:]+)(.*)\s*$/im;
35862
35881
  }
35863
35882
  });
35864
35883
 
@@ -45585,7 +45604,7 @@ ${lanes.join("\n")}
45585
45604
  return node ? getTypeFromTypeNode(node) : errorType;
45586
45605
  },
45587
45606
  getParameterType: getTypeAtPosition,
45588
- getParameterIdentifierNameAtPosition,
45607
+ getParameterIdentifierInfoAtPosition,
45589
45608
  getPromisedTypeOfPromise,
45590
45609
  getAwaitedType: (type) => getAwaitedType(type),
45591
45610
  getReturnTypeOfSignature,
@@ -54048,7 +54067,7 @@ ${lanes.join("\n")}
54048
54067
  false,
54049
54068
  definedInMethod && !definedInConstructor
54050
54069
  ));
54051
- if (symbol.valueDeclaration && filterType(widened, (t) => !!(t.flags & ~98304 /* Nullable */)) === neverType) {
54070
+ if (symbol.valueDeclaration && isInJSFile(symbol.valueDeclaration) && filterType(widened, (t) => !!(t.flags & ~98304 /* Nullable */)) === neverType) {
54052
54071
  reportImplicitAny(symbol.valueDeclaration, anyType);
54053
54072
  return anyType;
54054
54073
  }
@@ -55327,9 +55346,6 @@ ${lanes.join("\n")}
55327
55346
  }
55328
55347
  return type;
55329
55348
  }
55330
- function isTypeUsableAsPropertyName(type) {
55331
- return !!(type.flags & 8576 /* StringOrNumberLiteralOrUnique */);
55332
- }
55333
55349
  function isLateBindableName(node) {
55334
55350
  if (!isComputedPropertyName(node) && !isElementAccessExpression(node)) {
55335
55351
  return false;
@@ -55350,15 +55366,6 @@ ${lanes.join("\n")}
55350
55366
  function isNonBindableDynamicName(node) {
55351
55367
  return isDynamicName(node) && !isLateBindableName(node);
55352
55368
  }
55353
- function getPropertyNameFromType(type) {
55354
- if (type.flags & 8192 /* UniqueESSymbol */) {
55355
- return type.escapedName;
55356
- }
55357
- if (type.flags & (128 /* StringLiteral */ | 256 /* NumberLiteral */)) {
55358
- return escapeLeadingUnderscores("" + type.value);
55359
- }
55360
- return Debug.fail();
55361
- }
55362
55369
  function addDeclarationToLateBoundSymbol(symbol, member, symbolFlags) {
55363
55370
  Debug.assert(!!(getCheckFlags(symbol) & 4096 /* Late */), "Expected a late-bound symbol.");
55364
55371
  symbol.flags |= symbolFlags;
@@ -56005,20 +56012,17 @@ ${lanes.join("\n")}
56005
56012
  setStructuredTypeMembers(type, members2, callSignatures, constructSignatures, indexInfos2);
56006
56013
  return;
56007
56014
  }
56008
- let members = emptySymbols;
56015
+ let members = getExportsOfSymbol(symbol);
56009
56016
  let indexInfos;
56010
- if (symbol.exports) {
56011
- members = getExportsOfSymbol(symbol);
56012
- if (symbol === globalThisSymbol) {
56013
- const varsOnly = /* @__PURE__ */ new Map();
56014
- members.forEach((p) => {
56015
- var _a;
56016
- if (!(p.flags & 418 /* BlockScoped */) && !(p.flags & 512 /* ValueModule */ && ((_a = p.declarations) == null ? void 0 : _a.length) && every(p.declarations, isAmbientModule))) {
56017
- varsOnly.set(p.escapedName, p);
56018
- }
56019
- });
56020
- members = varsOnly;
56021
- }
56017
+ if (symbol === globalThisSymbol) {
56018
+ const varsOnly = /* @__PURE__ */ new Map();
56019
+ members.forEach((p) => {
56020
+ var _a;
56021
+ if (!(p.flags & 418 /* BlockScoped */) && !(p.flags & 512 /* ValueModule */ && ((_a = p.declarations) == null ? void 0 : _a.length) && every(p.declarations, isAmbientModule))) {
56022
+ varsOnly.set(p.escapedName, p);
56023
+ }
56024
+ });
56025
+ members = varsOnly;
56022
56026
  }
56023
56027
  let baseConstructorIndexInfo;
56024
56028
  setStructuredTypeMembers(type, members, emptyArray, emptyArray, emptyArray);
@@ -74530,7 +74534,7 @@ ${lanes.join("\n")}
74530
74534
  }
74531
74535
  return restParameter.escapedName;
74532
74536
  }
74533
- function getParameterIdentifierNameAtPosition(signature, pos) {
74537
+ function getParameterIdentifierInfoAtPosition(signature, pos) {
74534
74538
  var _a;
74535
74539
  if (((_a = signature.declaration) == null ? void 0 : _a.kind) === 324 /* JSDocFunctionType */) {
74536
74540
  return void 0;
@@ -74538,10 +74542,16 @@ ${lanes.join("\n")}
74538
74542
  const paramCount = signature.parameters.length - (signatureHasRestParameter(signature) ? 1 : 0);
74539
74543
  if (pos < paramCount) {
74540
74544
  const param = signature.parameters[pos];
74541
- return isParameterDeclarationWithIdentifierName(param) ? [param.escapedName, false] : void 0;
74545
+ const paramIdent = getParameterDeclarationIdentifier(param);
74546
+ return paramIdent ? {
74547
+ parameter: paramIdent,
74548
+ parameterName: param.escapedName,
74549
+ isRestParameter: false
74550
+ } : void 0;
74542
74551
  }
74543
74552
  const restParameter = signature.parameters[paramCount] || unknownSymbol;
74544
- if (!isParameterDeclarationWithIdentifierName(restParameter)) {
74553
+ const restIdent = getParameterDeclarationIdentifier(restParameter);
74554
+ if (!restIdent) {
74545
74555
  return void 0;
74546
74556
  }
74547
74557
  const restType = getTypeOfSymbol(restParameter);
@@ -74550,18 +74560,19 @@ ${lanes.join("\n")}
74550
74560
  const index = pos - paramCount;
74551
74561
  const associatedName = associatedNames == null ? void 0 : associatedNames[index];
74552
74562
  const isRestTupleElement = !!(associatedName == null ? void 0 : associatedName.dotDotDotToken);
74553
- return associatedName ? [
74554
- getTupleElementLabel(associatedName),
74555
- isRestTupleElement
74556
- ] : void 0;
74563
+ if (associatedName) {
74564
+ Debug.assert(isIdentifier(associatedName.name));
74565
+ return { parameter: associatedName.name, parameterName: associatedName.name.escapedText, isRestParameter: isRestTupleElement };
74566
+ }
74567
+ return void 0;
74557
74568
  }
74558
74569
  if (pos === paramCount) {
74559
- return [restParameter.escapedName, true];
74570
+ return { parameter: restIdent, parameterName: restParameter.escapedName, isRestParameter: true };
74560
74571
  }
74561
74572
  return void 0;
74562
74573
  }
74563
- function isParameterDeclarationWithIdentifierName(symbol) {
74564
- return symbol.valueDeclaration && isParameter(symbol.valueDeclaration) && isIdentifier(symbol.valueDeclaration.name);
74574
+ function getParameterDeclarationIdentifier(symbol) {
74575
+ return symbol.valueDeclaration && isParameter(symbol.valueDeclaration) && isIdentifier(symbol.valueDeclaration.name) && symbol.valueDeclaration.name;
74565
74576
  }
74566
74577
  function isValidDeclarationForTupleLabel(d) {
74567
74578
  return d.kind === 202 /* NamedTupleMember */ || isParameter(d) && d.name && isIdentifier(d.name);
@@ -134400,8 +134411,8 @@ ${lanes.join("\n")}
134400
134411
  diags.push(createDiagnosticForNode(init, Diagnostics.require_call_may_be_converted_to_an_import));
134401
134412
  }
134402
134413
  }
134403
- const jsdocTypedefNode = ts_codefix_exports.getJSDocTypedefNode(node);
134404
- if (jsdocTypedefNode) {
134414
+ const jsdocTypedefNodes = ts_codefix_exports.getJSDocTypedefNodes(node);
134415
+ for (const jsdocTypedefNode of jsdocTypedefNodes) {
134405
134416
  diags.push(createDiagnosticForNode(jsdocTypedefNode, Diagnostics.JSDoc_typedef_may_be_converted_to_TypeScript_type));
134406
134417
  }
134407
134418
  if (ts_codefix_exports.parameterShouldGetTypeFromJSDoc(node)) {
@@ -148329,23 +148340,60 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
148329
148340
  });
148330
148341
 
148331
148342
  // src/services/codefixes/convertTypedefToType.ts
148332
- function doChange12(changes, node, sourceFile) {
148333
- if (isJSDocTypedefTag(node)) {
148334
- fixSingleTypeDef(changes, node, sourceFile);
148335
- }
148336
- }
148337
- function fixSingleTypeDef(changes, typeDefNode, sourceFile) {
148338
- if (!typeDefNode)
148343
+ function doChange12(changes, node, sourceFile, newLine, fixAll = false) {
148344
+ if (!isJSDocTypedefTag(node))
148339
148345
  return;
148340
- const declaration = createDeclaration(typeDefNode);
148346
+ const declaration = createDeclaration(node);
148341
148347
  if (!declaration)
148342
148348
  return;
148343
- const comment = typeDefNode.parent;
148344
- changes.replaceNode(
148345
- sourceFile,
148346
- comment,
148347
- declaration
148349
+ const commentNode = node.parent;
148350
+ const { leftSibling, rightSibling } = getLeftAndRightSiblings(node);
148351
+ let pos = commentNode.getStart();
148352
+ let prefix = "";
148353
+ if (!leftSibling && commentNode.comment) {
148354
+ pos = findEndOfTextBetween(commentNode, commentNode.getStart(), node.getStart());
148355
+ prefix = `${newLine} */${newLine}`;
148356
+ }
148357
+ if (leftSibling) {
148358
+ if (fixAll && isJSDocTypedefTag(leftSibling)) {
148359
+ pos = node.getStart();
148360
+ prefix = "";
148361
+ } else {
148362
+ pos = findEndOfTextBetween(commentNode, leftSibling.getStart(), node.getStart());
148363
+ prefix = `${newLine} */${newLine}`;
148364
+ }
148365
+ }
148366
+ let end = commentNode.getEnd();
148367
+ let suffix = "";
148368
+ if (rightSibling) {
148369
+ if (fixAll && isJSDocTypedefTag(rightSibling)) {
148370
+ end = rightSibling.getStart();
148371
+ suffix = `${newLine}${newLine}`;
148372
+ } else {
148373
+ end = rightSibling.getStart();
148374
+ suffix = `${newLine}/**${newLine} * `;
148375
+ }
148376
+ }
148377
+ changes.replaceRange(sourceFile, { pos, end }, declaration, { prefix, suffix });
148378
+ }
148379
+ function getLeftAndRightSiblings(typedefNode) {
148380
+ const commentNode = typedefNode.parent;
148381
+ const maxChildIndex = commentNode.getChildCount() - 1;
148382
+ const currentNodeIndex = commentNode.getChildren().findIndex(
148383
+ (n) => n.getStart() === typedefNode.getStart() && n.getEnd() === typedefNode.getEnd()
148348
148384
  );
148385
+ const leftSibling = currentNodeIndex > 0 ? commentNode.getChildAt(currentNodeIndex - 1) : void 0;
148386
+ const rightSibling = currentNodeIndex < maxChildIndex ? commentNode.getChildAt(currentNodeIndex + 1) : void 0;
148387
+ return { leftSibling, rightSibling };
148388
+ }
148389
+ function findEndOfTextBetween(jsDocComment, from, to) {
148390
+ const comment = jsDocComment.getText().substring(from - jsDocComment.getStart(), to - jsDocComment.getStart());
148391
+ for (let i = comment.length; i > 0; i--) {
148392
+ if (!/[*\/\s]/g.test(comment.substring(i - 1, i))) {
148393
+ return from + i;
148394
+ }
148395
+ }
148396
+ return to;
148349
148397
  }
148350
148398
  function createDeclaration(tag) {
148351
148399
  var _a;
@@ -148366,7 +148414,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
148366
148414
  const propertySignatures = createSignatureFromTypeLiteral(typeLiteral);
148367
148415
  if (!some(propertySignatures))
148368
148416
  return;
148369
- const interfaceDeclaration = factory.createInterfaceDeclaration(
148417
+ return factory.createInterfaceDeclaration(
148370
148418
  /*modifiers*/
148371
148419
  void 0,
148372
148420
  typeName,
@@ -148376,13 +148424,12 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
148376
148424
  void 0,
148377
148425
  propertySignatures
148378
148426
  );
148379
- return interfaceDeclaration;
148380
148427
  }
148381
148428
  function createTypeAliasForTypeExpression(typeName, typeExpression) {
148382
148429
  const typeReference = getSynthesizedDeepClone(typeExpression.type);
148383
148430
  if (!typeReference)
148384
148431
  return;
148385
- const declaration = factory.createTypeAliasDeclaration(
148432
+ return factory.createTypeAliasDeclaration(
148386
148433
  /*modifiers*/
148387
148434
  void 0,
148388
148435
  factory.createIdentifier(typeName),
@@ -148390,7 +148437,6 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
148390
148437
  void 0,
148391
148438
  typeReference
148392
148439
  );
148393
- return declaration;
148394
148440
  }
148395
148441
  function createSignatureFromTypeLiteral(typeLiteral) {
148396
148442
  const propertyTags = typeLiteral.jsDocPropertyTags;
@@ -148410,30 +148456,28 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
148410
148456
  }
148411
148457
  if (typeReference && name) {
148412
148458
  const questionToken = isOptional ? factory.createToken(58 /* QuestionToken */) : void 0;
148413
- const prop = factory.createPropertySignature(
148459
+ return factory.createPropertySignature(
148414
148460
  /*modifiers*/
148415
148461
  void 0,
148416
148462
  name,
148417
148463
  questionToken,
148418
148464
  typeReference
148419
148465
  );
148420
- return prop;
148421
148466
  }
148422
148467
  };
148423
- const props = mapDefined(propertyTags, getSignature);
148424
- return props;
148468
+ return mapDefined(propertyTags, getSignature);
148425
148469
  }
148426
148470
  function getPropertyName(tag) {
148427
148471
  return tag.name.kind === 80 /* Identifier */ ? tag.name.text : tag.name.right.text;
148428
148472
  }
148429
- function getJSDocTypedefNode(node) {
148473
+ function getJSDocTypedefNodes(node) {
148430
148474
  if (hasJSDocNodes(node)) {
148431
- return forEach(node.jsDoc, (node2) => {
148475
+ return flatMap(node.jsDoc, (doc) => {
148432
148476
  var _a;
148433
- return (_a = node2.tags) == null ? void 0 : _a.find(isJSDocTypedefTag);
148477
+ return (_a = doc.tags) == null ? void 0 : _a.filter((tag) => isJSDocTypedefTag(tag));
148434
148478
  });
148435
148479
  }
148436
- return void 0;
148480
+ return [];
148437
148481
  }
148438
148482
  var fixId14, errorCodes15;
148439
148483
  var init_convertTypedefToType = __esm({
@@ -148447,13 +148491,14 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
148447
148491
  fixIds: [fixId14],
148448
148492
  errorCodes: errorCodes15,
148449
148493
  getCodeActions(context) {
148494
+ const newLineCharacter = getNewLineOrDefaultFromHost(context.host, context.formatContext.options);
148450
148495
  const node = getTokenAtPosition(
148451
148496
  context.sourceFile,
148452
148497
  context.span.start
148453
148498
  );
148454
148499
  if (!node)
148455
148500
  return;
148456
- const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange12(t, node, context.sourceFile));
148501
+ const changes = ts_textChanges_exports.ChangeTracker.with(context, (t) => doChange12(t, node, context.sourceFile, newLineCharacter));
148457
148502
  if (changes.length > 0) {
148458
148503
  return [
148459
148504
  createCodeFixAction(
@@ -148466,11 +148511,17 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
148466
148511
  ];
148467
148512
  }
148468
148513
  },
148469
- getAllCodeActions: (context) => codeFixAll(context, errorCodes15, (changes, diag2) => {
148470
- const node = getTokenAtPosition(diag2.file, diag2.start);
148471
- if (node)
148472
- doChange12(changes, node, diag2.file);
148473
- })
148514
+ getAllCodeActions: (context) => codeFixAll(
148515
+ context,
148516
+ errorCodes15,
148517
+ (changes, diag2) => {
148518
+ const newLineCharacter = getNewLineOrDefaultFromHost(context.host, context.formatContext.options);
148519
+ const node = getTokenAtPosition(diag2.file, diag2.start);
148520
+ const fixAll = true;
148521
+ if (node)
148522
+ doChange12(changes, node, diag2.file, newLineCharacter, fixAll);
148523
+ }
148524
+ )
148474
148525
  });
148475
148526
  }
148476
148527
  });
@@ -150745,6 +150796,8 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
150745
150796
  if (!declaration || !isCallExpression(declaration.parent) || !declaration.body)
150746
150797
  return void 0;
150747
150798
  const pos = declaration.parent.arguments.indexOf(declaration);
150799
+ if (pos === -1)
150800
+ return void 0;
150748
150801
  const type = checker.getContextualTypeForArgumentAtIndex(declaration.parent, pos);
150749
150802
  if (!type)
150750
150803
  return void 0;
@@ -154170,15 +154223,11 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
154170
154223
  }
154171
154224
  function addNewNodeForMemberSymbol(symbol, enclosingDeclaration, sourceFile, context, preferences, importAdder, addClassElement, body, preserveOptional = 3 /* All */, isAmbient = false) {
154172
154225
  const declarations = symbol.getDeclarations();
154173
- const declaration = declarations == null ? void 0 : declarations[0];
154226
+ const declaration = firstOrUndefined(declarations);
154174
154227
  const checker = context.program.getTypeChecker();
154175
154228
  const scriptTarget = getEmitScriptTarget(context.program.getCompilerOptions());
154176
154229
  const kind = (declaration == null ? void 0 : declaration.kind) ?? 171 /* PropertySignature */;
154177
- const declarationName = getSynthesizedDeepClone(
154178
- getNameOfDeclaration(declaration),
154179
- /*includeTrivia*/
154180
- false
154181
- );
154230
+ const declarationName = createDeclarationName(symbol, declaration);
154182
154231
  const effectiveModifierFlags = declaration ? getEffectiveModifierFlags(declaration) : 0 /* None */;
154183
154232
  let modifierFlags = effectiveModifierFlags & 32 /* Static */;
154184
154233
  modifierFlags |= effectiveModifierFlags & 4 /* Public */ ? 4 /* Public */ : effectiveModifierFlags & 16 /* Protected */ ? 16 /* Protected */ : 0 /* None */;
@@ -154329,6 +154378,19 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
154329
154378
  false
154330
154379
  );
154331
154380
  }
154381
+ function createDeclarationName(symbol2, declaration2) {
154382
+ if (getCheckFlags(symbol2) & 262144 /* Mapped */) {
154383
+ const nameType = symbol2.links.nameType;
154384
+ if (nameType && isTypeUsableAsPropertyName(nameType)) {
154385
+ return factory.createIdentifier(unescapeLeadingUnderscores(getPropertyNameFromType(nameType)));
154386
+ }
154387
+ }
154388
+ return getSynthesizedDeepClone(
154389
+ getNameOfDeclaration(declaration2),
154390
+ /*includeTrivia*/
154391
+ false
154392
+ );
154393
+ }
154332
154394
  }
154333
154395
  function createSignatureDeclarationFromSignature(kind, context, quotePreference, signature, body, name, modifiers, optional, enclosingDeclaration, importAdder) {
154334
154396
  const program = context.program;
@@ -155984,7 +156046,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
155984
156046
  getFixes: () => getFixes,
155985
156047
  getImportCompletionAction: () => getImportCompletionAction,
155986
156048
  getImportKind: () => getImportKind,
155987
- getJSDocTypedefNode: () => getJSDocTypedefNode,
156049
+ getJSDocTypedefNodes: () => getJSDocTypedefNodes,
155988
156050
  getNoopSymbolTrackerWithResolver: () => getNoopSymbolTrackerWithResolver,
155989
156051
  getPromoteTypeOnlyCompletionAction: () => getPromoteTypeOnlyCompletionAction,
155990
156052
  getSupportedErrorCodes: () => getSupportedErrorCodes,
@@ -163860,6 +163922,9 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
163860
163922
  function shouldShowLiteralParameterNameHintsOnly(preferences) {
163861
163923
  return preferences.includeInlayParameterNameHints === "literals";
163862
163924
  }
163925
+ function shouldUseInteractiveInlayHints(preferences) {
163926
+ return preferences.interactiveInlayHints === true;
163927
+ }
163863
163928
  function provideInlayHints(context) {
163864
163929
  const { file, program, span, cancellationToken, preferences } = context;
163865
163930
  const sourceFileText = file.text;
@@ -163910,9 +163975,15 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
163910
163975
  function isSignatureSupportingReturnAnnotation(node) {
163911
163976
  return isArrowFunction(node) || isFunctionExpression(node) || isFunctionDeclaration(node) || isMethodDeclaration(node) || isGetAccessorDeclaration(node);
163912
163977
  }
163913
- function addParameterHints(text, position, isFirstVariadicArgument) {
163978
+ function addParameterHints(text, parameter, position, isFirstVariadicArgument, sourceFile) {
163979
+ let hintText = `${isFirstVariadicArgument ? "..." : ""}${text}`;
163980
+ if (shouldUseInteractiveInlayHints(preferences)) {
163981
+ hintText = [getNodeDisplayPart(hintText, parameter, sourceFile), { text: ":" }];
163982
+ } else {
163983
+ hintText += ":";
163984
+ }
163914
163985
  result.push({
163915
- text: `${isFirstVariadicArgument ? "..." : ""}${truncation(text, maxHintsLength)}:`,
163986
+ text: hintText,
163916
163987
  position,
163917
163988
  kind: "Parameter" /* Parameter */,
163918
163989
  whitespaceAfter: true
@@ -163920,7 +163991,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
163920
163991
  }
163921
163992
  function addTypeHints(text, position) {
163922
163993
  result.push({
163923
- text: `: ${truncation(text, maxHintsLength)}`,
163994
+ text: `: ${text.length > maxTypeHintLength ? text.substr(0, maxTypeHintLength - "...".length) + "..." : text}`,
163924
163995
  position,
163925
163996
  kind: "Type" /* Type */,
163926
163997
  whitespaceBefore: true
@@ -163928,7 +163999,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
163928
163999
  }
163929
164000
  function addEnumMemberValueHints(text, position) {
163930
164001
  result.push({
163931
- text: `= ${truncation(text, maxHintsLength)}`,
164002
+ text: `= ${text}`,
163932
164003
  position,
163933
164004
  kind: "Enum" /* Enum */,
163934
164005
  whitespaceBefore: true
@@ -163978,6 +164049,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
163978
164049
  return;
163979
164050
  }
163980
164051
  let signatureParamPos = 0;
164052
+ const sourceFile = shouldUseInteractiveInlayHints(preferences) ? expr.getSourceFile() : void 0;
163981
164053
  for (const originalArg of args) {
163982
164054
  const arg = skipParentheses(originalArg);
163983
164055
  if (shouldShowLiteralParameterNameHintsOnly(preferences) && !isHintableLiteral(arg)) {
@@ -163998,10 +164070,10 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
163998
164070
  }
163999
164071
  }
164000
164072
  }
164001
- const identifierNameInfo = checker.getParameterIdentifierNameAtPosition(signature, signatureParamPos);
164073
+ const identifierInfo = checker.getParameterIdentifierInfoAtPosition(signature, signatureParamPos);
164002
164074
  signatureParamPos = signatureParamPos + (spreadArgs || 1);
164003
- if (identifierNameInfo) {
164004
- const [parameterName, isFirstVariadicArgument] = identifierNameInfo;
164075
+ if (identifierInfo) {
164076
+ const { parameter, parameterName, isRestParameter: isFirstVariadicArgument } = identifierInfo;
164005
164077
  const isParameterNameNotSameAsArgument = preferences.includeInlayParameterNameHintsWhenArgumentMatchesName || !identifierOrAccessExpressionPostfixMatchesParameterName(arg, parameterName);
164006
164078
  if (!isParameterNameNotSameAsArgument && !isFirstVariadicArgument) {
164007
164079
  continue;
@@ -164010,7 +164082,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
164010
164082
  if (leadingCommentsContainsParameterName(arg, name)) {
164011
164083
  continue;
164012
164084
  }
164013
- addParameterHints(name, originalArg.getStart(), isFirstVariadicArgument);
164085
+ addParameterHints(name, parameter, originalArg.getStart(), isFirstVariadicArgument, sourceFile);
164014
164086
  }
164015
164087
  }
164016
164088
  }
@@ -164116,12 +164188,6 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
164116
164188
  }
164117
164189
  return printTypeInSingleLine(signatureParamType);
164118
164190
  }
164119
- function truncation(text, maxLength2) {
164120
- if (text.length > maxLength2) {
164121
- return text.substr(0, maxLength2 - "...".length) + "...";
164122
- }
164123
- return text;
164124
- }
164125
164191
  function printTypeInSingleLine(type) {
164126
164192
  const flags = 70221824 /* IgnoreErrors */ | 1048576 /* AllowUniqueESSymbolType */ | 16384 /* UseAliasDefinedOutsideCurrentScope */;
164127
164193
  const printer = createPrinterWithRemoveComments();
@@ -164152,13 +164218,20 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
164152
164218
  }
164153
164219
  return true;
164154
164220
  }
164221
+ function getNodeDisplayPart(text, node, sourceFile) {
164222
+ return {
164223
+ text,
164224
+ span: createTextSpanFromNode(node, sourceFile),
164225
+ file: sourceFile.fileName
164226
+ };
164227
+ }
164155
164228
  }
164156
- var maxHintsLength, leadingParameterNameCommentRegexFactory;
164229
+ var maxTypeHintLength, leadingParameterNameCommentRegexFactory;
164157
164230
  var init_inlayHints = __esm({
164158
164231
  "src/services/inlayHints.ts"() {
164159
164232
  "use strict";
164160
164233
  init_ts4();
164161
- maxHintsLength = 30;
164234
+ maxTypeHintLength = 30;
164162
164235
  leadingParameterNameCommentRegexFactory = (name) => {
164163
164236
  return new RegExp(`^\\s?/\\*\\*?\\s?${name}\\s?\\*\\/\\s?$`);
164164
164237
  };
@@ -166660,7 +166733,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
166660
166733
  }
166661
166734
  return modifiers.size > 0 ? arrayFrom(modifiers.values()).join(",") : "" /* none */;
166662
166735
  }
166663
- function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, enclosingDeclaration, location, semanticMeaning = getMeaningFromLocation(location), alias) {
166736
+ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker, symbol, sourceFile, enclosingDeclaration, location, type, semanticMeaning, alias) {
166664
166737
  var _a;
166665
166738
  const displayParts = [];
166666
166739
  let documentation = [];
@@ -166669,7 +166742,6 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
166669
166742
  let symbolKind = semanticMeaning & 1 /* Value */ ? getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar(typeChecker, symbol, location) : "" /* unknown */;
166670
166743
  let hasAddedSymbolInfo = false;
166671
166744
  const isThisExpression = location.kind === 110 /* ThisKeyword */ && isInExpressionContext(location) || isThisInTypeQuery(location);
166672
- let type;
166673
166745
  let documentationFromAlias;
166674
166746
  let tagsFromAlias;
166675
166747
  let hasMultipleSignatures = false;
@@ -166698,7 +166770,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
166698
166770
  }
166699
166771
  }
166700
166772
  let signature;
166701
- type = isThisExpression ? typeChecker.getTypeAtLocation(location) : typeChecker.getTypeOfSymbolAtLocation(symbol, location);
166773
+ type ?? (type = isThisExpression ? typeChecker.getTypeAtLocation(location) : typeChecker.getTypeOfSymbolAtLocation(symbol, location));
166702
166774
  if (location.parent && location.parent.kind === 211 /* PropertyAccessExpression */) {
166703
166775
  const right = location.parent.name;
166704
166776
  if (right === location || right && right.getFullWidth() === 0) {
@@ -166913,12 +166985,13 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
166913
166985
  if (declarationName && !hasAddedSymbolInfo) {
166914
166986
  const isExternalModuleDeclaration = isModuleWithStringLiteralName(resolvedNode) && hasSyntacticModifier(resolvedNode, 2 /* Ambient */);
166915
166987
  const shouldUseAliasName = symbol.name !== "default" && !isExternalModuleDeclaration;
166916
- const resolvedInfo = getSymbolDisplayPartsDocumentationAndSymbolKind(
166988
+ const resolvedInfo = getSymbolDisplayPartsDocumentationAndSymbolKindWorker(
166917
166989
  typeChecker,
166918
166990
  resolvedSymbol,
166919
166991
  getSourceFileOfNode(resolvedNode),
166920
166992
  resolvedNode,
166921
166993
  declarationName,
166994
+ type,
166922
166995
  semanticMeaning,
166923
166996
  shouldUseAliasName ? symbol : resolvedSymbol
166924
166997
  );
@@ -167173,6 +167246,19 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
167173
167246
  addRange(displayParts, typeParameterParts);
167174
167247
  }
167175
167248
  }
167249
+ function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, enclosingDeclaration, location, semanticMeaning = getMeaningFromLocation(location), alias) {
167250
+ return getSymbolDisplayPartsDocumentationAndSymbolKindWorker(
167251
+ typeChecker,
167252
+ symbol,
167253
+ sourceFile,
167254
+ enclosingDeclaration,
167255
+ location,
167256
+ /*type*/
167257
+ void 0,
167258
+ semanticMeaning,
167259
+ alias
167260
+ );
167261
+ }
167176
167262
  function isLocalVariableOrFunction(symbol) {
167177
167263
  if (symbol.parent) {
167178
167264
  return false;
@@ -180846,10 +180932,22 @@ Project '${project.projectName}' (${ProjectKind[project.projectKind]}) ${counter
180846
180932
  const { file, project } = this.getFileAndProject(args);
180847
180933
  const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file);
180848
180934
  const hints = project.getLanguageService().provideInlayHints(file, args, this.getPreferences(file));
180849
- return hints.map((hint) => ({
180850
- ...hint,
180851
- position: scriptInfo.positionToLineOffset(hint.position)
180852
- }));
180935
+ return hints.map((hint) => {
180936
+ const { text, position } = hint;
180937
+ const hintText = typeof text === "string" ? text : text.map(({ text: text2, span, file: file2 }) => ({
180938
+ text: text2,
180939
+ span: span && {
180940
+ start: scriptInfo.positionToLineOffset(span.start),
180941
+ end: scriptInfo.positionToLineOffset(span.start + span.length),
180942
+ file: file2
180943
+ }
180944
+ }));
180945
+ return {
180946
+ ...hint,
180947
+ position: scriptInfo.positionToLineOffset(position),
180948
+ text: hintText
180949
+ };
180950
+ });
180853
180951
  }
180854
180952
  setCompilerOptionsForInferredProjects(args) {
180855
180953
  this.projectService.setCompilerOptionsForInferredProjects(args.options, args.projectRootPath);
@@ -183882,6 +183980,7 @@ ${e.message}`;
183882
183980
  getPropertyAssignmentAliasLikeExpression: () => getPropertyAssignmentAliasLikeExpression,
183883
183981
  getPropertyNameForPropertyNameNode: () => getPropertyNameForPropertyNameNode,
183884
183982
  getPropertyNameForUniqueESSymbol: () => getPropertyNameForUniqueESSymbol,
183983
+ getPropertyNameFromType: () => getPropertyNameFromType,
183885
183984
  getPropertyNameOfBindingOrAssignmentElement: () => getPropertyNameOfBindingOrAssignmentElement,
183886
183985
  getPropertySymbolFromBindingElement: () => getPropertySymbolFromBindingElement,
183887
183986
  getPropertySymbolsFromContextualType: () => getPropertySymbolsFromContextualType,
@@ -184714,6 +184813,7 @@ ${e.message}`;
184714
184813
  isTypeQueryNode: () => isTypeQueryNode,
184715
184814
  isTypeReferenceNode: () => isTypeReferenceNode,
184716
184815
  isTypeReferenceType: () => isTypeReferenceType,
184816
+ isTypeUsableAsPropertyName: () => isTypeUsableAsPropertyName,
184717
184817
  isUMDExportSymbol: () => isUMDExportSymbol,
184718
184818
  isUnaryExpression: () => isUnaryExpression,
184719
184819
  isUnaryExpressionWithWrite: () => isUnaryExpressionWithWrite,
@@ -186285,6 +186385,7 @@ ${e.message}`;
186285
186385
  getPropertyAssignmentAliasLikeExpression: () => getPropertyAssignmentAliasLikeExpression,
186286
186386
  getPropertyNameForPropertyNameNode: () => getPropertyNameForPropertyNameNode,
186287
186387
  getPropertyNameForUniqueESSymbol: () => getPropertyNameForUniqueESSymbol,
186388
+ getPropertyNameFromType: () => getPropertyNameFromType,
186288
186389
  getPropertyNameOfBindingOrAssignmentElement: () => getPropertyNameOfBindingOrAssignmentElement,
186289
186390
  getPropertySymbolFromBindingElement: () => getPropertySymbolFromBindingElement,
186290
186391
  getPropertySymbolsFromContextualType: () => getPropertySymbolsFromContextualType,
@@ -187117,6 +187218,7 @@ ${e.message}`;
187117
187218
  isTypeQueryNode: () => isTypeQueryNode,
187118
187219
  isTypeReferenceNode: () => isTypeReferenceNode,
187119
187220
  isTypeReferenceType: () => isTypeReferenceType,
187221
+ isTypeUsableAsPropertyName: () => isTypeUsableAsPropertyName,
187120
187222
  isUMDExportSymbol: () => isUMDExportSymbol,
187121
187223
  isUnaryExpression: () => isUnaryExpression,
187122
187224
  isUnaryExpressionWithWrite: () => isUnaryExpressionWithWrite,