typescript 4.7.0-dev.20220224 → 4.7.0-dev.20220227

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.20220224";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220227";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -33667,10 +33667,10 @@ var ts;
33667
33667
  setDecoratorContext(/*val*/ false);
33668
33668
  }
33669
33669
  var pos = getNodePos();
33670
- var expr = parseAssignmentExpressionOrHigher();
33670
+ var expr = parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false);
33671
33671
  var operatorToken;
33672
33672
  while ((operatorToken = parseOptionalToken(27 /* CommaToken */))) {
33673
- expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(), pos);
33673
+ expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false), pos);
33674
33674
  }
33675
33675
  if (saveDecoratorContext) {
33676
33676
  setDecoratorContext(/*val*/ true);
@@ -33678,9 +33678,9 @@ var ts;
33678
33678
  return expr;
33679
33679
  }
33680
33680
  function parseInitializer() {
33681
- return parseOptional(63 /* EqualsToken */) ? parseAssignmentExpressionOrHigher() : undefined;
33681
+ return parseOptional(63 /* EqualsToken */) ? parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false) : undefined;
33682
33682
  }
33683
- function parseAssignmentExpressionOrHigher() {
33683
+ function parseAssignmentExpressionOrHigher(disallowReturnTypeInArrowFunction) {
33684
33684
  // AssignmentExpression[in,yield]:
33685
33685
  // 1) ConditionalExpression[?in,?yield]
33686
33686
  // 2) LeftHandSideExpression = AssignmentExpression[?in,?yield]
@@ -33706,7 +33706,7 @@ var ts;
33706
33706
  // If we do successfully parse arrow-function, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is
33707
33707
  // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done
33708
33708
  // with AssignmentExpression if we see one.
33709
- var arrowExpression = tryParseParenthesizedArrowFunctionExpression() || tryParseAsyncSimpleArrowFunctionExpression();
33709
+ var arrowExpression = tryParseParenthesizedArrowFunctionExpression(disallowReturnTypeInArrowFunction) || tryParseAsyncSimpleArrowFunctionExpression(disallowReturnTypeInArrowFunction);
33710
33710
  if (arrowExpression) {
33711
33711
  return arrowExpression;
33712
33712
  }
@@ -33725,7 +33725,7 @@ var ts;
33725
33725
  // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single
33726
33726
  // identifier and the current token is an arrow.
33727
33727
  if (expr.kind === 79 /* Identifier */ && token() === 38 /* EqualsGreaterThanToken */) {
33728
- return parseSimpleArrowFunctionExpression(pos, expr, /*asyncModifier*/ undefined);
33728
+ return parseSimpleArrowFunctionExpression(pos, expr, disallowReturnTypeInArrowFunction, /*asyncModifier*/ undefined);
33729
33729
  }
33730
33730
  // Now see if we might be in cases '2' or '3'.
33731
33731
  // If the expression was a LHS expression, and we have an assignment operator, then
@@ -33734,7 +33734,7 @@ var ts;
33734
33734
  // Note: we call reScanGreaterToken so that we get an appropriately merged token
33735
33735
  // for cases like `> > =` becoming `>>=`
33736
33736
  if (ts.isLeftHandSideExpression(expr) && ts.isAssignmentOperator(reScanGreaterToken())) {
33737
- return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(), pos);
33737
+ return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(disallowReturnTypeInArrowFunction), pos);
33738
33738
  }
33739
33739
  // It wasn't an assignment or a lambda. This is a conditional expression:
33740
33740
  return parseConditionalExpressionRest(expr, pos);
@@ -33777,7 +33777,7 @@ var ts;
33777
33777
  nextToken();
33778
33778
  if (!scanner.hasPrecedingLineBreak() &&
33779
33779
  (token() === 41 /* AsteriskToken */ || isStartOfExpression())) {
33780
- return finishNode(factory.createYieldExpression(parseOptionalToken(41 /* AsteriskToken */), parseAssignmentExpressionOrHigher()), pos);
33780
+ return finishNode(factory.createYieldExpression(parseOptionalToken(41 /* AsteriskToken */), parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false)), pos);
33781
33781
  }
33782
33782
  else {
33783
33783
  // if the next token is not on the same line as yield. or we don't have an '*' or
@@ -33785,7 +33785,7 @@ var ts;
33785
33785
  return finishNode(factory.createYieldExpression(/*asteriskToken*/ undefined, /*expression*/ undefined), pos);
33786
33786
  }
