typescript 4.7.0-dev.20220421 → 4.7.0-dev.20220424

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tsserver.js CHANGED
@@ -100,7 +100,7 @@ var ts;
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-dev.20220421";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220424";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -14702,7 +14702,7 @@ var ts;
14702
14702
  var _a;
14703
14703
  // If we don't need to downlevel and we can reach the original source text using
14704
14704
  // the node's parent reference, then simply get the text as it was originally written.
14705
- if (canUseOriginalText(node, flags)) {
14705
+ if (sourceFile && canUseOriginalText(node, flags)) {
14706
14706
  return getSourceTextOfNodeFromSourceFile(sourceFile, node);
14707
14707
  }
14708
14708
  // If we can't reach the original source text, use the canonical form if it's a number,
@@ -18293,10 +18293,10 @@ var ts;
18293
18293
  return ts.combinePaths(newDirPath, sourceFilePath);
18294
18294
  }
18295
18295
  ts.getSourceFilePathInNewDirWorker = getSourceFilePathInNewDirWorker;
18296
- function writeFile(host, diagnostics, fileName, data, writeByteOrderMark, sourceFiles) {
18297
- host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) {
18296
+ function writeFile(host, diagnostics, fileName, text, writeByteOrderMark, sourceFiles, data) {
18297
+ host.writeFile(fileName, text, writeByteOrderMark, function (hostErrorMessage) {
18298
18298
  diagnostics.add(createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage));
18299
- }, sourceFiles);
18299
+ }, sourceFiles, data);
18300
18300
  }
18301
18301
  ts.writeFile = writeFile;
18302
18302
  function ensureDirectoriesExist(directoryPath, createDirectory, directoryExists) {
@@ -73432,6 +73432,7 @@ var ts;
73432
73432
  }
73433
73433
  }
73434
73434
  else {
73435
+ error(attributeDecl.expression, ts.Diagnostics.Spread_types_may_only_be_created_from_object_types);
73435
73436
  typeToIntersect = typeToIntersect ? getIntersectionType([typeToIntersect, exprType]) : exprType;
73436
73437
  }
73437
73438
  }
@@ -75669,6 +75670,7 @@ var ts;
75669
75670
  // decorators are applied to a declaration by the emitter, and not to an expression.
75670
75671
  var isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters;
75671
75672
  var argCheckMode = !isDecorator && !isSingleNonGenericCandidate && ts.some(args, isContextSensitive) ? 4 /* SkipContextSensitive */ : 0 /* Normal */;
75673
+ argCheckMode |= checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
75672
75674
  // The following variables are captured and modified by calls to chooseOverload.
75673
75675
  // If overload resolution or type argument inference fails, we want to report the
75674
75676
  // best error possible. The best error is one which says that an argument was not
@@ -75884,7 +75886,7 @@ var ts;
75884
75886
  // If one or more context sensitive arguments were excluded, we start including
75885
75887
  // them now (and keeping do so for any subsequent candidates) and perform a second
75886
75888
  // round of type inference and applicability checking for this particular candidate.
75887
- argCheckMode = 0 /* Normal */;
75889
+ argCheckMode = checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
75888
75890
  if (inferenceContext) {
75889
75891
  var typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext);
75890
75892
  checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
@@ -109966,6 +109968,7 @@ var ts;
109966
109968
  else {
109967
109969
  printer.writeFile(sourceFile, writer, sourceMapGenerator);
109968
109970
  }
