Skip to content

Commit

Permalink
Add strict option to ParseExpression (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 authored Sep 10, 2023
1 parent 423d691 commit 5713567
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Esprima/Ast/Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected Expression(Nodes type) : base(type)

/// <summary>
/// Gets or sets the list of tokens associated with the AST represented by this node.
/// This property is automatically set by <see cref="JavaScriptParser.ParseExpression(string)"/> when <see cref="ParserOptions.Tokens"/> is set to <see langword="true"/>.
/// This property is automatically set by <see cref="JavaScriptParser.ParseExpression(string, bool)"/> when <see cref="ParserOptions.Tokens"/> is set to <see langword="true"/>.
/// </summary>
/// <remarks>
/// The operation is not guaranteed to be thread-safe. In case concurrent access or update is possible, the necessary synchronization is caller's responsibility.
Expand All @@ -28,7 +28,7 @@ public IReadOnlyList<SyntaxToken>? Tokens

/// <summary>
/// Gets or sets the list of comments associated with the AST represented by this node.
/// This property is automatically set by <see cref="JavaScriptParser.ParseExpression(string)"/> when <see cref="ParserOptions.Comments"/> is set to <see langword="true"/>.
/// This property is automatically set by <see cref="JavaScriptParser.ParseExpression(string, bool)"/> when <see cref="ParserOptions.Comments"/> is set to <see langword="true"/>.
/// </summary>
/// <remarks>
/// The operation is not guaranteed to be thread-safe. In case concurrent access or update is possible, the necessary synchronization is caller's responsibility.
Expand Down
5 changes: 3 additions & 2 deletions src/Esprima/JavaScriptParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Esprima;
/// Provides JavaScript parsing capabilities.
/// </summary>
/// <remarks>
/// Use the <see cref="ParseScript" />, <see cref="ParseModule" /> or <see cref="ParseExpression(string)" /> methods to parse the JavaScript code.
/// Use the <see cref="ParseScript" />, <see cref="ParseModule" /> or <see cref="ParseExpression(string, bool)" /> methods to parse the JavaScript code.
/// </remarks>
public partial class JavaScriptParser
{
Expand Down Expand Up @@ -2751,11 +2751,12 @@ private Expression ParseExpression()
/// <summary>
/// Parses the code as a JavaScript expression.
/// </summary>
public Expression ParseExpression(string code)
public Expression ParseExpression(string code, bool strict = false)
{
Reset(code, source: null);
try
{
_context.Strict = strict;
_context.IsAsync = true;
return FinalizeRoot(ParseExpression());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Esprima/JsxParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Esprima;
/// </summary>
/// <remarks>
/// Use the <see cref="JavaScriptParser.ParseScript" />, <see cref="JavaScriptParser.ParseModule" /> or
/// <see cref="JavaScriptParser.ParseExpression(string)" /> methods to parse the JSX code.
/// <see cref="JavaScriptParser.ParseExpression(string, bool)" /> methods to parse the JSX code.
/// </remarks>
public class JsxParser : JavaScriptParser
{
Expand Down

0 comments on commit 5713567

Please sign in to comment.