Created
January 20, 2014 23:20
-
-
Save Buildstarted/8531393 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Compiler { | |
//this is for version 0.9.5 | |
private static libfile: any = ...; | |
private static FileName: string = 'sample.ts'; | |
private _compiler: any; | |
constructor(sourceFile: string) { | |
this._compiler = new TypeScript.TypeScriptCompiler(null, this.Settings()); | |
this._compiler.addFile('lib.d.ts', Compiler.libfile); | |
this._compiler.addFile(Compiler.FileName, new TypeScript.ScriptSnapshot.fromString(sourceFile)); | |
} | |
private Settings() : void { | |
var settings = new TypeScript.CompilationSettings(); | |
settings.codeGenTarget = TypeScript.LanguageVersion.EcmaScript5; | |
settings.moduleGenTarget = TypeScript.ModuleGenTarget.Synchronous; | |
settings.noLib = true; | |
settings.noResolve = true; | |
settings.noImplicitAny = true; | |
return settings; | |
} | |
public Add(sourceFile: string): void { | |
this._compiler.addFile(Compiler.FileName, new TypeScript.ScriptSnapshot.fromString(sourceFile)); | |
} | |
public ValidateSyntax(): any { | |
return this._compiler.getSyntaxTree(Compiler.FileName); | |
} | |
public Compile(): string { | |
var outputFile: File = new File(); | |
var x = this._compiler.emit(Compiler.FileName, function (createFile) { return outputFile; }); | |
return x.outputFiles[0].text; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment