Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strict option to ParseExpression #410

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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)
adams85 marked this conversation as resolved.
Show resolved Hide resolved
{
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