typescript 4.8.0-dev.20220617 → 4.8.0-dev.20220620

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.
@@ -303,7 +303,7 @@ var ts;
303
303
  // The following is baselined as a literal template type without intervention
304
304
  /** The version of the TypeScript compiler release */
305
305
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
306
- ts.version = ts.versionMajorMinor + ".0-dev.20220617";
306
+ ts.version = ts.versionMajorMinor + ".0-dev.20220620";
307
307
  /* @internal */
308
308
  var Comparison;
309
309
  (function (Comparison) {
@@ -10138,6 +10138,9 @@ var ts;
10138
10138
  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."),
10139
10139
  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."),
10140
10140
  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."),
10141
+ _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."),
10142
+ 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."),
10143
+ _0_is_automatically_exported_here: diag(18044, ts.DiagnosticCategory.Message, "_0_is_automatically_exported_here_18044", "'{0}' is automatically exported here."),
10141
10144
  };
10142
10145
  })(ts || (ts = {}));
10143
10146
  var ts;
@@ -34726,10 +34729,10 @@ var ts;
34726
34729
  setDecoratorContext(/*val*/ false);
34727
34730
  }
34728
34731
  var pos = getNodePos();
34729
- var expr = parseAssignmentExpressionOrHigher();
34732
+ var expr = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
34730
34733
  var operatorToken;
34731
34734
  while ((operatorToken = parseOptionalToken(27 /* CommaToken */))) {
34732
- expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(), pos);
34735
+ expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true), pos);
34733
34736
  }
34734
34737
  if (saveDecoratorContext) {
34735
34738
  setDecoratorContext(/*val*/ true);
@@ -34737,9 +34740,9 @@ var ts;
34737
34740
  return expr;
34738
34741
  }
34739
34742
  function parseInitializer() {
34740
- return parseOptional(63 /* EqualsToken */) ? parseAssignmentExpressionOrHigher() : undefined;
34743
+ return parseOptional(63 /* EqualsToken */) ? parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true) : undefined;
34741
34744
  }
34742
- function parseAssignmentExpressionOrHigher() {
34745
+ function parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction) {
34743
34746
  // AssignmentExpression[in,yield]:
34744
34747
  // 1) ConditionalExpression[?in,?yield]
34745
34748
  // 2) LeftHandSideExpression = AssignmentExpression[?in,?yield]
@@ -34765,7 +34768,7 @@ var ts;
34765
34768
  // If we do successfully parse arrow-function, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is
34766
34769
  // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done
34767
34770
  // with AssignmentExpression if we see one.
34768
- var arrowExpression = tryParseParenthesizedArrowFunctionExpression() || tryParseAsyncSimpleArrowFunctionExpression();
34771
+ var arrowExpression = tryParseParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction) || tryParseAsyncSimpleArrowFunctionExpression(allowReturnTypeInArrowFunction);
34769
34772
  if (arrowExpression) {
34770
34773
  return arrowExpression;
34771
34774
  }
@@ -34784,7 +34787,7 @@ var ts;
34784
34787
  // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single
34785
34788
  // identifier and the current token is an arrow.
34786
34789
  if (expr.kind === 79 /* Identifier */ && token() === 38 /* EqualsGreaterThanToken */) {
34787
- return parseSimpleArrowFunctionExpression(pos, expr, /*asyncModifier*/ undefined);
34790
+ return parseSimpleArrowFunctionExpression(pos, expr, allowReturnTypeInArrowFunction, /*asyncModifier*/ undefined);
34788
34791
  }
34789
34792
  // Now see if we might be in cases '2' or '3'.
34790
34793
  // If the expression was a LHS expression, and we have an assignment operator, then
@@ -34793,10 +34796,10 @@ var ts;
34793
34796
  // Note: we call reScanGreaterToken so that we get an appropriately merged token
34794
34797
  // for cases like `> > =` becoming `>>=`
