From 3ce43c2f326b20b7c21dc9ef1984501474fc650d Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Mon, 30 Sep 2013 22:24:50 -0700 Subject: [PATCH] remove hashbang before parsing JS file (#499) --- lib/jsdoc/src/parser.js | 3 +++ test/specs/jsdoc/src/parser.js | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/jsdoc/src/parser.js b/lib/jsdoc/src/parser.js index 64fbc455..cd4d6715 100644 --- a/lib/jsdoc/src/parser.js +++ b/lib/jsdoc/src/parser.js @@ -144,6 +144,9 @@ exports.Parser.prototype.getVisitors = function() { function pretreat(code) { return code + // comment out hashbang at the top of the file, like: #!/usr/bin/env node + .replace(/^(\#\![\S \t]+\n)/, '// $1') + // make starbangstar comments look like real jsdoc comments .replace(/\/\*\!\*/g, '/**') diff --git a/test/specs/jsdoc/src/parser.js b/test/specs/jsdoc/src/parser.js index b8b6996a..aae0cb64 100644 --- a/test/specs/jsdoc/src/parser.js +++ b/test/specs/jsdoc/src/parser.js @@ -113,6 +113,16 @@ describe("jsdoc/src/parser", function() { expect(parse).not.toThrow(); }); + + it("should comment out a POSIX hashbang at the start of the file", function() { + function parse() { + parser.parse(parserSrc); + } + + var parserSrc = 'javascript:#!/usr/bin/env node\n/** class */function Foo() {}'; + + expect(parse).not.toThrow(); + }); }); describe("results", function() {