Skip to content

Commit

Permalink
Fixed string conversion bug with global function
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasherceg committed Oct 16, 2023
1 parent 3c6ee78 commit 2a8200f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ JsExpression wrapInRound(JsExpression a) =>
}
else if (p[0].ParameterType == typeof(string) || p[0].ParameterType == typeof(bool))
{
AddMethodTranslator(m, translator: new GenericMethodCompiler(args => wrapInRound(new JsIdentifierExpression("Number").Invoke(args[1]))));
AddMethodTranslator(m, translator: new GenericMethodCompiler(args => wrapInRound(new JsIdentifierExpression("window").Member("Number").Invoke(args[1]))));
}
}

Expand All @@ -773,7 +773,7 @@ JsExpression wrapInRound(JsExpression a) =>
continue;
if (p[0].ParameterType.IsNumericType() && p[0].ParameterType != typeof(char))
{
AddMethodTranslator(m, translator: new GenericMethodCompiler(args => new JsIdentifierExpression("Boolean").Invoke(args[1])));
AddMethodTranslator(m, translator: new GenericMethodCompiler(args => new JsIdentifierExpression("window").Member("Boolean").Invoke(args[1])));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal static bool CanBeNull(Expression expr)
if (isNullable)
js = new JsBinaryExpression(js, BinaryOperatorType.NullishCoalescing, new JsLiteral(""));
if (!isStringAlready)
js = new JsIdentifierExpression("String").Invoke(js);
js = new JsIdentifierExpression("window").Member("String").Invoke(js);
return js;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Samples/Common/DotVVM.Samples.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<None Remove="Views\FeatureSamples\CustomPrimitiveTypes\RouteLink.dothtml" />
<None Remove="Views\FeatureSamples\CustomPrimitiveTypes\TextBox.dothtml" />
<None Remove="Views\FeatureSamples\CustomPrimitiveTypes\UsedInControls.dothtml" />
<None Remove="Views\FeatureSamples\Formatting\ToStringGlobalFunctionBug.dothtml" />
<None Remove="Views\FeatureSamples\HotReload\ViewChanges.dothtml" />
<None Remove="Views\FeatureSamples\JavascriptTranslation\ArrayTranslation.dothtml" />
<None Remove="Views\FeatureSamples\JavascriptTranslation\DateTimeTranslations.dothtml" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DotVVM.Framework.ViewModel;
using DotVVM.Framework.Hosting;

namespace DotVVM.Samples.Common.ViewModels.FeatureSamples.Formatting
{
public class ToStringGlobalFunctionBugViewModel : DotvvmViewModelBase
{
public bool Boolean { get; set; }

public string String { get; set; }
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@viewModel DotVVM.Samples.Common.ViewModels.FeatureSamples.Formatting.ToStringGlobalFunctionBugViewModel, DotVVM.Samples.Common

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<dot:Button Text="Set to true" Click="{staticCommand: Boolean = true}" />

<p class="result-boolean">Boolean: {{value: Boolean}}</p>
<p class="result-string">String: {{value: String}}</p>

</body>
</html>


Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion src/Samples/Tests/Tests/Feature/FormattingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,22 @@ public void Feature_Formatting_Formatting()
});
}

[Fact]
public void Feature_Formatting_ToStringGlobalFunctionBug()
{
RunInAllBrowsers(browser => {
browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_Formatting_ToStringGlobalFunctionBug);

AssertUI.TextEquals(browser.Single(".result-boolean"), "Boolean: false");
AssertUI.TextEquals(browser.Single(".result-string"), "String:");
browser.Single("input[type=button]").Click();
AssertUI.TextEquals(browser.Single(".result-boolean"), "Boolean: true");
AssertUI.TextEquals(browser.Single(".result-string"), "String:");
});
}

public FormattingTests(ITestOutputHelper output) : base(output)
{
}
}
}
}

0 comments on commit 2a8200f

Please sign in to comment.