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/typescript.js CHANGED
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220421";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220424";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -14896,7 +14896,7 @@ var ts;
14896
14896
  var _a;
14897
14897
  // If we don't need to downlevel and we can reach the original source text using
14898
14898
  // the node's parent reference, then simply get the text as it was originally written.
14899
- if (canUseOriginalText(node, flags)) {
14899
+ if (sourceFile && canUseOriginalText(node, flags)) {
14900
14900
  return getSourceTextOfNodeFromSourceFile(sourceFile, node);
14901
14901
  }
14902
14902
  // If we can't reach the original source text, use the canonical form if it's a number,
@@ -18487,10 +18487,10 @@ var ts;
18487
18487
  return ts.combinePaths(newDirPath, sourceFilePath);
18488
18488
  }
18489
18489
  ts.getSourceFilePathInNewDirWorker = getSourceFilePathInNewDirWorker;
18490
- function writeFile(host, diagnostics, fileName, data, writeByteOrderMark, sourceFiles) {
18491
- host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) {
18490
+ function writeFile(host, diagnostics, fileName, text, writeByteOrderMark, sourceFiles, data) {
18491
+ host.writeFile(fileName, text, writeByteOrderMark, function (hostErrorMessage) {
18492
18492
  diagnostics.add(createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage));
18493
- }, sourceFiles);
18493
+ }, sourceFiles, data);
18494
18494
  }
18495
18495
  ts.writeFile = writeFile;
18496
18496
  function ensureDirectoriesExist(directoryPath, createDirectory, directoryExists) {
@@ -73626,6 +73626,7 @@ var ts;
73626
73626
  }
73627
73627
  }
73628
73628
  else {
73629
+ error(attributeDecl.expression, ts.Diagnostics.Spread_types_may_only_be_created_from_object_types);
73629
73630
  typeToIntersect = typeToIntersect ? getIntersectionType([typeToIntersect, exprType]) : exprType;
73630
73631
  }
73631
73632
  }
@@ -75863,6 +75864,7 @@ var ts;
75863
75864
  // decorators are applied to a declaration by the emitter, and not to an expression.
75864
75865
  var isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters;
75865
75866
  var argCheckMode = !isDecorator && !isSingleNonGenericCandidate && ts.some(args, isContextSensitive) ? 4 /* SkipContextSensitive */ : 0 /* Normal */;
75867
+ argCheckMode |= checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
75866
75868
  // The following variables are captured and modified by calls to chooseOverload.
75867
75869
  // If overload resolution or type argument inference fails, we want to report the
75868
75870
  // best error possible. The best error is one which says that an argument was not
@@ -76078,7 +76080,7 @@ var ts;
76078
76080
  // If one or more context sensitive arguments were excluded, we start including
76079
76081
  // them now (and keeping do so for any subsequent candidates) and perform a second
76080
76082
  // round of type inference and applicability checking for this particular candidate.
76081
- argCheckMode = 0 /* Normal */;
76083
+ argCheckMode = checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
76082
76084
  if (inferenceContext) {
76083
76085
  var typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext);
76084
76086
  checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
@@ -110160,6 +110162,7 @@ var ts;
110160
110162
  else {
110161
110163
  printer.writeFile(sourceFile, writer, sourceMapGenerator);
110162
110164
  }
