Skip to content

Commit

Permalink
In typescript short hand property can be treated as key item or value (
Browse files Browse the repository at this point in the history
…#381)

Co-authored-by: Pokey Rule <pokey.rule@gmail.com>
  • Loading branch information
AndreasArvidsson and pokey authored Jan 5, 2022
1 parent 14749f4 commit 78aceac
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/languages/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function typeMatcher(): NodeMatcher {
}

function valueMatcher() {
const pFinder = patternFinder("assignment_expression[right]", "*[value]");
const pFinder = patternFinder("assignment_expression[right]", "*[value]", "shorthand_property_identifier");
return matcher(
(node: SyntaxNode) =>
node.type === "jsx_attribute" ? node.lastChild : pFinder(node),
Expand All @@ -145,7 +145,7 @@ const nodeMatchers: Partial<Record<ScopeType, NodeMatcherAlternative>> = {
list: listTypes,
string: ["string", "template_string"],
collectionKey: trailingMatcher(
["pair[key]", "jsx_attribute.property_identifier!"],
["pair[key]", "jsx_attribute.property_identifier!", "shorthand_property_identifier"],
[":"]
),
collectionItem: argumentMatcher(...mapTypes, ...listTypes),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
languageId: typescript
command:
version: 1
spokenForm: take every key
action: setSelection
targets:
- type: primitive
modifier: {type: containingScope, scopeType: collectionKey, includeSiblings: true}
initialState:
documentContents: |-
{
foo: "hello",
bar,
}
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
marks: {}
finalState:
documentContents: |-
{
foo: "hello",
bar,
}
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 7}
- anchor: {line: 2, character: 4}
active: {line: 2, character: 7}
thatMark:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 7}
- anchor: {line: 2, character: 4}
active: {line: 2, character: 7}
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: collectionKey, includeSiblings: true}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
languageId: typescript
command:
version: 1
spokenForm: take every value
action: setSelection
targets:
- type: primitive
modifier: {type: containingScope, scopeType: value, includeSiblings: true}
initialState:
documentContents: |-
{
foo: "hello",
bar,
}
selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
marks: {}
finalState:
documentContents: |-
{
foo: "hello",
bar,
}
selections:
- anchor: {line: 1, character: 9}
active: {line: 1, character: 16}
- anchor: {line: 2, character: 4}
active: {line: 2, character: 7}
thatMark:
- anchor: {line: 1, character: 9}
active: {line: 1, character: 16}
- anchor: {line: 2, character: 4}
active: {line: 2, character: 7}
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: value, includeSiblings: true}}]

0 comments on commit 78aceac

Please sign in to comment.