34795
34798
  if (ts.isLeftHandSideExpression(expr) && ts.isAssignmentOperator(reScanGreaterToken())) {
34796
- return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(), pos);
34799
+ return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction), pos);
34797
34800
  }
34798
34801
  // It wasn't an assignment or a lambda. This is a conditional expression:
34799
- return parseConditionalExpressionRest(expr, pos);
34802
+ return parseConditionalExpressionRest(expr, pos, allowReturnTypeInArrowFunction);
34800
34803
  }
34801
34804
  function isYieldExpression() {
34802
34805
  if (token() === 125 /* YieldKeyword */) {
@@ -34836,7 +34839,7 @@ var ts;
34836
34839
  nextToken();
34837
34840
  if (!scanner.hasPrecedingLineBreak() &&
34838
34841
  (token() === 41 /* AsteriskToken */ || isStartOfExpression())) {
34839
- return finishNode(factory.createYieldExpression(parseOptionalToken(41 /* AsteriskToken */), parseAssignmentExpressionOrHigher()), pos);
34842
+ return finishNode(factory.createYieldExpression(parseOptionalToken(41 /* AsteriskToken */), parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true)), pos);
34840
34843
  }
34841
34844
  else {
34842
34845
  // if the next token is not on the same line as yield. or we don't have an '*' or
@@ -34844,7 +34847,7 @@ var ts;
34844
34847
  return finishNode(factory.createYieldExpression(/*asteriskToken*/ undefined, /*expression*/ undefined), pos);
34845
34848
  }
34846
34849
  }
34847
- function parseSimpleArrowFunctionExpression(pos, identifier, asyncModifier) {
34850
+ function parseSimpleArrowFunctionExpression(pos, identifier, allowReturnTypeInArrowFunction, asyncModifier) {
34848
34851
  ts.Debug.assert(token() === 38 /* EqualsGreaterThanToken */, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
34849
34852
  var parameter = factory.createParameterDeclaration(
34850
34853
  /*modifiers*/ undefined,
@@ -34855,11 +34858,11 @@ var ts;
34855
34858
  finishNode(parameter, identifier.pos);
34856
34859
  var parameters = createNodeArray([parameter], parameter.pos, parameter.end);
34857
34860
  var equalsGreaterThanToken = parseExpectedToken(38 /* EqualsGreaterThanToken */);
34858
- var body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier);
34861
+ var body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier, allowReturnTypeInArrowFunction);
34859
34862
  var node = factory.createArrowFunction(asyncModifier, /*typeParameters*/ undefined, parameters, /*type*/ undefined, equalsGreaterThanToken, body);
34860
34863
  return addJSDocComment(finishNode(node, pos));
34861
34864
  }
34862
- function tryParseParenthesizedArrowFunctionExpression() {
34865
+ function tryParseParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction) {
34863
34866
  var triState = isParenthesizedArrowFunctionExpression();
34864
34867
  if (triState === 0 /* False */) {
34865
34868
  // It's definitely not a parenthesized arrow function expression.
@@ -34870,8 +34873,8 @@ var ts;
34870
34873
  // it out, but don't allow any ambiguity, and return 'undefined' if this could be an
34871
34874
  // expression instead.
34872
34875
  return triState === 1 /* True */ ?
34873
- parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true) :
34874
- tryParse(parsePossibleParenthesizedArrowFunctionExpression);
34876
+ parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true, /*allowReturnTypeInArrowFunction*/ true) :
34877
+ tryParse(function () { return parsePossibleParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction); });
34875
34878
  }
34876
34879
  // True -> We definitely expect a parenthesized arrow function here.
34877
34880
  // False -> There *cannot* be a parenthesized arrow function here.
@@ -35005,25 +35008,25 @@ var ts;
35005
35008
  return 2 /* Unknown */;
35006
35009
  }
35007
35010
  }
