|
1 | | -exports.activate = function () { |
2 | | - if (!atom.grammars.addInjectionPoint) return |
| 1 | +exports.activate = function() { |
| 2 | + if (!atom.grammars.addInjectionPoint) return; |
3 | 3 |
|
4 | 4 | atom.grammars.addInjectionPoint('source.js', { |
5 | 5 | type: 'call_expression', |
6 | 6 |
|
7 | | - language (callExpression) { |
8 | | - const {firstChild} = callExpression |
| 7 | + language(callExpression) { |
| 8 | + const { firstChild } = callExpression; |
9 | 9 | switch (firstChild.type) { |
10 | 10 | case 'identifier': |
11 | | - return languageStringForTemplateTag(firstChild.text) |
| 11 | + return languageStringForTemplateTag(firstChild.text); |
12 | 12 | case 'call_expression': |
13 | | - return languageStringForTemplateTag(firstChild.children[0].text) |
| 13 | + return languageStringForTemplateTag(firstChild.children[0].text); |
14 | 14 | case 'member_expression': |
15 | 15 | if (firstChild.startPosition.row === firstChild.endPosition.row) { |
16 | | - return languageStringForTemplateTag(firstChild.text) |
| 16 | + return languageStringForTemplateTag(firstChild.text); |
17 | 17 | } |
18 | 18 | } |
19 | 19 | }, |
20 | 20 |
|
21 | | - content (callExpression) { |
22 | | - const {lastChild} = callExpression |
| 21 | + content(callExpression) { |
| 22 | + const { lastChild } = callExpression; |
23 | 23 | if (lastChild.type === 'template_string') { |
24 | | - return lastChild |
| 24 | + return lastChild; |
25 | 25 | } |
26 | 26 | } |
27 | | - }) |
| 27 | + }); |
28 | 28 |
|
29 | 29 | atom.grammars.addInjectionPoint('source.js', { |
30 | 30 | type: 'assignment_expression', |
31 | 31 |
|
32 | | - language (callExpression) { |
33 | | - const {firstChild} = callExpression |
| 32 | + language(callExpression) { |
| 33 | + const { firstChild } = callExpression; |
34 | 34 | if (firstChild.type === 'member_expression') { |
35 | 35 | if (firstChild.lastChild.text === 'innerHTML') { |
36 | | - return 'html' |
| 36 | + return 'html'; |
37 | 37 | } |
38 | 38 | } |
39 | 39 | }, |
40 | 40 |
|
41 | | - content (callExpression) { |
42 | | - const {lastChild} = callExpression |
| 41 | + content(callExpression) { |
| 42 | + const { lastChild } = callExpression; |
43 | 43 | if (lastChild.type === 'template_string') { |
44 | | - return lastChild |
| 44 | + return lastChild; |
45 | 45 | } |
46 | 46 | } |
47 | | - }) |
| 47 | + }); |
48 | 48 |
|
49 | 49 | atom.grammars.addInjectionPoint('source.js', { |
50 | 50 | type: 'regex_pattern', |
51 | | - language (regex) { return 'regex' }, |
52 | | - content (regex) { return regex } |
53 | | - }) |
| 51 | + language(regex) { |
| 52 | + return 'regex'; |
| 53 | + }, |
| 54 | + content(regex) { |
| 55 | + return regex; |
| 56 | + } |
| 57 | + }); |
54 | 58 |
|
55 | 59 | for (const scopeName of ['source.js', 'source.flow', 'source.ts']) { |
56 | 60 | atom.grammars.addInjectionPoint(scopeName, { |
57 | 61 | type: 'comment', |
58 | | - language (comment) { |
59 | | - if (comment.text.startsWith('/**')) return 'jsdoc' |
| 62 | + language(comment) { |
| 63 | + if (comment.text.startsWith('/**')) return 'jsdoc'; |
60 | 64 | }, |
61 | | - content (comment) { |
62 | | - return comment |
| 65 | + content(comment) { |
| 66 | + return comment; |
63 | 67 | } |
64 | | - }) |
| 68 | + }); |
65 | 69 | } |
66 | | -} |
| 70 | +}; |
67 | 71 |
|
68 | | -const CSS_REGEX = /\bstyled\b|\bcss\b/i |
69 | | -const GQL_REGEX = /\bgraphql\b|\bgql\b/i |
70 | | -const SQL_REGEX = /\bsql\b/i |
| 72 | +const CSS_REGEX = /\bstyled\b|\bcss\b/i; |
| 73 | +const GQL_REGEX = /\bgraphql\b|\bgql\b/i; |
| 74 | +const SQL_REGEX = /\bsql\b/i; |
71 | 75 |
|
72 | | -function languageStringForTemplateTag (tag) { |
| 76 | +function languageStringForTemplateTag(tag) { |
73 | 77 | if (CSS_REGEX.test(tag)) { |
74 | | - return 'CSS' |
| 78 | + return 'CSS'; |
75 | 79 | } else if (GQL_REGEX.test(tag)) { |
76 | | - return 'GraphQL' |
| 80 | + return 'GraphQL'; |
77 | 81 | } else if (SQL_REGEX.test(tag)) { |
78 | | - return 'SQL' |
| 82 | + return 'SQL'; |
79 | 83 | } else { |
80 | | - return tag |
| 84 | + return tag; |
81 | 85 | } |
82 | 86 | } |
0 commit comments