Skip to content

Commit aca8fb3

Browse files
authored
Use global usings and aliases for Esprima namespaces and types (#1824)
* Use global usings for Esprima namespaces and Nodes * alias operators * add SourceLocation alias * cleanup Directory.Build.props
1 parent 23a2a25 commit aca8fb3

File tree

132 files changed

+304
-447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+304
-447
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,4 @@ BenchmarkDotNet.Artifacts*
165165

166166
# generated code
167167
Jint.Tests.Test262/Generated
168+
/artifacts

Diff for: Directory.Build.props

+30
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
11
<Project>
22

33
<PropertyGroup>
4+
5+
<Copyright>Sebastien Ros</Copyright>
6+
<Authors>Sebastien Ros</Authors>
7+
8+
<Description>Javascript interpreter for .NET.</Description>
9+
<PackageTags>javascript, interpreter, es5, es2015, es6, ecmascript, interop</PackageTags>
10+
<PackageProjectUrl>https://github.com/sebastienros/jint</PackageProjectUrl>
11+
<PackageLicenseExpression>BSD-2-Clause</PackageLicenseExpression>
12+
13+
<BuildNumber Condition="'$(BuildNumber)' == ''">0</BuildNumber>
14+
<VersionPrefix>3.0.1</VersionPrefix>
15+
<VersionSuffix>beta-$(BuildNumber)</VersionSuffix>
16+
<FileVersion>$(VersionPrefix).$(BuildNumber)</FileVersion>
17+
18+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
19+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
20+
<IncludeSymbols>true</IncludeSymbols>
21+
<DebugType>portable</DebugType>
22+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
23+
24+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
425
<UseArtifactsOutput>true</UseArtifactsOutput>
26+
527
</PropertyGroup>
628

29+
<ItemGroup>
30+
<Using Include="Esprima" />
31+
<Using Include="Esprima.Ast" />
32+
<Using Include="Esprima.Utils" />
33+
<Using Include="Esprima.Location" Alias="SourceLocation" />
34+
<Using Include="Esprima.Ast.Nodes" Alias="NodeType" />
35+
</ItemGroup>
36+
737
</Project>

Diff for: Jint.Benchmark/DromaeoBenchmark.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BenchmarkDotNet.Attributes;
2-
using Esprima.Ast;
32

43
namespace Jint.Benchmark;
54

Diff for: Jint.Benchmark/EngineComparisonBenchmark.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using BenchmarkDotNet.Attributes;
22
using BenchmarkDotNet.Configs;
33
using BenchmarkDotNet.Order;
4-
using Esprima;
5-
using Esprima.Ast;
64

75
namespace Jint.Benchmark;
86

Diff for: Jint.Benchmark/EngineConstructionBenchmark.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using BenchmarkDotNet.Attributes;
2-
using Esprima;
3-
using Esprima.Ast;
42
using Jint.Native;
53

64
namespace Jint.Benchmark;

Diff for: Jint.Benchmark/Jint.Benchmark.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
1111
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
1212
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
13+
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
14+
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
1315
<AssemblyOriginatorKeyFile>..\Jint\Jint.snk</AssemblyOriginatorKeyFile>
1416
<SignAssembly>true</SignAssembly>
1517
<LangVersion>latest</LangVersion>
@@ -29,4 +31,8 @@
2931
<PackageReference Include="NiL.JS" />
3032
<PackageReference Include="YantraJS.Core" />
3133
</ItemGroup>
34+
<ItemGroup>
35+
<Using Include="Esprima" />
36+
<Using Include="Esprima.Ast" />
37+
</ItemGroup>
3238
</Project>

Diff for: Jint.Benchmark/ObjectAccessBenchmark.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BenchmarkDotNet.Attributes;
2-
using Esprima.Ast;
32

43
namespace Jint.Benchmark;
54

Diff for: Jint.Benchmark/ShadowRealmBenchmark.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BenchmarkDotNet.Attributes;
2-
using Esprima.Ast;
32

43
namespace Jint.Benchmark;
54

Diff for: Jint.Benchmark/SingleScriptBenchmark.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BenchmarkDotNet.Attributes;
2-
using Esprima.Ast;
32

43
namespace Jint.Benchmark;
54

Diff for: Jint.Repl/Program.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Reflection;
2-
using Esprima;
32
using Jint;
43
using Jint.Native;
54
using Jint.Native.Json;

Diff for: Jint.Tests.CommonScripts/ConcurrencyTest.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using Esprima;
2-
31
namespace Jint.Tests.CommonScripts;
42

53
[Parallelizable(ParallelScope.Fixtures)]

Diff for: Jint.Tests.PublicInterface/ModuleLoaderTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using Jint.Native.Json;
44
using Jint.Runtime.Modules;
55

6+
using Module = Jint.Runtime.Modules.Module;
7+
68
#nullable enable
79

810
namespace Jint.Tests.PublicInterface;

Diff for: Jint.Tests.PublicInterface/RavenApiUsageTests.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Esprima.Ast;
21
using Jint.Constraints;
32
using Jint.Native;
43
using Jint.Native.Function;

Diff for: Jint.Tests.Test262/State.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using Esprima.Ast;
2-
31
namespace Jint.Tests.Test262;
42

53
/// <summary>

Diff for: Jint.Tests.Test262/Test262Test.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Esprima;
2-
using Jint.Native;
1+
using Jint.Native;
32
using Jint.Runtime;
43
using Jint.Runtime.Descriptors;
54
using Jint.Runtime.Interop;

Diff for: Jint.Tests/Parser/JavascriptParserTests.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Esprima;
2-
using Esprima.Ast;
3-
using Jint.Runtime;
1+
using Jint.Runtime;
42

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

1513
Assert.Single(body);
16-
Assert.Equal(Nodes.ThisExpression, body.First().As<ExpressionStatement>().Expression.Type);
14+
Assert.Equal(NodeType.ThisExpression, body.First().As<ExpressionStatement>().Expression.Type);
1715
}
1816

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

