@typescript-deploys/pr-build 4.7.0-pr-48792-4 → 4.7.0-pr-47461-10

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-insiders.20220420";
103
+ ts.version = ts.versionMajorMinor + ".0-insiders.20220425";
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,
@@ -17307,11 +17307,19 @@ var ts;
17307
17307
  return !!name && isDynamicName(name);
17308
17308
  }
17309
17309
  ts.hasDynamicName = hasDynamicName;
17310
+ function getComputedPropertyNameExpression(name) {
17311
+ return ts.isElementAccessExpression(name.expression)
17312
+ ? skipParentheses(name.expression.argumentExpression)
17313
+ : name.expression;
17314
+ }
17315
+ ts.getComputedPropertyNameExpression = getComputedPropertyNameExpression;
17310
17316
  function isDynamicName(name) {
17311
17317
  if (!(name.kind === 162 /* ComputedPropertyName */ || name.kind === 207 /* ElementAccessExpression */)) {
17312
17318
  return false;
17313
17319
  }
17314
- var expr = ts.isElementAccessExpression(name) ? skipParentheses(name.argumentExpression) : name.expression;
17320
+ var expr = ts.isElementAccessExpression(name)
17321
+ ? skipParentheses(name.argumentExpression)
17322
+ : getComputedPropertyNameExpression(name);
17315
17323
  return !isStringOrNumericLiteralLike(expr) &&
17316
17324
  !isSignedNumericLiteral(expr);
17317
17325
  }
@@ -17325,7 +17333,7 @@ var ts;
17325
17333
  case 8 /* NumericLiteral */:
17326
17334
  return ts.escapeLeadingUnderscores(name.text);
17327
17335
  case 162 /* ComputedPropertyName */:
17328
- var nameExpression = name.expression;
17336
+ var nameExpression = getComputedPropertyNameExpression(name);
17329
17337
  if (isStringOrNumericLiteralLike(nameExpression)) {
17330
17338
  return ts.escapeLeadingUnderscores(nameExpression.text);
17331
17339
  }
@@ -18293,10 +18301,10 @@ var ts;
18293
18301
  return ts.combinePaths(newDirPath, sourceFilePath);
18294
18302
  }
18295
18303
  ts.getSourceFilePathInNewDirWorker = getSourceFilePathInNewDirWorker;
18296
- function writeFile(host, diagnostics, fileName, data, writeByteOrderMark, sourceFiles) {
18297
- host.writeFile(fileName, data, writeByteOrderMark, function (hostErrorMessage) {
18304
+ function writeFile(host, diagnostics, fileName, text, writeByteOrderMark, sourceFiles, data) {
18305
+ host.writeFile(fileName, text, writeByteOrderMark, function (hostErrorMessage) {
18298
18306
  diagnostics.add(createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage));
18299
- }, sourceFiles);
18307
+ }, sourceFiles, data);
18300
18308
  }
18301
18309
  ts.writeFile = writeFile;
18302
18310
  function ensureDirectoriesExist(directoryPath, createDirectory, directoryExists) {
@@ -34223,7 +34231,7 @@ var ts;
34223
34231
  return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(disallowReturnTypeInArrowFunction), pos);
34224
34232
  }
34225
34233
  // It wasn't an assignment or a lambda. This is a conditional expression:
34226
- return parseConditionalExpressionRest(expr, pos, disallowReturnTypeInArrowFunction);
34234
+ return parseConditionalExpressionRest(expr, pos);
34227
34235
  }
34228
34236
  function isYieldExpression() {
34229
34237
  if (token() === 125 /* YieldKeyword */) {
@@ -34288,7 +34296,7 @@ var ts;
34288
34296
  return addJSDocComment(finishNode(node, pos));
34289
34297
  }
34290
34298
  function tryParseParenthesizedArrowFunctionExpression(disallowReturnTypeInArrowFunction) {
34291
- var triState = isParenthesizedArrowFunctionExpression(disallowReturnTypeInArrowFunction);
34299
+ var triState = isParenthesizedArrowFunctionExpression();
34292
34300
  if (triState === 0 /* False */) {
34293
34301
  // It's definitely not a parenthesized arrow function expression.
34294
34302
  return undefined;
@@ -34298,16 +34306,16 @@ var ts;
34298
34306
  // it out, but don't allow any ambiguity, and return 'undefined' if this could be an
34299
34307
  // expression instead.
34300
34308
  return triState === 1 /* True */ ?
34301
- parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true, disallowReturnTypeInArrowFunction) :
34309
+ parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true, /*disallowReturnTypeInArrowFunction*/ false) :
34302
34310
  tryParse(function () { return parsePossibleParenthesizedArrowFunctionExpression(disallowReturnTypeInArrowFunction); });
34303
34311
  }
34304
34312
  // True -> We definitely expect a parenthesized arrow function here.
34305
34313
  // False -> There *cannot* be a parenthesized arrow function here.
34306
34314
  // Unknown -> There *might* be a parenthesized arrow function here.
34307
34315
  // Speculatively look ahead to be sure, and rollback if not.
