Skip to content

Commit cfbfcb1

Browse files
authored
Add support for generators in js/ts (#600)
1 parent aefbcbe commit cfbfcb1

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

src/languages/typescript.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ const nodeMatchers: Partial<Record<ScopeType, NodeMatcherAlternative>> = {
162162
patternMatcher("return_statement.~return!")
163163
),
164164
ifStatement: "if_statement",
165-
anonymousFunction: ["arrow_function", "function"],
165+
anonymousFunction: [
166+
"arrow_function",
167+
"function",
168+
],
166169
name: [
167170
"*[name]",
168171
"optional_parameter.identifier!",
@@ -182,6 +185,8 @@ const nodeMatchers: Partial<Record<ScopeType, NodeMatcherAlternative>> = {
182185
functionName: [
183186
// function
184187
"function_declaration[name]",
188+
// generator function
189+
"generator_function_declaration[name]",
185190
// export default function
186191
"function[name]",
187192
// class method
@@ -218,6 +223,8 @@ const nodeMatchers: Partial<Record<ScopeType, NodeMatcherAlternative>> = {
218223
"assignment_expression.function",
219224
// foo = () => { }
220225
"assignment_expression.arrow_function",
226+
// foo = function*() { }
227+
"generator_function_declaration",
221228
],
222229
type: cascadingMatcher(
223230
// Typed parameters, properties, and functions
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
languageId: typescript
2+
command:
3+
version: 1
4+
spokenForm: change funk
5+
action: clearAndSetSelection
6+
targets:
7+
- type: primitive
8+
modifier: {type: containingScope, scopeType: namedFunction, includeSiblings: false}
9+
initialState:
10+
documentContents: |-
11+
function* generator(i) {
12+
yield i + 10;
13+
}
14+
selections:
15+
- anchor: {line: 1, character: 15}
16+
active: {line: 1, character: 15}
17+
marks: {}
18+
finalState:
19+
documentContents: ""
20+
selections:
21+
- anchor: {line: 0, character: 0}
22+
active: {line: 0, character: 0}
23+
thatMark:
24+
- anchor: {line: 0, character: 0}
25+
active: {line: 0, character: 0}
26+
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: namedFunction, includeSiblings: false}, isImplicit: false}]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: typescript
2+
command:
3+
version: 1
4+
spokenForm: change name
5+
action: clearAndSetSelection
6+
targets:
7+
- type: primitive
8+
modifier: {type: containingScope, scopeType: name, includeSiblings: false}
9+
initialState:
10+
documentContents: |-
11+
function* generator(i) {
12+
yield i + 10;
13+
}
14+
selections:
15+
- anchor: {line: 1, character: 15}
16+
active: {line: 1, character: 15}
17+
marks: {}
18+
finalState:
19+
documentContents: |-
20+
function* (i) {
21+
yield i + 10;
22+
}
23+
selections:
24+
- anchor: {line: 0, character: 10}
25+
active: {line: 0, character: 10}
26+
thatMark:
27+
- anchor: {line: 0, character: 10}
28+
active: {line: 0, character: 10}
29+
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: name, includeSiblings: false}, isImplicit: false}]

0 commit comments

Comments
 (0)