Make code prettier

This updates ESLint and our shared eslint-config-openlayers to use Prettier.  Most formatting changes were automatically applied with this:

    npm run lint -- --fix

A few manual changes were required:

 * In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
 * In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason.  While editing this, I reworked `ExampleBuilder` to be a class.
 * In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
Tim Schaub
2020-04-06 12:25:12 -06:00
parent 53b48baf62
commit 054af09032
790 changed files with 46833 additions and 33765 deletions

View File

@@ -2,19 +2,18 @@
* Define an @api tag
* @param {Object} dictionary The tag dictionary.
*/
exports.defineTags = function(dictionary) {
exports.defineTags = function (dictionary) {
dictionary.defineTag('api', {
mustNotHaveValue: true,
canHaveType: false,
canHaveName: false,
onTagged: function(doclet, tag) {
onTagged: function (doclet, tag) {
includeTypes(doclet);
doclet.stability = 'stable';
}
},
});
};
/*
* Based on @api annotations, and assuming that items with no @api annotation
* should not be documented, this plugin removes undocumented symbols
@@ -56,7 +55,7 @@ function includeAugments(doclet) {
if (!doclet.fires) {
doclet.fires = [];
}
cls.fires.forEach(function(f) {
cls.fires.forEach(function (f) {
if (doclet.fires.indexOf(f) == -1) {
doclet.fires.push(f);
}
@@ -66,7 +65,7 @@ function includeAugments(doclet) {
if (!doclet.observables) {
doclet.observables = [];
}
cls.observables.forEach(function(f) {
cls.observables.forEach(function (f) {
if (doclet.observables.indexOf(f) == -1) {
doclet.observables.push(f);
}
@@ -79,7 +78,7 @@ function includeAugments(doclet) {
}
function extractTypes(item) {
item.type.names.forEach(function(type) {
item.type.names.forEach(function (type) {
const match = type.match(/^(.*<)?([^>]*)>?$/);
if (match) {
modules[match[2]] = true;
@@ -109,31 +108,35 @@ const moduleRoot = path.join(process.cwd(), 'src');
// Tag default exported Identifiers because their name should be the same as the module name.
exports.astNodeVisitor = {
visitNode: function(node, e, parser, currentSourceName) {
visitNode: function (node, e, parser, currentSourceName) {
if (node.parent && node.parent.type === 'ExportDefaultDeclaration') {
const modulePath = path.relative(moduleRoot, currentSourceName).replace(/\.js$/, '');
const exportName = 'module:' + modulePath.replace(/\\/g, '/') + (node.name ? '~' + node.name : '');
const modulePath = path
.relative(moduleRoot, currentSourceName)
.replace(/\.js$/, '');
const exportName =
'module:' +
modulePath.replace(/\\/g, '/') +
(node.name ? '~' + node.name : '');
defaultExports[exportName] = true;
}
}
},
};
function sortOtherMembers(doclet) {
if (doclet.fires) {
doclet.fires.sort(function(a, b) {
doclet.fires.sort(function (a, b) {
return a.split(/#?event:/)[1] < b.split(/#?event:/)[1] ? -1 : 1;
});
}
if (doclet.observables) {
doclet.observables.sort(function(a, b) {
doclet.observables.sort(function (a, b) {
return a.name < b.name ? -1 : 1;
});
}
}
exports.handlers = {
newDoclet: function(e) {
newDoclet: function (e) {
const doclet = e.doclet;
if (doclet.stability) {
modules[doclet.longname.split(/[~\.]/).shift()] = true;
@@ -152,7 +155,7 @@ exports.handlers = {
}
},
parseComplete: function(e) {
parseComplete: function (e) {
const doclets = e.doclets;
const byLongname = doclets.index.longname;
for (let i = doclets.length - 1; i >= 0; --i) {
@@ -183,9 +186,12 @@ exports.handlers = {
// Remove all other undocumented symbols
doclet.undocumented = true;
}
if (doclet.memberof && byLongname[doclet.memberof] &&
byLongname[doclet.memberof][0].isEnum &&
!byLongname[doclet.memberof][0].properties.some(p => p.stability)) {
if (
doclet.memberof &&
byLongname[doclet.memberof] &&
byLongname[doclet.memberof][0].isEnum &&
!byLongname[doclet.memberof][0].properties.some((p) => p.stability)
) {
byLongname[doclet.memberof][0].undocumented = true;
}
}
@@ -194,10 +200,9 @@ exports.handlers = {
processingComplete(e) {
const byLongname = e.doclets.index.longname;
for (const name in defaultExports) {
byLongname[name].forEach(function(doclet) {
byLongname[name].forEach(function (doclet) {
doclet.isDefaultExport = true;
});
}
}
},
};

View File

@@ -1,8 +1,7 @@
const events = {};
exports.handlers = {
newDoclet: function(e) {
newDoclet: function (e) {
const doclet = e.doclet;
if (doclet.kind !== 'event') {
return;
@@ -15,7 +14,7 @@ exports.handlers = {
events[cls].push(doclet.longname);
},
parseComplete: function(e) {
parseComplete: function (e) {
const doclets = e.doclets;
for (let i = 0, ii = doclets.length - 1; i < ii; ++i) {
const doclet = doclets[i];
@@ -34,6 +33,5 @@ exports.handlers = {
}
}
}
}
},
};

View File

@@ -6,12 +6,11 @@
const properties = {};
exports.handlers = {
/**
* Collects all typedefs, keyed by longname
* @param {Object} e Event object.
*/
newDoclet: function(e) {
newDoclet: function (e) {
if (e.doclet.kind == 'typedef' && e.doclet.properties) {
properties[e.doclet.longname] = e.doclet.properties;
}
@@ -22,7 +21,7 @@ exports.handlers = {
* collected typedefs.
* @param {Object} e Event object.
*/
parseComplete: function(e) {
parseComplete: function (e) {
const doclets = e.doclets;
for (let i = 0, ii = doclets.length; i < ii; ++i) {
const doclet = doclets[i];
@@ -34,16 +33,18 @@ exports.handlers = {
const type = param.type.names[0];
if (type in properties) {
param.type.names[0] = type;
params.push.apply(params, properties[type].map(p => {
const property = Object.assign({}, p);
property.name = `${param.name}.${property.name}`;
return property;
}));
params.push.apply(
params,
properties[type].map((p) => {
const property = Object.assign({}, p);
property.name = `${param.name}.${property.name}`;
return property;
})
);
}
}
}
}
}
}
},
};

View File

@@ -19,7 +19,7 @@ const tags = [
'properties',
'returns',
'see',
'summary'
'summary',
];
const hasOwnProp = Object.prototype.hasOwnProperty;
@@ -27,32 +27,32 @@ const hasOwnProp = Object.prototype.hasOwnProperty;
const markedRenderer = new marked.Renderer();
// Allow prettyprint to work on inline code samples
markedRenderer.code = function(code, language) {
markedRenderer.code = function (code, language) {
const langClass = language ? ' lang-' + language : '';
return format('<pre class="prettyprint source%s"><code>%s</code></pre>',
langClass, escapeCode(code));
return format(
'<pre class="prettyprint source%s"><code>%s</code></pre>',
langClass,
escapeCode(code)
);
};
function escapeCode(source) {
return source.replace(/</g, '&lt;')
return source
.replace(/</g, '&lt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
}
function escapeUnderscoresAndTildes(source) {
return source.replace(/\{@[^}\r\n]+\}/g, function(wholeMatch) {
return wholeMatch
.replace(/(^|[^\\])_/g, '$1\\_')
.replace('~', '&tilde;');
return source.replace(/\{@[^}\r\n]+\}/g, function (wholeMatch) {
return wholeMatch.replace(/(^|[^\\])_/g, '$1\\_').replace('~', '&tilde;');
});
}
function unencodeQuotesAndTildes(source) {
return source.replace(/\{@[^}\r\n]+\}/g, function(wholeMatch) {
return wholeMatch
.replace(/&quot;/g, '"')
.replace(/&tilde;/g, '~');
return source.replace(/\{@[^}\r\n]+\}/g, function (wholeMatch) {
return wholeMatch.replace(/&quot;/g, '"').replace(/&tilde;/g, '~');
});
}
@@ -63,7 +63,7 @@ function parse(source) {
result = marked(source, {renderer: markedRenderer})
.replace(/\s+$/, '')
.replace(/&#39;/g, '\'');
.replace(/&#39;/g, "'");
result = unencodeQuotesAndTildes(result);
@@ -82,15 +82,18 @@ function shouldProcessString(tagName, text) {
}
function process(doclet) {
tags.forEach(function(tag) {
tags.forEach(function (tag) {
if (!hasOwnProp.call(doclet, tag)) {
return;
}
if (typeof doclet[tag] === 'string' && shouldProcessString(tag, doclet[tag])) {
if (
typeof doclet[tag] === 'string' &&
shouldProcessString(tag, doclet[tag])
) {
doclet[tag] = parse(doclet[tag]);
} else if (Array.isArray(doclet[tag])) {
doclet[tag].forEach(function(value, index, original) {
doclet[tag].forEach(function (value, index, original) {
const inner = {};
inner[tag] = value;
@@ -103,9 +106,8 @@ function process(doclet) {
});
}
exports.handlers = {
newDoclet: function(e) {
newDoclet: function (e) {
process(e.doclet);
}
},
};

View File

@@ -2,15 +2,14 @@ const classes = {};
const observables = {};
exports.handlers = {
newDoclet: function(e) {
newDoclet: function (e) {
const doclet = e.doclet;
if (doclet.kind == 'class' && !(doclet.longname in classes)) {
classes[doclet.longname] = doclet;
}
},
parseComplete: function(e) {
parseComplete: function (e) {
const doclets = e.doclets;
let cls, doclet, event, i, ii, observable;
for (i = 0, ii = doclets.length - 1; i < ii; ++i) {
@@ -26,8 +25,8 @@ exports.handlers = {
}
observable = observables[key];
observable.name = name;
observable.readonly = typeof observable.readonly == 'boolean' ?
observable.readonly : true;
observable.readonly =
typeof observable.readonly == 'boolean' ? observable.readonly : true;
if (doclet.name.indexOf('get') === 0) {
observable.type = doclet.returns[0].type;
observable.description = doclet.returns[0].description;
@@ -53,17 +52,16 @@ exports.handlers = {
}
}
}
}
},
};
exports.defineTags = function(dictionary) {
exports.defineTags = function (dictionary) {
dictionary.defineTag('observable', {
mustNotHaveValue: true,
canHaveType: false,
canHaveName: false,
onTagged: function(doclet, tag) {
onTagged: function (doclet, tag) {
doclet.observable = '';
}
},
});
};

View File

@@ -4,7 +4,7 @@ const hasOwnProp = Object.prototype.hasOwnProperty;
// Work around an issue with hasOwnProperty in JSDoc's templateHelper.js.
//TODO Fix in JSDoc.
Object.prototype.hasOwnProperty = function(property) {
Object.prototype.hasOwnProperty = function (property) {
return property in this;
};
@@ -31,7 +31,11 @@ function find(spec) {
}
function tutoriallink(tutorial) {
return helper.toTutorial(tutorial, null, {tag: 'em', classname: 'disabled', prefix: 'Tutorial: '});
return helper.toTutorial(tutorial, null, {
tag: 'em',
classname: 'disabled',
prefix: 'Tutorial: ',
});
}
function getAncestorLinks(doclet) {
@@ -55,8 +59,12 @@ function needsSignature(doclet) {
// function and class definitions always get a signature
if (doclet.kind === 'function' || doclet.kind === 'class') {
needsSig = true;
} else if (doclet.kind === 'typedef' && doclet.type && doclet.type.names &&
doclet.type.names.length) {
} else if (
doclet.kind === 'typedef' &&
doclet.type &&
doclet.type.names &&
doclet.type.names.length
) {
// typedefs that contain functions get a signature, too
for (let i = 0, l = doclet.type.names.length; i < l; i++) {
if (doclet.type.names[i].toLowerCase() === 'function') {
@@ -81,22 +89,30 @@ function addSignatureReturns(f) {
f.signature = '<span class="signature">' + (f.signature || '') + '</span>';
if (returnTypes.length) {
f.signature += '<span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">' + (returnTypes.length ? '{' + returnTypes.join('|') + '}' : '') + '</span>';
f.signature +=
'<span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">' +
(returnTypes.length ? '{' + returnTypes.join('|') + '}' : '') +
'</span>';
}
}
function addSignatureTypes(f) {
const types = helper.getSignatureTypes(f);
f.signature = (f.signature || '') + '<span class="type-signature">' + (types.length ? ' :' + types.join('|') : '') + ' </span>';
f.signature =
(f.signature || '') +
'<span class="type-signature">' +
(types.length ? ' :' + types.join('|') : '') +
' </span>';
}
function shortenPaths(files, commonPrefix) {
// always use forward slashes
const regexp = new RegExp('\\\\', 'g');
Object.keys(files).forEach(function(file) {
files[file].shortened = files[file].resolved.replace(commonPrefix, '')
Object.keys(files).forEach(function (file) {
files[file].shortened = files[file].resolved
.replace(commonPrefix, '')
.replace(regexp, '/');
});
@@ -112,9 +128,10 @@ function getPathFromDoclet(doclet) {
return;
}
const filepath = doclet.meta.path && doclet.meta.path !== 'null' ?
doclet.meta.path + '/' + doclet.meta.filename.split(/[\/\\]/).pop() :
doclet.meta.filename;
const filepath =
doclet.meta.path && doclet.meta.path !== 'null'
? doclet.meta.path + '/' + doclet.meta.filename.split(/[\/\\]/).pop()
: doclet.meta.filename;
return filepath;
}
@@ -126,7 +143,7 @@ function generate(title, docs, filename, resolveLinks) {
filename: filename,
title: title,
docs: docs,
packageInfo: (find({kind: 'package'}) || []) [0]
packageInfo: (find({kind: 'package'}) || [])[0],
};
const outpath = path.join(outdir, filename);
@@ -140,7 +157,7 @@ function generate(title, docs, filename, resolveLinks) {
}
function generateSourceFiles(sourceFiles) {
Object.keys(sourceFiles).forEach(function(file) {
Object.keys(sourceFiles).forEach(function (file) {
let source;
// links are keyed to the shortened path in each doclet's `meta.filename` property
const sourceOutfile = helper.getUniqueFilename(sourceFiles[file].shortened);
@@ -149,14 +166,20 @@ function generateSourceFiles(sourceFiles) {
try {
source = {
kind: 'source',
code: helper.htmlsafe(fs.readFileSync(sourceFiles[file].resolved, 'utf8'))
code: helper.htmlsafe(
fs.readFileSync(sourceFiles[file].resolved, 'utf8')
),
};
} catch (e) {
handle(e);
}
generate('Source: ' + sourceFiles[file].shortened, [source], sourceOutfile,
false);
generate(
'Source: ' + sourceFiles[file].shortened,
[source],
sourceOutfile,
false
);
});
}
@@ -175,14 +198,15 @@ function attachModuleSymbols(doclets, modules) {
const symbols = {};
// build a lookup table
doclets.forEach(function(symbol) {
doclets.forEach(function (symbol) {
symbols[symbol.longname] = symbol;
});
modules.forEach(function(module) {
modules.forEach(function (module) {
if (symbols[module.longname]) {
module.module = symbols[module.longname];
module.module.name = module.module.name.replace('module:', 'require("') + '")';
module.module.name =
module.module.name.replace('module:', 'require("') + '")';
}
});
}
@@ -210,7 +234,7 @@ function getPrettyName(doclet) {
*/
function buildNav(members) {
const nav = [];
members.classes.forEach(function(v) {
members.classes.forEach(function (v) {
// exclude interfaces from sidebar
if (v.interface !== true) {
nav.push({
@@ -220,52 +244,55 @@ function buildNav(members) {
name: v.name,
module: find({
kind: 'module',
longname: v.memberof
longname: v.memberof,
})[0],
members: find({
kind: 'member',
memberof: v.longname
memberof: v.longname,
}),
methods: find({
kind: 'function',
memberof: v.longname
memberof: v.longname,
}),
typedefs: find({
kind: 'typedef',
memberof: v.longname
memberof: v.longname,
}),
fires: v.fires,
events: find({
kind: 'event',
memberof: v.longname
})
memberof: v.longname,
}),
});
}
});
members.modules.forEach(function(v) {
members.modules.forEach(function (v) {
const classes = find({
kind: 'class',
memberof: v.longname
memberof: v.longname,
});
const members = find({
kind: 'member',
memberof: v.longname
memberof: v.longname,
});
const methods = find({
kind: 'function',
memberof: v.longname
memberof: v.longname,
});
const typedefs = find({
kind: 'typedef',
memberof: v.longname
memberof: v.longname,
});
const events = find({
kind: 'event',
memberof: v.longname
memberof: v.longname,
});
// Only add modules that contain more than just classes with their
// associated Options typedef
if (typedefs.length > classes.length || members.length + methods.length > 0) {
if (
typedefs.length > classes.length ||
members.length + methods.length > 0
) {
nav.push({
type: 'module',
longname: v.longname,
@@ -275,12 +302,12 @@ function buildNav(members) {
methods: methods,
typedefs: typedefs,
fires: v.fires,
events: events
events: events,
});
}
});
nav.sort(function(a, b) {
nav.sort(function (a, b) {
const prettyNameA = a.prettyname.toLowerCase();
const prettyNameB = b.prettyname.toLowerCase();
if (prettyNameA > prettyNameB) {
@@ -294,13 +321,12 @@ function buildNav(members) {
return nav;
}
/**
* @param {Object} taffyData See <http://taffydb.com/>.
* @param {Object} opts Options.
* @param {Object} tutorials Tutorials.
*/
exports.publish = function(taffyData, opts, tutorials) {
exports.publish = function (taffyData, opts, tutorials) {
data = taffyData;
const conf = env.conf.templates || {};
@@ -329,26 +355,30 @@ exports.publish = function(taffyData, opts, tutorials) {
let sourceFiles = {};
const sourceFilePaths = [];
data().each(function(doclet) {
data().each(function (doclet) {
doclet.attribs = '';
if (doclet.examples) {
doclet.examples = doclet.examples.map(function(example) {
doclet.examples = doclet.examples.map(function (example) {
let caption, code;
if (example.match(/^\s*<caption>([\s\S]+?)<\/caption>(\s*[\n\r])([\s\S]+)$/i)) {
if (
example.match(
/^\s*<caption>([\s\S]+?)<\/caption>(\s*[\n\r])([\s\S]+)$/i
)
) {
caption = RegExp.$1;
code = RegExp.$3;
}
return {
caption: caption || '',
code: code || example
code: code || example,
};
});
}
if (doclet.see) {
doclet.see.forEach(function(seeItem, i) {
doclet.see.forEach(function (seeItem, i) {
doclet.see[i] = hashToLink(doclet, seeItem);
});
}
@@ -361,7 +391,7 @@ exports.publish = function(taffyData, opts, tutorials) {
resolvedSourcePath = resolveSourcePath(sourcePath);
sourceFiles[sourcePath] = {
resolved: resolvedSourcePath,
shortened: null
shortened: null,
};
sourceFilePaths.push(resolvedSourcePath);
}
@@ -373,7 +403,7 @@ exports.publish = function(taffyData, opts, tutorials) {
const fromDir = path.join(templatePath, 'static');
const staticFiles = fs.ls(fromDir, 3);
staticFiles.forEach(function(fileName) {
staticFiles.forEach(function (fileName) {
const toDir = fs.toDir(fileName.replace(fromDir, outdir));
fs.mkPath(toDir);
fs.copyFileSync(fileName, toDir);
@@ -385,15 +415,22 @@ exports.publish = function(taffyData, opts, tutorials) {
let staticFileScanner;
if (conf['default'].staticFiles) {
staticFilePaths = conf['default'].staticFiles.paths || [];
staticFileFilter = new (require('jsdoc/lib/jsdoc/src/filter')).Filter(conf['default'].staticFiles);
staticFileScanner = new (require('jsdoc/lib/jsdoc/src/scanner')).Scanner();
staticFileFilter = new (require('jsdoc/lib/jsdoc/src/filter').Filter)(
conf['default'].staticFiles
);
staticFileScanner = new (require('jsdoc/lib/jsdoc/src/scanner').Scanner)();
staticFilePaths.forEach(function(filePath) {
const extraStaticFiles = staticFileScanner.scan([filePath], 10, staticFileFilter);
staticFilePaths.forEach(function (filePath) {
const extraStaticFiles = staticFileScanner.scan(
[filePath],
10,
staticFileFilter
);
extraStaticFiles.forEach(function(fileName) {
const sourcePath = fs.statSync(filePath).isDirectory() ? filePath :
path.dirname(filePath);
extraStaticFiles.forEach(function (fileName) {
const sourcePath = fs.statSync(filePath).isDirectory()
? filePath
: path.dirname(filePath);
const toDir = fs.toDir(fileName.replace(sourcePath, outdir));
fs.mkPath(toDir);
fs.copyFileSync(fileName, toDir);
@@ -404,7 +441,7 @@ exports.publish = function(taffyData, opts, tutorials) {
if (sourceFilePaths.length) {
sourceFiles = shortenPaths(sourceFiles, path.commonPrefix(sourceFilePaths));
}
data().each(function(doclet) {
data().each(function (doclet) {
const url = helper.createLink(doclet);
helper.registerLink(doclet.longname, url);
@@ -419,7 +456,7 @@ exports.publish = function(taffyData, opts, tutorials) {
}
});
data().each(function(doclet) {
data().each(function (doclet) {
const url = helper.longnameToUrl[doclet.longname];
if (url.indexOf('#') > -1) {
@@ -435,7 +472,7 @@ exports.publish = function(taffyData, opts, tutorials) {
});
// do this after the urls have all been generated
data().each(function(doclet) {
data().each(function (doclet) {
doclet.ancestors = getAncestorLinks(doclet);
if (doclet.kind === 'member') {
@@ -461,8 +498,10 @@ exports.publish = function(taffyData, opts, tutorials) {
// once for all
view.nav = buildNav(members);
attachModuleSymbols(find({kind: ['class', 'function'], longname: {left: 'module:'}}),
members.modules);
attachModuleSymbols(
find({kind: ['class', 'function'], longname: {left: 'module:'}}),
members.modules
);
// only output pretty-printed source files if requested; do this before generating any other
// pages, so the other pages can link to the source files
@@ -478,9 +517,17 @@ exports.publish = function(taffyData, opts, tutorials) {
const files = find({kind: 'file'});
view.navigationHtml = helper.resolveLinks(view.partial('navigation.tmpl'));
generate('Index',
[{kind: 'mainpage', readme: opts.readme, longname: (opts.mainpagetitle) ? opts.mainpagetitle : 'Main Page'}].concat(files),
indexUrl);
generate(
'Index',
[
{
kind: 'mainpage',
readme: opts.readme,
longname: opts.mainpagetitle ? opts.mainpagetitle : 'Main Page',
},
].concat(files),
indexUrl
);
// set up the lists that we'll use to generate pages
const classes = taffy(members.classes);
@@ -493,27 +540,47 @@ exports.publish = function(taffyData, opts, tutorials) {
if (hasOwnProp.call(helper.longnameToUrl, longname)) {
const myClasses = helper.find(classes, {longname: longname});
if (myClasses.length) {
generate('Class: ' + myClasses[0].name, myClasses, helper.longnameToUrl[longname]);
generate(
'Class: ' + myClasses[0].name,
myClasses,
helper.longnameToUrl[longname]
);
}
const myModules = helper.find(modules, {longname: longname});
if (myModules.length) {
generate('Module: ' + myModules[0].name, myModules, helper.longnameToUrl[longname]);
generate(
'Module: ' + myModules[0].name,
myModules,
helper.longnameToUrl[longname]
);
}
const myNamespaces = helper.find(namespaces, {longname: longname});
if (myNamespaces.length) {
generate('Namespace: ' + myNamespaces[0].name, myNamespaces, helper.longnameToUrl[longname]);
generate(
'Namespace: ' + myNamespaces[0].name,
myNamespaces,
helper.longnameToUrl[longname]
);
}
const myMixins = helper.find(mixins, {longname: longname});
if (myMixins.length) {
generate('Mixin: ' + myMixins[0].name, myMixins, helper.longnameToUrl[longname]);
generate(
'Mixin: ' + myMixins[0].name,
myMixins,
helper.longnameToUrl[longname]
);
}
const myExternals = helper.find(externals, {longname: longname});
if (myExternals.length) {
generate('External: ' + myExternals[0].name, myExternals, helper.longnameToUrl[longname]);
generate(
'External: ' + myExternals[0].name,
myExternals,
helper.longnameToUrl[longname]
);
}
}
}
@@ -524,7 +591,7 @@ exports.publish = function(taffyData, opts, tutorials) {
title: title,
header: tutorial.title,
content: tutorial.parse(),
children: tutorial.children
children: tutorial.children,
};
let html = view.render('tutorial.tmpl', tutorialData);
@@ -537,8 +604,12 @@ exports.publish = function(taffyData, opts, tutorials) {
// tutorials can have only one parent so there is no risk for loops
function saveChildren(node) {
node.children.forEach(function(child) {
generateTutorial('Tutorial: ' + child.title, child, helper.tutorialToUrl(child.name));
node.children.forEach(function (child) {
generateTutorial(
'Tutorial: ' + child.title,
child,
helper.tutorialToUrl(child.name)
);
saveChildren(child);
});
}

View File

@@ -1,15 +1,11 @@
/**
* Handle the api annotation.
* @param {Object} dictionary The tag dictionary.
*/
exports.defineTags = function(dictionary) {
exports.defineTags = function (dictionary) {
dictionary.defineTag('api', {
onTagged: function(doclet, tag) {
onTagged: function (doclet, tag) {
doclet.api = true;
}
},
});
};

View File

@@ -5,31 +5,27 @@
* insensitive, with or without ticks).
*/
const DEFAULT_VALUE = /default\s+is\s+`?(true|false)`?/i;
/**
* Hook to define new tags.
* @param {Object} dictionary The tag dictionary.
*/
exports.defineTags = function(dictionary) {
exports.defineTags = function (dictionary) {
dictionary.defineTag('define', {
canHaveType: true,
mustHaveValue: true,
onTagged: function(doclet, tag) {
onTagged: function (doclet, tag) {
const types = tag.value.type.names;
if (types.length === 1 && types[0] === 'boolean') {
const match = tag.value.description.match(DEFAULT_VALUE);
if (match) {
doclet.define = {
default: match[1] === 'true'
default: match[1] === 'true',
};
doclet.description = tag.value.description;
}
}
}
},
});
};

View File

@@ -5,18 +5,16 @@
const assert = require('assert');
const path = require('path');
/**
* Publish hook for the JSDoc template. Writes to JSON stdout.
* @param {function} data The root of the Taffy DB containing doclet records.
* @param {Object} opts Options.
* @return {Promise} A promise that resolves when writing is complete.
*/
exports.publish = function(data, opts) {
exports.publish = function (data, opts) {
function getTypes(data) {
const types = [];
data.forEach(function(name) {
data.forEach(function (name) {
types.push(name.replace(/^function$/, 'Function'));
});
return types;
@@ -27,19 +25,22 @@ exports.publish = function(data, opts) {
const docs = data(
[
{define: {isObject: true}},
function() {
function () {
if (this.kind == 'class') {
if (!('extends' in this) || typeof this.api == 'boolean') {
classes[this.longname] = this;
return true;
}
}
return (typeof this.api == 'boolean' ||
this.meta && (/[\\\/]externs$/).test(this.meta.path));
}
return (
typeof this.api == 'boolean' ||
(this.meta && /[\\\/]externs$/.test(this.meta.path))
);
},
],
{kind: {'!is': 'file'}},
{kind: {'!is': 'event'}}).get();
{kind: {'!is': 'event'}}
).get();
// get symbols data, filter out those that are members of private classes
const symbols = [];
@@ -49,117 +50,133 @@ exports.publish = function(data, opts) {
let base = [];
const augments = {};
const symbolsByName = {};
docs.filter(function(doc) {
let include = true;
const constructor = doc.memberof;
if (constructor && constructor.substr(-1) === '_' && constructor.indexOf('module:') === -1) {
assert.strictEqual(doc.inherited, true,
'Unexpected export on private class: ' + doc.longname);
include = false;
}
return include;
}).forEach(function(doc) {
const isExterns = (/[\\\/]externs$/).test(doc.meta.path);
if (doc.define) {
defines.push({
name: doc.longname,
description: doc.description,
path: path.join(doc.meta.path, doc.meta.filename),
default: doc.define.default
});
} else if (doc.kind == 'typedef' || doc.isEnum === true) {
typedefs.push({
name: doc.longname,
types: getTypes(doc.type.names)
});
} else {
const symbol = {
name: doc.longname,
kind: doc.kind,
description: doc.classdesc || doc.description,
path: path.join(doc.meta.path, doc.meta.filename)
};
if (doc.augments) {
symbol.extends = doc.augments[0];
docs
.filter(function (doc) {
let include = true;
const constructor = doc.memberof;
if (
constructor &&
constructor.substr(-1) === '_' &&
constructor.indexOf('module:') === -1
) {
assert.strictEqual(
doc.inherited,
true,
'Unexpected export on private class: ' + doc.longname
);
include = false;
}
if (doc.virtual) {
symbol.virtual = true;
}
if (doc.type) {
symbol.types = getTypes(doc.type.names);
}
if (doc.params) {
const params = [];
doc.params.forEach(function(param) {
const paramInfo = {
name: param.name
};
params.push(paramInfo);
paramInfo.types = getTypes(param.type.names);
if (typeof param.variable == 'boolean') {
paramInfo.variable = param.variable;
}
if (typeof param.optional == 'boolean') {
paramInfo.optional = param.optional;
}
if (typeof param.nullable == 'boolean') {
paramInfo.nullable = param.nullable;
}
return include;
})
.forEach(function (doc) {
const isExterns = /[\\\/]externs$/.test(doc.meta.path);
if (doc.define) {
defines.push({
name: doc.longname,
description: doc.description,
path: path.join(doc.meta.path, doc.meta.filename),
default: doc.define.default,
});
symbol.params = params;
}
if (doc.returns) {
symbol.returns = {
types: getTypes(doc.returns[0].type.names)
} else if (doc.kind == 'typedef' || doc.isEnum === true) {
typedefs.push({
name: doc.longname,
types: getTypes(doc.type.names),
});
} else {
const symbol = {
name: doc.longname,
kind: doc.kind,
description: doc.classdesc || doc.description,
path: path.join(doc.meta.path, doc.meta.filename),
};
if (typeof doc.returns[0].nullable == 'boolean') {
symbol.returns.nullable = doc.returns[0].nullable;
if (doc.augments) {
symbol.extends = doc.augments[0];
}
}
if (doc.tags) {
doc.tags.every(function(tag) {
if (tag.title == 'template') {
symbol.template = tag.value;
return false;
if (doc.virtual) {
symbol.virtual = true;
}
if (doc.type) {
symbol.types = getTypes(doc.type.names);
}
if (doc.params) {
const params = [];
doc.params.forEach(function (param) {
const paramInfo = {
name: param.name,
};
params.push(paramInfo);
paramInfo.types = getTypes(param.type.names);
if (typeof param.variable == 'boolean') {
paramInfo.variable = param.variable;
}
if (typeof param.optional == 'boolean') {
paramInfo.optional = param.optional;
}
if (typeof param.nullable == 'boolean') {
paramInfo.nullable = param.nullable;
}
});
symbol.params = params;
}
if (doc.returns) {
symbol.returns = {
types: getTypes(doc.returns[0].type.names),
};
if (typeof doc.returns[0].nullable == 'boolean') {
symbol.returns.nullable = doc.returns[0].nullable;
}
return true;
});
}
const target = isExterns ? externs : (doc.api ? symbols : base);
const existingSymbol = symbolsByName[symbol.name];
if (existingSymbol) {
const idx = target.indexOf(existingSymbol);
target.splice(idx, 1);
}
target.push(symbol);
symbolsByName[symbol.name] = symbol;
if (doc.api && symbol.extends) {
while (symbol.extends in classes && !classes[symbol.extends].api &&
classes[symbol.extends].augments) {
symbol.extends = classes[symbol.extends].augments[0];
}
if (symbol.extends) {
augments[symbol.extends] = true;
if (doc.tags) {
doc.tags.every(function (tag) {
if (tag.title == 'template') {
symbol.template = tag.value;
return false;
}
return true;
});
}
const target = isExterns ? externs : doc.api ? symbols : base;
const existingSymbol = symbolsByName[symbol.name];
if (existingSymbol) {
const idx = target.indexOf(existingSymbol);
target.splice(idx, 1);
}
target.push(symbol);
symbolsByName[symbol.name] = symbol;
if (doc.api && symbol.extends) {
while (
symbol.extends in classes &&
!classes[symbol.extends].api &&
classes[symbol.extends].augments
) {
symbol.extends = classes[symbol.extends].augments[0];
}
if (symbol.extends) {
augments[symbol.extends] = true;
}
}
}
}
});
base = base.filter(function (symbol) {
return symbol.name in augments || symbol.virtual;
});
base = base.filter(function(symbol) {
return (symbol.name in augments || symbol.virtual);
});
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
process.stdout.write(
JSON.stringify({
symbols: symbols,
defines: defines,
typedefs: typedefs,
externs: externs,
base: base
}, null, 2));
JSON.stringify(
{
symbols: symbols,
defines: defines,
typedefs: typedefs,
externs: externs,
base: base,
},
null,
2
)
);
});
};

View File

@@ -2,15 +2,13 @@
* Handle the interface and abstract annotations.
* @param {Object} dictionary The tag dictionary.
*/
exports.defineTags = function(dictionary) {
exports.defineTags = function (dictionary) {
const classTag = dictionary.lookUp('class');
dictionary.defineTag('interface', {
mustNotHaveValue: true,
onTagged: function(doclet, tag) {
onTagged: function (doclet, tag) {
classTag.onTagged.apply(this, arguments);
doclet.virtual = true;
}
},
});
};