Skip to content

Commit 78fa2b3

Browse files
AndreasArvidssonpokeypre-commit-ci[bot]
authored
Supports states scope for interface properties (#1065)
* Supports states scope for interface properties * Remove trailing semi * Added test * Add class fields * Use extend past optional finder * updated test * Added inline test * Updated state definition for typescript * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add "item" tests Co-authored-by: Pokey Rule <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ba9644b commit 78fa2b3

File tree

11 files changed

+296
-1
lines changed

11 files changed

+296
-1
lines changed

src/languages/typescript.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,20 @@ const nodeMatchers: Partial<
200200
childRangeSelector(["arguments"], []),
201201
),
202202
),
203-
statement: STATEMENT_TYPES.map((type) => `export_statement?.${type}`),
203+
statement: cascadingMatcher(
204+
matcher(
205+
patternFinder(
206+
"property_signature",
207+
"public_field_definition",
208+
"abstract_method_signature",
209+
),
210+
extendForwardPastOptional(";"),
211+
),
212+
patternMatcher(
213+
...STATEMENT_TYPES.map((type) => `export_statement?.${type}`),
214+
"method_definition",
215+
),
216+
),
204217
condition: cascadingMatcher(
205218
patternMatcher("ternary_expression[condition]"),
206219
conditionMatcher(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
languageId: typescript
2+
command:
3+
spokenForm: chuck state
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: statement}
10+
usePrePhraseSnapshot: true
11+
action: {name: remove}
12+
initialState:
13+
documentContents: |-
14+
interface Foo {
15+
bar: Bar;
16+
baz: Baz;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 2}
20+
active: {line: 1, character: 2}
21+
marks: {}
22+
finalState:
23+
documentContents: |-
24+
interface Foo {
25+
26+
baz: Baz;
27+
}
28+
selections:
29+
- anchor: {line: 1, character: 0}
30+
active: {line: 1, character: 0}
31+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: statement}}]}]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: typescript
2+
command:
3+
spokenForm: chuck state
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: statement}
10+
usePrePhraseSnapshot: true
11+
action: {name: remove}
12+
initialState:
13+
documentContents: |-
14+
class Foo {
15+
private value: string;
16+
}
17+
selections:
18+
- anchor: {line: 1, character: 4}
19+
active: {line: 1, character: 4}
20+
marks: {}
21+
finalState:
22+
documentContents: |-
23+
class Foo {
24+
25+
}
26+
selections:
27+
- anchor: {line: 1, character: 0}
28+
active: {line: 1, character: 0}
29+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: statement}}]}]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: typescript
2+
command:
3+
spokenForm: clear item
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: collectionItem}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: "let foo: { a: string };"
14+
selections:
15+
- anchor: {line: 0, character: 11}
16+
active: {line: 0, character: 11}
17+
marks: {}
18+
finalState:
19+
documentContents: "let foo: { };"
20+
selections:
21+
- anchor: {line: 0, character: 11}
22+
active: {line: 0, character: 11}
23+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: collectionItem}}]}]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: typescript
2+
command:
3+
spokenForm: clear item
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: collectionItem}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: "let foo: { a: string, b: string };"
14+
selections:
15+
- anchor: {line: 0, character: 11}
16+
active: {line: 0, character: 11}
17+
marks: {}
18+
finalState:
19+
documentContents: "let foo: { , b: string };"
20+
selections:
21+
- anchor: {line: 0, character: 11}
22+
active: {line: 0, character: 11}
23+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: collectionItem}}]}]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: typescript
2+
command:
3+
spokenForm: clear item
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: collectionItem}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: "let foo: { a: string, b: string };"
14+
selections:
15+
- anchor: {line: 0, character: 22}
16+
active: {line: 0, character: 22}
17+
marks: {}
18+
finalState:
19+
documentContents: "let foo: { a: string, };"
20+
selections:
21+
- anchor: {line: 0, character: 22}
22+
active: {line: 0, character: 22}
23+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: collectionItem}}]}]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
languageId: typescript
2+
command:
3+
spokenForm: clear state
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: statement}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |-
14+
interface Foo {
15+
bar: Bar;
16+
baz: Baz;
17+
}
18+
selections:
19+
- anchor: {line: 1, character: 2}
20+
active: {line: 1, character: 2}
21+
marks: {}
22+
finalState:
23+
documentContents: |-
24+
interface Foo {
25+
26+
baz: Baz;
27+
}
28+
selections:
29+
- anchor: {line: 1, character: 2}
30+
active: {line: 1, character: 2}
31+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: statement}}]}]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: typescript
2+
command:
3+
spokenForm: clear state
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: statement}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |-
14+
type Foo = {
15+
bar: string;
16+
}
17+
selections:
18+
- anchor: {line: 1, character: 2}
19+
active: {line: 1, character: 2}
20+
marks: {}
21+
finalState:
22+
documentContents: |-
23+
type Foo = {
24+
25+
}
26+
selections:
27+
- anchor: {line: 1, character: 2}
28+
active: {line: 1, character: 2}
29+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: statement}}]}]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: typescript
2+
command:
3+
spokenForm: clear state
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: statement}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: |-
14+
class Foo {
15+
private value: string;
16+
}
17+
selections:
18+
- anchor: {line: 1, character: 4}
19+
active: {line: 1, character: 4}
20+
marks: {}
21+
finalState:
22+
documentContents: |-
23+
class Foo {
24+
25+
}
26+
selections:
27+
- anchor: {line: 1, character: 4}
28+
active: {line: 1, character: 4}
29+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: statement}}]}]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: typescript
2+
command:
3+
spokenForm: clear state
4+
version: 3
5+
targets:
6+
- type: primitive
7+
modifiers:
8+
- type: containingScope
9+
scopeType: {type: statement}
10+
usePrePhraseSnapshot: true
11+
action: {name: clearAndSetSelection}
12+
initialState:
13+
documentContents: "let foo: { a: string };"
14+
selections:
15+
- anchor: {line: 0, character: 12}
16+
active: {line: 0, character: 12}
17+
marks: {}
18+
finalState:
19+
documentContents: "let foo: { };"
20+
selections:
21+
- anchor: {line: 0, character: 11}
22+
active: {line: 0, character: 11}
23+
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: statement}}]}]

0 commit comments

Comments
 (0)