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.
@@ -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.20220617";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220620";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -10129,6 +10129,9 @@ var ts;
10129
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."),
10130
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."),
10131
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."),
10132
10135
  };
10133
10136
  })(ts || (ts = {}));
10134
10137
  var ts;
@@ -34717,10 +34720,10 @@ var ts;
34717
34720
  setDecoratorContext(/*val*/ false);
34718
34721
  }
34719
34722
  var pos = getNodePos();
34720
- var expr = parseAssignmentExpressionOrHigher();
34723
+ var expr = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
34721
34724
  var operatorToken;
34722
34725
  while ((operatorToken = parseOptionalToken(27 /* CommaToken */))) {
34723
- expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(), pos);
34726
+ expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true), pos);
34724
34727
  }
34725
34728
  if (saveDecoratorContext) {
34726
34729
  setDecoratorContext(/*val*/ true);
@@ -34728,9 +34731,9 @@ var ts;
34728
34731
  return expr;
34729
34732
  }
34730
34733
  function parseInitializer() {
34731
- return parseOptional(63 /* EqualsToken */) ? parseAssignmentExpressionOrHigher() : undefined;
34734
+ return parseOptional(63 /* EqualsToken */) ? parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true) : undefined;
34732
34735
  }
34733
- function parseAssignmentExpressionOrHigher() {
34736
+ function parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction) {
34734
34737
  // AssignmentExpression[in,yield]:
34735
34738
  // 1) ConditionalExpression[?in,?yield]
34736
34739
  // 2) LeftHandSideExpression = AssignmentExpression[?in,?yield]
@@ -34756,7 +34759,7 @@ var ts;
34756
34759
  // If we do successfully parse arrow-function, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is
34757
34760
  // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done
34758
34761
  // with AssignmentExpression if we see one.
34759
- var arrowExpression = tryParseParenthesizedArrowFunctionExpression() || tryParseAsyncSimpleArrowFunctionExpression();
34762
+ var arrowExpression = tryParseParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction) || tryParseAsyncSimpleArrowFunctionExpression(allowReturnTypeInArrowFunction);
34760
34763
  if (arrowExpression) {
34761
34764
  return arrowExpression;
34762
34765
  }
@@ -34775,7 +34778,7 @@ var ts;
34775
34778
  // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single
34776
34779
  // identifier and the current token is an arrow.
34777
34780
  if (expr.kind === 79 /* Identifier */ && token() === 38 /* EqualsGreaterThanToken */) {
34778
- return parseSimpleArrowFunctionExpression(pos, expr, /*asyncModifier*/ undefined);
34781
+ return parseSimpleArrowFunctionExpression(pos, expr, allowReturnTypeInArrowFunction, /*asyncModifier*/ undefined);
34779
34782
  }
34780
34783
  // Now see if we might be in cases '2' or '3'.
34781
34784
  // If the expression was a LHS expression, and we have an assignment operator, then
@@ -34784,10 +34787,10 @@ var ts;
34784
34787
  // Note: we call reScanGreaterToken so that we get an appropriately merged token
34785
34788
  // for cases like `> > =` becoming `>>=`
34786
34789
  if (ts.isLeftHandSideExpression(expr) && ts.isAssignmentOperator(reScanGreaterToken())) {
34787
- return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(), pos);
34790
+ return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction), pos);
34788
34791
  }
34789
34792
  // It wasn't an assignment or a lambda. This is a conditional expression:
34790
- return parseConditionalExpressionRest(expr, pos);
34793
+ return parseConditionalExpressionRest(expr, pos, allowReturnTypeInArrowFunction);
34791
34794
  }
