refactor(jsdoc): remove unused code for multiple parsers

This code was used to support both a Mozilla Rhino-based parser and a native ES-based parser. We now have only one parser.
This commit is contained in:
Jeff Williams 2021-09-26 10:16:09 -07:00
parent b850fa14b9
commit 9d843fb803
3 changed files with 11 additions and 53 deletions

View File

@ -287,7 +287,7 @@ module.exports = (() => {
const parser = require('jsdoc/src/parser');
const plugins = require('jsdoc/plugins');
props.parser = parser.createParser(env.conf.parser, env.conf);
props.parser = parser.createParser(env.conf);
if (env.conf.plugins) {
plugins.installPlugins(env.conf.plugins, props.parser);

View File

@ -12,10 +12,6 @@ const { Walker } = require('jsdoc/src/walker');
const hasOwnProp = Object.prototype.hasOwnProperty;
// TODO: docs
const PARSERS = (exports.PARSERS = {
js: 'jsdoc/src/parser',
});
/* eslint-disable no-script-url */
// Prefix for JavaScript strings that were provided in lieu of a filename.
const SCHEMA = 'javascript:';
@ -44,26 +40,6 @@ class DocletCache {
}
}
// TODO: docs
exports.createParser = (type, conf) => {
let modulePath;
if (!type) {
/* istanbul ignore next */
type = 'js';
}
if (hasOwnProp.call(PARSERS, type)) {
modulePath = PARSERS[type];
} else {
log.fatal(`The parser type "${type}" is not recognized.`);
return null;
}
return new (require(modulePath).Parser)(conf);
};
// TODO: docs
function pretreat(code) {
return (
@ -649,6 +625,11 @@ class Parser extends EventEmitter {
}
exports.Parser = Parser;
// TODO: docs
exports.createParser = (config) => {
return new Parser(config);
};
// TODO: document other events
/**
* Fired once for each JSDoc comment in the current source code.

View File

@ -2,6 +2,7 @@
describe('jsdoc/src/parser', () => {
const _ = require('lodash');
const { attachTo } = require('jsdoc/src/handlers');
const env = require('jsdoc/env');
const fs = require('fs');
const jsdocParser = require('jsdoc/src/parser');
const path = require('path');
@ -21,33 +22,17 @@ describe('jsdoc/src/parser', () => {
});
describe('createParser', () => {
it('should return a Parser when called without arguments', () => {
expect(jsdocParser.createParser()).toBeObject();
});
it('should create a jsdoc/src/parser.Parser instance with the argument "js"', () => {
const parser = jsdocParser.createParser('js');
expect(parser instanceof jsdocParser.Parser).toBeTrue();
});
it('should log a fatal error on bad input', () => {
function createParser() {
jsdocParser.createParser('not-a-real-parser-ever');
}
expect(jsdoc.didLog(createParser, 'fatal')).toBeTrue();
it('should return a Parser when called with a config', () => {
expect(jsdocParser.createParser(env.conf)).toBeObject();
});
});
describe('Parser', () => {
let parser;
function newParser() {
beforeEach(() => {
parser = new jsdocParser.Parser();
}
newParser();
});
it('should have a "visitor" property', () => {
expect(parser.visitor).toBeObject();
@ -90,8 +75,6 @@ describe('jsdoc/src/parser', () => {
});
describe('parse', () => {
beforeEach(newParser);
it('should fire "parseBegin" events before it parses any files', () => {
const spy = jasmine.createSpy();
const sourceFiles = ['javascript:/** @name foo */'];
@ -287,8 +270,6 @@ describe('jsdoc/src/parser', () => {
});
describe('results', () => {
beforeEach(newParser);
it('returns an empty array before files are parsed', () => {
const results = parser.results();
@ -374,8 +355,6 @@ describe('jsdoc/src/parser', () => {
let visitors;
beforeEach(newParser);
it('should work with a single node visitor', () => {
parser.addAstNodeVisitor(visitorA);
@ -395,8 +374,6 @@ describe('jsdoc/src/parser', () => {
});
describe('getAstNodeVisitors', () => {
beforeEach(newParser);
it('should return an empty array by default', () => {
const visitors = parser.getAstNodeVisitors();