Skip to content

Commit 2bd8657

Browse files
committed
factor test-value out of the project
1 parent e206a5d commit 2bd8657

File tree

3 files changed

+19
-65
lines changed

3 files changed

+19
-65
lines changed

lib/transform.js

+17-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const testValue = require('test-value')
2-
const where = testValue.where
31
const arrayify = require('array-back')
42
const omit = require('lodash.omit')
53
const findReplace = require('find-replace')
@@ -55,14 +53,20 @@ function transform (data) {
5553
return doclet
5654
})
5755

58-
const exported = json.filter(where({ isExported: true }))
56+
const exported = json.filter(i => i.isExported === true)
5957
const newIDs = exported.map(d => d.id)
6058

61-
newIDs.forEach(function (newID) {
62-
update(json, { isExported: undefined, '!kind': 'module' }, function (doclet) {
63-
return updateIDReferences(doclet, newID)
64-
})
65-
})
59+
for (const newID of newIDs) {
60+
for (let i = 0; i < json.length; i++) {
61+
const doclet = json[i]
62+
if (doclet.isExported === undefined && doclet.kind !== 'module') {
63+
const values = updateIDReferences(doclet, newID)
64+
for (const prop in values) {
65+
if (values[prop] !== undefined) doclet[prop] = values[prop]
66+
}
67+
}
68+
}
69+
}
6670

6771
json = removeEnumChildren(json)
6872
json = json.map(removeUnwanted)
@@ -175,17 +179,11 @@ hence the need for these four functions */
175179
function getEs6Constructor (data, parent) {
176180
return data.find(i => isES6Constructor(i) && i.memberof === parent.longname)
177181
}
178-
function isES6Class (doclet) {
179-
return testValue(doclet, {
180-
kind: 'class',
181-
meta: { code: { type: 'ClassDeclaration' } }
182-
})
182+
function isES6Class (doclet = {}) {
183+
return doclet.kind === 'class' && doclet.meta && doclet.meta.code && doclet.meta.code.type === 'ClassDeclaration'
183184
}
184185
function isES6Constructor (doclet) {
185-
return testValue(doclet, {
186-
kind: 'class',
187-
meta: { code: { type: 'MethodDefinition' } }
188-
})
186+
return doclet.kind === 'class' && doclet.meta && doclet.meta.code && doclet.meta.code.type === 'MethodDefinition'
189187
}
190188

191189
function replaceID (id, oldID, newID) {
@@ -356,17 +354,6 @@ function sortIdentifier (doclet) {
356354
})
357355
}
358356

359-
function update (array, query, newValues) {
360-
for (let i = 0; i < array.length; i++) {
361-
if (testValue(array[i], query)) {
362-
const values = typeof newValues === 'function' ? newValues(array[i]) : newValues
363-
for (const prop in values) {
364-
if (values[prop] !== undefined) array[i][prop] = values[prop]
365-
}
366-
}
367-
}
368-
}
369-
370357
function renameThisProperty (doclet) {
371358
doclet.thisvalue = doclet.this
372359
delete doclet.this
@@ -386,7 +373,7 @@ function fixES6ConstructorMemberLongnames (data) {
386373
if (isES6Class(i)) {
387374
const es6constructor = getEs6Constructor(data, i)
388375
if (es6constructor) {
389-
const constructorChildren = data.filter(where({ memberof: es6constructor.longname }))
376+
const constructorChildren = data.filter(c => c.memberof === es6constructor.longname)
390377
constructorChildren.forEach(child => {
391378
child.memberof = i.longname
392379
})
@@ -407,7 +394,7 @@ function convertIsEnumFlagToKind (doclet) {
407394
/* remove properties which have enum parents.. depends on convertIsEnumFlagToKind */
408395
function removeEnumChildren (json) {
409396
return json.filter(function (doclet) {
410-
const parent = json.find(where({ id: doclet.memberof }))
397+
const parent = json.find(i => i.id === doclet.memberof)
411398
if (parent && parent.kind === 'enum') {
412399
return false
413400
} else {

package-lock.json

+1-33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
"array-back": "^6.2.2",
2626
"find-replace": "^5.0.1",
2727
"lodash.omit": "^4.5.0",
28-
"sort-array": "^5.0.0",
29-
"test-value": "^3.0.0"
28+
"sort-array": "^5.0.0"
3029
},
3130
"devDependencies": {
3231
"test-runner": "^0.10.1"

0 commit comments

Comments
 (0)