Răsfoiți Sursa

Add more Acornima friendly type aliases (#1825)

Marko Lahma 1 an în urmă
părinte
comite
5656b1d3dc
29 a modificat fișierele cu 233 adăugiri și 232 ștergeri
  1. 6 1
      Directory.Build.props
  2. 2 2
      Jint.Benchmark/EngineComparisonBenchmark.cs
  3. 1 1
      Jint.Benchmark/EngineConstructionBenchmark.cs
  4. 1 0
      Jint.Benchmark/Jint.Benchmark.csproj
  5. 1 1
      Jint.Tests.CommonScripts/ConcurrencyTest.cs
  6. 1 1
      Jint.Tests.PublicInterface/ShadowRealmTests.cs
  7. 2 2
      Jint.Tests.Test262/Test262Test.cs
  8. 152 153
      Jint.Tests/Parser/JavascriptParserTests.cs
  9. 1 1
      Jint.Tests/Runtime/Debugger/EvaluateTests.cs
  10. 2 2
      Jint.Tests/Runtime/EngineTests.cs
  11. 3 3
      Jint/Engine.Ast.cs
  12. 4 4
      Jint/Engine.cs
  13. 3 7
      Jint/EsprimaExtensions.cs
  14. 1 1
      Jint/JsValueExtensions.cs
  15. 1 1
      Jint/Native/Function/ClassDefinition.cs
  16. 2 2
      Jint/Native/Function/EvalFunction.cs
  17. 2 2
      Jint/Native/Function/FunctionInstance.Dynamic.cs
  18. 1 1
      Jint/Native/JsTypedArray.cs
  19. 2 2
      Jint/Native/ShadowRealm/ShadowRealm.cs
  20. 2 2
      Jint/Runtime/Debugger/DebugHandler.cs
  21. 2 2
      Jint/Runtime/Environments/FunctionEnvironment.cs
  22. 13 13
      Jint/Runtime/Interpreter/Expressions/DestructuringPatternAssignmentExpression.cs
  23. 2 2
      Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs
  24. 7 7
      Jint/Runtime/Interpreter/Expressions/JintLiteralExpression.cs
  25. 6 6
      Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs
  26. 6 6
      Jint/Runtime/Interpreter/Statements/JintVariableDeclaration.cs
  27. 3 3
      Jint/Runtime/Modules/ModuleBuilder.cs
  28. 3 3
      Jint/Runtime/Modules/ModuleFactory.cs
  29. 1 1
      Jint/Runtime/TypeConverter.cs

+ 6 - 1
Directory.Build.props

@@ -30,8 +30,13 @@
     <Using Include="Esprima" />
     <Using Include="Esprima.Ast" />
     <Using Include="Esprima.Utils" />
-    <Using Include="Esprima.Location" Alias="SourceLocation" />
+
+    <Using Include="Esprima.Ast.BindingPattern" Alias="DestructuringPattern" />
     <Using Include="Esprima.Ast.Nodes" Alias="NodeType" />
+    <Using Include="Esprima.JavaScriptParser" Alias="Parser" />
+    <Using Include="Esprima.Location" Alias="SourceLocation" />
+    <Using Include="Esprima.TokenType" Alias="TokenKind" />
+    <Using Include="Esprima.ParserException" Alias="ParseErrorException" />
   </ItemGroup>
 
 </Project>

+ 2 - 2
Jint.Benchmark/EngineComparisonBenchmark.cs

@@ -38,7 +38,7 @@ public class EngineComparisonBenchmark
     [GlobalSetup]
     public void Setup()
     {
-        var javaScriptParser = new JavaScriptParser();
+        var parser = new Parser();
         foreach (var fileName in _files.Keys.ToList())
         {
             var script = File.ReadAllText($"Scripts/{fileName}.js");
@@ -47,7 +47,7 @@ public class EngineComparisonBenchmark
                 script = _dromaeoHelpers + Environment.NewLine + Environment.NewLine + script;
             }
             _files[fileName] = script;
-            _parsedScripts[fileName] = javaScriptParser.ParseScript(script, strict: true);
+            _parsedScripts[fileName] = parser.ParseScript(script, strict: true);
         }
     }
 

+ 1 - 1
Jint.Benchmark/EngineConstructionBenchmark.cs

@@ -12,7 +12,7 @@ public class EngineConstructionBenchmark
     [GlobalSetup]
     public void GlobalSetup()
     {
-        var parser = new JavaScriptParser();
+        var parser = new Parser();
         _program = parser.ParseScript("([].length + ''.length)");
         _simple = parser.ParseScript("1");
         new Engine().Evaluate(_program);

+ 1 - 0
Jint.Benchmark/Jint.Benchmark.csproj

@@ -34,5 +34,6 @@
   <ItemGroup>
     <Using Include="Esprima" />
     <Using Include="Esprima.Ast" />
+    <Using Include="Esprima.JavaScriptParser" Alias="Parser" />
   </ItemGroup>
 </Project>

+ 1 - 1
Jint.Tests.CommonScripts/ConcurrencyTest.cs

@@ -11,7 +11,7 @@ public class ConcurrencyTest
         var scriptContents = SunSpiderTests.GetEmbeddedFile("babel-standalone.js");
         var script = prepared
             ? Engine.PrepareScript(scriptContents)
-            : new JavaScriptParser().ParseScript(scriptContents);
+            : new Parser().ParseScript(scriptContents);
 
         Parallel.ForEach(Enumerable.Range(0, 3), x =>
         {

+ 1 - 1
Jint.Tests.PublicInterface/ShadowRealmTests.cs

@@ -83,7 +83,7 @@ public class ShadowRealmTests
         var shadowRealm2 = engine.Intrinsics.ShadowRealm.Construct();
         shadowRealm2.SetValue("message", "realm 2");
 
-        var parser = new Esprima.JavaScriptParser();
+        var parser = new Parser();
         var script = parser.ParseScript("(function hello() {return \"hello \" + message})();");
 
         // Act & Assert

+ 2 - 2
Jint.Tests.Test262/Test262Test.cs

@@ -38,7 +38,7 @@ public abstract partial class Test262Test
                 }
 
                 var options = new ParserOptions { RegExpParseMode = RegExpParseMode.AdaptToInterpreted, Tolerant = false };
-                var parser = new JavaScriptParser(options);
+                var parser = new Parser(options);
                 var script = parser.ParseScript(args.At(0).AsString());
 
                 return engine.Evaluate(script);
@@ -93,7 +93,7 @@ public abstract partial class Test262Test
         }
         else
         {
-            engine.Execute(new JavaScriptParser().ParseScript(file.Program, source: file.FileName));
+            engine.Execute(new Parser().ParseScript(file.Program, source: file.FileName));
         }
     }
 

