Skip to content

Commit a51a279

Browse files
committed
Revert "Fix and export link function"
e28d259 Turns out the currently released version of documentation-theme-default has a bug and this change will break it. Easiest fix is to revert and rerelease as 2.0.0.
1 parent 0a0b196 commit a51a279

File tree

3 files changed

+23
-64
lines changed

3 files changed

+23
-64
lines changed

index.js

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,10 @@ function t(text) {
66
return u('text', text);
77
}
88

9-
/**
10-
* Helper used to automatically link items to global JS documentation or to internal
11-
* documentation.
12-
*
13-
* @param {String} text - text to potentially link
14-
* @param {function} [getHref] - a function that tries
15-
* to find a URL to point a named link to
16-
* @returns {Object} [mdast](https://www.npmjs.com/package/mdast) node
17-
*/
18-
function link(text, getHref, description) {
19-
var href = (getHref && getHref(text)) || globalsDocs.getDoc(text);
20-
if (href) {
21-
return u('link', { href: href }, [u('text', description || text)]);
9+
function link(text) {
10+
var docs = globalsDocs.getDoc(text);
11+
if (docs) {
12+
return u('link', { href: docs }, [u('text', text)]);
2213
}
2314
return u('text', text);
2415
}
@@ -51,8 +42,8 @@ function decorate(formatted, str, prefix) {
5142
* Helper used to format JSDoc-style type definitions into HTML or Markdown.
5243
*
5344
* @name formatType
54-
* @param {Object} node - type object in doctrine style
55-
* @param {function} getHref - a function that tries
45+
* @param {Object} node type object in doctrine style
46+
* @param {function(text): text} getNamedLink a function that tries
5647
* to find a URL to point a named link to
5748
* @returns {Object[]} array of [mdast](https://www.npmjs.com/package/mdast) syntax trees
5849
* @example
@@ -61,7 +52,7 @@ function decorate(formatted, str, prefix) {
6152
* // {{ type x }}
6253
* // generates String
6354
*/
64-
function formatType(node, getHref) {
55+
function formatType(node, getNamedLink) {
6556
var result = [];
6657

6758
if (!node) {
@@ -78,25 +69,25 @@ function formatType(node, getHref) {
7869
case Syntax.VoidLiteral:
7970
return [t('void')];
8071
case Syntax.UndefinedLiteral:
81-
return [link('undefined', getHref)];
72+
return [link('undefined')];
8273
case Syntax.NameExpression:
83-
return [link(node.name, getHref)];
74+
return [link(node.name)];
8475
case Syntax.ParameterType:
85-
return [t(node.name + ': ')].concat(formatType(node.expression, getHref));
76+
return [t(node.name + ': ')].concat(formatType(node.expression, getNamedLink));
8677

8778
case Syntax.TypeApplication:
88-
return formatType(node.expression, getHref)
89-
.concat(commaList(getHref, node.applications, '.<', '>'));
79+
return formatType(node.expression, getNamedLink)
80+
.concat(commaList(getNamedLink, node.applications, '.<', '>'));
9081
case Syntax.UnionType:
91-
return commaList(getHref, node.elements, '(', ')', '|');
82+
return commaList(getNamedLink, node.elements, '(', ')', '|');
9283
case Syntax.ArrayType:
93-
return commaList(getHref, node.elements, '[', ']');
84+
return commaList(getNamedLink, node.elements, '[', ']');
9485
case Syntax.RecordType:
95-
return commaList(getHref, node.fields, '{', '}');
86+
return commaList(getNamedLink, node.fields, '{', '}');
9687

9788
case Syntax.FieldType:
9889
if (node.value) {
99-
return [t(node.key + ': ')].concat(formatType(node.value, getHref));
90+
return [t(node.key + ': ')].concat(formatType(node.value, getNamedLink));
10091
}
10192
return [t(node.key)];
10293

@@ -110,36 +101,35 @@ function formatType(node, getHref) {
110101
result.push(t('this: '));
111102
}
112103

113-
result = result.concat(formatType(node['this'], getHref));
104+
result = result.concat(formatType(node['this'], getNamedLink));
114105

115106
if (node.params.length !== 0) {
116107
result.push(t(', '));
117108
}
118109
}
119110

120-
result = result.concat(commaList(getHref, node.params, '', ')'));
111+
result = result.concat(commaList(getNamedLink, node.params, '', ')'));
121112

122113
if (node.result) {
123-
result = result.concat([t(': ')].concat(formatType(node.result, getHref)));
114+
result = result.concat([t(': ')].concat(formatType(node.result, getNamedLink)));
124115
}
125116
return result;
126117

127118
case Syntax.RestType:
128119
// note that here we diverge from doctrine itself, which
129120
// lets the expression be omitted.
130-
return decorate(formatType(node.expression, getHref), '...', true);
121+
return decorate(formatType(node.expression, getNamedLink), '...', true);
131122
case Syntax.OptionalType:
132-
return decorate(formatType(node.expression, getHref), '=').concat(
123+
return decorate(formatType(node.expression, getNamedLink), '=').concat(
133124
node.default ? t('(default ' + node.default + ')') : []);
134125
case Syntax.NonNullableType:
135-
return decorate(formatType(node.expression, getHref), '!', node.prefix);
126+
return decorate(formatType(node.expression, getNamedLink), '!', node.prefix);
136127
case Syntax.NullableType:
137-
return decorate(formatType(node.expression, getHref), '?', node.prefix);
128+
return decorate(formatType(node.expression, getNamedLink), '?', node.prefix);
138129

139130
default:
140131
throw new Error('Unknown type ' + node.type);
141132
}
142133
}
143134

144-
module.exports.link = link;
145135
module.exports.formatType = formatType;

test/format_type.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
'use strict';
33

44
var formatType = require('../index').formatType,
5-
link = require('../index').link,
65
remark = require('remark'),
76
parse = require('doctrine').parse,
87
test = require('tap').test;
@@ -46,12 +45,6 @@ test('formatType', function (t) {
4645
parse('@param {number} [a=1]', { sloppy: true }).tags[0].type)
4746
}), '[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)=', 'default');
4847

49-
t.deepEqual(remark().stringify({
50-
type: 'paragraph',
51-
children: formatType(
52-
parse('@param {Foo} a', { sloppy: true }).tags[0].type, function () { return '#Foo' })
53-
}), '[Foo](#Foo)', 'with getHref');
54-
5548
t.deepEqual(formatType(), [], 'empty case');
5649

5750
t.throws(function () {

test/link.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)