-
Notifications
You must be signed in to change notification settings - Fork 853
Expand file tree
/
Copy pathjavascript.py
More file actions
202 lines (173 loc) · 5.44 KB
/
javascript.py
File metadata and controls
202 lines (173 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
from talon import Context, Module, actions, settings
from ...core.described_functions import create_described_insert_between
from ..tags.operators import Operators
mod = Module()
ctx = Context()
ctx.matches = r"""
code.language: javascript
code.language: typescript
code.language: javascriptreact
code.language: typescriptreact
"""
ctx.lists["user.code_common_method"] = {
"catch": "catch",
"concat": "concat",
"filter": "filter",
"finally": "finally",
"find": "find",
"flat map": "flatMap",
"for each": "forEach",
"join": "join",
"includes": "includes",
"map": "map",
"pop": "pop",
"push": "push",
"reduce": "reduce",
"slice": "slice",
"some": "some",
"split": "split",
"substring": "substring",
"then": "then",
}
ctx.lists["user.code_keyword"] = {
"a sink": "async ",
"await": "await ",
"break": "break",
"class": "class ",
"const": "const ",
"continue": "continue",
"default": "default ",
"export": "export ",
"false": "false",
"function": "function ",
"import": "import ",
"let": "let ",
"new": "new ",
"null": "null",
"private": "private ",
"protected": "protected ",
"public": "public ",
"return": "return ",
"throw": "throw ",
"true": "true",
"try": "try ",
"undefined": "undefined",
"yield": "yield ",
}
operators = Operators(
# code_operators_array
SUBSCRIPT=create_described_insert_between("[", "]"),
# code_operators_assignment
ASSIGNMENT=" = ",
ASSIGNMENT_OR=" ||= ",
ASSIGNMENT_ADDITION=" += ",
ASSIGNMENT_SUBTRACTION=" -= ",
ASSIGNMENT_MULTIPLICATION=" *= ",
ASSIGNMENT_DIVISION=" /= ",
ASSIGNMENT_MODULO=" %= ",
ASSIGNMENT_INCREMENT="++",
ASSIGNMENT_BITWISE_AND=" &= ",
ASSIGNMENT_BITWISE_OR=" |= ",
ASSIGNMENT_BITWISE_EXCLUSIVE_OR=" ^= ",
ASSIGNMENT_BITWISE_LEFT_SHIFT=" <<= ",
ASSIGNMENT_BITWISE_RIGHT_SHIFT=" >>= ",
# code_operators_bitwise
BITWISE_AND=" & ",
BITWISE_OR=" | ",
BITWISE_EXCLUSIVE_OR=" ^ ",
BITWISE_LEFT_SHIFT=" << ",
BITWISE_RIGHT_SHIFT=" >> ",
# code_operators_lambda
LAMBDA=" => ",
# code_operators_math
MATH_ADD=" + ",
MATH_SUBTRACT=" - ",
MATH_MULTIPLY=" * ",
MATH_DIVIDE=" / ",
MATH_MODULO=" % ",
MATH_EXPONENT=" ** ",
MATH_EQUAL=" === ",
MATH_NOT_EQUAL=" !== ",
MATH_OR=" || ",
MATH_AND=" && ",
MATH_GREATER_THAN=" > ",
MATH_LESS_THAN=" < ",
MATH_GREATER_THAN_OR_EQUAL=" >= ",
MATH_LESS_THAN_OR_EQUAL=" <= ",
MATH_WEAK_EQUAL=" == ",
MATH_WEAK_NOT_EQUAL=" != ",
)
@ctx.action_class("user")
class UserActions:
def code_get_operators() -> Operators:
return operators
def code_insert_is_not_null():
actions.insert(" !== null")
def code_insert_is_null():
actions.insert(" === null")
def code_self():
actions.insert("this")
def code_operator_object_accessor():
actions.insert(".")
def code_insert_true():
actions.insert("true")
def code_insert_false():
actions.insert("false")
def code_insert_null():
actions.insert("null")
def code_insert_function(text: str, selection: str):
text += f"({selection or ''})"
actions.user.paste(text)
actions.edit.left()
def code_default_function(text: str):
"""Inserts function declaration without modifiers"""
result = "function {}".format(
actions.user.formatted_text(
text, settings.get("user.code_private_function_formatter")
)
)
actions.user.code_insert_function(result, None)
def code_private_function(text: str):
"""Inserts private function declaration"""
result = "function {}".format(
actions.user.formatted_text(
text, settings.get("user.code_private_function_formatter")
)
)
actions.user.code_insert_function(result, None)
# def code_private_static_function(text: str):
# """Inserts private static function"""
# result = "private static void {}".format(
# actions.user.formatted_text(
# text, settings.get("user.code_private_function_formatter")
# )
# )
# actions.user.code_insert_function(result, None)
def code_protected_function(text: str):
result = "function {}".format(
actions.user.formatted_text(
text, settings.get("user.code_protected_function_formatter")
)
)
actions.user.code_insert_function(result, None)
# def code_protected_static_function(text: str):
# result = "protected static void {}".format(
# actions.user.formatted_text(
# text, settings.get("user.code_protected_function_formatter")
# )
# )
# actions.user.code_insert_function(result, None)
def code_public_function(text: str):
result = "function {}".format(
actions.user.formatted_text(
text, settings.get("user.code_public_function_formatter")
)
)
actions.user.code_insert_function(result, None)
# def code_public_static_function(text: str):
# result = "public static void {}".format(
# actions.user.formatted_text(
# text, settings.get("user.code_public_function_formatter")
# )
# )
# actions.user.code_insert_function(result, None)