109971
+ var sourceMapUrlPos;
109969
109972
  if (sourceMapGenerator) {
109970
109973
  if (sourceMapDataList) {
109971
109974
  sourceMapDataList.push({
@@ -109977,6 +109980,7 @@ var ts;
109977
109980
  if (sourceMappingURL) {
109978
109981
  if (!writer.isAtStartOfLine())
109979
109982
  writer.rawWrite(newLine);
109983
+ sourceMapUrlPos = writer.getTextPos();
109980
109984
  writer.writeComment("//# " + "sourceMappingURL" + "=" + sourceMappingURL); // Tools can sometimes see this line as a source mapping url comment
109981
109985
  }
109982
109986
  // Write the source map
@@ -109989,7 +109993,7 @@ var ts;
109989
109993
  writer.writeLine();
109990
109994
  }
109991
109995
  // Write the output file
109992
- ts.writeFile(host, emitterDiagnostics, jsFilePath, writer.getText(), !!compilerOptions.emitBOM, sourceFiles);
109996
+ ts.writeFile(host, emitterDiagnostics, jsFilePath, writer.getText(), !!compilerOptions.emitBOM, sourceFiles, { sourceMapUrlPos: sourceMapUrlPos });
109993
109997
  // Reset state
109994
109998
  writer.clear();
109995
109999
  }
@@ -110511,7 +110515,7 @@ var ts;
110511
110515
  setWriter(/*output*/ undefined, /*_sourceMapGenerator*/ undefined);
110512
110516
  }
110513
110517
  function getCurrentLineMap() {
110514
- return currentLineMap || (currentLineMap = ts.getLineStarts(currentSourceFile));
110518
+ return currentLineMap || (currentLineMap = ts.getLineStarts(ts.Debug.checkDefined(currentSourceFile)));
110515
110519
  }
110516
110520
  function emit(node, parenthesizerRule) {
110517
110521
  if (node === undefined)
@@ -111686,7 +111690,7 @@ var ts;
111686
111690
  increaseIndent();
111687
111691
  }
111688
111692
  var preferNewLine = node.multiLine ? 65536 /* PreferNewLine */ : 0 /* None */;
111689
- var allowTrailingComma = currentSourceFile.languageVersion >= 1 /* ES5 */ && !ts.isJsonSourceFile(currentSourceFile) ? 64 /* AllowTrailingComma */ : 0 /* None */;
111693
+ var allowTrailingComma = currentSourceFile && currentSourceFile.languageVersion >= 1 /* ES5 */ && !ts.isJsonSourceFile(currentSourceFile) ? 64 /* AllowTrailingComma */ : 0 /* None */;
111690
111694
  emitList(node, node.properties, 526226 /* ObjectLiteralExpressionProperties */ | allowTrailingComma | preferNewLine);
111691
111695
  if (indentedFlag) {
111692
111696
  decreaseIndent();
@@ -112042,7 +112046,7 @@ var ts;
112042
112046
  emitExpression(node.expression, parenthesizer.parenthesizeExpressionOfExpressionStatement);
112043
112047
  // Emit semicolon in non json files
112044
112048
  // or if json file that created synthesized expression(eg.define expression statement when --out and amd code generation)
112045
- if (!ts.isJsonSourceFile(currentSourceFile) || ts.nodeIsSynthesized(node.expression)) {
112049
+ if (!currentSourceFile || !ts.isJsonSourceFile(currentSourceFile) || ts.nodeIsSynthesized(node.expression)) {
112046
112050
  writeTrailingSemicolon();
112047
112051
  }
112048
112052
  }
@@ -112335,7 +112339,7 @@ var ts;
112335
112339
  if (body.multiLine) {
112336
112340
  return false;
112337
112341
  }
112338
- if (!ts.nodeIsSynthesized(body) && !ts.rangeIsOnSingleLine(body, currentSourceFile)) {
112342
+ if (!ts.nodeIsSynthesized(body) && currentSourceFile && !ts.rangeIsOnSingleLine(body, currentSourceFile)) {
112339
112343
  return false;
112340
112344
  }
112341
112345
  if (getLeadingLineTerminatorCount(body, body.statements, 2 /* PreserveLines */)
@@ -112360,12 +112364,7 @@ var ts;
112360
112364
  var emitBlockFunctionBody = shouldEmitBlockFunctionBodyOnSingleLine(body)
112361
112365
  ? emitBlockFunctionBodyOnSingleLine
112362
112366
  : emitBlockFunctionBodyWorker;
112363
- if (emitBodyWithDetachedComments) {
112364
- emitBodyWithDetachedComments(body, body.statements, emitBlockFunctionBody);
112365
- }
112366
- else {
112367
- emitBlockFunctionBody(body);
112368
- }
112367
+ emitBodyWithDetachedComments(body, body.statements, emitBlockFunctionBody);
112369
112368
  decreaseIndent();
112370
112369
  writeToken(19 /* CloseBraceToken */, body.statements.end, writePunctuation, body);
112371
112370
  onAfterEmitNode === null || onAfterEmitNode === void 0 ? void 0 : onAfterEmitNode(body);
@@ -112762,7 +112761,8 @@ var ts;
112762
112761
  var emitAsSingleStatement = statements.length === 1 &&
112763
112762
  (
112764
112763
  // treat synthesized nodes as located on the same line for emit purposes
112765
- ts.nodeIsSynthesized(parentNode) ||
112764
+ !currentSourceFile ||
112765
+ ts.nodeIsSynthesized(parentNode) ||
112766
112766
  ts.nodeIsSynthesized(statements[0]) ||
112767
112767
  ts.rangeStartPositionsAreOnSameLine(parentNode, statements[0], currentSourceFile));
112768
112768
  var format = 163969 /* CaseOrDefaultClauseStatements */;
@@ -112993,16 +112993,14 @@ var ts;
112993
112993
  function emitSourceFile(node) {
112994
112994
  writeLine();
112995
112995
  var statements = node.statements;
112996
- if (emitBodyWithDetachedComments) {
112997
- // Emit detached comment if there are no prologue directives or if the first node is synthesized.
112998
- // The synthesized node will have no leading comment so some comments may be missed.
112999
- var shouldEmitDetachedComment = statements.length === 0 ||
113000
- !ts.isPrologueDirective(statements[0]) ||
113001
- ts.nodeIsSynthesized(statements[0]);
113002
- if (shouldEmitDetachedComment) {
113003
- emitBodyWithDetachedComments(node, statements, emitSourceFileWorker);
113004
- return;
113005
- }
112996
+ // Emit detached comment if there are no prologue directives or if the first node is synthesized.
112997
+ // The synthesized node will have no leading comment so some comments may be missed.
112998
+ var shouldEmitDetachedComment = statements.length === 0 ||
112999
+ !ts.isPrologueDirective(statements[0]) ||
113000
+ ts.nodeIsSynthesized(statements[0]);
113001
+ if (shouldEmitDetachedComment) {
113002
+ emitBodyWithDetachedComments(node, statements, emitSourceFileWorker);
113003
+ return;
113006
113004
  }
113007
113005
  emitSourceFileWorker(node);
113008
113006
  }
@@ -113391,7 +113389,7 @@ var ts;
113391
113389
  }
113392
113390
  if (isEmpty) {
113393
113391
  // Write a line terminator if the parent node was multi-line
113394
- if (format & 1 /* MultiLine */ && !(preserveSourceNewlines && (!parentNode || ts.rangeIsOnSingleLine(parentNode, currentSourceFile)))) {
113392
+ if (format & 1 /* MultiLine */ && !(preserveSourceNewlines && (!parentNode || currentSourceFile && ts.rangeIsOnSingleLine(parentNode, currentSourceFile)))) {
113395
113393
  writeLine();
113396
113394
  }
113397
113395
  else if (format & 256 /* SpaceBetweenBraces */ && !(format & 524288 /* NoSpaceIfEmpty */)) {
@@ -113652,7 +113650,7 @@ var ts;
113652
113650
  }
113653
113651
  var firstChild_1 = children[0];
113654
113652
  if (firstChild_1 === undefined) {
113655
- return !parentNode || ts.rangeIsOnSingleLine(parentNode, currentSourceFile) ? 0 : 1;
113653
+ return !parentNode || currentSourceFile && ts.rangeIsOnSingleLine(parentNode, currentSourceFile) ? 0 : 1;
113656
113654
  }
113657
113655
  if (firstChild_1.pos === nextListElementPos) {
113658
113656
  // If this child starts at the beginning of a list item in a parent list, its leading
@@ -113676,7 +113674,7 @@ var ts;
113676
113674
  // JsxText will be written with its leading whitespace, so don't add more manually.
113677
113675
  return 0;
113678
113676
  }
113679
- if (parentNode &&
113677
+ if (currentSourceFile && parentNode &&
113680
113678
  !ts.positionIsSynthesized(parentNode.pos) &&
113681
113679
  !ts.nodeIsSynthesized(firstChild_1) &&
113682
113680
  (!firstChild_1.parent || ts.getOriginalNode(firstChild_1.parent) === ts.getOriginalNode(parentNode))) {
@@ -113700,7 +113698,7 @@ var ts;
113700
113698
  // JsxText will be written with its leading whitespace, so don't add more manually.
113701
113699
  return 0;
113702
113700
  }
113703
- else if (!ts.nodeIsSynthesized(previousNode) && !ts.nodeIsSynthesized(nextNode)) {
113701
+ else if (currentSourceFile && !ts.nodeIsSynthesized(previousNode) && !ts.nodeIsSynthesized(nextNode)) {
113704
113702
  if (preserveSourceNewlines && siblingNodePositionsAreComparable(previousNode, nextNode)) {
113705
113703
  return getEffectiveLines(function (includeComments) { return ts.getLinesBetweenRangeEndAndRangeStart(previousNode, nextNode, currentSourceFile, includeComments); });
113706
113704
  }
@@ -113732,9 +113730,9 @@ var ts;
113732
113730
  }
113733
113731
  var lastChild = ts.lastOrUndefined(children);
113734
113732
  if (lastChild === undefined) {
113735
- return !parentNode || ts.rangeIsOnSingleLine(parentNode, currentSourceFile) ? 0 : 1;
113733
+ return !parentNode || currentSourceFile && ts.rangeIsOnSingleLine(parentNode, currentSourceFile) ? 0 : 1;
113736
113734
  }
113737
- if (parentNode && !ts.positionIsSynthesized(parentNode.pos) && !ts.nodeIsSynthesized(lastChild) && (!lastChild.parent || lastChild.parent === parentNode)) {
113735
+ if (currentSourceFile && parentNode && !ts.positionIsSynthesized(parentNode.pos) && !ts.nodeIsSynthesized(lastChild) && (!lastChild.parent || lastChild.parent === parentNode)) {
113738
113736
  if (preserveSourceNewlines) {
113739
113737
  var end_1 = ts.isNodeArray(children) && !ts.positionIsSynthesized(children.end) ? children.end : lastChild.end;
113740
113738
  return getEffectiveLines(function (includeComments) { return ts.getLinesBetweenPositionAndNextNonWhitespaceCharacter(end_1, parentNode.end, currentSourceFile, includeComments); });
@@ -113807,7 +113805,7 @@ var ts;
113807
113805
  if (ts.getStartsOnNewLine(node2)) {
113808
113806
  return 1;
113809
113807
  }
113810
- if (!ts.nodeIsSynthesized(parent) && !ts.nodeIsSynthesized(node1) && !ts.nodeIsSynthesized(node2)) {
113808
+ if (currentSourceFile && !ts.nodeIsSynthesized(parent) && !ts.nodeIsSynthesized(node1) && !ts.nodeIsSynthesized(node2)) {
113811
113809
  if (preserveSourceNewlines) {
113812
113810
  return getEffectiveLines(function (includeComments) { return ts.getLinesBetweenRangeEndAndRangeStart(node1, node2, currentSourceFile, includeComments); });
113813
113811
  }
@@ -113817,7 +113815,7 @@ var ts;
113817
113815
  }
113818
113816
  function isEmptyBlock(block) {
113819
113817
  return block.statements.length === 0
113820
- && ts.rangeEndIsOnSameLineAsRangeStart(block, block, currentSourceFile);
113818
+ && (!currentSourceFile || ts.rangeEndIsOnSameLineAsRangeStart(block, block, currentSourceFile));
113821
113819
  }
113822
113820
  function skipSynthesizedParentheses(node) {
113823
113821
  while (node.kind === 212 /* ParenthesizedExpression */ && ts.nodeIsSynthesized(node)) {
@@ -113829,16 +113827,23 @@ var ts;
113829
113827
  if (ts.isGeneratedIdentifier(node)) {
113830
113828
  return generateName(node);
113831
113829
  }
113832
- else if ((ts.isIdentifier(node) || ts.isPrivateIdentifier(node)) && (ts.nodeIsSynthesized(node) || !node.parent || !currentSourceFile || (node.parent && currentSourceFile && ts.getSourceFileOfNode(node) !== ts.getOriginalNode(currentSourceFile)))) {
113833
- return ts.idText(node);
113834
- }
113835
- else if (node.kind === 10 /* StringLiteral */ && node.textSourceNode) {
113830
+ if (ts.isStringLiteral(node) && node.textSourceNode) {
113836
113831
  return getTextOfNode(node.textSourceNode, includeTrivia);
113837
113832
  }
113838
- else if (ts.isLiteralExpression(node) && (ts.nodeIsSynthesized(node) || !node.parent)) {
113839
- return node.text;
113833
+ var sourceFile = currentSourceFile; // const needed for control flow
113834
+ var canUseSourceFile = !!sourceFile && !!node.parent && !ts.nodeIsSynthesized(node);
113835
+ if (ts.isMemberName(node)) {
113836
+ if (!canUseSourceFile || ts.getSourceFileOfNode(node) !== ts.getOriginalNode(sourceFile)) {
113837
+ return ts.idText(node);
113838
+ }
113840
113839
  }
113841
- return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node, includeTrivia);
113840
+ else {
113841
+ ts.Debug.assertNode(node, ts.isLiteralExpression); // not strictly necessary
113842
+ if (!canUseSourceFile) {
113843
+ return node.text;
113844
+ }
113845
+ }
113846
+ return ts.getSourceTextOfNodeFromSourceFile(sourceFile, node, includeTrivia);
113842
113847
  }
113843
113848
  function getLiteralTextOfNode(node, neverAsciiEscape, jsxAttributeEscape) {
113844
113849
  if (node.kind === 10 /* StringLiteral */ && node.textSourceNode) {
@@ -114417,7 +114422,7 @@ var ts;
114417
114422
  return true;
114418
114423
  }
114419
114424
  function emitLeadingComment(commentPos, commentEnd, kind, hasTrailingNewLine, rangePos) {
114420
- if (!shouldWriteComment(currentSourceFile.text, commentPos))
114425
+ if (!currentSourceFile || !shouldWriteComment(currentSourceFile.text, commentPos))
114421
114426
  return;
114422
114427
  if (!hasWrittenComment) {
114423
114428
  ts.emitNewLineBeforeLeadingCommentOfPosition(getCurrentLineMap(), writer, rangePos, commentPos);
@@ -114444,7 +114449,7 @@ var ts;
114444
114449
  forEachTrailingCommentToEmit(pos, emitTrailingComment);
114445
114450
  }
114446
114451
  function emitTrailingComment(commentPos, commentEnd, _kind, hasTrailingNewLine) {
114447
- if (!shouldWriteComment(currentSourceFile.text, commentPos))
114452
+ if (!currentSourceFile || !shouldWriteComment(currentSourceFile.text, commentPos))
114448
114453
  return;
114449
114454
  // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment2*/
114450
114455
  if (!writer.isAtStartOfLine()) {
@@ -114466,6 +114471,8 @@ var ts;
114466
114471
  exitComment();
114467
114472
  }
114468
114473
  function emitTrailingCommentOfPositionNoNewline(commentPos, commentEnd, kind) {
114474
+ if (!currentSourceFile)
114475
+ return;
114469
114476
  // trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
114470
114477
  emitPos(commentPos);
114471
114478
  ts.writeCommentRange(currentSourceFile.text, getCurrentLineMap(), writer, commentPos, commentEnd, newLine);
@@ -114475,6 +114482,8 @@ var ts;
114475
114482
  }
114476
114483
  }
114477
114484
  function emitTrailingCommentOfPosition(commentPos, commentEnd, _kind, hasTrailingNewLine) {
114485
+ if (!currentSourceFile)
114486
+ return;
114478
114487
  // trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
114479
114488
  emitPos(commentPos);
114480
114489
  ts.writeCommentRange(currentSourceFile.text, getCurrentLineMap(), writer, commentPos, commentEnd, newLine);
@@ -114507,6 +114516,8 @@ var ts;
114507
114516
  return detachedCommentsInfo !== undefined && ts.last(detachedCommentsInfo).nodePos === pos;
114508
114517
  }
114509
114518
  function forEachLeadingCommentWithoutDetachedComments(cb) {
114519
+ if (!currentSourceFile)
114520
+ return;
114510
114521
  // get the leading comments from detachedPos
114511
114522
  var pos = ts.last(detachedCommentsInfo).detachedCommentEndPos;
114512
114523
  if (detachedCommentsInfo.length - 1) {
@@ -114518,7 +114529,7 @@ var ts;
114518
114529
  ts.forEachLeadingCommentRange(currentSourceFile.text, pos, cb, /*state*/ pos);
114519
114530
  }
114520
114531
  function emitDetachedCommentsAndUpdateCommentsInfo(range) {
114521
- var currentDetachedCommentInfo = ts.emitDetachedComments(currentSourceFile.text, getCurrentLineMap(), writer, emitComment, range, newLine, commentsDisabled);
114532
+ var currentDetachedCommentInfo = currentSourceFile && ts.emitDetachedComments(currentSourceFile.text, getCurrentLineMap(), writer, emitComment, range, newLine, commentsDisabled);
114522
114533
  if (currentDetachedCommentInfo) {
114523
114534
  if (detachedCommentsInfo) {
114524
114535
  detachedCommentsInfo.push(currentDetachedCommentInfo);
@@ -114529,7 +114540,7 @@ var ts;
114529
114540
  }
114530
114541
  }
114531
114542
  function emitComment(text, lineMap, writer, commentPos, commentEnd, newLine) {
114532
- if (!shouldWriteComment(currentSourceFile.text, commentPos))
114543
+ if (!currentSourceFile || !shouldWriteComment(currentSourceFile.text, commentPos))
114533
114544
  return;
114534
114545
  emitPos(commentPos);
114535
114546
  ts.writeCommentRange(text, lineMap, writer, commentPos, commentEnd, newLine);
@@ -114541,7 +114552,7 @@ var ts;
114541
114552
  * @return true if the comment is a triple-slash comment else false
114542
114553
  */
114543
114554
  function isTripleSlashComment(commentPos, commentEnd) {
114544
- return ts.isRecognizedTripleSlashComment(currentSourceFile.text, commentPos, commentEnd);
114555
+ return !!currentSourceFile && ts.isRecognizedTripleSlashComment(currentSourceFile.text, commentPos, commentEnd);
114545
114556
  }
114546
114557
  // Source Maps
114547
114558
  function getParsedSourceMap(node) {
@@ -115456,7 +115467,11 @@ var ts;
115456
115467
  return newValue;
115457
115468
  };
115458
115469
  if (originalWriteFile) {
115459
- host.writeFile = function (fileName, data, writeByteOrderMark, onError, sourceFiles) {
115470
+ host.writeFile = function (fileName, data) {
115471
+ var rest = [];
115472
+ for (var _i = 2; _i < arguments.length; _i++) {
115473
+ rest[_i - 2] = arguments[_i];
115474
+ }
115460
115475
  var key = toPath(fileName);
115461
115476
  fileExistsCache.delete(key);
115462
115477
  var value = readFileCache.get(key);
@@ -115470,7 +115485,7 @@ var ts;
115470
115485
  sourceFileCache.delete(key);
115471
115486
  }
115472
115487
  }
115473
- originalWriteFile.call(host, fileName, data, writeByteOrderMark, onError, sourceFiles);
115488
+ originalWriteFile.call.apply(originalWriteFile, __spreadArray([host, fileName, data], rest, false));
115474
115489
  };
115475
115490
  }
115476
115491
  // directoryExists
@@ -116403,6 +116418,7 @@ var ts;
116403
116418
  useCaseSensitiveFileNames: function () { return host.useCaseSensitiveFileNames(); },
116404
116419
  getFileIncludeReasons: function () { return fileReasons; },
116405
116420
  structureIsReused: structureIsReused,
116421
+ writeFile: writeFile,
116406
116422
  };
116407
116423
  onProgramCreateComplete();
116408
116424
  // Add file processingDiagnostics
@@ -116900,7 +116916,7 @@ var ts;
116900
116916
  getProjectReferenceRedirect: getProjectReferenceRedirect,
116901
116917
  isSourceOfProjectReferenceRedirect: isSourceOfProjectReferenceRedirect,
116902
116918
  getSymlinkCache: getSymlinkCache,
116903
- writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError, sourceFiles) { return host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); }),
116919
+ writeFile: writeFileCallback || writeFile,
116904
116920
  isEmitBlocked: isEmitBlocked,
116905
116921
  readFile: function (f) { return host.readFile(f); },
116906
116922
  fileExists: function (f) {
@@ -116920,6 +116936,9 @@ var ts;
116920
116936
  getFileIncludeReasons: program.getFileIncludeReasons,
116921
116937
  };
116922
116938
  }
116939
+ function writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data) {
116940
+ host.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
116941
+ }
116923
116942
  function emitBuildInfo(writeFileCallback) {
116924
116943
  ts.Debug.assert(!ts.outFile(options));
116925
116944
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("emit" /* Emit */, "emitBuildInfo", {}, /*separateBeginAndEnd*/ true);
@@ -119362,6 +119381,7 @@ var ts;
119362
119381
  }
119363
119382
  }
119364
119383
  }
119384
+ BuilderState.updateExportedModules = updateExportedModules;
119365
119385
  /**
119366
119386
  * Updates the exported modules from cache into state's exported modules map
119367
119387
  * This should be called whenever it is safe to commit the state of the builder
@@ -120326,7 +120346,43 @@ var ts;
120326
120346
  return toAffectedFileEmitResult(state,
120327
120347
  // When whole program is affected, do emit only once (eg when --out or --outFile is specified)
120328
120348
  // Otherwise just affected file
120329
- ts.Debug.checkDefined(state.program).emit(affected === state.program ? undefined : affected, writeFile || ts.maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles || emitKind === 0 /* DtsOnly */, customTransformers), affected, emitKind, isPendingEmitFile);
120349
+ ts.Debug.checkDefined(state.program).emit(affected === state.program ? undefined : affected, affected !== state.program && ts.getEmitDeclarations(state.compilerOptions) && !customTransformers ?
120350
+ getWriteFileUpdatingSignatureCallback(writeFile) :
120351
+ writeFile || ts.maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles || emitKind === 0 /* DtsOnly */, customTransformers), affected, emitKind, isPendingEmitFile);
120352
+ }
120353
+ function getWriteFileUpdatingSignatureCallback(writeFile) {
120354
+ return function (fileName, text, writeByteOrderMark, onError, sourceFiles, data) {
120355
+ var _a;
120356
+ if (ts.isDeclarationFileName(fileName)) {
120357
+ ts.Debug.assert((sourceFiles === null || sourceFiles === void 0 ? void 0 : sourceFiles.length) === 1);
120358
+ var file = sourceFiles[0];
120359
+ var info = state.fileInfos.get(file.resolvedPath);
120360
+ var signature = ((_a = state.currentAffectedFilesSignatures) === null || _a === void 0 ? void 0 : _a.get(file.resolvedPath)) || info.signature;
120361
+ if (signature === file.version) {
120362
+ var newSignature = (computeHash || ts.generateDjb2Hash)((data === null || data === void 0 ? void 0 : data.sourceMapUrlPos) !== undefined ? text.substring(0, data.sourceMapUrlPos) : text);
120363
+ if (newSignature !== file.version) { // Update it
120364
+ if (host.storeFilesChangingSignatureDuringEmit)
120365
+ (state.filesChangingSignature || (state.filesChangingSignature = new ts.Set())).add(file.resolvedPath);
120366
+ if (state.exportedModulesMap)
120367
+ ts.BuilderState.updateExportedModules(file, file.exportedModulesFromDeclarationEmit, state.currentAffectedFilesExportedModulesMap || (state.currentAffectedFilesExportedModulesMap = ts.BuilderState.createManyToManyPathMap()));
120368
+ if (state.affectedFiles && state.affectedFilesIndex < state.affectedFiles.length) {
120369
+ state.currentAffectedFilesSignatures.set(file.resolvedPath, newSignature);
120370
+ }
120371
+ else {
120372
+ info.signature = newSignature;
120373
+ if (state.exportedModulesMap)
120374
+ ts.BuilderState.updateExportedFilesMapFromCache(state, state.currentAffectedFilesExportedModulesMap);
120375
+ }
120376
+ }
120377
+ }
120378
+ }
120379
+ if (writeFile)
120380
+ writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
120381
+ else if (host.writeFile)
120382
+ host.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
120383
+ else
120384
+ state.program.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
120385
+ };
120330
120386
  }
120331
120387
  /**
120332
120388
  * Emits the JavaScript and declaration files.
@@ -120383,7 +120439,9 @@ var ts;
120383
120439
  }
120384
120440
  }
120385
120441
  }
120386
- return ts.Debug.checkDefined(state.program).emit(targetSourceFile, writeFile || ts.maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
120442
+ return ts.Debug.checkDefined(state.program).emit(targetSourceFile, !ts.outFile(state.compilerOptions) && ts.getEmitDeclarations(state.compilerOptions) && !customTransformers ?
120443
+ getWriteFileUpdatingSignatureCallback(writeFile) :
120444
+ writeFile || ts.maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
120387
120445
  }
120388
120446
  /**
120389
120447
  * Return the semantic diagnostics for the next affected file or undefined if iteration is complete
@@ -122575,6 +122633,7 @@ var ts;
122575
122633
  createHash: ts.maybeBind(host, host.createHash),
122576
122634
  readDirectory: ts.maybeBind(host, host.readDirectory),
122577
122635
  disableUseFileVersionAsSignature: host.disableUseFileVersionAsSignature,
122636
+ storeFilesChangingSignatureDuringEmit: host.storeFilesChangingSignatureDuringEmit,
122578
122637
  };
122579
122638
  function writeFile(fileName, text, writeByteOrderMark, onError) {
122580
122639
  try {
@@ -122634,6 +122693,7 @@ var ts;
122634
122693
  createHash: ts.maybeBind(system, system.createHash),
122635
122694
  createProgram: createProgram || ts.createEmitAndSemanticDiagnosticsBuilderProgram,
122636
122695
  disableUseFileVersionAsSignature: system.disableUseFileVersionAsSignature,
122696
+ storeFilesChangingSignatureDuringEmit: system.storeFilesChangingSignatureDuringEmit,
122637
122697
  };
122638
122698
  }
122639
122699
  ts.createProgramHost = createProgramHost;
@@ -122722,6 +122782,7 @@ var ts;
122722
122782
  var host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, system);
122723
122783
  host.createHash = ts.maybeBind(system, system.createHash);
122724
122784
  host.disableUseFileVersionAsSignature = system.disableUseFileVersionAsSignature;
122785
+ host.storeFilesChangingSignatureDuringEmit = system.storeFilesChangingSignatureDuringEmit;
122725
122786
  ts.setGetSourceFileAsHashVersioned(host, system);
122726
122787
  ts.changeCompilerHostLikeToUseCache(host, function (fileName) { return ts.toPath(fileName, host.getCurrentDirectory(), host.getCanonicalFileName); });
122727
122788
  return host;
@@ -131054,7 +131115,7 @@ var ts;
131054
131115
  GlobalsSearch[GlobalsSearch["Success"] = 1] = "Success";
131055
131116
  GlobalsSearch[GlobalsSearch["Fail"] = 2] = "Fail";
131056
131117
  })(GlobalsSearch || (GlobalsSearch = {}));
131057
- function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, preferences, isForImportStatementCompletion, cb) {
131118
+ function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, position, preferences, isForImportStatementCompletion, isValidTypeOnlyUseSite, cb) {
131058
131119
  var _a, _b, _c;
131059
131120
  var start = ts.timestamp();
131060
131121
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
@@ -131069,9 +131130,9 @@ var ts;
131069
131130
  (_b = host.log) === null || _b === void 0 ? void 0 : _b.call(host, logPrefix + ": response is " + (resolutionLimitExceeded ? "incomplete" : "complete"));
131070
131131
  (_c = host.log) === null || _c === void 0 ? void 0 : _c.call(host, logPrefix + ": " + (ts.timestamp() - start));
131071
131132
  return result;
131072
- function tryResolve(exportInfo, isFromAmbientModule) {
131133
+ function tryResolve(exportInfo, symbolName, isFromAmbientModule) {
131073
131134
  if (isFromAmbientModule) {
131074
- var result_1 = ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, sourceFile, program, host, preferences);
131135
+ var result_1 = ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences);
131075
131136
  if (result_1) {
131076
131137
  ambientCount++;
131077
131138
  }
@@ -131080,7 +131141,7 @@ var ts;
131080
131141
  var shouldResolveModuleSpecifier = isForImportStatementCompletion || preferences.allowIncompleteCompletions && resolvedCount < Completions.moduleSpecifierResolutionLimit;
131081
131142
  var shouldGetModuleSpecifierFromCache = !shouldResolveModuleSpecifier && preferences.allowIncompleteCompletions && cacheAttemptCount < Completions.moduleSpecifierResolutionCacheAttemptLimit;
131082
131143
  var result = (shouldResolveModuleSpecifier || shouldGetModuleSpecifierFromCache)
131083
- ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
131144
+ ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
131084
131145
  : undefined;
131085
131146
  if (!shouldResolveModuleSpecifier && !shouldGetModuleSpecifierFromCache || shouldGetModuleSpecifierFromCache && !result) {
131086
131147
  resolutionLimitExceeded = true;
@@ -131185,8 +131246,8 @@ var ts;
131185
131246
  return undefined;
131186
131247
  var lowerCaseTokenText = location.text.toLowerCase();
131187
131248
  var exportMap = ts.getExportInfoMap(file, host, program, cancellationToken);
131188
- var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, program, file, preferences,
131189
- /*isForImportStatementCompletion*/ false, function (context) {
131249
+ var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, program, file, location.getStart(), preferences,
131250
+ /*isForImportStatementCompletion*/ false, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
131190
131251
  var entries = ts.mapDefined(previousResponse.entries, function (entry) {
131191
131252
  if (!entry.hasAction || !entry.source || !entry.data || completionEntryDataIsResolved(entry.data)) {
131192
131253
  // Not an auto import or already resolved; keep as is
@@ -131198,7 +131259,7 @@ var ts;
131198
131259
  }
131199
131260
  var origin = ts.Debug.checkDefined(getAutoImportSymbolFromCompletionEntryData(entry.name, entry.data, program, host)).origin;
131200
131261
  var info = exportMap.get(file.path, entry.data.exportMapKey);
131201
- var result = info && context.tryResolve(info, !ts.isExternalModuleNameRelative(ts.stripQuotes(origin.moduleSymbol.name)));
131262
+ var result = info && context.tryResolve(info, entry.name, !ts.isExternalModuleNameRelative(ts.stripQuotes(origin.moduleSymbol.name)));
131202
131263
  if (!result)
131203
131264
  return entry;
131204
131265
  var newOrigin = __assign(__assign({}, origin), { kind: 32 /* ResolvedExport */, moduleSpecifier: result.moduleSpecifier });
@@ -131790,22 +131851,44 @@ var ts;
131790
131851
  }
131791
131852
  }
131792
131853
  function createSnippetPrinter(printerOptions) {
131854
+ var escapes;
131793
131855
  var baseWriter = ts.textChanges.createWriter(ts.getNewLineCharacter(printerOptions));
131794
131856
  var printer = ts.createPrinter(printerOptions, baseWriter);
131795
- var writer = __assign(__assign({}, baseWriter), { write: function (s) { return baseWriter.write(ts.escapeSnippetText(s)); }, nonEscapingWrite: baseWriter.write, writeLiteral: function (s) { return baseWriter.writeLiteral(ts.escapeSnippetText(s)); }, writeStringLiteral: function (s) { return baseWriter.writeStringLiteral(ts.escapeSnippetText(s)); }, writeSymbol: function (s, symbol) { return baseWriter.writeSymbol(ts.escapeSnippetText(s), symbol); }, writeParameter: function (s) { return baseWriter.writeParameter(ts.escapeSnippetText(s)); }, writeComment: function (s) { return baseWriter.writeComment(ts.escapeSnippetText(s)); }, writeProperty: function (s) { return baseWriter.writeProperty(ts.escapeSnippetText(s)); } });
131857
+ var writer = __assign(__assign({}, baseWriter), { write: function (s) { return escapingWrite(s, function () { return baseWriter.write(s); }); }, nonEscapingWrite: baseWriter.write, writeLiteral: function (s) { return escapingWrite(s, function () { return baseWriter.writeLiteral(s); }); }, writeStringLiteral: function (s) { return escapingWrite(s, function () { return baseWriter.writeStringLiteral(s); }); }, writeSymbol: function (s, symbol) { return escapingWrite(s, function () { return baseWriter.writeSymbol(s, symbol); }); }, writeParameter: function (s) { return escapingWrite(s, function () { return baseWriter.writeParameter(s); }); }, writeComment: function (s) { return escapingWrite(s, function () { return baseWriter.writeComment(s); }); }, writeProperty: function (s) { return escapingWrite(s, function () { return baseWriter.writeProperty(s); }); } });
131796
131858
  return {
131797
131859
  printSnippetList: printSnippetList,
131798
131860
  printAndFormatSnippetList: printAndFormatSnippetList,
131799
131861
  };
131862
+ // The formatter/scanner will have issues with snippet-escaped text,
131863
+ // so instead of writing the escaped text directly to the writer,
131864
+ // generate a set of changes that can be applied to the unescaped text
131865
+ // to escape it post-formatting.
131866
+ function escapingWrite(s, write) {
131867
+ var escaped = ts.escapeSnippetText(s);
131868
+ if (escaped !== s) {
131869
+ var start = baseWriter.getTextPos();
131870
+ write();
131871
+ var end = baseWriter.getTextPos();
131872
+ escapes = ts.append(escapes || (escapes = []), { newText: escaped, span: { start: start, length: end - start } });
131873
+ }
131874
+ else {
131875
+ write();
131876
+ }
131877
+ }
131800
131878
  /* Snippet-escaping version of `printer.printList`. */
131801
131879
  function printSnippetList(format, list, sourceFile) {
131880
+ var unescaped = printUnescapedSnippetList(format, list, sourceFile);
131881
+ return escapes ? ts.textChanges.applyChanges(unescaped, escapes) : unescaped;
131882
+ }
131883
+ function printUnescapedSnippetList(format, list, sourceFile) {
131884
+ escapes = undefined;
131802
131885
  writer.clear();
131803
131886
  printer.writeList(format, list, sourceFile, writer);
131804
131887
  return writer.getText();
131805
131888
  }
131806
131889
  function printAndFormatSnippetList(format, list, sourceFile, formatContext) {
131807
131890
  var syntheticFile = {
131808
- text: printSnippetList(format, list, sourceFile),
131891
+ text: printUnescapedSnippetList(format, list, sourceFile),
131809
131892
  getLineAndCharacterOfPosition: function (pos) {
131810
131893
  return ts.getLineAndCharacterOfPosition(this, pos);
131811
131894
  },
@@ -131817,7 +131900,10 @@ var ts;
131817
131900
  /* indentation */ 0,
131818
131901
  /* delta */ 0, __assign(__assign({}, formatContext), { options: formatOptions }));
131819
131902
  });
131820
- return ts.textChanges.applyChanges(syntheticFile.text, changes);
131903
+ var allChanges = escapes
131904
+ ? ts.stableSort(ts.concatenate(changes, escapes), function (a, b) { return ts.compareTextSpans(a.span, b.span); })
131905
+ : changes;
131906
+ return ts.textChanges.applyChanges(syntheticFile.text, allChanges);
131821
131907
  }
131822
131908
  }
131823
131909
  function originToCompletionEntryData(origin) {
@@ -132709,7 +132795,7 @@ var ts;
132709
132795
  moduleSymbol: moduleSymbol,
132710
132796
  symbol: firstAccessibleSymbol,
132711
132797
  targetFlags: ts.skipAlias(firstAccessibleSymbol, typeChecker).flags,
132712
- }], sourceFile, program, host, preferences) || {}).moduleSpecifier;
132798
+ }], firstAccessibleSymbol.name, position, ts.isValidTypeOnlyAliasUseSite(location), sourceFile, program, host, preferences) || {}).moduleSpecifier;
132713
132799
  if (moduleSpecifier) {
132714
132800
  var origin = {
132715
132801
  kind: getNullableSymbolOriginInfoKind(6 /* SymbolMemberExport */),
@@ -132964,7 +133050,7 @@ var ts;
132964
133050
  var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
132965
133051
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
132966
133052
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
132967
- resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, preferences, !!importCompletionNode, function (context) {
133053
+ resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
132968
133054
  exportInfo.search(sourceFile.path,
132969
133055
  /*preferCapitalized*/ isRightOfOpenTag, function (symbolName, targetFlags) {
132970
133056
  if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
@@ -132992,7 +133078,7 @@ var ts;
132992
133078
  }
132993
133079
  // If we don't need to resolve module specifiers, we can use any re-export that is importable at all
132994
133080
  // (We need to ensure that at least one is importable to show a completion.)
132995
- var _a = context.tryResolve(info, isFromAmbientModule) || {}, _b = _a.exportInfo, exportInfo = _b === void 0 ? defaultExportInfo : _b, moduleSpecifier = _a.moduleSpecifier;
133081
+ var _a = context.tryResolve(info, symbolName, isFromAmbientModule) || {}, _b = _a.exportInfo, exportInfo = _b === void 0 ? defaultExportInfo : _b, moduleSpecifier = _a.moduleSpecifier;
132996
133082
  var isDefaultExport = exportInfo.exportKind === 1 /* Default */;
132997
133083
  var symbol = isDefaultExport && ts.getLocalSymbolForExportDefault(exportInfo.symbol) || exportInfo.symbol;
132998
133084
  pushAutoImportSymbol(symbol, {
@@ -151816,7 +151902,7 @@ var ts;
151816
151902
  var symbol = checker.getMergedSymbol(ts.skipAlias(exportedSymbol, checker));
151817
151903
  var exportInfo = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, /*isJsxTagName*/ false, host, program, preferences, useAutoImportProvider);
151818
151904
  var useRequire = shouldUseRequire(sourceFile, program);
151819
- var fix = getImportFixForSymbol(sourceFile, exportInfo, moduleSymbol, symbolName, program, /*position*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
151905
+ var fix = getImportFixForSymbol(sourceFile, exportInfo, moduleSymbol, program, /*useNamespaceInfo*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
151820
151906
  if (fix) {
151821
151907
  addImport({ fixes: [fix], symbolName: symbolName, errorIdentifierText: undefined });
151822
151908
  }
@@ -151986,7 +152072,7 @@ var ts;
151986
152072
  : getAllReExportingModules(sourceFile, targetSymbol, moduleSymbol, symbolName, isJsxTagName, host, program, preferences, /*useAutoImportProvider*/ true);
151987
152073
  var useRequire = shouldUseRequire(sourceFile, program);
151988
152074
  var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
151989
- var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences));
152075
+ var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, program, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite, useRequire, host, preferences));
151990
152076
  return {
151991
152077
  moduleSpecifier: fix.moduleSpecifier,
151992
152078
  codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix,
@@ -152002,10 +152088,10 @@ var ts;
152002
152088
  return fix && codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, includeSymbolNameInDescription, 1 /* Double */, compilerOptions));
