Permalink
Browse files

ES6 transpilation WIP

  • Loading branch information...
1 parent 4629086 commit e1a2018e3d01be92a885a7765eebaf1c19abd426 @ggoodman ggoodman committed May 6, 2013
Showing with 74 additions and 44 deletions.
  1. +3 −0 .gitignore
  2. +37 −0 compilers/traceur.coffee
  3. +1 −1 compilers/typescript/index.coffee
  4. +0 −4 config.json
  5. +15 −26 configure.coffee
  6. +15 −11 index.coffee
  7. +3 −2 package.json
View
@@ -17,4 +17,7 @@ npm-debug.log
.c9revisions
+config.production.json
+config.development.json
+
builtAssets
@@ -0,0 +1,37 @@
+nconf = require("nconf")
+traceur = require("traceur")
+
+SourceMapGenerator = traceur.outputgeneration.SourceMapGenerator
+
+traceur.options.freeVariableChecker = false
+traceur.options.deferredFunctions = true
+traceur.options.experimental = true
+
+ext = 'es6.js'
+extRegex = /\.es6\.js$/
+
+module.exports =
+ match: /\.js$/
+ ext: [ext]
+ compile: (path, filename, source, str, plunk, fn) ->
+ reporter = new traceur.util.ErrorReporter()
+ project = new traceur.semantics.symbols.Project(nconf.get("url:run"))
+
+ #for fname, file of plunk.files when file.filename.match(extRegex)
+ # sourceFile = new traceur.syntax.SourceFile(file.filename.replace(extRegex, ".js"), file.content)
+ # project.addFile(sourceFile)
+
+ project.addFile new traceur.syntax.SourceFile(filename, str)
+
+ results = traceur.codegeneration.Compiler.compile(reporter, project)
+
+ return fn(new Error("Unable to compile es6", + reporter)) if reporter.hadError()
+
+ for file in results.keys() when file.name is filename
+ tree = results.get(file)
+ code = traceur.outputgeneration.TreeWriter.write(tree, false)
+ return fn(null, code)
+
+ return fn(new Error("Unable to parse file"))
+
+
@@ -22,7 +22,7 @@ createFile = ->
module.exports =
match: /\.js$/
ext: ["ts"]
- compile: (filename, source, str, fn) ->
+ compile: (filename, source, str, plunk, fn) ->
jsOutput = createFile()
mapOutput = createFile()
View
@@ -1,4 +0,0 @@
-{
- "host": "plnkr.co",
- "port": 8080
-}
View
@@ -1,26 +1,15 @@
-nconf = require("nconf")
-
-nconf.use("memory")
- .argv()
- .env()
- .file({file: "config.json"})
- .defaults({
- PORT: 8080
- })
-
-unless host = nconf.get("host")
- console.error "The 'host' option is required for Plunker to run."
- process.exit(1)
-
-if nconf.get("nosubdomains")
- nconf.set("url:www", "http://#{host}")
- nconf.set("url:raw", "http://#{host}/raw");
- nconf.set("url:run", "http://#{host}/run");
- nconf.set("url:api", "http://plnkr.co/api");
- nconf.set("url:embed", "http://#{host}/embed");
-
-else
- nconf.set("url:www", "http://#{host}")
- nconf.set("url:run", "http://run.plnkr.co")
- nconf.set("url:api", "http://api.plnkr.co")
- nconf.set("url:embed", "http://embed.plnkr.co")
+nconf = require("nconf")
+
+env = process.env.NODE_ENV or "development"
+
+nconf.use("memory")
+ .argv()
+ .env()
+ .file({file: "config.#{env}.json"})
+ .defaults({
+ PORT: 8080
+ })
+
+unless host = nconf.get("host")
+ console.error "The 'host' option is required for Plunker to run."
+ process.exit(1)
View
@@ -41,12 +41,13 @@ jade = require("jade")
markdown = require("marked")
stylus = require("stylus")
nib = require("nib")
+traceur = require("traceur")
compilers =
scss:
match: /\.css$/
ext: ['scss']
- compile: (path, filename, source, str, fn) ->
+ compile: (path, filename, source, str, plunk, fn) ->
try
scss.render(str, fn)
catch err
@@ -55,7 +56,7 @@ compilers =
sass:
match: /\.css$/
ext: ['sass']
- compile: (path, filename, source, str, fn) ->
+ compile: (path, filename, source, str, plunk, fn) ->
try
fn(null, sass.render(str))
catch err
@@ -64,7 +65,7 @@ compilers =
less:
match: /\.css$/
ext: ['less']
- compile: (path, filename, source, str, fn) ->
+ compile: (path, filename, source, str, plunk, fn) ->
try
less.render(str, fn)
catch err
@@ -73,7 +74,7 @@ compilers =
stylus:
match: /\.css/
ext: ['styl']
- compile: (path, filename, source, str, fn) ->
+ compile: (path, filename, source, str, plunk, fn) ->
try
stylus(str)
.use(nib())
@@ -84,7 +85,7 @@ compilers =
coffeescript:
match: /\.js$/
ext: ['coffee']
- compile: (path, filename, source, str, fn) ->
+ compile: (path, filename, source, str, plunk, fn) ->
try
answer = coffee.compile str,
bare: true
@@ -102,7 +103,7 @@ compilers =
livescript:
match: /\.js$/
ext: ['ls']
- compile: (path, filename, source, str, fn) ->
+ compile: (path, filename, source, str, plunk, fn) ->
try
fn(null, livescript.compile(str))
catch err
@@ -111,7 +112,7 @@ compilers =
icedcoffee:
match: /\.js$/
ext: ['iced']
- compile: (path, filename, source, str, fn) ->
+ compile: (path, filename, source, str, plunk, fn) ->
try
fn(null, iced.compile(str, runtime: "inline"))
catch err
@@ -120,7 +121,7 @@ compilers =
jade:
match: /\.html$/
ext: ['jade']
- compile: (path, filename, source, str, fn) ->
+ compile: (path, filename, source, str, plunk, fn) ->
render = jade.compile(str, pretty: true)
try
fn(null, render({}))
@@ -130,13 +131,15 @@ compilers =
markdown:
match: /\.html$/
ext: ['md',"markdown"]
- compile: (path, filename, source, str, fn) ->
+ compile: (path, filename, source, str, plunk, fn) ->
try
fn(null, markdown(str))
catch err
fn(err)
typescript: require("./compilers/typescript")
+
+ traceur: require("./compilers/traceur")
renderPlunkFile = (req, res, next) ->
plunk = req.plunk
@@ -158,13 +161,14 @@ renderPlunkFile = (req, res, next) ->
else
render = (filename) ->
- base = path.basename(filename, path.extname(filename))
+ extension = "." + path.basename(filename).split(".").slice(1).join(".")
+ base = path.basename(filename, extension)
type = mime.lookup(filename) or "text/plain"
for name, compiler of compilers when filename.match(compiler.match)
for ext in compiler.ext
if found = plunk.files["#{base}.#{ext}"]
- compiler.compile req.dir, filename, found.filename, found.content, (err, compiled, sourcemap) ->
+ compiler.compile req.dir, filename, found.filename, found.content, plunk, (err, compiled, sourcemap) ->
if err
console.log "[ERR] Compilation error:", err.message
return res.send 500, err.message or "Compilation error"
View
@@ -10,7 +10,7 @@
"engines": {
"node": "0.8.x"
},
- "version": "0.3.14-56",
+ "version": "0.3.15-3",
"private": true,
"dependencies": {
"coffee-script": "1.6.x",
@@ -31,7 +31,8 @@
"iced-coffee-script": "*",
"stylus": "*",
"nib": "*",
- "typescript-wrapper": "*"
+ "typescript-wrapper": "*",
+ "traceur": "0.0.x"
},
"bundledDependencies": [
"json-schema"

0 comments on commit e1a2018

Please sign in to comment.