Skip to content

Commit 7ccf89d

Browse files
authored
Fix linkerStack resolution order (#564)
1 parent 145c199 commit 7ccf89d

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lib/output/util/linker_stack.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ function LinkerStack(config) {
4343
this.stack = [];
4444

4545
if (config.defaultGlobals !== false) {
46-
this.stack.push(function (namespace) {
46+
this.stack.unshift(function (namespace) {
4747
if (namespace) {
4848
return globalsDocs.getDoc(namespace, config.defaultGlobalsEnvs);
4949
}
5050
});
5151
}
5252

5353
if (config.paths) {
54-
this.stack.push(pathsLinker(config.paths));
54+
this.stack.unshift(pathsLinker(config.paths));
5555
}
5656

5757
this.link = this.link.bind(this);
@@ -84,7 +84,7 @@ LinkerStack.prototype.namespaceResolver = function (comments, resolver) {
8484
walk(comments, function (comment) {
8585
namespaces[comment.namespace] = true;
8686
});
87-
this.stack.push(function (namespace) {
87+
this.stack.unshift(function (namespace) {
8888
if (namespaces[namespace] === true) {
8989
return resolver(namespace);
9090
}

test/linker.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,31 @@ test('linkerStack', function (t) {
1717
'http://geojson.org/geojson-spec.html#point',
1818
'Custom hardcoded path for a GeoJSON type');
1919

20+
21+
t.equal(createLinkerStack({
22+
paths: {
23+
Image: 'http://custom.com/'
24+
}
25+
}).link('Image'),
26+
'http://custom.com/',
27+
'Prefers config link to native.');
28+
29+
30+
var linker = createLinkerStack({
31+
paths: {
32+
Image: 'http://custom.com/'
33+
}
34+
});
35+
36+
linker.namespaceResolver([{
37+
namespace: 'Image',
38+
}], function (namespace) {
39+
return '#' + namespace;
40+
});
41+
42+
t.equal(linker.link('Image'),
43+
'#Image',
44+
'Prefers local link over all.');
45+
2046
t.end();
2147
});

0 commit comments

Comments
 (0)