nikhilk / scriptsharp

Script# Project - a C# to JavaScript compiler, to power your HTML5 and Node.js web development.
http://scriptsharp.com
Other
658 stars 182 forks source link

Class dependency order issue in 0.8 #311

Open theoutlander opened 11 years ago

theoutlander commented 11 years ago

I'm not sure if this is a similar issue to https://github.com/nikhilk/scriptsharp/issues/62, but there are times when the generated Javascript doesn't define the classes in the order of execution (or something on those lines) resulting in the objects utilizing those classes being null.

In the past, I avoided this issue by renaming the namespaces. However, this time I have classes that are part of an object heirarchy and cannot be moved into a different namespace.

nikhilk commented 11 years ago

At this point the best suggestion I have is to write a module class (internal static class annotated with [Module] with a static ctor) and do your assembly level static initialization there where you control the order explicitly if you have scenarios where there are inter-dependencies between classes and their static members.

Some level of ordering can be achieved by ordering sources, but obviously this is brittle, and painful to maintain.