Skip to content

Commit

Permalink
Use global usings and aliases for Esprima namespaces and types (#1824)
Browse files Browse the repository at this point in the history
* Use global usings for Esprima namespaces and Nodes
* alias operators
* add SourceLocation alias
* cleanup Directory.Build.props
  • Loading branch information
lahma authored Mar 31, 2024
1 parent 23a2a25 commit aca8fb3
Show file tree
Hide file tree
Showing 132 changed files with 304 additions and 447 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,4 @@ BenchmarkDotNet.Artifacts*

# generated code
Jint.Tests.Test262/Generated
/artifacts
30 changes: 30 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
<Project>

<PropertyGroup>

<Copyright>Sebastien Ros</Copyright>
<Authors>Sebastien Ros</Authors>

<Description>Javascript interpreter for .NET.</Description>
<PackageTags>javascript, interpreter, es5, es2015, es6, ecmascript, interop</PackageTags>
<PackageProjectUrl>https://github.com/sebastienros/jint</PackageProjectUrl>
<PackageLicenseExpression>BSD-2-Clause</PackageLicenseExpression>

<BuildNumber Condition="'$(BuildNumber)' == ''">0</BuildNumber>
<VersionPrefix>3.0.1</VersionPrefix>
<VersionSuffix>beta-$(BuildNumber)</VersionSuffix>
<FileVersion>$(VersionPrefix).$(BuildNumber)</FileVersion>

<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<DebugType>portable</DebugType>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseArtifactsOutput>true</UseArtifactsOutput>

</PropertyGroup>

<ItemGroup>
<Using Include="Esprima" />
<Using Include="Esprima.Ast" />
<Using Include="Esprima.Utils" />
<Using Include="Esprima.Location" Alias="SourceLocation" />
<Using Include="Esprima.Ast.Nodes" Alias="NodeType" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion Jint.Benchmark/DromaeoBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BenchmarkDotNet.Attributes;
using Esprima.Ast;

namespace Jint.Benchmark;

Expand Down
2 changes: 0 additions & 2 deletions Jint.Benchmark/EngineComparisonBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Order;
using Esprima;
using Esprima.Ast;

namespace Jint.Benchmark;

Expand Down
2 changes: 0 additions & 2 deletions Jint.Benchmark/EngineConstructionBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using BenchmarkDotNet.Attributes;
using Esprima;
using Esprima.Ast;
using Jint.Native;

namespace Jint.Benchmark;
Expand Down
6 changes: 6 additions & 0 deletions Jint.Benchmark/Jint.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<AssemblyOriginatorKeyFile>..\Jint\Jint.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<LangVersion>latest</LangVersion>
Expand All @@ -29,4 +31,8 @@
<PackageReference Include="NiL.JS" />
<PackageReference Include="YantraJS.Core" />
</ItemGroup>
<ItemGroup>
<Using Include="Esprima" />
<Using Include="Esprima.Ast" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion Jint.Benchmark/ObjectAccessBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BenchmarkDotNet.Attributes;
using Esprima.Ast;

namespace Jint.Benchmark;

Expand Down
1 change: 0 additions & 1 deletion Jint.Benchmark/ShadowRealmBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BenchmarkDotNet.Attributes;
using Esprima.Ast;

namespace Jint.Benchmark;

Expand Down
1 change: 0 additions & 1 deletion Jint.Benchmark/SingleScriptBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BenchmarkDotNet.Attributes;
using Esprima.Ast;

namespace Jint.Benchmark;

Expand Down
1 change: 0 additions & 1 deletion Jint.Repl/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using Esprima;
using Jint;
using Jint.Native;
using Jint.Native.Json;
Expand Down
2 changes: 0 additions & 2 deletions Jint.Tests.CommonScripts/ConcurrencyTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Esprima;

namespace Jint.Tests.CommonScripts;

[Parallelizable(ParallelScope.Fixtures)]
Expand Down
2 changes: 2 additions & 0 deletions Jint.Tests.PublicInterface/ModuleLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Jint.Native.Json;
using Jint.Runtime.Modules;

using Module = Jint.Runtime.Modules.Module;

#nullable enable

namespace Jint.Tests.PublicInterface;
Expand Down
1 change: 0 additions & 1 deletion Jint.Tests.PublicInterface/RavenApiUsageTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Esprima.Ast;
using Jint.Constraints;
using Jint.Native;
using Jint.Native.Function;
Expand Down
2 changes: 0 additions & 2 deletions Jint.Tests.Test262/State.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Esprima.Ast;

namespace Jint.Tests.Test262;

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions Jint.Tests.Test262/Test262Test.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Esprima;
using Jint.Native;
using Jint.Native;
using Jint.Runtime;
using Jint.Runtime.Descriptors;
using Jint.Runtime.Interop;
Expand Down
10 changes: 4 additions & 6 deletions Jint.Tests/Parser/JavascriptParserTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Esprima;
using Esprima.Ast;
using Jint.Runtime;
using Jint.Runtime;

namespace Jint.Tests.Parser
{
Expand All @@ -13,7 +11,7 @@ public void ShouldParseThis()
var body = program.Body;

Assert.Single(body);
Assert.Equal(Nodes.ThisExpression, body.First().As<ExpressionStatement>().Expression.Type);
Assert.Equal(NodeType.ThisExpression, body.First().As<ExpressionStatement>().Expression.Type);
}

[Fact]
Expand All @@ -23,7 +21,7 @@ public void ShouldParseNull()
var body = program.Body;

Assert.Single(body);
Assert.Equal(Nodes.Literal, body.First().As<ExpressionStatement>().Expression.Type);
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);
}
Expand All @@ -38,7 +36,7 @@ public void ShouldParseNumeric()
var body = program.Body;