33787
33787
  }
33788
- function parseSimpleArrowFunctionExpression(pos, identifier, asyncModifier) {
33788
+ function parseSimpleArrowFunctionExpression(pos, identifier, disallowReturnTypeInArrowFunction, asyncModifier) {
33789
33789
  ts.Debug.assert(token() === 38 /* EqualsGreaterThanToken */, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
33790
33790
  var parameter = factory.createParameterDeclaration(
33791
33791
  /*decorators*/ undefined,
@@ -33797,11 +33797,11 @@ var ts;
33797
33797
  finishNode(parameter, identifier.pos);
33798
33798
  var parameters = createNodeArray([parameter], parameter.pos, parameter.end);
33799
33799
  var equalsGreaterThanToken = parseExpectedToken(38 /* EqualsGreaterThanToken */);
33800
- var body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier);
33800
+ var body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier, disallowReturnTypeInArrowFunction);
33801
33801
  var node = factory.createArrowFunction(asyncModifier, /*typeParameters*/ undefined, parameters, /*type*/ undefined, equalsGreaterThanToken, body);
33802
33802
  return addJSDocComment(finishNode(node, pos));
33803
33803
  }
33804
- function tryParseParenthesizedArrowFunctionExpression() {
33804
+ function tryParseParenthesizedArrowFunctionExpression(disallowReturnTypeInArrowFunction) {
33805
33805
  var triState = isParenthesizedArrowFunctionExpression();
33806
33806
  if (triState === 0 /* False */) {
33807
33807
  // It's definitely not a parenthesized arrow function expression.
@@ -33812,8 +33812,8 @@ var ts;
33812
33812
  // it out, but don't allow any ambiguity, and return 'undefined' if this could be an
33813
33813
  // expression instead.
33814
33814
  return triState === 1 /* True */ ?
33815
- parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true) :
33816
- tryParse(parsePossibleParenthesizedArrowFunctionExpression);
33815
+ parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true, /*disallowReturnTypeInArrowFunction*/ false) :
33816
+ tryParse(function () { return parsePossibleParenthesizedArrowFunctionExpression(disallowReturnTypeInArrowFunction); });
33817
33817
  }
33818
33818
  // True -> We definitely expect a parenthesized arrow function here.
33819
33819
  // False -> There *cannot* be a parenthesized arrow function here.
@@ -33943,25 +33943,25 @@ var ts;
33943
33943
  return 2 /* Unknown */;
33944
33944
  }
33945
33945
  }
33946
- function parsePossibleParenthesizedArrowFunctionExpression() {
33946
+ function parsePossibleParenthesizedArrowFunctionExpression(disallowReturnTypeInArrowFunction) {
33947
33947
  var tokenPos = scanner.getTokenPos();
33948
33948
  if (notParenthesizedArrow === null || notParenthesizedArrow === void 0 ? void 0 : notParenthesizedArrow.has(tokenPos)) {
33949
33949
  return undefined;
33950
33950
  }
33951
- var result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false);
33951
+ var result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false, disallowReturnTypeInArrowFunction);
33952
33952
  if (!result) {
33953
33953
  (notParenthesizedArrow || (notParenthesizedArrow = new ts.Set())).add(tokenPos);
33954
33954
  }
33955
33955
  return result;
33956
33956
  }
33957
- function tryParseAsyncSimpleArrowFunctionExpression() {
33957
+ function tryParseAsyncSimpleArrowFunctionExpression(disallowReturnTypeInArrowFunction) {
33958
33958
  // We do a check here so that we won't be doing unnecessarily call to "lookAhead"
33959
33959
  if (token() === 131 /* AsyncKeyword */) {
33960
33960
  if (lookAhead(isUnParenthesizedAsyncArrowFunctionWorker) === 1 /* True */) {
33961
33961
  var pos = getNodePos();
33962
33962
  var asyncModifier = parseModifiersForArrowFunction();
33963
33963
  var expr = parseBinaryExpressionOrHigher(0 /* Lowest */);
33964
- return parseSimpleArrowFunctionExpression(pos, expr, asyncModifier);
33964
+ return parseSimpleArrowFunctionExpression(pos, expr, disallowReturnTypeInArrowFunction, asyncModifier);
33965
33965
  }
33966
33966
  }
33967
33967
  return undefined;
@@ -33985,7 +33985,7 @@ var ts;
33985
33985
  }
33986
33986
  return 0 /* False */;
33987
33987
  }
