Skip to content

Commit cc7e63f

Browse files
authored
Merge pull request sublimehq#1464 from Thom1729/javascript-cleanup-nested-scopes
[JavaScript] Clean up nested scopes, fix a missing dollar highlight.
2 parents 5678855 + 3c42a72 commit cc7e63f

File tree

2 files changed

+76
-63
lines changed

2 files changed

+76
-63
lines changed

JavaScript/JavaScript.sublime-syntax

+72-63
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,6 @@ contexts:
996996
- match: class{{identifier_break}}
997997
scope: storage.type.class.js
998998
set:
999-
- - include: immediately-pop
1000999
- class-meta
10011000
- class-body
10021001
- class-extends
@@ -1009,31 +1008,33 @@ contexts:
10091008
class-body:
10101009
- match: '\{'
10111010
scope: punctuation.section.block.js
1012-
set:
1013-
- meta_scope: meta.block.js
1011+
set: class-body-contents
10141012

1015-
- match: '\}'
1016-
scope: punctuation.section.block.js
1017-
pop: true
1013+
- include: else-pop
10181014

1019-
- match: \;
1020-
scope: punctuation.terminator.statement.js
1015+
class-body-contents:
1016+
- meta_scope: meta.block.js
10211017

1022-
- match: constructor{{identifier_break}}
1023-
scope: entity.name.function.constructor.js
1024-
push:
1025-
- function-declaration-expect-body
1026-
- function-declaration-meta
1027-
- function-declaration-expect-parameters
1018+
- match: '\}'
1019+
scope: punctuation.section.block.js
1020+
pop: true
1021+
1022+
- match: \;
1023+
scope: punctuation.terminator.statement.js
10281024

1029-
- match: static{{identifier_break}}
1030-
scope: storage.modifier.js
1031-
push: class-field
1025+
- match: constructor{{identifier_break}}
1026+
scope: entity.name.function.constructor.js
1027+
push:
1028+
- function-declaration-expect-body
1029+
- function-declaration-meta
1030+
- function-declaration-expect-parameters
10321031

1033-
- match: (?={{class_element_name}})
1034-
push: class-field
1032+
- match: static{{identifier_break}}
1033+
scope: storage.modifier.js
1034+
push: class-field
10351035

1036-
- include: else-pop
1036+
- match: (?={{class_element_name}})
1037+
push: class-field
10371038

10381039
class-extends:
10391040
- match: extends{{identifier_break}}
@@ -1337,54 +1338,62 @@ contexts:
13371338
object-literal:
13381339
- match: '\{'
13391340
scope: punctuation.section.block.js
1340-
set:
1341-
- meta_scope: meta.object-literal.js
1342-
- match: '\}'
1343-
scope: punctuation.section.block.js
1344-
pop: true
1341+
set: object-literal-contents
13451342

1346-
- match: \.\.\.
1347-
scope: keyword.operator.spread.js
1348-
push: expression-no-comma
1343+
object-literal-contents:
1344+
- meta_scope: meta.object-literal.js
13491345

1350-
- match: >-
1351-
(?x)(?=
1352-
{{property_name}}\s*:
1353-
(?: {{either_func_lookahead}} )
1354-
)
1355-
push:
1356-
- either-function-declaration
1357-
- function-declaration-meta
1358-
- object-literal-expect-colon
1359-
- object-literal-meta-key
1360-
- method-name
1346+
- match: '\}'
1347+
scope: punctuation.section.block.js
1348+
pop: true
13611349

1362-
- match: '{{method_lookahead}}'
1363-
push: method-declaration
1350+
- match: \.\.\.
1351+
scope: keyword.operator.spread.js
1352+
push: expression-no-comma
13641353

1365-
- match: '{{identifier}}(?=\s*(?:[},]|$|//|/\*))'
1366-
scope: variable.other.readwrite.js
1367-
- match: (?=\[)
1368-
push: computed-property-name
1369-
- match: "(?=\"|')"
1370-
push:
1371-
- object-literal-meta-key
1372-
- literal-string
1373-
- match: '{{dollar_identifier}}'
1374-
scope: meta.object-literal.key.dollar.js
1375-
captures:
1376-
1: punctuation.dollar.js
1377-
- match: '{{identifier}}'
1378-
scope: meta.object-literal.key.js
1379-
- match: (?=[-+]?(?:\.[0-9]|0[bxo]|\d))
1380-
push:
1381-
- meta_scope: meta.object-literal.key.js
1382-
- include: literal-number
1354+
- match: >-
1355+
(?x)(?=
1356+
{{property_name}}\s*:
1357+
(?: {{either_func_lookahead}} )
1358+
)
1359+
push:
1360+
- either-function-declaration
1361+
- function-declaration-meta
1362+
- object-literal-expect-colon
1363+
- object-literal-meta-key
1364+
- method-name
13831365
1384-
- include: comma-separator
1385-
- match: ':'
1386-
scope: punctuation.separator.key-value.js
1387-
push: expression-no-comma
1366+
- match: '{{method_lookahead}}'
1367+
push: method-declaration
1368+
1369+
- match: '{{identifier}}(?=\s*(?:[},]|$|//|/\*))'
1370+
scope: variable.other.readwrite.js
1371+
- match: (?=\[)
1372+
push: computed-property-name
1373+
- match: "(?=\"|')"
1374+
push:
1375+
- object-literal-meta-key
1376+
- literal-string
1377+
- include: bare-property-name
1378+
- match: (?=[-+]?(?:\.[0-9]|0[bxo]|\d))
1379+
push:
1380+
- meta_scope: meta.object-literal.key.js
1381+
- include: literal-number
1382+
1383+
- include: comma-separator
1384+
- match: ':'
1385+
scope: punctuation.separator.key-value.js
1386+
push: expression-no-comma
1387+
1388+
bare-property-name:
1389+
- match: '{{dollar_only_identifier}}'
1390+
scope: meta.object-literal.key.dollar.only.js punctuation.dollar.js
1391+
- match: '{{dollar_identifier}}'
1392+
scope: meta.object-literal.key.dollar.js
1393+
captures:
1394+
1: punctuation.dollar.js
1395+
- match: '{{identifier}}'
1396+
scope: meta.object-literal.key.js
13881397

13891398
computed-property-name:
13901399
- match: \[

JavaScript/tests/syntax_test_js.js

+4
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ var obj = {
399399
$key3: 0,
400400
// <- meta.object-literal.key.dollar punctuation.dollar
401401
// <- meta.object-literal.key.dollar - punctuation.dollar
402+
403+
$: 0,
404+
// ^ meta.object-literal.key.dollar.only punctuation.dollar
405+
402406
$keyFunc: function() {
403407
// ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration
404408
// <- meta.object-literal.key.dollar entity.name.function punctuation.dollar

0 commit comments

Comments
 (0)