typedoc-plugin-resolve-crossmodule-references
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -10,79 +10,93 @@ "use strict"; | ||
function visitReflection(context, reflection) { | ||
if (!isTypedReflection(reflection)) | ||
if (isTypedReflection(reflection)) { | ||
recursivelyFixTyped(context, reflection, 'type'); | ||
} | ||
if (reflection instanceof typedoc_1.DeclarationReflection) { | ||
recursivelyFixTyped(context, reflection, 'extendedTypes'); | ||
recursivelyFixTyped(context, reflection, 'implementedTypes'); | ||
} | ||
} | ||
function recursivelyFixTyped(context, typed, f) { | ||
fixTyped(context, typed, f); | ||
const typedField = typed[f]; | ||
if (!typedField) | ||
return; | ||
checkTyped(context, reflection, 'type'); | ||
reflection.type?.visit((0, typedoc_1.makeRecursiveVisitor)({ | ||
const visitor = (0, typedoc_1.makeRecursiveVisitor)({ | ||
array(type) { | ||
checkTyped(context, type, 'elementType'); | ||
fixTyped(context, type, 'elementType'); | ||
}, | ||
conditional(type) { | ||
checkTyped(context, type, 'checkType'); | ||
checkTyped(context, type, 'trueType'); | ||
checkTyped(context, type, 'falseType'); | ||
checkTyped(context, type, 'extendsType'); | ||
fixTyped(context, type, 'checkType'); | ||
fixTyped(context, type, 'trueType'); | ||
fixTyped(context, type, 'falseType'); | ||
fixTyped(context, type, 'extendsType'); | ||
}, | ||
indexedAccess(type) { | ||
checkTyped(context, type, 'indexType'); | ||
checkTyped(context, type, 'objectType'); | ||
fixTyped(context, type, 'indexType'); | ||
fixTyped(context, type, 'objectType'); | ||
}, | ||
intersection(type) { | ||
checkTyped(context, type, 'types'); | ||
fixTyped(context, type, 'types'); | ||
}, | ||
mapped(type) { | ||
checkTyped(context, type, 'nameType'); | ||
checkTyped(context, type, 'parameterType'); | ||
checkTyped(context, type, 'templateType'); | ||
fixTyped(context, type, 'nameType'); | ||
fixTyped(context, type, 'parameterType'); | ||
fixTyped(context, type, 'templateType'); | ||
}, | ||
'named-tuple-member'(type) { | ||
checkTyped(context, type, 'element'); | ||
fixTyped(context, type, 'element'); | ||
}, | ||
optional(type) { | ||
checkTyped(context, type, 'elementType'); | ||
fixTyped(context, type, 'elementType'); | ||
}, | ||
predicate(type) { | ||
checkTyped(context, type, 'targetType'); | ||
fixTyped(context, type, 'targetType'); | ||
}, | ||
query(type) { | ||
checkTyped(context, type, 'queryType'); | ||
fixTyped(context, type, 'queryType'); | ||
}, | ||
reference(type) { | ||
checkTyped(context, type, 'typeArguments'); | ||
fixTyped(context, type, 'typeArguments'); | ||
}, | ||
reflection(type) { | ||
checkTyped(context, type.declaration, 'type'); | ||
fixTyped(context, type.declaration, 'type'); | ||
}, | ||
rest(type) { | ||
checkTyped(context, type, 'elementType'); | ||
fixTyped(context, type, 'elementType'); | ||
}, | ||
tuple(type) { | ||
checkTyped(context, type, 'elements'); | ||
fixTyped(context, type, 'elements'); | ||
}, | ||
// FIXME template-literal? | ||
typeOperator(type) { | ||
checkTyped(context, type, 'target'); | ||
fixTyped(context, type, 'target'); | ||
}, | ||
union(type) { | ||
checkTyped(context, type, 'types'); | ||
fixTyped(context, type, 'types'); | ||
}, | ||
})); | ||
}); | ||
if (Array.isArray(typedField)) { | ||
typedField.forEach((type) => type.visit(visitor)); | ||
} | ||
else { | ||
typedField.visit(visitor); | ||
} | ||
} | ||
function checkTyped(context, typed, f) { | ||
const type = typed[f]; | ||
if (Array.isArray(type)) { | ||
type.forEach((iType, i) => { | ||
if (!isReferenceType(iType)) | ||
return; | ||
type[i] = fixType(context, iType); | ||
function fixTyped(context, typed, field) { | ||
const typedField = typed[field]; | ||
if (!typedField) | ||
return; | ||
if (Array.isArray(typedField)) { | ||
typedField.forEach((iType, i) => { | ||
typedField[i] = fixType(context, iType); | ||
}); | ||
} | ||
else { | ||
if (!isReferenceType(type)) | ||
return; | ||
typed[f] = fixType(context, type); | ||
typed[field] = fixType(context, typedField); | ||
} | ||
} | ||
function fixType(context, type) { | ||
if (!isReferenceTypeBroken(type)) | ||
return type; | ||
return findReferenceType(type, context.project) ?? type; | ||
if (isReferenceType(type) && isReferenceTypeBroken(type)) | ||
return findReferenceType(type, context.project); | ||
return type; | ||
} | ||
@@ -92,7 +106,7 @@ function findReferenceType(type, project) { | ||
if (!newTargetReflection) | ||
return null; | ||
return type; | ||
return typedoc_1.ReferenceType.createResolvedReference(type.name, newTargetReflection, project); | ||
} | ||
function isReferenceType(type) { | ||
return type?.type === 'reference'; | ||
return type.type === 'reference'; | ||
} | ||
@@ -99,0 +113,0 @@ function isReferenceTypeBroken(type) { |
{ | ||
"name": "typedoc-plugin-resolve-crossmodule-references", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "TypeDoc plugin for resolving cross module reference in a mono-repository", | ||
@@ -5,0 +5,0 @@ "main": "dist", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17502
119