derivcoipswich / dsharp Goto Github PK
View Code? Open in Web Editor NEWThis project forked from nikhilk/scriptsharp
A fork of the Script# project.
Home Page: http://www.derivco.co.uk
License: Other
This project forked from nikhilk/scriptsharp
A fork of the Script# project.
Home Page: http://www.derivco.co.uk
License: Other
Support for VS2015 is required to ensure the latest tooling can be used with DSharp. Features like Static CodeAnalysis can be utilised once this is complete.
Support for
void CopyTo(T[] array, int arrayIndex)
since the CLR version requires you to implement it. Also part of Array
, etc
When comparing Date objects which are constructed the same, we are returned with false.
var date1 = new Date(1);
var date2 = new Date(1);
date1 === date2 //returns false
date1 == date2 //returns false
date1.valueOf() == date2.valueOf() //returns true
The same occurs for RegExp
, however value of comparisons fail and only the toString
method returns true.
Basic methods are required in the core script to compare these reference types
When the ss.js has been minified it is missing a semicolon from the end of the file. This only occurs when the minified script is inlined with another.
Currently when deriving from Exception a new type is created. This type however lacks some critical information like stack traces and line information. Deriving from Exception should create a real stack trace and use the correct construction:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
All system primitives are missing type information about if a value is of type Int32 or Int64 etc.
It would be ideal to use a property initialiser with a constructor like so:
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string GetFullName()
{
return FirstName + " " + LastName;
}
}
//usage
new Person
{
FirstName = "Fred",
LastName = "Perkins"
}
This could be achieved like the following:
function Person(firstName, lastName){
this.firstName = firstName || "";
this.lastName = lastName || "";
}
Person.prototype.GetFullName = function(){
return this.firstName + " " + this.lastName;
}
function initialiseProperties(object, properties){
if(!object || !properties){
return object;
}
for(var key in properties){
Object.defineProperty(object, key, { value: properties[key]});
}
return object;
}
whereby you could call the following:
initialiseProperties(new Person(), { firstName: "Fred", lastName: "Perkins"});
which would return a new object with those properties initialised correctly.
It would be ideal to add a new script template attribute which can be applied to any emit-able code. The purpose of this is so that you can easily define a method call or variable easily within the context of a specific scope.
You should be able to use the 'this' reference appropriately to pass itself into method calls.
An example of how this could look:
[ScriptTemplate("ss.localMethod({this}, {value})"]
public void LocalMethod(string value)
{
}
this could then be called like the following and emitted correctly:
someObject.LocalMethod("asdasd");
Emits to
ss.localMethod(someObject, "asdasd");
We tried to use this to format currency amounts as part of culture support, but it didn't work. So we had to work around and format as number and then replace decimal symbols by currency symbols. It is mostly an issue with cultures as Swedish (sv) where the decimal group separator differs for currency.
Cheers,
Currently DSharp doesn't support being able to create a fixed string of characters. E.g:
int len = 4;
string enumeration = new string(len, 'c'); //enumeration = "cccc"
In JavaScript a simple way would be to create an array of empty elements and iterate over the length to create a string of those fixed characters:
var len = 4;
var enumeration = new Array(len + 1).join('c'); //returns "cccc"
Or the new ES6 String repeat could be used with a shim
To achieve this we could take an array of available constructors and resolve the function calls based on symbol map with unique names. Each constructor would have the same type metadata attached.
The default keyword can be used outside of a generic context, whereby it will try to return the default value of a value or reference type. Default will also need to support the generics feature as in .Net
Currently the Dictionary & Dictionary<T,T> is sealed by the core library.
Exposing this for inheritance would mean we can wrap POCO style objects.
For example
public class PocoType : Dictionary<string, object>
{
public string GetProp(string key)
{
//Code here
}
}
This would allow aliasing of objects with needing to a using statement - For example with known models.
Need to remove the ToStringLocale as this is non standard.
Add default hashcode method to all defined classes programmatically and allow overrides to return a uint value using a built in hashing mechanism
We are missing objects like TimeSpan
, DateTime
and DateTimeOffset
This helps a lot and only requires tweaking some interfaces a bit
Negative numbers are returned as positive if they're smaller than the group size (not requiring commas)
Implement TPL style tasking library to create microtasks within ScriptSharp.
The tasking framework should support breaking code into blocks to execute in separate chunks. This means we could perform long running operations over time or on another Thread( Web Worker in JS).
To properly support IEnumerable we need a set of basic extension methods which allow us to ToArray, ToList or ToDictionary. This would lead the way to utilize LINQ queries in the future.
Both interfaces are used throughout C# to provide objects with equality checks.
Adding these will mean we can introduce comparers and equality comparers into the framework.
int[] integersSource = { 1, 2, 3 };
List listOfIntegers = new List(integersSource);
listOfIntegers.Add(4);
is producing:
(2) [Array(3),4]
0: (3) [1,2,3]
1: 4
while expected is:
(4) [1,2,3,4]
Currently yield return as an IEnumerable statement causes a csc error in the base compiler:
"csc.exe" exited with code -2146232797.
@ C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets. Line 84
This happens with the following code:
public IEnumerable<object[]> Data
{
get
{
yield return new object[] { 1, 2, 3 };
yield return new object[] { 4, 5, 6 };
}
}
CultureInfo is currently quite rigid and doesn't allow us to create cultures at runtime. It should be possible to download a culture file with the core script which allows us to create a culture based on its ISO code.
Also add Serialiser contracts or objects which understand how to create the culture object expected by dsharp
Is there a reason for these empty string in month name arrays in Culture.js? Drop them if not please.
When used in a class constructor the CanvasContext2D object in the script.web module will raise a js error as the generated javascript tries to use the built in class. It seems the correct name for this object is CanvasRenderingContext2D as per
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D.
casting with the as keyword may also cause the same issue
This is making the CLR fail when using List<T>.Contains(...)
We need to switch from
List<T>.Contains(object item)
to
List<T>.Contains(T item)
This is needed to avoid errors like System.MissingMethodException : Method not found: 'Boolean System.Collections.Generic.List``1.Contains(System.Object)'
The ss.Queue implementation seems to not be cleaning up the items as soon as you a .dequeue
It seems to only clean up when we reach half of the available items.
Ie:
10 items it will do 4 clean ups
The below snippet shows this issue:
`var queue = new ss.Queue();
queue.enqueue("1");
queue.enqueue("2");
queue.enqueue("3");
queue.enqueue("4");
queue.enqueue("5");
queue.enqueue("6");
queue.enqueue("7");
queue.enqueue("8");
queue.enqueue("9");
queue.enqueue("10");
for(i=0, ln = queue.count; i<ln;i++)
{
(function(num){
window.setTimeout(function(){
console.log(queue.dequeue(););
console.log(queue._items);
}, 10 * i);
})(i);
}`
To be noted that this is a mere internal issue. The items are returned in dequeue are correct.
Currently, enumerate(...)
is slow due to the local lookup
function.
This can be optimized by applying single responsibility principle: DictionaryEnumerator
and ArrayEnumerator
. With this structure, enumerate(...)
will instantiate an optimized enumerator for each case.
AMD loader was dropped, resulting on many tests failing. We need to fix all of them again.
$global
regex to replace
replace with
in files
define\('test', \['ss'\], function\(ss\) \{[\s\n\r]*var \$global = this;[\n]*
var test = (function($global){\n
**/*Baseline*.txt
\}\);[\r\n]*$(?![\n])
})(self);\n
**/*Baseline*.txt
Look into a flexible system which could be used to generate the required polyfills for DSharp depending on the browser targets specified by the project consuming DSharp. This means you could include specific polyfills for specific browsers through a piece of JSON configuration:
{
IE: "<10.0+[9.4.1]",
Chrome: "<38"
}
The string could be an expression compiled by the process which defines simply a range of browser versions with the ability to be generic and add specific overrides.
The compiler would then create the correct Polyfill.js and combine with the ss.js output
All types should allow operator overloading so that casting between types can allow us to call the overloaded operator method.
This could generate exactly like static methods.
Should transpile to window.history.scrollRestoration but transpiles to History.ScrollRestoration which is not defined
Add a default hashing mechanism so that objects can be used as keys within a dictionary. Doing so would allow you to get the hash code value and turn it into an sting to utilise a browsers built in hashing mechanism. Dictionaries from here on in would automatically call the getHashCode mechanism when trying to store the key in the dictionary.
Compile Enums into a key value pair which is easy to use. The could would output the enum property call which returns a value. For example the following:
DSharp.defineEnum("System", "SomeEnum": {
Value1: 1,
Value2: 2
});
Then we should be able to do the following:
var enumValue = System.SomeEnum.Value1;
The core library should expose the same core static methods to resolve type names and values from strings.
The commit from https://github.com/DerivcoIpswich/dsharp/pull/17/files is missing a ScriptName from the type in the corelib.
Adding support for Generics can be achieved by treating the token "T" or any generic type as the intrinsic type within the compiler.
Support should be added for both Contravariance and Covariance.
The RequestIdleCallback function accepts an optional timeout parameter to specify a deadline for maximum wait period before getting a callback. This is not reflected in the interface implemented by dsharp
For example:
public class CancellationTokenSource
{
private static CancellationTokenSource source;
private int cancellationState;
static CancellationTokenSource()
{
source = new CancellationTokenSource();
source.cancellationState = 1;
}
}
When attempting to call the following a not supported exception is thrown.
The issue boils down to being unable to get the scope of the static instance in the class correctly so the compiler returns null.
Line 561 in the ExpressionGenerator is throwing the null reference when Debug.Assert is called.
the code generated by:
int sample = a()??b();
is
var sample = ss.value( a(), b() );
which causes b() being executed even if a() evaluates to a not null.
The String api surface from mscorlib doesn't match the BCL's. This should be normalised and several additions added. Currently missing the following:
To achieve method overloading we could store all variations of the symbol in the map. Then when we output the symbol we resolve the required parameters and write the specific method call.
For example:
public void DoSomething() { DoSomething("SomeValue"); }
public void DoSomething(string parameter) { //Do some code here }
Could compile down to:
function DoSomething$1(){
this.DoSomething$2("SomeValue");
}
function DoSomething$2(){
//Do some code here
}
When specifying an optional or default arguments we can hoist the variable assignment inline into the method. For example the following C#:
public void SomeMethod(object instance = null)
{
//Method Body here
}
Might translate to the following JavaScript:
function SomeMethod(instance){
instance = instance || null;
//Method Body here
}
CultureInfo returns an array specifying number of digits in each group to the left of the decimal in currency values. In en-IN (English -India) culture the returned group size array is {3, 2 , 0}, which should create the first group after 3 digits, next after 2 digits and the rest of the values should'nt be grouped at all.
But string format clips the rest of the string when the group size is 0.
Example 89678145321.00 value should be grouped as 896781,45,321.00 but the actual string we get is
45,321.00
This should be noticeable on any culture which returns a 0 group size in this case it was en-IN
Currently the compiler is targeting against the ISO C#2 standard. To add new features we need to upgrade the target to a more modern language specification.
Ideally we need to target C#4 and above for additions to the compiler.
It should also be possible to target a modern specification and then add a set of client analysers which report where unsupported features are added
In the ScriptSharp.targets
the BuildScript
target will never be evaluated if the GenerateScript
condition is not set to true.
This condition could always be true by default.
We also need to migrate away from using $(BuildDependsOn)
and instead replace it with AfterTargets="Build"
The following static helper methods from the source code could be added with ease:
These could be achieved using custom javascript functions which evaluate the output javascript object - which has keys and values.
This is issue is caused by a series of fixes from the dotnet team.
It can be resolved by following link: https://developercommunity.visualstudio.com/content/problem/138986/1550-preview-2-breaks-scriptsharp-compilation.html
Fixes need to be applied to the vsix project templates.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.