Skip to content
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
1 change: 1 addition & 0 deletions ExtendedJavaScriptSubset.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{04AB
samples\typeresolving.js = samples\typeresolving.js
samples\vec2d.js = samples\vec2d.js
samples\cycled.js = samples\cycled.js
samples\scope.js = samples\scope.js
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Src", "Src", "{FB8F6EE1-1942-46D6-954E-9A1647BBDF10}"
Expand Down
10 changes: 10 additions & 0 deletions samples/scope.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type Obj = {
x: number;
}

let x: Obj
x = {
x: 1;
}

print(x.x as string)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using HydraScript.Domain.FrontEnd.Parser;
using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes;
using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Declarations.AfterTypesAreLoaded;
using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Expressions.ComplexLiterals;
using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Statements;
using HydraScript.Domain.IR.Impl;

Expand All @@ -9,7 +10,8 @@ namespace HydraScript.Application.StaticAnalysis.Visitors;
internal class SymbolTableInitializer : VisitorNoReturnBase<IAbstractSyntaxTreeNode>,
IVisitor<ScriptBody>,
IVisitor<FunctionDeclaration>,
IVisitor<BlockStatement>
IVisitor<BlockStatement>,
IVisitor<ObjectLiteral>
{
private readonly IStandardLibraryProvider _provider;
private readonly ISymbolTableStorage _symbolTables;
Expand Down Expand Up @@ -58,4 +60,13 @@ public VisitUnit Visit(BlockStatement visitable)
visitable[i].Accept(This);
return default;
}

public VisitUnit Visit(ObjectLiteral visitable)
{
visitable.InitScope(scope: new Scope());
_symbolTables.InitWithOpenScope(visitable.Scope);
for (var i = 0; i < visitable.Count; i++)
visitable[i].Accept(This);
return default;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,14 @@ public ObjectLiteral(IEnumerable<Property> properties)
_properties.ForEach(prop => prop.Parent = this);
}

/// <summary>Стратегия "блока" - углубление скоупа</summary>
/// <param name="scope">Новый скоуп</param>
public override void InitScope(Scope? scope = null)
{
ArgumentNullException.ThrowIfNull(scope);
Scope = scope;
Scope.AddOpenScope(Parent.Scope);
}

protected override string NodeRepresentation() => "{}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
<Link>Samples\recur.js</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\samples\scope.js">
<Link>Samples\scope.js</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\samples\searchinll.js">
<Link>Samples\searchinll.js</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void Invoke_NoError_ReturnCodeIsZero(string fileName)
"quicksort.js",
"range.js",
"recur.js",
"scope.js",
"searchinll.js",
"settable.js",
"squareroot.js",
Expand Down
Loading