152003
152089
  }
152004
152090
  codefix.getPromoteTypeOnlyCompletionAction = getPromoteTypeOnlyCompletionAction;
152005
- function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
152091
+ function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, program, useNamespaceInfo, isValidTypeOnlyUseSite, useRequire, host, preferences) {
152006
152092
  ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
152007
152093
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
152008
- return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, packageJsonImportFilter, host);
152094
+ return getBestFix(getImportFixes(exportInfos, useNamespaceInfo, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences).fixes, sourceFile, program, packageJsonImportFilter, host);
152009
152095
  }
152010
152096
  function codeFixActionToCodeAction(_a) {
152011
152097
  var description = _a.description, changes = _a.changes, commands = _a.commands;
@@ -152060,25 +152146,32 @@ var ts;
152060
152146
  return !moduleFile || ts.isImportableFile(program, importingFile, moduleFile, preferences, /*packageJsonFilter*/ undefined, getModuleSpecifierResolutionHost(isFromPackageJson), (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host));
152061
152147
  }
152062
152148
  }
152063
- function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
152064
- var _a = getNewImportFixes(program, importingFile,
152065
- /*position*/ undefined,
152066
- /*isValidTypeOnlyUseSite*/ false,
152067
- /*useRequire*/ false, exportInfo, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
152149
+ function getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
152150
+ var _a = getImportFixes(exportInfo, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite,
152151
+ /*useRequire*/ false, program, importingFile, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
152068
152152
  var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter || ts.createPackageJsonImportFilter(importingFile, preferences, host), host);
152069
152153
  return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
152070
152154
  }
