Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ switch (value) {
}
---

[Range] =
[Range] = 0:16-3:0
>
0| switch (value) {
1| case 0: { }
2| case 1: { }
3| }
<

[Domain] = 0:0-3:1
>----------------
0| switch (value) {
Expand Down
24 changes: 24 additions & 0 deletions data/fixtures/scopes/javascript.core/branch.try.iteration.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
try {
a
}
catch (e) {
b
}
finally {
c
}
---

[Range] =
[Domain] = 0:0-8:1
>-----
0| try {
1| a
2| }
3| catch (e) {
4| b
5| }
6| finally {
7| c
8| }
-<
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
switch (value) {
case 0: { }
case 1: { }
}
---

[Range] = 0:16-3:0
>
0| switch (value) {
1| case 0: { }
2| case 1: { }
3| }
<

[Domain] = 0:0-3:1
>----------------
0| switch (value) {
1| case 0: { }
2| case 1: { }
3| }
-<
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const aaa = 2;

---

[Range] =
[Domain] = 0:0-1:0
>--------------
0| const aaa = 2;
1|
<
10 changes: 10 additions & 0 deletions data/fixtures/scopes/javascript.core/statement.class.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Foo { }
---

[Content] =
[Removal] =
[Domain] = 0:0-0:13
>-------------<
0| class Foo { }

[Insertion delimiter] = "\n"
20 changes: 20 additions & 0 deletions data/fixtures/scopes/javascript.core/value.yield.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
yield 5;
---

[Content] = 0:6-0:7
>-<
0| yield 5;

[Removal] = 0:5-0:7
>--<
0| yield 5;

[Leading delimiter] = 0:5-0:6
>-<
0| yield 5;

[Domain] = 0:0-0:7
>-------<
0| yield 5;

[Insertion delimiter] = " "
80 changes: 70 additions & 10 deletions packages/common/src/scopeSupportFacets/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@ const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel;
export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = {
list: supported,
map: supported,
ifStatement: supported,
regularExpression: supported,
switchStatementSubject: supported,
fieldAccess: supported,
disqualifyDelimiter: supported,
pairDelimiter: supported,

"collectionItem.unenclosed": supported,

"textFragment.string.singleLine": supported,
"textFragment.string.multiLine": supported,
"textFragment.comment.line": supported,
"textFragment.comment.block": supported,

ifStatement: supported,

statement: supported,
"statement.iteration.document": supported,
"statement.iteration.block": supported,
"statement.class": supported,

class: supported,
className: supported,
Expand Down Expand Up @@ -67,6 +71,7 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = {
"branch.if": supported,
"branch.if.iteration": supported,
"branch.try": supported,
"branch.try.iteration": supported,
"branch.switchCase": supported,
"branch.switchCase.iteration": supported,
"branch.ternary": supported,
Expand All @@ -77,6 +82,7 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = {
"condition.for": supported,
"condition.ternary": supported,
"condition.switchCase": supported,
"condition.switchCase.iteration": supported,

"name.argument.formal": supported,
"name.argument.formal.iteration": supported,
Expand All @@ -94,6 +100,7 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = {
"name.constructor": supported,
"name.class": supported,
"name.field": supported,
"name.iteration.document": supported,

"key.mapPair": supported,
"key.mapPair.iteration": supported,
Expand All @@ -113,8 +120,52 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = {
"value.return": supported,
"value.return.lambda": supported,
"value.field": supported,

"collectionItem.unenclosed": supported,
"value.yield": supported,

// Unsupported

"collectionItem.unenclosed.iteration": unsupported,
"branch.loop": unsupported,
"namedFunction.iteration": unsupported,
"functionName.iteration": unsupported,

"class.iteration.block": unsupported,
"class.iteration.document": unsupported,
"className.iteration.block": unsupported,
"className.iteration.document": unsupported,

"name.iteration.block": unsupported,
"name.resource": unsupported,
"name.resource.iteration": unsupported,

"value.resource": unsupported,
"value.resource.iteration": unsupported,

"interior.class": unsupported,
"interior.function": unsupported,
"interior.if": unsupported,
"interior.lambda": unsupported,
"interior.loop": unsupported,
"interior.switchCase": unsupported,
"interior.ternary": unsupported,
"interior.try": unsupported,
"interior.with": unsupported,

// Not applicable

"interior.cell": notApplicable,
"interior.command": notApplicable,
"name.argument.actual.iteration": notApplicable,
"name.argument.actual": notApplicable,
"value.argument.actual": notApplicable,
"value.argument.actual.iteration": notApplicable,
"section.iteration.document": notApplicable,
"section.iteration.parent": notApplicable,
"textFragment.element": notApplicable,
command: notApplicable,
environment: notApplicable,
notebookCell: notApplicable,
section: notApplicable,
};

export const javascriptJsxScopeSupport: LanguageScopeSupportFacetMap = {
Expand All @@ -132,16 +183,25 @@ export const javascriptScopeSupport: LanguageScopeSupportFacetMap = {
...javascriptCoreScopeSupport,
...javascriptJsxScopeSupport,

"type.variable": notApplicable,
"type.argument.formal": notApplicable,
// Types are defined here because we don't want typescript to import them and
// accidentally forget to add support for them.
"value.typeAlias": notApplicable,
"type.alias": notApplicable,
"type.argument.formal.constructor.iteration": notApplicable,
"type.argument.formal.constructor": notApplicable,
"type.argument.formal.iteration": notApplicable,
"type.argument.formal.method": notApplicable,
"type.argument.formal.method.iteration": notApplicable,
"type.argument.formal.constructor": notApplicable,
"type.argument.formal.constructor.iteration": notApplicable,
"type.return": notApplicable,
"type.argument.formal.method": notApplicable,
"type.argument.formal": notApplicable,
"type.cast": notApplicable,
"type.class": notApplicable,
"type.enum": notApplicable,
"type.field.iteration": notApplicable,
"type.field": notApplicable,
"type.foreach": notApplicable,
"type.interface": notApplicable,
command: notApplicable,
"type.return": notApplicable,
"type.typeArgument.iteration": notApplicable,
"type.typeArgument": notApplicable,
"type.variable": notApplicable,
};
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const scopeSupportFacetInfos: Record<
scopeType: "namedFunction",
},
"namedFunction.iteration": {
description: "Iteration scope for named functions",
description: "Iteration scope for named functions: code blocks",
scopeType: "namedFunction",
isIteration: true,
},
Expand All @@ -172,7 +172,7 @@ export const scopeSupportFacetInfos: Record<
scopeType: "functionName",
},
"functionName.method.iteration.class": {
description: "Iteration scope for function names: class bodies",
description: "Iteration scope for method names: class bodies",
scopeType: "functionName",
isIteration: true,
},
Expand All @@ -181,7 +181,7 @@ export const scopeSupportFacetInfos: Record<
scopeType: "functionName",
},
"functionName.iteration": {
description: "Iteration scope for function names",
description: "Iteration scope for function names: code blocks",
scopeType: "functionName",
isIteration: true,
},
Expand Down
5 changes: 0 additions & 5 deletions packages/common/src/scopeSupportFacets/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const { supported } = ScopeSupportFacetLevel;
export const typescriptScopeSupport: LanguageScopeSupportFacetMap = {
...javascriptCoreScopeSupport,

"name.field": supported,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are already defined by javascript core


"type.argument.formal": supported,
"type.argument.formal.iteration": supported,
"type.argument.formal.method": supported,
Expand All @@ -23,8 +21,5 @@ export const typescriptScopeSupport: LanguageScopeSupportFacetMap = {
"type.return": supported,
"type.variable": supported,

"value.field": supported,
"value.typeAlias": supported,

disqualifyDelimiter: supported,
};
11 changes: 8 additions & 3 deletions queries/javascript.core.scm
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,14 @@

(switch_default) @branch

;;!! switch () {}
;;! ^^^^^^^^^^^^
(switch_statement) @branch.iteration @condition.iteration
;;!! switch () { }
;;! ^
(switch_statement
body: (_
"{" @branch.iteration.start.endOf @condition.iteration.start.endOf
"}" @branch.iteration.end.startOf @condition.iteration.end.startOf
)
) @branch.iteration.domain @condition.iteration.domain

;;!! if () {}
;;! ^^^^^^^^
Expand Down
Loading