Assert.Single(body);
Assert.Equal(Nodes.Literal, body.First().As<ExpressionStatement>().Expression.Type);
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);
}
Expand Down
4 changes: 1 addition & 3 deletions Jint.Tests/Runtime/Debugger/CallStackTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Esprima;
using Esprima.Ast;
using Jint.Runtime.Debugger;
using Jint.Runtime.Debugger;

namespace Jint.Tests.Runtime.Debugger
{
Expand Down
3 changes: 1 addition & 2 deletions Jint.Tests/Runtime/Debugger/EvaluateTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Esprima;
using Jint.Native;
using Jint.Native;
using Jint.Runtime;
using Jint.Runtime.Debugger;

Expand Down
6 changes: 2 additions & 4 deletions Jint.Tests/Runtime/Debugger/StepFlowTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Esprima;
using Esprima.Ast;
using Jint.Runtime.Debugger;
using Jint.Runtime.Debugger;

namespace Jint.Tests.Runtime.Debugger
{
Expand Down Expand Up @@ -271,7 +269,7 @@ private List<string> StepIntoScript(string script)
engine.Execute(script);
return stepStatements;

void OutputPosition(Location location)
void OutputPosition(in SourceLocation location)
{
var line = scriptLines[location.Start.Line - 1];
var withPositionIndicator = string.Concat(line.Substring(0, location.Start.Column), "»", line.Substring(location.Start.Column));
Expand Down
3 changes: 1 addition & 2 deletions Jint.Tests/Runtime/Debugger/TestHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Esprima.Ast;
using Jint.Runtime.Debugger;
using Jint.Runtime.Debugger;

namespace Jint.Tests.Runtime.Debugger
{
Expand Down
1 change: 0 additions & 1 deletion Jint.Tests/Runtime/EngineTests.ScriptPreparation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text.RegularExpressions;
using Esprima.Ast;
using Jint.Native;
using Jint.Runtime.Interpreter;
using Jint.Runtime.Interpreter.Expressions;
Expand Down
2 changes: 0 additions & 2 deletions Jint.Tests/Runtime/EngineTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Globalization;
using System.Reflection;
using Esprima;
using Esprima.Ast;
using Jint.Native;
using Jint.Native.Array;
using Jint.Native.Number;
Expand Down
1 change: 0 additions & 1 deletion Jint.Tests/Runtime/ErrorTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using Esprima;
using Jint.Native;
using Jint.Runtime;
using Jint.Tests.Runtime.TestClasses;
Expand Down
2 changes: 2 additions & 0 deletions Jint.Tests/Runtime/ModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Jint.Runtime;
using Jint.Runtime.Modules;

using Module = Jint.Runtime.Modules.Module;

namespace Jint.Tests.Runtime;

public class ModuleTests
Expand Down
32 changes: 0 additions & 32 deletions Jint/Directory.Build.props

This file was deleted.

22 changes: 10 additions & 12 deletions Jint/Engine.Ast.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using Esprima;
using Esprima.Ast;
using Jint.Native;
using Jint.Runtime;
using Jint.Runtime.Interpreter;
Expand Down Expand Up @@ -70,7 +68,7 @@ public void NodeVisitor(Node node)
{
switch (node.Type)
{
case Nodes.Identifier:
case NodeType.Identifier:
var identifier = (Identifier) node;
var name = identifier.Name;

Expand All @@ -82,7 +80,7 @@ public void NodeVisitor(Node node)
node.AssociatedData = new JintIdentifierExpression(identifier, bindingName);
break;

case Nodes.Literal:
case NodeType.Literal:
var literal = (Literal) node;

var constantValue = JintLiteralExpression.ConvertToJsValue(literal);
Expand Down Expand Up @@ -114,26 +112,26 @@ public void NodeVisitor(Node node)

break;

case Nodes.MemberExpression:
case NodeType.MemberExpression:
node.AssociatedData = JintMemberExpression.InitializeDeterminedProperty((MemberExpression) node, cache: true);
break;

case Nodes.ArrowFunctionExpression:
case Nodes.FunctionDeclaration:
case Nodes.FunctionExpression:
case NodeType.ArrowFunctionExpression:
case NodeType.FunctionDeclaration:
case NodeType.FunctionExpression:
var function = (IFunction) node;
node.AssociatedData = JintFunctionDefinition.BuildState(function);
break;

case Nodes.Program:
case NodeType.Program:
node.AssociatedData = new CachedHoistingScope((Program) node);
break;

case Nodes.UnaryExpression:
case NodeType.UnaryExpression:
node.AssociatedData = JintUnaryExpression.BuildConstantExpression((UnaryExpression) node);
break;

case Nodes.BinaryExpression:
case NodeType.BinaryExpression:
var binaryExpression = (BinaryExpression) node;
if (_options.FoldConstants
&& binaryExpression.Operator != BinaryOperator.InstanceOf
Expand Down Expand Up @@ -161,7 +159,7 @@ public void NodeVisitor(Node node)

break;

case Nodes.ReturnStatement:
case NodeType.ReturnStatement:
var returnStatement = (ReturnStatement) node;
if (returnStatement.Argument is Literal returnedLiteral)
{
Expand Down
6 changes: 3 additions & 3 deletions Jint/Engine.Modules.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Esprima;
using Jint.Native;
using Jint.Native;
using Jint.Native.Object;
using Jint.Native.Promise;
using Jint.Runtime;
using Jint.Runtime.Interpreter;
using Jint.Runtime.Modules;
using Module = Jint.Runtime.Modules.Module;

namespace Jint;

Expand Down Expand Up @@ -172,7 +172,7 @@ private JsValue EvaluateModule(string specifier, Module module)
{
var location = module is CyclicModule cyclicModuleRecord
? cyclicModuleRecord.AbnormalCompletionLocation
: Location.From(new Position(), new Position());
: SourceLocation.From(new Position(), new Position());

var node = EsprimaExtensions.CreateLocationNode(location);
ExceptionHelper.ThrowJavaScriptException(_engine, promise.Value, node.Location);
Expand Down
4 changes: 1 addition & 3 deletions Jint/Engine.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Esprima;
using Esprima.Ast;
using Jint.Native;
using Jint.Native.Function;
using Jint.Native.Generator;
Expand Down Expand Up @@ -531,7 +529,7 @@ internal void RunBeforeExecuteStatementChecks(StatementListItem? statement)
constraint.Check();
}

if (_isDebugMode && statement != null && statement.Type != Nodes.BlockStatement)
if (_isDebugMode && statement != null && statement.Type != NodeType.BlockStatement)
{
Debugger.OnStep(statement);
}
Expand Down
Loading

0 comments on commit aca8fb3

Please sign in to comment.