HoriSun / closure-compiler

Automatically exported from code.google.com/p/closure-compiler
0 stars 0 forks source link

Parser error if JS file has shebang (#!) #1317

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. specify shebang like "#!/usr/bin/env node" in test.js file
2. run closure-compiler with it
3. it files with the following error.
"test.js:1: ERROR - Parse error. primary expression expected
#!/usr/bin/env node"

What is the expected output? What do you see instead?
I expect it could succeed

What version of the product are you using? On what operating system?
lastest version

Please provide any additional information below.

Original issue reported on code.google.com by logyours...@gmail.com on 28 Apr 2014 at 2:48

GoogleCodeExporter commented 9 years ago
You forgot the opening " in the string literal.

Original comment by dim...@google.com on 28 Apr 2014 at 4:55

GoogleCodeExporter commented 9 years ago
Thanks for comment. I did'n know this.
Does it have to specify with Quote(") to write shebang in JS script file  ?

(Invalid)
#!/usr/bin/env node

(Valid)
"#!/usr/bin/env node"

Original comment by logyours...@gmail.com on 28 Apr 2014 at 5:01

GoogleCodeExporter commented 9 years ago
Hmm.. after wrapping it with the quota, it doesn't work properly..

When it has shebang in the first line on JS file, it works although not 
specifying node.
./test.js ( O )
this works fine like "node ./test.js"

But after wrapping it with quote, it does not work properly.
./test.js (X)
line 1: #!/usr/bin/env node: No such file or directory

Original comment by logyours...@gmail.com on 28 Apr 2014 at 5:06

GoogleCodeExporter commented 9 years ago
It looks shebang(#!) line should not start with " (Quote)
Please let me know if I was wrong.. :-( , please..

Original comment by logyours...@gmail.com on 28 Apr 2014 at 5:12

GoogleCodeExporter commented 9 years ago
Please find the attached one.

java -jar compiler.jar --language_in ECMASCRIPT5 --js ./test.js

./test.js:1: ERROR - Parse error. primary expression expected
#!/usr/bin/env node
^

1 error(s), 0 warning(s)

Original comment by logyours...@gmail.com on 28 Apr 2014 at 5:22

GoogleCodeExporter commented 9 years ago
"Contents of test.js"

#!/usr/bin/env node
var test = "normal ?"
console.log("Is this", test);

Original comment by logyours...@gmail.com on 28 Apr 2014 at 5:24

Attachments:

GoogleCodeExporter commented 9 years ago
#!/usr/bin/env node

is not valid JavaScript, that's why you're getting a parse error.

Original comment by dim...@google.com on 28 Apr 2014 at 5:24

GoogleCodeExporter commented 9 years ago
i've re-filed this as
https://github.com/google/closure-compiler/issues/410

I think we should do this.

Original comment by Nicholas.J.Santos on 8 May 2014 at 1:22