152071
152155
  codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
152072
- function getImportFixes(exportInfos, symbolName,
152156
+ function getImportFixes(exportInfos, useNamespaceInfo,
152073
152157
  /** undefined only for missing JSX namespace */
152074
- position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences) {
152158
+ isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, fromCacheOnly) {
152075
152159
  var checker = program.getTypeChecker();
152076
152160
  var existingImports = ts.flatMap(exportInfos, function (info) { return getExistingImportDeclarations(info, checker, sourceFile, program.getCompilerOptions()); });
152077
- var useNamespace = position === undefined ? undefined : tryUseExistingNamespaceImport(existingImports, symbolName, position, checker);
152161
+ var useNamespace = useNamespaceInfo && tryUseExistingNamespaceImport(existingImports, useNamespaceInfo.symbolName, useNamespaceInfo.position, checker);
152078
152162
  var addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
152079
- // Don't bother providing an action to add a new import if we can add to an existing one.
152080
- var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences);
152081
- return __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), addImport, true);
152163
+ if (addToExisting) {
152164
+ // Don't bother providing an action to add a new import if we can add to an existing one.
152165
+ return {
152166
+ computedWithoutCacheCount: 0,
152167
+ fixes: __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), [addToExisting], false),
152168
+ };
152169
+ }
152170
+ var _a = getFixesForAddImport(exportInfos, existingImports, program, sourceFile, useNamespaceInfo === null || useNamespaceInfo === void 0 ? void 0 : useNamespaceInfo.position, isValidTypeOnlyUseSite, useRequire, host, preferences, fromCacheOnly), fixes = _a.fixes, _b = _a.computedWithoutCacheCount, computedWithoutCacheCount = _b === void 0 ? 0 : _b;
152171
+ return {
152172
+ computedWithoutCacheCount: computedWithoutCacheCount,
152173
+ fixes: __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), fixes, true),
152174
+ };
152082
152175
  }
