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.
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220616";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220619";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -9857,6 +9857,8 @@ var ts;
9857
9857
  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}'."),
9858
9858
  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."),
9859
9859
  The_tag_was_first_specified_here: diag(8034, ts.DiagnosticCategory.Error, "The_tag_was_first_specified_here_8034", "The tag was first specified here."),
9860
+ 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."),
9861
+ 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."),
9860
9862
  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."),
9861
9863
  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."),
9862
9864
  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'."),
@@ -10127,6 +10129,9 @@ var ts;
10127
10129
  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."),
10128
10130
  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."),
10129
10131
  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."),
10132
+ _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."),
10133
+ 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."),
10134
+ _0_is_automatically_exported_here: diag(18044, ts.DiagnosticCategory.Message, "_0_is_automatically_exported_here_18044", "'{0}' is automatically exported here."),
10130
10135
  };
10131
10136
  })(ts || (ts = {}));
10132
10137
  var ts;
@@ -34715,10 +34720,10 @@ var ts;
34715
34720
  setDecoratorContext(/*val*/ false);
34716
34721
  }
34717
34722
  var pos = getNodePos();
34718
- var expr = parseAssignmentExpressionOrHigher();
34723
+ var expr = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
34719
34724
  var operatorToken;
34720
34725
  while ((operatorToken = parseOptionalToken(27 /* CommaToken */))) {
34721
- expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(), pos);
34726
+ expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true), pos);
34722
34727
  }
34723
34728
  if (saveDecoratorContext) {
34724
34729
  setDecoratorContext(/*val*/ true);
@@ -34726,9 +34731,9 @@ var ts;
34726
34731
  return expr;
34727
34732
  }
34728
34733
  function parseInitializer() {
34729
- return parseOptional(63 /* EqualsToken */) ? parseAssignmentExpressionOrHigher() : undefined;
34734
+ return parseOptional(63 /* EqualsToken */) ? parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true) : undefined;
34730
34735
  }
34731
- function parseAssignmentExpressionOrHigher() {
34736
+ function parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction) {
34732
34737
  // AssignmentExpression[in,yield]:
34733
34738
  // 1) ConditionalExpression[?in,?yield]
34734
34739
  // 2) LeftHandSideExpression = AssignmentExpression[?in,?yield]
@@ -34754,7 +34759,7 @@ var ts;
34754
34759
  // If we do successfully parse arrow-function, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is
34755
34760
  // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done
34756
34761
  // with AssignmentExpression if we see one.
34757
- var arrowExpression = tryParseParenthesizedArrowFunctionExpression() || tryParseAsyncSimpleArrowFunctionExpression();
34762
+ var arrowExpression = tryParseParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction) || tryParseAsyncSimpleArrowFunctionExpression(allowReturnTypeInArrowFunction);
34758
34763
  if (arrowExpression) {
34759
34764
  return arrowExpression;
34760
34765
  }
@@ -34773,7 +34778,7 @@ var ts;
34773
34778
  // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single
34774
34779
  // identifier and the current token is an arrow.
34775
34780
  if (expr.kind === 79 /* Identifier */ && token() === 38 /* EqualsGreaterThanToken */) {
34776
- return parseSimpleArrowFunctionExpression(pos, expr, /*asyncModifier*/ undefined);
34781
+ return parseSimpleArrowFunctionExpression(pos, expr, allowReturnTypeInArrowFunction, /*asyncModifier*/ undefined);
34777
34782
  }
34778
34783
  // Now see if we might be in cases '2' or '3'.
34779
34784
  // If the expression was a LHS expression, and we have an assignment operator, then
@@ -34782,10 +34787,10 @@ var ts;
34782
34787
  // Note: we call reScanGreaterToken so that we get an appropriately merged token
34783
34788
  // for cases like `> > =` becoming `>>=`
34784
34789
  if (ts.isLeftHandSideExpression(expr) && ts.isAssignmentOperator(reScanGreaterToken())) {
34785
- return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(), pos);
34790
+ return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction), pos);
34786
34791
  }
34787
34792
  // It wasn't an assignment or a lambda. This is a conditional expression:
34788
- return parseConditionalExpressionRest(expr, pos);
34793
+ return parseConditionalExpressionRest(expr, pos, allowReturnTypeInArrowFunction);
34789
34794
  }
34790
34795
  function isYieldExpression() {
34791
34796
  if (token() === 125 /* YieldKeyword */) {
@@ -34825,7 +34830,7 @@ var ts;
34825
34830
  nextToken();
34826
34831
  if (!scanner.hasPrecedingLineBreak() &&
34827
34832
  (token() === 41 /* AsteriskToken */ || isStartOfExpression())) {
34828
- return finishNode(factory.createYieldExpression(parseOptionalToken(41 /* AsteriskToken */), parseAssignmentExpressionOrHigher()), pos);
34833
+ return finishNode(factory.createYieldExpression(parseOptionalToken(41 /* AsteriskToken */), parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true)), pos);
34829
34834
  }
34830
34835
  else {
34831
34836
  // if the next token is not on the same line as yield. or we don't have an '*' or
@@ -34833,7 +34838,7 @@ var ts;
34833
34838
  return finishNode(factory.createYieldExpression(/*asteriskToken*/ undefined, /*expression*/ undefined), pos);
34834
34839
  }
34835
34840
  }
