Skip to content

Commit 70efe34

Browse files
committed
Fix l-value variable scope in assignments
Fixes #254
1 parent 008a045 commit 70efe34

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed

CoffeeScript.sublime-syntax

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ contexts:
3030

3131
script:
3232
- include: classes
33-
- include: keywords
3433
- include: functions
34+
- include: keywords
3535
- include: jsx-tags
3636
- include: expressions
3737

@@ -155,7 +155,7 @@ contexts:
155155
branch_point: function
156156
branch:
157157
- function-name
158-
- immediately-pop
158+
- variable
159159
- match: '[=-]>'
160160
scope: keyword.declaration.function.coffee
161161

@@ -353,41 +353,41 @@ contexts:
353353

354354
keywords:
355355
# export/import
356-
- match: export(?!\s*:)\b
356+
- match: export\b
357357
scope: keyword.control.export.coffee
358-
- match: (?:import|from)(?!\s*:)\b
358+
- match: (?:import|from)\b
359359
scope: keyword.control.import.coffee
360360
# excpetion
361-
- match: (?:catch|finally|try)(?!\s*:)\b
361+
- match: (?:catch|finally|try)\b
362362
scope: keyword.control.exception.coffee
363363
# conditional
364-
- match: if(?!\s*:)\b
364+
- match: if\b
365365
scope: keyword.control.conditional.if.coffee
366-
- match: else(?!\s*:)\b
366+
- match: else\b
367367
scope: keyword.control.conditional.else.coffee
368-
- match: switch(?!\s*:)\b
368+
- match: switch\b
369369
scope: keyword.control.conditional.switch.coffee
370-
- match: then(?!\s*:)\b
370+
- match: then\b
371371
scope: keyword.control.conditional.then.coffee
372-
- match: unless(?!\s*:)\b
372+
- match: unless\b
373373
scope: keyword.control.conditional.unless.coffee
374-
- match: when(?!\s*:)\b
374+
- match: when\b
375375
scope: keyword.control.conditional.when.coffee
376376
# loop
377-
- match: by(?!\s*:)\b
377+
- match: by\b
378378
scope: keyword.control.loop.by.coffee
379-
- match: do(?!\s*:)\b
379+
- match: do\b
380380
scope: keyword.control.loop.do.coffee
381-
- match: for(?:\s+own)?(?!\s*:)\b
381+
- match: for(?:\s+own)?\b
382382
scope: keyword.control.loop.for.coffee
383-
- match: loop(?!\s*:)\b
383+
- match: loop\b
384384
scope: keyword.control.loop.loopcoffee
385-
- match: until(?!\s*:)\b
385+
- match: until\b
386386
scope: keyword.control.loop.until.coffee
387-
- match: while(?!\s*:)\b
387+
- match: while\b
388388
scope: keyword.control.loop.while.coffee
389389
# flow
390-
- match: (?:await|break|continue|return|throw|yield(?:\s+from)?)(?!\s*:)\b
390+
- match: (?:await|break|continue|return|throw|yield(?:\s+from)?)\b
391391
scope: keyword.control.flow.coffee
392392
# other
393393
- match: (?:debugger\b|\\)
@@ -805,6 +805,24 @@ contexts:
805805
- match: '{{identifier}}'
806806
scope: variable.other.readwrite.coffee
807807

808+
variable:
809+
- match: (?:this|extends)(?!\s*[:=])\b
810+
scope: variable.language.coffee
811+
pop: 1
812+
- match: ({{identifier}})?(\.)
813+
captures:
814+
1: variable.other.object.coffee
815+
2: punctuation.accessor.dot.coffee
816+
set: member
817+
- match: (@)(?:{{identifier}})?
818+
scope: variable.other.member.coffee
819+
captures:
820+
1: punctuation.definition.variable.coffee
821+
pop: 1
822+
- match: '{{identifier}}'
823+
scope: variable.other.readwrite.coffee
824+
pop: 1
825+
808826
member:
809827
- meta_scope: meta.path.coffee
810828
# member objects

tests/syntax_test_scope.coffee

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,30 @@ class App.Router extends Snakeskin.Router
267267
->
268268
# ^^ keyword.declaration.function.coffee
269269

270+
geometry = new Class();
271+
# ^^^^^^^^ variable.other.readwrite.coffee
272+
# ^ keyword.operator.assignment.coffee
273+
# ^^^ keyword.operator.object.new.coffee
274+
# ^^^^^ support.class.coffee
275+
276+
try = new Class();
277+
# ^^^ variable.other.readwrite.coffee
278+
# ^ keyword.operator.assignment.coffee
279+
# ^^^ keyword.operator.object.new.coffee
280+
# ^^^^^ support.class.coffee
281+
282+
geometry: new Class();
283+
# ^^^^^^^^ variable.other.readwrite.coffee
284+
# ^ keyword.operator.assignment.coffee
285+
# ^^^ keyword.operator.object.new.coffee
286+
# ^^^^^ support.class.coffee
287+
288+
try: new Class();
289+
# ^^^ variable.other.readwrite.coffee
290+
# ^ keyword.operator.assignment.coffee
291+
# ^^^ keyword.operator.object.new.coffee
292+
# ^^^^^ support.class.coffee
293+
270294
###[ KEYWORDS ]################################################################
271295

272296
if .if _if $if

0 commit comments

Comments
 (0)