ASP/JScript to ASP.NET/JScript.NET Translator
I was the lead architect on an enterprise, commercial product that was based on Active Server Pages; however, we chose to use JScript.NET as our programming language on the server. While many companies choose to use VBScript on the server, we felt that JScript gave us greater flexibility. By 2006, our application grew to more than 1.2 million lines of code written in JScript and ASP.
When Microsoft released ASP.NET, they provided a fairly straightforward migration path from ASP to ASP.NET for application developed in VBScript. Unfortunately, they did not provide a useful upgrade path for applications developed in JScript. Even worse, they made dozens of changes to JScript.NET that broke compatibility with previous JScript. This meant we had 1.2 million lines of code and no upgrade path to .NET.
This is just a small sample of the tasks that the translator automatically performed:
- Successfully parsed an ASP-based web application (1.2 million lines of code and more than 800 visual pages) into an enormous language DOM in memory.
- Traced the complex pattern of include files to determine the objects and methods that were accessible by each visual screen.
- Identified and removed dead code.
- Refactored commonly included JScript files into JScript.NET classes and moved them into an external DLL. All references to globally accessible objects or methods were updated to go through thread-safe static objects exposed by the DLL.
- Refactored HTML and inline JScript into ASPX pages and refactored page-specific JScript methods into code behind.
- Refactored proprietary string resource libraries into proper .NET Resource Assemblies and updated all references.
- Restructured directories to follow a more “.NET” friendly structure. Detected and updated URL’s accordingly.
Corrected differences between JScript and JScript.NET including:
- Converted prototypes (even complex prototype hierarchies) into properly subclassed class models.
- Converted references to the arguments collections to a new params based model.
- Corrected the case of references to well-known objects (such as ASP and Data Access objects) since these references are case-sensitive in JScript.NET.
- Corrected “default property” references for well-known objects to use an explicit property notation.
- Corrected “undeclared variable” references by inferring and declaring properly scoped variables.
- Inferred the strong data type for variables where the data type could be safely inferred.
- Updated cookie access methods.
- Preserved or improved whitespace and comments from original source code.
While a small number of manual changes were required for some pages, in general the project was incredibly successful. Despite the radical restructuring of the code, we were able to convert to an ASP.NET application with risk of regression and substantial performance improvement.