110165
+ var sourceMapUrlPos;
110163
110166
  if (sourceMapGenerator) {
110164
110167
  if (sourceMapDataList) {
110165
110168
  sourceMapDataList.push({
@@ -110171,6 +110174,7 @@ var ts;
110171
110174
  if (sourceMappingURL) {
110172
110175
  if (!writer.isAtStartOfLine())
110173
110176
  writer.rawWrite(newLine);
110177
+ sourceMapUrlPos = writer.getTextPos();
110174
110178
  writer.writeComment("//# " + "sourceMappingURL" + "=" + sourceMappingURL); // Tools can sometimes see this line as a source mapping url comment
110175
110179
  }
110176
110180
  // Write the source map
@@ -110183,7 +110187,7 @@ var ts;
110183
110187
  writer.writeLine();
110184
110188
  }
110185
110189
  // Write the output file
110186
- ts.writeFile(host, emitterDiagnostics, jsFilePath, writer.getText(), !!compilerOptions.emitBOM, sourceFiles);
110190
+ ts.writeFile(host, emitterDiagnostics, jsFilePath, writer.getText(), !!compilerOptions.emitBOM, sourceFiles, { sourceMapUrlPos: sourceMapUrlPos });
110187
110191
  // Reset state
110188
110192
  writer.clear();
110189
110193
  }
@@ -110705,7 +110709,7 @@ var ts;
110705
110709
  setWriter(/*output*/ undefined, /*_sourceMapGenerator*/ undefined);
110706
110710
  }
110707
110711
  function getCurrentLineMap() {
110708
- return currentLineMap || (currentLineMap = ts.getLineStarts(currentSourceFile));
110712
+ return currentLineMap || (currentLineMap = ts.getLineStarts(ts.Debug.checkDefined(currentSourceFile)));
110709
110713
  }
110710
110714
  function emit(node, parenthesizerRule) {
110711
110715
  if (node === undefined)
@@ -111880,7 +111884,7 @@ var ts;
111880
111884
  increaseIndent();
111881
111885
  }
111882
111886
  var preferNewLine = node.multiLine ? 65536 /* PreferNewLine */ : 0 /* None */;
111883
- var allowTrailingComma = currentSourceFile.languageVersion >= 1 /* ES5 */ && !ts.isJsonSourceFile(currentSourceFile) ? 64 /* AllowTrailingComma */ : 0 /* None */;
111887
+ var allowTrailingComma = currentSourceFile && currentSourceFile.languageVersion >= 1 /* ES5 */ && !ts.isJsonSourceFile(currentSourceFile) ? 64 /* AllowTrailingComma */ : 0 /* None */;
111884
111888
  emitList(node, node.properties, 526226 /* ObjectLiteralExpressionProperties */ | allowTrailingComma | preferNewLine);
111885
111889
  if (indentedFlag) {
111886
111890
  decreaseIndent();
@@ -112236,7 +112240,7 @@ var ts;
112236
112240
  emitExpression(node.expression, parenthesizer.parenthesizeExpressionOfExpressionStatement);
112237
112241
  // Emit semicolon in non json files
112238
112242
  // or if json file that created synthesized expression(eg.define expression statement when --out and amd code generation)
112239
- if (!ts.isJsonSourceFile(currentSourceFile) || ts.nodeIsSynthesized(node.expression)) {
112243
+ if (!currentSourceFile || !ts.isJsonSourceFile(currentSourceFile) || ts.nodeIsSynthesized(node.expression)) {
112240
112244
  writeTrailingSemicolon();
112241
112245
  }
112242
112246
  }
@@ -112529,7 +112533,7 @@ var ts;
112529
112533
  if (body.multiLine) {
112530
112534
  return false;
112531
112535
  }
112532
- if (!ts.nodeIsSynthesized(body) && !ts.rangeIsOnSingleLine(body, currentSourceFile)) {
112536
+ if (!ts.nodeIsSynthesized(body) && currentSourceFile && !ts.rangeIsOnSingleLine(body, currentSourceFile)) {
112533
112537
  return false;
112534
112538
  }
112535
112539
  if (getLeadingLineTerminatorCount(body, body.statements, 2 /* PreserveLines */)
@@ -112554,12 +112558,7 @@ var ts;
112554
112558
  var emitBlockFunctionBody = shouldEmitBlockFunctionBodyOnSingleLine(body)
112555
112559
  ? emitBlockFunctionBodyOnSingleLine
112556
112560
  : emitBlockFunctionBodyWorker;
112557
- if (emitBodyWithDetachedComments) {
112558
- emitBodyWithDetachedComments(body, body.statements, emitBlockFunctionBody);
112559
- }
112560
- else {
112561
- emitBlockFunctionBody(body);
112562
- }
112561
+ emitBodyWithDetachedComments(body, body.statements, emitBlockFunctionBody);
112563
112562
  decreaseIndent();
112564
112563
  writeToken(19 /* CloseBraceToken */, body.statements.end, writePunctuation, body);
112565
112564
  onAfterEmitNode === null || onAfterEmitNode === void 0 ? void 0 : onAfterEmitNode(body);
@@ -112956,7 +112955,8 @@ var ts;
112956
112955
  var emitAsSingleStatement = statements.length === 1 &&
112957
112956
  (
112958
112957
  // treat synthesized nodes as located on the same line for emit purposes
112959
- ts.nodeIsSynthesized(parentNode) ||
112958
+ !currentSourceFile ||
112959
+ ts.nodeIsSynthesized(parentNode) ||
112960
112960
  ts.nodeIsSynthesized(statements[0]) ||
112961
112961
  ts.rangeStartPositionsAreOnSameLine(parentNode, statements[0], currentSourceFile));
112962
112962
  var format = 163969 /* CaseOrDefaultClauseStatements */;
@@ -113187,16 +113187,14 @@ var ts;
113187
113187
  function emitSourceFile(node) {
113188
113188
  writeLine();
113189
113189
  var statements = node.statements;
113190
- if (emitBodyWithDetachedComments) {
113191
- // Emit detached comment if there are no prologue directives or if the first node is synthesized.
113192
- // The synthesized node will have no leading comment so some comments may be missed.
113193
- var shouldEmitDetachedComment = statements.length === 0 ||
113194
- !ts.isPrologueDirective(statements[0]) ||
113195
- ts.nodeIsSynthesized(statements[0]);
113196
- if (shouldEmitDetachedComment) {
113197
- emitBodyWithDetachedComments(node, statements, emitSourceFileWorker);
113198
- return;
113199
- }
113190
+ // Emit detached comment if there are no prologue directives or if the first node is synthesized.
113191
+ // The synthesized node will have no leading comment so some comments may be missed.
113192
+ var shouldEmitDetachedComment = statements.length === 0 ||
113193
+ !ts.isPrologueDirective(statements[0]) ||
113194
+ ts.nodeIsSynthesized(statements[0]);
113195
+ if (shouldEmitDetachedComment) {
113196
+ emitBodyWithDetachedComments(node, statements, emitSourceFileWorker);
113197
+ return;
113200
113198
  }
113201
113199
  emitSourceFileWorker(node);
113202
113200
  }
@@ -113585,7 +113583,7 @@ var ts;
113585
113583
  }
113586
113584
  if (isEmpty) {
113587
113585
  // Write a line terminator if the parent node was multi-line
113588
- if (format & 1 /* MultiLine */ && !(preserveSourceNewlines && (!parentNode || ts.rangeIsOnSingleLine(parentNode, currentSourceFile)))) {
113586
+ if (format & 1 /* MultiLine */ && !(preserveSourceNewlines && (!parentNode || currentSourceFile && ts.rangeIsOnSingleLine(parentNode, currentSourceFile)))) {
113589
113587
  writeLine();
113590
113588
  }
113591
113589
  else if (format & 256 /* SpaceBetweenBraces */ && !(format & 524288 /* NoSpaceIfEmpty */)) {
@@ -113846,7 +113844,7 @@ var ts;
113846
113844
  }
113847
113845
  var firstChild_1 = children[0];
113848
113846
  if (firstChild_1 === undefined) {
113849
- return !parentNode || ts.rangeIsOnSingleLine(parentNode, currentSourceFile) ? 0 : 1;
113847
+ return !parentNode || currentSourceFile && ts.rangeIsOnSingleLine(parentNode, currentSourceFile) ? 0 : 1;
113850
113848
  }
113851
113849
  if (firstChild_1.pos === nextListElementPos) {
113852
113850
  // If this child starts at the beginning of a list item in a parent list, its leading
@@ -113870,7 +113868,7 @@ var ts;
113870
113868
  // JsxText will be written with its leading whitespace, so don't add more manually.
113871
113869
  return 0;
113872
113870
  }
113873
- if (parentNode &&
113871
+ if (currentSourceFile && parentNode &&
113874
113872
  !ts.positionIsSynthesized(parentNode.pos) &&
113875
113873
  !ts.nodeIsSynthesized(firstChild_1) &&
113876
113874
  (!firstChild_1.parent || ts.getOriginalNode(firstChild_1.parent) === ts.getOriginalNode(parentNode))) {
@@ -113894,7 +113892,7 @@ var ts;
113894
113892
  // JsxText will be written with its leading whitespace, so don't add more manually.
113895
113893
  return 0;
113896
113894
  }
113897
- else if (!ts.nodeIsSynthesized(previousNode) && !ts.nodeIsSynthesized(nextNode)) {
113895
+ else if (currentSourceFile && !ts.nodeIsSynthesized(previousNode) && !ts.nodeIsSynthesized(nextNode)) {
113898
113896
  if (preserveSourceNewlines && siblingNodePositionsAreComparable(previousNode, nextNode)) {
113899
113897
  return getEffectiveLines(function (includeComments) { return ts.getLinesBetweenRangeEndAndRangeStart(previousNode, nextNode, currentSourceFile, includeComments); });
113900
113898
  }
@@ -113926,9 +113924,9 @@ var ts;
113926
113924
  }
113927
113925
  var lastChild = ts.lastOrUndefined(children);
113928
113926
  if (lastChild === undefined) {
113929
- return !parentNode || ts.rangeIsOnSingleLine(parentNode, currentSourceFile) ? 0 : 1;
113927
+ return !parentNode || currentSourceFile && ts.rangeIsOnSingleLine(parentNode, currentSourceFile) ? 0 : 1;
113930
113928
  }
113931
- if (parentNode && !ts.positionIsSynthesized(parentNode.pos) && !ts.nodeIsSynthesized(lastChild) && (!lastChild.parent || lastChild.parent === parentNode)) {
113929
+ if (currentSourceFile && parentNode && !ts.positionIsSynthesized(parentNode.pos) && !ts.nodeIsSynthesized(lastChild) && (!lastChild.parent || lastChild.parent === parentNode)) {
113932
113930
  if (preserveSourceNewlines) {
113933
113931
  var end_1 = ts.isNodeArray(children) && !ts.positionIsSynthesized(children.end) ? children.end : lastChild.end;
113934
113932
  return getEffectiveLines(function (includeComments) { return ts.getLinesBetweenPositionAndNextNonWhitespaceCharacter(end_1, parentNode.end, currentSourceFile, includeComments); });
@@ -114001,7 +113999,7 @@ var ts;
114001
113999
  if (ts.getStartsOnNewLine(node2)) {
114002
114000
  return 1;
114003
114001
  }
114004
- if (!ts.nodeIsSynthesized(parent) && !ts.nodeIsSynthesized(node1) && !ts.nodeIsSynthesized(node2)) {
114002
+ if (currentSourceFile && !ts.nodeIsSynthesized(parent) && !ts.nodeIsSynthesized(node1) && !ts.nodeIsSynthesized(node2)) {
114005
114003
  if (preserveSourceNewlines) {
114006
114004
  return getEffectiveLines(function (includeComments) { return ts.getLinesBetweenRangeEndAndRangeStart(node1, node2, currentSourceFile, includeComments); });
114007
114005
  }
@@ -114011,7 +114009,7 @@ var ts;
114011
114009
  }
114012
114010
  function isEmptyBlock(block) {
114013
114011
  return block.statements.length === 0
114014
- && ts.rangeEndIsOnSameLineAsRangeStart(block, block, currentSourceFile);
114012
+ && (!currentSourceFile || ts.rangeEndIsOnSameLineAsRangeStart(block, block, currentSourceFile));
114015
114013
  }
114016
114014
  function skipSynthesizedParentheses(node) {
114017
114015
  while (node.kind === 212 /* ParenthesizedExpression */ && ts.nodeIsSynthesized(node)) {
@@ -114023,16 +114021,23 @@ var ts;
114023
114021
  if (ts.isGeneratedIdentifier(node)) {
114024
114022
  return generateName(node);
114025
114023
  }
114026
- else if ((ts.isIdentifier(node) || ts.isPrivateIdentifier(node)) && (ts.nodeIsSynthesized(node) || !node.parent || !currentSourceFile || (node.parent && currentSourceFile && ts.getSourceFileOfNode(node) !== ts.getOriginalNode(currentSourceFile)))) {
114027
- return ts.idText(node);
114028
- }
114029
- else if (node.kind === 10 /* StringLiteral */ && node.textSourceNode) {
114024
+ if (ts.isStringLiteral(node) && node.textSourceNode) {
114030
114025
  return getTextOfNode(node.textSourceNode, includeTrivia);
114031
114026
  }
114032
- else if (ts.isLiteralExpression(node) && (ts.nodeIsSynthesized(node) || !node.parent)) {
114033
- return node.text;
114027
+ var sourceFile = currentSourceFile; // const needed for control flow
114028
+ var canUseSourceFile = !!sourceFile && !!node.parent && !ts.nodeIsSynthesized(node);
114029
+ if (ts.isMemberName(node)) {
114030
+ if (!canUseSourceFile || ts.getSourceFileOfNode(node) !== ts.getOriginalNode(sourceFile)) {
114031
+ return ts.idText(node);
114032
+ }
114034
114033
  }
114035
- return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node, includeTrivia);
114034
+ else {
114035
+ ts.Debug.assertNode(node, ts.isLiteralExpression); // not strictly necessary
114036
+ if (!canUseSourceFile) {
114037
+ return node.text;
114038
+ }
114039
+ }
114040
+ return ts.getSourceTextOfNodeFromSourceFile(sourceFile, node, includeTrivia);
114036
114041
  }
114037
114042
  function getLiteralTextOfNode(node, neverAsciiEscape, jsxAttributeEscape) {
114038
114043
  if (node.kind === 10 /* StringLiteral */ && node.textSourceNode) {
@@ -114611,7 +114616,7 @@ var ts;
114611
114616
  return true;
114612
114617
  }
114613
114618
  function emitLeadingComment(commentPos, commentEnd, kind, hasTrailingNewLine, rangePos) {
114614
- if (!shouldWriteComment(currentSourceFile.text, commentPos))
114619
+ if (!currentSourceFile || !shouldWriteComment(currentSourceFile.text, commentPos))
114615
114620
  return;
114616
114621
  if (!hasWrittenComment) {
114617
114622
  ts.emitNewLineBeforeLeadingCommentOfPosition(getCurrentLineMap(), writer, rangePos, commentPos);
@@ -114638,7 +114643,7 @@ var ts;
114638
114643
  forEachTrailingCommentToEmit(pos, emitTrailingComment);
114639
114644
  }
114640
114645
  function emitTrailingComment(commentPos, commentEnd, _kind, hasTrailingNewLine) {
114641
- if (!shouldWriteComment(currentSourceFile.text, commentPos))
114646
+ if (!currentSourceFile || !shouldWriteComment(currentSourceFile.text, commentPos))
114642
114647
  return;
114643
114648
  // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment2*/
114644
114649
  if (!writer.isAtStartOfLine()) {
@@ -114660,6 +114665,8 @@ var ts;
114660
114665
  exitComment();
114661
114666
  }
114662
114667
  function emitTrailingCommentOfPositionNoNewline(commentPos, commentEnd, kind) {
114668
+ if (!currentSourceFile)
114669
+ return;
114663
114670
  // trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
114664
114671
  emitPos(commentPos);
114665
114672
  ts.writeCommentRange(currentSourceFile.text, getCurrentLineMap(), writer, commentPos, commentEnd, newLine);
@@ -114669,6 +114676,8 @@ var ts;
114669
114676
  }
114670
114677
  }
114671
114678
  function emitTrailingCommentOfPosition(commentPos, commentEnd, _kind, hasTrailingNewLine) {
114679
+ if (!currentSourceFile)
114680
+ return;
114672
114681
  // trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
114673
114682
  emitPos(commentPos);
114674
114683
  ts.writeCommentRange(currentSourceFile.text, getCurrentLineMap(), writer, commentPos, commentEnd, newLine);
@@ -114701,6 +114710,8 @@ var ts;
114701
114710
  return detachedCommentsInfo !== undefined && ts.last(detachedCommentsInfo).nodePos === pos;
114702
114711
  }
114703
114712
  function forEachLeadingCommentWithoutDetachedComments(cb) {
114713
+ if (!currentSourceFile)
114714
+ return;
114704
114715
  // get the leading comments from detachedPos
114705
114716
  var pos = ts.last(detachedCommentsInfo).detachedCommentEndPos;
114706
114717
  if (detachedCommentsInfo.length - 1) {
@@ -114712,7 +114723,7 @@ var ts;
114712
114723
  ts.forEachLeadingCommentRange(currentSourceFile.text, pos, cb, /*state*/ pos);
114713
114724
  }
114714
114725
  function emitDetachedCommentsAndUpdateCommentsInfo(range) {
114715
- var currentDetachedCommentInfo = ts.emitDetachedComments(currentSourceFile.text, getCurrentLineMap(), writer, emitComment, range, newLine, commentsDisabled);
114726
+ var currentDetachedCommentInfo = currentSourceFile && ts.emitDetachedComments(currentSourceFile.text, getCurrentLineMap(), writer, emitComment, range, newLine, commentsDisabled);
114716
114727
  if (currentDetachedCommentInfo) {
114717
114728
  if (detachedCommentsInfo) {
114718
114729
  detachedCommentsInfo.push(currentDetachedCommentInfo);
@@ -114723,7 +114734,7 @@ var ts;
114723
114734
  }
114724
114735
  }
114725
114736
  function emitComment(text, lineMap, writer, commentPos, commentEnd, newLine) {
114726
- if (!shouldWriteComment(currentSourceFile.text, commentPos))
114737
+ if (!currentSourceFile || !shouldWriteComment(currentSourceFile.text, commentPos))
114727
114738
  return;
114728
114739
  emitPos(commentPos);
114729
114740
  ts.writeCommentRange(text, lineMap, writer, commentPos, commentEnd, newLine);
@@ -114735,7 +114746,7 @@ var ts;
114735
114746
  * @return true if the comment is a triple-slash comment else false
114736
114747
  */
114737
114748
  function isTripleSlashComment(commentPos, commentEnd) {
114738
- return ts.isRecognizedTripleSlashComment(currentSourceFile.text, commentPos, commentEnd);
114749
+ return !!currentSourceFile && ts.isRecognizedTripleSlashComment(currentSourceFile.text, commentPos, commentEnd);
114739
114750
  }
114740
114751
  // Source Maps
114741
114752
  function getParsedSourceMap(node) {
@@ -115650,7 +115661,11 @@ var ts;
115650
115661
  return newValue;
115651
115662
  };
115652
115663
  if (originalWriteFile) {
115653
- host.writeFile = function (fileName, data, writeByteOrderMark, onError, sourceFiles) {
115664
+ host.writeFile = function (fileName, data) {
115665
+ var rest = [];
115666
+ for (var _i = 2; _i < arguments.length; _i++) {
115667
+ rest[_i - 2] = arguments[_i];
115668
+ }
115654
115669
  var key = toPath(fileName);
115655
115670
  fileExistsCache.delete(key);
115656
115671
  var value = readFileCache.get(key);
@@ -115664,7 +115679,7 @@ var ts;
115664
115679
  sourceFileCache.delete(key);
115665
115680
  }
115666
115681
  }
115667
- originalWriteFile.call(host, fileName, data, writeByteOrderMark, onError, sourceFiles);
115682
+ originalWriteFile.call.apply(originalWriteFile, __spreadArray([host, fileName, data], rest, false));
115668
115683
  };
115669
115684
  }
115670
115685
  // directoryExists
@@ -116597,6 +116612,7 @@ var ts;
116597
116612
  useCaseSensitiveFileNames: function () { return host.useCaseSensitiveFileNames(); },
116598
116613
  getFileIncludeReasons: function () { return fileReasons; },
116599
116614
  structureIsReused: structureIsReused,
116615
+ writeFile: writeFile,
116600
116616
  };
116601
116617
  onProgramCreateComplete();
116602
116618
  // Add file processingDiagnostics
@@ -117094,7 +117110,7 @@ var ts;
117094
117110
  getProjectReferenceRedirect: getProjectReferenceRedirect,
117095
117111
  isSourceOfProjectReferenceRedirect: isSourceOfProjectReferenceRedirect,
117096
117112
  getSymlinkCache: getSymlinkCache,
117097
- writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError, sourceFiles) { return host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); }),
117113
+ writeFile: writeFileCallback || writeFile,
117098
117114
  isEmitBlocked: isEmitBlocked,
117099
117115
  readFile: function (f) { return host.readFile(f); },
117100
117116
  fileExists: function (f) {
@@ -117114,6 +117130,9 @@ var ts;
117114
117130
  getFileIncludeReasons: program.getFileIncludeReasons,
117115
117131
  };
117116
117132
  }
117133
+ function writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data) {
117134
+ host.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
117135
+ }
117117
117136
  function emitBuildInfo(writeFileCallback) {
117118
117137
  ts.Debug.assert(!ts.outFile(options));
117119
117138
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("emit" /* Emit */, "emitBuildInfo", {}, /*separateBeginAndEnd*/ true);
@@ -119556,6 +119575,7 @@ var ts;
119556
119575
  }
119557
119576
  }
119558
119577
  }
119578
+ BuilderState.updateExportedModules = updateExportedModules;
119559
119579
  /**
119560
119580
  * Updates the exported modules from cache into state's exported modules map
119561
119581
  * This should be called whenever it is safe to commit the state of the builder
@@ -120520,7 +120540,43 @@ var ts;
120520
120540
  return toAffectedFileEmitResult(state,
120521
120541
  // When whole program is affected, do emit only once (eg when --out or --outFile is specified)
120522
120542
  // Otherwise just affected file
120523
- 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);
120543
+ ts.Debug.checkDefined(state.program).emit(affected === state.program ? undefined : affected, affected !== state.program && ts.getEmitDeclarations(state.compilerOptions) && !customTransformers ?
120544
+ getWriteFileUpdatingSignatureCallback(writeFile) :
120545
+ writeFile || ts.maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles || emitKind === 0 /* DtsOnly */, customTransformers), affected, emitKind, isPendingEmitFile);
120546
+ }
120547
+ function getWriteFileUpdatingSignatureCallback(writeFile) {
120548
+ return function (fileName, text, writeByteOrderMark, onError, sourceFiles, data) {
120549
+ var _a;
120550
+ if (ts.isDeclarationFileName(fileName)) {
120551
+ ts.Debug.assert((sourceFiles === null || sourceFiles === void 0 ? void 0 : sourceFiles.length) === 1);
120552
+ var file = sourceFiles[0];
120553
+ var info = state.fileInfos.get(file.resolvedPath);
120554
+ var signature = ((_a = state.currentAffectedFilesSignatures) === null || _a === void 0 ? void 0 : _a.get(file.resolvedPath)) || info.signature;
120555
+ if (signature === file.version) {
120556
+ var newSignature = (computeHash || ts.generateDjb2Hash)((data === null || data === void 0 ? void 0 : data.sourceMapUrlPos) !== undefined ? text.substring(0, data.sourceMapUrlPos) : text);
120557
+ if (newSignature !== file.version) { // Update it
120558
+ if (host.storeFilesChangingSignatureDuringEmit)
120559
+ (state.filesChangingSignature || (state.filesChangingSignature = new ts.Set())).add(file.resolvedPath);
120560
+ if (state.exportedModulesMap)
120561
+ ts.BuilderState.updateExportedModules(file, file.exportedModulesFromDeclarationEmit, state.currentAffectedFilesExportedModulesMap || (state.currentAffectedFilesExportedModulesMap = ts.BuilderState.createManyToManyPathMap()));
120562
+ if (state.affectedFiles && state.affectedFilesIndex < state.affectedFiles.length) {
120563
+ state.currentAffectedFilesSignatures.set(file.resolvedPath, newSignature);
120564
+ }
120565
+ else {
120566
+ info.signature = newSignature;
120567
+ if (state.exportedModulesMap)
120568
+ ts.BuilderState.updateExportedFilesMapFromCache(state, state.currentAffectedFilesExportedModulesMap);
120569
+ }
120570
+ }
120571
+ }
120572
+ }
120573
+ if (writeFile)
120574
+ writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
120575
+ else if (host.writeFile)
120576
+ host.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
120577
+ else
120578
+ state.program.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
120579
+ };
120524
120580
  }
120525
120581
  /**
120526
120582
  * Emits the JavaScript and declaration files.
@@ -120577,7 +120633,9 @@ var ts;
120577
120633
  }
120578
120634
  }
120579
120635
  }
120580
- return ts.Debug.checkDefined(state.program).emit(targetSourceFile, writeFile || ts.maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
120636
+ return ts.Debug.checkDefined(state.program).emit(targetSourceFile, !ts.outFile(state.compilerOptions) && ts.getEmitDeclarations(state.compilerOptions) && !customTransformers ?
120637
+ getWriteFileUpdatingSignatureCallback(writeFile) :
120638
+ writeFile || ts.maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
120581
120639
  }
120582
120640
  /**
120583
120641
  * Return the semantic diagnostics for the next affected file or undefined if iteration is complete
@@ -122769,6 +122827,7 @@ var ts;
122769
122827
  createHash: ts.maybeBind(host, host.createHash),
122770
122828
  readDirectory: ts.maybeBind(host, host.readDirectory),
122771
122829
  disableUseFileVersionAsSignature: host.disableUseFileVersionAsSignature,
122830
+ storeFilesChangingSignatureDuringEmit: host.storeFilesChangingSignatureDuringEmit,
122772
122831
  };
122773
122832
  function writeFile(fileName, text, writeByteOrderMark, onError) {
122774
122833
  try {
@@ -122828,6 +122887,7 @@ var ts;
122828
122887
  createHash: ts.maybeBind(system, system.createHash),
122829
122888
  createProgram: createProgram || ts.createEmitAndSemanticDiagnosticsBuilderProgram,
122830
122889
  disableUseFileVersionAsSignature: system.disableUseFileVersionAsSignature,
122890
+ storeFilesChangingSignatureDuringEmit: system.storeFilesChangingSignatureDuringEmit,
122831
122891
  };
122832
122892
  }
122833
122893
  ts.createProgramHost = createProgramHost;
@@ -122916,6 +122976,7 @@ var ts;
122916
122976
  var host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, system);
122917
122977
  host.createHash = ts.maybeBind(system, system.createHash);
122918
122978
  host.disableUseFileVersionAsSignature = system.disableUseFileVersionAsSignature;
122979
+ host.storeFilesChangingSignatureDuringEmit = system.storeFilesChangingSignatureDuringEmit;
122919
122980
  ts.setGetSourceFileAsHashVersioned(host, system);
122920
122981
  ts.changeCompilerHostLikeToUseCache(host, function (fileName) { return ts.toPath(fileName, host.getCurrentDirectory(), host.getCanonicalFileName); });
122921
122982
  return host;
@@ -131665,7 +131726,7 @@ var ts;
131665
131726
  GlobalsSearch[GlobalsSearch["Success"] = 1] = "Success";
131666
131727
  GlobalsSearch[GlobalsSearch["Fail"] = 2] = "Fail";
131667
131728
  })(GlobalsSearch || (GlobalsSearch = {}));
131668
- function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, preferences, isForImportStatementCompletion, cb) {
131729
+ function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, position, preferences, isForImportStatementCompletion, isValidTypeOnlyUseSite, cb) {
131669
131730
  var _a, _b, _c;
131670
131731
  var start = ts.timestamp();
131671
131732
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
@@ -131680,9 +131741,9 @@ var ts;
131680
131741
  (_b = host.log) === null || _b === void 0 ? void 0 : _b.call(host, logPrefix + ": response is " + (resolutionLimitExceeded ? "incomplete" : "complete"));
131681
131742
  (_c = host.log) === null || _c === void 0 ? void 0 : _c.call(host, logPrefix + ": " + (ts.timestamp() - start));
131682
131743
  return result;
131683
- function tryResolve(exportInfo, isFromAmbientModule) {
131744
+ function tryResolve(exportInfo, symbolName, isFromAmbientModule) {
131684
131745
  if (isFromAmbientModule) {
131685
- var result_1 = ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, sourceFile, program, host, preferences);
131746
+ var result_1 = ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences);
131686
131747
  if (result_1) {
131687
131748
  ambientCount++;
131688
131749
  }
@@ -131691,7 +131752,7 @@ var ts;
131691
131752
  var shouldResolveModuleSpecifier = isForImportStatementCompletion || preferences.allowIncompleteCompletions && resolvedCount < Completions.moduleSpecifierResolutionLimit;
131692
131753
  var shouldGetModuleSpecifierFromCache = !shouldResolveModuleSpecifier && preferences.allowIncompleteCompletions && cacheAttemptCount < Completions.moduleSpecifierResolutionCacheAttemptLimit;
131693
131754
  var result = (shouldResolveModuleSpecifier || shouldGetModuleSpecifierFromCache)
131694
- ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
131755
+ ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
131695
131756
  : undefined;
131696
131757
  if (!shouldResolveModuleSpecifier && !shouldGetModuleSpecifierFromCache || shouldGetModuleSpecifierFromCache && !result) {
131697
131758
  resolutionLimitExceeded = true;
@@ -131796,8 +131857,8 @@ var ts;
131796
131857
  return undefined;
131797
131858
  var lowerCaseTokenText = location.text.toLowerCase();
131798
131859
  var exportMap = ts.getExportInfoMap(file, host, program, cancellationToken);
131799
- var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, program, file, preferences,
131800
- /*isForImportStatementCompletion*/ false, function (context) {
131860
+ var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, program, file, location.getStart(), preferences,
131861
+ /*isForImportStatementCompletion*/ false, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
131801
131862
  var entries = ts.mapDefined(previousResponse.entries, function (entry) {
131802
131863
  if (!entry.hasAction || !entry.source || !entry.data || completionEntryDataIsResolved(entry.data)) {
131803
131864
  // Not an auto import or already resolved; keep as is
@@ -131809,7 +131870,7 @@ var ts;
131809
131870
  }
131810
131871
  var origin = ts.Debug.checkDefined(getAutoImportSymbolFromCompletionEntryData(entry.name, entry.data, program, host)).origin;
131811
131872
  var info = exportMap.get(file.path, entry.data.exportMapKey);
131812
- var result = info && context.tryResolve(info, !ts.isExternalModuleNameRelative(ts.stripQuotes(origin.moduleSymbol.name)));
131873
+ var result = info && context.tryResolve(info, entry.name, !ts.isExternalModuleNameRelative(ts.stripQuotes(origin.moduleSymbol.name)));
131813
131874
  if (!result)
131814
131875
  return entry;
131815
131876
  var newOrigin = __assign(__assign({}, origin), { kind: 32 /* ResolvedExport */, moduleSpecifier: result.moduleSpecifier });
@@ -132401,22 +132462,44 @@ var ts;
132401
132462
  }
132402
132463
  }
132403
132464
  function createSnippetPrinter(printerOptions) {
132465
+ var escapes;
132404
132466
  var baseWriter = ts.textChanges.createWriter(ts.getNewLineCharacter(printerOptions));
132405
132467
  var printer = ts.createPrinter(printerOptions, baseWriter);
132406
- 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)); } });
132468
+ 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); }); } });
132407
132469
  return {
132408
132470
  printSnippetList: printSnippetList,
132409
132471
  printAndFormatSnippetList: printAndFormatSnippetList,
132410
132472
  };