35008
- function parsePossibleParenthesizedArrowFunctionExpression() {
35011
+ function parsePossibleParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction) {
35009
35012
  var tokenPos = scanner.getTokenPos();
35010
35013
  if (notParenthesizedArrow === null || notParenthesizedArrow === void 0 ? void 0 : notParenthesizedArrow.has(tokenPos)) {
35011
35014
  return undefined;
35012
35015
  }
35013
- var result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false);
35016
+ var result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false, allowReturnTypeInArrowFunction);
35014
35017
  if (!result) {
35015
35018
  (notParenthesizedArrow || (notParenthesizedArrow = new ts.Set())).add(tokenPos);
35016
35019
  }
35017
35020
  return result;
35018
35021
  }
35019
- function tryParseAsyncSimpleArrowFunctionExpression() {
35022
+ function tryParseAsyncSimpleArrowFunctionExpression(allowReturnTypeInArrowFunction) {
35020
35023
  // We do a check here so that we won't be doing unnecessarily call to "lookAhead"
35021
35024
  if (token() === 131 /* AsyncKeyword */) {
35022
35025
  if (lookAhead(isUnParenthesizedAsyncArrowFunctionWorker) === 1 /* True */) {
35023
35026
  var pos = getNodePos();
35024
35027
  var asyncModifier = parseModifiersForArrowFunction();
35025
35028
  var expr = parseBinaryExpressionOrHigher(0 /* Lowest */);
35026
- return parseSimpleArrowFunctionExpression(pos, expr, asyncModifier);
35029
+ return parseSimpleArrowFunctionExpression(pos, expr, allowReturnTypeInArrowFunction, asyncModifier);
35027
35030
  }
35028
35031
  }
35029
35032
  return undefined;
@@ -35047,7 +35050,7 @@ var ts;
35047
35050
  }
35048
35051
  return 0 /* False */;
35049
35052
  }
35050
- function parseParenthesizedArrowFunctionExpression(allowAmbiguity) {
35053
+ function parseParenthesizedArrowFunctionExpression(allowAmbiguity, allowReturnTypeInArrowFunction) {
35051
35054
  var pos = getNodePos();
35052
35055
  var hasJSDoc = hasPrecedingJSDocComment();
35053
35056
  var modifiers = parseModifiersForArrowFunction();
@@ -35082,6 +35085,7 @@ var ts;
35082
35085
  return undefined;
35083
35086
  }
35084
35087
  }
35088
+ var hasReturnColon = token() === 58 /* ColonToken */;
35085
35089
  var type = parseReturnType(58 /* ColonToken */, /*isType*/ false);
35086
35090
  if (type && !allowAmbiguity && typeHasArrowFunctionBlockingParseError(type)) {
35087
35091
  return undefined;
@@ -35110,12 +35114,37 @@ var ts;
35110
35114
  var lastToken = token();
35111
35115
  var equalsGreaterThanToken = parseExpectedToken(38 /* EqualsGreaterThanToken */);
35112
35116
  var body = (lastToken === 38 /* EqualsGreaterThanToken */ || lastToken === 18 /* OpenBraceToken */)
35113
- ? parseArrowFunctionExpressionBody(ts.some(modifiers, ts.isAsyncModifier))
35117
+ ? parseArrowFunctionExpressionBody(ts.some(modifiers, ts.isAsyncModifier), allowReturnTypeInArrowFunction)
35114
35118
  : parseIdentifier();
35119
+ // Given:
35120
+ // x ? y => ({ y }) : z => ({ z })
35121
+ // We try to parse the body of the first arrow function by looking at:
35122
+ // ({ y }) : z => ({ z })
35123
+ // This is a valid arrow function with "z" as the return type.
35124
+ //
35125
+ // But, if we're in the true side of a conditional expression, this colon
35126
+ // terminates the expression, so we cannot allow a return type if we aren't
35127
+ // certain whether or not the preceding text was parsed as a parameter list.
35128
+ //
35129
+ // For example,
35130
+ // a() ? (b: number, c?: string): void => d() : e
35131
+ // is determined by isParenthesizedArrowFunctionExpression to unambiguously
35132
+ // be an arrow expression, so we allow a return type.
35133
+ if (!allowReturnTypeInArrowFunction && hasReturnColon) {
35134
+ // However, if the arrow function we were able to parse is followed by another colon
35135
+ // as in:
35136
+ // a ? (x): string => x : null
35137
+ // Then allow the arrow function, and treat the second colon as terminating
35138
+ // the conditional expression. It's okay to do this because this code would
35139
+ // be a syntax error in JavaScript (as the second colon shouldn't be there).
35140
+ if (token() !== 58 /* ColonToken */) {
35141
+ return undefined;
35142
+ }
35143
+ }
35115
35144
  var node = factory.createArrowFunction(modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body);
35116
35145
  return withJSDoc(finishNode(node, pos), hasJSDoc);
35117
35146
  }