33988
- function parseParenthesizedArrowFunctionExpression(allowAmbiguity) {
33988
+ function parseParenthesizedArrowFunctionExpression(allowAmbiguity, disallowReturnTypeInArrowFunction) {
33989
33989
  var pos = getNodePos();
33990
33990
  var hasJSDoc = hasPrecedingJSDocComment();
33991
33991
  var modifiers = parseModifiersForArrowFunction();
@@ -34011,6 +34011,23 @@ var ts;
34011
34011
  return undefined;
34012
34012
  }
34013
34013
  }
34014
+ // Given:
34015
+ // x ? y => ({ y }) : z => ({ z })
34016
+ // We try to parse the body of the first arrow function by looking at:
34017
+ // ({ y }) : z => ({ z })
34018
+ // This is a valid arrow function with "z" as the return type.
34019
+ //
34020
+ // But, if we're in the true side of a conditional expression, this colon
34021
+ // terminates the expression, so we cannot allow a return type if we aren't
34022
+ // certain whether or not the preceding text was parsed as a parameter list.
34023
+ //
34024
+ // For example,
34025
+ // a() ? (b: number, c?: string): void => d() : e
34026
+ // is determined by isParenthesizedArrowFunctionExpression to unambiguously
34027
+ // be an arrow expression, so we allow a return type.
34028
+ if (disallowReturnTypeInArrowFunction && token() === 58 /* ColonToken */) {
34029
+ return undefined;
34030
+ }
34014
34031
  var type = parseReturnType(58 /* ColonToken */, /*isType*/ false);
34015
34032
  if (type && !allowAmbiguity && typeHasArrowFunctionBlockingParseError(type)) {
34016
34033
  return undefined;
@@ -34039,12 +34056,12 @@ var ts;
34039
34056
  var lastToken = token();
34040
34057
  var equalsGreaterThanToken = parseExpectedToken(38 /* EqualsGreaterThanToken */);
34041
34058
  var body = (lastToken === 38 /* EqualsGreaterThanToken */ || lastToken === 18 /* OpenBraceToken */)
34042
- ? parseArrowFunctionExpressionBody(ts.some(modifiers, ts.isAsyncModifier))
34059
+ ? parseArrowFunctionExpressionBody(ts.some(modifiers, ts.isAsyncModifier), disallowReturnTypeInArrowFunction)
34043
34060
  : parseIdentifier();
34044
34061
  var node = factory.createArrowFunction(modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body);
34045
34062
  return withJSDoc(finishNode(node, pos), hasJSDoc);
34046
34063
  }
34047
- function parseArrowFunctionExpressionBody(isAsync) {
34064
+ function parseArrowFunctionExpressionBody(isAsync, disallowReturnTypeInArrowFunction) {
34048
34065
  if (token() === 18 /* OpenBraceToken */) {
34049
34066
  return parseFunctionBlock(isAsync ? 2 /* Await */ : 0 /* None */);
34050
34067
  }
@@ -34072,8 +34089,8 @@ var ts;
34072
34089
  var savedTopLevel = topLevel;
34073
34090
  topLevel = false;
34074
34091
  var node = isAsync
34075
- ? doInAwaitContext(parseAssignmentExpressionOrHigher)
34076
- : doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher);
34092
+ ? doInAwaitContext(function () { return parseAssignmentExpressionOrHigher(disallowReturnTypeInArrowFunction); })
34093
+ : doOutsideOfAwaitContext(function () { return parseAssignmentExpressionOrHigher(disallowReturnTypeInArrowFunction); });
34077
34094
  topLevel = savedTopLevel;
34078
34095
  return node;
34079
34096
  }
@@ -34086,8 +34103,8 @@ var ts;
34086
34103
  // Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and
34087
34104
  // we do not that for the 'whenFalse' part.
34088
34105
  var colonToken;