132473
+ // The formatter/scanner will have issues with snippet-escaped text,
132474
+ // so instead of writing the escaped text directly to the writer,
132475
+ // generate a set of changes that can be applied to the unescaped text
132476
+ // to escape it post-formatting.
132477
+ function escapingWrite(s, write) {
132478
+ var escaped = ts.escapeSnippetText(s);
132479
+ if (escaped !== s) {
132480
+ var start = baseWriter.getTextPos();
132481
+ write();
132482
+ var end = baseWriter.getTextPos();
132483
+ escapes = ts.append(escapes || (escapes = []), { newText: escaped, span: { start: start, length: end - start } });
132484
+ }
132485
+ else {
132486
+ write();
132487
+ }
132488
+ }
132411
132489
  /* Snippet-escaping version of `printer.printList`. */
132412
132490
  function printSnippetList(format, list, sourceFile) {
132491
+ var unescaped = printUnescapedSnippetList(format, list, sourceFile);
132492
+ return escapes ? ts.textChanges.applyChanges(unescaped, escapes) : unescaped;
132493
+ }
132494
+ function printUnescapedSnippetList(format, list, sourceFile) {
132495
+ escapes = undefined;
132413
132496
  writer.clear();
132414
132497
  printer.writeList(format, list, sourceFile, writer);
132415
132498
  return writer.getText();
132416
132499
  }
