typescript 4.8.0-dev.20220616 → 4.8.0-dev.20220619

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
@@ -109,7 +109,7 @@ var ts;
109
109
  // The following is baselined as a literal template type without intervention
110
110
  /** The version of the TypeScript compiler release */
111
111
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
112
- ts.version = ts.versionMajorMinor + ".0-dev.20220616";
112
+ ts.version = ts.versionMajorMinor + ".0-dev.20220619";
113
113
  /* @internal */
114
114
  var Comparison;
115
115
  (function (Comparison) {
@@ -9672,6 +9672,8 @@ var ts;
9672
9672
  Qualified_name_0_is_not_allowed_without_a_leading_param_object_1: diag(8032, ts.DiagnosticCategory.Error, "Qualified_name_0_is_not_allowed_without_a_leading_param_object_1_8032", "Qualified name '{0}' is not allowed without a leading '@param {object} {1}'."),
9673
9673
  A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags: diag(8033, ts.DiagnosticCategory.Error, "A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags_8033", "A JSDoc '@typedef' comment may not contain multiple '@type' tags."),
9674
9674
  The_tag_was_first_specified_here: diag(8034, ts.DiagnosticCategory.Error, "The_tag_was_first_specified_here_8034", "The tag was first specified here."),
9675
+ You_cannot_rename_elements_that_are_defined_in_a_node_modules_folder: diag(8035, ts.DiagnosticCategory.Error, "You_cannot_rename_elements_that_are_defined_in_a_node_modules_folder_8035", "You cannot rename elements that are defined in a 'node_modules' folder."),
9676
+ You_cannot_rename_elements_that_are_defined_in_another_node_modules_folder: diag(8036, ts.DiagnosticCategory.Error, "You_cannot_rename_elements_that_are_defined_in_another_node_modules_folder_8036", "You cannot rename elements that are defined in another 'node_modules' folder."),
9675
9677
  Declaration_emit_for_this_file_requires_using_private_name_0_An_explicit_type_annotation_may_unblock_declaration_emit: diag(9005, ts.DiagnosticCategory.Error, "Declaration_emit_for_this_file_requires_using_private_name_0_An_explicit_type_annotation_may_unblock_9005", "Declaration emit for this file requires using private name '{0}'. An explicit type annotation may unblock declaration emit."),
9676
9678
  Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotation_may_unblock_declaration_emit: diag(9006, ts.DiagnosticCategory.Error, "Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotati_9006", "Declaration emit for this file requires using private name '{0}' from module '{1}'. An explicit type annotation may unblock declaration emit."),
9677
9679
  JSX_attributes_must_only_be_assigned_a_non_empty_expression: diag(17000, ts.DiagnosticCategory.Error, "JSX_attributes_must_only_be_assigned_a_non_empty_expression_17000", "JSX attributes must only be assigned a non-empty 'expression'."),
@@ -9942,6 +9944,9 @@ var ts;
9942
9944
  For_await_loops_cannot_be_used_inside_a_class_static_block: diag(18038, ts.DiagnosticCategory.Error, "For_await_loops_cannot_be_used_inside_a_class_static_block_18038", "'For await' loops cannot be used inside a class static block."),
9943
9945
  Invalid_use_of_0_It_cannot_be_used_inside_a_class_static_block: diag(18039, ts.DiagnosticCategory.Error, "Invalid_use_of_0_It_cannot_be_used_inside_a_class_static_block_18039", "Invalid use of '{0}'. It cannot be used inside a class static block."),
9944
9946
  A_return_statement_cannot_be_used_inside_a_class_static_block: diag(18041, ts.DiagnosticCategory.Error, "A_return_statement_cannot_be_used_inside_a_class_static_block_18041", "A 'return' statement cannot be used inside a class static block."),
9947
+ _0_is_a_type_and_cannot_be_imported_in_JavaScript_files_Use_1_in_a_JSDoc_type_annotation: diag(18042, ts.DiagnosticCategory.Error, "_0_is_a_type_and_cannot_be_imported_in_JavaScript_files_Use_1_in_a_JSDoc_type_annotation_18042", "'{0}' is a type and cannot be imported in JavaScript files. Use '{1}' in a JSDoc type annotation."),
9948
+ Types_cannot_appear_in_export_declarations_in_JavaScript_files: diag(18043, ts.DiagnosticCategory.Error, "Types_cannot_appear_in_export_declarations_in_JavaScript_files_18043", "Types cannot appear in export declarations in JavaScript files."),
9949
+ _0_is_automatically_exported_here: diag(18044, ts.DiagnosticCategory.Message, "_0_is_automatically_exported_here_18044", "'{0}' is automatically exported here."),
9945
9950
  };
9946
9951
  })(ts || (ts = {}));
9947
9952
  var ts;
@@ -34530,10 +34535,10 @@ var ts;
34530
34535
  setDecoratorContext(/*val*/ false);
34531
34536
  }
34532
34537
  var pos = getNodePos();
34533
- var expr = parseAssignmentExpressionOrHigher();
34538
+ var expr = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
34534
34539
  var operatorToken;
34535
34540
  while ((operatorToken = parseOptionalToken(27 /* CommaToken */))) {
34536
- expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(), pos);
34541
+ expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true), pos);
34537
34542
  }
34538
34543
  if (saveDecoratorContext) {
34539
34544
  setDecoratorContext(/*val*/ true);
@@ -34541,9 +34546,9 @@ var ts;
34541
34546
  return expr;
34542
34547
  }
34543
34548
  function parseInitializer() {
34544
- return parseOptional(63 /* EqualsToken */) ? parseAssignmentExpressionOrHigher() : undefined;
34549
+ return parseOptional(63 /* EqualsToken */) ? parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true) : undefined;
34545
34550
  }
34546
- function parseAssignmentExpressionOrHigher() {
34551
+ function parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction) {
34547
34552
  // AssignmentExpression[in,yield]:
34548
34553
  // 1) ConditionalExpression[?in,?yield]
34549
34554
  // 2) LeftHandSideExpression = AssignmentExpression[?in,?yield]
@@ -34569,7 +34574,7 @@ var ts;
34569
34574
  // If we do successfully parse arrow-function, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is
34570
34575
  // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done
34571
34576
  // with AssignmentExpression if we see one.
34572
- var arrowExpression = tryParseParenthesizedArrowFunctionExpression() || tryParseAsyncSimpleArrowFunctionExpression();
34577
+ var arrowExpression = tryParseParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction) || tryParseAsyncSimpleArrowFunctionExpression(allowReturnTypeInArrowFunction);
34573
34578
  if (arrowExpression) {
34574
34579
  return arrowExpression;
34575
34580
  }
@@ -34588,7 +34593,7 @@ var ts;
34588
34593
  // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single
34589
34594
  // identifier and the current token is an arrow.
34590
34595
  if (expr.kind === 79 /* Identifier */ && token() === 38 /* EqualsGreaterThanToken */) {
34591
- return parseSimpleArrowFunctionExpression(pos, expr, /*asyncModifier*/ undefined);
34596
+ return parseSimpleArrowFunctionExpression(pos, expr, allowReturnTypeInArrowFunction, /*asyncModifier*/ undefined);
34592
34597
  }
34593
34598
  // Now see if we might be in cases '2' or '3'.
34594
34599
  // If the expression was a LHS expression, and we have an assignment operator, then
@@ -34597,10 +34602,10 @@ var ts;
34597
34602
  // Note: we call reScanGreaterToken so that we get an appropriately merged token
34598
34603
  // for cases like `> > =` becoming `>>=`
34599
34604
  if (ts.isLeftHandSideExpression(expr) && ts.isAssignmentOperator(reScanGreaterToken())) {
34600
- return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(), pos);
34605
+ return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction), pos);
34601
34606
  }
34602
34607
  // It wasn't an assignment or a lambda. This is a conditional expression:
34603
- return parseConditionalExpressionRest(expr, pos);
34608
+ return parseConditionalExpressionRest(expr, pos, allowReturnTypeInArrowFunction);
34604
34609
  }
