Use TypeScript compiler from node

后端 未结 6 1686
既然无缘
既然无缘 2021-02-02 17:30

It\'s pretty easy to do this with coffee-script.

var coffee = require(\'coffee-script\');
coffee.compile(\"a = 1\");
//=> \'(function() {\\n  var a;\\n\\n  a          


        
6条回答
  •  余生分开走
    2021-02-02 17:49

    It seems that nowadays there is a simpler solution, you can do:

    let ts = require('typescript');
    let source = ts.transpileModule('class Test {}', {}).outputText;
    

    This results in:

    "use strict";
    var Test = (function () {
        function Test() {
        }
        return Test;
    }());
    

提交回复
热议问题