34792
34795
  function isYieldExpression() {
34793
34796
  if (token() === 125 /* YieldKeyword */) {
@@ -34827,7 +34830,7 @@ var ts;
34827
34830
  nextToken();
34828
34831
  if (!scanner.hasPrecedingLineBreak() &&
34829
34832
  (token() === 41 /* AsteriskToken */ || isStartOfExpression())) {
34830
- return finishNode(factory.createYieldExpression(parseOptionalToken(41 /* AsteriskToken */), parseAssignmentExpressionOrHigher()), pos);
34833
+ return finishNode(factory.createYieldExpression(parseOptionalToken(41 /* AsteriskToken */), parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true)), pos);
34831
34834
  }
34832
34835
  else {
34833
34836
  // if the next token is not on the same line as yield. or we don't have an '*' or
@@ -34835,7 +34838,7 @@ var ts;
34835
34838
  return finishNode(factory.createYieldExpression(/*asteriskToken*/ undefined, /*expression*/ undefined), pos);
34836
34839
  }
34837
34840
  }
34838
- function parseSimpleArrowFunctionExpression(pos, identifier, asyncModifier) {
34841
+ function parseSimpleArrowFunctionExpression(pos, identifier, allowReturnTypeInArrowFunction, asyncModifier) {
34839
34842
  ts.Debug.assert(token() === 38 /* EqualsGreaterThanToken */, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
34840
34843
  var parameter = factory.createParameterDeclaration(
34841
34844
  /*modifiers*/ undefined,
@@ -34846,11 +34849,11 @@ var ts;
34846
34849
  finishNode(parameter, identifier.pos);
34847
34850
  var parameters = createNodeArray([parameter], parameter.pos, parameter.end);
34848
34851
  var equalsGreaterThanToken = parseExpectedToken(38 /* EqualsGreaterThanToken */);
34849
- var body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier);
34852
+ var body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier, allowReturnTypeInArrowFunction);
34850
34853
  var node = factory.createArrowFunction(asyncModifier, /*typeParameters*/ undefined, parameters, /*type*/ undefined, equalsGreaterThanToken, body);
34851
34854
  return addJSDocComment(finishNode(node, pos));
34852
34855
  }
34853
- function tryParseParenthesizedArrowFunctionExpression() {
34856
+ function tryParseParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction) {
34854
34857
  var triState = isParenthesizedArrowFunctionExpression();
34855
34858
  if (triState === 0 /* False */) {
34856
34859
  // It's definitely not a parenthesized arrow function expression.
@@ -34861,8 +34864,8 @@ var ts;
34861
34864
  // it out, but don't allow any ambiguity, and return 'undefined' if this could be an
34862
34865
  // expression instead.
34863
34866
  return triState === 1 /* True */ ?
34864
- parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true) :
34865
- tryParse(parsePossibleParenthesizedArrowFunctionExpression);
34867
+ parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true, /*allowReturnTypeInArrowFunction*/ true) :
34868
+ tryParse(function () { return parsePossibleParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction); });
34866
34869
  }
34867
34870
  // True -> We definitely expect a parenthesized arrow function here.
34868
34871
  // False -> There *cannot* be a parenthesized arrow function here.
@@ -34996,25 +34999,25 @@ var ts;
34996
34999
  return 2 /* Unknown */;
34997
35000
  }
34998
35001
  }
34999
- function parsePossibleParenthesizedArrowFunctionExpression() {
35002
+ function parsePossibleParenthesizedArrowFunctionExpression(allowReturnTypeInArrowFunction) {
35000
35003
  var tokenPos = scanner.getTokenPos();
35001
35004
  if (notParenthesizedArrow === null || notParenthesizedArrow === void 0 ? void 0 : notParenthesizedArrow.has(tokenPos)) {
35002
35005
  return undefined;
35003
35006
  }
35004
- var result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false);
35007
+ var result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false, allowReturnTypeInArrowFunction);
35005
35008
  if (!result) {
35006
35009
  (notParenthesizedArrow || (notParenthesizedArrow = new ts.Set())).add(tokenPos);
35007
35010
  }
35008
35011
  return result;
35009
35012
  }
