Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/Esprima/Ast/AssignmentExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public AssignmentExpression(
Right = right;
}


public static AssignmentOperator ParseAssignmentOperator(string op)
{
return op switch
Expand All @@ -67,6 +66,30 @@ public static AssignmentOperator ParseAssignmentOperator(string op)
};
}

public static string ConvertAssignmentOperator(AssignmentOperator op)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably be internal

{
return op switch
{
AssignmentOperator.Assign => "=",
AssignmentOperator.PlusAssign => "+=",
AssignmentOperator.MinusAssign => "-=",
AssignmentOperator.TimesAssign => "*=",
AssignmentOperator.DivideAssign => "/=",
AssignmentOperator.ModuloAssign => "%=",
AssignmentOperator.BitwiseAndAssign => "&=",
AssignmentOperator.BitwiseOrAssign => "|=",
AssignmentOperator.BitwiseXOrAssign => "^=",
AssignmentOperator.ExponentiationAssign => "**=",
AssignmentOperator.LeftShiftAssign => "<<=",
AssignmentOperator.RightShiftAssign => ">>=",
AssignmentOperator.UnsignedRightShiftAssign => ">>>=",
AssignmentOperator.NullishAssign => "??=",
AssignmentOperator.AndAssign => "&&=",
AssignmentOperator.OrAssign => "||=",
_ => ThrowArgumentOutOfRangeException<string>(nameof(op), "Invalid assignment operator: " + op)
};
}

public override NodeCollection ChildNodes => new(Left, Right);

protected internal override void Accept(AstVisitor visitor)
Expand Down
33 changes: 33 additions & 0 deletions src/Esprima/Ast/BinaryExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,39 @@ public static BinaryOperator ParseBinaryOperator(string op)
};
}

public static string ConvertBinaryOperator(BinaryOperator op)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal

{
return op switch
{
BinaryOperator.Plus => "+",
BinaryOperator.Minus => "-",
BinaryOperator.Times => "*",
BinaryOperator.Divide => "/",
BinaryOperator.Modulo => "%",
BinaryOperator.Equal => "==",
BinaryOperator.NotEqual => "!=",
BinaryOperator.Greater => ">",
BinaryOperator.GreaterOrEqual => ">=",
BinaryOperator.Less => "<",
BinaryOperator.LessOrEqual => "<=",
BinaryOperator.StrictlyEqual => "===",
BinaryOperator.StricltyNotEqual => "!==",
BinaryOperator.BitwiseAnd => "&",
BinaryOperator.BitwiseOr => "|",
BinaryOperator.BitwiseXOr => "^",
BinaryOperator.LeftShift => "<<",
BinaryOperator.RightShift => ">>",
BinaryOperator.UnsignedRightShift => ">>>",
BinaryOperator.InstanceOf => "instanceof",
BinaryOperator.In => "in",
BinaryOperator.LogicalAnd => "&&",
BinaryOperator.LogicalOr => "||",
BinaryOperator.Exponentiation => "**",
BinaryOperator.NullishCoalescing => "??",
_ => ThrowArgumentOutOfRangeException<string>(nameof(op), "Invalid binary operator: " + op)
};
}

public override NodeCollection ChildNodes => new(Left, Right);

protected internal override void Accept(AstVisitor visitor)
Expand Down
19 changes: 18 additions & 1 deletion src/Esprima/Ast/UnaryExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected UnaryExpression(Nodes type, string? op, Expression arg) : base(type)
Prefix = true;
}

private static UnaryOperator ParseUnaryOperator(string? op)
public static UnaryOperator ParseUnaryOperator(string? op)
{
return op switch
{
Expand All @@ -50,6 +50,23 @@ private static UnaryOperator ParseUnaryOperator(string? op)
};
}

public static string ConvertUnaryOperator(UnaryOperator op)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal

{
return op switch
{
UnaryOperator.Plus => "+",
UnaryOperator.Minus => "-",
UnaryOperator.Increment => "++",
UnaryOperator.Decrement => "--",
UnaryOperator.BitwiseNot => "~",
UnaryOperator.LogicalNot => "!",
UnaryOperator.Delete => "delete",
UnaryOperator.Void => "void",
UnaryOperator.TypeOf => "typeof",
_ => ThrowArgumentOutOfRangeException<string>(nameof(op), "Invalid unary operator: " + op)
};
}

public override NodeCollection ChildNodes => new(Argument);

protected internal override void Accept(AstVisitor visitor)
Expand Down
2 changes: 1 addition & 1 deletion src/Esprima/JavascriptParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2281,7 +2281,7 @@ private void CheckPatternParam(ParsedParameters options, Node param)
};
}

private const int MaxAssignmentDepth = 100;
public int MaxAssignmentDepth { get; set; } = 1000;
private int _assignmentDepth = 0;

private Expression ParseAssignmentExpression()
Expand Down
Loading