34605
34610
  function isYieldExpression() {
34606
34611
  if (token() === 125 /* YieldKeyword */) {
@@ -34640,7 +34645,7 @@ var ts;
34640
34645
  nextToken();
34641
34646
  if (!scanner.hasPrecedingLineBreak() &&
34642
34647
  (token() === 41 /* AsteriskToken */ || isStartOfExpression())) {
34643
- return finishNode(factory.createYieldExpression(parseOptionalToken(41 /* AsteriskToken */), parseAssignmentExpressionOrHigher()), pos);
34648
+ return finishNode(factory.createYieldExpression(parseOptionalToken(41 /* AsteriskToken */), parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true)), pos);
34644
34649
  }
34645
34650
  else {
34646
34651
  // if the next token is not on the same line as yield. or we don't have an '*' or
@@ -34648,7 +34653,7 @@ var ts;
34648
34653
  return finishNode(factory.createYieldExpression(/*asteriskToken*/ undefined, /*expression*/ undefined), pos);
34649
34654
  }
34650
34655
  }
34651
- function parseSimpleArrowFunctionExpression(pos, identifier, asyncModifier) {
34656
+ function parseSimpleArrowFunctionExpression(pos, identifier, allowReturnTypeInArrowFunction, asyncModifier) {
34652
34657
  ts.Debug.assert(token() === 38 /* EqualsGreaterThanToken */, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
34653
34658
  var parameter = factory.createParameterDeclaration(
34654
34659
  /*modifiers*/ undefined,
@@ -34659,11 +34664,11 @@ var ts;
34659
34664
  finishNode(parameter, identifier.pos);
34660
34665
  var parameters = createNodeArray([parameter], parameter.pos, parameter.end);
34661
34666
  var equalsGreaterThanToken = parseExpectedToken(38 /* EqualsGreaterThanToken */);
34662
- var body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier);
34667
+ var body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier, allowReturnTypeInArrowFunction);
34663
34668
  var node = factory.createArrowFunction(asyncModifier, /*typeParameters*/ undefined, parameters, /*type*/ undefined, equalsGreaterThanToken, body);
34664
34669
  return addJSDocComment(finishNode(node, pos));
34665
34670
  }
34666
- function tryParseParenthesizedArrowFunctionExpression() {
34671
+ function tryParseParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction) {
34667
34672
  var triState = isParenthesizedArrowFunctionExpression();
34668
34673
  if (triState === 0 /* False */) {
34669
34674
  // It's definitely not a parenthesized arrow function expression.
@@ -34674,8 +34679,8 @@ var ts;
34674
34679
  // it out, but don't allow any ambiguity, and return 'undefined' if this could be an
34675
34680
  // expression instead.
34676
34681
  return triState === 1 /* True */ ?
34677
- parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true) :
34678
- tryParse(parsePossibleParenthesizedArrowFunctionExpression);
34682
+ parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true, /*allowReturnTypeInArrowFunction*/ true) :
34683
+ tryParse(function () { return parsePossibleParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction); });
34679
34684
  }
34680
34685
  // True -> We definitely expect a parenthesized arrow function here.
34681
34686
  // False -> There *cannot* be a parenthesized arrow function here.
@@ -34809,25 +34814,25 @@ var ts;
34809
34814
  return 2 /* Unknown */;
34810
34815
  }
34811
34816
  }
34812
- function parsePossibleParenthesizedArrowFunctionExpression() {
34817
+ function parsePossibleParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction) {
34813
34818
  var tokenPos = scanner.getTokenPos();
34814
34819
  if (notParenthesizedArrow === null || notParenthesizedArrow === void 0 ? void 0 : notParenthesizedArrow.has(tokenPos)) {
34815
34820
  return undefined;
34816
34821
  }
34817
- var result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false);
34822
+ var result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false, allowReturnTypeInArrowFunction);
34818
34823
  if (!result) {
34819
34824
  (notParenthesizedArrow || (notParenthesizedArrow = new ts.Set())).add(tokenPos);
34820
34825
  }
34821
34826
  return result;
34822
34827
  }
34823
- function tryParseAsyncSimpleArrowFunctionExpression() {
34828
+ function tryParseAsyncSimpleArrowFunctionExpression(allowReturnTypeInArrowFunction) {
34824
34829
  // We do a check here so that we won't be doing unnecessarily call to "lookAhead"
34825
34830
  if (token() === 131 /* AsyncKeyword */) {
34826
34831
  if (lookAhead(isUnParenthesizedAsyncArrowFunctionWorker) === 1 /* True */) {
34827
34832
  var pos = getNodePos();
34828
34833
  var asyncModifier = parseModifiersForArrowFunction();
34829
34834
  var expr = parseBinaryExpressionOrHigher(0 /* Lowest */);
34830
- return parseSimpleArrowFunctionExpression(pos, expr, asyncModifier);
34835
+ return parseSimpleArrowFunctionExpression(pos, expr, allowReturnTypeInArrowFunction, asyncModifier);
34831
34836
  }
34832
34837
  }
34833
34838
  return undefined;
@@ -34851,7 +34856,7 @@ var ts;
34851
34856
  }
34852
34857
  return 0 /* False */;
34853
34858
  }
34854
- function parseParenthesizedArrowFunctionExpression(allowAmbiguity) {
34859
+ function parseParenthesizedArrowFunctionExpression(allowAmbiguity, allowReturnTypeInArrowFunction) {
34855
34860
  var pos = getNodePos();
34856
34861
  var hasJSDoc = hasPrecedingJSDocComment();
34857
34862
  var modifiers = parseModifiersForArrowFunction();
@@ -34886,6 +34891,7 @@ var ts;
34886
34891
  return undefined;
34887
34892
  }
34888
34893
  }
34894
+ var hasReturnColon = token() === 58 /* ColonToken */;
34889
34895
  var type = parseReturnType(58 /* ColonToken */, /*isType*/ false);
34890
34896
  if (type && !allowAmbiguity && typeHasArrowFunctionBlockingParseError(type)) {
34891
34897
  return undefined;
@@ -34914,12 +34920,37 @@ var ts;
34914
34920
  var lastToken = token();
34915
34921
  var equalsGreaterThanToken = parseExpectedToken(38 /* EqualsGreaterThanToken */);
34916
34922
  var body = (lastToken === 38 /* EqualsGreaterThanToken */ || lastToken === 18 /* OpenBraceToken */)
34917
- ? parseArrowFunctionExpressionBody(ts.some(modifiers, ts.isAsyncModifier))
34923
+ ? parseArrowFunctionExpressionBody(ts.some(modifiers, ts.isAsyncModifier), allowReturnTypeInArrowFunction)
34918
34924
  : parseIdentifier();
34925
+ // Given:
34926
+ // x ? y => ({ y }) : z => ({ z })
34927
+ // We try to parse the body of the first arrow function by looking at:
34928
+ // ({ y }) : z => ({ z })
34929
+ // This is a valid arrow function with "z" as the return type.
34930
+ //
34931
+ // But, if we're in the true side of a conditional expression, this colon
34932
+ // terminates the expression, so we cannot allow a return type if we aren't
34933
+ // certain whether or not the preceding text was parsed as a parameter list.
34934
+ //
34935
+ // For example,
34936
+ // a() ? (b: number, c?: string): void => d() : e
34937
+ // is determined by isParenthesizedArrowFunctionExpression to unambiguously
34938
+ // be an arrow expression, so we allow a return type.
34939
+ if (!allowReturnTypeInArrowFunction && hasReturnColon) {
34940
+ // However, if the arrow function we were able to parse is followed by another colon
34941
+ // as in:
34942
+ // a ? (x): string => x : null
34943
+ // Then allow the arrow function, and treat the second colon as terminating
34944
+ // the conditional expression. It's okay to do this because this code would
34945
+ // be a syntax error in JavaScript (as the second colon shouldn't be there).
34946
+ if (token() !== 58 /* ColonToken */) {
34947
+ return undefined;
34948
+ }
34949
+ }
34919
34950
  var node = factory.createArrowFunction(modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body);
34920
34951
  return withJSDoc(finishNode(node, pos), hasJSDoc);
34921
34952
  }