35010
- function tryParseAsyncSimpleArrowFunctionExpression() {
35013
+ function tryParseAsyncSimpleArrowFunctionExpression(allowReturnTypeInArrowFunction) {
35011
35014
  // We do a check here so that we won't be doing unnecessarily call to "lookAhead"
35012
35015
  if (token() === 131 /* AsyncKeyword */) {
35013
35016
  if (lookAhead(isUnParenthesizedAsyncArrowFunctionWorker) === 1 /* True */) {
35014
35017
  var pos = getNodePos();
35015
35018
  var asyncModifier = parseModifiersForArrowFunction();
35016
35019
  var expr = parseBinaryExpressionOrHigher(0 /* Lowest */);
35017
- return parseSimpleArrowFunctionExpression(pos, expr, asyncModifier);
35020
+ return parseSimpleArrowFunctionExpression(pos, expr, allowReturnTypeInArrowFunction, asyncModifier);
35018
35021
  }
35019
35022
  }
35020
35023
  return undefined;
@@ -35038,7 +35041,7 @@ var ts;
35038
35041
  }
35039
35042
  return 0 /* False */;
35040
35043
  }
35041
- function parseParenthesizedArrowFunctionExpression(allowAmbiguity) {
35044
+ function parseParenthesizedArrowFunctionExpression(allowAmbiguity, allowReturnTypeInArrowFunction) {
35042
35045
  var pos = getNodePos();
35043
35046
  var hasJSDoc = hasPrecedingJSDocComment();
35044
35047
  var modifiers = parseModifiersForArrowFunction();
@@ -35073,6 +35076,7 @@ var ts;
35073
35076
  return undefined;
35074
35077
  }
35075
35078
  }
35079
+ var hasReturnColon = token() === 58 /* ColonToken */;
35076
35080
  var type = parseReturnType(58 /* ColonToken */, /*isType*/ false);
35077
35081
  if (type && !allowAmbiguity && typeHasArrowFunctionBlockingParseError(type)) {
35078
35082
  return undefined;
@@ -35101,12 +35105,37 @@ var ts;
35101
35105
  var lastToken = token();
35102
35106
  var equalsGreaterThanToken = parseExpectedToken(38 /* EqualsGreaterThanToken */);
35103
35107
  var body = (lastToken === 38 /* EqualsGreaterThanToken */ || lastToken === 18 /* OpenBraceToken */)
35104
- ? parseArrowFunctionExpressionBody(ts.some(modifiers, ts.isAsyncModifier))
35108
+ ? parseArrowFunctionExpressionBody(ts.some(modifiers, ts.isAsyncModifier), allowReturnTypeInArrowFunction)
35105
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
+ }
35106
35135
  var node = factory.createArrowFunction(modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body);
35107
35136
  return withJSDoc(finishNode(node, pos), hasJSDoc);
35108
35137
  }
35109
- function parseArrowFunctionExpressionBody(isAsync) {
35138
+ function parseArrowFunctionExpressionBody(isAsync, allowReturnTypeInArrowFunction) {
35110
35139
  if (token() === 18 /* OpenBraceToken */) {
35111
35140
  return parseFunctionBlock(isAsync ? 2 /* Await */ : 0 /* None */);
35112
35141
  }
@@ -35134,12 +35163,12 @@ var ts;
35134
35163
  var savedTopLevel = topLevel;
35135
35164
  topLevel = false;
35136
35165
  var node = isAsync
35137
- ? doInAwaitContext(parseAssignmentExpressionOrHigher)
35138
- : doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher);
35166
+ ? doInAwaitContext(function () { return parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction); })
35167
+ : doOutsideOfAwaitContext(function () { return parseAssignmentExpressionOrHigher(allowReturnTypeInArrowFunction); });
35139
35168
  topLevel = savedTopLevel;
35140
35169
  return node;
35141
35170
  }