34836
- function parseSimpleArrowFunctionExpression(pos, identifier, asyncModifier) {
34841
+ function parseSimpleArrowFunctionExpression(pos, identifier, allowReturnTypeInArrowFunction, asyncModifier) {
34837
34842
  ts.Debug.assert(token() === 38 /* EqualsGreaterThanToken */, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
34838
34843
  var parameter = factory.createParameterDeclaration(
34839
34844
  /*modifiers*/ undefined,
@@ -34844,11 +34849,11 @@ var ts;
34844
34849
  finishNode(parameter, identifier.pos);
34845
34850
  var parameters = createNodeArray([parameter], parameter.pos, parameter.end);
34846
34851
  var equalsGreaterThanToken = parseExpectedToken(38 /* EqualsGreaterThanToken */);
34847
- var body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier);
34852
+ var body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier, allowReturnTypeInArrowFunction);
34848
34853
  var node = factory.createArrowFunction(asyncModifier, /*typeParameters*/ undefined, parameters, /*type*/ undefined, equalsGreaterThanToken, body);
34849
34854
  return addJSDocComment(finishNode(node, pos));
34850
34855
  }
34851
- function tryParseParenthesizedArrowFunctionExpression() {
34856
+ function tryParseParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction) {
34852
34857
  var triState = isParenthesizedArrowFunctionExpression();
34853
34858
  if (triState === 0 /* False */) {
34854
34859
  // It's definitely not a parenthesized arrow function expression.
@@ -34859,8 +34864,8 @@ var ts;
34859
34864
  // it out, but don't allow any ambiguity, and return 'undefined' if this could be an
34860
34865
  // expression instead.
34861
34866
  return triState === 1 /* True */ ?
34862
- parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true) :
34863
- tryParse(parsePossibleParenthesizedArrowFunctionExpression);
34867
+ parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true, /*allowReturnTypeInArrowFunction*/ true) :
34868
+ tryParse(function () { return parsePossibleParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction); });
34864
34869
  }
34865
34870
  // True -> We definitely expect a parenthesized arrow function here.
34866
34871
  // False -> There *cannot* be a parenthesized arrow function here.
@@ -34994,25 +34999,25 @@ var ts;
34994
34999
  return 2 /* Unknown */;
34995
35000
  }
34996
35001
  }
34997
- function parsePossibleParenthesizedArrowFunctionExpression() {
35002
+ function parsePossibleParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction) {
34998
35003
  var tokenPos = scanner.getTokenPos();
34999
35004
  if (notParenthesizedArrow === null || notParenthesizedArrow === void 0 ? void 0 : notParenthesizedArrow.has(tokenPos)) {
35000
35005
  return undefined;
35001
35006
  }
35002
- var result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false);
35007
+ var result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false, allowReturnTypeInArrowFunction);
35003
35008
  if (!result) {
35004
35009
  (notParenthesizedArrow || (notParenthesizedArrow = new ts.Set())).add(tokenPos);
35005
35010
  }
35006
35011
  return result;
35007
35012
  }
35008
- function tryParseAsyncSimpleArrowFunctionExpression() {
35013
+ function tryParseAsyncSimpleArrowFunctionExpression(allowReturnTypeInArrowFunction) {
35009
35014
  // We do a check here so that we won't be doing unnecessarily call to "lookAhead"
35010
35015
  if (token() === 131 /* AsyncKeyword */) {
35011
35016
  if (lookAhead(isUnParenthesizedAsyncArrowFunctionWorker) === 1 /* True */) {
35012
35017
  var pos = getNodePos();
35013
35018
  var asyncModifier = parseModifiersForArrowFunction();
35014
35019
  var expr = parseBinaryExpressionOrHigher(0 /* Lowest */);
35015
- return parseSimpleArrowFunctionExpression(pos, expr, asyncModifier);
35020
+ return parseSimpleArrowFunctionExpression(pos, expr, allowReturnTypeInArrowFunction, asyncModifier);
35016
35021
  }
35017
35022
  }
35018
35023
  return undefined;
@@ -35036,7 +35041,7 @@ var ts;
35036
35041
  }
35037
35042
  return 0 /* False */;
35038
35043
  }
35039
- function parseParenthesizedArrowFunctionExpression(allowAmbiguity) {
35044
+ function parseParenthesizedArrowFunctionExpression(allowAmbiguity, allowReturnTypeInArrowFunction) {
35040
35045
  var pos = getNodePos();
35041
35046
  var hasJSDoc = hasPrecedingJSDocComment();
35042
35047
  var modifiers = parseModifiersForArrowFunction();
@@ -35071,6 +35076,7 @@ var ts;
35071
35076
  return undefined;
35072
35077
  }
35073
35078
  }
35079
+ var hasReturnColon = token() === 58 /* ColonToken */;
35074
35080
  var type = parseReturnType(58 /* ColonToken */, /*isType*/ false);
35075
35081
  if (type && !allowAmbiguity && typeHasArrowFunctionBlockingParseError(type)) {
35076
35082
  return undefined;
@@ -35099,12 +35105,37 @@ var ts;
35099
35105
  var lastToken = token();
35100
35106
  var equalsGreaterThanToken = parseExpectedToken(38 /* EqualsGreaterThanToken */);
35101
35107
  var body = (lastToken === 38 /* EqualsGreaterThanToken */ || lastToken === 18 /* OpenBraceToken */)
35102
- ? parseArrowFunctionExpressionBody(ts.some(modifiers, ts.isAsyncModifier))
35108
+ ? parseArrowFunctionExpressionBody(ts.some(modifiers, ts.isAsyncModifier), allowReturnTypeInArrowFunction)
35103
35109
  : parseIdentifier();
35110
+ // Given:
35111
+ // x ? y => ({ y }) : z => ({ z })
35112
+ // We try to parse the body of the first arrow function by looking at:
35113
+ // ({ y }) : z => ({ z })
35114
+ // This is a valid arrow function with "z" as the return type.
35115
+ //
35116
+ // But, if we're in the true side of a conditional expression, this colon
35117
+ // terminates the expression, so we cannot allow a return type if we aren't
35118
+ // certain whether or not the preceding text was parsed as a parameter list.
35119
+ //
35120
+ // For example,
35121
+ // a() ? (b: number, c?: string): void => d() : e
35122
+ // is determined by isParenthesizedArrowFunctionExpression to unambiguously
35123
+ // be an arrow expression, so we allow a return type.
35124
+ if (!allowReturnTypeInArrowFunction && hasReturnColon) {
35125
+ // However, if the arrow function we were able to parse is followed by another colon
35126
+ // as in:
35127
+ // a ? (x): string => x : null
35128
+ // Then allow the arrow function, and treat the second colon as terminating
35129
+ // the conditional expression. It's okay to do this because this code would
35130
+ // be a syntax error in JavaScript (as the second colon shouldn't be there).
35131
+ if (token() !== 58 /* ColonToken */) {
35132
+ return undefined;
35133
+ }
35134
+ }
35104
35135
  var node = factory.createArrowFunction(modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body);
35105
35136
  return withJSDoc(finishNode(node, pos), hasJSDoc);
35106
35137
  }
