esdoc
Advanced tools
Comparing version 0.5.1 to 0.5.2
# Changelog | ||
## 0.5.2 (2017-01-02) | ||
- **Fix** | ||
- Display error message when invalid function type ([#351](https://github.com/esdoc/esdoc/issues/351)) Thanks [@LukasHechenberger](https://github.com/LukasHechenberger) | ||
- Crash when destructure sparse array ([#350](https://github.com/esdoc/esdoc/issues/350)) | ||
- Crash when guess type of array detructuring ([#301](https://github.com/esdoc/esdoc/issues/301)) | ||
- A union type in a generics type ([eb051e7](https://github.com/esdoc/esdoc/commit/eb051e729b83bca552a3d4b43351dc1272ee4154)) | ||
- A union type with a spread type ([199d834](https://github.com/esdoc/esdoc/commit/199d834cfe68ba986212b51cb59ea2d9de55ba1c)) | ||
- Crash when function was assigned by member expression ([e59820a](https://github.com/esdoc/esdoc/commit/e59820aed2f3e2091f32d35de34925d0132630e0)) | ||
- Broken to guess type when property has null value or object expression using string key ([5920c1f](https://github.com/esdoc/esdoc/commit/5920c1f91633202ec795f360bb0ac12f68f258f2)) | ||
- Crash when guess type of return value that has object spread ([#364](https://github.com/esdoc/esdoc/pull/364)) Thanks [vovkasm](https://github.com/vovkasm) | ||
- **Feat** | ||
- Automatically take a super class description if the method override a super class method. ([7b515f0](https://github.com/esdoc/esdoc/commit/7b515f0367a386ceb732b4606b96abf24bfab627)) | ||
## 0.5.1 (2016-12-26) | ||
@@ -4,0 +17,0 @@ - **Fix** |
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _babelGenerator = require('babel-generator'); | ||
var _babelGenerator2 = _interopRequireDefault(_babelGenerator); | ||
var _AbstractDoc = require('./AbstractDoc.js'); | ||
@@ -38,4 +42,5 @@ | ||
if (this._node.id.type === 'MemberExpression') { | ||
// todo: can not reproduce this condition. | ||
// this._value.name = ASTUtil.flattenMemberExpression(this._node.id); | ||
// e.g. foo[bar.baz] = function bal(){} | ||
const expression = (0, _babelGenerator2.default)(this._node.id).code; | ||
this._value.name = `[${ expression }]`; | ||
} else { | ||
@@ -42,0 +47,0 @@ this._value.name = this._node.id.name; |
@@ -37,8 +37,10 @@ 'use strict'; | ||
case 'ObjectPattern': | ||
// TODO: optimize | ||
// TODO: optimize for multi variables. | ||
// e.g. export const {a, b} = obj | ||
this._value.name = this._node.declarations[0].id.properties[0].key.name; | ||
break; | ||
case 'ArrayPattern': | ||
// TODO: optimize | ||
this._value.name = this._node.declarations[0].id.elements[0].name; | ||
// TODO: optimize for multi variables. | ||
// e.g. export cont [a, b] = arr | ||
this._value.name = this._node.declarations[0].id.elements.find(v => v).name; | ||
break; | ||
@@ -45,0 +47,0 @@ default: |
@@ -136,3 +136,8 @@ 'use strict'; | ||
publisher(results, asts, config); | ||
try { | ||
publisher(results, asts, config); | ||
} catch (e) { | ||
_InvalidCodeLogger2.default.showError(e); | ||
process.exit(1); | ||
} | ||
@@ -139,0 +144,0 @@ _Plugin2.default.onComplete(); |
@@ -68,6 +68,21 @@ 'use strict'; | ||
if (name) { | ||
match = value.match(/^(\S+)/); | ||
if (match) { | ||
paramName = match[1]; | ||
value = value.replace(/^\S+\s*/, ''); | ||
if (value.charAt(0) === '[') { | ||
paramName = ''; | ||
let counter = 0; | ||
for (const c of value) { | ||
paramName += c; | ||
if (c === '[') counter++; | ||
if (c === ']') counter--; | ||
if (counter === 0) break; | ||
} | ||
if (paramName) { | ||
value = value.substr(paramName.length).trim(); | ||
} | ||
} else { | ||
match = value.match(/^(\S+)/); | ||
if (match) { | ||
paramName = match[1]; | ||
value = value.replace(/^\S+\s*/, ''); | ||
} | ||
} | ||
@@ -122,3 +137,13 @@ } | ||
} else if (typeText.includes('|')) { | ||
result.types = typeText.split('|'); | ||
if (typeText.match(/<.*?\|.*?>/)) { | ||
// union in generics. e.g. `Array<string|number>` | ||
// hack: in this case, process this type in DocBuilder#_buildTypeDocLinkHTML | ||
result.types = [typeText]; | ||
} else if (typeText.match(/^\.\.\.\(.*?\)/)) { | ||
// union with spread. e.g. `...(string|number)` | ||
// hack: in this case, process this type in DocBuilder#_buildTypeDocLinkHTML | ||
result.types = [typeText]; | ||
} else { | ||
result.types = typeText.split('|'); | ||
} | ||
} else { | ||
@@ -162,3 +187,3 @@ result.types = [typeText]; | ||
result.name = pair[0]; | ||
result.name = pair[0].trim(); | ||
} | ||
@@ -172,2 +197,3 @@ | ||
/* eslint-disable complexity */ | ||
/* eslint-disable max-statements */ | ||
/** | ||
@@ -276,2 +302,28 @@ * guess param type by using param default arguments. | ||
} | ||
case 'ArrayPattern': | ||
{ | ||
// e.g. func([a, b = 10]){} | ||
let arrayType = null; | ||
const raw = []; | ||
for (const element of param.elements) { | ||
if (element.type === 'Identifier') { | ||
raw.push('null'); | ||
} else if (element.type === 'AssignmentPattern') { | ||
if ('value' in element.right) { | ||
if (!arrayType && element.right.value !== null) arrayType = typeof element.right.value; | ||
raw.push(JSON.stringify(element.right.value)); | ||
} else { | ||
raw.push('*'); | ||
} | ||
} | ||
} | ||
if (!arrayType) arrayType = '*'; | ||
result.name = `arrayPattern${ i === 0 ? '' : i }`; | ||
result.types = [`${ arrayType }[]`]; | ||
result.defaultRaw = raw; | ||
result.defaultValue = `[${ raw.join(', ') }]`; | ||
break; | ||
} | ||
default: | ||
@@ -331,2 +383,6 @@ logger.w('unknown param.type', param); | ||
if (right.type === 'NullLiteral') { | ||
return { types: ['*'] }; | ||
} | ||
if (right.type.includes('Literal')) { | ||
@@ -349,9 +405,24 @@ return { types: [typeof right.value] }; | ||
case 'ObjectProperty': | ||
typeMap[prop.key.name] = typeof prop.value.value; | ||
break; | ||
{ | ||
const name = `"${ prop.key.name || prop.key.value }"`; | ||
typeMap[name] = prop.value.value ? typeof prop.value.value : '*'; | ||
break; | ||
} | ||
case 'ObjectMethod': | ||
typeMap[prop.key.name] = 'function'; | ||
break; | ||
{ | ||
const name = `"${ prop.key.name || prop.key.value }"`; | ||
typeMap[name] = 'function'; | ||
break; | ||
} | ||
case 'SpreadProperty': | ||
{ | ||
const name = `...${ prop.argument.name }`; | ||
typeMap[name] = 'Object'; | ||
break; | ||
} | ||
default: | ||
typeMap[prop.key.name] = '*'; | ||
{ | ||
const name = `"${ prop.key.name || prop.key.value }"`; | ||
typeMap[name] = '*'; | ||
} | ||
} | ||
@@ -362,3 +433,3 @@ } | ||
for (const key of Object.keys(typeMap)) { | ||
types.push(`"${ key }": ${ typeMap[key] }`); | ||
types.push(`${ key }: ${ typeMap[key] }`); | ||
} | ||
@@ -365,0 +436,0 @@ |
@@ -483,3 +483,3 @@ 'use strict'; | ||
ice.load('signature', this._buildSignatureHTML(doc)); | ||
ice.load('description', doc.description); | ||
ice.load('description', doc.description || this._buildOverrideMethodDescription(doc)); | ||
ice.text('abstract', doc.abstract ? 'abstract' : ''); | ||
@@ -752,2 +752,4 @@ ice.text('access', doc.access); | ||
const tmp = v.split(':').map(v => v.trim()); | ||
if (tmp.length !== 2) throw new SyntaxError(`Invalid function type annotation: \`${ matched[0] }\``); | ||
const paramName = tmp[0]; | ||
@@ -804,4 +806,6 @@ const typeName = tmp[1].replace(/\\Z/g, ',').replace(/\\Y/g, ':'); | ||
const innerTypes = inner.split(',').map(v => { | ||
v = v.trim().replace(/\\Z/g, ',').replace(/\\Y/g, ':'); | ||
return this._buildTypeDocLinkHTML(v); | ||
return v.split('|').map(vv => { | ||
vv = vv.trim().replace(/\\Z/g, ',').replace(/\\Y/g, ':'); | ||
return this._buildTypeDocLinkHTML(vv); | ||
}).join('|'); | ||
}); | ||
@@ -815,3 +819,9 @@ | ||
typeName = typeName.replace('...', ''); | ||
return `...${ this._buildDocLinkHTML(typeName) }`; | ||
if (typeName.includes('|')) { | ||
const typeNames = typeName.replace('(', '').replace(')', '').split('|'); | ||
const typeLinks = typeNames.map(v => this._buildDocLinkHTML(v)); | ||
return `...(${ typeLinks.join('|') })`; | ||
} else { | ||
return `...${ this._buildDocLinkHTML(typeName) }`; | ||
} | ||
} else if (typeName.indexOf('?') === 0) { | ||
@@ -1053,2 +1063,27 @@ typeName = typeName.replace('?', ''); | ||
/** | ||
* build method of ancestor class description. | ||
* @param {DocObject} doc - target doc object. | ||
* @returns {string} description. if doc does not override ancestor method, returns empty. | ||
* @private | ||
*/ | ||
_buildOverrideMethodDescription(doc) { | ||
const parentDoc = this._findByName(doc.memberof)[0]; | ||
if (!parentDoc) return ''; | ||
if (!parentDoc._custom_extends_chains) return ''; | ||
const chains = [...parentDoc._custom_extends_chains].reverse(); | ||
for (const longname of chains) { | ||
const superClassDoc = this._findByName(longname)[0]; | ||
if (!superClassDoc) continue; | ||
const superMethodDoc = this._find({ name: doc.name, memberof: superClassDoc.longname })[0]; | ||
if (!superMethodDoc) continue; | ||
if (superMethodDoc.description) return superMethodDoc.description; | ||
} | ||
return ''; | ||
} | ||
_buildDecoratorHTML(doc) { | ||
@@ -1055,0 +1090,0 @@ if (!doc.decorators) return ''; |
@@ -255,3 +255,9 @@ 'use strict'; | ||
let superClassDoc = this._builder._findByName(doc.extends[0])[0]; | ||
if (superClassDoc) { | ||
// this is circular extends | ||
if (superClassDoc.longname === selfDoc.longname) { | ||
break; | ||
} | ||
chains.push(superClassDoc.longname); | ||
@@ -258,0 +264,0 @@ doc = superClassDoc; |
@@ -78,3 +78,3 @@ 'use strict'; | ||
const availableTags = ['span', 'a', 'p', 'div', 'img', 'h1', 'h2', 'h3', 'h4', 'h5', 'br', 'hr', 'li', 'ul', 'ol', 'code', 'pre']; | ||
const availableAttributes = ['src', 'href', 'title', 'class', 'id', 'name', 'width', 'height']; | ||
const availableAttributes = ['src', 'href', 'title', 'class', 'id', 'name', 'width', 'height', 'target']; | ||
@@ -81,0 +81,0 @@ const compiled = (0, _marked2.default)(text, { |
@@ -57,2 +57,12 @@ 'use strict'; | ||
/** | ||
* show error log. | ||
* @param {Error} error - target error. | ||
*/ | ||
showError(error) { | ||
console.log('[31m'); | ||
console.log(error); | ||
console.log('[0m'); | ||
} | ||
/** | ||
* show log. | ||
@@ -59,0 +69,0 @@ * @param {string} filePath - invalid code in this file. |
{ | ||
"name": "esdoc", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Good Documentation Generator For JavaScript", | ||
@@ -26,3 +26,3 @@ "author": "h13i32maru", | ||
"dependencies": { | ||
"cheerio": "0.20.0", | ||
"cheerio": "0.22.0", | ||
"color-logger": "0.0.3", | ||
@@ -33,3 +33,3 @@ "escape-html": "1.0.3", | ||
"babel-traverse": "6.12.0", | ||
"fs-extra": "0.30.0", | ||
"fs-extra": "1.0.0", | ||
"ice-cap": "0.0.4", | ||
@@ -45,4 +45,3 @@ "marked": "0.3.6", | ||
"codecov": "1.0.1", | ||
"docpad": "6.78.6", | ||
"esdoc-importpath-plugin": "0.0.1", | ||
"esdoc-importpath-plugin": "0.1.0", | ||
"eslint": "3.6.0", | ||
@@ -49,0 +48,0 @@ "http-server": "0.9.0", |
@@ -9,3 +9,4 @@ <!--![Owner Status](https://img.shields.io/badge/owner-busy-red.svg)--> | ||
ESDoc is a documentation generator for JavaScript(ES2015 or later). | ||
ESDoc is a documentation generator for JavaScript.<br/> | ||
Please <a href="https://try.esdoc.org">try it out</a>! | ||
@@ -50,4 +51,2 @@ <img class="screen-shot" src="https://esdoc.org/manual/asset/image/top.png" width="500px" style="max-width: 500px; border: 1px solid rgba(0,0,0,0.1); box-shadow: 1px 1px 1px rgba(0,0,0,0.5);"> | ||
[roadmap of v1.0.0](https://github.com/esdoc/esdoc/issues/293) | ||
# License | ||
@@ -54,0 +53,0 @@ MIT |
358974
10
8200
55
+ Addedcheerio@0.22.0(transitive)
+ Addeddomhandler@2.4.2(transitive)
+ Addedfs-extra@1.0.0(transitive)
+ Addedhtmlparser2@3.10.1(transitive)
+ Addedlodash.assignin@4.2.0(transitive)
+ Addedlodash.bind@4.2.1(transitive)
+ Addedlodash.defaults@4.2.0(transitive)
+ Addedlodash.filter@4.6.0(transitive)
+ Addedlodash.flatten@4.4.0(transitive)
+ Addedlodash.foreach@4.5.0(transitive)
+ Addedlodash.map@4.6.0(transitive)
+ Addedlodash.merge@4.6.2(transitive)
+ Addedlodash.pick@4.4.0(transitive)
+ Addedlodash.reduce@4.6.0(transitive)
+ Addedlodash.reject@4.6.0(transitive)
+ Addedlodash.some@4.6.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedfs-extra@0.30.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedinflight@1.0.6(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedcheerio@0.22.0
Updatedfs-extra@1.0.0