- git clone https://git01.codeplex.com/typescript
- RC file
let typescript_path=<path>
- let's typescript
scratchpad.js がある場合は、
tsc --scratchpad
で scratchpad で コーディングできます。
interface を 実装していないので、エラーになります。
let typescript_path=<path>scratchpad.js がある場合は、
tsc --scratchpad
で scratchpad で コーディングできます。
interface を 実装していないので、エラーになります。
| var self = this; | |
| XPCOMUtils.defineLazyGetter(this, "scope", function () { | |
| var scope = {}; | |
| services.get("scriptloader").loadSubScript( | |
| services.get("io").newFileURI(File(TS_PATH("bin/typescript.js"))).spec, | |
| scope); | |
| return scope; | |
| }); | |
| function safeURI(path) { | |
| if (path instanceof Ci.nsIURI) { | |
| } else if (path instanceof Ci.nsIFile) { | |
| path = services.get("io").newFileURI(path); | |
| } else { | |
| try { | |
| path = makeURI(path); | |
| } catch (ex) { | |
| path = File(path); | |
| path = services.get("io").newFileURI(path); | |
| } | |
| } | |
| return path; | |
| } | |
| function TS_PATH(path) { | |
| return liberator.globalVariables.typescript_path + "/" + path; | |
| } | |
| XPCOMUtils.defineLazyGetter(this, "commonScripts", function () { | |
| var out = new StringFile; | |
| var err = new StringFile; | |
| var compiler = new scope.TypeScript.TypeScriptCompiler(out, err, new Logger); | |
| var f = File(TS_PATH("bin/lib.d.ts")); | |
| compiler.addUnit(f.read(), f.path); | |
| compiler.typeCheck(); | |
| return compiler.scripts.members; | |
| }); | |
| function createCompiler() { | |
| var out = new StringFile; | |
| var err = new StringFile; | |
| var _this = new scope.TypeScript.TypeScriptCompiler(out, err, new Logger); | |
| var scripts = commonScripts; | |
| for (var i = 0, j = scripts.length; i < j; i++) { | |
| var script = scripts[i]; | |
| _this.persistentTypeState.setCollectionMode(script.isResident | |
| ? scope.TypeScript.TypeCheckCollectionMode.Resident | |
| : scope.TypeScript.TypeCheckCollectionMode.Transient); | |
| var index = _this.units.length; | |
| _this.units[index] = script.locationInfo; | |
| _this.typeChecker.collectTypes(script); | |
| _this.scripts.append(script); | |
| } | |
| //_this.typeCheck(); | |
| return _this; | |
| } | |
| function StringFile() { | |
| this.source = ""; | |
| } | |
| (function (C) { | |
| var P = C.prototype; | |
| P.Write = function (s) { this.source += s; }; | |
| P.WriteLine = function (s) {this.source += s + "\n"; }; | |
| P.Close = function () {}; | |
| P.Clear = function () {this.source = "";} | |
| })(StringFile); | |
| function Logger() {} | |
| (function (C) { | |
| var P = C.prototype; | |
| function report(s) { Cu.reportError(s); } | |
| P.debug = P.error = P.fatal = P.infomation = P.log = P.warnning = report; | |
| })(Logger); | |
| function convert1(str, filename) { | |
| var compiler = createCompiler(); | |
| var out = compiler.outfile; | |
| var err = compiler.errorOutput; | |
| return compiler.timeFunction("TypeScript to JavaScript", function () { | |
| if (!filename) filename = "input.ts"; | |
| out.Clear(); | |
| err.Clear(); | |
| var script = compiler.addUnit(str, filename); | |
| compiler.reTypeCheck(); | |
| compiler.emit(false, function () out); | |
| return [out.source, err.source]; | |
| }); | |
| } | |
| self.cmd = commands.addUserCommand(["tsc"], "execute TypeScript", function (args) { | |
| var optionFile = "--file"; | |
| if (args["--scratchpad"]) { | |
| plugins.scratchpad.callScratchPad({}, function (args) { | |
| var notify = this.notificationBox; | |
| this.execute = function () { | |
| var selection = this.selectedText || this.getText(); | |
| try { | |
| var name = "TypeCheck"; | |
| var box = notify.getNotificationWithValue(name); | |
| if (box) box.close(); | |
| var res = convert1(selection, "scratchpad"); | |
| if (res[1]) throw res[1]; | |
| } catch (ex) { | |
| Cu.reportError(ex); | |
| notify.appendNotification(ex, name, null, notify.PRIORITY_CRITICAL_LOW); | |
| return [selection, "\0", null]; | |
| } | |
| liberator.echo(<pre>{res[0]}</pre>, commandline.FORCE_MULTILINE); | |
| //liberator.echo(res[0], commandline.FORCE_MULTILINE); | |
| var [error, result] = this.evalForContext(res[0]); | |
| this.deselect(); | |
| return [selection, error, result]; | |
| }; | |
| notify.appendNotification("TypeScript Mode"); | |
| }); | |
| return; | |
| } else if (args[optionFile]) { | |
| var t = Date.now(); | |
| var file = File(args[optionFile]); | |
| var res = convert1(file.read(), args[optionFile]); | |
| Cu.reportError("action time:" + (Date.now() - t)); | |
| } else { | |
| var res = convert1(args.literalArg); | |
| } | |
| if (res[1]) { | |
| throw res[1]; | |
| } else if (args["--test"]) { | |
| liberator.echo("<pre>\n" + res[0] + "</pre>"); | |
| } else { | |
| liberator.eval(res[0]); | |
| } | |
| }, { | |
| literal: 0, | |
| completer: completion.javascript, | |
| }, true); | |
| XPCOMUtils.defineLazyGetter(cmd, "options", function () { | |
| var res = [ | |
| [["--test"], commands.OPTION_NOARG], | |
| [["--file"], commands.OPTION_STRING, null, function (context) { | |
| var c = context.fork("file", 0); | |
| completion.file(c, true); | |
| return []; | |
| }], | |
| ]; | |
| if (plugins.scratchpad) { | |
| res.push([ ["--scratchpad"], commands.OPTION_NOARG ]); | |
| } | |
| return res; | |
| }); | |
| delete self.cmd; |