Skip to content

Commit

Permalink
simplify byStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Aug 21, 2021
1 parent e8bbb3f commit 93ef486
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mode/javascript-mixed/javascript-mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@
// a map of all rules, keyed by id/type for quick lookup during matching
const rulesById = {};
const rulesByType = {};
const rulesByStyle = {};
const rulesByLangCmt = [];

/** @typedef {function(RunContext):(?boolean)} RuleLambda */

Expand All @@ -532,7 +532,7 @@
* @property {boolean} id - current context
* @property {?string} next - next context or null
* @property {?string} type - token type
* @property {?string} style - token style
* @property {?string} style - token style, only 'comment' is handled for language hints
* @property {Object} [mode] - CodeMirror mode
* @property {boolean} [hasBeginBacktick=true]
* @property {RuleLambda|string|RegExp} match - matching function/text/regexp,
Expand Down Expand Up @@ -567,8 +567,8 @@
if (rule.id) {
rulesById[rule.id] = [rule];
}
if (style) {
(rulesByStyle[style] || (rulesByStyle[style] = [])).push(rule);
if (style === 'comment') {
rulesByLangCmt.push(rule);
}
(rulesByType[type || ''] || (rulesByType[type || ''] = [])).push(rule);
});
Expand All @@ -579,7 +579,7 @@
const ctx = RunContext.get(stream, state, jsTokenStyle);
const id = state.maybeLocalContext || '';
const rules = id ? rulesById[id]
: ctx.jsTokenStyle === 'comment' && ctx.text[1] === '*' ? rulesByStyle.comment
: jsTokenStyle === 'comment' && ctx.text[1] === '*' ? rulesByLangCmt
: rulesByType[ctx.type];
if (rules) {
for (const rule of rules) {
Expand Down

0 comments on commit 93ef486

Please sign in to comment.