152083
152176
  function tryUseExistingNamespaceImport(existingImports, symbolName, position, checker) {
152084
152177
  // It is possible that multiple import statements with the same specifier exist in the file.
@@ -152268,9 +152361,9 @@ var ts;
152268
152361
  });
152269
152362
  return { computedWithoutCacheCount: computedWithoutCacheCount, fixes: fixes };
152270
152363
  }
152271
- function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
152364
+ function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences, fromCacheOnly) {
152272
152365
  var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info, isValidTypeOnlyUseSite, useRequire, program.getTypeChecker(), program.getCompilerOptions()); });
152273
- return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences).fixes;
152366
+ return existingDeclaration ? { fixes: [existingDeclaration] } : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences, fromCacheOnly);
152274
152367
  }
152275
152368
  function newImportInfoFromExistingSpecifier(_a, isValidTypeOnlyUseSite, useRequire, checker, compilerOptions) {
152276
152369
  var _b;
@@ -152366,7 +152459,8 @@ var ts;
152366
152459
  var symbolName = umdSymbol.name;
152367
152460
  var exportInfo = [{ symbol: umdSymbol, moduleSymbol: symbol, moduleFileName: undefined, exportKind: 3 /* UMD */, targetFlags: symbol.flags, isFromPackageJson: false }];
152368
152461
  var useRequire = shouldUseRequire(sourceFile, program);
152369
- var fixes = getImportFixes(exportInfo, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences);
152462
+ var position = ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined;
152463
+ var fixes = getImportFixes(exportInfo, position ? { position: position, symbolName: symbolName } : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences).fixes;
152370
152464
  return { fixes: fixes, symbolName: symbolName, errorIdentifierText: (_b = ts.tryCast(token, ts.isIdentifier)) === null || _b === void 0 ? void 0 : _b.text };
152371
152465
  }
152372
152466
  function getUmdSymbol(token, checker) {
@@ -152438,7 +152532,7 @@ var ts;
152438
152532
  var exportInfo = getExportInfos(symbolName, ts.isJSXTagName(symbolToken), ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
152439
152533
  var fixes = ts.arrayFrom(ts.flatMapIterator(exportInfo.entries(), function (_a) {
152440
152534
  var _ = _a[0], exportInfos = _a[1];
152441
- return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences);
152535
+ return getImportFixes(exportInfos, { symbolName: symbolName, position: symbolToken.getStart(sourceFile) }, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences).fixes;
152442
152536
  }));
152443
152537
  return { fixes: fixes, symbolName: symbolName, errorIdentifierText: symbolToken.text };
152444
152538
  }