+ 152 - 153
Jint.Tests/Parser/JavascriptParserTests.cs

@@ -1,182 +1,181 @@
 using Jint.Runtime;
 
-namespace Jint.Tests.Parser
+namespace Jint.Tests.Parsing;
+
+public class JavascriptParserTests
 {
-    public class JavascriptParserTests
+    [Fact]
+    public void ShouldParseThis()
+    {
+        var program = new Parser().ParseScript("this");
+        var body = program.Body;
+
+        Assert.Single(body);
+        Assert.Equal(NodeType.ThisExpression, body.First().As<ExpressionStatement>().Expression.Type);
+    }
+
+    [Fact]
+    public void ShouldParseNull()
+    {
+        var program = new Parser().ParseScript("null");
+        var body = program.Body;
+
+        Assert.Single(body);
+        Assert.Equal(NodeType.Literal, body.First().As<ExpressionStatement>().Expression.Type);
+        Assert.Equal(null, body.First().As<ExpressionStatement>().Expression.As<Literal>().Value);
+        Assert.Equal("null", body.First().As<ExpressionStatement>().Expression.As<Literal>().Raw);
+    }
+
+    [Fact]
+    public void ShouldParseNumeric()
     {
-        [Fact]
-        public void ShouldParseThis()
-        {
-            var program = new JavaScriptParser().ParseScript("this");
-            var body = program.Body;
-
-            Assert.Single(body);
-            Assert.Equal(NodeType.ThisExpression, body.First().As<ExpressionStatement>().Expression.Type);
-        }
-
-        [Fact]
-        public void ShouldParseNull()
-        {
-            var program = new JavaScriptParser().ParseScript("null");
-            var body = program.Body;
-
-            Assert.Single(body);
-            Assert.Equal(NodeType.Literal, body.First().As<ExpressionStatement>().Expression.Type);
-            Assert.Equal(null, body.First().As<ExpressionStatement>().Expression.As<Literal>().Value);
-            Assert.Equal("null", body.First().As<ExpressionStatement>().Expression.As<Literal>().Raw);
-        }
-
-        [Fact]
-        public void ShouldParseNumeric()
-        {
-            var code = @"
+        var code = @"
                 42
             ";
-            var program = new JavaScriptParser().ParseScript(code);
-            var body = program.Body;
-
-            Assert.Single(body);
-            Assert.Equal(NodeType.Literal, body.First().As<ExpressionStatement>().Expression.Type);
-            Assert.Equal(42d, body.First().As<ExpressionStatement>().Expression.As<Literal>().Value);
-            Assert.Equal("42", body.First().As<ExpressionStatement>().Expression.As<Literal>().Raw);
-        }
-
-        [Fact]
-        public void ShouldParseBinaryExpression()
-        {
-            BinaryExpression binary;
-
-            var program = new JavaScriptParser().ParseScript("(1 + 2 ) * 3");
-            var body = program.Body;
-
-            Assert.Single(body);
-            Assert.NotNull(binary = body.First().As<ExpressionStatement>().Expression.As<BinaryExpression>());
-            Assert.Equal(3d, binary.Right.As<Literal>().Value);
-            Assert.Equal(BinaryOperator.Times, binary.Operator);
-            Assert.Equal(1d, binary.Left.As<BinaryExpression>().Left.As<Literal>().Value);
-            Assert.Equal(2d, binary.Left.As<BinaryExpression>().Right.As<Literal>().Value);
-            Assert.Equal(BinaryOperator.Plus, binary.Left.As<BinaryExpression>().Operator);
-        }
-
-        [Theory]
-        [InlineData(0, "0")]
-        [InlineData(42, "42")]
-        [InlineData(0.14, "0.14")]
-        [InlineData(3.14159, "3.14159")]
-        [InlineData(6.02214179e+23, "6.02214179e+23")]
-        [InlineData(1.492417830e-10, "1.492417830e-10")]
-        [InlineData(0, "0x0")]
-        [InlineData(0, "0x0;")]
-        [InlineData(0xabc, "0xabc")]
-        [InlineData(0xdef, "0xdef")]
-        [InlineData(0X1A, "0X1A")]
-        [InlineData(0x10, "0x10")]
-        [InlineData(0x100, "0x100")]
-        [InlineData(0X04, "0X04")]
-        [InlineData(02, "02")]
-        [InlineData(10, "012")]
-        [InlineData(10, "0012")]
-        [InlineData(1.189008226412092e+38, "0x5973772948c653ac1971f1576e03c4d4")]
-        [InlineData(18446744073709552000d, "0xffffffffffffffff")]
-        public void ShouldParseNumericLiterals(object expected, string code)
-        {
-            Literal literal;
-
-            var program = new JavaScriptParser().ParseScript(code);
-            var body = program.Body;
-
-            Assert.Single(body);
-            Assert.NotNull(literal = body.First().As<ExpressionStatement>().Expression.As<Literal>());
-            Assert.Equal(Convert.ToDouble(expected), Convert.ToDouble(literal.Value));
-        }
-
-        [Theory]
-        [InlineData("Hello", @"'Hello'")]
-        [InlineData("\n\r\t\v\b\f\\\'\"\0", @"'\n\r\t\v\b\f\\\'\""\0'")]
-        [InlineData("\u0061", @"'\u0061'")]
-        [InlineData("\x61", @"'\x61'")]
-        [InlineData("Hello\nworld", @"'Hello\nworld'")]
-        [InlineData("Hello\\\nworld", @"'Hello\\\nworld'")]
-        public void ShouldParseStringLiterals(string expected, string code)
-        {
-            Literal literal;
-
-            var program = new JavaScriptParser().ParseScript(code);
-            var body = program.Body;
-
-            Assert.Single(body);
-            Assert.NotNull(literal = body.First().As<ExpressionStatement>().Expression.As<Literal>());
-            Assert.Equal(expected, literal.Value);
-        }
-
-        [Theory]
-        [InlineData(@"{ x
+        var program = new Parser().ParseScript(code);
+        var body = program.Body;
+
+        Assert.Single(body);
+        Assert.Equal(NodeType.Literal, body.First().As<ExpressionStatement>().Expression.Type);
+        Assert.Equal(42d, body.First().As<ExpressionStatement>().Expression.As<Literal>().Value);
+        Assert.Equal("42", body.First().As<ExpressionStatement>().Expression.As<Literal>().Raw);
+    }
+
+    [Fact]
+    public void ShouldParseBinaryExpression()
+    {
+        BinaryExpression binary;
+
+        var program = new Parser().ParseScript("(1 + 2 ) * 3");
+        var body = program.Body;
+
+        Assert.Single(body);
+        Assert.NotNull(binary = body.First().As<ExpressionStatement>().Expression.As<BinaryExpression>());
+        Assert.Equal(3d, binary.Right.As<Literal>().Value);
+        Assert.Equal(BinaryOperator.Times, binary.Operator);
+        Assert.Equal(1d, binary.Left.As<BinaryExpression>().Left.As<Literal>().Value);
+        Assert.Equal(2d, binary.Left.As<BinaryExpression>().Right.As<Literal>().Value);
+        Assert.Equal(BinaryOperator.Plus, binary.Left.As<BinaryExpression>().Operator);
+    }
+
+    [Theory]
+    [InlineData(0, "0")]
+    [InlineData(42, "42")]
+    [InlineData(0.14, "0.14")]
+    [InlineData(3.14159, "3.14159")]
+    [InlineData(6.02214179e+23, "6.02214179e+23")]
+    [InlineData(1.492417830e-10, "1.492417830e-10")]
+    [InlineData(0, "0x0")]
+    [InlineData(0, "0x0;")]
+    [InlineData(0xabc, "0xabc")]
+    [InlineData(0xdef, "0xdef")]
+    [InlineData(0X1A, "0X1A")]
+    [InlineData(0x10, "0x10")]
+    [InlineData(0x100, "0x100")]
+    [InlineData(0X04, "0X04")]
+    [InlineData(02, "02")]
+    [InlineData(10, "012")]
+    [InlineData(10, "0012")]
+    [InlineData(1.189008226412092e+38, "0x5973772948c653ac1971f1576e03c4d4")]
+    [InlineData(18446744073709552000d, "0xffffffffffffffff")]
+    public void ShouldParseNumericLiterals(object expected, string code)
+    {
+        Literal literal;
+
+        var program = new Parser().ParseScript(code);
+        var body = program.Body;
+
+        Assert.Single(body);
+        Assert.NotNull(literal = body.First().As<ExpressionStatement>().Expression.As<Literal>());
+        Assert.Equal(Convert.ToDouble(expected), Convert.ToDouble(literal.Value));
+    }
+
+    [Theory]
+    [InlineData("Hello", @"'Hello'")]
+    [InlineData("\n\r\t\v\b\f\\\'\"\0", @"'\n\r\t\v\b\f\\\'\""\0'")]
+    [InlineData("\u0061", @"'\u0061'")]
+    [InlineData("\x61", @"'\x61'")]
+    [InlineData("Hello\nworld", @"'Hello\nworld'")]
+    [InlineData("Hello\\\nworld", @"'Hello\\\nworld'")]
+    public void ShouldParseStringLiterals(string expected, string code)
+    {
+        Literal literal;
+
+        var program = new Parser().ParseScript(code);
+        var body = program.Body;
+
+        Assert.Single(body);
+        Assert.NotNull(literal = body.First().As<ExpressionStatement>().Expression.As<Literal>());
+        Assert.Equal(expected, literal.Value);
+    }
+
+    [Theory]
+    [InlineData(@"{ x
                       ++y }")]
-        [InlineData(@"{ x
+    [InlineData(@"{ x
                       --y }")]
-        [InlineData(@"var x /* comment */;
+    [InlineData(@"var x /* comment */;
                       { var x = 14, y = 3
                       z; }")]
-        [InlineData(@"while (true) { continue
+    [InlineData(@"while (true) { continue
                       there; }")]
-        [InlineData(@"while (true) { continue // Comment
+    [InlineData(@"while (true) { continue // Comment
                       there; }")]
-        [InlineData(@"while (true) { continue /* Multiline
+    [InlineData(@"while (true) { continue /* Multiline
                       Comment */there; }")]
-        [InlineData(@"while (true) { break
+    [InlineData(@"while (true) { break
                       there; }")]
-        [InlineData(@"while (true) { break // Comment
+    [InlineData(@"while (true) { break // Comment
                       there; }")]
-        [InlineData(@"while (true) { break /* Multiline
+    [InlineData(@"while (true) { break /* Multiline
                       Comment */there; }")]
-        [InlineData(@"(function(){ return
+    [InlineData(@"(function(){ return
                       x; })")]
-        [InlineData(@"(function(){ return // Comment
+    [InlineData(@"(function(){ return // Comment
                       x; })")]
-        [InlineData(@"(function(){ return/* Multiline
+    [InlineData(@"(function(){ return/* Multiline
                       Comment */x; })")]
-        [InlineData(@"{ throw error
+    [InlineData(@"{ throw error
                       error; }")]
-        [InlineData(@"{ throw error// Comment
+    [InlineData(@"{ throw error// Comment
                       error; }")]
-        [InlineData(@"{ throw error/* Multiline
+    [InlineData(@"{ throw error/* Multiline
                       Comment */error; }")]
 
-        public void ShouldInsertSemicolons(string code)
-        {
-            new JavaScriptParser().ParseScript(code);
-        }
+    public void ShouldInsertSemicolons(string code)
+    {
+        new Parser().ParseScript(code);
+    }
 
-        [Fact]
-        public void ShouldProvideLocationForMultiLinesStringLiterals()
-        {
-            const string Code = @"'\
+    [Fact]
+    public void ShouldProvideLocationForMultiLinesStringLiterals()
+    {
+        const string Code = @"'\
 \
 '
 ";
-            var program = new JavaScriptParser(new ParserOptions()).ParseScript(Code);
-            var expr = program.Body.First().As<ExpressionStatement>().Expression;
-            Assert.Equal(1, expr.Location.Start.Line);
-            Assert.Equal(0, expr.Location.Start.Column);
-            Assert.Equal(3, expr.Location.End.Line);
-            Assert.Equal(1, expr.Location.End.Column);
-        }
-
-        [Fact]
-        public void ShouldThrowErrorForInvalidLeftHandOperation()
-        {
-            Assert.Throws<JavaScriptException>(() => new Engine().Execute("~ (WE0=1)--- l('1');"));
-        }
-
-
-        [Theory]
-        [InlineData("....")]
-        [InlineData("while")]
-        [InlineData("var")]
-        [InlineData("-.-")]
-        public void ShouldThrowParserExceptionForInvalidCode(string code)
-        {
-            Assert.Throws<ParserException>(() => new JavaScriptParser().ParseScript(code));
-        }
+        var program = new Parser(new ParserOptions()).ParseScript(Code);
+        var expr = program.Body.First().As<ExpressionStatement>().Expression;
+        Assert.Equal(1, expr.Location.Start.Line);
+        Assert.Equal(0, expr.Location.Start.Column);
+        Assert.Equal(3, expr.Location.End.Line);
+        Assert.Equal(1, expr.Location.End.Column);
+    }
+
+    [Fact]
+    public void ShouldThrowErrorForInvalidLeftHandOperation()
+    {
+        Assert.Throws<JavaScriptException>(() => new Engine().Execute("~ (WE0=1)--- l('1');"));
+    }
+
+
+    [Theory]
+    [InlineData("....")]
+    [InlineData("while")]
+    [InlineData("var")]
+    [InlineData("-.-")]
+    public void ShouldThrowParseErrorExceptionForInvalidCode(string code)
+    {
+        Assert.Throws<ParseErrorException>(() => new Parser().ParseScript(code));
     }
 }

+ 1 - 1
Jint.Tests/Runtime/Debugger/EvaluateTests.cs

@@ -72,7 +72,7 @@ namespace Jint.Tests.Runtime.Debugger
             {
                 var exception = Assert.Throws<DebugEvaluationException>(() =>
                     engine.Debugger.Evaluate("this is a syntax error"));
-                Assert.IsType<ParserException>(exception.InnerException);
+                Assert.IsType<ParseErrorException>(exception.InnerException);
             });
         }
 

+ 2 - 2
Jint.Tests/Runtime/EngineTests.cs

@@ -1046,7 +1046,7 @@ namespace Jint.Tests.Runtime
             {
                 engine.Evaluate("1.2+ new", "jQuery.js");
             }
-            catch (ParserException e)
+            catch (ParseErrorException e)
             {
                 Assert.Equal(1, e.LineNumber);
                 Assert.Equal(9, e.Column);
@@ -1314,7 +1314,7 @@ var prep = function (fn) { fn(); };
         {
             var code = "if({ __proto__: [], __proto__:[] } instanceof Array) {}";
 
-            Exception ex = Assert.Throws<ParserException>(() => _engine.Execute(code, new ParserOptions { Tolerant = false }));
+            Exception ex = Assert.Throws<ParseErrorException>(() => _engine.Execute(code, new ParserOptions { Tolerant = false }));
             Assert.Contains("Duplicate __proto__ fields are not allowed in object literals", ex.Message);
 
             ex = Assert.Throws<JavaScriptException>(() => _engine.Execute($"eval('{code}')"));

+ 3 - 3
Jint/Engine.Ast.cs

@@ -25,7 +25,7 @@ public partial class Engine
             AllowReturnOutsideFunction = true, OnNodeCreated = astAnalyzer.NodeVisitor
         };
 
-        return new JavaScriptParser(options).ParseScript(script, source, strict);
+        return new Parser(options).ParseScript(script, source, strict);
     }
 
     /// <summary>
@@ -42,7 +42,7 @@ public partial class Engine
             OnNodeCreated = astAnalyzer.NodeVisitor
         };
 
-        return new JavaScriptParser(options).ParseModule(script, source);
+        return new Parser(options).ParseModule(script, source);
     }
 
     [StructLayout(LayoutKind.Auto)]
@@ -86,7 +86,7 @@ public partial class Engine
                     var constantValue = JintLiteralExpression.ConvertToJsValue(literal);
                     node.AssociatedData = constantValue is not null ? new JintConstantExpression(literal, constantValue) : null;
 
-                    if (node.AssociatedData is null && literal.TokenType == TokenType.RegularExpression && _options.CompileRegex)
+                    if (node.AssociatedData is null && literal.TokenType == TokenKind.RegularExpression && _options.CompileRegex)
                     {
                         var regExpLiteral = (RegExpLiteral) literal;
                         var regExpParseResult = regExpLiteral.ParseResult;

+ 4 - 4
Jint/Engine.cs

@@ -30,7 +30,7 @@ namespace Jint
         private static readonly Options _defaultEngineOptions = new();
 
         private readonly ParserOptions _defaultParserOptions;
-        private readonly JavaScriptParser _defaultParser;
+        private readonly Parser _defaultParser;
 
         private readonly ExecutionContextStack _executionContexts;
         private JsValue _completionValue = JsValue.Undefined;
@@ -150,7 +150,7 @@ namespace Jint
                 RegexTimeout = Options.Constraints.RegexTimeout
             };
 
-            _defaultParser = new JavaScriptParser(_defaultParserOptions);
+            _defaultParser = new Parser(_defaultParserOptions);
         }
 
         private void Reset()
@@ -349,7 +349,7 @@ namespace Jint
         {
             var parser = ReferenceEquals(_defaultParserOptions, parserOptions)
                 ? _defaultParser
-                : new JavaScriptParser(parserOptions);
+                : new Parser(parserOptions);
 
             var script = parser.ParseScript(code, source, _isStrict);
 
@@ -381,7 +381,7 @@ namespace Jint
         {
             var parser = ReferenceEquals(_defaultParserOptions, parserOptions)
                 ? _defaultParser
-                : new JavaScriptParser(parserOptions);
+                : new Parser(parserOptions);
 
             var script = parser.ParseScript(code, source, _isStrict);
 

+ 3 - 7
Jint/EsprimaExtensions.cs

@@ -37,7 +37,7 @@ namespace Jint
             JsValue key;
             if (expression is Literal literal)
             {
-                key = literal.TokenType == TokenType.NullLiteral ? JsValue.Null : LiteralKeyToString(literal);
+                key = literal.TokenType == TokenKind.NullLiteral ? JsValue.Null : LiteralKeyToString(literal);
             }
             else if (!resolveComputed && expression is Identifier identifier)
             {
@@ -287,13 +287,9 @@ namespace Jint
                 var catchEnvRecord = (DeclarativeEnvironment) env;
                 catchEnvRecord.CreateMutableBindingAndInitialize(identifier.Name, canBeDeleted: false, value);
             }
-            else if (expression is BindingPattern bindingPattern)
+            else if (expression is DestructuringPattern pattern)
             {
-                BindingPatternAssignmentExpression.ProcessPatterns(
-                    context,
-                    bindingPattern,
-                    value,
-                    env);
+                DestructuringPatternAssignmentExpression.ProcessPatterns(context, pattern, value, env);
             }
         }
 

+ 1 - 1
Jint/JsValueExtensions.cs

@@ -661,7 +661,7 @@ public static class JsValueExtensions
         {
             return TypeConverter.ToBigInt(value);
         }
-        catch (ParserException ex)
+        catch (ParseErrorException ex)
         {
             ExceptionHelper.ThrowSyntaxError(engine.Realm, ex.Message);
             return default;

+ 1 - 1
Jint/Native/Function/ClassDefinition.cs

@@ -24,7 +24,7 @@ internal sealed class ClassDefinition
         // generate missing constructor AST only once
         static MethodDefinition CreateConstructorMethodDefinition(string source)
         {
-            var script = new JavaScriptParser().ParseScript(source);
+            var script = new Parser().ParseScript(source);
             var classDeclaration = (ClassDeclaration) script.Body[0];
             return (MethodDefinition) classDeclaration.Body.Body[0];
         }

+ 2 - 2
Jint/Native/Function/EvalFunction.cs

@@ -11,7 +11,7 @@ public sealed class EvalFunction : Function
     private static readonly JsString _functionName = new("eval");
 
     private static readonly ParserOptions _parserOptions = ParserOptions.Default with { Tolerant = true };
-    private readonly JavaScriptParser _parser = new(_parserOptions);
+    private readonly Parser _parser = new(_parserOptions);
 
     internal EvalFunction(
         Engine engine,
@@ -79,7 +79,7 @@ public sealed class EvalFunction : Function
         {
             script = _parser.ParseScript(x.ToString(), strict: strictCaller);
         }
-        catch (ParserException e)
+        catch (ParseErrorException e)
         {
             if (string.Equals(e.Description, Messages.InvalidLHSInAssignment, StringComparison.Ordinal))
             {

+ 2 - 2
Jint/Native/Function/FunctionInstance.Dynamic.cs

@@ -142,14 +142,14 @@ public partial class Function
                 }
             }
 
-            JavaScriptParser parser = new(new ParserOptions
+            Parser parser = new(new ParserOptions
             {
                 Tolerant = false,
                 RegexTimeout = _engine.Options.Constraints.RegexTimeout
             });
             function = (IFunction) parser.ParseScript(functionExpression, source: null, _engine._isStrict).Body[0];
         }
-        catch (ParserException ex)
+        catch (ParseErrorException ex)
         {
             ExceptionHelper.ThrowSyntaxError(_engine.ExecutionContext.Realm, ex.Message);
         }

+ 1 - 1
Jint/Native/JsTypedArray.cs

@@ -319,7 +319,7 @@ namespace Jint.Native
                         DoIntegerIndexedElementSet((int) index, numValue);
                     }
                 }
-                catch (ParserException ex)
+                catch (ParseErrorException ex)
                 {
                     ExceptionHelper.ThrowSyntaxError(_engine.Realm, ex.Message);
                 }

+ 2 - 2
Jint/Native/ShadowRealm/ShadowRealm.cs

@@ -19,7 +19,7 @@ namespace Jint.Native.ShadowRealm;
 public sealed class ShadowRealm : ObjectInstance
 #pragma warning restore MA0049
 {
-    private readonly JavaScriptParser _parser;
+    private readonly Parser _parser;
     internal readonly Realm _shadowRealm;
     private readonly ExecutionContext _executionContext;
 
@@ -111,7 +111,7 @@ public sealed class ShadowRealm : ObjectInstance
         {
             script = _parser.ParseScript(sourceText, source: null, _engine._isStrict);
         }
-        catch (ParserException e)
+        catch (ParseErrorException e)
         {
             if (string.Equals(e.Description, Messages.InvalidLHSInAssignment, StringComparison.Ordinal))
             {

+ 2 - 2
Jint/Runtime/Debugger/DebugHandler.cs

@@ -125,13 +125,13 @@ namespace Jint.Runtime.Debugger
         public JsValue Evaluate(string source, ParserOptions? options = null)
         {
             options ??= new ParserOptions();
-            var parser = new JavaScriptParser(options);
+            var parser = new Parser(options);
             try
             {
                 var script = parser.ParseScript(source, "evaluation");
                 return Evaluate(script);
             }
-            catch (ParserException ex)
+            catch (ParseErrorException ex)
             {
                 throw new DebugEvaluationException("An error occurred during debugger expression parsing", ex);
             }

+ 2 - 2
Jint/Runtime/Environments/FunctionEnvironment.cs

@@ -299,9 +299,9 @@ namespace Jint.Runtime.Environments
             {
                 SetItemSafely(restIdentifier.Name, array, initiallyEmpty);
             }
-            else if (restElement.Argument is BindingPattern bindingPattern)
+            else if (restElement.Argument is DestructuringPattern pattern)
             {
-                SetFunctionParameter(context, bindingPattern, new [] { array }, 0, initiallyEmpty);
+                SetFunctionParameter(context, pattern, [array], 0, initiallyEmpty);
             }
             else
             {

+ 13 - 13
Jint/Runtime/Interpreter/Expressions/BindingPatternAssignmentExpression.cs → Jint/Runtime/Interpreter/Expressions/DestructuringPatternAssignmentExpression.cs

@@ -6,15 +6,15 @@ using Environment = Jint.Runtime.Environments.Environment;
 
 namespace Jint.Runtime.Interpreter.Expressions
 {
-    internal sealed class BindingPatternAssignmentExpression : JintExpression
+    internal sealed class DestructuringPatternAssignmentExpression : JintExpression
     {
-        private readonly BindingPattern _pattern;
+        private readonly DestructuringPattern _pattern;
         private JintExpression _right = null!;
         private bool _initialized;
 
-        public BindingPatternAssignmentExpression(AssignmentExpression expression) : base(expression)
+        public DestructuringPatternAssignmentExpression(AssignmentExpression expression) : base(expression)
         {
-            _pattern = (BindingPattern) expression.Left;
+            _pattern = (DestructuringPattern) expression.Left;
         }
 
         protected override object EvaluateInternal(EvaluationContext context)
@@ -42,7 +42,7 @@ namespace Jint.Runtime.Interpreter.Expressions
 
         internal static JsValue ProcessPatterns(
             EvaluationContext context,
-            BindingPattern pattern,
+            DestructuringPattern pattern,
             JsValue argument,
             Environment? environment,
             bool checkPatternPropertyReference = true)
@@ -157,7 +157,7 @@ namespace Jint.Runtime.Interpreter.Expressions
 
                         AssignToReference(engine, reference, value, environment);
                     }
-                    else if (left is BindingPattern bindingPattern)
+                    else if (left is DestructuringPattern dp)
                     {
                         JsValue value;
                         if (arrayOperations != null)
@@ -169,7 +169,7 @@ namespace Jint.Runtime.Interpreter.Expressions
                             iterator!.TryIteratorStep(out var temp);
                             value = temp;
                         }
-                        ProcessPatterns(context, bindingPattern, value, environment);
+                        ProcessPatterns(context, dp, value, environment);
                     }
                     else if (left is RestElement restElement)
                     {
@@ -215,7 +215,7 @@ namespace Jint.Runtime.Interpreter.Expressions
                         {
                             AssignToIdentifier(engine, leftIdentifier.Name, array, environment, checkReference);
                         }
-                        else if (restElement.Argument is BindingPattern bp)
+                        else if (restElement.Argument is DestructuringPattern bp)
                         {
                             ProcessPatterns(context, bp, array, environment);
                         }
@@ -256,7 +256,7 @@ namespace Jint.Runtime.Interpreter.Expressions
 
                             AssignToIdentifier(engine, leftIdentifier.Name, value, environment, checkReference);
                         }
-                        else if (assignmentPattern.Left is BindingPattern bp)
+                        else if (assignmentPattern.Left is DestructuringPattern bp)
                         {
                             ProcessPatterns(context, bp, value, environment);
                         }
@@ -334,7 +334,7 @@ namespace Jint.Runtime.Interpreter.Expressions
                             value = completion;
                         }
 
-                        if (assignmentPattern.Left is BindingPattern bp)
+                        if (assignmentPattern.Left is DestructuringPattern bp)
                         {
                             ProcessPatterns(context, bp, value, environment);
                             continue;
@@ -349,10 +349,10 @@ namespace Jint.Runtime.Interpreter.Expressions
 
                         AssignToIdentifier(context.Engine, target!.Name, value, environment, checkReference);
                     }
-                    else if (p.Value is BindingPattern bindingPattern)
+                    else if (p.Value is DestructuringPattern dp)
                     {
                         var value = source.Get(sourceKey);
-                        ProcessPatterns(context, bindingPattern, value, environment);
+                        ProcessPatterns(context, dp, value, environment);
                     }
                     else if (p.Value is MemberExpression memberExpression)
                     {
@@ -378,7 +378,7 @@ namespace Jint.Runtime.Interpreter.Expressions
                         source.CopyDataProperties(rest, processedProperties);
                         AssignToIdentifier(context.Engine, leftIdentifier.Name, rest, environment, checkReference);
                     }
-                    else if (restElement.Argument is BindingPattern bp)
+                    else if (restElement.Argument is DestructuringPattern bp)
                     {
                         ProcessPatterns(context, bp, argument, environment);
                     }

+ 2 - 2
Jint/Runtime/Interpreter/Expressions/JintAssignmentExpression.cs

@@ -29,9 +29,9 @@ namespace Jint.Runtime.Interpreter.Expressions
         {
             if (expression.Operator == Operator.Assign)
             {
-                if (expression.Left is BindingPattern)
+                if (expression.Left is DestructuringPattern)
                 {
-                    return new BindingPatternAssignmentExpression(expression);
+                    return new DestructuringPatternAssignmentExpression(expression);
                 }
 
                 return new SimpleAssignmentExpression(expression);

+ 7 - 7
Jint/Runtime/Interpreter/Expressions/JintLiteralExpression.cs

@@ -28,11 +28,11 @@ namespace Jint.Runtime.Interpreter.Expressions
         {
             switch (literal.TokenType)
             {
-                case TokenType.BooleanLiteral:
+                case TokenKind.BooleanLiteral:
                     return literal.BooleanValue!.Value ? JsBoolean.True : JsBoolean.False;
-                case TokenType.NullLiteral:
+                case TokenKind.NullLiteral:
                     return JsValue.Null;
-                case TokenType.NumericLiteral:
+                case TokenKind.NumericLiteral:
                     {
                         // unbox only once
                         var numericValue = (double) literal.Value!;
@@ -42,11 +42,11 @@ namespace Jint.Runtime.Interpreter.Expressions
                             ? JsNumber.Create(intValue)
                             : JsNumber.Create(numericValue);
                     }
-                case TokenType.StringLiteral:
+                case TokenKind.StringLiteral:
                     return JsString.Create((string) literal.Value!);
-                case TokenType.BigIntLiteral:
+                case TokenKind.BigIntLiteral:
                     return JsBigInt.Create((BigInteger) literal.Value!);
-                case TokenType.RegularExpression:
+                case TokenKind.RegularExpression:
                     break;
             }
 
@@ -65,7 +65,7 @@ namespace Jint.Runtime.Interpreter.Expressions
         private JsValue ResolveValue(EvaluationContext context)
         {
             var expression = (Literal) _expression;
-            if (expression.TokenType == TokenType.RegularExpression)
+            if (expression.TokenType == TokenKind.RegularExpression)
             {
                 var regExpLiteral = (RegExpLiteral) expression;
                 var regExpParseResult = regExpLiteral.ParseResult;

+ 6 - 6
Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs

@@ -19,7 +19,7 @@ namespace Jint.Runtime.Interpreter.Statements
 
         private ProbablyBlockStatement _body;
         private JintExpression? _expr;
-        private BindingPattern? _assignmentPattern;
+        private DestructuringPattern? _assignmentPattern;
         private JintExpression _right = null!;
         private List<Key>? _tdzNames;
         private bool _destructuring;
@@ -59,10 +59,10 @@ namespace Jint.Runtime.Interpreter.Statements
                     id.GetBoundNames(_tdzNames);
                 }
 
-                if (id is BindingPattern bindingPattern)
+                if (id is DestructuringPattern pattern)
                 {
                     _destructuring = true;
-                    _assignmentPattern = bindingPattern;
+                    _assignmentPattern = pattern;
                 }
                 else
                 {
@@ -70,10 +70,10 @@ namespace Jint.Runtime.Interpreter.Statements
                     _expr = new JintIdentifierExpression(identifier);
                 }
             }
-            else if (_leftNode is BindingPattern bindingPattern)
+            else if (_leftNode is DestructuringPattern pattern)
             {
                 _destructuring = true;
-                _assignmentPattern = bindingPattern;
+                _assignmentPattern = pattern;
             }
             else if (_leftNode is MemberExpression memberExpression)
             {
@@ -232,7 +232,7 @@ namespace Jint.Runtime.Interpreter.Statements
                     }
                     else
                     {
-                        nextValue = BindingPatternAssignmentExpression.ProcessPatterns(
+                        nextValue = DestructuringPatternAssignmentExpression.ProcessPatterns(
                             context,
                             _assignmentPattern!,
                             nextValue,

+ 6 - 6
Jint/Runtime/Interpreter/Statements/JintVariableDeclaration.cs

@@ -11,7 +11,7 @@ namespace Jint.Runtime.Interpreter.Statements
         private sealed class ResolvedDeclaration
         {
             internal JintExpression? Left;
-            internal BindingPattern? LeftPattern;
+            internal DestructuringPattern? LeftPattern;
             internal JintExpression? Init;
             internal JintIdentifierExpression? LeftIdentifierExpression;
             internal bool EvalOrArguments;
@@ -30,11 +30,11 @@ namespace Jint.Runtime.Interpreter.Statements
 
                 JintExpression? left = null;
                 JintExpression? init = null;
-                BindingPattern? bindingPattern = null;
+                DestructuringPattern? pattern = null;
 
-                if (declaration.Id is BindingPattern bp)
+                if (declaration.Id is DestructuringPattern bp)
                 {
-                    bindingPattern = bp;
+                    pattern = bp;
                 }
                 else
                 {
@@ -50,7 +50,7 @@ namespace Jint.Runtime.Interpreter.Statements
                 _declarations[i] = new ResolvedDeclaration
                 {
                     Left = left,
-                    LeftPattern = bindingPattern,
+                    LeftPattern = pattern,
                     LeftIdentifierExpression = leftIdentifier,
                     EvalOrArguments = leftIdentifier?.HasEvalOrArguments == true,
                     Init = init
@@ -89,7 +89,7 @@ namespace Jint.Runtime.Interpreter.Statements
 
                         var value = declaration.Init.GetValue(context);
 
-                        BindingPatternAssignmentExpression.ProcessPatterns(
+                        DestructuringPatternAssignmentExpression.ProcessPatterns(
                             context,
                             declaration.LeftPattern,
                             value,

+ 3 - 3
Jint/Runtime/Modules/ModuleBuilder.cs

@@ -130,13 +130,13 @@ public sealed class ModuleBuilder
             return new global::Esprima.Ast.Module(NodeList.Create(Array.Empty<Statement>()));
         }
 
-        var javaScriptParser = new JavaScriptParser(_options);
+        var parser = new Parser(_options);
         try
         {
             var source = _sourceRaw.Count == 1 ? _sourceRaw[0] : string.Join(Environment.NewLine, _sourceRaw);
-            return javaScriptParser.ParseModule(source, _specifier);
+            return parser.ParseModule(source, _specifier);
         }
-        catch (ParserException ex)
+        catch (ParseErrorException ex)
         {
             var location = SourceLocation.From(Position.From(ex.LineNumber, ex.Column), Position.From(ex.LineNumber, ex.Column), _specifier);
             ExceptionHelper.ThrowSyntaxError(_engine.Realm, $"Error while loading module: error in module '{_specifier}': {ex.Error}", location);

+ 3 - 3
Jint/Runtime/Modules/ModuleFactory.cs

@@ -17,7 +17,7 @@ public static class ModuleFactory
     /// <see cref="Uri.LocalPath"/> if <see cref="ResolvedSpecifier.Uri"/> is not null. If
     /// <see cref="ResolvedSpecifier.Uri"/> is null, the modules location source will be null as well.
     /// </remarks>
-    /// <exception cref="ParserException">Is thrown if the provided <paramref name="code"/> can not be parsed.</exception>
+    /// <exception cref="ParseErrorException">Is thrown if the provided <paramref name="code"/> can not be parsed.</exception>
     /// <exception cref="JavaScriptException">Is thrown if an error occured when parsing <paramref name="code"/>.</exception>
     public static Module BuildSourceTextModule(Engine engine, ResolvedSpecifier resolved, string code)
     {
@@ -25,9 +25,9 @@ public static class ModuleFactory
         Esprima.Ast.Module module;
         try
         {
-            module = new JavaScriptParser().ParseModule(code, source);
+            module = new Parser().ParseModule(code, source);
         }
-        catch (ParserException ex)
+        catch (ParseErrorException ex)
         {
             ExceptionHelper.ThrowSyntaxError(engine.Realm, $"Error while loading module: error in module '{source}': {ex.Error}");
             module = null;

+ 1 - 1
Jint/Runtime/TypeConverter.cs

@@ -587,7 +587,7 @@ namespace Jint.Runtime
         {
             if (!TryStringToBigInt(str, out var result))
             {
-                throw new ParserException(" Cannot convert " + str + " to a BigInt");
+                throw new ParseErrorException(" Cannot convert " + str + " to a BigInt");
             }
 
             return result;