34922
- function parseArrowFunctionExpressionBody(isAsync) {
34953
+ function parseArrowFunctionExpressionBody(isAsync, allowReturnTypeInArrowFunction) {
34923
34954
  if (token() === 18 /* OpenBraceToken */) {
34924
34955
  return parseFunctionBlock(isAsync ? 2 /* Await */ : 0 /* None */);
34925
34956
  }
@@ -34947,12 +34978,12 @@ var ts;
34947
34978
  var savedTopLevel = topLevel;
34948
34979
  topLevel = false;
34949
34980
  var node = isAsync
34950
- ? doInAwaitContext(parseAssignmentExpressionOrHigher)
34951
- : doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher);
34981
+ ? doInAwaitContext(function () { return parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction); })
34982
+ : doOutsideOfAwaitContext(function () { return parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction); });
34952
34983
  topLevel = savedTopLevel;
34953
34984
  return node;
34954
34985
  }
34955
- function parseConditionalExpressionRest(leftOperand, pos) {
34986
+ function parseConditionalExpressionRest(leftOperand, pos, allowReturnTypeInArrowFunction) {
34956
34987
  // Note: we are passed in an expression which was produced from parseBinaryExpressionOrHigher.
34957
34988
  var questionToken = parseOptionalToken(57 /* QuestionToken */);
34958
34989
  if (!questionToken) {
@@ -34961,8 +34992,8 @@ var ts;
34961
34992
  // Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and
34962
34993
  // we do not that for the 'whenFalse' part.
34963
34994
  var colonToken;
34964
- return finishNode(factory.createConditionalExpression(leftOperand, questionToken, doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher), colonToken = parseExpectedToken(58 /* ColonToken */), ts.nodeIsPresent(colonToken)
34965
- ? parseAssignmentExpressionOrHigher()
34995
+ return finishNode(factory.createConditionalExpression(leftOperand, questionToken, doOutsideOfContext(disallowInAndDecoratorContext, function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ false); }), colonToken = parseExpectedToken(58 /* ColonToken */), ts.nodeIsPresent(colonToken)
34996
+ ? parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction)
34966
34997
  : createMissingNode(79 /* Identifier */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(58 /* ColonToken */))), pos);
34967
34998
  }
34968
34999
  function parseBinaryExpressionOrHigher(precedence) {
@@ -35877,13 +35908,13 @@ var ts;
35877
35908
  function parseSpreadElement() {
35878
35909
  var pos = getNodePos();
35879
35910
  parseExpected(25 /* DotDotDotToken */);
35880
- var expression = parseAssignmentExpressionOrHigher();
35911
+ var expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
35881
35912
  return finishNode(factory.createSpreadElement(expression), pos);
35882
35913
  }
35883
35914
  function parseArgumentOrArrayLiteralElement() {
35884
35915
  return token() === 25 /* DotDotDotToken */ ? parseSpreadElement() :
35885
35916
  token() === 27 /* CommaToken */ ? finishNode(factory.createOmittedExpression(), getNodePos()) :
35886
- parseAssignmentExpressionOrHigher();
35917
+ parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
35887
35918
  }
35888
35919
  function parseArgumentExpression() {
35889
35920
  return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement);
@@ -35901,7 +35932,7 @@ var ts;
35901
35932
  var pos = getNodePos();
35902
35933
  var hasJSDoc = hasPrecedingJSDocComment();
35903
35934
  if (parseOptionalToken(25 /* DotDotDotToken */)) {
35904
- var expression = parseAssignmentExpressionOrHigher();
35935
+ var expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
35905
35936
  return withJSDoc(finishNode(factory.createSpreadAssignment(expression), pos), hasJSDoc);
35906
35937
  }
35907
35938
  var decorators = parseDecorators();
@@ -35930,7 +35961,7 @@ var ts;
35930
35961
  var isShorthandPropertyAssignment = tokenIsIdentifier && (token() !== 58 /* ColonToken */);
35931
35962
  if (isShorthandPropertyAssignment) {
35932
35963
  var equalsToken = parseOptionalToken(63 /* EqualsToken */);
35933
- var objectAssignmentInitializer = equalsToken ? allowInAnd(parseAssignmentExpressionOrHigher) : undefined;
35964
+ var objectAssignmentInitializer = equalsToken ? allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); }) : undefined;
35934
35965
  node = factory.createShorthandPropertyAssignment(name, objectAssignmentInitializer);
35935
35966
  // Save equals token for error reporting.
35936
35967
  // TODO(rbuckton): Consider manufacturing this when we need to report an error as it is otherwise not useful.
@@ -35938,7 +35969,7 @@ var ts;
35938
35969
  }
35939
35970
  else {
35940
35971
  parseExpected(58 /* ColonToken */);
35941
- var initializer = allowInAnd(parseAssignmentExpressionOrHigher);
35972
+ var initializer = allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); });
35942
35973
  node = factory.createPropertyAssignment(name, initializer);
35943
35974
  }
35944
35975
  // Decorators, Modifiers, questionToken, and exclamationToken are not supported by property assignments and are reported in the grammar checker
@@ -36115,7 +36146,7 @@ var ts;
36115
36146
  }
36116
36147
  var node;
36117
36148
  if (awaitToken ? parseExpected(160 /* OfKeyword */) : parseOptional(160 /* OfKeyword */)) {
36118
- var expression = allowInAnd(parseAssignmentExpressionOrHigher);
36149
+ var expression = allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); });
36119
36150
  parseExpected(21 /* CloseParenToken */);
36120
36151
  node = factory.createForOfStatement(awaitToken, initializer, expression, parseStatement());
36121
36152
  }
@@ -37303,7 +37334,7 @@ var ts;
37303
37334
  var pos = getNodePos();
37304
37335
  var name = ts.tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(10 /* StringLiteral */);
37305
37336
  parseExpected(58 /* ColonToken */);
37306
- var value = parseAssignmentExpressionOrHigher();
37337
+ var value = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
37307
37338
  return finishNode(factory.createAssertEntry(name, value), pos);
37308
37339
  }
37309
37340
  function parseAssertClause(skipAssertKeyword) {
@@ -37544,7 +37575,7 @@ var ts;
37544
37575
  else {
37545
37576
  parseExpected(88 /* DefaultKeyword */);
37546
37577
  }
37547
- var expression = parseAssignmentExpressionOrHigher();
37578
+ var expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
37548
37579
  parseSemicolon();
37549
37580
  setAwaitContext(savedAwaitContext);
37550
37581
  var node = factory.createExportAssignment(modifiers, isExportEquals, expression);
@@ -48910,9 +48941,9 @@ var ts;
48910
48941
  return moduleSpecifier && resolveExternalModuleName(moduleSpecifier, moduleSpecifier, /*ignoreErrors*/ true);
48911
48942
  },
48912
48943
  resolveExternalModuleSymbol: resolveExternalModuleSymbol,
