diff --git a/lib/ace/mode/javascript_highlight_rules.js b/lib/ace/mode/javascript_highlight_rules.js index 0571c342..7b315fcf 100644 --- a/lib/ace/mode/javascript_highlight_rules.js +++ b/lib/ace/mode/javascript_highlight_rules.js @@ -51,6 +51,9 @@ var JavaScriptHighlightRules = function() { "if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|" + "const|yield|import|get|set").split("|") ); + + // keywords which can be followed by regular expressions + var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield"; var buildinConstants = lang.arrayToMap( ("null|Infinity|NaN|undefined").split("|") @@ -111,6 +114,10 @@ var JavaScriptHighlightRules = function() { }, { token : "constant.language.boolean", regex : "(?:true|false)\\b" + }, { + token : "keyword", + regex : kwBeforeRe, + next : "regex_allowed" }, { token : function(value) { if (value == "this") diff --git a/lib/ace/mode/javascript_tokenizer_test.js b/lib/ace/mode/javascript_tokenizer_test.js index 311fb7e8..cc3bca64 100644 --- a/lib/ace/mode/javascript_tokenizer_test.js +++ b/lib/ace/mode/javascript_tokenizer_test.js @@ -136,6 +136,10 @@ module.exports = { assert.equal(7, tokens.length); assert.equal("string.regexp", tokens[2].type); assert.equal("string.regexp", tokens[6].type); + + var tokens = this.tokenizer.getLineTokens("case /a/.test(c)", "start").tokens; + assert.equal(8, tokens.length); + assert.equal("string.regexp", tokens[2].type); },