Skip to content

Commit

Permalink
Highlight ({ "foo": function foo(){ } }) the same way as ({ "foo": fu…
Browse files Browse the repository at this point in the history
…nction(){ } }) for consistency.

Make sure methods are highlighted when there's a whitespace between identifier and parens (e.g. `alert (123)`).
  • Loading branch information
kangax committed Oct 25, 2010
1 parent a1c823e commit 103801b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
13 changes: 7 additions & 6 deletions JavaScript.plist
Expand Up @@ -100,7 +100,7 @@
},
{ name = 'meta.function.json.js';
comment = 'Attempt to match "foo": function';
match = '(?:(('')(.*?)(''))|((")(.*?)(")))\s*:\s*\b(function)?\s*(\()(.*?)(\))';
match = '(?:(('')(.*?)(''))|((")(.*?)(")))\s*:\s*\b(function)?\s*([a-zA-Z_$][\w$]*\s*)?(\()(.*?)(\))';
captures = {
1 = { name = 'string.quoted.single.js'; };
2 = { name = 'punctuation.definition.string.begin.js'; };
Expand All @@ -110,10 +110,11 @@
6 = { name = 'punctuation.definition.string.begin.js'; };
7 = { name = 'entity.name.function.js'; };
8 = { name = 'punctuation.definition.string.end.js'; };
9 = { name = 'entity.name.function.js'; };
10 = { name = 'punctuation.definition.parameters.begin.js'; };
11 = { name = 'variable.parameter.function.js'; };
12 = { name = 'punctuation.definition.parameters.end.js'; };
9 = { name = 'storage.type.function.js'; };
10 = { name = 'entity.name.function.js'; };
11 = { name = 'punctuation.definition.parameters.begin.js'; };
12 = { name = 'variable.parameter.function.js'; };
13 = { name = 'punctuation.definition.parameters.end.js'; };
};
},
{ name = 'meta.class.instance.constructor';
Expand Down Expand Up @@ -206,7 +207,7 @@
match = '\b(Anchor|Applet|Area|Array|Boolean|Button|Checkbox|Date|document|event|FileUpload|Form|Frame|Function|Hidden|History|Image|JavaArray|JavaClass|JavaObject|JavaPackage|JSON|java|Layer|Link|Location|Math|MimeType|Number|navigator|netscape|Object|Option|Packages|Password|Plugin|Radio|RegExp|Reset|Select|String|Style|Submit|screen|sun|Text|Textarea|window|XMLHttpRequest)\b';
},
{ name = 'support.function.js';
match = '\b(s(h(ift|ow(Mod(elessDialog|alDialog)|Help))|croll(X|By(Pages|Lines)?|Y|To)?|t(op|rike)|i(n|zeToContent|debar|gnText)|ort|u(p|b(str(ing)?)?)|pli(ce|t)|e(nd|t(Re(sizable|questHeader)|M(i(nutes|lliseconds)|onth)|Seconds|Ho(tKeys|urs)|Year|Cursor|Time(out)?|Interval|ZOptions|Date|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(ome|andleEvent)|navigate|c(har(CodeAt|At)|o(s|n(cat|textual|firm)|mpile)|eil|lear(Timeout|Interval)?|a(ptureEvents|ll)|reate(StyleSheet|Popup|EventObject))|t(o(GMTString|S(tring|ource)|U(TCString|pperCase)|Lo(caleString|werCase))|est|a(n|int(Enabled)?))|i(s(NaN|Finite)|ndexOf|talics)|d(isableExternalCapture|ump|etachEvent)|u(n(shift|taint|escape|watch)|pdateCommands)|j(oin|avaEnabled)|p(o(p|w)|ush|lugins.refresh|a(ddings|rse(Int|Float)?)|r(int|ompt|eference))|e(scape|nableExternalCapture|val|lementFromPoint|x(p|ec(Script|Command)?))|valueOf|UTC|queryCommand(State|Indeterm|Enabled|Value)|f(i(nd|le(ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(nt(size|color)|rward)|loor|romCharCode)|watch|l(ink|o(ad|g)|astIndexOf)|a(sin|nchor|cos|t(tachEvent|ob|an(2)?)|pply|lert|b(s|ort))|r(ou(nd|teEvents)|e(size(By|To)|calc|turnValue|place|verse|l(oad|ease(Capture|Events)))|andom)|g(o|et(ResponseHeader|M(i(nutes|lliseconds)|onth)|Se(conds|lection)|Hours|Year|Time(zoneOffset)?|Da(y|te)|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Da(y|te)|FullYear)|FullYear|A(ttention|llResponseHeaders)))|m(in|ove(B(y|elow)|To(Absolute)?|Above)|ergeAttributes|a(tch|rgins|x))|b(toa|ig|o(ld|rderWidths)|link|ack)|every|some|forEach|map|filter|reduce|reduceRight|hasOwnProperty|isPrototypeOf|propertyIsEnumerable|now|(en|de)codeURI(Component)?|getPrototypeOf|getOwnPropertyDescriptor|getOwnPropertyNames|create|defineProperty|defineProperties|seal|freeze|preventExtensions|isSealed|isFrozen|isExtensible|keys|bind)\b(?=\()';
match = '\b(s(h(ift|ow(Mod(elessDialog|alDialog)|Help))|croll(X|By(Pages|Lines)?|Y|To)?|t(op|rike)|i(n|zeToContent|debar|gnText)|ort|u(p|b(str(ing)?)?)|pli(ce|t)|e(nd|t(Re(sizable|questHeader)|M(i(nutes|lliseconds)|onth)|Seconds|Ho(tKeys|urs)|Year|Cursor|Time(out)?|Interval|ZOptions|Date|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(ome|andleEvent)|navigate|c(har(CodeAt|At)|o(s|n(cat|textual|firm)|mpile)|eil|lear(Timeout|Interval)?|a(ptureEvents|ll)|reate(StyleSheet|Popup|EventObject))|t(o(GMTString|S(tring|ource)|U(TCString|pperCase)|Lo(caleString|werCase))|est|a(n|int(Enabled)?))|i(s(NaN|Finite)|ndexOf|talics)|d(isableExternalCapture|ump|etachEvent)|u(n(shift|taint|escape|watch)|pdateCommands)|j(oin|avaEnabled)|p(o(p|w)|ush|lugins.refresh|a(ddings|rse(Int|Float)?)|r(int|ompt|eference))|e(scape|nableExternalCapture|val|lementFromPoint|x(p|ec(Script|Command)?))|valueOf|UTC|queryCommand(State|Indeterm|Enabled|Value)|f(i(nd|le(ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(nt(size|color)|rward)|loor|romCharCode)|watch|l(ink|o(ad|g)|astIndexOf)|a(sin|nchor|cos|t(tachEvent|ob|an(2)?)|pply|lert|b(s|ort))|r(ou(nd|teEvents)|e(size(By|To)|calc|turnValue|place|verse|l(oad|ease(Capture|Events)))|andom)|g(o|et(ResponseHeader|M(i(nutes|lliseconds)|onth)|Se(conds|lection)|Hours|Year|Time(zoneOffset)?|Da(y|te)|UTC(M(i(nutes|lliseconds)|onth)|Seconds|Hours|Da(y|te)|FullYear)|FullYear|A(ttention|llResponseHeaders)))|m(in|ove(B(y|elow)|To(Absolute)?|Above)|ergeAttributes|a(tch|rgins|x))|b(toa|ig|o(ld|rderWidths)|link|ack)|every|some|forEach|map|filter|reduce|reduceRight|hasOwnProperty|isPrototypeOf|propertyIsEnumerable|now|(en|de)codeURI(Component)?|getPrototypeOf|getOwnPropertyDescriptor|getOwnPropertyNames|create|defineProperty|defineProperties|seal|freeze|preventExtensions|isSealed|isFrozen|isExtensible|keys|bind)\b(?=\s*\()';
},
{ name = 'support.function.dom.js';
match = '\b(s(ub(stringData|mit)|plitText|e(t(NamedItem|Attribute(Node)?)|lect))|has(ChildNodes|Feature)|namedItem|c(l(ick|o(se|neNode))|reate(C(omment|DATASection|aption)|T(Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(ntityReference|lement)|Attribute))|tabIndex|i(nsert(Row|Before|Cell|Data)|tem)|open|delete(Row|C(ell|aption)|T(Head|Foot)|Data)|focus|write(ln)?|a(dd|ppend(Child|Data))|re(set|place(Child|Data)|move(NamedItem|Child|Attribute(Node)?)?)|get(NamedItem|Element(sBy(Name|TagName)|ById)|Attribute(Node)?)|blur)\b(?=\()';
Expand Down
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -44,6 +44,18 @@

({ get foo() { }, set foo(value) { } });

- Highlights methods w. whitespace between identifier and parens

alert (123); // alert is highlighted
foo.toString (); // toString is highlighted

- Consistently highlights named function expressions in object literals

({
"foo": function () { },
"bar": function bar() { }
})


### How to install

Expand Down
19 changes: 18 additions & 1 deletion test.js
Expand Up @@ -116,4 +116,21 @@ Object.keys()
(to avoid using reserved words as property names — which is disallowed in ES3,
and is best avoided for compatibility reasons) */

({ if: 1, break: 2 });
({ if: 1, break: 2 });

/* function calls with space in between identifier and call operator should still be highlighted as functions */

alert (1);
foo.toString ();

/* named function expressions as property values in object literals (where property names are string literals)
should be highlighted SAME way as anonymous function expressions in same context */

({
"foo": function() {

},
"bar": function bar() {

}
})

0 comments on commit 103801b

Please sign in to comment.