35142
- function parseConditionalExpressionRest(leftOperand, pos) {
35171
+ function parseConditionalExpressionRest(leftOperand, pos, allowReturnTypeInArrowFunction) {
35143
35172
  // Note: we are passed in an expression which was produced from parseBinaryExpressionOrHigher.
35144
35173
  var questionToken = parseOptionalToken(57 /* QuestionToken */);
35145
35174
  if (!questionToken) {
@@ -35148,8 +35177,8 @@ var ts;
35148
35177
  // Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and
35149
35178
  // we do not that for the 'whenFalse' part.
35150
35179
  var colonToken;
35151
- return finishNode(factory.createConditionalExpression(leftOperand, questionToken, doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher), colonToken = parseExpectedToken(58 /* ColonToken */), ts.nodeIsPresent(colonToken)
35152
- ? 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)
35153
35182
  : createMissingNode(79 /* Identifier */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(58 /* ColonToken */))), pos);
35154
35183
  }
35155
35184
  function parseBinaryExpressionOrHigher(precedence) {
@@ -36064,13 +36093,13 @@ var ts;
36064
36093
  function parseSpreadElement() {
36065
36094
  var pos = getNodePos();
36066
36095
  parseExpected(25 /* DotDotDotToken */);
36067
- var expression = parseAssignmentExpressionOrHigher();
36096
+ var expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
36068
36097
  return finishNode(factory.createSpreadElement(expression), pos);
36069
36098
  }
36070
36099
  function parseArgumentOrArrayLiteralElement() {
36071
36100
  return token() === 25 /* DotDotDotToken */ ? parseSpreadElement() :
36072
36101
  token() === 27 /* CommaToken */ ? finishNode(factory.createOmittedExpression(), getNodePos()) :
36073
- parseAssignmentExpressionOrHigher();
36102
+ parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
36074
36103
  }
36075
36104
  function parseArgumentExpression() {
36076
36105
  return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement);
@@ -36088,7 +36117,7 @@ var ts;
36088
36117
  var pos = getNodePos();
36089
36118
  var hasJSDoc = hasPrecedingJSDocComment();
36090
36119
  if (parseOptionalToken(25 /* DotDotDotToken */)) {
36091
- var expression = parseAssignmentExpressionOrHigher();
36120
+ var expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
36092
36121
  return withJSDoc(finishNode(factory.createSpreadAssignment(expression), pos), hasJSDoc);
36093
36122
  }
36094
36123
  var decorators = parseDecorators();
@@ -36117,7 +36146,7 @@ var ts;
36117
36146
  var isShorthandPropertyAssignment = tokenIsIdentifier && (token() !== 58 /* ColonToken */);
36118
36147
  if (isShorthandPropertyAssignment) {
36119
36148
  var equalsToken = parseOptionalToken(63 /* EqualsToken */);
36120
- var objectAssignmentInitializer = equalsToken ? allowInAnd(parseAssignmentExpressionOrHigher) : undefined;
36149
+ var objectAssignmentInitializer = equalsToken ? allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); }) : undefined;
36121
36150
  node = factory.createShorthandPropertyAssignment(name, objectAssignmentInitializer);
36122
36151
  // Save equals token for error reporting.
36123
36152
  // TODO(rbuckton): Consider manufacturing this when we need to report an error as it is otherwise not useful.
@@ -36125,7 +36154,7 @@ var ts;
36125
36154
  }
36126
36155
  else {
36127
36156
  parseExpected(58 /* ColonToken */);
36128
- var initializer = allowInAnd(parseAssignmentExpressionOrHigher);
36157
+ var initializer = allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); });
36129
36158
  node = factory.createPropertyAssignment(name, initializer);
36130
36159
  }
36131
36160
  // Decorators, Modifiers, questionToken, and exclamationToken are not supported by property assignments and are reported in the grammar checker
@@ -36302,7 +36331,7 @@ var ts;
36302
36331
  }
36303
36332
  var node;
36304
36333
  if (awaitToken ? parseExpected(160 /* OfKeyword */) : parseOptional(160 /* OfKeyword */)) {
36305
- var expression = allowInAnd(parseAssignmentExpressionOrHigher);
36334
+ var expression = allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); });
36306
36335
  parseExpected(21 /* CloseParenToken */);
36307
36336
  node = factory.createForOfStatement(awaitToken, initializer, expression, parseStatement());
36308
36337
  }
@@ -37490,7 +37519,7 @@ var ts;
37490
37519
  var pos = getNodePos();