35118
- function parseArrowFunctionExpressionBody(isAsync) {
35147
+ function parseArrowFunctionExpressionBody(isAsync, allowReturnTypeInArrowFunction) {
35119
35148
  if (token() === 18 /* OpenBraceToken */) {
35120
35149
  return parseFunctionBlock(isAsync ? 2 /* Await */ : 0 /* None */);
35121
35150
  }
@@ -35143,12 +35172,12 @@ var ts;
35143
35172
  var savedTopLevel = topLevel;
35144
35173
  topLevel = false;
35145
35174
  var node = isAsync
35146
- ? doInAwaitContext(parseAssignmentExpressionOrHigher)
35147
- : doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher);
35175
+ ? doInAwaitContext(function () { return parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction); })
35176
+ : doOutsideOfAwaitContext(function () { return parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction); });
35148
35177
  topLevel = savedTopLevel;
35149
35178
  return node;
35150
35179
  }
35151
- function parseConditionalExpressionRest(leftOperand, pos) {
35180
+ function parseConditionalExpressionRest(leftOperand, pos, allowReturnTypeInArrowFunction) {
35152
35181
  // Note: we are passed in an expression which was produced from parseBinaryExpressionOrHigher.
35153
35182
  var questionToken = parseOptionalToken(57 /* QuestionToken */);
35154
35183
  if (!questionToken) {
@@ -35157,8 +35186,8 @@ var ts;
35157
35186
  // Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and
35158
35187
  // we do not that for the 'whenFalse' part.
35159
35188
  var colonToken;
35160
- return finishNode(factory.createConditionalExpression(leftOperand, questionToken, doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher), colonToken = parseExpectedToken(58 /* ColonToken */), ts.nodeIsPresent(colonToken)
35161
- ? parseAssignmentExpressionOrHigher()
35189
+ return finishNode(factory.createConditionalExpression(leftOperand, questionToken, doOutsideOfContext(disallowInAndDecoratorContext, function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ false); }), colonToken = parseExpectedToken(58 /* ColonToken */), ts.nodeIsPresent(colonToken)
35190
+ ? parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction)
35162
35191
  : createMissingNode(79 /* Identifier */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(58 /* ColonToken */))), pos);
35163
35192
  }
