Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
Add TypeScript support with sourcemaps (untested). See filearts/plunk…
Browse files Browse the repository at this point in the history
  • Loading branch information
ggoodman committed Jan 14, 2013
1 parent 4198c47 commit 1672b2b
Show file tree
Hide file tree
Showing 8 changed files with 31,579 additions and 79 deletions.
48 changes: 48 additions & 0 deletions compilers/typescript/index.coffee
@@ -0,0 +1,48 @@
fs = require("fs")
TypeScript = require("typescript-wrapper")

libfile = fs.readFileSync(TypeScript._libdPath, "utf8")


###
Compiler for TypeScript
Code adapted from the following sources:
* https://github.com/damassi/TypeScript-Watcher/
* https://github.com/niutech/typescript-compile/
###

createFile = ->
source: ""
Write: (text) -> @source += text
WriteLine: (text) -> @source += text + "\n"
Close: ->

module.exports =
match: /\.js$/
ext: ["ts"]
compile: (filename, source, str, fn) ->

jsOutput = createFile()
mapOutput = createFile()
errOutput = createFile()


compiler = new TypeScript.TypeScriptCompiler(errOutput)

compiler.settings.mapSourceFiles = true
compiler.settings.resolve = false

compiler.parser.errorRecovery = true

compiler.addUnit(libfile, "lib.d.ts")
compiler.addUnit(str, source or "")

compiler.typeCheck()

compiler.emit (filename) ->
if filename.match(/\.map$/) then mapOutput
else jsOutput

fn null, jsOutput.source, mapOutput.source

0 comments on commit 1672b2b

Please sign in to comment.