37491
37520
  var name = ts.tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(10 /* StringLiteral */);
37492
37521
  parseExpected(58 /* ColonToken */);
37493
- var value = parseAssignmentExpressionOrHigher();
37522
+ var value = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
37494
37523
  return finishNode(factory.createAssertEntry(name, value), pos);
37495
37524
  }
37496
37525
  function parseAssertClause(skipAssertKeyword) {
@@ -37731,7 +37760,7 @@ var ts;
37731
37760
  else {
37732
37761
  parseExpected(88 /* DefaultKeyword */);
37733
37762
  }
37734
- var expression = parseAssignmentExpressionOrHigher();
37763
+ var expression = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
37735
37764
  parseSemicolon();
37736
37765
  setAwaitContext(savedAwaitContext);
37737
37766
  var node = factory.createExportAssignment(modifiers, isExportEquals, expression);
@@ -85857,6 +85886,7 @@ var ts;
85857
85886
  return true;
85858
85887
  }
85859
85888
  function checkAliasSymbol(node) {
85889
+ var _a, _b, _c, _d, _e;
85860
85890
  var symbol = getSymbolOfNode(node);
85861
85891
  var target = resolveAlias(symbol);
85862
85892
  if (target !== unknownSymbol) {
@@ -85867,6 +85897,31 @@ var ts;
85867
85897
  // otherwise it will conflict with some local declaration). Note that in addition to normal flags we include matching SymbolFlags.Export*
85868
85898
  // in order to prevent collisions with declarations that were exported from the current module (they still contribute to local names).
85869
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
+ }
85870
85925
  var excludedMeanings = (symbol.flags & (111551 /* Value */ | 1048576 /* ExportValue */) ? 111551 /* Value */ : 0) |
85871
85926
  (symbol.flags & 788968 /* Type */ ? 788968 /* Type */ : 0) |
85872
85927
  (symbol.flags & 1920 /* Namespace */ ? 1920 /* Namespace */ : 0);
@@ -131286,32 +131341,41 @@ var ts;
131286
131341
  || ts.startsWith(getCanonicalFileName(fromPath), toNodeModulesParent)
131287
131342
  || (!!globalCachePath && ts.startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));
131288
131343
  }
131289
- function forEachExternalModuleToImportFrom(program, host, useAutoImportProvider, cb) {
131344
+ function forEachExternalModuleToImportFrom(program, host, preferences, useAutoImportProvider, cb) {
131290
131345
  var _a, _b;
131291
- 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); });
131292
131354
  var autoImportProvider = useAutoImportProvider && ((_a = host.getPackageJsonAutoImportProvider) === null || _a === void 0 ? void 0 : _a.call(host));
131293
131355
  if (autoImportProvider) {
131294
131356
  var start = ts.timestamp();
131295
- 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); });
131296
131358
  (_b = host.log) === null || _b === void 0 ? void 0 : _b.call(host, "forEachExternalModuleToImportFrom autoImportProvider: " + (ts.timestamp() - start));
131297
131359
  }
131298
131360
  }
131299
131361
  ts.forEachExternalModuleToImportFrom = forEachExternalModuleToImportFrom;
131300
- function forEachExternalModule(checker, allSourceFiles, cb) {
131301
- for (var _i = 0, _a = checker.getAmbientModules(); _i < _a.length; _i++) {
131302
- var ambient = _a[_i];
131303
- 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); })))) {
131304
131368
  cb(ambient, /*sourceFile*/ undefined);
131305
131369
  }
131306
131370
  }
131307
- for (var _b = 0, allSourceFiles_1 = allSourceFiles; _b < allSourceFiles_1.length; _b++) {
131308
- var sourceFile = allSourceFiles_1[_b];
131309
- 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)) {
131310
131374
  cb(checker.getMergedSymbol(sourceFile.symbol), sourceFile);
131311
131375
  }
131312
131376
  }
131313
131377
  }