35107
- function parseArrowFunctionExpressionBody(isAsync) {
35138
+ function parseArrowFunctionExpressionBody(isAsync, allowReturnTypeInArrowFunction) {
35108
35139
  if (token() === 18 /* OpenBraceToken */) {
35109
35140
  return parseFunctionBlock(isAsync ? 2 /* Await */ : 0 /* None */);
35110
35141
  }
@@ -35132,12 +35163,12 @@ var ts;
35132
35163
  var savedTopLevel = topLevel;
35133
35164
  topLevel = false;
35134
35165
  var node = isAsync
35135
- ? doInAwaitContext(parseAssignmentExpressionOrHigher)
35136
- : doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher);
35166
+ ? doInAwaitContext(function () { return parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction); })
35167
+ : doOutsideOfAwaitContext(function () { return parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction); });
35137
35168
  topLevel = savedTopLevel;
35138
35169
  return node;
35139
35170
  }
35140
- function parseConditionalExpressionRest(leftOperand, pos) {
35171
+ function parseConditionalExpressionRest(leftOperand, pos, allowReturnTypeInArrowFunction) {
35141
35172
  // Note: we are passed in an expression which was produced from parseBinaryExpressionOrHigher.
35142
35173
  var questionToken = parseOptionalToken(57 /* QuestionToken */);
35143
35174
  if (!questionToken) {
@@ -35146,8 +35177,8 @@ var ts;
35146
35177
  // Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and
35147
35178
  // we do not that for the 'whenFalse' part.
35148
35179
  var colonToken;
35149
- return finishNode(factory.createConditionalExpression(leftOperand, questionToken, doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher), colonToken = parseExpectedToken(58 /* ColonToken */), ts.nodeIsPresent(colonToken)
35150
- ? parseAssignmentExpressionOrHigher()
35180
+ return finishNode(factory.createConditionalExpression(leftOperand, questionToken, doOutsideOfContext(disallowInAndDecoratorContext, function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ false); }), colonToken = parseExpectedToken(58 /* ColonToken */), ts.nodeIsPresent(colonToken)
35181
+ ? parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction)
35151
35182
  : createMissingNode(79 /* Identifier */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(58 /* ColonToken */))), pos);
35152
35183
  }
35153
35184
  function parseBinaryExpressionOrHigher(precedence) {
@@ -36062,13 +36093,13 @@ var ts;
36062
36093
  function parseSpreadElement() {
36063
36094
  var pos = getNodePos();
36064
36095
  parseExpected(25 /* DotDotDotToken */);
36065
- var expression = parseAssignmentExpressionOrHigher();
36096
+ var expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
36066
36097
  return finishNode(factory.createSpreadElement(expression), pos);
36067
36098
  }
36068
36099
  function parseArgumentOrArrayLiteralElement() {
36069
36100
  return token() === 25 /* DotDotDotToken */ ? parseSpreadElement() :
36070
36101
  token() === 27 /* CommaToken */ ? finishNode(factory.createOmittedExpression(), getNodePos()) :
36071
- parseAssignmentExpressionOrHigher();
36102
+ parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
36072
36103
  }
36073
36104
  function parseArgumentExpression() {
36074
36105
  return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement);
@@ -36086,7 +36117,7 @@ var ts;
36086
36117
  var pos = getNodePos();
36087
36118
  var hasJSDoc = hasPrecedingJSDocComment();
36088
36119
  if (parseOptionalToken(25 /* DotDotDotToken */)) {
36089
- var expression = parseAssignmentExpressionOrHigher();
36120
+ var expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
36090
36121
  return withJSDoc(finishNode(factory.createSpreadAssignment(expression), pos), hasJSDoc);
36091
36122
  }
36092
36123
  var decorators = parseDecorators();
@@ -36115,7 +36146,7 @@ var ts;
36115
36146
  var isShorthandPropertyAssignment = tokenIsIdentifier && (token() !== 58 /* ColonToken */);
36116
36147
  if (isShorthandPropertyAssignment) {
36117
36148
  var equalsToken = parseOptionalToken(63 /* EqualsToken */);
36118
- var objectAssignmentInitializer = equalsToken ? allowInAnd(parseAssignmentExpressionOrHigher) : undefined;
36149
+ var objectAssignmentInitializer = equalsToken ? allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); }) : undefined;
36119
36150
  node = factory.createShorthandPropertyAssignment(name, objectAssignmentInitializer);
36120
36151
  // Save equals token for error reporting.
36121
36152
  // TODO(rbuckton): Consider manufacturing this when we need to report an error as it is otherwise not useful.
@@ -36123,7 +36154,7 @@ var ts;
36123
36154
  }
36124
36155
  else {
36125
36156
  parseExpected(58 /* ColonToken */);
36126
- var initializer = allowInAnd(parseAssignmentExpressionOrHigher);
36157
+ var initializer = allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); });
36127
36158
  node = factory.createPropertyAssignment(name, initializer);
36128
36159
  }
36129
36160
  // Decorators, Modifiers, questionToken, and exclamationToken are not supported by property assignments and are reported in the grammar checker
@@ -36300,7 +36331,7 @@ var ts;
36300
36331
  }
36301
36332
  var node;
36302
36333
  if (awaitToken ? parseExpected(160 /* OfKeyword */) : parseOptional(160 /* OfKeyword */)) {
36303
- var expression = allowInAnd(parseAssignmentExpressionOrHigher);
36334
+ var expression = allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); });
36304
36335
  parseExpected(21 /* CloseParenToken */);
36305
36336
  node = factory.createForOfStatement(awaitToken, initializer, expression, parseStatement());
36306
36337
  }
@@ -37488,7 +37519,7 @@ var ts;
37488
37519
  var pos = getNodePos();
37489
37520
  var name = ts.tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(10 /* StringLiteral */);
37490
37521
  parseExpected(58 /* ColonToken */);
37491
- var value = parseAssignmentExpressionOrHigher();
37522
+ var value = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
37492
37523
  return finishNode(factory.createAssertEntry(name, value), pos);
37493
37524
  }
