diff --git a/src/DotVVM.Framework.Tests.Common/Binding/BindingCompilationTests.cs b/src/DotVVM.Framework.Tests.Common/Binding/BindingCompilationTests.cs
index 591522a6fc..3cb6d3536b 100755
--- a/src/DotVVM.Framework.Tests.Common/Binding/BindingCompilationTests.cs
+++ b/src/DotVVM.Framework.Tests.Common/Binding/BindingCompilationTests.cs
@@ -612,6 +612,24 @@ public void BindingCompiler_ComparisonOperators()
Assert.AreEqual(false, result);
}
+ [TestMethod]
+ public void BindingCompiler_Variables()
+ {
+ Assert.AreEqual(2, ExecuteBinding("var a = 1; a + 1"));
+ Assert.AreEqual(typeof(int), ExecuteBinding("var a = 1; a.GetType()"));
+
+ var result = ExecuteBinding("var a = 1; var b = a + LongProperty; var c = b + StringProp; c", new [] { new TestViewModel { LongProperty = 1, StringProp = "X" } });
+ Assert.AreEqual("2X", result);
+ }
+
+ [TestMethod]
+ public void BindingCompiler_VariableShadowing()
+ {
+ Assert.AreEqual(121L, ExecuteBinding("var LongProperty = LongProperty + 120; LongProperty", new TestViewModel { LongProperty = 1 }));
+ Assert.AreEqual(7, ExecuteBinding("var a = 1; var b = (var a = 5; a + 1); a + b"));
+ Assert.AreEqual(3, ExecuteBinding("var a = 1; var a = a + 1; var a = a + 1; a"));
+ }
+
[TestMethod]
public void BindingCompiler_Errors_AssigningToType()
{
diff --git a/src/DotVVM.Framework.Tests.Common/Binding/JavascriptCompilationTests.cs b/src/DotVVM.Framework.Tests.Common/Binding/JavascriptCompilationTests.cs
index e105e96a54..8956861017 100644
--- a/src/DotVVM.Framework.Tests.Common/Binding/JavascriptCompilationTests.cs
+++ b/src/DotVVM.Framework.Tests.Common/Binding/JavascriptCompilationTests.cs
@@ -425,6 +425,34 @@ public void StaticCommandCompilation_IndexParameterInParent()
Assert.AreEqual("$parentContext.$parentContext.$index()", result);
}
+ [TestMethod]
+ public void JavascriptCompilation_Variable()
+ {
+ var result = CompileBinding("var a = 1; var b = 2; var c = 3; a + b + c", typeof(TestViewModel));
+ Assert.AreEqual("function(a,b,c){a=1;b=2;c=3;return a+b+c;}()", result);
+ }
+
+ [TestMethod]
+ public void JavascriptCompilation_Variable_Nested()
+ {
+ var result = CompileBinding("var a = 1; var b = (var a = 5; a + 1); a + b", typeof(TestViewModel));
+ Assert.AreEqual("function(a0,b){a0=1;b=function(a){a=5;return a+1;}();return a0+b;}()", result);
+ }
+
+ [TestMethod]
+ public void JavascriptCompilation_Variable_Property()
+ {
+ var result = CompileBinding("var a = _this.StringProp; var b = _this.StringProp2; StringProp2 = a + b", typeof(TestViewModel));
+ Assert.AreEqual("function(a,b){a=StringProp();b=StringProp2();return StringProp2(a+b);}()", result);
+ }
+
+ [TestMethod]
+ public void JavascriptCompilation_Variable_VM()
+ {
+ var result = CompileBinding("var a = _parent; var b = _this.StringProp2; StringProp2 = a + b", new [] { typeof(string), typeof(TestViewModel) });
+ Assert.AreEqual("function(a,b){a=$parent;b=StringProp2();return StringProp2(a+b);}()", result);
+ }
+
[TestMethod]
public void JavascriptCompilation_AssignAndUse()
{
diff --git a/src/DotVVM.Framework.Tests.Common/Binding/StaticCommandCompilationTests.cs b/src/DotVVM.Framework.Tests.Common/Binding/StaticCommandCompilationTests.cs
index ce4f7e0cc9..42a000f72f 100644
--- a/src/DotVVM.Framework.Tests.Common/Binding/StaticCommandCompilationTests.cs
+++ b/src/DotVVM.Framework.Tests.Common/Binding/StaticCommandCompilationTests.cs
@@ -113,6 +113,13 @@ public void StaticCommandCompilation_ChainedCommands()
Assert.AreEqual("(function(a,b){return new Promise(function(resolve,reject){dotvvm.staticCommandPostback(a,\"WARNING/NOT/ENCRYPTED+++WyJEb3RWVk0uRnJhbWV3b3JrLlRlc3RzLkJpbmRpbmcuU3RhdGljQ29tbWFuZHMsIERvdFZWTS5GcmFtZXdvcmsuVGVzdHMuQ29tbW9uIiwiR2V0TGVuZ3RoIixbXSwiQUE9PSJd\",[b.$data.StringProp()],options).then(function(r_0){dotvvm.staticCommandPostback(a,\"WARNING/NOT/ENCRYPTED+++WyJEb3RWVk0uRnJhbWV3b3JrLlRlc3RzLkJpbmRpbmcuU3RhdGljQ29tbWFuZHMsIERvdFZWTS5GcmFtZXdvcmsuVGVzdHMuQ29tbW9uIiwiR2V0TGVuZ3RoIixbXSwiQUE9PSJd\",[dotvvm.globalize.bindingNumberToString(r_0)()],options).then(function(r_1){resolve(b.$data.StringProp(dotvvm.globalize.bindingNumberToString(r_1)()).StringProp());},reject);},reject);});}(this,ko.contextFor(this)))", result);
}
+ [TestMethod]
+ public void StaticCommandCompilation_MultipleCommandsWithVariable()
+ {
+ var result = CompileBinding("var lenVar = StaticCommands.GetLength(StringProp).ToString(); StringProp = StaticCommands.GetLength(lenVar).ToString();", niceMode: false, typeof(TestViewModel));
+ Assert.AreEqual("(function(a,d,b,c){return new Promise(function(resolve,reject){dotvvm.staticCommandPostback(a,\"WARNING/NOT/ENCRYPTED+++WyJEb3RWVk0uRnJhbWV3b3JrLlRlc3RzLkJpbmRpbmcuU3RhdGljQ29tbWFuZHMsIERvdFZWTS5GcmFtZXdvcmsuVGVzdHMuQ29tbW9uIiwiR2V0TGVuZ3RoIixbXSwiQUE9PSJd\",[d.$data.StringProp()],options).then(function(r_0){(c=b=dotvvm.globalize.bindingNumberToString(r_0)(),dotvvm.staticCommandPostback(a,\"WARNING/NOT/ENCRYPTED+++WyJEb3RWVk0uRnJhbWV3b3JrLlRlc3RzLkJpbmRpbmcuU3RhdGljQ29tbWFuZHMsIERvdFZWTS5GcmFtZXdvcmsuVGVzdHMuQ29tbW9uIiwiR2V0TGVuZ3RoIixbXSwiQUE9PSJd\",[b],options).then(function(r_1){resolve((c,d.$data.StringProp(dotvvm.globalize.bindingNumberToString(r_1)()).StringProp(),null));},reject));},reject);});}(this,ko.contextFor(this)))", result);
+ }
+
[TestMethod]
public void StaticCommandCompilation_ChainedCommandsWithSemicolon()
{
diff --git a/src/DotVVM.Framework.Tests.Common/ControlTests/testoutputs/ViewModulesServerSideTests.IncludeViewModule.html b/src/DotVVM.Framework.Tests.Common/ControlTests/testoutputs/ViewModulesServerSideTests.IncludeViewModule.html
index fcd1d7fa18..9a9065042f 100644
--- a/src/DotVVM.Framework.Tests.Common/ControlTests/testoutputs/ViewModulesServerSideTests.IncludeViewModule.html
+++ b/src/DotVVM.Framework.Tests.Common/ControlTests/testoutputs/ViewModulesServerSideTests.IncludeViewModule.html
@@ -39,6 +39,6 @@
],
"typeMetadata": {}
}">
-
+