Skip to content

Commit 9fe0e71

Browse files
committed
Fixes #2502 -- improper compilation with parenthesized inner value of instance properties in a class body.
1 parent b3452c1 commit 9fe0e71

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/coffee-script/nodes.js

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,12 +908,15 @@ exports.Class = class Class extends Base
908908
# Walk the body of the class, looking for prototype properties to be converted.
909909
walkBody: (name, o) ->
910910
@traverseChildren false, (child) =>
911+
cont = true
911912
return false if child instanceof Class
912913
if child instanceof Block
913914
for node, i in exps = child.expressions
914915
if node instanceof Value and node.isObject(true)
916+
cont = false
915917
exps[i] = @addProperties node, name, o
916918
child.expressions = exps = flatten exps
919+
cont and child not instanceof Class
917920

918921
# `use strict` (and other directives) must be the first expression statement(s)
919922
# of a function body. This method ensures the prologue is correctly positioned

test/classes.coffee

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ test "classes with value'd constructors", ->
312312
eq (new Two).value, 2
313313

314314

315-
test "exectuable class bodies", ->
315+
test "executable class bodies", ->
316316

317317
class A
318318
if true
@@ -326,6 +326,17 @@ test "exectuable class bodies", ->
326326
eq a.c, undefined
327327

328328

329+
test "#2502: parenthesizing inner object values", ->
330+
331+
class A
332+
category: (type: 'string')
333+
sections: (type: 'number', default: 0)
334+
335+
eq (new A).category.type, 'string'
336+
337+
eq (new A).sections.default, 0
338+
339+
329340
test "mild metaprogramming", ->
330341

331342
class Base

0 commit comments

Comments
 (0)