37494
37525
  function parseAssertClause(skipAssertKeyword) {
@@ -37729,7 +37760,7 @@ var ts;
37729
37760
  else {
37730
37761
  parseExpected(88 /* DefaultKeyword */);
37731
37762
  }
37732
- var expression = parseAssignmentExpressionOrHigher();
37763
+ var expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
37733
37764
  parseSemicolon();
37734
37765
  setAwaitContext(savedAwaitContext);
37735
37766
  var node = factory.createExportAssignment(modifiers, isExportEquals, expression);
@@ -49095,9 +49126,9 @@ var ts;
49095
49126
  return moduleSpecifier && resolveExternalModuleName(moduleSpecifier, moduleSpecifier, /*ignoreErrors*/ true);
49096
49127
  },
49097
49128
  resolveExternalModuleSymbol: resolveExternalModuleSymbol,
49098
- tryGetThisTypeAt: function (nodeIn, includeGlobalThis) {
49129
+ tryGetThisTypeAt: function (nodeIn, includeGlobalThis, container) {
49099
49130
  var node = ts.getParseTreeNode(nodeIn);
49100
- return node && tryGetThisTypeAt(node, includeGlobalThis);
49131
+ return node && tryGetThisTypeAt(node, includeGlobalThis, container);
49101
49132
  },
49102
49133
  getTypeArgumentConstraint: function (nodeIn) {
49103
49134
  var node = ts.getParseTreeNode(nodeIn, ts.isTypeNode);
@@ -59545,7 +59576,7 @@ var ts;
59545
59576
  }
59546
59577
  if (t.flags & 268435456 /* StringMapping */) {
59547
59578
  var constraint = getBaseConstraint(t.type);
59548
- return constraint ? getStringMappingType(t.symbol, constraint) : stringType;
59579
+ return constraint && constraint !== t.type ? getStringMappingType(t.symbol, constraint) : stringType;
59549
59580
  }
59550
59581
  if (t.flags & 8388608 /* IndexedAccess */) {
59551
59582
  if (isMappedTypeGenericIndexedAccess(t)) {
@@ -62515,9 +62546,12 @@ var ts;
62515
62546
  }
62516
62547
  function getStringMappingType(symbol, type) {
62517
62548
  return type.flags & (1048576 /* Union */ | 131072 /* Never */) ? mapType(type, function (t) { return getStringMappingType(symbol, t); }) :
62518
- isGenericIndexType(type) ? getStringMappingTypeForGenericType(symbol, type) :
62519
- type.flags & 128 /* StringLiteral */ ? getStringLiteralType(applyStringMapping(symbol, type.value)) :
62520
- type;
62549
+ // Mapping<Mapping<T>> === Mapping<T>
62550
+ type.flags & 268435456 /* StringMapping */ && symbol === type.symbol ? type :
62551
+ isGenericIndexType(type) || isPatternLiteralPlaceholderType(type) ? getStringMappingTypeForGenericType(symbol, isPatternLiteralPlaceholderType(type) && !(type.flags & 268435456 /* StringMapping */) ? getTemplateLiteralType(["", ""], [type]) : type) :
62552
+ type.flags & 128 /* StringLiteral */ ? getStringLiteralType(applyStringMapping(symbol, type.value)) :
62553
+ type.flags & 134217728 /* TemplateLiteral */ ? getTemplateLiteralType.apply(void 0, applyTemplateStringMapping(symbol, type.texts, type.types)) :
62554
+ type;
62521
62555
  }
62522
62556
  function applyStringMapping(symbol, str) {
62523
62557
  switch (intrinsicTypeKinds.get(symbol.escapedName)) {
@@ -62528,6 +62562,15 @@ var ts;
62528
62562
  }
62529
62563
  return str;
62530
62564
  }
62565
+ function applyTemplateStringMapping(symbol, texts, types) {
62566
+ switch (intrinsicTypeKinds.get(symbol.escapedName)) {
62567
+ case 0 /* Uppercase */: return [texts.map(function (t) { return t.toUpperCase(); }), types.map(function (t) { return getStringMappingType(symbol, t); })];
62568
+ case 1 /* Lowercase */: return [texts.map(function (t) { return t.toLowerCase(); }), types.map(function (t) { return getStringMappingType(symbol, t); })];
62569
+ 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];
62570
+ 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];
62571
+ }
62572
+ return [texts, types];
62573
+ }
62531
62574
  function getStringMappingTypeForGenericType(symbol, type) {
62532
62575
  var id = getSymbolId(symbol) + "," + getTypeId(type);
62533
62576
  var result = stringMappingTypes.get(id);
@@ -62769,7 +62812,7 @@ var ts;
62769
62812
  accessNode;
62770
62813
  }
62771
62814
  function isPatternLiteralPlaceholderType(type) {
62772
- return !!(type.flags & (1 /* Any */ | 4 /* String */ | 8 /* Number */ | 64 /* BigInt */));
62815
+ return !!(type.flags & (1 /* Any */ | 4 /* String */ | 8 /* Number */ | 64 /* BigInt */)) || !!(type.flags & 268435456 /* StringMapping */ && isPatternLiteralPlaceholderType(type.type));
62773
62816
  }
62774
62817
  function isPatternLiteralType(type) {
62775
62818
  return !!(type.flags & 134217728 /* TemplateLiteral */) && ts.every(type.types, isPatternLiteralPlaceholderType);
@@ -66481,6 +66524,13 @@ var ts;
66481
66524
  return -1 /* True */;
66482
66525
  }
66483
66526
  }
66527
+ else if (target.flags & 268435456 /* StringMapping */) {
66528
+ if (!(source.flags & 268435456 /* StringMapping */)) {
66529
+ if (isMemberOfStringMapping(source, target)) {
66530
+ return -1 /* True */;
66531
+ }
66532
+ }
66533
+ }
66484
66534
  if (sourceFlags & 8650752 /* TypeVariable */) {
66485
66535
  // IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
66486
66536
  if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
@@ -66524,7 +66574,10 @@ var ts;
66524
66574
  }
66525
66575
  }
66526
66576
  else if (sourceFlags & 268435456 /* StringMapping */) {
66527
- if (targetFlags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
66577
+ if (targetFlags & 268435456 /* StringMapping */) {
66578
+ if (source.symbol !== target.symbol) {
66579
+ return 0 /* False */;
66580
+ }
66528
66581
  if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
66529
66582
  resetErrorInfo(saveErrorInfo);
66530
66583
  return result;
@@ -67449,7 +67502,7 @@ var ts;
67449
67502
  return typeCouldHaveTopLevelSingletonTypes(constraint);
67450
67503
  }
67451
67504
  }
67452
- return isUnitType(type) || !!(type.flags & 134217728 /* TemplateLiteral */);
67505
+ return isUnitType(type) || !!(type.flags & 134217728 /* TemplateLiteral */) || !!(type.flags & 268435456 /* StringMapping */);
67453
67506
  }