35164
35193
  function parseBinaryExpressionOrHigher(precedence) {
@@ -36073,13 +36102,13 @@ var ts;
36073
36102
  function parseSpreadElement() {
36074
36103
  var pos = getNodePos();
36075
36104
  parseExpected(25 /* DotDotDotToken */);
36076
- var expression = parseAssignmentExpressionOrHigher();
36105
+ var expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
36077
36106
  return finishNode(factory.createSpreadElement(expression), pos);
36078
36107
  }
36079
36108
  function parseArgumentOrArrayLiteralElement() {
36080
36109
  return token() === 25 /* DotDotDotToken */ ? parseSpreadElement() :
36081
36110
  token() === 27 /* CommaToken */ ? finishNode(factory.createOmittedExpression(), getNodePos()) :
36082
- parseAssignmentExpressionOrHigher();
36111
+ parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
36083
36112
  }
36084
36113
  function parseArgumentExpression() {
36085
36114
  return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement);
@@ -36097,7 +36126,7 @@ var ts;
36097
36126
  var pos = getNodePos();
36098
36127
  var hasJSDoc = hasPrecedingJSDocComment();
36099
36128
  if (parseOptionalToken(25 /* DotDotDotToken */)) {
36100
- var expression = parseAssignmentExpressionOrHigher();
36129
+ var expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
36101
36130
  return withJSDoc(finishNode(factory.createSpreadAssignment(expression), pos), hasJSDoc);
36102
36131
  }
36103
36132
  var decorators = parseDecorators();
@@ -36126,7 +36155,7 @@ var ts;
36126
36155
  var isShorthandPropertyAssignment = tokenIsIdentifier && (token() !== 58 /* ColonToken */);
36127
36156
  if (isShorthandPropertyAssignment) {
36128
36157
  var equalsToken = parseOptionalToken(63 /* EqualsToken */);
36129
- var objectAssignmentInitializer = equalsToken ? allowInAnd(parseAssignmentExpressionOrHigher) : undefined;
36158
+ var objectAssignmentInitializer = equalsToken ? allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); }) : undefined;
36130
36159
  node = factory.createShorthandPropertyAssignment(name, objectAssignmentInitializer);
36131
36160
  // Save equals token for error reporting.
36132
36161
  // TODO(rbuckton): Consider manufacturing this when we need to report an error as it is otherwise not useful.
@@ -36134,7 +36163,7 @@ var ts;
36134
36163
  }
36135
36164
  else {
36136
36165
  parseExpected(58 /* ColonToken */);
36137
- var initializer = allowInAnd(parseAssignmentExpressionOrHigher);
36166
+ var initializer = allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); });
36138
36167
  node = factory.createPropertyAssignment(name, initializer);
36139
36168
  }
36140
36169
  // Decorators, Modifiers, questionToken, and exclamationToken are not supported by property assignments and are reported in the grammar checker
@@ -36311,7 +36340,7 @@ var ts;
36311
36340
  }
36312
36341
  var node;
36313
36342
  if (awaitToken ? parseExpected(160 /* OfKeyword */) : parseOptional(160 /* OfKeyword */)) {
36314
- var expression = allowInAnd(parseAssignmentExpressionOrHigher);
36343
+ var expression = allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); });
36315
36344
  parseExpected(21 /* CloseParenToken */);
36316
36345
  node = factory.createForOfStatement(awaitToken, initializer, expression, parseStatement());
36317
36346
  }
@@ -37499,7 +37528,7 @@ var ts;
37499
37528
  var pos = getNodePos();
37500
37529
  var name = ts.tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(10 /* StringLiteral */);
37501
37530
  parseExpected(58 /* ColonToken */);
37502
- var value = parseAssignmentExpressionOrHigher();
37531
+ var value = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
37503
37532
  return finishNode(factory.createAssertEntry(name, value), pos);
37504
37533
  }
37505
37534
  function parseAssertClause(skipAssertKeyword) {
@@ -37740,7 +37769,7 @@ var ts;
37740
37769
  else {
37741
37770
  parseExpected(88 /* DefaultKeyword */);
37742
37771
  }
37743
- var expression = parseAssignmentExpressionOrHigher();
37772
+ var expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
37744
37773
  parseSemicolon();
37745
37774
  setAwaitContext(savedAwaitContext);
37746
37775
  var node = factory.createExportAssignment(modifiers, isExportEquals, expression);
@@ -85866,6 +85895,7 @@ var ts;
85866
85895
  return true;
85867
85896
  }