34308
- function isParenthesizedArrowFunctionExpression(disallowReturnTypeInArrowFunction) {
34316
+ function isParenthesizedArrowFunctionExpression() {
34309
34317
  if (token() === 20 /* OpenParenToken */ || token() === 29 /* LessThanToken */ || token() === 131 /* AsyncKeyword */) {
34310
- return lookAhead(function () { return isParenthesizedArrowFunctionExpressionWorker(disallowReturnTypeInArrowFunction); });
34318
+ return lookAhead(isParenthesizedArrowFunctionExpressionWorker);
34311
34319
  }
34312
34320
  if (token() === 38 /* EqualsGreaterThanToken */) {
34313
34321
  // ERROR RECOVERY TWEAK:
@@ -34318,7 +34326,7 @@ var ts;
34318
34326
  // Definitely not a parenthesized arrow function.
34319
34327
  return 0 /* False */;
34320
34328
  }
34321
- function isParenthesizedArrowFunctionExpressionWorker(disallowReturnTypeInArrowFunction) {
34329
+ function isParenthesizedArrowFunctionExpressionWorker() {
34322
34330
  if (token() === 131 /* AsyncKeyword */) {
34323
34331
  nextToken();
34324
34332
  if (scanner.hasPrecedingLineBreak()) {
@@ -34338,13 +34346,8 @@ var ts;
34338
34346
  // but this is probably what the user intended.
34339
34347
  var third = nextToken();
34340
34348
  switch (third) {
34341
- case 58 /* ColonToken */:
34342
- if (disallowReturnTypeInArrowFunction) {
34343
- // "a ? () : ..."
34344
- return 0 /* False */;
34345
- }
34346
- return 1 /* True */;
34347
34349
  case 38 /* EqualsGreaterThanToken */:
34350
+ case 58 /* ColonToken */:
34348
34351
  case 18 /* OpenBraceToken */:
34349
34352
  return 1 /* True */;
34350
34353
  default:
@@ -34518,8 +34521,13 @@ var ts;
34518
34521
  // This is a valid arrow function with "z" as the return type.
34519
34522
  //
34520
34523
  // But, if we're in the true side of a conditional expression, this colon
34521
- // terminates the expression, so we cannot allow a return type, even if we aren't
34524
+ // terminates the expression, so we cannot allow a return type if we aren't
34522
34525
  // certain whether or not the preceding text was parsed as a parameter list.
34526
+ //
34527
+ // For example,
34528
+ // a() ? (b: number, c?: string): void => d() : e
34529
+ // is determined by isParenthesizedArrowFunctionExpression to unambiguously
34530
+ // be an arrow expression, so we allow a return type.
34523
34531
  if (disallowReturnTypeInArrowFunction && token() === 58 /* ColonToken */) {
34524
34532
  return undefined;
34525
34533
  }
@@ -34589,7 +34597,7 @@ var ts;
34589
34597
  topLevel = savedTopLevel;
34590
34598
  return node;
34591
34599
  }
34592
- function parseConditionalExpressionRest(leftOperand, pos, disallowReturnTypeInArrowFunction) {
34600
+ function parseConditionalExpressionRest(leftOperand, pos) {
34593
34601
  // Note: we are passed in an expression which was produced from parseBinaryExpressionOrHigher.
34594
34602
  var questionToken = parseOptionalToken(57 /* QuestionToken */);
34595
34603
  if (!questionToken) {
@@ -34599,7 +34607,7 @@ var ts;
34599
34607
  // we do not that for the 'whenFalse' part.
34600
34608
  var colonToken;
34601
34609
  return finishNode(factory.createConditionalExpression(leftOperand, questionToken, doOutsideOfContext(disallowInAndDecoratorContext, function () { return parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ true); }), colonToken = parseExpectedToken(58 /* ColonToken */), ts.nodeIsPresent(colonToken)
34602
- ? parseAssignmentExpressionOrHigher(disallowReturnTypeInArrowFunction) // inherit disallowReturnTypeInArrowFunction in false side
34610
+ ? parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ true)
34603
34611
  : createMissingNode(79 /* Identifier */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(58 /* ColonToken */))), pos);
34604
34612
  }
34605
34613
  function parseBinaryExpressionOrHigher(precedence) {
@@ -44447,7 +44455,7 @@ var ts;
44447
44455
  return (ts.isGlobalScopeAugmentation(node) ? "__global" : "\"" + moduleName + "\"");
44448
44456
  }
44449
44457
  if (name.kind === 162 /* ComputedPropertyName */) {
44450
- var nameExpression = name.expression;
44458
+ var nameExpression = ts.getComputedPropertyNameExpression(name);
44451
44459
  // treat computed property names where expression is string/numeric literal as just string/numeric literal
44452
44460
  if (ts.isStringOrNumericLiteralLike(nameExpression)) {
44453
44461
  return ts.escapeLeadingUnderscores(nameExpression.text);
@@ -73432,6 +73440,7 @@ var ts;
73432
73440
  }
73433
73441
  }
73434
73442
  else {
73443
+ error(attributeDecl.expression, ts.Diagnostics.Spread_types_may_only_be_created_from_object_types);
73435
73444
  typeToIntersect = typeToIntersect ? getIntersectionType([typeToIntersect, exprType]) : exprType;
73436
73445
  }
73437
73446
  }
@@ -75669,6 +75678,7 @@ var ts;
75669
75678
  // decorators are applied to a declaration by the emitter, and not to an expression.
75670
75679
  var isSingleNonGenericCandidate = candidates.length === 1 && !candidates[0].typeParameters;
75671
75680
  var argCheckMode = !isDecorator && !isSingleNonGenericCandidate && ts.some(args, isContextSensitive) ? 4 /* SkipContextSensitive */ : 0 /* Normal */;
75681
+ argCheckMode |= checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
75672
75682
  // The following variables are captured and modified by calls to chooseOverload.
75673
75683
  // If overload resolution or type argument inference fails, we want to report the
75674
75684
  // best error possible. The best error is one which says that an argument was not
@@ -75884,7 +75894,7 @@ var ts;
75884
75894
  // If one or more context sensitive arguments were excluded, we start including
75885
75895
  // them now (and keeping do so for any subsequent candidates) and perform a second
75886
75896
  // round of type inference and applicability checking for this particular candidate.
75887
- argCheckMode = 0 /* Normal */;
75897
+ argCheckMode = checkMode & 32 /* IsForStringLiteralArgumentCompletions */;
75888
75898
  if (inferenceContext) {
75889
75899
  var typeArgumentTypes = inferTypeArguments(node, candidate, args, argCheckMode, inferenceContext);
75890
75900
  checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration), inferenceContext && inferenceContext.inferredTypeParameters);
@@ -109966,6 +109976,7 @@ var ts;
109966
109976
  else {
109967
109977
  printer.writeFile(sourceFile, writer, sourceMapGenerator);
109968
109978
  }
109979
+ var sourceMapUrlPos;
109969
109980
  if (sourceMapGenerator) {
109970
109981
  if (sourceMapDataList) {
109971
109982
  sourceMapDataList.push({
@@ -109977,6 +109988,7 @@ var ts;
109977
109988
  if (sourceMappingURL) {
109978
109989
  if (!writer.isAtStartOfLine())
109979
109990
  writer.rawWrite(newLine);
109991
+ sourceMapUrlPos = writer.getTextPos();
109980
109992
  writer.writeComment("//# " + "sourceMappingURL" + "=" + sourceMappingURL); // Tools can sometimes see this line as a source mapping url comment
109981
109993
  }
109982
109994
  // Write the source map
@@ -109989,7 +110001,7 @@ var ts;
109989
110001
  writer.writeLine();
109990
110002
  }
109991
110003
  // Write the output file
109992
- ts.writeFile(host, emitterDiagnostics, jsFilePath, writer.getText(), !!compilerOptions.emitBOM, sourceFiles);
110004
+ ts.writeFile(host, emitterDiagnostics, jsFilePath, writer.getText(), !!compilerOptions.emitBOM, sourceFiles, { sourceMapUrlPos: sourceMapUrlPos });
109993
110005
  // Reset state
109994
110006
  writer.clear();
109995
110007
  }
@@ -110511,7 +110523,7 @@ var ts;
110511
110523
  setWriter(/*output*/ undefined, /*_sourceMapGenerator*/ undefined);
110512
110524
  }
110513
110525
  function getCurrentLineMap() {
110514
- return currentLineMap || (currentLineMap = ts.getLineStarts(currentSourceFile));
110526
+ return currentLineMap || (currentLineMap = ts.getLineStarts(ts.Debug.checkDefined(currentSourceFile)));
110515
110527
  }
110516
110528
  function emit(node, parenthesizerRule) {
110517
110529
  if (node === undefined)
@@ -111686,7 +111698,7 @@ var ts;
111686
111698
  increaseIndent();
111687
111699
  }
111688
111700
  var preferNewLine = node.multiLine ? 65536 /* PreferNewLine */ : 0 /* None */;
111689
- var allowTrailingComma = currentSourceFile.languageVersion >= 1 /* ES5 */ && !ts.isJsonSourceFile(currentSourceFile) ? 64 /* AllowTrailingComma */ : 0 /* None */;
111701
+ var allowTrailingComma = currentSourceFile && currentSourceFile.languageVersion >= 1 /* ES5 */ && !ts.isJsonSourceFile(currentSourceFile) ? 64 /* AllowTrailingComma */ : 0 /* None */;
111690
111702
  emitList(node, node.properties, 526226 /* ObjectLiteralExpressionProperties */ | allowTrailingComma | preferNewLine);
111691
111703
  if (indentedFlag) {
111692
111704
  decreaseIndent();
@@ -112042,7 +112054,7 @@ var ts;
112042
112054
  emitExpression(node.expression, parenthesizer.parenthesizeExpressionOfExpressionStatement);
112043
112055
  // Emit semicolon in non json files
112044
112056
  // 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)) {
112057
+ if (!currentSourceFile || !ts.isJsonSourceFile(currentSourceFile) || ts.nodeIsSynthesized(node.expression)) {
112046
112058
  writeTrailingSemicolon();
112047
112059
  }
112048
112060
  }
@@ -112335,7 +112347,7 @@ var ts;
112335
112347
  if (body.multiLine) {
112336
112348
  return false;
112337
112349
  }
112338
- if (!ts.nodeIsSynthesized(body) && !ts.rangeIsOnSingleLine(body, currentSourceFile)) {
112350
+ if (!ts.nodeIsSynthesized(body) && currentSourceFile && !ts.rangeIsOnSingleLine(body, currentSourceFile)) {
112339
112351
  return false;
112340
112352
  }
112341
112353
  if (getLeadingLineTerminatorCount(body, body.statements, 2 /* PreserveLines */)
@@ -112360,12 +112372,7 @@ var ts;
112360
112372
  var emitBlockFunctionBody = shouldEmitBlockFunctionBodyOnSingleLine(body)
112361
112373
  ? emitBlockFunctionBodyOnSingleLine
112362
112374
  : emitBlockFunctionBodyWorker;
112363
- if (emitBodyWithDetachedComments) {
112364
- emitBodyWithDetachedComments(body, body.statements, emitBlockFunctionBody);
112365
- }
112366
- else {
112367
- emitBlockFunctionBody(body);
112368
- }
112375
+ emitBodyWithDetachedComments(body, body.statements, emitBlockFunctionBody);
112369
112376
  decreaseIndent();
112370
112377
  writeToken(19 /* CloseBraceToken */, body.statements.end, writePunctuation, body);
112371
112378
  onAfterEmitNode === null || onAfterEmitNode === void 0 ? void 0 : onAfterEmitNode(body);
@@ -112762,7 +112769,8 @@ var ts;
112762
112769
  var emitAsSingleStatement = statements.length === 1 &&
112763
112770
  (
112764
112771
  // treat synthesized nodes as located on the same line for emit purposes
112765
- ts.nodeIsSynthesized(parentNode) ||
112772
+ !currentSourceFile ||
112773
+ ts.nodeIsSynthesized(parentNode) ||
112766
112774
  ts.nodeIsSynthesized(statements[0]) ||
112767
112775
  ts.rangeStartPositionsAreOnSameLine(parentNode, statements[0], currentSourceFile));
112768
112776
  var format = 163969 /* CaseOrDefaultClauseStatements */;
@@ -112993,16 +113001,14 @@ var ts;
112993
113001
  function emitSourceFile(node) {
112994
113002
  writeLine();
112995
113003
  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
- }
113004
+ // Emit detached comment if there are no prologue directives or if the first node is synthesized.
113005
+ // The synthesized node will have no leading comment so some comments may be missed.
113006
+ var shouldEmitDetachedComment = statements.length === 0 ||
113007
+ !ts.isPrologueDirective(statements[0]) ||
113008
+ ts.nodeIsSynthesized(statements[0]);
113009
+ if (shouldEmitDetachedComment) {
113010
+ emitBodyWithDetachedComments(node, statements, emitSourceFileWorker);
113011
+ return;
113006
113012
  }
113007
113013
  emitSourceFileWorker(node);
113008
113014
  }
@@ -113391,7 +113397,7 @@ var ts;
113391
113397
  }
113392
113398
  if (isEmpty) {
113393
113399
  // Write a line terminator if the parent node was multi-line
113394
- if (format & 1 /* MultiLine */ && !(preserveSourceNewlines && (!parentNode || ts.rangeIsOnSingleLine(parentNode, currentSourceFile)))) {
113400
+ if (format & 1 /* MultiLine */ && !(preserveSourceNewlines && (!parentNode || currentSourceFile && ts.rangeIsOnSingleLine(parentNode, currentSourceFile)))) {
113395
113401
  writeLine();
113396
113402
  }
113397
113403
  else if (format & 256 /* SpaceBetweenBraces */ && !(format & 524288 /* NoSpaceIfEmpty */)) {
@@ -113652,7 +113658,7 @@ var ts;
113652
113658
  }
113653
113659
  var firstChild_1 = children[0];
113654
113660
  if (firstChild_1 === undefined) {
113655
- return !parentNode || ts.rangeIsOnSingleLine(parentNode, currentSourceFile) ? 0 : 1;
113661
+ return !parentNode || currentSourceFile && ts.rangeIsOnSingleLine(parentNode, currentSourceFile) ? 0 : 1;
113656
113662
  }
113657
113663
  if (firstChild_1.pos === nextListElementPos) {
113658
113664
  // If this child starts at the beginning of a list item in a parent list, its leading
@@ -113676,7 +113682,7 @@ var ts;
113676
113682
  // JsxText will be written with its leading whitespace, so don't add more manually.
113677
113683
  return 0;
113678
113684
  }
113679
- if (parentNode &&
113685
+ if (currentSourceFile && parentNode &&
113680
113686
  !ts.positionIsSynthesized(parentNode.pos) &&
113681
113687
  !ts.nodeIsSynthesized(firstChild_1) &&
113682
113688
  (!firstChild_1.parent || ts.getOriginalNode(firstChild_1.parent) === ts.getOriginalNode(parentNode))) {
@@ -113700,7 +113706,7 @@ var ts;
113700
113706
  // JsxText will be written with its leading whitespace, so don't add more manually.
113701
113707
  return 0;
113702
113708
  }
113703
- else if (!ts.nodeIsSynthesized(previousNode) && !ts.nodeIsSynthesized(nextNode)) {
113709
+ else if (currentSourceFile && !ts.nodeIsSynthesized(previousNode) && !ts.nodeIsSynthesized(nextNode)) {
113704
113710
  if (preserveSourceNewlines && siblingNodePositionsAreComparable(previousNode, nextNode)) {
113705
113711
  return getEffectiveLines(function (includeComments) { return ts.getLinesBetweenRangeEndAndRangeStart(previousNode, nextNode, currentSourceFile, includeComments); });
113706
113712
  }
@@ -113732,9 +113738,9 @@ var ts;
113732
113738
  }
113733
113739
  var lastChild = ts.lastOrUndefined(children);
113734
113740
  if (lastChild === undefined) {
113735
- return !parentNode || ts.rangeIsOnSingleLine(parentNode, currentSourceFile) ? 0 : 1;
113741
+ return !parentNode || currentSourceFile && ts.rangeIsOnSingleLine(parentNode, currentSourceFile) ? 0 : 1;
113736
113742
  }
113737
- if (parentNode && !ts.positionIsSynthesized(parentNode.pos) && !ts.nodeIsSynthesized(lastChild) && (!lastChild.parent || lastChild.parent === parentNode)) {
113743
+ if (currentSourceFile && parentNode && !ts.positionIsSynthesized(parentNode.pos) && !ts.nodeIsSynthesized(lastChild) && (!lastChild.parent || lastChild.parent === parentNode)) {
113738
113744
  if (preserveSourceNewlines) {
113739
113745
  var end_1 = ts.isNodeArray(children) && !ts.positionIsSynthesized(children.end) ? children.end : lastChild.end;
113740
113746
  return getEffectiveLines(function (includeComments) { return ts.getLinesBetweenPositionAndNextNonWhitespaceCharacter(end_1, parentNode.end, currentSourceFile, includeComments); });
@@ -113807,7 +113813,7 @@ var ts;
113807
113813
  if (ts.getStartsOnNewLine(node2)) {
113808
113814
  return 1;
113809
113815
  }
113810
- if (!ts.nodeIsSynthesized(parent) && !ts.nodeIsSynthesized(node1) && !ts.nodeIsSynthesized(node2)) {
113816
+ if (currentSourceFile && !ts.nodeIsSynthesized(parent) && !ts.nodeIsSynthesized(node1) && !ts.nodeIsSynthesized(node2)) {
113811
113817
  if (preserveSourceNewlines) {
113812
113818
  return getEffectiveLines(function (includeComments) { return ts.getLinesBetweenRangeEndAndRangeStart(node1, node2, currentSourceFile, includeComments); });
113813
113819
  }
@@ -113817,7 +113823,7 @@ var ts;
113817
113823
  }
113818
113824
  function isEmptyBlock(block) {
113819
113825
  return block.statements.length === 0
113820
- && ts.rangeEndIsOnSameLineAsRangeStart(block, block, currentSourceFile);
113826
+ && (!currentSourceFile || ts.rangeEndIsOnSameLineAsRangeStart(block, block, currentSourceFile));
113821
113827
  }
113822
113828
  function skipSynthesizedParentheses(node) {
113823
113829
  while (node.kind === 212 /* ParenthesizedExpression */ && ts.nodeIsSynthesized(node)) {
@@ -113829,16 +113835,23 @@ var ts;
113829
113835
  if (ts.isGeneratedIdentifier(node)) {
113830
113836
  return generateName(node);
113831
113837
  }
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) {
113838
+ if (ts.isStringLiteral(node) && node.textSourceNode) {
113836
113839
  return getTextOfNode(node.textSourceNode, includeTrivia);
113837
113840
  }
113838
- else if (ts.isLiteralExpression(node) && (ts.nodeIsSynthesized(node) || !node.parent)) {
113839
- return node.text;
113841
+ var sourceFile = currentSourceFile; // const needed for control flow
113842
+ var canUseSourceFile = !!sourceFile && !!node.parent && !ts.nodeIsSynthesized(node);
113843
+ if (ts.isMemberName(node)) {
113844
+ if (!canUseSourceFile || ts.getSourceFileOfNode(node) !== ts.getOriginalNode(sourceFile)) {
113845
+ return ts.idText(node);
113846
+ }
113847
+ }
113848
+ else {
113849
+ ts.Debug.assertNode(node, ts.isLiteralExpression); // not strictly necessary
113850
+ if (!canUseSourceFile) {
113851
+ return node.text;
113852
+ }
113840
113853
  }
113841
- return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node, includeTrivia);
113854
+ return ts.getSourceTextOfNodeFromSourceFile(sourceFile, node, includeTrivia);
113842
113855
  }
113843
113856
  function getLiteralTextOfNode(node, neverAsciiEscape, jsxAttributeEscape) {
113844
113857
  if (node.kind === 10 /* StringLiteral */ && node.textSourceNode) {
@@ -114417,7 +114430,7 @@ var ts;
114417
114430
  return true;
114418
114431
  }
114419
114432
  function emitLeadingComment(commentPos, commentEnd, kind, hasTrailingNewLine, rangePos) {
114420
- if (!shouldWriteComment(currentSourceFile.text, commentPos))
114433
+ if (!currentSourceFile || !shouldWriteComment(currentSourceFile.text, commentPos))
114421
114434
  return;
114422
114435
  if (!hasWrittenComment) {
114423
114436
  ts.emitNewLineBeforeLeadingCommentOfPosition(getCurrentLineMap(), writer, rangePos, commentPos);
@@ -114444,7 +114457,7 @@ var ts;
114444
114457
  forEachTrailingCommentToEmit(pos, emitTrailingComment);
114445
114458
  }
114446
114459
  function emitTrailingComment(commentPos, commentEnd, _kind, hasTrailingNewLine) {
114447
- if (!shouldWriteComment(currentSourceFile.text, commentPos))
114460
+ if (!currentSourceFile || !shouldWriteComment(currentSourceFile.text, commentPos))
114448
114461
  return;
114449
114462
  // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment2*/
114450
114463
  if (!writer.isAtStartOfLine()) {
@@ -114466,6 +114479,8 @@ var ts;
114466
114479
  exitComment();
114467
114480
  }
114468
114481
  function emitTrailingCommentOfPositionNoNewline(commentPos, commentEnd, kind) {
114482
+ if (!currentSourceFile)
114483
+ return;
114469
114484
  // trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
114470
114485
  emitPos(commentPos);
114471
114486
  ts.writeCommentRange(currentSourceFile.text, getCurrentLineMap(), writer, commentPos, commentEnd, newLine);
@@ -114475,6 +114490,8 @@ var ts;
114475
114490
  }
114476
114491
  }
114477
114492
  function emitTrailingCommentOfPosition(commentPos, commentEnd, _kind, hasTrailingNewLine) {
114493
+ if (!currentSourceFile)
114494
+ return;
114478
114495
  // trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
114479
114496
  emitPos(commentPos);
114480
114497
  ts.writeCommentRange(currentSourceFile.text, getCurrentLineMap(), writer, commentPos, commentEnd, newLine);
@@ -114507,6 +114524,8 @@ var ts;
114507
114524
  return detachedCommentsInfo !== undefined && ts.last(detachedCommentsInfo).nodePos === pos;
114508
114525
  }
114509
114526
  function forEachLeadingCommentWithoutDetachedComments(cb) {
114527
+ if (!currentSourceFile)
114528
+ return;
114510
114529
  // get the leading comments from detachedPos
114511
114530
  var pos = ts.last(detachedCommentsInfo).detachedCommentEndPos;
114512
114531
  if (detachedCommentsInfo.length - 1) {
@@ -114518,7 +114537,7 @@ var ts;
114518
114537
  ts.forEachLeadingCommentRange(currentSourceFile.text, pos, cb, /*state*/ pos);
114519
114538
  }
114520
114539
  function emitDetachedCommentsAndUpdateCommentsInfo(range) {
114521
- var currentDetachedCommentInfo = ts.emitDetachedComments(currentSourceFile.text, getCurrentLineMap(), writer, emitComment, range, newLine, commentsDisabled);
114540
+ var currentDetachedCommentInfo = currentSourceFile && ts.emitDetachedComments(currentSourceFile.text, getCurrentLineMap(), writer, emitComment, range, newLine, commentsDisabled);
114522
114541
  if (currentDetachedCommentInfo) {
114523
114542
  if (detachedCommentsInfo) {
114524
114543
  detachedCommentsInfo.push(currentDetachedCommentInfo);
@@ -114529,7 +114548,7 @@ var ts;
114529
114548
  }
114530
114549
  }
114531
114550
  function emitComment(text, lineMap, writer, commentPos, commentEnd, newLine) {
114532
- if (!shouldWriteComment(currentSourceFile.text, commentPos))
114551
+ if (!currentSourceFile || !shouldWriteComment(currentSourceFile.text, commentPos))
114533
114552
  return;
114534
114553
  emitPos(commentPos);
114535
114554
  ts.writeCommentRange(text, lineMap, writer, commentPos, commentEnd, newLine);
@@ -114541,7 +114560,7 @@ var ts;
114541
114560
  * @return true if the comment is a triple-slash comment else false
114542
114561
  */
114543
114562
  function isTripleSlashComment(commentPos, commentEnd) {
114544
- return ts.isRecognizedTripleSlashComment(currentSourceFile.text, commentPos, commentEnd);
114563
+ return !!currentSourceFile && ts.isRecognizedTripleSlashComment(currentSourceFile.text, commentPos, commentEnd);
114545
114564
  }
114546
114565
  // Source Maps
114547
114566
  function getParsedSourceMap(node) {
@@ -115456,7 +115475,11 @@ var ts;
115456
115475
  return newValue;
115457
115476
  };
115458
115477
  if (originalWriteFile) {
115459
- host.writeFile = function (fileName, data, writeByteOrderMark, onError, sourceFiles) {
115478
+ host.writeFile = function (fileName, data) {
115479
+ var rest = [];
115480
+ for (var _i = 2; _i < arguments.length; _i++) {
115481
+ rest[_i - 2] = arguments[_i];
115482
+ }
115460
115483
  var key = toPath(fileName);
115461
115484
  fileExistsCache.delete(key);
115462
115485
  var value = readFileCache.get(key);
@@ -115470,7 +115493,7 @@ var ts;
115470
115493
  sourceFileCache.delete(key);
115471
115494
  }
115472
115495
  }
115473
- originalWriteFile.call(host, fileName, data, writeByteOrderMark, onError, sourceFiles);
115496
+ originalWriteFile.call.apply(originalWriteFile, __spreadArray([host, fileName, data], rest, false));
115474
115497
  };
115475
115498
  }
115476
115499
  // directoryExists
@@ -116403,6 +116426,7 @@ var ts;
116403
116426
  useCaseSensitiveFileNames: function () { return host.useCaseSensitiveFileNames(); },
116404
116427
  getFileIncludeReasons: function () { return fileReasons; },
116405
116428
  structureIsReused: structureIsReused,
116429
+ writeFile: writeFile,
116406
116430
  };
116407
116431
  onProgramCreateComplete();
116408
116432
  // Add file processingDiagnostics
@@ -116900,7 +116924,7 @@ var ts;
116900
116924
  getProjectReferenceRedirect: getProjectReferenceRedirect,
116901
116925
  isSourceOfProjectReferenceRedirect: isSourceOfProjectReferenceRedirect,
116902
116926
  getSymlinkCache: getSymlinkCache,
116903
- writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError, sourceFiles) { return host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); }),
116927
+ writeFile: writeFileCallback || writeFile,
116904
116928
  isEmitBlocked: isEmitBlocked,
116905
116929
  readFile: function (f) { return host.readFile(f); },
116906
116930
  fileExists: function (f) {
@@ -116920,6 +116944,9 @@ var ts;
116920
116944
  getFileIncludeReasons: program.getFileIncludeReasons,
116921
116945
  };
116922
116946
  }
116947
+ function writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data) {
116948
+ host.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
116949
+ }
116923
116950
  function emitBuildInfo(writeFileCallback) {
116924
116951
  ts.Debug.assert(!ts.outFile(options));
116925
116952
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("emit" /* Emit */, "emitBuildInfo", {}, /*separateBeginAndEnd*/ true);
@@ -119362,6 +119389,7 @@ var ts;
119362
119389
  }
119363
119390
  }
119364
119391
  }
119392
+ BuilderState.updateExportedModules = updateExportedModules;
119365
119393
  /**
119366
119394
  * Updates the exported modules from cache into state's exported modules map
119367
119395
  * This should be called whenever it is safe to commit the state of the builder
@@ -119785,6 +119813,18 @@ var ts;
119785
119813
  }
119786
119814
  return undefined;
119787
119815
  }
119816
+ function removeDiagnosticsOfLibraryFiles(state) {
119817
+ if (!state.cleanedDiagnosticsOfLibFiles) {
119818
+ state.cleanedDiagnosticsOfLibFiles = true;
119819
+ var program_1 = ts.Debug.checkDefined(state.program);
119820
+ var options_2 = program_1.getCompilerOptions();
119821
+ ts.forEach(program_1.getSourceFiles(), function (f) {
119822
+ return program_1.isSourceFileDefaultLibrary(f) &&
119823
+ !ts.skipTypeChecking(f, options_2, program_1) &&
119824
+ removeSemanticDiagnosticsOf(state, f.resolvedPath);
119825
+ });
119826
+ }
119827
+ }
119788
119828
  /**
119789
119829
  * Handles semantic diagnostics and dts emit for affectedFile and files, that are referencing modules that export entities from affected file
119790
119830
  * This is because even though js emit doesnt change, dts emit / type used can change resulting in need for dts emit and js change
@@ -119794,28 +119834,17 @@ var ts;
119794
119834
  removeSemanticDiagnosticsOf(state, affectedFile.resolvedPath);
119795
119835
  // If affected files is everything except default library, then nothing more to do
119796
119836
  if (state.allFilesExcludingDefaultLibraryFile === state.affectedFiles) {
119797
- if (!state.cleanedDiagnosticsOfLibFiles) {
119798
- state.cleanedDiagnosticsOfLibFiles = true;
119799
- var program_1 = ts.Debug.checkDefined(state.program);
119800
- var options_2 = program_1.getCompilerOptions();
119801
- ts.forEach(program_1.getSourceFiles(), function (f) {
119802
- return program_1.isSourceFileDefaultLibrary(f) &&
119803
- !ts.skipTypeChecking(f, options_2, program_1) &&
119804
- removeSemanticDiagnosticsOf(state, f.resolvedPath);
119805
- });
119806
- }
119837
+ removeDiagnosticsOfLibraryFiles(state);
119807
119838
  // When a change affects the global scope, all files are considered to be affected without updating their signature
119808
119839
  // That means when affected file is handled, its signature can be out of date
119809
119840
  // To avoid this, ensure that we update the signature for any affected file in this scenario.
119810
119841
  ts.BuilderState.updateShapeSignature(state, ts.Debug.checkDefined(state.program), affectedFile, ts.Debug.checkDefined(state.currentAffectedFilesSignatures), cancellationToken, computeHash, state.currentAffectedFilesExportedModulesMap);
119811
119842
  return;
119812
119843
  }
119813
- else {
119814
- ts.Debug.assert(state.hasCalledUpdateShapeSignature.has(affectedFile.resolvedPath) || ((_a = state.currentAffectedFilesSignatures) === null || _a === void 0 ? void 0 : _a.has(affectedFile.resolvedPath)), "Signature not updated for affected file: " + affectedFile.fileName);
119815
- }
119816
- if (!state.compilerOptions.assumeChangesOnlyAffectDirectDependencies) {
119817
- forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, function (state, path) { return handleDtsMayChangeOf(state, path, cancellationToken, computeHash, host); });
119818
- }
119844
+ ts.Debug.assert(state.hasCalledUpdateShapeSignature.has(affectedFile.resolvedPath) || ((_a = state.currentAffectedFilesSignatures) === null || _a === void 0 ? void 0 : _a.has(affectedFile.resolvedPath)), "Signature not updated for affected file: " + affectedFile.fileName);
119845
+ if (state.compilerOptions.assumeChangesOnlyAffectDirectDependencies)
119846
+ return;
119847
+ handleDtsMayChangeOfReferencingExportOfAffectedFile(state, affectedFile, cancellationToken, computeHash, host);
119819
119848
  }
119820
119849
  /**
119821
119850
  * Handle the dts may change, so they need to be added to pending emit if dts emit is enabled,
@@ -119857,16 +119886,41 @@ var ts;
119857
119886
  var oldSignature = ts.Debug.checkDefined(state.fileInfos.get(path)).signature;
119858
119887
  return newSignature !== oldSignature;
119859
119888
  }
119889
+ function forEachKeyOfExportedModulesMap(state, filePath, fn) {
119890
+ // Go through exported modules from cache first
119891
+ var keys = state.currentAffectedFilesExportedModulesMap.getKeys(filePath);
119892
+ var result = keys && ts.forEachKey(keys, fn);
119893
+ if (result)
119894
+ return result;
119895
+ // If exported from path is not from cache and exported modules has path, all files referencing file exported from are affected
119896
+ keys = state.exportedModulesMap.getKeys(filePath);
119897
+ return keys && ts.forEachKey(keys, function (exportedFromPath) {
119898
+ var _a;
119899
+ // If the cache had an updated value, skip
119900
+ return !state.currentAffectedFilesExportedModulesMap.hasKey(exportedFromPath) &&
119901
+ !((_a = state.currentAffectedFilesExportedModulesMap.deletedKeys()) === null || _a === void 0 ? void 0 : _a.has(exportedFromPath)) ?
119902
+ fn(exportedFromPath) :
119903
+ undefined;
119904
+ });
119905
+ }
119906
+ function handleDtsMayChangeOfGlobalScope(state, filePath, cancellationToken, computeHash, host) {
119907
+ var _a;
119908
+ if (!((_a = state.fileInfos.get(filePath)) === null || _a === void 0 ? void 0 : _a.affectsGlobalScope))
119909
+ return false;
119910
+ // Every file needs to be handled
119911
+ ts.BuilderState.getAllFilesExcludingDefaultLibraryFile(state, state.program, /*firstSourceFile*/ undefined)
119912
+ .forEach(function (file) { return handleDtsMayChangeOf(state, file.resolvedPath, cancellationToken, computeHash, host); });
119913
+ removeDiagnosticsOfLibraryFiles(state);
119914
+ return true;
119915
+ }
119860
119916
  /**
119861
- * Iterate on referencing modules that export entities from affected file
119917
+ * Iterate on referencing modules that export entities from affected file and delete diagnostics and add pending emit
119862
119918
  */
119863
- function forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, fn) {
119864
- var _a, _b;
119919
+ function handleDtsMayChangeOfReferencingExportOfAffectedFile(state, affectedFile, cancellationToken, computeHash, host) {
119865
119920
  // If there was change in signature (dts output) for the changed file,
119866
119921
  // then only we need to handle pending file emit
119867
- if (!state.exportedModulesMap || !state.changedFilesSet.has(affectedFile.resolvedPath)) {
119922
+ if (!state.exportedModulesMap || !state.changedFilesSet.has(affectedFile.resolvedPath))
119868
119923
  return;
119869
- }
119870
119924
  if (!isChangedSignature(state, affectedFile.resolvedPath))
119871
119925
  return;
119872
119926
  // Since isolated modules dont change js files, files affected by change in signature is itself
@@ -119879,7 +119933,9 @@ var ts;
119879
119933
  var currentPath = queue.pop();
119880
119934
  if (!seenFileNamesMap.has(currentPath)) {
119881
119935
  seenFileNamesMap.set(currentPath, true);
119882
- fn(state, currentPath);
119936
+ if (handleDtsMayChangeOfGlobalScope(state, currentPath, cancellationToken, computeHash, host))
119937
+ return;
119938
+ handleDtsMayChangeOf(state, currentPath, cancellationToken, computeHash, host);
119883
119939
  if (isChangedSignature(state, currentPath)) {
119884
119940
  var currentSourceFile = ts.Debug.checkDefined(state.program).getSourceFileByPath(currentPath);
119885
119941
  queue.push.apply(queue, ts.BuilderState.getReferencedByPaths(state, currentSourceFile.resolvedPath));
@@ -119891,56 +119947,38 @@ var ts;
119891
119947
  var seenFileAndExportsOfFile = new ts.Set();
119892
119948
  // Go through exported modules from cache first
119893
119949
  // If exported modules has path, all files referencing file exported from are affected
119894
- (_a = state.currentAffectedFilesExportedModulesMap.getKeys(affectedFile.resolvedPath)) === null || _a === void 0 ? void 0 : _a.forEach(function (exportedFromPath) {
119895
- return forEachFilesReferencingPath(state, exportedFromPath, seenFileAndExportsOfFile, fn);
119896
- });
119897
- // If exported from path is not from cache and exported modules has path, all files referencing file exported from are affected
119898
- (_b = state.exportedModulesMap.getKeys(affectedFile.resolvedPath)) === null || _b === void 0 ? void 0 : _b.forEach(function (exportedFromPath) {
119899
- var _a;
119900
- // If the cache had an updated value, skip
119901
- return !state.currentAffectedFilesExportedModulesMap.hasKey(exportedFromPath) &&
119902
- !((_a = state.currentAffectedFilesExportedModulesMap.deletedKeys()) === null || _a === void 0 ? void 0 : _a.has(exportedFromPath)) &&
119903
- forEachFilesReferencingPath(state, exportedFromPath, seenFileAndExportsOfFile, fn);
119950
+ forEachKeyOfExportedModulesMap(state, affectedFile.resolvedPath, function (exportedFromPath) {
119951
+ if (handleDtsMayChangeOfGlobalScope(state, exportedFromPath, cancellationToken, computeHash, host))
119952
+ return true;
119953
+ var references = state.referencedMap.getKeys(exportedFromPath);
119954
+ return references && ts.forEachKey(references, function (filePath) {
119955
+ return handleDtsMayChangeOfFileAndExportsOfFile(state, filePath, seenFileAndExportsOfFile, cancellationToken, computeHash, host);
119956
+ });
119904
119957
  });
119905
119958
  }
119906
119959
  /**
119907
- * Iterate on files referencing referencedPath
119960
+ * handle dts and semantic diagnostics on file and iterate on anything that exports this file
119961
+ * return true when all work is done and we can exit handling dts emit and semantic diagnostics
119908
119962
  */
119909
- function forEachFilesReferencingPath(state, referencedPath, seenFileAndExportsOfFile, fn) {
119963
+ function handleDtsMayChangeOfFileAndExportsOfFile(state, filePath, seenFileAndExportsOfFile, cancellationToken, computeHash, host) {
119910
119964
  var _a;
119911
- (_a = state.referencedMap.getKeys(referencedPath)) === null || _a === void 0 ? void 0 : _a.forEach(function (filePath) {
119912
- return forEachFileAndExportsOfFile(state, filePath, seenFileAndExportsOfFile, fn);
119913
- });
119914
- }
119915
- /**
119916
- * fn on file and iterate on anything that exports this file
119917
- */
119918
- function forEachFileAndExportsOfFile(state, filePath, seenFileAndExportsOfFile, fn) {
119919
- var _a, _b, _c;
119920
- if (!ts.tryAddToSet(seenFileAndExportsOfFile, filePath)) {
119921
- return;
119922
- }
119923
- fn(state, filePath);
119965
+ if (!ts.tryAddToSet(seenFileAndExportsOfFile, filePath))
119966
+ return undefined;
119967
+ if (handleDtsMayChangeOfGlobalScope(state, filePath, cancellationToken, computeHash, host))
119968
+ return true;
119969
+ handleDtsMayChangeOf(state, filePath, cancellationToken, computeHash, host);
119924
119970
  ts.Debug.assert(!!state.currentAffectedFilesExportedModulesMap);
119925
- // Go through exported modules from cache first
119926
119971
  // If exported modules has path, all files referencing file exported from are affected
119927
- (_a = state.currentAffectedFilesExportedModulesMap.getKeys(filePath)) === null || _a === void 0 ? void 0 : _a.forEach(function (exportedFromPath) {
119928
- return forEachFileAndExportsOfFile(state, exportedFromPath, seenFileAndExportsOfFile, fn);
119929
- });
119930
- // If exported from path is not from cache and exported modules has path, all files referencing file exported from are affected
119931
- (_b = state.exportedModulesMap.getKeys(filePath)) === null || _b === void 0 ? void 0 : _b.forEach(function (exportedFromPath) {
119932
- var _a;
119933
- // If the cache had an updated value, skip
119934
- return !state.currentAffectedFilesExportedModulesMap.hasKey(exportedFromPath) &&
119935
- !((_a = state.currentAffectedFilesExportedModulesMap.deletedKeys()) === null || _a === void 0 ? void 0 : _a.has(exportedFromPath)) &&
119936
- forEachFileAndExportsOfFile(state, exportedFromPath, seenFileAndExportsOfFile, fn);
119972
+ forEachKeyOfExportedModulesMap(state, filePath, function (exportedFromPath) {
119973
+ return handleDtsMayChangeOfFileAndExportsOfFile(state, exportedFromPath, seenFileAndExportsOfFile, cancellationToken, computeHash, host);
119937
119974
  });
119938
119975
  // Remove diagnostics of files that import this file (without going to exports of referencing files)
119939
- (_c = state.referencedMap.getKeys(filePath)) === null || _c === void 0 ? void 0 : _c.forEach(function (referencingFilePath) {
119976
+ (_a = state.referencedMap.getKeys(filePath)) === null || _a === void 0 ? void 0 : _a.forEach(function (referencingFilePath) {
119940
119977
  return !seenFileAndExportsOfFile.has(referencingFilePath) && // Not already removed diagnostic file
119941
- fn(state, referencingFilePath);
119942
- } // Dont add to seen since this is not yet done with the export removal
119943
- );
119978
+ handleDtsMayChangeOf(// Dont add to seen since this is not yet done with the export removal
119979
+ state, referencingFilePath, cancellationToken, computeHash, host);
119980
+ });
119981
+ return undefined;
119944
119982
  }
119945
119983
  /**
119946
119984
  * This is called after completing operation on the next affected file.
@@ -120316,7 +120354,43 @@ var ts;
120316
120354
  return toAffectedFileEmitResult(state,
120317
120355
  // When whole program is affected, do emit only once (eg when --out or --outFile is specified)
120318
120356
  // Otherwise just affected file
120319
- 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);
120357
+ ts.Debug.checkDefined(state.program).emit(affected === state.program ? undefined : affected, affected !== state.program && ts.getEmitDeclarations(state.compilerOptions) && !customTransformers ?
120358
+ getWriteFileUpdatingSignatureCallback(writeFile) :
120359
+ writeFile || ts.maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles || emitKind === 0 /* DtsOnly */, customTransformers), affected, emitKind, isPendingEmitFile);
120360
+ }
120361
+ function getWriteFileUpdatingSignatureCallback(writeFile) {
120362
+ return function (fileName, text, writeByteOrderMark, onError, sourceFiles, data) {
120363
+ var _a;
120364
+ if (ts.isDeclarationFileName(fileName)) {
120365
+ ts.Debug.assert((sourceFiles === null || sourceFiles === void 0 ? void 0 : sourceFiles.length) === 1);
120366
+ var file = sourceFiles[0];
120367
+ var info = state.fileInfos.get(file.resolvedPath);
120368
+ var signature = ((_a = state.currentAffectedFilesSignatures) === null || _a === void 0 ? void 0 : _a.get(file.resolvedPath)) || info.signature;
120369
+ if (signature === file.version) {
120370
+ var newSignature = (computeHash || ts.generateDjb2Hash)((data === null || data === void 0 ? void 0 : data.sourceMapUrlPos) !== undefined ? text.substring(0, data.sourceMapUrlPos) : text);
120371
+ if (newSignature !== file.version) { // Update it
120372
+ if (host.storeFilesChangingSignatureDuringEmit)
120373
+ (state.filesChangingSignature || (state.filesChangingSignature = new ts.Set())).add(file.resolvedPath);
120374
+ if (state.exportedModulesMap)
120375
+ ts.BuilderState.updateExportedModules(file, file.exportedModulesFromDeclarationEmit, state.currentAffectedFilesExportedModulesMap || (state.currentAffectedFilesExportedModulesMap = ts.BuilderState.createManyToManyPathMap()));
120376
+ if (state.affectedFiles && state.affectedFilesIndex < state.affectedFiles.length) {
120377
+ state.currentAffectedFilesSignatures.set(file.resolvedPath, newSignature);
120378
+ }
120379
+ else {
120380
+ info.signature = newSignature;
120381
+ if (state.exportedModulesMap)
120382
+ ts.BuilderState.updateExportedFilesMapFromCache(state, state.currentAffectedFilesExportedModulesMap);
120383
+ }
120384
+ }
120385
+ }
120386
+ }
120387
+ if (writeFile)
120388
+ writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
120389
+ else if (host.writeFile)
120390
+ host.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
120391
+ else
120392
+ state.program.writeFile(fileName, text, writeByteOrderMark, onError, sourceFiles, data);
120393
+ };
120320
120394
  }
120321
120395
  /**
120322
120396
  * Emits the JavaScript and declaration files.
@@ -120373,7 +120447,9 @@ var ts;
120373
120447
  }
120374
120448
  }
120375
120449
  }
120376
- return ts.Debug.checkDefined(state.program).emit(targetSourceFile, writeFile || ts.maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
120450
+ return ts.Debug.checkDefined(state.program).emit(targetSourceFile, !ts.outFile(state.compilerOptions) && ts.getEmitDeclarations(state.compilerOptions) && !customTransformers ?
120451
+ getWriteFileUpdatingSignatureCallback(writeFile) :
120452
+ writeFile || ts.maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
120377
120453
  }
120378
120454
  /**
120379
120455
  * Return the semantic diagnostics for the next affected file or undefined if iteration is complete
@@ -122565,6 +122641,7 @@ var ts;
122565
122641
  createHash: ts.maybeBind(host, host.createHash),
122566
122642
  readDirectory: ts.maybeBind(host, host.readDirectory),
122567
122643
  disableUseFileVersionAsSignature: host.disableUseFileVersionAsSignature,
122644
+ storeFilesChangingSignatureDuringEmit: host.storeFilesChangingSignatureDuringEmit,
122568
122645
  };
122569
122646
  function writeFile(fileName, text, writeByteOrderMark, onError) {
122570
122647
  try {
@@ -122624,6 +122701,7 @@ var ts;
122624
122701
  createHash: ts.maybeBind(system, system.createHash),
122625
122702
  createProgram: createProgram || ts.createEmitAndSemanticDiagnosticsBuilderProgram,
122626
122703
  disableUseFileVersionAsSignature: system.disableUseFileVersionAsSignature,
122704
+ storeFilesChangingSignatureDuringEmit: system.storeFilesChangingSignatureDuringEmit,
122627
122705
  };
122628
122706
  }
122629
122707
  ts.createProgramHost = createProgramHost;
@@ -122712,6 +122790,7 @@ var ts;
122712
122790
  var host = ts.createCompilerHostWorker(options, /*setParentNodes*/ undefined, system);
122713
122791
  host.createHash = ts.maybeBind(system, system.createHash);
122714
122792
  host.disableUseFileVersionAsSignature = system.disableUseFileVersionAsSignature;
122793
+ host.storeFilesChangingSignatureDuringEmit = system.storeFilesChangingSignatureDuringEmit;
122715
122794
  ts.setGetSourceFileAsHashVersioned(host, system);
122716
122795
  ts.changeCompilerHostLikeToUseCache(host, function (fileName) { return ts.toPath(fileName, host.getCurrentDirectory(), host.getCanonicalFileName); });
122717
122796
  return host;
@@ -131044,7 +131123,7 @@ var ts;
131044
131123
  GlobalsSearch[GlobalsSearch["Success"] = 1] = "Success";
131045
131124
  GlobalsSearch[GlobalsSearch["Fail"] = 2] = "Fail";
131046
131125
  })(GlobalsSearch || (GlobalsSearch = {}));
131047
- function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, preferences, isForImportStatementCompletion, cb) {
131126
+ function resolvingModuleSpecifiers(logPrefix, host, program, sourceFile, position, preferences, isForImportStatementCompletion, isValidTypeOnlyUseSite, cb) {
131048
131127
  var _a, _b, _c;
131049
131128
  var start = ts.timestamp();
131050
131129
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
@@ -131059,9 +131138,9 @@ var ts;
131059
131138
  (_b = host.log) === null || _b === void 0 ? void 0 : _b.call(host, logPrefix + ": response is " + (resolutionLimitExceeded ? "incomplete" : "complete"));
131060
131139
  (_c = host.log) === null || _c === void 0 ? void 0 : _c.call(host, logPrefix + ": " + (ts.timestamp() - start));
131061
131140
  return result;
131062
- function tryResolve(exportInfo, isFromAmbientModule) {
131141
+ function tryResolve(exportInfo, symbolName, isFromAmbientModule) {
131063
131142
  if (isFromAmbientModule) {
131064
- var result_1 = ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, sourceFile, program, host, preferences);
131143
+ var result_1 = ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences);
131065
131144
  if (result_1) {
131066
131145
  ambientCount++;
131067
131146
  }
@@ -131070,7 +131149,7 @@ var ts;
131070
131149
  var shouldResolveModuleSpecifier = isForImportStatementCompletion || preferences.allowIncompleteCompletions && resolvedCount < Completions.moduleSpecifierResolutionLimit;
131071
131150
  var shouldGetModuleSpecifierFromCache = !shouldResolveModuleSpecifier && preferences.allowIncompleteCompletions && cacheAttemptCount < Completions.moduleSpecifierResolutionCacheAttemptLimit;
131072
131151
  var result = (shouldResolveModuleSpecifier || shouldGetModuleSpecifierFromCache)
131073
- ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
131152
+ ? ts.codefix.getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, sourceFile, program, host, preferences, packageJsonImportFilter, shouldGetModuleSpecifierFromCache)
131074
131153
  : undefined;
131075
131154
  if (!shouldResolveModuleSpecifier && !shouldGetModuleSpecifierFromCache || shouldGetModuleSpecifierFromCache && !result) {
131076
131155
  resolutionLimitExceeded = true;
@@ -131175,8 +131254,8 @@ var ts;
131175
131254
  return undefined;
131176
131255
  var lowerCaseTokenText = location.text.toLowerCase();
131177
131256
  var exportMap = ts.getExportInfoMap(file, host, program, cancellationToken);
131178
- var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, program, file, preferences,
131179
- /*isForImportStatementCompletion*/ false, function (context) {
131257
+ var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, program, file, location.getStart(), preferences,
131258
+ /*isForImportStatementCompletion*/ false, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
131180
131259
  var entries = ts.mapDefined(previousResponse.entries, function (entry) {
131181
131260
  if (!entry.hasAction || !entry.source || !entry.data || completionEntryDataIsResolved(entry.data)) {
131182
131261
  // Not an auto import or already resolved; keep as is
@@ -131188,7 +131267,7 @@ var ts;
131188
131267
  }
131189
131268
  var origin = ts.Debug.checkDefined(getAutoImportSymbolFromCompletionEntryData(entry.name, entry.data, program, host)).origin;
131190
131269
  var info = exportMap.get(file.path, entry.data.exportMapKey);
131191
- var result = info && context.tryResolve(info, !ts.isExternalModuleNameRelative(ts.stripQuotes(origin.moduleSymbol.name)));
131270
+ var result = info && context.tryResolve(info, entry.name, !ts.isExternalModuleNameRelative(ts.stripQuotes(origin.moduleSymbol.name)));
131192
131271
  if (!result)
131193
131272
  return entry;
131194
131273
  var newOrigin = __assign(__assign({}, origin), { kind: 32 /* ResolvedExport */, moduleSpecifier: result.moduleSpecifier });
@@ -131780,22 +131859,44 @@ var ts;
131780
131859
  }
131781
131860
  }
131782
131861
  function createSnippetPrinter(printerOptions) {
131862
+ var escapes;
131783
131863
  var baseWriter = ts.textChanges.createWriter(ts.getNewLineCharacter(printerOptions));
131784
131864
  var printer = ts.createPrinter(printerOptions, baseWriter);
131785
- 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)); } });
131865
+ 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); }); } });
131786
131866
  return {
131787
131867
  printSnippetList: printSnippetList,
131788
131868
  printAndFormatSnippetList: printAndFormatSnippetList,
131789
131869
  };
131870
+ // The formatter/scanner will have issues with snippet-escaped text,
131871
+ // so instead of writing the escaped text directly to the writer,
131872
+ // generate a set of changes that can be applied to the unescaped text
131873
+ // to escape it post-formatting.
131874
+ function escapingWrite(s, write) {
131875
+ var escaped = ts.escapeSnippetText(s);
131876
+ if (escaped !== s) {
131877
+ var start = baseWriter.getTextPos();
131878
+ write();
131879
+ var end = baseWriter.getTextPos();
131880
+ escapes = ts.append(escapes || (escapes = []), { newText: escaped, span: { start: start, length: end - start } });
131881
+ }
131882
+ else {
131883
+ write();
131884
+ }
131885
+ }
131790
131886
  /* Snippet-escaping version of `printer.printList`. */
131791
131887
  function printSnippetList(format, list, sourceFile) {
131888
+ var unescaped = printUnescapedSnippetList(format, list, sourceFile);
131889
+ return escapes ? ts.textChanges.applyChanges(unescaped, escapes) : unescaped;
131890
+ }
131891
+ function printUnescapedSnippetList(format, list, sourceFile) {
131892
+ escapes = undefined;
131792
131893
  writer.clear();
131793
131894
  printer.writeList(format, list, sourceFile, writer);
131794
131895
  return writer.getText();
131795
131896
  }
131796
131897
  function printAndFormatSnippetList(format, list, sourceFile, formatContext) {
131797
131898
  var syntheticFile = {
131798
- text: printSnippetList(format, list, sourceFile),
131899
+ text: printUnescapedSnippetList(format, list, sourceFile),
131799
131900
  getLineAndCharacterOfPosition: function (pos) {
131800
131901
  return ts.getLineAndCharacterOfPosition(this, pos);
131801
131902
  },
@@ -131807,7 +131908,10 @@ var ts;
131807
131908
  /* indentation */ 0,
131808
131909
  /* delta */ 0, __assign(__assign({}, formatContext), { options: formatOptions }));
131809
131910
  });
131810
- return ts.textChanges.applyChanges(syntheticFile.text, changes);
131911
+ var allChanges = escapes
131912
+ ? ts.stableSort(ts.concatenate(changes, escapes), function (a, b) { return ts.compareTextSpans(a.span, b.span); })
131913
+ : changes;
131914
+ return ts.textChanges.applyChanges(syntheticFile.text, allChanges);
131811
131915
  }