67454
67507
  function getExactOptionalUnassignableProperties(source, target) {
67455
67508
  if (isTupleType(source) && isTupleType(target))
@@ -68920,6 +68973,31 @@ var ts;
68920
68973
  return success && result === 9 /* BigIntLiteral */ && scanner.getTextPos() === (s.length + 1) && !(flags & 512 /* ContainsSeparator */)
68921
68974
  && (!roundTripOnly || s === ts.pseudoBigIntToString({ negative: negative, base10Value: ts.parsePseudoBigInt(scanner.getTokenValue()) }));
68922
68975
  }
68976
+ function isMemberOfStringMapping(source, target) {
68977
+ if (target.flags & (4 /* String */ | 3 /* AnyOrUnknown */)) {
68978
+ return true;
68979
+ }
68980
+ if (target.flags & 134217728 /* TemplateLiteral */) {
68981
+ return isTypeAssignableTo(source, target);
68982
+ }
68983
+ if (target.flags & 268435456 /* StringMapping */) {
68984
+ // We need to see whether applying the same mappings of the target
68985
+ // onto the source would produce an identical type *and* that
68986
+ // it's compatible with the inner-most non-string-mapped type.
68987
+ //
68988
+ // The intuition here is that if same mappings don't affect the source at all,
68989
+ // and the source is compatible with the unmapped target, then they must
68990
+ // still reside in the same domain.
68991
+ var mappingStack = [];
68992
+ while (target.flags & 268435456 /* StringMapping */) {
68993
+ mappingStack.unshift(target.symbol);
68994
+ target = target.type;
68995
+ }
68996
+ var mappedSource = ts.reduceLeft(mappingStack, function (memo, value) { return getStringMappingType(value, memo); }, source);
68997
+ return mappedSource === source && isMemberOfStringMapping(source, target);
68998
+ }
68999
+ return false;
69000
+ }
68923
69001
  function isValidTypeForTemplateLiteralPlaceholder(source, target) {
68924
69002
  if (source === target || target.flags & (1 /* Any */ | 4 /* String */)) {
68925
69003
  return true;
@@ -68928,7 +69006,8 @@ var ts;
68928
69006
  var value = source.value;
68929
69007
  return !!(target.flags & 8 /* Number */ && isValidNumberString(value, /*roundTripOnly*/ false) ||
68930
69008
  target.flags & 64 /* BigInt */ && isValidBigIntString(value, /*roundTripOnly*/ false) ||
68931
- target.flags & (512 /* BooleanLiteral */ | 98304 /* Nullable */) && value === target.intrinsicName);
69009
+ target.flags & (512 /* BooleanLiteral */ | 98304 /* Nullable */) && value === target.intrinsicName ||
69010
+ target.flags & 268435456 /* StringMapping */ && isMemberOfStringMapping(getStringLiteralType(value), target));
68932
69011
  }
68933
69012
  if (source.flags & 134217728 /* TemplateLiteral */) {
68934
69013
  var texts = source.texts;
@@ -85807,6 +85886,7 @@ var ts;
85807
85886
  return true;
85808
85887
  }
85809
85888
  function checkAliasSymbol(node) {
85889
+ var _a, _b, _c, _d, _e;
85810
85890
  var symbol = getSymbolOfNode(node);
85811
85891
  var target = resolveAlias(symbol);
85812
85892
  if (target !== unknownSymbol) {
@@ -85817,6 +85897,31 @@ var ts;
85817
85897
  // otherwise it will conflict with some local declaration). Note that in addition to normal flags we include matching SymbolFlags.Export*
85818
85898
  // in order to prevent collisions with declarations that were exported from the current module (they still contribute to local names).
85819
85899
  symbol = getMergedSymbol(symbol.exportSymbol || symbol);
85900
+ // A type-only import/export will already have a grammar error in a JS file, so no need to issue more errors within
85901
+ if (ts.isInJSFile(node) && !(target.flags & 111551 /* Value */) && !ts.isTypeOnlyImportOrExportDeclaration(node)) {
85902
+ var errorNode = ts.isImportOrExportSpecifier(node) ? node.propertyName || node.name :
85903
+ ts.isNamedDeclaration(node) ? node.name :
85904
+ node;
85905
+ ts.Debug.assert(node.kind !== 274 /* NamespaceExport */);
85906
+ if (node.kind === 275 /* ExportSpecifier */) {
85907
+ var diag = error(errorNode, ts.Diagnostics.Types_cannot_appear_in_export_declarations_in_JavaScript_files);
85908
+ 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);
85909
+ if (alreadyExportedSymbol === target) {
85910
+ var exportingDeclaration = (_c = alreadyExportedSymbol.declarations) === null || _c === void 0 ? void 0 : _c.find(ts.isJSDocNode);
85911
+ if (exportingDeclaration) {
85912
+ ts.addRelatedInfo(diag, ts.createDiagnosticForNode(exportingDeclaration, ts.Diagnostics._0_is_automatically_exported_here, ts.unescapeLeadingUnderscores(alreadyExportedSymbol.escapedName)));
85913
+ }
85914
+ }
85915
+ }
85916
+ else {
85917
+ ts.Debug.assert(node.kind !== 254 /* VariableDeclaration */);
85918
+ var importDeclaration = ts.findAncestor(node, ts.or(ts.isImportDeclaration, ts.isImportEqualsDeclaration));
85919
+ var moduleSpecifier = (_e = (importDeclaration && ((_d = ts.tryGetModuleSpecifierFromDeclaration(importDeclaration)) === null || _d === void 0 ? void 0 : _d.text))) !== null && _e !== void 0 ? _e : "...";
85920
+ var importedIdentifier = ts.unescapeLeadingUnderscores(ts.isIdentifier(errorNode) ? errorNode.escapedText : symbol.escapedName);
85921
+ 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);
85922
+ }
85923
+ return;
85924
+ }
85820
85925
  var excludedMeanings = (symbol.flags & (111551 /* Value */ | 1048576 /* ExportValue */) ? 111551 /* Value */ : 0) |
