Skip to content

Commit 831d812

Browse files
fix(Param): fix default value shorthand declaration
Closes #1554
1 parent 74aa609 commit 831d812

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/urlMatcherFactory.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -864,27 +864,23 @@ function $UrlMatcherFactory() {
864864

865865
this.Param = function Param(id, type, config, location) {
866866
var self = this;
867-
var defaultValueConfig = getDefaultValueConfig(config);
868-
config = config || {};
867+
config = unwrapShorthand(config);
869868
type = getType(config, type);
870869
var arrayMode = getArrayMode();
871870
type = arrayMode ? type.$asArray(arrayMode, location === "search") : type;
872-
if (type.name === "string" && !arrayMode && location === "path" && defaultValueConfig.value === undefined)
873-
defaultValueConfig.value = ""; // for 0.2.x; in 0.3.0+ do not automatically default to ""
874-
var isOptional = defaultValueConfig.value !== undefined;
871+
if (type.name === "string" && !arrayMode && location === "path" && config.value === undefined)
872+
config.value = ""; // for 0.2.x; in 0.3.0+ do not automatically default to ""
873+
var isOptional = config.value !== undefined;
875874
var squash = getSquashPolicy(config, isOptional);
876875
var replace = getReplace(config, arrayMode, isOptional, squash);
877876

878-
function getDefaultValueConfig(config) {
877+
function unwrapShorthand(config) {
879878
var keys = isObject(config) ? objectKeys(config) : [];
880879
var isShorthand = indexOf(keys, "value") === -1 && indexOf(keys, "type") === -1 &&
881880
indexOf(keys, "squash") === -1 && indexOf(keys, "array") === -1;
882-
var configValue = isShorthand ? config : config.value;
883-
var result = {
884-
fn: isInjectable(configValue) ? configValue : function () { return result.value; },
885-
value: configValue
886-
};
887-
return result;
881+
if (isShorthand) config = { value: config };
882+
config.$$fn = isInjectable(config.value) ? config.value : function () { return config.value; };
883+
return config;
888884
}
889885

890886
function getType(config, urlType) {
@@ -929,7 +925,7 @@ function $UrlMatcherFactory() {
929925
*/
930926
function $$getDefaultValue() {
931927
if (!injector) throw new Error("Injectable functions cannot be called at configuration time");
932-
return injector.invoke(defaultValueConfig.fn);
928+
return injector.invoke(config.$$fn);
933929
}
934930

935931
/**

0 commit comments

Comments
 (0)