internal static ReadOnlySpan <char> ParseArguments(this ReadOnlySpan <char> literal, out List <JsToken> arguments, char termination) { arguments = new List <JsToken>(); while (!literal.IsNullOrEmpty()) { JsToken listValue; literal = literal.AdvancePastWhitespace(); if (literal[0] == termination) { literal = literal.Advance(1); break; } if (literal.StartsWith("...")) { literal = literal.Advance(3); literal = literal.ParseJsExpression(out listValue); if (!(listValue is JsIdentifier) && !(listValue is JsArrayExpression)) { throw new SyntaxErrorException($"Spread operator expected array but instead found {listValue.DebugToken()}"); } listValue = new JsSpreadElement(listValue); } else { literal = literal.ParseJsExpression(out listValue); } arguments.Add(listValue); literal = literal.AdvancePastWhitespace(); if (literal.IsNullOrEmpty()) { break; } if (literal[0] == termination) { literal = literal.Advance(1); break; } literal = literal.AdvancePastWhitespace(); var c = literal.SafeGetChar(0); if (c.IsEnd() || c == termination) { literal = literal.Advance(1); break; } if (c != ',') { throw new SyntaxErrorException($"Unterminated arguments expression near: {literal.DebugLiteral()}"); } literal = literal.Advance(1); literal = literal.AdvancePastWhitespace(); } literal = literal.AdvancePastWhitespace(); return(literal); }
protected bool Equals(JsSpreadElement other) { return(Equals(Argument, other.Argument)); }