2523
Assert.Single(body);
26-
Assert.Equal(Nodes.Literal, body.First().As<ExpressionStatement>().Expression.Type);
24+
Assert.Equal(NodeType.Literal, body.First().As<ExpressionStatement>().Expression.Type);
2725
Assert.Equal(null, body.First().As<ExpressionStatement>().Expression.As<Literal>().Value);
2826
Assert.Equal("null", body.First().As<ExpressionStatement>().Expression.As<Literal>().Raw);
2927
}
@@ -38,7 +36,7 @@ public void ShouldParseNumeric()
3836
var body = program.Body;
3937

4038
Assert.Single(body);
41-
Assert.Equal(Nodes.Literal, body.First().As<ExpressionStatement>().Expression.Type);
39+
Assert.Equal(NodeType.Literal, body.First().As<ExpressionStatement>().Expression.Type);
4240
Assert.Equal(42d, body.First().As<ExpressionStatement>().Expression.As<Literal>().Value);
4341
Assert.Equal("42", body.First().As<ExpressionStatement>().Expression.As<Literal>().Raw);
4442
}

Diff for: Jint.Tests/Runtime/Debugger/CallStackTests.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Esprima;
2-
using Esprima.Ast;
3-
using Jint.Runtime.Debugger;
1+
using Jint.Runtime.Debugger;
42

