Make 'traceur' ignore shebang lines in files. (issue 7945043)

2 views
Skip to first unread message

usrb...@yahoo.com

unread,
Mar 21, 2013, 11:46:43 AM3/21/13
to a...@chromium.org, sligh...@google.com, traceur-comp...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reviewers: arv-chromium, slightlylate,

Message:
Even though the blanket shebang ignore is a blunt instrument, it does
replicate node's behavior, so it's probably a feature, not a bug.

#--cut--
git checkout 60408908bf3c682b # last merge with branch master

dl_check() {
local f=$(basename $1)
test -e $f || curl -sO $1
openssl sha1 < $f | grep -q "= $2" && return 0
echo sha1 mismatch!
return 1
}

git checkout -b issue7945043-handle-shebang

dl_check https://codereview.appspot.com/download/issue7945043_1.diff \
1fbfff451b022bd8 && git apply issue7945043_1.diff && make test

cat > shebang-test.js <<"END"
#!./traceur
console.log(`Hello ${'she'}bang`);
END

chmod +x shebang-test.js
./shebang-test.js
#--cut--



https://codereview.appspot.com/7945043/diff/1/src/node/inline-module.js
File src/node/inline-module.js (right):

https://codereview.appspot.com/7945043/diff/1/src/node/inline-module.js#newcode137
src/node/inline-module.js:137: data = '//' + data;
It's not as elegant as removing, but it's by far the simplest solution
that maintains line numbering while also handling odd cases like files
that contain only a shebang line that does not end in a newline.

Description:
Make 'traceur' ignore shebang lines in files.

BUG=https://code.google.com/p/traceur-compiler/issues/detail?id=221
TEST=None


Please review this at https://codereview.appspot.com/7945043/

Affected files:
M src/node/inline-module.js


Index: src/node/inline-module.js
diff --git a/src/node/inline-module.js b/src/node/inline-module.js
index
e57ba9bd45ec470698706c09dff9430525c37410..7623df05c85c0cc6c48988cf59a2d5c0cf236143
100644
--- a/src/node/inline-module.js
+++ b/src/node/inline-module.js
@@ -132,6 +132,9 @@ InlineCodeLoader.prototype = {
if (err) {
errback(err);
} else {
+ // Ignore shebang lines
+ if (/^#!/.test(data))
+ data = '//' + data;
text = data;
callback(data);
}


a...@chromium.org

unread,
Mar 21, 2013, 12:16:13 PM3/21/13
to usrb...@yahoo.com, sligh...@google.com, traceur-comp...@googlegroups.com, re...@codereview-hr.appspotmail.com
LGTM

FYI, if you "npm install -g" you can do

#!/usr/bin/env traceur
On 2013/03/21 15:46:43, usrbincc wrote:
> It's not as elegant as removing, but it's by far the simplest solution
> that maintains line numbering while also handling odd cases like files
> that contain only a shebang line that does not end in a newline.

Agreed.

https://codereview.appspot.com/7945043/
Reply all
Reply to author
Forward
0 new messages