diff --git a/spec/app/text-mate-grammar-spec.coffee b/spec/app/text-mate-grammar-spec.coffee index 8d421b142..80d2a8df1 100644 --- a/spec/app/text-mate-grammar-spec.coffee +++ b/spec/app/text-mate-grammar-spec.coffee @@ -268,3 +268,9 @@ describe "TextMateGrammar", -> expect(tokens[0].value).toBe "a" expect(tokens[1].value).toBe "bc" expect(console.error).toHaveBeenCalled() + + describe "when a grammar has a pattern that has back references in the match value", -> + it "does not special handle the back references and instead allows oniguruma to resolve them", -> + grammar = syntax.selectGrammar("style.scss") + {tokens} = grammar.tokenizeLine("@mixin x() { -moz-selector: whatever; }") + expect(tokens[9]).toEqual value: "-moz-selector", scopes: ["source.css.scss", "meta.property-list.scss", "meta.property-name.scss"] diff --git a/src/app/text-mate-grammar.coffee b/src/app/text-mate-grammar.coffee index 94a6c0ff4..93fe9559f 100644 --- a/src/app/text-mate-grammar.coffee +++ b/src/app/text-mate-grammar.coffee @@ -159,10 +159,10 @@ class Pattern backReferences: null anchored: false - constructor: (@grammar, { name, contentName, @include, match, begin, end, captures, beginCaptures, endCaptures, patterns, @popRule, hasBackReferences}) -> + constructor: (@grammar, { name, contentName, @include, match, begin, end, captures, beginCaptures, endCaptures, patterns, @popRule, @hasBackReferences}) -> @scopeName = name ? contentName # TODO: We need special treatment of contentName if match - if @hasBackReferences = hasBackReferences ? /\\\d+/.test(match) + if (end or @popRule) and @hasBackReferences ?= /\\\d+/.test(match) @match = match else @regexSource = match