Skip to content

Commit 5333a54

Browse files
committed
fixed in expression
1 parent 56c362f commit 5333a54

6 files changed

Lines changed: 54 additions & 32 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,4 @@ MigrationBackup/
356356
/Test/Test.csproj
357357
/YantraJS.Network/Generated
358358
/YantraJS.Core/Generated
359+
.idea

YantraJS.Core.Tests/Imported/StatementTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace YantraJS.Core.Tests.Imported
1010
/// <summary>
1111
/// Language statement tests.
1212
/// </summary>
13-
//[TestClass]
13+
// [TestClass]
1414
public class StatementTests : TestBase
1515
{
1616
[TestMethod]
@@ -99,6 +99,14 @@ function test() {
9999
test();
100100
}());
101101
}");
102+
103+
Execute(@"
104+
var a;
105+
var b = { a: 1 };
106+
for(a in b) {
107+
console.log(a);
108+
}
109+
");
102110
}
103111

104112
[TestMethod]

YantraJS.Core.Tests/YantraJS.Core.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<IsTestProject>true</IsTestProject>
77
</PropertyGroup>

YantraJS.Core/FastParser/Parser/FastParser.ForStatement.cs

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,35 +83,48 @@ bool ForStatement(out AstStatement node)
8383
AstExpression? ofTarget = null;
8484
AstExpression? test = null;
8585
AstExpression? update = null;
86-
87-
if (stream.CheckAndConsume(TokenTypes.In))
86+
87+
// we need to check if beginNode contains `in` expression
88+
// as `a in b` is a valid single expression
89+
if (beginNode is AstBinaryExpression b
90+
&& b.Operator == TokenTypes.In
91+
&& stream.CheckAndConsume(TokenTypes.BracketEnd))
8892
{
8993
@in = true;
90-
if (!Expression(out inTarget))
91-
throw stream.Unexpected();
92-
stream.Expect(TokenTypes.BracketEnd);
93-
}
94-
else if (stream.CheckAndConsumeContextualKeyword(FastKeywords.of))
95-
{
96-
of = true;
97-
if (!Expression(out ofTarget))
98-
throw stream.Unexpected();
99-
stream.Expect(TokenTypes.BracketEnd);
94+
beginNode = b.Left;
95+
inTarget = b.Right;
10096
}
101-
else if (ExpressionSequence(out test, TokenTypes.SemiColon, true))
97+
else
10298
{
103-
// case of automatic semicolon insertion
104-
if (test.End.Type == TokenTypes.BracketEnd)
105-
throw stream.Unexpected();
106-
if (test.Type == FastNodeType.EmptyExpression)
107-
test = null;
108-
if (!ExpressionSequence(out update, TokenTypes.BracketEnd, true))
109-
throw stream.Unexpected();
110-
if (update.Type == FastNodeType.EmptyExpression)
111-
update = null;
112-
}
113-
else stream.Unexpected();
11499

100+
if (stream.CheckAndConsume(TokenTypes.In))
101+
{
102+
@in = true;
103+
if (!Expression(out inTarget))
104+
throw stream.Unexpected();
105+
stream.Expect(TokenTypes.BracketEnd);
106+
}
107+
else if (stream.CheckAndConsumeContextualKeyword(FastKeywords.of))
108+
{
109+
of = true;
110+
if (!Expression(out ofTarget))
111+
throw stream.Unexpected();
112+
stream.Expect(TokenTypes.BracketEnd);
113+
}
114+
else if (ExpressionSequence(out test, TokenTypes.SemiColon, true))
115+
{
116+
// case of automatic semicolon insertion
117+
if (test.End.Type == TokenTypes.BracketEnd)
118+
throw stream.Unexpected();
119+
if (test.Type == FastNodeType.EmptyExpression)
120+
test = null;
121+
if (!ExpressionSequence(out update, TokenTypes.BracketEnd, true))
122+
throw stream.Unexpected();
123+
if (update.Type == FastNodeType.EmptyExpression)
124+
update = null;
125+
}
126+
else stream.Unexpected();
127+
}
115128

116129
AstStatement statement;
117130
if (stream.CheckAndConsume(TokenTypes.CurlyBracketStart))

YantraJS/Properties/launchSettings.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
"profiles": {
33
"Yantra TypeScript": {
44
"commandName": "Project",
5-
"commandLineArgs": "..\\..\\..\\..\\YantraTests\\Modules\\ts\\index.js"
5+
"commandLineArgs": "../../../../YantraTests/Modules/ts/index.js"
66
},
77
"Yantra Box2d": {
88
"commandName": "Project",
9-
"commandLineArgs": "..\\..\\..\\..\\YantraTests\\Modules\\box2d\\index.js"
9+
"commandLineArgs": "../../../../YantraTests/Modules/box2d/index.js"
1010
},
1111
"Yantra CodeLoad": {
1212
"commandName": "Project",
13-
"commandLineArgs": "..\\..\\..\\..\\YantraTests\\Modules\\code-load\\code-loade.js"
13+
"commandLineArgs": "../../../../YantraTests/Modules/code-load/index.js"
1414
},
1515
"Yantra XF-Samples": {
1616
"commandName": "Project",
17-
"commandLineArgs": "..\\..\\..\\..\\YantraJS.Core.Tests\\Generator\\Files\\es5\\Index\\Index.pack.js"
17+
"commandLineArgs": "../../../../YantraJS.Core.Tests/Generator/Files/es5/Index/Index.pack.js"
1818
},
1919
"Yantra REPL": {
2020
"commandName": "Project",
@@ -26,7 +26,7 @@
2626
},
2727
"Yantra File": {
2828
"commandName": "Project",
29-
"commandLineArgs": "D:\\git\\github\\yantrajs\\yantra\\YantraJS.Core.Tests\\Generator\\Files\\es6\\Syntax\\linq\\linqjs.js"
29+
"commandLineArgs": "D:/git/github/yantrajs/yantra/YantraJS.Core.Tests/Generator/Files/es6/Syntax/linq/linqjs.js"
3030
}
3131
}
3232
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import "./code-load.js";
1+
import * as a1 from "./code-load.js";

0 commit comments

Comments
 (0)