131314
- function getExportInfoMap(importingFile, host, program, cancellationToken) {
131378
+ function getExportInfoMap(importingFile, host, program, preferences, cancellationToken) {
131315
131379
  var _a, _b, _c, _d, _e;
131316
131380
  var start = ts.timestamp();
131317
131381
  // Pulling the AutoImportProvider project will trigger its updateGraph if pending,
@@ -131331,7 +131395,7 @@ var ts;
131331
131395
  var compilerOptions = program.getCompilerOptions();
131332
131396
  var moduleCount = 0;
131333
131397
  try {
131334
- forEachExternalModuleToImportFrom(program, host, /*useAutoImportProvider*/ true, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
131398
+ forEachExternalModuleToImportFrom(program, host, preferences, /*useAutoImportProvider*/ true, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
131335
131399
  if (++moduleCount % 100 === 0)
131336
131400
  cancellationToken === null || cancellationToken === void 0 ? void 0 : cancellationToken.throwIfCancellationRequested();
131337
131401
  var seenExports = new ts.Map();
@@ -133727,7 +133791,7 @@ var ts;
133727
133791
  if (!previousResponse)
133728
133792
  return undefined;
133729
133793
  var lowerCaseTokenText = location.text.toLowerCase();
133730
- var exportMap = ts.getExportInfoMap(file, host, program, cancellationToken);
133794
+ var exportMap = ts.getExportInfoMap(file, host, program, preferences, cancellationToken);
133731
133795
  var newEntries = resolvingModuleSpecifiers("continuePreviousIncompleteResponse", host, ts.codefix.createImportSpecifierResolver(file, program, host, preferences), program, location.getStart(), preferences,
133732
133796
  /*isForImportStatementCompletion*/ false, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
133733
133797
  var entries = ts.mapDefined(previousResponse.entries, function (entry) {
@@ -135539,7 +135603,7 @@ var ts;
135539
135603
  previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() :
135540
135604
  "";
135541
135605
  var moduleSpecifierCache = (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host);
135542
- var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
135606
+ var exportInfo = ts.getExportInfoMap(sourceFile, host, program, preferences, cancellationToken);
135543
135607
  var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
135544
135608
  var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
135545
135609
  resolvingModuleSpecifiers("collectAutoImports", host, importSpecifierResolver || (importSpecifierResolver = ts.codefix.createImportSpecifierResolver(sourceFile, program, host, preferences)), program, position, preferences, !!importCompletionNode, ts.isValidTypeOnlyAliasUseSite(location), function (context) {
@@ -154736,7 +154800,7 @@ var ts;
154736
154800
  var getModuleSpecifierResolutionHost = ts.memoizeOne(function (isFromPackageJson) {
154737
154801
  return ts.createModuleSpecifierResolutionHost(isFromPackageJson ? host.getPackageJsonAutoImportProvider() : program, host);
154738
154802
  });
154739
- ts.forEachExternalModuleToImportFrom(program, host, useAutoImportProvider, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
154803
+ ts.forEachExternalModuleToImportFrom(program, host, preferences, useAutoImportProvider, function (moduleSymbol, moduleFile, program, isFromPackageJson) {
154740
154804
  var checker = program.getTypeChecker();
154741
154805
  // Don't import from a re-export when looking "up" like to `./index` or `../index`.
154742
154806
  if (moduleFile && moduleSymbol !== exportingModuleSymbol && ts.startsWith(importingFile.fileName, ts.getDirectoryPath(moduleFile.fileName))) {
@@ -155205,7 +155269,7 @@ var ts;
155205
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 });
155206
155270
  }
155207
155271
  }
155208
- ts.forEachExternalModuleToImportFrom(program, host, useAutoImportProvider, function (moduleSymbol, sourceFile, program, isFromPackageJson) {
155272
+ ts.forEachExternalModuleToImportFrom(program, host, preferences, useAutoImportProvider, function (moduleSymbol, sourceFile, program, isFromPackageJson) {
155209
155273
  var checker = program.getTypeChecker();
155210
155274
  cancellationToken.throwIfCancellationRequested();
155211
155275
  var compilerOptions = program.getCompilerOptions();