Add support for generators in js/ts (#600)

This commit is contained in:
Will Sommers 2022-03-11 02:09:24 -05:00 committed by GitHub
parent aefbcbe996
commit cfbfcb1168
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 1 deletions

View File

@ -162,7 +162,10 @@ const nodeMatchers: Partial<Record<ScopeType, NodeMatcherAlternative>> = {
patternMatcher("return_statement.~return!")
),
ifStatement: "if_statement",
anonymousFunction: ["arrow_function", "function"],
anonymousFunction: [
"arrow_function",
"function",
],
name: [
"*[name]",
"optional_parameter.identifier!",
@ -182,6 +185,8 @@ const nodeMatchers: Partial<Record<ScopeType, NodeMatcherAlternative>> = {
functionName: [
// function
"function_declaration[name]",
// generator function
"generator_function_declaration[name]",
// export default function
"function[name]",
// class method
@ -218,6 +223,8 @@ const nodeMatchers: Partial<Record<ScopeType, NodeMatcherAlternative>> = {
"assignment_expression.function",
// foo = () => { }
"assignment_expression.arrow_function",
// foo = function*() { }
"generator_function_declaration",
],
type: cascadingMatcher(
// Typed parameters, properties, and functions

View File

@ -0,0 +1,26 @@
languageId: typescript
command:
version: 1
spokenForm: change funk
action: clearAndSetSelection
targets:
- type: primitive
modifier: {type: containingScope, scopeType: namedFunction, includeSiblings: false}
initialState:
documentContents: |-
function* generator(i) {
yield i + 10;
}
selections:
- anchor: {line: 1, character: 15}
active: {line: 1, character: 15}
marks: {}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
thatMark:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: namedFunction, includeSiblings: false}, isImplicit: false}]

View File

@ -0,0 +1,29 @@
languageId: typescript
command:
version: 1
spokenForm: change name
action: clearAndSetSelection
targets:
- type: primitive
modifier: {type: containingScope, scopeType: name, includeSiblings: false}
initialState:
documentContents: |-
function* generator(i) {
yield i + 10;
}
selections:
- anchor: {line: 1, character: 15}
active: {line: 1, character: 15}
marks: {}
finalState:
documentContents: |-
function* (i) {
yield i + 10;
}
selections:
- anchor: {line: 0, character: 10}
active: {line: 0, character: 10}
thatMark:
- anchor: {line: 0, character: 10}
active: {line: 0, character: 10}
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: name, includeSiblings: false}, isImplicit: false}]