From 57135670d778f32002b8c879089442b127063847 Mon Sep 17 00:00:00 2001 From: adams85 <31276480+adams85@users.noreply.github.com> Date: Sun, 10 Sep 2023 19:45:46 +0200 Subject: [PATCH] Add strict option to ParseExpression (#410) --- src/Esprima/Ast/Expression.cs | 4 ++-- src/Esprima/JavaScriptParser.cs | 5 +++-- src/Esprima/JsxParser.cs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Esprima/Ast/Expression.cs b/src/Esprima/Ast/Expression.cs index 0ed3f7f6..9fba4ffe 100644 --- a/src/Esprima/Ast/Expression.cs +++ b/src/Esprima/Ast/Expression.cs @@ -13,7 +13,7 @@ protected Expression(Nodes type) : base(type) /// /// Gets or sets the list of tokens associated with the AST represented by this node. - /// This property is automatically set by when is set to . + /// This property is automatically set by when is set to . /// /// /// The operation is not guaranteed to be thread-safe. In case concurrent access or update is possible, the necessary synchronization is caller's responsibility. @@ -28,7 +28,7 @@ public IReadOnlyList? Tokens /// /// Gets or sets the list of comments associated with the AST represented by this node. - /// This property is automatically set by when is set to . + /// This property is automatically set by when is set to . /// /// /// The operation is not guaranteed to be thread-safe. In case concurrent access or update is possible, the necessary synchronization is caller's responsibility. diff --git a/src/Esprima/JavaScriptParser.cs b/src/Esprima/JavaScriptParser.cs index d90bcee9..d897a870 100644 --- a/src/Esprima/JavaScriptParser.cs +++ b/src/Esprima/JavaScriptParser.cs @@ -8,7 +8,7 @@ namespace Esprima; /// Provides JavaScript parsing capabilities. /// /// -/// Use the , or methods to parse the JavaScript code. +/// Use the , or methods to parse the JavaScript code. /// public partial class JavaScriptParser { @@ -2751,11 +2751,12 @@ private Expression ParseExpression() /// /// Parses the code as a JavaScript expression. /// - 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()); } diff --git a/src/Esprima/JsxParser.cs b/src/Esprima/JsxParser.cs index a76d721d..d8239eac 100644 --- a/src/Esprima/JsxParser.cs +++ b/src/Esprima/JsxParser.cs @@ -9,7 +9,7 @@ namespace Esprima; /// /// /// Use the , or -/// methods to parse the JSX code. +/// methods to parse the JSX code. /// public class JsxParser : JavaScriptParser {