regexps are allowed after case statements

This commit is contained in:
Fabian Jakobs 2011-09-06 16:52:49 +02:00
commit 86344d92b7
2 changed files with 11 additions and 0 deletions

View file

@ -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")

View file

@ -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);
},