Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ES6 support with babel #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/helpers/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var TerraformError = exports.TerraformError = require("../error").TerraformError
var processors = exports.processors = {
"html": ["jade", "ejs", "md"],
"css" : ["styl", "less", "scss", "sass"],
"js" : ["coffee"]
"js" : ["coffee", "es"]
}


Expand Down
19 changes: 19 additions & 0 deletions lib/javascript/processors/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var babel = require("babel-core")
var TerraformError = require("../../error").TerraformError

exports.compile = function(filePath, fileContents, callback) {
var script = null
var error = null
try {
script = babel.transform(fileContents.toString()).code
} catch (e) {
e.source = "Babel"
e.dest = "JavaScript"
e.filename = filePath
e.lineno = parseInt(e.loc.line)
error = new TerraformError(e)
if (global.token) delete global.token // remove babel leak
}finally{
callback(error, script)
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
],
"license": "MIT",
"dependencies": {
"autoprefixer": "5.1.0",
"babel-core": "^5.4.7",
"lru-cache": "2.6.1",
"jade": "git://github.com/harp/jade#v1.9.3-bc.2",
"coffee-script": "1.9.2",
Expand All @@ -37,7 +39,7 @@
"less": "2.5.0",
"stylus": "0.47.3",
"minify": "git://github.com/kennethormandy/minify#v0.3.0",
"autoprefixer": "5.1.0"
"stylus": "0.47.3"
},
"devDependencies": {
"mocha": "1.8.2",
Expand Down
19 changes: 19 additions & 0 deletions test/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,25 @@ describe("errors", function(){
})
})


describe(".es", function(){
it("should error with invalid file", function(done){
poly.render("es/invalid.es", function(error, body){
should.not.exist(body)
should.exist(error)
console.log('err', error, 'body', body);
error.should.have.property('source', "Babel")
error.should.have.property('dest', "JavaScript")
error.should.have.property('lineno', 3)
error.should.have.property('filename')
error.should.have.property('message')
error.should.have.property('stack')
done()
})
})
})


describe(".scss", function(){
it("should get error if var missing in scss", function(done){
poly.render("scss/novar.scss", function(error, body){
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/errors/es/invalid.es
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


foo(
4 changes: 4 additions & 0 deletions test/fixtures/javascripts/coffee/invalid.es
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

foo = function(){
this shouldnt work
}
1 change: 1 addition & 0 deletions test/fixtures/javascripts/es/invalid.es
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo = function{ !shouldntwork; }
5 changes: 5 additions & 0 deletions test/fixtures/javascripts/es/main.es
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@




let add = (x, y) => { x + y }
31 changes: 31 additions & 0 deletions test/javascripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,35 @@ describe("javascripts", function(){

})

describe(".es", function() {

var root = __dirname + "/fixtures/javascripts/es"
var poly = polymer.root(root)

it("should transpile ES6 to ES5", function(done){
poly.render("main.es", function(errors, body){
should.not.exist(errors)
should.exist(body)
done()
})
})
it("should minify beyond transpiling", function(done){
poly.render("main.es", function(errors, body){
should.not.exist(errors)
body.should.not.include("\n\n")
done()
})
})
it("should return errors if invalid", function(done){
poly.render("invalid.es", function(errors, body){
should.exist(errors)
should.not.exist(body)
errors.should.have.property("name")
errors.should.have.property("message")
errors.should.have.property("stack")
done()
})
})
})

})