termi / es6-transpiler

Tomorrow's JavaScript syntax today
Other
216 stars 18 forks source link

Error on Hash-Bang #49

Open kobezzza opened 10 years ago

kobezzza commented 10 years ago
#!/bin/bash
function foo() {
}

Error:

Error: Line 1: Unexpected token ILLEGAL
raiden-dev commented 10 years ago

Scripts starting with shebang should be invoked directly from shell, not through node.js. You are getting an error because /bin/bash is not a valid interpreter for JavaScript. Try something like #!/usr/bin/env node and look for details about using shebang in general and especially for node.

kobezzza commented 10 years ago

Scripts starting with shebang should be invoked directly from shell, not through node.js.

Yes, but here is something else: the code is not transpiled - es6-transpiler error.

console.es6

#!/usr/bin/env node

/* my console app */

https://github.com/visionmedia/jade/blob/master/bin/jade.js

raiden-dev commented 10 years ago

Why it should be transpiled? It is not a valid JS at all. Transpiler gives a proper error, cause you can not do tricks like this. Transpile your script first and then use transpiled output to make a shell script with a shebang.

kobezzza commented 10 years ago

This could be done optionally, for example

//#!/usr/bin/env node

/* my CLI app */
es6-transpiler myApp.es6 --sha-bang > myApp.js

->

#!/usr/bin/env node

/* my CLI app */

Why not? It is more convenient than writing wrapper.

raiden-dev commented 10 years ago

Such things have no relation to JavaScript. You not blames browsers that throws an exception for invalid code and you can't blame transpiler for the same reasons. You should write the wrapper cause it is out of transpiler's responsibility zone.