mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
change ID for pure JS parser to 'js'; remove half-baked ability to use arbitrary parsers; test coverage
This commit is contained in:
parent
8ea7078d39
commit
fe04fa18f9
@ -73,10 +73,10 @@ gulp.task('test-rhino', function(cb) {
|
|||||||
exec(cmd, execCb.bind(null, cb));
|
exec(cmd, execCb.bind(null, cb));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test-rhino-esprima', function(cb) {
|
gulp.task('test-rhino-jsparser', function(cb) {
|
||||||
var cmd = util.format('"%s" -T -q "parser=esprima"', options.rhinoBin);
|
var cmd = util.format('"%s" -T -q "parser=js"', options.rhinoBin);
|
||||||
exec(cmd, execCb.bind(null, cb));
|
exec(cmd, execCb.bind(null, cb));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test', ['test-node', 'test-rhino', 'test-rhino-esprima']);
|
gulp.task('test', ['test-node', 'test-rhino', 'test-rhino-jsparser']);
|
||||||
gulp.task('default', ['lint', 'test']);
|
gulp.task('default', ['lint', 'test']);
|
||||||
|
|||||||
@ -27,7 +27,7 @@ var Syntax = jsdoc.src.syntax.Syntax;
|
|||||||
|
|
||||||
// TODO: docs
|
// TODO: docs
|
||||||
var PARSERS = exports.PARSERS = {
|
var PARSERS = exports.PARSERS = {
|
||||||
esprima: 'jsdoc/src/parser',
|
js: 'jsdoc/src/parser',
|
||||||
rhino: 'rhino/jsdoc/src/parser'
|
rhino: 'rhino/jsdoc/src/parser'
|
||||||
};
|
};
|
||||||
/*eslint-disable no-script-url */
|
/*eslint-disable no-script-url */
|
||||||
@ -40,22 +40,19 @@ exports.createParser = function(type) {
|
|||||||
var modulePath;
|
var modulePath;
|
||||||
|
|
||||||
if (!type) {
|
if (!type) {
|
||||||
type = jsdoc.util.runtime.isRhino() ? 'rhino' : 'esprima';
|
/* istanbul ignore next */
|
||||||
|
type = jsdoc.util.runtime.isRhino() ? 'rhino' : 'js';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PARSERS[type]) {
|
if (hasOwnProp.call(PARSERS, type)) {
|
||||||
modulePath = PARSERS[type];
|
modulePath = PARSERS[type];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
modulePath = path.join( path.getResourcePath(path.dirname(type)), path.basename(type) );
|
logger.fatal('The parser type "%s" is not recognized.', type);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
return new ( require(modulePath) ).Parser();
|
||||||
return new ( require(modulePath) ).Parser();
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
logger.fatal('Unable to create the parser type "' + type + '": ' + e);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: docs
|
// TODO: docs
|
||||||
|
|||||||
@ -40,9 +40,9 @@ jasmine.getParseResults = function() {
|
|||||||
return parseResults;
|
return parseResults;
|
||||||
};
|
};
|
||||||
|
|
||||||
// use the requested parser, or default to Esprima (on Node.js) or Rhino (on Rhino)
|
// use the requested parser, or default to the pure JS parser (on Node.js) or Rhino (on Rhino)
|
||||||
jasmine.jsParser = (function() {
|
jasmine.jsParser = (function() {
|
||||||
var parser = jsdoc.util.runtime.isRhino() ? 'rhino' : 'esprima';
|
var parser = jsdoc.util.runtime.isRhino() ? 'rhino' : 'js';
|
||||||
|
|
||||||
if (jsdoc.env.opts.query && jsdoc.env.opts.query.parser) {
|
if (jsdoc.env.opts.query && jsdoc.env.opts.query.parser) {
|
||||||
parser = jsdoc.env.opts.query.parser;
|
parser = jsdoc.env.opts.query.parser;
|
||||||
|
|||||||
@ -8,6 +8,10 @@ describe('jsdoc/src/parser', function() {
|
|||||||
src: {
|
src: {
|
||||||
handlers: require('jsdoc/src/handlers'),
|
handlers: require('jsdoc/src/handlers'),
|
||||||
parser: require('jsdoc/src/parser')
|
parser: require('jsdoc/src/parser')
|
||||||
|
},
|
||||||
|
util: {
|
||||||
|
logger: require('jsdoc/util/logger'),
|
||||||
|
runtime: require('jsdoc/util/runtime')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var path = require('jsdoc/path');
|
var path = require('jsdoc/path');
|
||||||
@ -17,11 +21,45 @@ describe('jsdoc/src/parser', function() {
|
|||||||
expect(typeof jsdoc.src.parser).toBe('object');
|
expect(typeof jsdoc.src.parser).toBe('object');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should export a "createParser" method', function() {
|
||||||
|
expect(typeof jsdoc.src.parser.createParser).toBe('function');
|
||||||
|
});
|
||||||
|
|
||||||
it('should export a "Parser" constructor', function() {
|
it('should export a "Parser" constructor', function() {
|
||||||
expect(jsdoc.src.parser.Parser).toBeDefined();
|
|
||||||
expect(typeof jsdoc.src.parser.Parser).toBe('function');
|
expect(typeof jsdoc.src.parser.Parser).toBe('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('createParser', function() {
|
||||||
|
it('should return a Parser when called without arguments', function() {
|
||||||
|
// we don't check instanceof because we get different objects on Node.js and Rhino
|
||||||
|
expect(typeof jsdoc.src.parser.createParser()).toBe('object');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a jsdoc/src/parser.Parser instance with the argument "js"', function() {
|
||||||
|
var parser = jsdoc.src.parser.createParser('js');
|
||||||
|
|
||||||
|
expect(parser instanceof jsdoc.src.parser.Parser).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (jsdoc.util.runtime.isRhino()) {
|
||||||
|
it('should create a Rhino parser with the argument "rhino"', function() {
|
||||||
|
var RhinoParser = require('rhino/jsdoc/src/parser').Parser;
|
||||||
|
var parser = jsdoc.src.parser.createParser('rhino');
|
||||||
|
|
||||||
|
expect(parser instanceof RhinoParser).toBe(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
it('should log a fatal error on bad input', function() {
|
||||||
|
var parser;
|
||||||
|
|
||||||
|
spyOn(jsdoc.util.logger, 'fatal');
|
||||||
|
parser = jsdoc.src.parser.createParser('not-a-real-parser-ever');
|
||||||
|
|
||||||
|
expect(jsdoc.util.logger.fatal).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Parser', function() {
|
describe('Parser', function() {
|
||||||
var parser;
|
var parser;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user