132417
132500
  function printAndFormatSnippetList(format, list, sourceFile, formatContext) {
132418
132501
  var syntheticFile = {
132419
- text: printSnippetList(format, list, sourceFile),
132502
+ text: printUnescapedSnippetList(format, list, sourceFile),
132420
132503
  getLineAndCharacterOfPosition: function (pos) {
132421
132504
  return ts.getLineAndCharacterOfPosition(this, pos);
132422
132505
  },
@@ -132428,7 +132511,10 @@ var ts;
132428
132511
  /* indentation */ 0,
132429
132512
  /* delta */ 0, __assign(__assign({}, formatContext), { options: formatOptions }));
132430
132513
  });
132431
- return ts.textChanges.applyChanges(syntheticFile.text, changes);
132514
+ var allChanges = escapes
132515
+ ? ts.stableSort(ts.concatenate(changes, escapes), function (a, b) { return ts.compareTextSpans(a.span, b.span); })
132516
+ : changes;
132517
+ return ts.textChanges.applyChanges(syntheticFile.text, allChanges);
132432
132518
  }
132433
132519
  }
132434
132520
  function originToCompletionEntryData(origin) {
@@ -133320,7 +133406,7 @@ var ts;
133320
133406
  moduleSymbol: moduleSymbol,
133321
133407
  symbol: firstAccessibleSymbol,
133322
133408
  targetFlags: ts.skipAlias(firstAccessibleSymbol, typeChecker).flags,
133323
- }], sourceFile, program, host, preferences) || {}).moduleSpecifier;
133409
+ }], firstAccessibleSymbol.name, position, ts.isValidTypeOnlyAliasUseSite(location), sourceFile, program, host, preferences) || {}).moduleSpecifier;
133324
133410
  if (moduleSpecifier) {
133325
133411
  var origin = {
133326
133412
  kind: getNullableSymbolOriginInfoKind(6 /* SymbolMemberExport */),
@@ -133575,7 +133661,7 @@ var ts;
133575
133661
  var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
133576
133662
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
133577
133663
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
133578
- resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, preferences, !!importCompletionNode, function (context) {
133664
+ resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
133579
133665
  exportInfo.search(sourceFile.path,
133580
133666
  /*preferCapitalized*/ isRightOfOpenTag, function (symbolName, targetFlags) {
133581
133667
  if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
@@ -133603,7 +133689,7 @@ var ts;
133603
133689
  }
133604
133690
  // If we don't need to resolve module specifiers, we can use any re-export that is importable at all
133605
133691
  // (We need to ensure that at least one is importable to show a completion.)
133606
- var _a = context.tryResolve(info, isFromAmbientModule) || {}, _b = _a.exportInfo, exportInfo = _b === void 0 ? defaultExportInfo : _b, moduleSpecifier = _a.moduleSpecifier;
133692
+ var _a = context.tryResolve(info, symbolName, isFromAmbientModule) || {}, _b = _a.exportInfo, exportInfo = _b === void 0 ? defaultExportInfo : _b, moduleSpecifier = _a.moduleSpecifier;
133607
133693
  var isDefaultExport = exportInfo.exportKind === 1 /* Default */;
133608
133694
  var symbol = isDefaultExport && ts.getLocalSymbolForExportDefault(exportInfo.symbol) || exportInfo.symbol;
133609
133695
  pushAutoImportSymbol(symbol, {
@@ -152427,7 +152513,7 @@ var ts;
152427
152513
  var symbol = checker.getMergedSymbol(ts.skipAlias(exportedSymbol, checker));
152428
152514
  var exportInfo = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, /*isJsxTagName*/ false, host, program, preferences, useAutoImportProvider);
152429
152515
  var useRequire = shouldUseRequire(sourceFile, program);
152430
- var fix = getImportFixForSymbol(sourceFile, exportInfo, moduleSymbol, symbolName, program, /*position*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
152516
+ var fix = getImportFixForSymbol(sourceFile, exportInfo, moduleSymbol, program, /*useNamespaceInfo*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
152431
152517
  if (fix) {
152432
152518
  addImport({ fixes: [fix], symbolName: symbolName, errorIdentifierText: undefined });
152433
152519
  }
@@ -152597,7 +152683,7 @@ var ts;
152597
152683
  : getAllReExportingModules(sourceFile, targetSymbol, moduleSymbol, symbolName, isJsxTagName, host, program, preferences, /*useAutoImportProvider*/ true);
152598
152684
  var useRequire = shouldUseRequire(sourceFile, program);
152599
152685
  var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
152600
- var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences));
152686
+ var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, program, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite, useRequire, host, preferences));
152601
152687
  return {
152602
152688
  moduleSpecifier: fix.moduleSpecifier,
152603
152689
  codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix,
@@ -152613,10 +152699,10 @@ var ts;
152613
152699
  return fix && codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, includeSymbolNameInDescription, 1 /* Double */, compilerOptions));