85868
85897
  function checkAliasSymbol(node) {
85898
+ var _a, _b, _c, _d, _e;
85869
85899
  var symbol = getSymbolOfNode(node);
85870
85900
  var target = resolveAlias(symbol);
85871
85901
  if (target !== unknownSymbol) {
@@ -85876,6 +85906,31 @@ var ts;
85876
85906
  // otherwise it will conflict with some local declaration). Note that in addition to normal flags we include matching SymbolFlags.Export*
85877
85907
  // in order to prevent collisions with declarations that were exported from the current module (they still contribute to local names).
85878
85908
  symbol = getMergedSymbol(symbol.exportSymbol || symbol);
85909
+ // A type-only import/export will already have a grammar error in a JS file, so no need to issue more errors within
85910
+ if (ts.isInJSFile(node) && !(target.flags & 111551 /* Value */) && !ts.isTypeOnlyImportOrExportDeclaration(node)) {
85911
+ var errorNode = ts.isImportOrExportSpecifier(node) ? node.propertyName || node.name :
85912
+ ts.isNamedDeclaration(node) ? node.name :
85913
+ node;
85914
+ ts.Debug.assert(node.kind !== 274 /* NamespaceExport */);
85915
+ if (node.kind === 275 /* ExportSpecifier */) {
85916
+ var diag = error(errorNode, ts.Diagnostics.Types_cannot_appear_in_export_declarations_in_JavaScript_files);
85917
+ 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);
85918
+ if (alreadyExportedSymbol === target) {
85919
+ var exportingDeclaration = (_c = alreadyExportedSymbol.declarations) === null || _c === void 0 ? void 0 : _c.find(ts.isJSDocNode);
85920
+ if (exportingDeclaration) {
85921
+ ts.addRelatedInfo(diag, ts.createDiagnosticForNode(exportingDeclaration, ts.Diagnostics._0_is_automatically_exported_here, ts.unescapeLeadingUnderscores(alreadyExportedSymbol.escapedName)));
85922
+ }
85923
+ }
85924
+ }
85925
+ else {
85926
+ ts.Debug.assert(node.kind !== 254 /* VariableDeclaration */);
85927
+ var importDeclaration = ts.findAncestor(node, ts.or(ts.isImportDeclaration, ts.isImportEqualsDeclaration));
85928
+ var moduleSpecifier = (_e = (importDeclaration && ((_d = ts.tryGetModuleSpecifierFromDeclaration(importDeclaration)) === null || _d === void 0 ? void 0 : _d.text))) !== null && _e !== void 0 ? _e : "...";
85929
+ var importedIdentifier = ts.unescapeLeadingUnderscores(ts.isIdentifier(errorNode) ? errorNode.escapedText : symbol.escapedName);
85930
+ 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);
85931
+ }
85932
+ return;
85933
+ }
85879
85934
  var excludedMeanings = (symbol.flags & (111551 /* Value */ | 1048576 /* ExportValue */) ? 111551 /* Value */ : 0) |
85880
85935
  (symbol.flags & 788968 /* Type */ ? 788968 /* Type */ : 0) |
85881
85936
  (symbol.flags & 1920 /* Namespace */ ? 1920 /* Namespace */ : 0);
@@ -131295,32 +131350,41 @@ var ts;
131295
131350
  || ts.startsWith(getCanonicalFileName(fromPath), toNodeModulesParent)
131296
131351
  || (!!globalCachePath && ts.startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));
131297
131352
  }
