Skip to content

Commit

Permalink
Fix l-value variable scope in assignments
Browse files Browse the repository at this point in the history
Fixes #254
  • Loading branch information
deathaxe committed Sep 11, 2024
1 parent 008a045 commit 70efe34
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
54 changes: 36 additions & 18 deletions CoffeeScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ contexts:

script:
- include: classes
- include: keywords
- include: functions
- include: keywords
- include: jsx-tags
- include: expressions

Expand Down Expand Up @@ -155,7 +155,7 @@ contexts:
branch_point: function
branch:
- function-name
- immediately-pop
- variable
- match: '[=-]>'
scope: keyword.declaration.function.coffee

Expand Down Expand Up @@ -353,41 +353,41 @@ contexts:

keywords:
# export/import
- match: export(?!\s*:)\b
- match: export\b
scope: keyword.control.export.coffee
- match: (?:import|from)(?!\s*:)\b
- match: (?:import|from)\b
scope: keyword.control.import.coffee
# excpetion
- match: (?:catch|finally|try)(?!\s*:)\b
- match: (?:catch|finally|try)\b
scope: keyword.control.exception.coffee
# conditional
- match: if(?!\s*:)\b
- match: if\b
scope: keyword.control.conditional.if.coffee
- match: else(?!\s*:)\b
- match: else\b
scope: keyword.control.conditional.else.coffee
- match: switch(?!\s*:)\b
- match: switch\b
scope: keyword.control.conditional.switch.coffee
- match: then(?!\s*:)\b
- match: then\b
scope: keyword.control.conditional.then.coffee
- match: unless(?!\s*:)\b
- match: unless\b
scope: keyword.control.conditional.unless.coffee
- match: when(?!\s*:)\b
- match: when\b
scope: keyword.control.conditional.when.coffee
# loop
- match: by(?!\s*:)\b
- match: by\b
scope: keyword.control.loop.by.coffee
- match: do(?!\s*:)\b
- match: do\b
scope: keyword.control.loop.do.coffee
- match: for(?:\s+own)?(?!\s*:)\b
- match: for(?:\s+own)?\b
scope: keyword.control.loop.for.coffee
- match: loop(?!\s*:)\b
- match: loop\b
scope: keyword.control.loop.loopcoffee
- match: until(?!\s*:)\b
- match: until\b
scope: keyword.control.loop.until.coffee
- match: while(?!\s*:)\b
- match: while\b
scope: keyword.control.loop.while.coffee
# flow
- match: (?:await|break|continue|return|throw|yield(?:\s+from)?)(?!\s*:)\b
- match: (?:await|break|continue|return|throw|yield(?:\s+from)?)\b
scope: keyword.control.flow.coffee
# other
- match: (?:debugger\b|\\)
Expand Down Expand Up @@ -805,6 +805,24 @@ contexts:
- match: '{{identifier}}'
scope: variable.other.readwrite.coffee

variable:
- match: (?:this|extends)(?!\s*[:=])\b
scope: variable.language.coffee
pop: 1
- match: ({{identifier}})?(\.)
captures:
1: variable.other.object.coffee
2: punctuation.accessor.dot.coffee
set: member
- match: (@)(?:{{identifier}})?
scope: variable.other.member.coffee
captures:
1: punctuation.definition.variable.coffee
pop: 1
- match: '{{identifier}}'
scope: variable.other.readwrite.coffee
pop: 1

member:
- meta_scope: meta.path.coffee
# member objects
Expand Down
24 changes: 24 additions & 0 deletions tests/syntax_test_scope.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,30 @@ class App.Router extends Snakeskin.Router
->
# ^^ keyword.declaration.function.coffee

geometry = new Class();
# ^^^^^^^^ variable.other.readwrite.coffee
# ^ keyword.operator.assignment.coffee
# ^^^ keyword.operator.object.new.coffee
# ^^^^^ support.class.coffee

try = new Class();
# ^^^ variable.other.readwrite.coffee
# ^ keyword.operator.assignment.coffee
# ^^^ keyword.operator.object.new.coffee
# ^^^^^ support.class.coffee

geometry: new Class();
# ^^^^^^^^ variable.other.readwrite.coffee
# ^ keyword.operator.assignment.coffee
# ^^^ keyword.operator.object.new.coffee
# ^^^^^ support.class.coffee

try: new Class();
# ^^^ variable.other.readwrite.coffee
# ^ keyword.operator.assignment.coffee
# ^^^ keyword.operator.object.new.coffee
# ^^^^^ support.class.coffee

###[ KEYWORDS ]################################################################

if .if _if $if
Expand Down

0 comments on commit 70efe34

Please sign in to comment.