131812
131916
  }
131813
131917
  function originToCompletionEntryData(origin) {
@@ -132699,7 +132803,7 @@ var ts;
132699
132803
  moduleSymbol: moduleSymbol,
132700
132804
  symbol: firstAccessibleSymbol,
132701
132805
  targetFlags: ts.skipAlias(firstAccessibleSymbol, typeChecker).flags,
132702
- }], sourceFile, program, host, preferences) || {}).moduleSpecifier;
132806
+ }], firstAccessibleSymbol.name, position, ts.isValidTypeOnlyAliasUseSite(location), sourceFile, program, host, preferences) || {}).moduleSpecifier;
132703
132807
  if (moduleSpecifier) {
132704
132808
  var origin = {
132705
132809
  kind: getNullableSymbolOriginInfoKind(6 /* SymbolMemberExport */),
@@ -132954,7 +133058,7 @@ var ts;
132954
133058
  var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
132955
133059
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
132956
133060
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
132957
- resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, preferences, !!importCompletionNode, function (context) {
133061
+ resolvingModuleSpecifiers("collectAutoImports", host, program, sourceFile, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
132958
133062
  exportInfo.search(sourceFile.path,
132959
133063
  /*preferCapitalized*/ isRightOfOpenTag, function (symbolName, targetFlags) {
132960
133064
  if (!ts.isIdentifierText(symbolName, ts.getEmitScriptTarget(host.getCompilationSettings())))
@@ -132982,7 +133086,7 @@ var ts;
132982
133086
  }
132983
133087
  // If we don't need to resolve module specifiers, we can use any re-export that is importable at all
132984
133088
  // (We need to ensure that at least one is importable to show a completion.)
132985
- var _a = context.tryResolve(info, isFromAmbientModule) || {}, _b = _a.exportInfo, exportInfo = _b === void 0 ? defaultExportInfo : _b, moduleSpecifier = _a.moduleSpecifier;
133089
+ var _a = context.tryResolve(info, symbolName, isFromAmbientModule) || {}, _b = _a.exportInfo, exportInfo = _b === void 0 ? defaultExportInfo : _b, moduleSpecifier = _a.moduleSpecifier;
132986
133090
  var isDefaultExport = exportInfo.exportKind === 1 /* Default */;
132987
133091
  var symbol = isDefaultExport && ts.getLocalSymbolForExportDefault(exportInfo.symbol) || exportInfo.symbol;
132988
133092
  pushAutoImportSymbol(symbol, {
@@ -151806,7 +151910,7 @@ var ts;
151806
151910
  var symbol = checker.getMergedSymbol(ts.skipAlias(exportedSymbol, checker));
151807
151911
  var exportInfo = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, /*isJsxTagName*/ false, host, program, preferences, useAutoImportProvider);
151808
151912
  var useRequire = shouldUseRequire(sourceFile, program);
151809
- var fix = getImportFixForSymbol(sourceFile, exportInfo, moduleSymbol, symbolName, program, /*position*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
151913
+ var fix = getImportFixForSymbol(sourceFile, exportInfo, moduleSymbol, program, /*useNamespaceInfo*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
151810
151914
  if (fix) {
151811
151915
  addImport({ fixes: [fix], symbolName: symbolName, errorIdentifierText: undefined });
151812
151916
  }
@@ -151976,7 +152080,7 @@ var ts;
151976
152080
  : getAllReExportingModules(sourceFile, targetSymbol, moduleSymbol, symbolName, isJsxTagName, host, program, preferences, /*useAutoImportProvider*/ true);
151977
152081
  var useRequire = shouldUseRequire(sourceFile, program);
151978
152082
  var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
151979
- var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences));
152083
+ var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, program, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite, useRequire, host, preferences));
151980
152084
  return {
151981
152085
  moduleSpecifier: fix.moduleSpecifier,
151982
152086
  codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix,
@@ -151992,10 +152096,10 @@ var ts;
151992
152096
  return fix && codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, includeSymbolNameInDescription, 1 /* Double */, compilerOptions));
151993
152097
  }
