Skip to content

Commit db1908a

Browse files
committed
[mode/simple addon] Allow token source to be a function
Issue #4787
1 parent 0aec8bf commit db1908a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

addon/mode/simple.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777

7878
function asToken(val) {
7979
if (!val) return null;
80+
if (val.apply) return val
8081
if (typeof val == "string") return val.replace(/\./g, " ");
8182
var result = [];
8283
for (var i = 0; i < val.length; i++)
@@ -133,17 +134,19 @@
133134
state.indent.push(stream.indentation() + config.indentUnit);
134135
if (rule.data.dedent)
135136
state.indent.pop();
137+
var token = rule.token
138+
if (token.apply) token = token(matches)
136139
if (matches.length > 2) {
137140
state.pending = [];
138141
for (var j = 2; j < matches.length; j++)
139142
if (matches[j])
140143
state.pending.push({text: matches[j], token: rule.token[j - 1]});
141144
stream.backUp(matches[0].length - (matches[1] ? matches[1].length : 0));
142-
return rule.token[0];
143-
} else if (rule.token && rule.token.join) {
144-
return rule.token[0];
145+
return token[0];
146+
} else if (token && token.join) {
147+
return token[0];
145148
} else {
146-
return rule.token;
149+
return token;
147150
}
148151
}
149152
}

0 commit comments

Comments
 (0)