scriptsharp icon indicating copy to clipboard operation
scriptsharp copied to clipboard

Logic Bug - 0.8

Open andrewharry opened this issue 12 years ago • 2 comments

The following piece of ScriptSharp code is getting translated into javascript which doesn't retain the correct logic:

//C# code SyncData sync = (!Script.IsUndefined(GlobalVariables.SyncData)) ? GlobalVariables.SyncData : null;

//Javascript var sync = (!window.SyncData === undefined) ? window.SyncData : null;

Even when GlobalVariables.SyncData is a valid object the above code assigns null.

Where as if the ! is moved outside brackets the correct logic is given:

//C# code SyncData sync = !(Script.IsUndefined(GlobalVariables.SyncData)) ? GlobalVariables.SyncData : null;

//Javascript var sync = (!(window.SyncData === undefined)) ? window.SyncData : null;

andrewharry avatar Oct 08 '12 06:10 andrewharry

Looks like a good catch - a missing case of parentheses needed scenario. Will get to it.

Meanwhile, I'd actually recommend using this:

SyncData sync = Script.Value<SyncData>(GlobalVariables.SyncData, null);

It should generate:

var sync = window.SyncData || null;

nikhilk avatar Oct 08 '12 06:10 nikhilk

Fix is in ... will include in next preview build.

nikhilk avatar Oct 08 '12 07:10 nikhilk