34089
- return finishNode(factory.createConditionalExpression(leftOperand, questionToken, doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher), colonToken = parseExpectedToken(58 /* ColonToken */), ts.nodeIsPresent(colonToken)
34090
- ? parseAssignmentExpressionOrHigher()
34106
+ return finishNode(factory.createConditionalExpression(leftOperand, questionToken, doOutsideOfContext(disallowInAndDecoratorContext, function () { return parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ true); }), colonToken = parseExpectedToken(58 /* ColonToken */), ts.nodeIsPresent(colonToken)
34107
+ ? parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ true)
34091
34108
  : createMissingNode(79 /* Identifier */, /*reportAtCurrentPosition*/ false, ts.Diagnostics._0_expected, ts.tokenToString(58 /* ColonToken */))), pos);
34092
34109
  }
34093
34110
  function parseBinaryExpressionOrHigher(precedence) {
@@ -35003,13 +35020,13 @@ var ts;
35003
35020
  function parseSpreadElement() {
35004
35021
  var pos = getNodePos();
35005
35022
  parseExpected(25 /* DotDotDotToken */);
35006
- var expression = parseAssignmentExpressionOrHigher();
35023
+ var expression = parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false);
35007
35024
  return finishNode(factory.createSpreadElement(expression), pos);
35008
35025
  }
35009
35026
  function parseArgumentOrArrayLiteralElement() {
35010
35027
  return token() === 25 /* DotDotDotToken */ ? parseSpreadElement() :
35011
35028
  token() === 27 /* CommaToken */ ? finishNode(factory.createOmittedExpression(), getNodePos()) :
35012
- parseAssignmentExpressionOrHigher();
35029
+ parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false);
35013
35030
  }
35014
35031
  function parseArgumentExpression() {
35015
35032
  return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement);
@@ -35026,7 +35043,7 @@ var ts;
35026
35043
  var pos = getNodePos();
35027
35044
  var hasJSDoc = hasPrecedingJSDocComment();
35028
35045
  if (parseOptionalToken(25 /* DotDotDotToken */)) {
35029
- var expression = parseAssignmentExpressionOrHigher();
35046
+ var expression = parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false);
35030
35047
  return withJSDoc(finishNode(factory.createSpreadAssignment(expression), pos), hasJSDoc);
35031
35048
  }
35032
35049
  var decorators = parseDecorators();
@@ -35055,7 +35072,7 @@ var ts;
35055
35072
  var isShorthandPropertyAssignment = tokenIsIdentifier && (token() !== 58 /* ColonToken */);
35056
35073
  if (isShorthandPropertyAssignment) {
35057
35074
  var equalsToken = parseOptionalToken(63 /* EqualsToken */);
35058
- var objectAssignmentInitializer = equalsToken ? allowInAnd(parseAssignmentExpressionOrHigher) : undefined;
35075
+ var objectAssignmentInitializer = equalsToken ? allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false); }) : undefined;
35059
35076
  node = factory.createShorthandPropertyAssignment(name, objectAssignmentInitializer);
35060
35077
  // Save equals token for error reporting.
35061
35078
  // TODO(rbuckton): Consider manufacturing this when we need to report an error as it is otherwise not useful.
@@ -35063,7 +35080,7 @@ var ts;
35063
35080
  }
35064
35081
  else {
35065
35082
  parseExpected(58 /* ColonToken */);
35066
- var initializer = allowInAnd(parseAssignmentExpressionOrHigher);
35083
+ var initializer = allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false); });
35067
35084
  node = factory.createPropertyAssignment(name, initializer);
35068
35085
  }
35069
35086
  // Decorators, Modifiers, questionToken, and exclamationToken are not supported by property assignments and are reported in the grammar checker
@@ -35243,7 +35260,7 @@ var ts;
35243
35260
  }
35244
35261
  var node;
35245
35262
  if (awaitToken ? parseExpected(159 /* OfKeyword */) : parseOptional(159 /* OfKeyword */)) {
35246
- var expression = allowInAnd(parseAssignmentExpressionOrHigher);
35263
+ var expression = allowInAnd(function () { return parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false); });
35247
35264
  parseExpected(21 /* CloseParenToken */);
35248
35265
  node = factory.createForOfStatement(awaitToken, initializer, expression, parseStatement());
35249
35266
  }
@@ -36410,7 +36427,7 @@ var ts;
36410
36427
  var pos = getNodePos();
36411
36428
  var name = ts.tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(10 /* StringLiteral */);
36412
36429
  parseExpected(58 /* ColonToken */);
36413
- var value = parseAssignmentExpressionOrHigher();
36430
+ var value = parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false);
36414
36431
  return finishNode(factory.createAssertEntry(name, value), pos);
36415
36432
  }
