Closed
Description
Version: v12.1.0
$ node -e 'require("fs").writeFileSync("test.js", `\u{FEFF}#!`, "utf8")'
$ node -c test.js
(function (exports, require, module, __filename, __dirname) { #!
^
SyntaxError: Invalid or unexpected token
$ echo $?
1
$ node test.js
$ echo $?
0
The bug is that check_syntax.js
call stripShebang
before stripBOM
, but the actual loader calls stripBOM before stripShebag.
It's not totally clear which behavior is desired. The original bug which lead to the introduction of stripBOM
actually had a script with a BOM preceding the #!
, though the test included in that commit doesn't. But unix systems generally require the #!
to be the first two bytes for it to be parsed as an interpreter directive, which means it cannot be preceded by a BOM.