53
namespace Jint.Tests.Runtime.Debugger
64
{

Diff for: Jint.Tests/Runtime/Debugger/EvaluateTests.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Esprima;
2-
using Jint.Native;
1+
using Jint.Native;
32
using Jint.Runtime;
43
using Jint.Runtime.Debugger;
54

Diff for: Jint.Tests/Runtime/Debugger/StepFlowTests.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Esprima;
2-
using Esprima.Ast;
3-
using Jint.Runtime.Debugger;
1+
using Jint.Runtime.Debugger;
42

53
namespace Jint.Tests.Runtime.Debugger
64
{
@@ -271,7 +269,7 @@ private List<string> StepIntoScript(string script)
271269
engine.Execute(script);
272270
return stepStatements;
273271

274-
void OutputPosition(Location location)
272+
void OutputPosition(in SourceLocation location)
275273
{
276274
var line = scriptLines[location.Start.Line - 1];
277275
var withPositionIndicator = string.Concat(line.Substring(0, location.Start.Column), "»", line.Substring(location.Start.Column));

Diff for: Jint.Tests/Runtime/Debugger/TestHelpers.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Esprima.Ast;
2-
using Jint.Runtime.Debugger;
1+
using Jint.Runtime.Debugger;
32

43
namespace Jint.Tests.Runtime.Debugger
54
{

Diff for: Jint.Tests/Runtime/EngineTests.ScriptPreparation.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Text.RegularExpressions;
2-
using Esprima.Ast;
32
using Jint.Native;
43
using Jint.Runtime.Interpreter;
54
using Jint.Runtime.Interpreter.Expressions;

Diff for: Jint.Tests/Runtime/EngineTests.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System.Globalization;
22
using System.Reflection;
3-
using Esprima;
4-
using Esprima.Ast;
53
using Jint.Native;
64
using Jint.Native.Array;
75
using Jint.Native.Number;

Diff for: Jint.Tests/Runtime/ErrorTests.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Reflection;
2-
using Esprima;
32
using Jint.Native;
43
using Jint.Runtime;
54
using Jint.Tests.Runtime.TestClasses;

Diff for: Jint.Tests/Runtime/ModuleTests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using Jint.Runtime;
33
using Jint.Runtime.Modules;
44

5+
using Module = Jint.Runtime.Modules.Module;
6+
57
namespace Jint.Tests.Runtime;
68

79
public class ModuleTests

Diff for: Jint/Directory.Build.props

-32
This file was deleted.

Diff for: Jint/Engine.Ast.cs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System.Runtime.InteropServices;
22
using System.Text.RegularExpressions;
3-
using Esprima;
4-
using Esprima.Ast;
53
using Jint.Native;
64
using Jint.Runtime;
75
using Jint.Runtime.Interpreter;
@@ -70,7 +68,7 @@ public void NodeVisitor(Node node)
7068
{
7169
switch (node.Type)
7270
{
73-
case Nodes.Identifier:
71+
case NodeType.Identifier:
7472
var identifier = (Identifier) node;
7573
var name = identifier.Name;
7674

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

85-
case Nodes.Literal:
83+
case NodeType.Literal:
8684
var literal = (Literal) node;
8785

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

115113
break;
116114

117-
case Nodes.MemberExpression:
115+
case NodeType.MemberExpression:
118116
node.AssociatedData = JintMemberExpression.InitializeDeterminedProperty((MemberExpression) node, cache: true);
119117
break;
120118

121-
case Nodes.ArrowFunctionExpression:
122-
case Nodes.FunctionDeclaration:
123-
case Nodes.FunctionExpression:
119+
case NodeType.ArrowFunctionExpression:
120+
case NodeType.FunctionDeclaration:
121+
case NodeType.FunctionExpression:
124122
var function = (IFunction) node;
125123
node.AssociatedData = JintFunctionDefinition.BuildState(function);
126124
break;
127125

128-
case Nodes.Program:
126+
case NodeType.Program:
129127
node.AssociatedData = new CachedHoistingScope((Program) node);
130128
break;
131129

132-
case Nodes.UnaryExpression:
130+
case NodeType.UnaryExpression:
133131
node.AssociatedData = JintUnaryExpression.BuildConstantExpression((UnaryExpression) node);
134132
break;
135133

136-
case Nodes.BinaryExpression:
134+
case NodeType.BinaryExpression:
137135
var binaryExpression = (BinaryExpression) node;
138136
if (_options.FoldConstants
139137
&& binaryExpression.Operator != BinaryOperator.InstanceOf
@@ -161,7 +159,7 @@ public void NodeVisitor(Node node)
161159

162160
break;
163161

164-
case Nodes.ReturnStatement:
162+
case NodeType.ReturnStatement:
165163
var returnStatement = (ReturnStatement) node;
166164
if (returnStatement.Argument is Literal returnedLiteral)
167165
{

Diff for: Jint/Engine.Modules.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using Esprima;
2-
using Jint.Native;
1+
using Jint.Native;
32
using Jint.Native.Object;
43
using Jint.Native.Promise;
54
using Jint.Runtime;
65
using Jint.Runtime.Interpreter;
76
using Jint.Runtime.Modules;
7+
using Module = Jint.Runtime.Modules.Module;
88

99
namespace Jint;
1010

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

177177
var node = EsprimaExtensions.CreateLocationNode(location);
178178
ExceptionHelper.ThrowJavaScriptException(_engine, promise.Value, node.Location);

Diff for: Jint/Engine.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System.Diagnostics;
22
using System.Diagnostics.CodeAnalysis;
33
using System.Runtime.CompilerServices;
4-
using Esprima;
5-
using Esprima.Ast;
64
using Jint.Native;
75
using Jint.Native.Function;
86
using Jint.Native.Generator;
@@ -531,7 +529,7 @@ internal void RunBeforeExecuteStatementChecks(StatementListItem? statement)
531529
constraint.Check();
532530
}
533531

534-
if (_isDebugMode && statement != null && statement.Type != Nodes.BlockStatement)
532+
if (_isDebugMode && statement != null && statement.Type != NodeType.BlockStatement)
535533
{
536534
Debugger.OnStep(statement);
537535
}

0 commit comments

Comments
 (0)