152614
152700
  }
152615
152701
  codefix.getPromoteTypeOnlyCompletionAction = getPromoteTypeOnlyCompletionAction;
152616
- function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
152702
+ function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, program, useNamespaceInfo, isValidTypeOnlyUseSite, useRequire, host, preferences) {
152617
152703
  ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
152618
152704
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
152619
- return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, packageJsonImportFilter, host);
152705
+ return getBestFix(getImportFixes(exportInfos, useNamespaceInfo, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences).fixes, sourceFile, program, packageJsonImportFilter, host);
152620
152706
  }
152621
152707
  function codeFixActionToCodeAction(_a) {
152622
152708
  var description = _a.description, changes = _a.changes, commands = _a.commands;
@@ -152671,25 +152757,32 @@ var ts;
152671
152757
  return !moduleFile || ts.isImportableFile(program, importingFile, moduleFile, preferences, /*packageJsonFilter*/ undefined, getModuleSpecifierResolutionHost(isFromPackageJson), (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host));
152672
152758
  }
152673
152759
  }
152674
- function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
152675
- var _a = getNewImportFixes(program, importingFile,
152676
- /*position*/ undefined,
152677
- /*isValidTypeOnlyUseSite*/ false,
152678
- /*useRequire*/ false, exportInfo, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
152760
+ function getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
152761
+ var _a = getImportFixes(exportInfo, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite,
152762
+ /*useRequire*/ false, program, importingFile, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
152679
152763
  var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter || ts.createPackageJsonImportFilter(importingFile, preferences, host), host);
152680
152764
  return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
152681
152765
  }