48913
- tryGetThisTypeAt: function (nodeIn, includeGlobalThis) {
48944
+ tryGetThisTypeAt: function (nodeIn, includeGlobalThis, container) {
48914
48945
  var node = ts.getParseTreeNode(nodeIn);
48915
- return node && tryGetThisTypeAt(node, includeGlobalThis);
48946
+ return node && tryGetThisTypeAt(node, includeGlobalThis, container);
48916
48947
  },
48917
48948
  getTypeArgumentConstraint: function (nodeIn) {
48918
48949
  var node = ts.getParseTreeNode(nodeIn, ts.isTypeNode);
@@ -59360,7 +59391,7 @@ var ts;
59360
59391
  }
59361
59392
  if (t.flags & 268435456 /* StringMapping */) {
59362
59393
  var constraint = getBaseConstraint(t.type);
59363
- return constraint ? getStringMappingType(t.symbol, constraint) : stringType;
59394
+ return constraint && constraint !== t.type ? getStringMappingType(t.symbol, constraint) : stringType;
59364
59395
  }
59365
59396
  if (t.flags & 8388608 /* IndexedAccess */) {
59366
59397
  if (isMappedTypeGenericIndexedAccess(t)) {
@@ -62330,9 +62361,12 @@ var ts;
62330
62361
  }
62331
62362
  function getStringMappingType(symbol, type) {
62332
62363
  return type.flags & (1048576 /* Union */ | 131072 /* Never */) ? mapType(type, function (t) { return getStringMappingType(symbol, t); }) :
62333
- isGenericIndexType(type) ? getStringMappingTypeForGenericType(symbol, type) :
62334
- type.flags & 128 /* StringLiteral */ ? getStringLiteralType(applyStringMapping(symbol, type.value)) :
62335
- type;
62364
+ // Mapping<Mapping<T>> === Mapping<T>
62365
+ type.flags & 268435456 /* StringMapping */ && symbol === type.symbol ? type :
62366
+ isGenericIndexType(type) || isPatternLiteralPlaceholderType(type) ? getStringMappingTypeForGenericType(symbol, isPatternLiteralPlaceholderType(type) && !(type.flags & 268435456 /* StringMapping */) ? getTemplateLiteralType(["", ""], [type]) : type) :
62367
+ type.flags & 128 /* StringLiteral */ ? getStringLiteralType(applyStringMapping(symbol, type.value)) :
62368
+ type.flags & 134217728 /* TemplateLiteral */ ? getTemplateLiteralType.apply(void 0, applyTemplateStringMapping(symbol, type.texts, type.types)) :
62369
+ type;
62336
62370
  }
62337
62371
  function applyStringMapping(symbol, str) {
62338
62372
  switch (intrinsicTypeKinds.get(symbol.escapedName)) {
@@ -62343,6 +62377,15 @@ var ts;
62343
62377
  }
62344
62378
  return str;
62345
62379
  }
62380
+ function applyTemplateStringMapping(symbol, texts, types) {
62381
+ switch (intrinsicTypeKinds.get(symbol.escapedName)) {
62382
+ case 0 /* Uppercase */: return [texts.map(function (t) { return t.toUpperCase(); }), types.map(function (t) { return getStringMappingType(symbol, t); })];
62383
+ case 1 /* Lowercase */: return [texts.map(function (t) { return t.toLowerCase(); }), types.map(function (t) { return getStringMappingType(symbol, t); })];
62384
+ case 2 /* Capitalize */: return [texts[0] === "" ? texts : __spreadArray([texts[0].charAt(0).toUpperCase() + texts[0].slice(1)], texts.slice(1), true), texts[0] === "" ? __spreadArray([getStringMappingType(symbol, types[0])], types.slice(1), true) : types];
62385
+ case 3 /* Uncapitalize */: return [texts[0] === "" ? texts : __spreadArray([texts[0].charAt(0).toLowerCase() + texts[0].slice(1)], texts.slice(1), true), texts[0] === "" ? __spreadArray([getStringMappingType(symbol, types[0])], types.slice(1), true) : types];
62386
+ }
62387
+ return [texts, types];
62388
+ }
62346
62389
  function getStringMappingTypeForGenericType(symbol, type) {
62347
62390
  var id = getSymbolId(symbol) + "," + getTypeId(type);
62348
62391
  var result = stringMappingTypes.get(id);
@@ -62584,7 +62627,7 @@ var ts;
62584
62627
  accessNode;
62585
62628
  }
62586
62629
  function isPatternLiteralPlaceholderType(type) {
62587
- return !!(type.flags & (1 /* Any */ | 4 /* String */ | 8 /* Number */ | 64 /* BigInt */));
62630
+ return !!(type.flags & (1 /* Any */ | 4 /* String */ | 8 /* Number */ | 64 /* BigInt */)) || !!(type.flags & 268435456 /* StringMapping */ && isPatternLiteralPlaceholderType(type.type));
62588
62631
  }
62589
62632
  function isPatternLiteralType(type) {
62590
62633
  return !!(type.flags & 134217728 /* TemplateLiteral */) && ts.every(type.types, isPatternLiteralPlaceholderType);
@@ -66296,6 +66339,13 @@ var ts;
66296
66339
  return -1 /* True */;
66297
66340
  }
66298
66341
  }
66342
+ else if (target.flags & 268435456 /* StringMapping */) {
66343
+ if (!(source.flags & 268435456 /* StringMapping */)) {
66344
+ if (isMemberOfStringMapping(source, target)) {
66345
+ return -1 /* True */;
66346
+ }
66347
+ }
66348
+ }
66299
66349
  if (sourceFlags & 8650752 /* TypeVariable */) {
66300
66350
  // IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
66301
66351
  if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
@@ -66339,7 +66389,10 @@ var ts;
66339
66389
  }
66340
66390
  }
66341
66391
  else if (sourceFlags & 268435456 /* StringMapping */) {
66342
- if (targetFlags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
66392
+ if (targetFlags & 268435456 /* StringMapping */) {
66393
+ if (source.symbol !== target.symbol) {
66394
+ return 0 /* False */;
66395
+ }
66343
66396
  if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
66344
66397
  resetErrorInfo(saveErrorInfo);
66345
66398
  return result;
@@ -67264,7 +67317,7 @@ var ts;
67264
67317
  return typeCouldHaveTopLevelSingletonTypes(constraint);
67265
67318
  }
67266
67319
  }
67267
- return isUnitType(type) || !!(type.flags & 134217728 /* TemplateLiteral */);
67320
+ return isUnitType(type) || !!(type.flags & 134217728 /* TemplateLiteral */) || !!(type.flags & 268435456 /* StringMapping */);
67268
67321
  }
67269
67322
  function getExactOptionalUnassignableProperties(source, target) {
67270
67323
  if (isTupleType(source) && isTupleType(target))
@@ -68735,6 +68788,31 @@ var ts;
68735
68788
  return success && result === 9 /* BigIntLiteral */ && scanner.getTextPos() === (s.length + 1) && !(flags & 512 /* ContainsSeparator */)
68736
68789
  && (!roundTripOnly || s === ts.pseudoBigIntToString({ negative: negative, base10Value: ts.parsePseudoBigInt(scanner.getTokenValue()) }));
68737
68790
  }
68791
+ function isMemberOfStringMapping(source, target) {
68792
+ if (target.flags & (4 /* String */ | 3 /* AnyOrUnknown */)) {
68793
+ return true;
68794
+ }
68795
+ if (target.flags & 134217728 /* TemplateLiteral */) {
68796
+ return isTypeAssignableTo(source, target);
68797
+ }
68798
+ if (target.flags & 268435456 /* StringMapping */) {
68799
+ // We need to see whether applying the same mappings of the target
68800
+ // onto the source would produce an identical type *and* that
68801
+ // it's compatible with the inner-most non-string-mapped type.
68802
+ //
68803
+ // The intuition here is that if same mappings don't affect the source at all,
68804
+ // and the source is compatible with the unmapped target, then they must
68805
+ // still reside in the same domain.
68806
+ var mappingStack = [];
68807
+ while (target.flags & 268435456 /* StringMapping */) {
68808
+ mappingStack.unshift(target.symbol);
68809
+ target = target.type;
68810
+ }
68811
+ var mappedSource = ts.reduceLeft(mappingStack, function (memo, value) { return getStringMappingType(value, memo); }, source);
68812
+ return mappedSource === source && isMemberOfStringMapping(source, target);
68813
+ }
68814
+ return false;
68815
+ }
68738
68816
  function isValidTypeForTemplateLiteralPlaceholder(source, target) {
68739
68817
  if (source === target || target.flags & (1 /* Any */ | 4 /* String */)) {
68740
68818
  return true;
@@ -68743,7 +68821,8 @@ var ts;
68743
68821
  var value = source.value;
68744
68822
  return !!(target.flags & 8 /* Number */ && isValidNumberString(value, /*roundTripOnly*/ false) ||
68745
68823
  target.flags & 64 /* BigInt */ && isValidBigIntString(value, /*roundTripOnly*/ false) ||
68746
- target.flags & (512 /* BooleanLiteral */ | 98304 /* Nullable */) && value === target.intrinsicName);
68824
+ target.flags & (512 /* BooleanLiteral */ | 98304 /* Nullable */) && value === target.intrinsicName ||
68825
+ target.flags & 268435456 /* StringMapping */ && isMemberOfStringMapping(getStringLiteralType(value), target));
68747
68826
  }
