From 7ccf89d83cee4f4b97cae3deee63ffdfbfe8a886 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 11 Oct 2016 18:08:13 -0400 Subject: [PATCH] Fix linkerStack resolution order (#564) --- lib/output/util/linker_stack.js | 6 +++--- test/linker.js | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/output/util/linker_stack.js b/lib/output/util/linker_stack.js index 7a6346d..951a096 100644 --- a/lib/output/util/linker_stack.js +++ b/lib/output/util/linker_stack.js @@ -43,7 +43,7 @@ function LinkerStack(config) { this.stack = []; if (config.defaultGlobals !== false) { - this.stack.push(function (namespace) { + this.stack.unshift(function (namespace) { if (namespace) { return globalsDocs.getDoc(namespace, config.defaultGlobalsEnvs); } @@ -51,7 +51,7 @@ function LinkerStack(config) { } if (config.paths) { - this.stack.push(pathsLinker(config.paths)); + this.stack.unshift(pathsLinker(config.paths)); } this.link = this.link.bind(this); @@ -84,7 +84,7 @@ LinkerStack.prototype.namespaceResolver = function (comments, resolver) { walk(comments, function (comment) { namespaces[comment.namespace] = true; }); - this.stack.push(function (namespace) { + this.stack.unshift(function (namespace) { if (namespaces[namespace] === true) { return resolver(namespace); } diff --git a/test/linker.js b/test/linker.js index 501fc76..f3cca7c 100644 --- a/test/linker.js +++ b/test/linker.js @@ -17,5 +17,31 @@ test('linkerStack', function (t) { 'http://geojson.org/geojson-spec.html#point', 'Custom hardcoded path for a GeoJSON type'); + + t.equal(createLinkerStack({ + paths: { + Image: 'http://custom.com/' + } + }).link('Image'), + 'http://custom.com/', + 'Prefers config link to native.'); + + + var linker = createLinkerStack({ + paths: { + Image: 'http://custom.com/' + } + }); + + linker.namespaceResolver([{ + namespace: 'Image', + }], function (namespace) { + return '#' + namespace; + }); + + t.equal(linker.link('Image'), + '#Image', + 'Prefers local link over all.'); + t.end(); });