131298
- function forEachExternalModuleToImportFrom(program, host, useAutoImportProvider, cb) {
131353
+ function forEachExternalModuleToImportFrom(program, host, preferences, useAutoImportProvider, cb) {
131299
131354
  var _a, _b;
131300
- forEachExternalModule(program.getTypeChecker(), program.getSourceFiles(), function (module, file) { return cb(module, file, program, /*isFromPackageJson*/ false); });
131355
+ var useCaseSensitiveFileNames = ts.hostUsesCaseSensitiveFileNames(host);
131356
+ var excludePatterns = preferences.autoImportFileExcludePatterns && ts.mapDefined(preferences.autoImportFileExcludePatterns, function (spec) {
131357
+ // The client is expected to send rooted path specs since we don't know
131358
+ // what directory a relative path is relative to.
131359
+ var pattern = ts.getPatternFromSpec(spec, "", "exclude");
131360
+ return pattern ? ts.getRegexFromPattern(pattern, useCaseSensitiveFileNames) : undefined;
131361
+ });
131362
+ forEachExternalModule(program.getTypeChecker(), program.getSourceFiles(), excludePatterns, function (module, file) { return cb(module, file, program, /*isFromPackageJson*/ false); });
131301
131363
  var autoImportProvider = useAutoImportProvider && ((_a = host.getPackageJsonAutoImportProvider) === null || _a === void 0 ? void 0 : _a.call(host));
131302
131364
  if (autoImportProvider) {
131303
131365
  var start = ts.timestamp();
131304
- forEachExternalModule(autoImportProvider.getTypeChecker(), autoImportProvider.getSourceFiles(), function (module, file) { return cb(module, file, autoImportProvider, /*isFromPackageJson*/ true); });
131366
+ forEachExternalModule(autoImportProvider.getTypeChecker(), autoImportProvider.getSourceFiles(), excludePatterns, function (module, file) { return cb(module, file, autoImportProvider, /*isFromPackageJson*/ true); });
131305
131367
  (_b = host.log) === null || _b === void 0 ? void 0 : _b.call(host, "forEachExternalModuleToImportFrom autoImportProvider: " + (ts.timestamp() - start));
131306
131368
  }
131307
131369
  }
131308
131370
  ts.forEachExternalModuleToImportFrom = forEachExternalModuleToImportFrom;
131309
- function forEachExternalModule(checker, allSourceFiles, cb) {
131310
- for (var _i = 0, _a = checker.getAmbientModules(); _i < _a.length; _i++) {
131311
- var ambient = _a[_i];
131312
- if (!ts.stringContains(ambient.name, "*")) {
131371
+ function forEachExternalModule(checker, allSourceFiles, excludePatterns, cb) {
131372
+ var _a;
131373
+ var isExcluded = function (fileName) { return excludePatterns === null || excludePatterns === void 0 ? void 0 : excludePatterns.some(function (p) { return p.test(fileName); }); };
131374
+ for (var _i = 0, _b = checker.getAmbientModules(); _i < _b.length; _i++) {
131375
+ var ambient = _b[_i];
131376
+ if (!ts.stringContains(ambient.name, "*") && !(excludePatterns && ((_a = ambient.declarations) === null || _a === void 0 ? void 0 : _a.every(function (d) { return isExcluded(d.getSourceFile().fileName); })))) {
131313
131377
  cb(ambient, /*sourceFile*/ undefined);
131314
131378
  }
131315
131379
  }
131316
- for (var _b = 0, allSourceFiles_1 = allSourceFiles; _b < allSourceFiles_1.length; _b++) {
131317
- var sourceFile = allSourceFiles_1[_b];
131318
- if (ts.isExternalOrCommonJsModule(sourceFile)) {
131380
+ for (var _c = 0, allSourceFiles_1 = allSourceFiles; _c < allSourceFiles_1.length; _c++) {
131381
+ var sourceFile = allSourceFiles_1[_c];
131382
+ if (ts.isExternalOrCommonJsModule(sourceFile) && !isExcluded(sourceFile.fileName)) {
131319
131383
  cb(checker.getMergedSymbol(sourceFile.symbol), sourceFile);
131320
131384
  }
131321
131385
  }
131322
131386
  }
131323
- function getExportInfoMap(importingFile, host, program, cancellationToken) {
131387
+ function getExportInfoMap(importingFile, host, program, preferences, cancellationToken) {
131324
131388
  var _a, _b, _c, _d, _e;
131325
131389
  var start = ts.timestamp();
131326
131390
  // Pulling the AutoImportProvider project will trigger its updateGraph if pending,
@@ -131340,7 +131404,7 @@ var ts;
131340
131404
  var compilerOptions = program.getCompilerOptions();
131341
131405
  var moduleCount = 0;
131342
131406
  try {
131343
- forEachExternalModuleToImportFrom(program, host, /*useAutoImportProvider*/ true, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
131407
+ forEachExternalModuleToImportFrom(program, host, preferences, /*useAutoImportProvider*/ true, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
131344
131408
  if (++moduleCount % 100 === 0)
131345
131409
  cancellationToken === null || cancellationToken === void 0 ? void 0 : cancellationToken.throwIfCancellationRequested();
131346
131410
  var seenExports = new ts.Map();
@@ -133736,7 +133800,7 @@ var ts;
133736
133800
  if (!previousResponse)
133737
133801
  return undefined;
133738
133802
  var lowerCaseTokenText = location.text.toLowerCase();
133739
- var exportMap = ts.getExportInfoMap(file, host, program, cancellationToken);
133803
+ var exportMap = ts.getExportInfoMap(file, host, program, preferences, cancellationToken);
133740
133804
  var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, ts.codefix.createImportSpecifierResolver(file, program, host, preferences), program, location.getStart(), preferences,
133741
133805
  /*isForImportStatementCompletion*/ false, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
133742
133806
  var entries = ts.mapDefined(previousResponse.entries, function (entry) {
@@ -135548,7 +135612,7 @@ var ts;
135548
135612
  previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() :
135549
135613
  "";
135550
135614
  var moduleSpecifierCache = (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host);
135551
- var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
135615
+ var exportInfo = ts.getExportInfoMap(sourceFile, host, program, preferences, cancellationToken);
135552
135616
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
135553
135617
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
135554
135618
  resolvingModuleSpecifiers("collectAutoImports", host, importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences)), program, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
@@ -154745,7 +154809,7 @@ var ts;
154745
154809
  var getModuleSpecifierResolutionHost = ts.memoizeOne(function (isFromPackageJson) {
154746
154810
  return ts.createModuleSpecifierResolutionHost(isFromPackageJson ? host.getPackageJsonAutoImportProvider() : program, host);
154747
154811
  });
154748
- ts.forEachExternalModuleToImportFrom(program, host, useAutoImportProvider, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
154812
+ ts.forEachExternalModuleToImportFrom(program, host, preferences, useAutoImportProvider, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
154749
154813
  var checker = program.getTypeChecker();
154750
154814
  // Don't import from a re-export when looking "up" like to `./index` or `../index`.
154751
154815
  if (moduleFile && moduleSymbol !== exportingModuleSymbol && ts.startsWith(importingFile.fileName, ts.getDirectoryPath(moduleFile.fileName))) {
@@ -155214,7 +155278,7 @@ var ts;
155214
155278
  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 });
155215
155279
  }
155216
155280
  }
155217
- ts.forEachExternalModuleToImportFrom(program, host, useAutoImportProvider, function (moduleSymbol, sourceFile, program, isFromPackageJson) {
155281
+ ts.forEachExternalModuleToImportFrom(program, host, preferences, useAutoImportProvider, function (moduleSymbol, sourceFile, program, isFromPackageJson) {
155218
155282
  var checker = program.getTypeChecker();
155219
155283
  cancellationToken.throwIfCancellationRequested();
155220
155284
  var compilerOptions = program.getCompilerOptions();
@@ -4138,6 +4138,7 @@ declare namespace ts {
4138
4138
  readonly includeInlayFunctionLikeReturnTypeHints?: boolean;
4139
4139
  readonly includeInlayEnumMemberValueHints?: boolean;
4140
4140
  readonly allowRenameOfImportPath?: boolean;
4141
+ readonly autoImportFileExcludePatterns?: string[];
4141
4142
  }
4142
4143
  /** Represents a bigint literal value without requiring bigint support */
4143
4144
  export interface PseudoBigInt {