36416
36433
  function parseAssertClause() {
@@ -36647,7 +36664,7 @@ var ts;
36647
36664
  else {
36648
36665
  parseExpected(88 /* DefaultKeyword */);
36649
36666
  }
36650
- var expression = parseAssignmentExpressionOrHigher();
36667
+ var expression = parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false);
36651
36668
  parseSemicolon();
36652
36669
  setAwaitContext(savedAwaitContext);
36653
36670
  var node = factory.createExportAssignment(decorators, modifiers, isExportEquals, expression);
@@ -135521,6 +135538,9 @@ var ts;
135521
135538
  // *don’t* include readonly member modifiers.
135522
135539
  return getAllReferencesForKeyword(sourceFiles, node.kind, cancellationToken, node.kind === 144 /* ReadonlyKeyword */ ? isReadonlyTypeOperator : undefined);
135523
135540
  }
135541
+ if (ts.isImportMeta(node.parent) && node.parent.name === node) {
135542
+ return getAllReferencesForImportMeta(sourceFiles, cancellationToken);
135543
+ }
135524
135544
  if (ts.isStaticModifier(node) && ts.isClassStaticBlockDeclaration(node.parent)) {
135525
135545
  return [{ definition: { type: 2 /* Keyword */, node: node }, references: [nodeEntry(node)] }];
135526
135546
  }
@@ -136002,6 +136022,18 @@ var ts;
136002
136022
  return false;
136003
136023
  }
136004
136024
  }
136025
+ function getAllReferencesForImportMeta(sourceFiles, cancellationToken) {
136026
+ var references = ts.flatMap(sourceFiles, function (sourceFile) {
136027
+ cancellationToken.throwIfCancellationRequested();
136028
+ return ts.mapDefined(getPossibleSymbolReferenceNodes(sourceFile, "meta", sourceFile), function (node) {
136029
+ var parent = node.parent;
136030
+ if (ts.isImportMeta(parent)) {
136031
+ return nodeEntry(parent);
136032
+ }
136033
+ });
136034
+ });
136035
+ return references.length ? [{ definition: { type: 2 /* Keyword */, node: references[0].node }, references: references }] : undefined;
136036
+ }
136005
136037
  function getAllReferencesForKeyword(sourceFiles, keywordKind, cancellationToken, filter) {
136006
136038
  var references = ts.flatMap(sourceFiles, function (sourceFile) {
136007
136039
  cancellationToken.throwIfCancellationRequested();
@@ -137714,6 +137746,9 @@ var ts;
137714
137746
  if (node === sourceFile) {
137715
137747
  return undefined;
137716
137748
  }
137749
+ if (ts.isImportMeta(node.parent) && node.parent.name === node) {
137750
+ return definitionFromType(typeChecker.getTypeAtLocation(node.parent), typeChecker, node.parent);
137751
+ }
137717
137752
  var symbol = getSymbol(node, typeChecker);
137718
137753
  if (!symbol)
137719
137754
  return undefined;
@@ -162842,6 +162877,9 @@ var ts;
162842
162877
  if (ts.isNamedTupleMember(node.parent) && node.pos === node.parent.pos) {
162843
162878
  return node.parent;
162844
162879
  }
162880
+ if (ts.isImportMeta(node.parent) && node.parent.name === node) {
162881
+ return node.parent;
162882
+ }
162845
162883
  return node;
162846
162884
  }
162847
162885
  function shouldGetType(sourceFile, node, position) {
@@ -162857,6 +162895,8 @@ var ts;
162857
162895
  case 106 /* SuperKeyword */:
162858
162896
  case 196 /* NamedTupleMember */:
162859
162897
  return true;
162898
+ case 230 /* MetaProperty */:
162899
+ return ts.isImportMeta(node);
162860
162900
  default:
162861
162901
  return false;
162862
162902
  }
@@ -2015,6 +2015,12 @@ declare namespace ts {
2015
2015
  path: string;
2016
2016
  name?: string;
2017
2017
  }
2018
+ /**
2019
+ * Subset of properties from SourceFile that are used in multiple utility functions
2020
+ */
2021
+ export interface SourceFileLike {
2022
+ readonly text: string;
2023
+ }
2018
2024
  export interface SourceFile extends Declaration {
2019
2025
  readonly kind: SyntaxKind.SourceFile;
2020
2026
  readonly statements: NodeArray<Statement>;