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

* Add support for LiveScript: http://livescript.net/ #9

Open
wants to merge 1 commit 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 @@ -16,7 +16,7 @@ var TerraformError = exports.TerraformError = require("../error").TerraformError
var processors = exports.processors = {
"html": ["jade", "ejs", "md"],
"css" : ["styl", "less"],
"js" : ["coffee"]
"js" : ["coffee", "ls"]
}


Expand Down
5 changes: 3 additions & 2 deletions lib/javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ var helpers = require('../helpers')
* same as doing...
*
* var processors = {
* "coffee" : require("./processors/coffee")
* "coffee" : require("./processors/coffee"),
* "ls" : require("./processors/ls")
* }
*
*/
Expand Down Expand Up @@ -44,4 +45,4 @@ module.exports = function(root, filePath, callback){

})

}
}
26 changes: 26 additions & 0 deletions lib/javascript/processors/ls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var ls = require("LiveScript")
var TerraformError = require("../../error").TerraformError

exports.compile = function(filePath, fileContents, callback){
try{
var errors = null
var script = ls.compile(fileContents.toString(), { bare: true })
}catch(e){
var errors = {}
errors.source = "LiveScript"
errors.dest = "JavaScript"
errors.filename = filePath
errors.location = { first_line: 0 }
if (/Error: ([^:]+) on line (\d+): (.+)/.test(e)){
errors.name = RegExp.$1
errors.location.first_line = Number(RegExp.$2)
errors.message = RegExp.$3
}
errors.stack = fileContents.toString()
errors.lineno = parseInt(errors.location.first_line ? errors.location.first_line + 1 : -1)
var script = null
var error = new TerraformError(errors)
}finally{
callback(error, script)
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"lru-cache" : "2.3.0",
"jade" : "0.28.2",
"coffee-script" : "1.6.3",
"LiveScript" : "1.2.0",
"ejs" : "0.8.4",
"marked": "0.2.8",
"less" : "1.3.3",
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/javascripts/ls/invalid.ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foo = function(){
this shouldnt work
}
1 change: 1 addition & 0 deletions test/fixtures/javascripts/ls/main.ls
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add = (+)
26 changes: 26 additions & 0 deletions test/javascripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,30 @@ describe("javascripts", function(){

})

describe(".ls", function(){
var root = __dirname + "/fixtures/javascripts/ls"
var poly = polymer.root(root)

it("should translate livescript to javascript", function(done){
poly.render("main.ls", function(errors, body){
should.not.exist(errors)
should.exist(body)
done()
})
})

it("should return errors if invalid", function(done){
poly.render("invalid.ls", 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()
})
})

})


})