This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TypeScript support with sourcemaps (untested). See filearts/plunk…
- Loading branch information
Showing
8 changed files
with
31,579 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.