152682
152766
  codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
152683
- function getImportFixes(exportInfos, symbolName,
152767
+ function getImportFixes(exportInfos, useNamespaceInfo,
152684
152768
  /** undefined only for missing JSX namespace */
152685
- position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences) {
152769
+ isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, fromCacheOnly) {
152686
152770
  var checker = program.getTypeChecker();
152687
152771
  var existingImports = ts.flatMap(exportInfos, function (info) { return getExistingImportDeclarations(info, checker, sourceFile, program.getCompilerOptions()); });
152688
- var useNamespace = position === undefined ? undefined : tryUseExistingNamespaceImport(existingImports, symbolName, position, checker);
152772
+ var useNamespace = useNamespaceInfo && tryUseExistingNamespaceImport(existingImports, useNamespaceInfo.symbolName, useNamespaceInfo.position, checker);
152689
152773
  var addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
152690
- // Don't bother providing an action to add a new import if we can add to an existing one.
152691
- var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences);
152692
- return __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), addImport, true);
152774
+ if (addToExisting) {
152775
+ // Don't bother providing an action to add a new import if we can add to an existing one.
152776
+ return {
152777
+ computedWithoutCacheCount: 0,
152778
+ fixes: __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), [addToExisting], false),
152779
+ };
152780
+ }
152781
+ 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;
152782
+ return {
152783
+ computedWithoutCacheCount: computedWithoutCacheCount,
152784
+ fixes: __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), fixes, true),
152785
+ };
152693
152786
  }
