Beispiel #1
0
        private static SubpatternSyntax?TrySimplify(SubpatternSyntax currentSubpattern)
        {
            if (!SimplifyPropertyPatternHelpers.IsSimplifiable(currentSubpattern, out var innerSubpattern, out var outerExpressionColon))
            {
                return(null);
            }

            // attempt to simplify the inner pattern we're pointing at as well (that way if the user
            // invokes the fix on a top level property, we collapse as far inwards as possible).
            innerSubpattern = TrySimplify(innerSubpattern) ?? innerSubpattern;

            var innerExpressionColon = innerSubpattern.ExpressionColon;

            if (!SimplifyPropertyPatternHelpers.IsMergable(outerExpressionColon.Expression) ||
                !SimplifyPropertyPatternHelpers.IsMergable(innerExpressionColon?.Expression))
            {
                return(null);
            }

            var merged = Merge(outerExpressionColon, innerExpressionColon);

            if (merged == null)
            {
                return(null);
            }

            return(currentSubpattern.WithExpressionColon(merged)
                   .WithPattern(innerSubpattern.Pattern)
                   .WithAdditionalAnnotations(Formatter.Annotation));
        }
Beispiel #2
0
 public static bool IsSimplifiable(
     SubpatternSyntax subpattern,
     [NotNullWhen(true)] out SubpatternSyntax?innerSubpattern,
     [NotNullWhen(true)] out BaseExpressionColonSyntax?outerExpressionColon)
 {
     // can't simplify if we have anything inside other than a property pattern clause.  i.e.
     // `a: { b: ... } x` is not simplifiable as we'll lose the `x` binding for the `a` property.
     //
     // can't simplify `a: { }` or `a: { b: ..., c: ... }`
     if (subpattern is
     {
         ExpressionColon : { } outer,
         Pattern : RecursivePatternSyntax
         {
             Type : null,
             PositionalPatternClause : null,
             Designation : null,
             PropertyPatternClause : { Subpatterns : { Count : 1 } subpatterns }
         }
     } &&
 public override void VisitSubpattern(SubpatternSyntax node)
 {
     Log(node, "Unsupported Syntax !");
 }