andry-tino / Rosetta

Toolset for migrating your codebase from C# to TypeScript
http://antino-enlad.cloudapp.net:8080/job/Rosetta/
GNU General Public License v3.0
24 stars 9 forks source link

Referenced types' DN ScriptNamespace not detected when translating #30

Closed andry-tino closed 7 years ago

andry-tino commented 7 years ago

We have the ability, after semantic alignment, to detect the ScriptNamespace in referenced types. However this is working only if the referenced type is in the local syntax tree.

If the referenced type is in the referenced assembly, then the original namespace is used even though the ScriptNamespace attribute was specified in that assembly's source code for that type at definition time.

Example

In local syntax tree:

namespace MyNamespace {
  [ScriptNamespace{"NewNamespace"}]
  public class MyClass : MyBase { } // MyBase is in referenced assembly
  public class MySecondClass : MyClass { }
}

In the referenced assembly:

namespace MyNamespace {
  [ScriptNamespace{"NewNamespace"}]
  public class MyBase { }
}

When using Rosetta and passing the assembly through --assembly we get:

declare module DN {
  export class MyClass extends MyNamespace.MyBase { }
  export class MySecondClass extends DN.MyClass { }
}
andry-tino commented 7 years ago

Root cause analysis

Seems like the cause in majority of cases is wrong TypeReference helper being constructed. The one associated to ScriptSharp is not generated, but the ordinary one is used, thus no ScriptNamespace check is performed.

Syntax nodes

This reproes in:

Solution

Check constructed helper in factory and fix.

Tests

Add unit tests for factories (need to create mocks) and check created helper to be the expected one.