Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/jsdoc package #295

Merged
merged 3 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions jsdoc/file-readers/jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ module.exports = function jsdocFileReader(log, jsParser) {
try {
fileInfo.ast = jsParser(fileInfo.content);
} catch(ex) {
ex.file = fileInfo.filePath;
throw new Error(
`JavaScript error in file "${ex.file}"" [line ${ex.lineNumber}, column ${ex.column}]: "${ex.description}"`);
ex.file = fileInfo.filePath;
throw new Error(`JavaScript error in file "${ex.file}" [line ${ex.lineNumber}, column ${ex.column}]`);
}

return [{
Expand Down
2 changes: 1 addition & 1 deletion jsdoc/file-readers/jsdoc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("jsdoc fileReader", () => {
" sync:true\n" +
"}\n",
'.');
expect(() => fileReader.getDocs(fileInfo)).toThrowError('JavaScript error in file "some/file.js"" [line 13, column 3]: "Unexpected identifier"');
expect(() => fileReader.getDocs(fileInfo)).toThrowError('JavaScript error in file "some/file.js" [line 13, column 3]');
});

});
Expand Down
2 changes: 2 additions & 0 deletions jsdoc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = new Package('jsdoc', [require('../base')])

.factory(require('./services/code-name-map'))
.factory(require('./services/code-name'))
.factory(require('./services/transforms/boolean-tag'))
.factory(require('./services/transforms/extract-access'))
.factory(require('./services/transforms/extract-name'))
.factory(require('./services/transforms/extract-type'))
Expand All @@ -31,6 +32,7 @@ module.exports = new Package('jsdoc', [require('../base')])
.factory(require('./services/parser-adapters/backtick-parser-adapter'))
.factory(require('./services/parser-adapters/html-block-parser-adapter'))

.factory(require('./services/jsParser-config'))
.factory(require('./services/jsParser'))
.factory(require('./file-readers/jsdoc'))