151994
152098
  codefix.getPromoteTypeOnlyCompletionAction = getPromoteTypeOnlyCompletionAction;
151995
- function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
152099
+ function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, program, useNamespaceInfo, isValidTypeOnlyUseSite, useRequire, host, preferences) {
151996
152100
  ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
151997
152101
  var packageJsonImportFilter = ts.createPackageJsonImportFilter(sourceFile, preferences, host);
151998
- return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, packageJsonImportFilter, host);
152102
+ return getBestFix(getImportFixes(exportInfos, useNamespaceInfo, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences).fixes, sourceFile, program, packageJsonImportFilter, host);
151999
152103
  }
152000
152104
  function codeFixActionToCodeAction(_a) {
152001
152105
  var description = _a.description, changes = _a.changes, commands = _a.commands;
@@ -152050,25 +152154,32 @@ var ts;
152050
152154
  return !moduleFile || ts.isImportableFile(program, importingFile, moduleFile, preferences, /*packageJsonFilter*/ undefined, getModuleSpecifierResolutionHost(isFromPackageJson), (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host));
152051
152155
  }
152052
152156
  }
152053
- function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
152054
- var _a = getNewImportFixes(program, importingFile,
152055
- /*position*/ undefined,
152056
- /*isValidTypeOnlyUseSite*/ false,
152057
- /*useRequire*/ false, exportInfo, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
152157
+ function getModuleSpecifierForBestExportInfo(exportInfo, symbolName, position, isValidTypeOnlyUseSite, importingFile, program, host, preferences, packageJsonImportFilter, fromCacheOnly) {
152158
+ var _a = getImportFixes(exportInfo, { symbolName: symbolName, position: position }, isValidTypeOnlyUseSite,
152159
+ /*useRequire*/ false, program, importingFile, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
152058
152160
  var result = getBestFix(fixes, importingFile, program, packageJsonImportFilter || ts.createPackageJsonImportFilter(importingFile, preferences, host), host);
152059
152161
  return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
152060
152162
  }
152061
152163
  codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
152062
- function getImportFixes(exportInfos, symbolName,
152164
+ function getImportFixes(exportInfos, useNamespaceInfo,
152063
152165
  /** undefined only for missing JSX namespace */
152064
- position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences) {
152166
+ isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, fromCacheOnly) {
152065
152167
  var checker = program.getTypeChecker();
152066
152168
  var existingImports = ts.flatMap(exportInfos, function (info) { return getExistingImportDeclarations(info, checker, sourceFile, program.getCompilerOptions()); });
152067
- var useNamespace = position === undefined ? undefined : tryUseExistingNamespaceImport(existingImports, symbolName, position, checker);
152169
+ var useNamespace = useNamespaceInfo && tryUseExistingNamespaceImport(existingImports, useNamespaceInfo.symbolName, useNamespaceInfo.position, checker);
152068
152170
  var addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
152069
- // Don't bother providing an action to add a new import if we can add to an existing one.
152070
- var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences);
152071
- return __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), addImport, true);
152171
+ if (addToExisting) {
152172
+ // Don't bother providing an action to add a new import if we can add to an existing one.
152173
+ return {
152174
+ computedWithoutCacheCount: 0,
152175
+ fixes: __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), [addToExisting], false),
152176
+ };
152177
+ }
152178
+ 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;
152179
+ return {
152180
+ computedWithoutCacheCount: computedWithoutCacheCount,
152181
+ fixes: __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), fixes, true),
152182
+ };
152072
152183
  }