68748
68827
  if (source.flags & 134217728 /* TemplateLiteral */) {
68749
68828
  var texts = source.texts;
@@ -85622,6 +85701,7 @@ var ts;
85622
85701
  return true;
85623
85702
  }
85624
85703
  function checkAliasSymbol(node) {
85704
+ var _a, _b, _c, _d, _e;
85625
85705
  var symbol = getSymbolOfNode(node);
85626
85706
  var target = resolveAlias(symbol);
85627
85707
  if (target !== unknownSymbol) {
@@ -85632,6 +85712,31 @@ var ts;
85632
85712
  // otherwise it will conflict with some local declaration). Note that in addition to normal flags we include matching SymbolFlags.Export*
85633
85713
  // in order to prevent collisions with declarations that were exported from the current module (they still contribute to local names).
85634
85714
  symbol = getMergedSymbol(symbol.exportSymbol || symbol);
85715
+ // A type-only import/export will already have a grammar error in a JS file, so no need to issue more errors within
85716
+ if (ts.isInJSFile(node) && !(target.flags & 111551 /* Value */) && !ts.isTypeOnlyImportOrExportDeclaration(node)) {
85717
+ var errorNode = ts.isImportOrExportSpecifier(node) ? node.propertyName || node.name :
85718
+ ts.isNamedDeclaration(node) ? node.name :
85719
+ node;
85720
+ ts.Debug.assert(node.kind !== 274 /* NamespaceExport */);
85721
+ if (node.kind === 275 /* ExportSpecifier */) {
85722
+ var diag = error(errorNode, ts.Diagnostics.Types_cannot_appear_in_export_declarations_in_JavaScript_files);
85723
+ var alreadyExportedSymbol = (_b = (_a = ts.getSourceFileOfNode(node).symbol) === null || _a === void 0 ? void 0 : _a.exports) === null || _b === void 0 ? void 0 : _b.get((node.propertyName || node.name).escapedText);
85724
+ if (alreadyExportedSymbol === target) {
85725
+ var exportingDeclaration = (_c = alreadyExportedSymbol.declarations) === null || _c === void 0 ? void 0 : _c.find(ts.isJSDocNode);
85726
+ if (exportingDeclaration) {
85727
+ ts.addRelatedInfo(diag, ts.createDiagnosticForNode(exportingDeclaration, ts.Diagnostics._0_is_automatically_exported_here, ts.unescapeLeadingUnderscores(alreadyExportedSymbol.escapedName)));
85728
+ }
85729
+ }
85730
+ }
85731
+ else {
85732
+ ts.Debug.assert(node.kind !== 254 /* VariableDeclaration */);
85733
+ var importDeclaration = ts.findAncestor(node, ts.or(ts.isImportDeclaration, ts.isImportEqualsDeclaration));
85734
+ var moduleSpecifier = (_e = (importDeclaration && ((_d = ts.tryGetModuleSpecifierFromDeclaration(importDeclaration)) === null || _d === void 0 ? void 0 : _d.text))) !== null && _e !== void 0 ? _e : "...";
85735
+ var importedIdentifier = ts.unescapeLeadingUnderscores(ts.isIdentifier(errorNode) ? errorNode.escapedText : symbol.escapedName);
85736
+ error(errorNode, ts.Diagnostics._0_is_a_type_and_cannot_be_imported_in_JavaScript_files_Use_1_in_a_JSDoc_type_annotation, importedIdentifier, "import(\"" + moduleSpecifier + "\")." + importedIdentifier);
85737
+ }
85738
+ return;
85739
+ }
85635
85740
  var excludedMeanings = (symbol.flags & (111551 /* Value */ | 1048576 /* ExportValue */) ? 111551 /* Value */ : 0) |
85636
85741
  (symbol.flags & 788968 /* Type */ ? 788968 /* Type */ : 0) |
85637
85742
  (symbol.flags & 1920 /* Namespace */ ? 1920 /* Namespace */ : 0);
@@ -130632,32 +130737,41 @@ var ts;
130632
130737
  || ts.startsWith(getCanonicalFileName(fromPath), toNodeModulesParent)
130633
130738
  || (!!globalCachePath && ts.startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));
130634
130739
  }