Expand Down
2 changes: 1 addition & 1 deletion jsdoc/processors/extractJSDocComments.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const LEADING_STAR = /^[^\S\r\n]*\*[^\S\n\r]?/gm;
/**
* @dgProcessor extractJSDocCommentsProcessor
* @description
* This processor will create an doc for each jsdoc style comment in each jsFile
* This processor will create a doc for each jsdoc style comment in each jsFile
* doc in the docs collection.
*
* It will optionaly remove those jsFile docs from the collection by setting the
Expand Down
2 changes: 1 addition & 1 deletion jsdoc/services/code-name.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @dgProcessor codeNameService
* @dgService codeNameService
lmores marked this conversation as resolved.
Show resolved Hide resolved
* @description Infer the name of the document from name of the following code
*/
module.exports = function codeNameService(log, codeNameMap, getInjectables) {
Expand Down
36 changes: 36 additions & 0 deletions jsdoc/services/jsParser-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module.exports = function jsParserConfig() {
return {

// attach range information to each node
range: true,

// attach line/column location information to each node
loc: true,

// create a top-level comments array containing all comments
comment: true,

// create a top-level tokens array containing all tokens
tokens: true,

// Set to 3, 5 (default), 6, 7, 8, 9, 10, 11, or 12 to specify the version of ECMAScript syntax you want to use.
// You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11), or 2021 (same as 12) to use the year-based naming.
ecmaVersion: 6,

// specify which type of script you're parsing ("script" or "module")
sourceType: "script",

// specify additional language features
ecmaFeatures: {

// enable React JSX parsing
jsx: true,

// enable return in global scope
globalReturn: true,

// enable implied strict mode (if ecmaVersion >= 5)
impliedStrict: false
}
};
};
21 changes: 21 additions & 0 deletions jsdoc/services/jsParser-config.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var Dgeni = require('dgeni');
var mockPackage = require('../mocks/mockPackage');

describe('jsParserConfig service', function() {

var jsParserConfig;

beforeEach(function() {
var dgeni = new Dgeni([mockPackage()])
var injector = dgeni.configureInjector();
jsParserConfig = injector.get('jsParserConfig');
});

it("checks options required by this implementaion", function() {
expect(jsParserConfig.comment).toBe(true);
expect(jsParserConfig.loc).toBe(true);
expect(jsParserConfig.range).toBe(true);
expect(jsParserConfig.tokens).toBe(true);
expect(jsParserConfig.ecmaVersion).toBe(6);
});
});
105 changes: 4 additions & 101 deletions jsdoc/services/jsParser.js
Original file line number Diff line number Diff line change
@@ -1,102 +1,5 @@
const jsParserImpl = require('espree');
var jsParserImpl = require('espree');

module.exports = function jsParser() {
return code => {
return jsParserImpl.parse(code, {

// attach range information to each node
range: true,

// attach line/column location information to each node
loc: true,

// create a top-level comments array containing all comments
comments: true,

// attach comments to the closest relevant node as leadingComments and
// trailingComments
attachComment: true,

// create a top-level tokens array containing all tokens
tokens: true,

// try to continue parsing if an error is encountered, store errors in a
// top-level errors array
tolerant: true,

// specify parsing features (default only has blockBindings: true)
// setting this option replaces the default values
ecmaFeatures: {

// enable parsing of arrow functions
arrowFunctions: true,

// enable parsing of let/const
blockBindings: true,

// enable parsing of destructured arrays and objects
destructuring: true,

// enable parsing of regular expression y flag
regexYFlag: true,

// enable parsing of regular expression u flag
regexUFlag: true,

// enable parsing of template strings
templateStrings: true,

// enable parsing of binary literals
binaryLiterals: true,

// enable parsing of ES6 octal literals
octalLiterals: true,

// enable parsing unicode code point escape sequences
unicodeCodePointEscapes: true,

// enable parsing of default parameters
defaultParams: true,

// enable parsing of rest parameters
restParams: true,

// enable parsing of for-of statement
forOf: true,

// enable parsing computed object literal properties
objectLiteralComputedProperties: true,

// enable parsing of shorthand object literal methods
objectLiteralShorthandMethods: true,

// enable parsing of shorthand object literal properties
objectLiteralShorthandProperties: true,

// Allow duplicate object literal properties (except '__proto__')
objectLiteralDuplicateProperties: true,

// enable parsing of generators/yield
generators: true,

// enable parsing spread operator
spread: true,

// enable super in functions
superInFunctions: true,

// enable parsing classes
classes: true,

// enable parsing of modules
modules: true,

// enable React JSX parsing
jsx: true,

// enable return in global scope
globalReturn: true
}
});
};
};
module.exports = function jsParser(jsParserConfig) {
return code => jsParserImpl.parse(code, jsParserConfig);
};
9 changes: 9 additions & 0 deletions jsdoc/services/transforms/boolean-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Change the value of a tag to a boolean value (used by jsdoc tags like `@async`).
* @param {Tag} tag The tag to process
*/
module.exports = function booleanTagTransform() {
return function(doc, tag, value) {
return value !== null && value !== undefined;
};
};
32 changes: 32 additions & 0 deletions jsdoc/services/transforms/boolean-tag.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var transformFactory = require('./boolean-tag');

describe("boolean-tag transform", function() {
var transform;

beforeEach(function() {
transform = transformFactory();
});

it("should transform non-null and non-undefined values to `true`", function() {
var doc = {}, tag = {};

var value = '', newValue = transform(doc, tag, value);
expect(newValue).toEqual(true);

var value = 'some text', newValue = transform(doc, tag, value);
expect(newValue).toEqual(true);

var value = {}, newValue = transform(doc, tag, value);
expect(newValue).toEqual(true);
});

it("should transform null and undefined values to `false`", function() {
var doc = {}, tag = {};

var value = null, newValue = transform(doc, tag, value);
expect(newValue).toEqual(false);

var value = undefined, newValue = transform(doc, tag, value);
expect(newValue).toEqual(false);
});
});
6 changes: 6 additions & 0 deletions jsdoc/tag-defs/async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function(booleanTagTransform) {
return {
name: 'async',
transforms: [ booleanTagTransform ]
};
};
7 changes: 7 additions & 0 deletions jsdoc/tag-defs/constant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function(extractTypeTransform, extractNameTransform, wholeTagTransform) {
return {
name: 'constant',
aliases: ['const'],
transforms: [ extractTypeTransform, extractNameTransform, wholeTagTransform ]
};
};
6 changes: 6 additions & 0 deletions jsdoc/tag-defs/enum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function(extractTypeTransform) {
return {
name: 'enum',
transforms: [ extractTypeTransform ]
};
};
44 changes: 24 additions & 20 deletions jsdoc/tag-defs/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@

module.exports = [
require('./access'),
require('./private'),
require('./protected'),
require('./public'),
require('./name'),
require('./memberof'),
require('./param'),
require('./property'),
require('./propertyof'),
require('./returns'),
require('./type'),
require('./requires'),
require('./module'),
require('./description'),
require('./deprecated'),
require('./see'),
require('./usage'),
require('./animations'),
require('./constructor'),
require('./async'),
require('./class'),
require('./classdesc'),
require('./constant'),
require('./constructor'),
require('./deprecated'),
require('./description'),
require('./enum'),
require('./function'),
require('./global'),
require('./namespace'),
require('./kind'),
require('./function'),
require('./license'),
require('./memberof'),
require('./method'),
require('./license')
require('./module'),
require('./name'),
require('./namespace'),
require('./param'),
require('./private'),
require('./property'),
require('./propertyof'),
require('./protected'),
require('./public'),
require('./requires'),
require('./returns'),
require('./see'),
require('./since'),
require('./type'),
require('./usage')
];
2 changes: 1 addition & 1 deletion jsdoc/tag-defs/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const tagDefFactories = require('./');
describe("jsdoc tagdefs", () => {
it("should contain an array of tagDef factory functions", () => {
expect(tagDefFactories).toEqual(jasmine.any(Array));
expect(tagDefFactories.length).toEqual(27);
expect(tagDefFactories.length).toEqual(31);
tagDefFactories.forEach(factory => expect(factory).toEqual(jasmine.any(Function)));
});
});
3 changes: 3 additions & 0 deletions jsdoc/tag-defs/since.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function() {
return { name: 'since' };
};
4 changes: 2 additions & 2 deletions nunjucks/services/nunjucks-template-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ module.exports = function templateEngine(templateFinder) {
* Nunjucks specific options, such as using `{$ $}` for nunjucks interpolation
* rather than `{{ }}`, which conflicts with AngularJS
*/
config: {autoescape: false},
config: {autoescape: false, throwOnUndefined: true},

filters: [],
tags: [],

getRenderer() {
const loader = new nunjucks.FileSystemLoader(templateFinder.templateFolders, {throwOnUndefined: true, watch: false, noCache: false});
const loader = new nunjucks.FileSystemLoader(templateFinder.templateFolders, {watch: false, noCache: false});
const engine = new nunjucks.Environment(loader, this.config);

// Configure nunjucks with the custom filters
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"change-case": "3.0.0",
"dgeni": "^0.4.13",
"eslint": "^7.17.0",
"espree": "^2.2.3",
"espree": "^7.3.1",
"estraverse": "^4.1.0",
"glob": "^7.0.5",
"htmlencode": "^0.0.4",
Expand All @@ -53,7 +53,7 @@
"marked": "^0.7.0",
"minimatch": "^3.0.2",
"mkdirp": "^1.0.3",
"nunjucks": "^3.1.6",
"nunjucks": "^3.2.2",
"rehype": "^8.0.0",
"semver": "^5.2.0",
"source-map-support": "^0.4.15",
Expand Down Expand Up @@ -116,6 +116,7 @@
"Christoffer Hasselberg <[email protected]>",
"David Herges <[email protected]>",
"Greg Magolan <[email protected]>",
"Livio Brunner <[email protected]>"
"Livio Brunner <[email protected]>",
"Lorenzo Moreschini <[email protected]>"
]
}
Loading