152694
152787
  function tryUseExistingNamespaceImport(existingImports, symbolName, position, checker) {
152695
152788
  // It is possible that multiple import statements with the same specifier exist in the file.
@@ -152879,9 +152972,9 @@ var ts;
152879
152972
  });
152880
152973
  return { computedWithoutCacheCount: computedWithoutCacheCount, fixes: fixes };
152881
152974
  }
152882
- function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
152975
+ function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences, fromCacheOnly) {
152883
152976
  var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info, isValidTypeOnlyUseSite, useRequire, program.getTypeChecker(), program.getCompilerOptions()); });
152884
- return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences).fixes;
152977
+ return existingDeclaration ? { fixes: [existingDeclaration] } : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences, fromCacheOnly);
152885
152978
  }
152886
152979
  function newImportInfoFromExistingSpecifier(_a, isValidTypeOnlyUseSite, useRequire, checker, compilerOptions) {
152887
152980
  var _b;
@@ -152977,7 +153070,8 @@ var ts;
152977
153070
  var symbolName = umdSymbol.name;
152978
153071
  var exportInfo = [{ symbol: umdSymbol, moduleSymbol: symbol, moduleFileName: undefined, exportKind: 3 /* UMD */, targetFlags: symbol.flags, isFromPackageJson: false }];
152979
153072
  var useRequire = shouldUseRequire(sourceFile, program);
152980
- var fixes = getImportFixes(exportInfo, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences);
153073
+ var position = ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined;
153074
+ var fixes = getImportFixes(exportInfo, position ? { position: position, symbolName: symbolName } : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences).fixes;
152981
153075
  return { fixes: fixes, symbolName: symbolName, errorIdentifierText: (_b = ts.tryCast(token, ts.isIdentifier)) === null || _b === void 0 ? void 0 : _b.text };
152982
153076
  }
152983
153077
  function getUmdSymbol(token, checker) {
@@ -153049,7 +153143,7 @@ var ts;
153049
153143
  var exportInfo = getExportInfos(symbolName, ts.isJSXTagName(symbolToken), ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
153050
153144
  var fixes = ts.arrayFrom(ts.flatMapIterator(exportInfo.entries(), function (_a) {
153051
153145
  var _ = _a[0], exportInfos = _a[1];
153052
- return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences);
153146
+ return getImportFixes(exportInfos, { symbolName: symbolName, position: symbolToken.getStart(sourceFile) }, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences).fixes;
153053
153147
  }));
153054
153148
  return { fixes: fixes, symbolName: symbolName, errorIdentifierText: symbolToken.text };
153055
153149
  }