使用 CoffeeScript 很容易做到这一点。
var coffee = require('coffee-script');
coffee.compile("a = 1");
//=> '(function() {\n var a;\n\n a = 1;\n\n}).call(this);\n'
有没有办法用 typescript 做到这一点?
编辑:还有posted on codeplex
最佳答案
现在看来有一个更简单的解决方案,你可以这样做:
let ts = require('typescript');
let source = ts.transpileModule('class Test {}', {}).outputText;
这会导致:
"use strict";
var Test = (function () {
function Test() {
}
return Test;
}());
关于node.js - 从 Node 使用 TypeScript 编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12729779/