Merge pull request #133 from hegemonic/parser-exception

Fix parser.js so it doesn't throw exceptions when parsing itself
This commit is contained in:
Michael Mathews 2012-07-03 15:20:58 -07:00
commit 1899713e33
2 changed files with 15 additions and 9 deletions

View File

@ -143,17 +143,11 @@ function pretreat(code) {
// make starbangstar comments look like real jsdoc comments
.replace(/\/\*\!\*/g, '/**')
// make matching comment endings easier
.replace(/\*\//g, '»')
// merge adjacent doclets
.replace(/»\/\*\*+/g, '@also')
.replace(/\*\/\/\*\*+/g, '@also')
// make lent objectliterals documentable by giving them a dummy name
.replace(/(\/\*\*[^»]*?@lends\b[^»]*?»\s*)\{/g, '$1 ____ = {') // like return @lends {
.replace(/(\/\*\*[^»]*?@lends\b[^»]*?»)(\s*)return(\s*)\{/g, '$2$3 return $1 ____ = {') // like @lends return {
// make matching comment endings harder
.replace(/»/g, '*/');
.replace(/(\/\*\*[^\*\/]*?@lends\b[^\*\/]*?\*\/\s*)\{/g, '$1 ____ = {') // like return @lends {
.replace(/(\/\*\*[^\*\/]*?@lends\b[^\*\/]*?\*\/)(\s*)return(\s*)\{/g, '$2$3 return $1 ____ = {'); // like @lends return {
}
var tkn = { NAMEDFUNCTIONSTATEMENT: -1001 };

View File

@ -39,6 +39,18 @@ describe("jsdoc/src/parser", function() {
parser.on('symbolFound', spy).parse(sourceCode);
expect(spy).toHaveBeenCalled();
});
it("should be able to parse its own source file", function() {
var fs = require("fs"),
path = require("path"),
parserSrc = "javascript:" + fs.readFileSync( path.join(__dirname,
"rhino_modules", "jsdoc", "src", "parser.js") ),
parse = function() {
parser.parse(parserSrc);
};
expect(parse).not.toThrow();
});
});
});
});