152073
152184
  function tryUseExistingNamespaceImport(existingImports, symbolName, position, checker) {
152074
152185
  // It is possible that multiple import statements with the same specifier exist in the file.
@@ -152258,9 +152369,9 @@ var ts;
152258
152369
  });
152259
152370
  return { computedWithoutCacheCount: computedWithoutCacheCount, fixes: fixes };
152260
152371
  }
152261
- function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
152372
+ function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences, fromCacheOnly) {
152262
152373
  var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info, isValidTypeOnlyUseSite, useRequire, program.getTypeChecker(), program.getCompilerOptions()); });
152263
- return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences).fixes;
152374
+ return existingDeclaration ? { fixes: [existingDeclaration] } : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences, fromCacheOnly);
152264
152375
  }
152265
152376
  function newImportInfoFromExistingSpecifier(_a, isValidTypeOnlyUseSite, useRequire, checker, compilerOptions) {
152266
152377
  var _b;
@@ -152356,7 +152467,8 @@ var ts;
152356
152467
  var symbolName = umdSymbol.name;
152357
152468
  var exportInfo = [{ symbol: umdSymbol, moduleSymbol: symbol, moduleFileName: undefined, exportKind: 3 /* UMD */, targetFlags: symbol.flags, isFromPackageJson: false }];
152358
152469
  var useRequire = shouldUseRequire(sourceFile, program);
152359
- var fixes = getImportFixes(exportInfo, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences);
152470
+ var position = ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined;
152471
+ var fixes = getImportFixes(exportInfo, position ? { position: position, symbolName: symbolName } : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences).fixes;
152360
152472
  return { fixes: fixes, symbolName: symbolName, errorIdentifierText: (_b = ts.tryCast(token, ts.isIdentifier)) === null || _b === void 0 ? void 0 : _b.text };
152361
152473
  }
152362
152474
  function getUmdSymbol(token, checker) {
@@ -152428,7 +152540,7 @@ var ts;
152428
152540
  var exportInfo = getExportInfos(symbolName, ts.isJSXTagName(symbolToken), ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
152429
152541
  var fixes = ts.arrayFrom(ts.flatMapIterator(exportInfo.entries(), function (_a) {
152430
152542
  var _ = _a[0], exportInfos = _a[1];
152431
- return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences);
152543
+ return getImportFixes(exportInfos, { symbolName: symbolName, position: symbolToken.getStart(sourceFile) }, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences).fixes;
152432
152544
  }));
152433
152545
  return { fixes: fixes, symbolName: symbolName, errorIdentifierText: symbolToken.text };
152434
152546
  }