jskinner / DefaultPackages

Old bug tracker for Sublime Text's "Default Packages", e.g. bad syntax highlighting
http://web.archive.org/web/20150524043750/https://www.sublimetext.com/forum/viewtopic.php?f=2&t=12095
26 stars 2 forks source link

JavaScript syntax highlighting: no space between `function` and parens breaks argument highlighting #100

Closed MattDMo closed 8 years ago

MattDMo commented 9 years ago

This is an issue in both ST2 and ST3. Take the following code:

arr.forEach(function(arg1) { return arg1; })
arr.forEach(function (arg1) { return arg1; })
play = function(arg) { return arg; }
function foo(arg1, arg2) { return arg1 + arg2; }

bar = {
    baz: function(args) {}
}

In arr.forEach(function(arg1) { return arg1; }), arg1 is not scoped as variable.parameter.function.js, whereas in arr.forEach(function (arg1) { return arg1; }) (note space between function and opening paren) it is highlighted appropriately. Other types of functions work fine:

js_args_1

The problem is on line 260 of JavaScript.tmLanguage:

<string>\b(function)\s+([a-zA-Z_$]\w*)?\s*(\()(.*?)(\))</string>
<!--                  ^                           -->

\s+ is matching one or more whitespace characters after function, where it should be zero or more - \s*. With that one change, everything works fine:

js_args_2

FichteFoll commented 8 years ago

Fixed in 3104, probably earlier around 3087 though.