130635
- function forEachExternalModuleToImportFrom(program, host, useAutoImportProvider, cb) {
130740
+ function forEachExternalModuleToImportFrom(program, host, preferences, useAutoImportProvider, cb) {
130636
130741
  var _a, _b;
130637
- forEachExternalModule(program.getTypeChecker(), program.getSourceFiles(), function (module, file) { return cb(module, file, program, /*isFromPackageJson*/ false); });
130742
+ var useCaseSensitiveFileNames = ts.hostUsesCaseSensitiveFileNames(host);
130743
+ var excludePatterns = preferences.autoImportFileExcludePatterns && ts.mapDefined(preferences.autoImportFileExcludePatterns, function (spec) {
130744
+ // The client is expected to send rooted path specs since we don't know
130745
+ // what directory a relative path is relative to.
130746
+ var pattern = ts.getPatternFromSpec(spec, "", "exclude");
130747
+ return pattern ? ts.getRegexFromPattern(pattern, useCaseSensitiveFileNames) : undefined;
130748
+ });
130749
+ forEachExternalModule(program.getTypeChecker(), program.getSourceFiles(), excludePatterns, function (module, file) { return cb(module, file, program, /*isFromPackageJson*/ false); });
130638
130750
  var autoImportProvider = useAutoImportProvider && ((_a = host.getPackageJsonAutoImportProvider) === null || _a === void 0 ? void 0 : _a.call(host));
130639
130751
  if (autoImportProvider) {
130640
130752
  var start = ts.timestamp();
130641
- forEachExternalModule(autoImportProvider.getTypeChecker(), autoImportProvider.getSourceFiles(), function (module, file) { return cb(module, file, autoImportProvider, /*isFromPackageJson*/ true); });
130753
+ forEachExternalModule(autoImportProvider.getTypeChecker(), autoImportProvider.getSourceFiles(), excludePatterns, function (module, file) { return cb(module, file, autoImportProvider, /*isFromPackageJson*/ true); });
130642
130754
  (_b = host.log) === null || _b === void 0 ? void 0 : _b.call(host, "forEachExternalModuleToImportFrom autoImportProvider: " + (ts.timestamp() - start));
130643
130755
  }
130644
130756
  }
130645
130757
  ts.forEachExternalModuleToImportFrom = forEachExternalModuleToImportFrom;
130646
- function forEachExternalModule(checker, allSourceFiles, cb) {
130647
- for (var _i = 0, _a = checker.getAmbientModules(); _i < _a.length; _i++) {
130648
- var ambient = _a[_i];
130649
- if (!ts.stringContains(ambient.name, "*")) {
130758
+ function forEachExternalModule(checker, allSourceFiles, excludePatterns, cb) {
130759
+ var _a;
130760
+ var isExcluded = function (fileName) { return excludePatterns === null || excludePatterns === void 0 ? void 0 : excludePatterns.some(function (p) { return p.test(fileName); }); };
130761
+ for (var _i = 0, _b = checker.getAmbientModules(); _i < _b.length; _i++) {
130762
+ var ambient = _b[_i];
130763
+ if (!ts.stringContains(ambient.name, "*") && !(excludePatterns && ((_a = ambient.declarations) === null || _a === void 0 ? void 0 : _a.every(function (d) { return isExcluded(d.getSourceFile().fileName); })))) {
130650
130764
  cb(ambient, /*sourceFile*/ undefined);
130651
130765
  }
130652
130766
  }
130653
- for (var _b = 0, allSourceFiles_1 = allSourceFiles; _b < allSourceFiles_1.length; _b++) {
130654
- var sourceFile = allSourceFiles_1[_b];
130655
- if (ts.isExternalOrCommonJsModule(sourceFile)) {
130767
+ for (var _c = 0, allSourceFiles_1 = allSourceFiles; _c < allSourceFiles_1.length; _c++) {
130768
+ var sourceFile = allSourceFiles_1[_c];
130769
+ if (ts.isExternalOrCommonJsModule(sourceFile) && !isExcluded(sourceFile.fileName)) {
130656
130770
  cb(checker.getMergedSymbol(sourceFile.symbol), sourceFile);
130657
130771
  }
130658
130772
  }
130659
130773
  }
130660
- function getExportInfoMap(importingFile, host, program, cancellationToken) {
130774
+ function getExportInfoMap(importingFile, host, program, preferences, cancellationToken) {
130661
130775
  var _a, _b, _c, _d, _e;
130662
130776
  var start = ts.timestamp();
130663
130777
  // Pulling the AutoImportProvider project will trigger its updateGraph if pending,
@@ -130677,7 +130791,7 @@ var ts;
130677
130791
  var compilerOptions = program.getCompilerOptions();
130678
130792
  var moduleCount = 0;
130679
130793
  try {
130680
- forEachExternalModuleToImportFrom(program, host, /*useAutoImportProvider*/ true, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
130794
+ forEachExternalModuleToImportFrom(program, host, preferences, /*useAutoImportProvider*/ true, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
130681
130795
  if (++moduleCount % 100 === 0)
130682
130796
  cancellationToken === null || cancellationToken === void 0 ? void 0 : cancellationToken.throwIfCancellationRequested();
130683
130797
  var seenExports = new ts.Map();
@@ -133073,7 +133187,7 @@ var ts;
133073
133187
  if (!previousResponse)
133074
133188
  return undefined;
133075
133189
  var lowerCaseTokenText = location.text.toLowerCase();
133076
- var exportMap = ts.getExportInfoMap(file, host, program, cancellationToken);
133190
+ var exportMap = ts.getExportInfoMap(file, host, program, preferences, cancellationToken);
133077
133191
  var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, ts.codefix.createImportSpecifierResolver(file, program, host, preferences), program, location.getStart(), preferences,
133078
133192
  /*isForImportStatementCompletion*/ false, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
133079
133193
  var entries = ts.mapDefined(previousResponse.entries, function (entry) {
@@ -134782,7 +134896,7 @@ var ts;
134782
134896
  }
134783
134897
  // Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions`
134784
134898
  if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== 305 /* SourceFile */) {
134785
- var thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false);
134899
+ var thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false, ts.isClassLike(scopeNode.parent) ? scopeNode : undefined);
134786
134900
  if (thisType && !isProbablyGlobalType(thisType, sourceFile, typeChecker)) {
134787
134901
  for (var _i = 0, _a = getPropertiesForCompletion(thisType, typeChecker); _i < _a.length; _i++) {
134788
134902
  var symbol = _a[_i];
@@ -134885,7 +134999,7 @@ var ts;
134885
134999
  previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() :
134886
135000
  "";
134887
135001
  var moduleSpecifierCache = (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host);
134888
- var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
135002
+ var exportInfo = ts.getExportInfoMap(sourceFile, host, program, preferences, cancellationToken);
134889
135003
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
134890
135004
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
134891
135005
  resolvingModuleSpecifiers("collectAutoImports", host, importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences)), program, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
@@ -144120,10 +144234,10 @@ var ts;
144120
144234
  (function (ts) {
144121
144235
  var Rename;
144122
144236
  (function (Rename) {
144123
- function getRenameInfo(program, sourceFile, position, options) {
144237
+ function getRenameInfo(program, sourceFile, position, preferences) {
144124
144238
  var node = ts.getAdjustedRenameLocation(ts.getTouchingPropertyName(sourceFile, position));
144125
144239
  if (nodeIsEligibleForRename(node)) {
144126
- var renameInfo = getRenameInfoForNode(node, program.getTypeChecker(), sourceFile, program, options);
144240
+ var renameInfo = getRenameInfoForNode(node, program.getTypeChecker(), sourceFile, program, preferences);
144127
144241
  if (renameInfo) {
144128
144242
  return renameInfo;
144129
144243
  }
@@ -144131,7 +144245,7 @@ var ts;
144131
144245
  return getRenameInfoError(ts.Diagnostics.You_cannot_rename_this_element);
144132
144246
  }
144133
144247
  Rename.getRenameInfo = getRenameInfo;
144134
- function getRenameInfoForNode(node, typeChecker, sourceFile, program, options) {
144248
+ function getRenameInfoForNode(node, typeChecker, sourceFile, program, preferences) {
144135
144249
  var symbol = typeChecker.getSymbolAtLocation(node);
144136
144250
  if (!symbol) {
144137
144251
  if (ts.isStringLiteralLike(node)) {
@@ -144159,7 +144273,12 @@ var ts;
144159
144273
  return undefined;
144160
144274
  }
144161
144275
  if (ts.isStringLiteralLike(node) && ts.tryGetImportFromModuleSpecifier(node)) {
144162
- return options && options.allowRenameOfImportPath ? getRenameInfoForModule(node, sourceFile, symbol) : undefined;
144276
+ return preferences.allowRenameOfImportPath ? getRenameInfoForModule(node, sourceFile, symbol) : undefined;
144277
+ }
144278
+ // Disallow rename for elements that would rename across `*/node_modules/*` packages.
144279
+ var wouldRenameNodeModules = wouldRenameInOtherNodeModules(sourceFile, symbol, typeChecker, preferences);
144280
+ if (wouldRenameNodeModules) {
144281
+ return getRenameInfoError(wouldRenameNodeModules);
144163
144282
  }
144164
144283
  var kind = ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, node);
144165
144284
  var specifierName = (ts.isImportOrExportSpecifierName(node) || ts.isStringOrNumericLiteralLike(node) && node.parent.kind === 162 /* ComputedPropertyName */)
@@ -144173,6 +144292,49 @@ var ts;
144173
144292
  var sourceFile = declaration.getSourceFile();
144174
144293
  return program.isSourceFileDefaultLibrary(sourceFile) && ts.fileExtensionIs(sourceFile.fileName, ".d.ts" /* Dts */);
144175
144294
  }
144295
+ function wouldRenameInOtherNodeModules(originalFile, symbol, checker, preferences) {
144296
+ if (!preferences.providePrefixAndSuffixTextForRename && symbol.flags & 2097152 /* Alias */) {
144297
+ var importSpecifier = symbol.declarations && ts.find(symbol.declarations, function (decl) { return ts.isImportSpecifier(decl); });
144298
+ if (importSpecifier && !importSpecifier.propertyName) {
144299
+ symbol = checker.getAliasedSymbol(symbol);
144300
+ }
144301
+ }
144302
+ var declarations = symbol.declarations;
144303
+ if (!declarations) {
144304
+ return undefined;
144305
+ }
144306
+ var originalPackage = getPackagePathComponents(originalFile.path);
144307
+ if (originalPackage === undefined) { // original source file is not in node_modules
144308
+ if (ts.some(declarations, function (declaration) { return ts.isInsideNodeModules(declaration.getSourceFile().path); })) {
144309
+ return ts.Diagnostics.You_cannot_rename_elements_that_are_defined_in_a_node_modules_folder;
144310
+ }
144311
+ else {
144312
+ return undefined;
144313
+ }
144314
+ }
144315
+ // original source file is in node_modules
144316
+ for (var _i = 0, declarations_4 = declarations; _i < declarations_4.length; _i++) {
144317
+ var declaration = declarations_4[_i];
144318
+ var declPackage = getPackagePathComponents(declaration.getSourceFile().path);
144319
+ if (declPackage) {
144320
+ var length_2 = Math.min(originalPackage.length, declPackage.length);
144321
+ for (var i = 0; i <= length_2; i++) {
144322
+ if (ts.compareStringsCaseSensitive(originalPackage[i], declPackage[i]) !== 0 /* EqualTo */) {
144323
+ return ts.Diagnostics.You_cannot_rename_elements_that_are_defined_in_another_node_modules_folder;
144324
+ }
144325
+ }
144326
+ }
144327
+ }
144328
+ return undefined;
144329
+ }
144330
+ function getPackagePathComponents(filePath) {
144331
+ var components = ts.getPathComponents(filePath);
144332
+ var nodeModulesIdx = components.lastIndexOf("node_modules");
144333
+ if (nodeModulesIdx === -1) {
144334
+ return undefined;
144335
+ }
144336
+ return components.slice(0, nodeModulesIdx + 2);
144337
+ }
144176
144338
  function getRenameInfoForModule(node, sourceFile, moduleSymbol) {
144177
144339
  if (!ts.isExternalModuleNameRelative(node.text)) {
144178
144340
  return getRenameInfoError(ts.Diagnostics.You_cannot_rename_a_module_via_a_global_import);
@@ -154034,7 +154196,7 @@ var ts;
154034
154196
  var getModuleSpecifierResolutionHost = ts.memoizeOne(function (isFromPackageJson) {
154035
154197
  return ts.createModuleSpecifierResolutionHost(isFromPackageJson ? host.getPackageJsonAutoImportProvider() : program, host);
154036
154198
  });
154037
- ts.forEachExternalModuleToImportFrom(program, host, useAutoImportProvider, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
154199
+ ts.forEachExternalModuleToImportFrom(program, host, preferences, useAutoImportProvider, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
154038
154200
  var checker = program.getTypeChecker();
154039
154201
  // Don't import from a re-export when looking "up" like to `./index` or `../index`.
154040
154202
  if (moduleFile && moduleSymbol !== exportingModuleSymbol && ts.startsWith(importingFile.fileName, ts.getDirectoryPath(moduleFile.fileName))) {
@@ -154503,7 +154665,7 @@ var ts;
154503
154665
  originalSymbolToExportInfos.add(ts.getUniqueSymbolId(exportedSymbol, checker).toString(), { symbol: exportedSymbol, moduleSymbol: moduleSymbol, moduleFileName: toFile === null || toFile === void 0 ? void 0 : toFile.fileName, exportKind: exportKind, targetFlags: ts.skipAlias(exportedSymbol, checker).flags, isFromPackageJson: isFromPackageJson });
154504
154666
  }
154505
154667
  }
154506
- ts.forEachExternalModuleToImportFrom(program, host, useAutoImportProvider, function (moduleSymbol, sourceFile, program, isFromPackageJson) {
154668
+ ts.forEachExternalModuleToImportFrom(program, host, preferences, useAutoImportProvider, function (moduleSymbol, sourceFile, program, isFromPackageJson) {
154507
154669
  var checker = program.getTypeChecker();
154508
154670
  cancellationToken.throwIfCancellationRequested();
154509
154671
  var compilerOptions = program.getCompilerOptions();
@@ -161212,11 +161374,11 @@ var ts;
161212
161374
  }
161213
161375
  }
161214
161376
  else if (ts.isVariableStatement(node) || ts.isVariableDeclarationList(node)) {
161215
- var declarations_5 = ts.isVariableStatement(node) ? node.declarationList.declarations : node.declarations;
161377
+ var declarations_6 = ts.isVariableStatement(node) ? node.declarationList.declarations : node.declarations;
161216
161378
  var numInitializers = 0;
161217
161379
  var lastInitializer = void 0;
161218
- for (var _i = 0, declarations_4 = declarations_5; _i < declarations_4.length; _i++) {
161219
- var declaration = declarations_4[_i];
161380
+ for (var _i = 0, declarations_5 = declarations_6; _i < declarations_5.length; _i++) {
161381
+ var declaration = declarations_5[_i];
161220
161382
  if (declaration.initializer) {
161221
161383
  numInitializers++;
161222
161384
  lastInitializer = declaration.initializer;
@@ -165353,8 +165515,8 @@ var ts;
165353
165515
  tags = __spreadArray(__spreadArray([], inheritedTags, true), tags, true);
165354
165516
  }
165355
165517
  };
165356
- for (var _i = 0, declarations_6 = declarations; _i < declarations_6.length; _i++) {
165357
- var declaration = declarations_6[_i];
165518
+ for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
165519
+ var declaration = declarations_7[_i];
165358
165520
  _loop_21(declaration);
165359
165521
  }
165360
165522
  }
@@ -165380,8 +165542,8 @@ var ts;
165380
165542
  if (inheritedDocs)
165381
165543
  doc = doc.length === 0 ? inheritedDocs.slice() : inheritedDocs.concat(ts.lineBreakPart(), doc);
165382
165544
  };
165383
- for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
165384
- var declaration = declarations_7[_i];
165545
+ for (var _i = 0, declarations_8 = declarations; _i < declarations_8.length; _i++) {
165546
+ var declaration = declarations_8[_i];
165385
165547
  _loop_22(declaration);
165386
165548
  }
165387
165549
  }
@@ -166958,9 +167120,9 @@ var ts;
166958
167120
  return ts.stringContains(path, "/node_modules/");
166959
167121
  }
166960
167122
  }
166961
- function getRenameInfo(fileName, position, options) {
167123
+ function getRenameInfo(fileName, position, preferences) {
166962
167124
  synchronizeHostData();
166963
- return ts.Rename.getRenameInfo(program, getValidSourceFile(fileName), position, options);
167125
+ return ts.Rename.getRenameInfo(program, getValidSourceFile(fileName), position, preferences || {});
166964
167126
  }
166965
167127
  function getRefactorContext(file, positionOrRange, preferences, formatOptions, triggerReason, kind) {
166966
167128
  var _a = typeof positionOrRange === "number" ? [positionOrRange, undefined] : [positionOrRange.pos, positionOrRange.end], startPosition = _a[0], endPosition = _a[1];
@@ -168326,9 +168488,9 @@ var ts;
168326
168488
  var _this = this;
168327
168489
  return this.forwardJSONCall("getImplementationAtPosition('" + fileName + "', " + position + ")", function () { return _this.languageService.getImplementationAtPosition(fileName, position); });
168328
168490
  };
168329
- LanguageServiceShimObject.prototype.getRenameInfo = function (fileName, position, options) {
168491
+ LanguageServiceShimObject.prototype.getRenameInfo = function (fileName, position, preferences) {
168330
168492
  var _this = this;
168331
- return this.forwardJSONCall("getRenameInfo('" + fileName + "', " + position + ")", function () { return _this.languageService.getRenameInfo(fileName, position, options); });
168493
+ return this.forwardJSONCall("getRenameInfo('" + fileName + "', " + position + ")", function () { return _this.languageService.getRenameInfo(fileName, position, preferences); });
168332
168494
  };
168333
168495
  LanguageServiceShimObject.prototype.getSmartSelectionRange = function (fileName, position) {
168334
168496
  var _this = this;
@@ -176498,7 +176660,7 @@ var ts;
176498
176660
  return info && !info.isLocal ? { fileName: info.fileName, pos: info.textSpan.start } : undefined;
176499
176661
  }
176500
176662
  function getReferencesWorker(projects, defaultProject, initialLocation, logger) {
176501
- var _a;
176663
+ var _a, _b;
176502
176664
  var perProjectResults = getPerProjectReferences(projects, defaultProject, initialLocation,
176503
176665
  /*isForRename*/ false, function (project, position) {
176504
176666
  logger.info("Finding references to " + position.fileName + " position " + position.pos + " in project " + project.getProjectName());
@@ -176518,7 +176680,7 @@ var ts;
176518
176680
  // have started the other project searches from related symbols. Propagate the
176519
176681
  // correct results to all other projects.
176520
176682
  var defaultProjectResults = perProjectResults.get(defaultProject);
176521
- if (((_a = defaultProjectResults === null || defaultProjectResults === void 0 ? void 0 : defaultProjectResults[0].references[0]) === null || _a === void 0 ? void 0 : _a.isDefinition) === undefined) {
176683
+ if (((_b = (_a = defaultProjectResults === null || defaultProjectResults === void 0 ? void 0 : defaultProjectResults[0]) === null || _a === void 0 ? void 0 : _a.references[0]) === null || _b === void 0 ? void 0 : _b.isDefinition) === undefined) {
176522
176684
  // Clear all isDefinition properties
176523
176685
  perProjectResults.forEach(function (projectResults) {
176524
176686
  for (var _i = 0, projectResults_2 = projectResults; _i < projectResults_2.length; _i++) {
@@ -176535,8 +176697,8 @@ var ts;
176535
176697
  var knownSymbolSpans_1 = createDocumentSpanSet();
176536
176698
  for (var _i = 0, defaultProjectResults_1 = defaultProjectResults; _i < defaultProjectResults_1.length; _i++) {
176537
176699
  var referencedSymbol = defaultProjectResults_1[_i];
176538
- for (var _b = 0, _c = referencedSymbol.references; _b < _c.length; _b++) {
176539
- var ref = _c[_b];
176700
+ for (var _c = 0, _d = referencedSymbol.references; _c < _d.length; _c++) {
176701
+ var ref = _d[_c];
176540
176702
  if (ref.isDefinition) {
176541
176703
  knownSymbolSpans_1.add(ref);
176542
176704
  // One is enough - updateIsDefinitionOfReferencedSymbols will fill out the set based on symbols
@@ -176655,23 +176817,30 @@ var ts;
176655
176817
  var getSourceDefinition = ts.memoize(function () { return defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition.fileName) ?
176656
176818
  defaultDefinition :
176657
176819
  defaultProject.getLanguageService().getSourceMapper().tryGetSourcePosition(defaultDefinition); });
176658
- // Track which projects we have already searched so that we don't repeat searches.
176659
- // We store the project key, rather than the project, because that's what `loadAncestorProjectTree` wants.
176660
- // (For that same reason, we don't use `resultsMap` for this check.)
176661
- var searchedProjects = new ts.Set();
176820
+ // The keys of resultsMap allow us to check which projects have already been searched, but we also
176821
+ // maintain a set of strings because that's what `loadAncestorProjectTree` wants.
176822
+ var searchedProjectKeys = new ts.Set();
176662
176823
  onCancellation: while (queue.length) {
176663
176824
  while (queue.length) {
176664
176825
  if (cancellationToken.isCancellationRequested())
176665
176826
  break onCancellation;
176827
+ var skipCount = 0;
176828
+ for (; skipCount < queue.length && resultsMap.has(queue[skipCount].project); skipCount++)
176829
+ ;
176830
+ if (skipCount === queue.length) {
176831
+ queue.length = 0;
176832
+ break;
176833
+ }
176834
+ if (skipCount > 0) {
176835
+ queue.splice(0, skipCount);
176836
+ }
176837
+ // NB: we may still skip if it's a project reference redirect
176666
176838
  var _a = queue.shift(), project = _a.project, location = _a.location;
176667
176839
  if (isLocationProjectReferenceRedirect(project, location))
176668
176840
  continue;
176669
- if (!ts.tryAddToSet(searchedProjects, getProjectKey(project)))
176670
- continue;
176671
176841
  var projectResults = searchPosition(project, location);
176672
- if (projectResults) {
176673
- resultsMap.set(project, projectResults);
176674
- }
176842
+ resultsMap.set(project, projectResults !== null && projectResults !== void 0 ? projectResults : server.emptyArray);
176843
+ searchedProjectKeys.add(getProjectKey(project));
176675
176844
  }
176676
176845
  // At this point, we know about all projects passed in as arguments and any projects in which
176677
176846
  // `getResultsForPosition` has returned results. We expand that set to include any projects
@@ -176679,11 +176848,11 @@ var ts;
176679
176848
  // containing `initialLocation`.
176680
176849
  if (defaultDefinition) {
176681
176850
  // This seems to mean "load all projects downstream from any member of `seenProjects`".
176682
- projectService.loadAncestorProjectTree(searchedProjects);
176851
+ projectService.loadAncestorProjectTree(searchedProjectKeys);
176683
176852
  projectService.forEachEnabledProject(function (project) {
176684
176853
  if (cancellationToken.isCancellationRequested())
176685
176854
  return; // There's no mechanism for skipping the remaining projects
176686
- if (searchedProjects.has(getProjectKey(project)))
176855
+ if (resultsMap.has(project))
176687
176856
  return; // Can loop forever without this (enqueue here, dequeue above, repeat)
176688
176857
  var location = mapDefinitionInProject(defaultDefinition, project, getGeneratedDefinition, getSourceDefinition);
176689
176858
  if (location) {
@@ -176694,9 +176863,10 @@ var ts;
176694
176863
  }
176695
176864
  // In the common case where there's only one project, return a simpler result to make
176696
176865
  // it easier for the caller to skip post-processing.
176697
- if (searchedProjects.size === 1) {
176866
+ if (resultsMap.size === 1) {
176698
176867
  var it = resultsMap.values().next();
176699
- return it.done ? server.emptyArray : it.value; // There may not be any results at all
176868
+ ts.Debug.assert(!it.done);
176869
+ return it.value;
176700
176870
  }
176701
176871
  return resultsMap;
176702
176872
  function searchPosition(project, location) {
@@ -176713,7 +176883,7 @@ var ts;
176713
176883
  var originalScriptInfo = projectService.getScriptInfo(originalLocation.fileName);
176714
176884
  for (var _i = 0, _a = originalScriptInfo.containingProjects; _i < _a.length; _i++) {
176715
176885
  var project_1 = _a[_i];
176716
- if (!project_1.isOrphan()) {
176886
+ if (!project_1.isOrphan() && !resultsMap.has(project_1)) { // Optimization: don't enqueue if will be discarded
176717
176887
  queue.push({ project: project_1, location: originalLocation });
176718
176888
  }
176719
176889
  }
@@ -176722,7 +176892,7 @@ var ts;
176722
176892
  symlinkedProjectsMap.forEach(function (symlinkedProjects, symlinkedPath) {
176723
176893
  for (var _i = 0, symlinkedProjects_2 = symlinkedProjects; _i < symlinkedProjects_2.length; _i++) {
176724
176894
  var symlinkedProject = symlinkedProjects_2[_i];
176725
- if (!symlinkedProject.isOrphan()) {
176895
+ if (!symlinkedProject.isOrphan() && !resultsMap.has(symlinkedProject)) { // Optimization: don't enqueue if will be discarded
176726
176896
  queue.push({ project: symlinkedProject, location: { fileName: symlinkedPath, pos: originalLocation.pos } });
176727
176897
  }
176728
176898
  }
@@ -178015,7 +178185,8 @@ var ts;
178015
178185
  Session.prototype.getRenameInfo = function (args) {
178016
178186
  var _a = this.getFileAndProject(args), file = _a.file, project = _a.project;
178017
178187
  var position = this.getPositionInFile(args, file);
178018
- return project.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: this.getPreferences(file).allowRenameOfImportPath });
178188
+ var preferences = this.getPreferences(file);
178189
+ return project.getLanguageService().getRenameInfo(file, position, preferences);
178019
178190
  };
178020
178191
  Session.prototype.getProjects = function (args, getScriptInfoEnsuringProjectsUptoDate, ignoreNoProjectError) {
178021
178192
  var _a;
@@ -178066,10 +178237,11 @@ var ts;
178066
178237
  var position = this.getPositionInFile(args, file);
178067
178238
  var projects = this.getProjects(args);
178068
178239
  var defaultProject = this.getDefaultProject(args);
178069
- var renameInfo = this.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: this.getPreferences(file).allowRenameOfImportPath }), ts.Debug.checkDefined(this.projectService.getScriptInfo(file)));
178240
+ var preferences = this.getPreferences(file);
178241
+ var renameInfo = this.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position, preferences), ts.Debug.checkDefined(this.projectService.getScriptInfo(file)));
178070
178242
  if (!renameInfo.canRename)
178071
178243
  return simplifiedResult ? { info: renameInfo, locs: [] } : [];
178072
- var locations = getRenameLocationsWorker(projects, defaultProject, { fileName: args.file, pos: position }, !!args.findInStrings, !!args.findInComments, this.getPreferences(file));
178244
+ var locations = getRenameLocationsWorker(projects, defaultProject, { fileName: args.file, pos: position }, !!args.findInStrings, !!args.findInComments, preferences);
178073
178245
  if (!simplifiedResult)
178074
178246
  return locations;
178075
178247
  return { info: renameInfo, locs: this.toSpanGroups(locations) };