diff --git a/lib/transform.js b/lib/transform.js index b2d43c1..cfff5b0 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -1,5 +1,3 @@ -const testValue = require('test-value') -const where = testValue.where const arrayify = require('array-back') const omit = require('lodash.omit') const findReplace = require('find-replace') @@ -55,14 +53,20 @@ function transform (data) { return doclet }) - const exported = json.filter(where({ isExported: true })) + const exported = json.filter(i => i.isExported === true) const newIDs = exported.map(d => d.id) - newIDs.forEach(function (newID) { - update(json, { isExported: undefined, '!kind': 'module' }, function (doclet) { - return updateIDReferences(doclet, newID) - }) - }) + for (const newID of newIDs) { + for (let i = 0; i < json.length; i++) { + const doclet = json[i] + if (doclet.isExported === undefined && doclet.kind !== 'module') { + const values = updateIDReferences(doclet, newID) + for (const prop in values) { + if (values[prop] !== undefined) doclet[prop] = values[prop] + } + } + } + } json = removeEnumChildren(json) json = json.map(removeUnwanted) @@ -175,17 +179,11 @@ hence the need for these four functions */ function getEs6Constructor (data, parent) { return data.find(i => isES6Constructor(i) && i.memberof === parent.longname) } -function isES6Class (doclet) { - return testValue(doclet, { - kind: 'class', - meta: { code: { type: 'ClassDeclaration' } } - }) +function isES6Class (doclet = {}) { + return doclet.kind === 'class' && doclet.meta && doclet.meta.code && doclet.meta.code.type === 'ClassDeclaration' } function isES6Constructor (doclet) { - return testValue(doclet, { - kind: 'class', - meta: { code: { type: 'MethodDefinition' } } - }) + return doclet.kind === 'class' && doclet.meta && doclet.meta.code && doclet.meta.code.type === 'MethodDefinition' } function replaceID (id, oldID, newID) { @@ -356,17 +354,6 @@ function sortIdentifier (doclet) { }) } -function update (array, query, newValues) { - for (let i = 0; i < array.length; i++) { - if (testValue(array[i], query)) { - const values = typeof newValues === 'function' ? newValues(array[i]) : newValues - for (const prop in values) { - if (values[prop] !== undefined) array[i][prop] = values[prop] - } - } - } -} - function renameThisProperty (doclet) { doclet.thisvalue = doclet.this delete doclet.this @@ -386,7 +373,7 @@ function fixES6ConstructorMemberLongnames (data) { if (isES6Class(i)) { const es6constructor = getEs6Constructor(data, i) if (es6constructor) { - const constructorChildren = data.filter(where({ memberof: es6constructor.longname })) + const constructorChildren = data.filter(c => c.memberof === es6constructor.longname) constructorChildren.forEach(child => { child.memberof = i.longname }) @@ -407,7 +394,7 @@ function convertIsEnumFlagToKind (doclet) { /* remove properties which have enum parents.. depends on convertIsEnumFlagToKind */ function removeEnumChildren (json) { return json.filter(function (doclet) { - const parent = json.find(where({ id: doclet.memberof })) + const parent = json.find(i => i.id === doclet.memberof) if (parent && parent.kind === 'enum') { return false } else { diff --git a/package-lock.json b/package-lock.json index c2b6b55..9271edb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,8 +12,7 @@ "array-back": "^6.2.2", "find-replace": "^5.0.1", "lodash.omit": "^4.5.0", - "sort-array": "^5.0.0", - "test-value": "^3.0.0" + "sort-array": "^5.0.0" }, "devDependencies": { "test-runner": "^0.10.1" @@ -677,37 +676,6 @@ "node": ">=12.17" } }, - "node_modules/test-value": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/test-value/-/test-value-3.0.0.tgz", - "integrity": "sha512-sVACdAWcZkSU9x7AOmJo5TqE+GyNJknHaHsMrR6ZnhjVlVN9Yx6FjHrsKZ3BjIpPCT68zYesPWkakrNupwfOTQ==", - "license": "MIT", - "dependencies": { - "array-back": "^2.0.0", - "typical": "^2.6.1" - }, - "engines": { - "node": ">=4.0.0" - } - }, - "node_modules/test-value/node_modules/array-back": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/array-back/-/array-back-2.0.0.tgz", - "integrity": "sha512-eJv4pLLufP3g5kcZry0j6WXpIbzYw9GUB4mVJZno9wfwiBxbizTnHCw3VJb07cBihbFX48Y7oSrW9y+gt4glyw==", - "license": "MIT", - "dependencies": { - "typical": "^2.6.1" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/test-value/node_modules/typical": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/typical/-/typical-2.6.1.tgz", - "integrity": "sha512-ofhi8kjIje6npGozTip9Fr8iecmYfEbS06i0JnIg+rh51KakryWF4+jX8lLKZVhy6N+ID45WYSFCxPOdTWCzNg==", - "license": "MIT" - }, "node_modules/typical": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/typical/-/typical-7.1.1.tgz", diff --git a/package.json b/package.json index feeade7..c183be6 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,7 @@ "array-back": "^6.2.2", "find-replace": "^5.0.1", "lodash.omit": "^4.5.0", - "sort-array": "^5.0.0", - "test-value": "^3.0.0" + "sort-array": "^5.0.0" }, "devDependencies": { "test-runner": "^0.10.1"