85821
85926
  (symbol.flags & 788968 /* Type */ ? 788968 /* Type */ : 0) |
85822
85927
  (symbol.flags & 1920 /* Namespace */ ? 1920 /* Namespace */ : 0);
@@ -131236,32 +131341,41 @@ var ts;
131236
131341
  || ts.startsWith(getCanonicalFileName(fromPath), toNodeModulesParent)
131237
131342
  || (!!globalCachePath && ts.startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));
131238
131343
  }
131239
- function forEachExternalModuleToImportFrom(program, host, useAutoImportProvider, cb) {
131344
+ function forEachExternalModuleToImportFrom(program, host, preferences, useAutoImportProvider, cb) {
131240
131345
  var _a, _b;
131241
- forEachExternalModule(program.getTypeChecker(), program.getSourceFiles(), function (module, file) { return cb(module, file, program, /*isFromPackageJson*/ false); });
131346
+ var useCaseSensitiveFileNames = ts.hostUsesCaseSensitiveFileNames(host);
131347
+ var excludePatterns = preferences.autoImportFileExcludePatterns && ts.mapDefined(preferences.autoImportFileExcludePatterns, function (spec) {
131348
+ // The client is expected to send rooted path specs since we don't know
131349
+ // what directory a relative path is relative to.
131350
+ var pattern = ts.getPatternFromSpec(spec, "", "exclude");
131351
+ return pattern ? ts.getRegexFromPattern(pattern, useCaseSensitiveFileNames) : undefined;
131352
+ });
131353
+ forEachExternalModule(program.getTypeChecker(), program.getSourceFiles(), excludePatterns, function (module, file) { return cb(module, file, program, /*isFromPackageJson*/ false); });
131242
131354
  var autoImportProvider = useAutoImportProvider && ((_a = host.getPackageJsonAutoImportProvider) === null || _a === void 0 ? void 0 : _a.call(host));
131243
131355
  if (autoImportProvider) {
131244
131356
  var start = ts.timestamp();
131245
- forEachExternalModule(autoImportProvider.getTypeChecker(), autoImportProvider.getSourceFiles(), function (module, file) { return cb(module, file, autoImportProvider, /*isFromPackageJson*/ true); });
131357
+ forEachExternalModule(autoImportProvider.getTypeChecker(), autoImportProvider.getSourceFiles(), excludePatterns, function (module, file) { return cb(module, file, autoImportProvider, /*isFromPackageJson*/ true); });
131246
131358
  (_b = host.log) === null || _b === void 0 ? void 0 : _b.call(host, "forEachExternalModuleToImportFrom autoImportProvider: " + (ts.timestamp() - start));
131247
131359
  }
131248
131360
  }
131249
131361
  ts.forEachExternalModuleToImportFrom = forEachExternalModuleToImportFrom;
131250
- function forEachExternalModule(checker, allSourceFiles, cb) {
131251
- for (var _i = 0, _a = checker.getAmbientModules(); _i < _a.length; _i++) {
131252
- var ambient = _a[_i];
131253
- if (!ts.stringContains(ambient.name, "*")) {
131362
+ function forEachExternalModule(checker, allSourceFiles, excludePatterns, cb) {
131363
+ var _a;
131364
+ var isExcluded = function (fileName) { return excludePatterns === null || excludePatterns === void 0 ? void 0 : excludePatterns.some(function (p) { return p.test(fileName); }); };
131365
+ for (var _i = 0, _b = checker.getAmbientModules(); _i < _b.length; _i++) {
131366
+ var ambient = _b[_i];
131367
+ if (!ts.stringContains(ambient.name, "*") && !(excludePatterns && ((_a = ambient.declarations) === null || _a === void 0 ? void 0 : _a.every(function (d) { return isExcluded(d.getSourceFile().fileName); })))) {
131254
131368
  cb(ambient, /*sourceFile*/ undefined);
131255
131369
  }
131256
131370
  }
131257
- for (var _b = 0, allSourceFiles_1 = allSourceFiles; _b < allSourceFiles_1.length; _b++) {
131258
- var sourceFile = allSourceFiles_1[_b];
131259
- if (ts.isExternalOrCommonJsModule(sourceFile)) {
131371
+ for (var _c = 0, allSourceFiles_1 = allSourceFiles; _c < allSourceFiles_1.length; _c++) {
131372
+ var sourceFile = allSourceFiles_1[_c];
131373
+ if (ts.isExternalOrCommonJsModule(sourceFile) && !isExcluded(sourceFile.fileName)) {
131260
131374
  cb(checker.getMergedSymbol(sourceFile.symbol), sourceFile);
131261
131375
  }
131262
131376
  }
131263
131377
  }
131264
- function getExportInfoMap(importingFile, host, program, cancellationToken) {
131378
+ function getExportInfoMap(importingFile, host, program, preferences, cancellationToken) {
131265
131379
  var _a, _b, _c, _d, _e;
131266
131380
  var start = ts.timestamp();
131267
131381
  // Pulling the AutoImportProvider project will trigger its updateGraph if pending,
@@ -131281,7 +131395,7 @@ var ts;
131281
131395
  var compilerOptions = program.getCompilerOptions();
131282
131396
  var moduleCount = 0;
131283
131397
  try {
131284
- forEachExternalModuleToImportFrom(program, host, /*useAutoImportProvider*/ true, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
131398
+ forEachExternalModuleToImportFrom(program, host, preferences, /*useAutoImportProvider*/ true, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
131285
131399
  if (++moduleCount % 100 === 0)
131286
131400
  cancellationToken === null || cancellationToken === void 0 ? void 0 : cancellationToken.throwIfCancellationRequested();
131287
131401
  var seenExports = new ts.Map();
@@ -133677,7 +133791,7 @@ var ts;
133677
133791
  if (!previousResponse)
133678
133792
  return undefined;
133679
133793
  var lowerCaseTokenText = location.text.toLowerCase();
133680
- var exportMap = ts.getExportInfoMap(file, host, program, cancellationToken);
133794
+ var exportMap = ts.getExportInfoMap(file, host, program, preferences, cancellationToken);
133681
133795
  var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, ts.codefix.createImportSpecifierResolver(file, program, host, preferences), program, location.getStart(), preferences,
133682
133796
  /*isForImportStatementCompletion*/ false, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
133683
133797
  var entries = ts.mapDefined(previousResponse.entries, function (entry) {
@@ -135386,7 +135500,7 @@ var ts;
135386
135500
  }
135387
135501
  // Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions`
135388
135502
  if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== 305 /* SourceFile */) {
135389
- var thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false);
135503
+ var thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false, ts.isClassLike(scopeNode.parent) ? scopeNode : undefined);
135390
135504
  if (thisType && !isProbablyGlobalType(thisType, sourceFile, typeChecker)) {
135391
135505
  for (var _i = 0, _a = getPropertiesForCompletion(thisType, typeChecker); _i < _a.length; _i++) {
135392
135506
  var symbol = _a[_i];
@@ -135489,7 +135603,7 @@ var ts;
135489
135603
  previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() :
135490
135604
  "";
135491
135605
  var moduleSpecifierCache = (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host);
135492
- var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
135606
+ var exportInfo = ts.getExportInfoMap(sourceFile, host, program, preferences, cancellationToken);
135493
135607
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
135494
135608
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
135495
135609
  resolvingModuleSpecifiers("collectAutoImports", host, importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences)), program, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
@@ -144724,10 +144838,10 @@ var ts;
144724
144838
  (function (ts) {
144725
144839
  var Rename;
144726
144840
  (function (Rename) {
144727
- function getRenameInfo(program, sourceFile, position, options) {
144841
+ function getRenameInfo(program, sourceFile, position, preferences) {
144728
144842
  var node = ts.getAdjustedRenameLocation(ts.getTouchingPropertyName(sourceFile, position));
144729
144843
  if (nodeIsEligibleForRename(node)) {
144730
- var renameInfo = getRenameInfoForNode(node, program.getTypeChecker(), sourceFile, program, options);
144844
+ var renameInfo = getRenameInfoForNode(node, program.getTypeChecker(), sourceFile, program, preferences);
144731
144845
  if (renameInfo) {
144732
144846
  return renameInfo;
144733
144847
  }
@@ -144735,7 +144849,7 @@ var ts;
144735
144849
  return getRenameInfoError(ts.Diagnostics.You_cannot_rename_this_element);
144736
144850
  }
144737
144851
  Rename.getRenameInfo = getRenameInfo;
144738
- function getRenameInfoForNode(node, typeChecker, sourceFile, program, options) {
144852
+ function getRenameInfoForNode(node, typeChecker, sourceFile, program, preferences) {
144739
144853
  var symbol = typeChecker.getSymbolAtLocation(node);
144740
144854
  if (!symbol) {
144741
144855
  if (ts.isStringLiteralLike(node)) {
@@ -144763,7 +144877,12 @@ var ts;
144763
144877
  return undefined;
144764
144878
  }
144765
144879
  if (ts.isStringLiteralLike(node) && ts.tryGetImportFromModuleSpecifier(node)) {
144766
- return options && options.allowRenameOfImportPath ? getRenameInfoForModule(node, sourceFile, symbol) : undefined;
144880
+ return preferences.allowRenameOfImportPath ? getRenameInfoForModule(node, sourceFile, symbol) : undefined;
144881
+ }
144882
+ // Disallow rename for elements that would rename across `*/node_modules/*` packages.
144883
+ var wouldRenameNodeModules = wouldRenameInOtherNodeModules(sourceFile, symbol, typeChecker, preferences);
144884
+ if (wouldRenameNodeModules) {
144885
+ return getRenameInfoError(wouldRenameNodeModules);
144767
144886
  }
144768
144887
  var kind = ts.SymbolDisplay.getSymbolKind(typeChecker, symbol, node);
144769
144888
  var specifierName = (ts.isImportOrExportSpecifierName(node) || ts.isStringOrNumericLiteralLike(node) && node.parent.kind === 162 /* ComputedPropertyName */)
@@ -144777,6 +144896,49 @@ var ts;
144777
144896
  var sourceFile = declaration.getSourceFile();
144778
144897
  return program.isSourceFileDefaultLibrary(sourceFile) && ts.fileExtensionIs(sourceFile.fileName, ".d.ts" /* Dts */);
144779
144898
  }
144899
+ function wouldRenameInOtherNodeModules(originalFile, symbol, checker, preferences) {
144900
+ if (!preferences.providePrefixAndSuffixTextForRename && symbol.flags & 2097152 /* Alias */) {
144901
+ var importSpecifier = symbol.declarations && ts.find(symbol.declarations, function (decl) { return ts.isImportSpecifier(decl); });
144902
+ if (importSpecifier && !importSpecifier.propertyName) {
144903
+ symbol = checker.getAliasedSymbol(symbol);
144904
+ }
144905
+ }
144906
+ var declarations = symbol.declarations;
144907
+ if (!declarations) {
144908
+ return undefined;
144909
+ }
144910
+ var originalPackage = getPackagePathComponents(originalFile.path);
144911
+ if (originalPackage === undefined) { // original source file is not in node_modules
144912
+ if (ts.some(declarations, function (declaration) { return ts.isInsideNodeModules(declaration.getSourceFile().path); })) {
144913
+ return ts.Diagnostics.You_cannot_rename_elements_that_are_defined_in_a_node_modules_folder;
144914
+ }
144915
+ else {
144916
+ return undefined;
144917
+ }
144918
+ }
144919
+ // original source file is in node_modules
144920
+ for (var _i = 0, declarations_4 = declarations; _i < declarations_4.length; _i++) {
144921
+ var declaration = declarations_4[_i];
144922
+ var declPackage = getPackagePathComponents(declaration.getSourceFile().path);
144923
+ if (declPackage) {
144924
+ var length_2 = Math.min(originalPackage.length, declPackage.length);
144925
+ for (var i = 0; i <= length_2; i++) {
144926
+ if (ts.compareStringsCaseSensitive(originalPackage[i], declPackage[i]) !== 0 /* EqualTo */) {
144927
+ return ts.Diagnostics.You_cannot_rename_elements_that_are_defined_in_another_node_modules_folder;
144928
+ }
144929
+ }
144930
+ }
144931
+ }
144932
+ return undefined;
144933
+ }
144934
+ function getPackagePathComponents(filePath) {
144935
+ var components = ts.getPathComponents(filePath);
144936
+ var nodeModulesIdx = components.lastIndexOf("node_modules");
144937
+ if (nodeModulesIdx === -1) {
144938
+ return undefined;
144939
+ }
144940
+ return components.slice(0, nodeModulesIdx + 2);
144941
+ }
144780
144942
  function getRenameInfoForModule(node, sourceFile, moduleSymbol) {
144781
144943
  if (!ts.isExternalModuleNameRelative(node.text)) {
144782
144944
  return getRenameInfoError(ts.Diagnostics.You_cannot_rename_a_module_via_a_global_import);
@@ -154638,7 +154800,7 @@ var ts;
154638
154800
  var getModuleSpecifierResolutionHost = ts.memoizeOne(function (isFromPackageJson) {
154639
154801
  return ts.createModuleSpecifierResolutionHost(isFromPackageJson ? host.getPackageJsonAutoImportProvider() : program, host);
154640
154802
  });
154641
- ts.forEachExternalModuleToImportFrom(program, host, useAutoImportProvider, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
154803
+ ts.forEachExternalModuleToImportFrom(program, host, preferences, useAutoImportProvider, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
154642
154804
  var checker = program.getTypeChecker();
154643
154805
  // Don't import from a re-export when looking "up" like to `./index` or `../index`.
154644
154806
  if (moduleFile && moduleSymbol !== exportingModuleSymbol && ts.startsWith(importingFile.fileName, ts.getDirectoryPath(moduleFile.fileName))) {
@@ -155107,7 +155269,7 @@ var ts;
155107
155269
  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 });
155108
155270
  }
155109
155271
  }
155110
- ts.forEachExternalModuleToImportFrom(program, host, useAutoImportProvider, function (moduleSymbol, sourceFile, program, isFromPackageJson) {
155272
+ ts.forEachExternalModuleToImportFrom(program, host, preferences, useAutoImportProvider, function (moduleSymbol, sourceFile, program, isFromPackageJson) {
155111
155273
  var checker = program.getTypeChecker();
155112
155274
  cancellationToken.throwIfCancellationRequested();
155113
155275
  var compilerOptions = program.getCompilerOptions();
@@ -161816,11 +161978,11 @@ var ts;
161816
161978
  }
161817
161979
  }
161818
161980
  else if (ts.isVariableStatement(node) || ts.isVariableDeclarationList(node)) {
161819
- var declarations_5 = ts.isVariableStatement(node) ? node.declarationList.declarations : node.declarations;
161981
+ var declarations_6 = ts.isVariableStatement(node) ? node.declarationList.declarations : node.declarations;
161820
161982
  var numInitializers = 0;
161821
161983
  var lastInitializer = void 0;
161822
- for (var _i = 0, declarations_4 = declarations_5; _i < declarations_4.length; _i++) {
161823
- var declaration = declarations_4[_i];
161984
+ for (var _i = 0, declarations_5 = declarations_6; _i < declarations_5.length; _i++) {
161985
+ var declaration = declarations_5[_i];
161824
161986
  if (declaration.initializer) {
161825
161987
  numInitializers++;
161826
161988
  lastInitializer = declaration.initializer;
@@ -165957,8 +166119,8 @@ var ts;
165957
166119
  tags = __spreadArray(__spreadArray([], inheritedTags, true), tags, true);
165958
166120
  }
165959
166121
  };
165960
- for (var _i = 0, declarations_6 = declarations; _i < declarations_6.length; _i++) {
165961
- var declaration = declarations_6[_i];
166122
+ for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
166123
+ var declaration = declarations_7[_i];
165962
166124
  _loop_21(declaration);
165963
166125
  }
165964
166126
  }
@@ -165984,8 +166146,8 @@ var ts;
165984
166146
  if (inheritedDocs)
165985
166147
  doc = doc.length === 0 ? inheritedDocs.slice() : inheritedDocs.concat(ts.lineBreakPart(), doc);
165986
166148
  };
165987
- for (var _i = 0, declarations_7 = declarations; _i < declarations_7.length; _i++) {
165988
- var declaration = declarations_7[_i];
166149
+ for (var _i = 0, declarations_8 = declarations; _i < declarations_8.length; _i++) {
166150
+ var declaration = declarations_8[_i];
165989
166151
  _loop_22(declaration);
165990
166152
  }
165991
166153
  }
@@ -167562,9 +167724,9 @@ var ts;
167562
167724
  return ts.stringContains(path, "/node_modules/");
167563
167725
  }
167564
167726
  }
167565
- function getRenameInfo(fileName, position, options) {
167727
+ function getRenameInfo(fileName, position, preferences) {
167566
167728
  synchronizeHostData();
167567
- return ts.Rename.getRenameInfo(program, getValidSourceFile(fileName), position, options);
167729
+ return ts.Rename.getRenameInfo(program, getValidSourceFile(fileName), position, preferences || {});
167568
167730
  }
167569
167731
  function getRefactorContext(file, positionOrRange, preferences, formatOptions, triggerReason, kind) {
167570
167732
  var _a = typeof positionOrRange === "number" ? [positionOrRange, undefined] : [positionOrRange.pos, positionOrRange.end], startPosition = _a[0], endPosition = _a[1];
@@ -168930,9 +169092,9 @@ var ts;
168930
169092
  var _this = this;
168931
169093
  return this.forwardJSONCall("getImplementationAtPosition('" + fileName + "', " + position + ")", function () { return _this.languageService.getImplementationAtPosition(fileName, position); });
168932
169094
  };
168933
- LanguageServiceShimObject.prototype.getRenameInfo = function (fileName, position, options) {
169095
+ LanguageServiceShimObject.prototype.getRenameInfo = function (fileName, position, preferences) {
168934
169096
  var _this = this;
168935
- return this.forwardJSONCall("getRenameInfo('" + fileName + "', " + position + ")", function () { return _this.languageService.getRenameInfo(fileName, position, options); });
169097
+ return this.forwardJSONCall("getRenameInfo('" + fileName + "', " + position + ")", function () { return _this.languageService.getRenameInfo(fileName, position, preferences); });
168936
169098
  };
168937
169099
  LanguageServiceShimObject.prototype.getSmartSelectionRange = function (fileName, position) {
168938
169100
  var _this = this;