Skip to content

Commit 4a06071

Browse files
committed
ensuring config object exists
1 parent 52fdd83 commit 4a06071

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

extension.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,31 @@ module.exports = new Extension({
3838
* @param {object} tokens Original tokens for this extension
3939
*/
4040
function _extendTokens(args, tokens) {
41-
var _tokens = {},
42-
expectedKeys = ['flags'];
41+
// if we have an args object, there might be properties we want to
42+
// migrate into the tokens object.
43+
if (typeof(args) === 'object') {
4344

44-
// shallow-copy the original tokens object
45-
for (let key in tokens) {
46-
_tokens[key] = tokens[key];
47-
}
45+
var _tokens = {},
46+
expectedKeys = ['flags'];
4847

49-
// copy expected arguments from args to the new tokens object
50-
// defaulting to an emptystring
51-
for (let key of expectedKeys) {
52-
// prepend keys with a dollar-sign for template-replacement
53-
_tokens['$'+key] = args[key] || '';
54-
}
48+
// shallow-copy the original tokens object
49+
for (let key in tokens) {
50+
_tokens[key] = tokens[key];
51+
}
52+
53+
// copy expected arguments from args to the new tokens object
54+
// defaulting to an emptystring
55+
for (let key of expectedKeys) {
56+
// prepend keys with a dollar-sign for template-replacement
57+
_tokens['$'+key] = args[key] || '';
58+
}
5559

56-
return _tokens;
60+
return _tokens;
61+
}
62+
// otherwise we just pass through the original tokens object
63+
else {
64+
return tokens;
65+
}
5766
}
5867

5968
/**

0 commit comments

Comments
 (0)