Skip to content

Commit 3ce8cae

Browse files
committed
Merge pull request #12 from bfanger/master
tests/cases/classes.coffee now "passes" using coffeescript 1.3.3
2 parents ef26288 + 247cd8c commit 3ce8cae

15 files changed

Lines changed: 257 additions & 69 deletions

src/CoffeeScript/Nodes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static function utility_extends()
6262
. 'function ctor() { '
6363
. 'this.constructor = child; '
6464
. '} '
65-
. 'ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; '
65+
. 'ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; '
6666
. 'return child; '
6767
. '}';
6868
}

src/CoffeeScript/yy/Class.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,6 @@ function compile_node($options)
121121
array_unshift($this->body->expressions, $this->ctor);
122122
}
123123

124-
if ($decl)
125-
{
126-
array_unshift($this->body->expressions, yy('Assign', yy('Value', yy('Literal', $name), array(yy('Access', yy('Literal', 'name')))), yy('Literal', "'{$name}'")));
127-
}
128-
129124
$this->body->expressions[] = $lname;
130125
$this->body->expressions = array_merge($this->directives, $this->body->expressions);
131126

tests/cases/assignment.coffee

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,18 @@ test "#1838: Regression with variable assignment", ->
350350
'dave'
351351

352352
eq name, 'dave'
353+
354+
test '#2211: splats in destructured parameters', ->
355+
doesNotThrow -> CoffeeScript.compile '([a...]) ->'
356+
doesNotThrow -> CoffeeScript.compile '([a...],b) ->'
357+
doesNotThrow -> CoffeeScript.compile '([a...],[b...]) ->'
358+
throws -> CoffeeScript.compile '([a...,[a...]]) ->'
359+
doesNotThrow -> CoffeeScript.compile '([a...,[b...]]) ->'
360+
361+
test '#2213: invocations within destructured parameters', ->
362+
throws -> CoffeeScript.compile '([a()])->'
363+
throws -> CoffeeScript.compile '([a:b()])->'
364+
throws -> CoffeeScript.compile '([a:b.c()])->'
365+
throws -> CoffeeScript.compile '({a()})->'
366+
throws -> CoffeeScript.compile '({a:b()})->'
367+
throws -> CoffeeScript.compile '({a:b.c()})->'

tests/cases/classes.coffee

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -595,17 +595,6 @@ test "#1813: Passing class definitions as expressions", ->
595595

596596
eq result, B
597597

598-
test "#494: Named classes", ->
599-
600-
class A
601-
eq A.name, 'A'
602-
603-
class A.B
604-
eq A.B.name, 'B'
605-
606-
class A.B["C"]
607-
ok A.B.C.name isnt 'C'
608-
609598
test "#1966: external constructors should produce their return value", ->
610599
ctor = -> {}
611600
class A then constructor: ctor
@@ -679,3 +668,11 @@ test "#1534: class then 'use strict'", ->
679668
#{error}"""
680669
]
681670
throws (-> CoffeeScript.run directive, bare: yes) for directive in directives
671+
672+
test "#2052: classes should work in strict mode", ->
673+
try
674+
do ->
675+
'use strict'
676+
class A
677+
catch e
678+
ok no

tests/cases/comprehensions.coffee

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -244,21 +244,13 @@ test "Optimized range comprehensions.", ->
244244

245245
exxes = ('x' for [0...10])
246246
ok exxes.join(' ') is 'x x x x x x x x x x'
247-
248-
249-
test "Comprehensions safely redeclare parameters if they're not present in closest scope.", ->
250-
251-
rule = (x) -> x
252-
253-
learn = ->
254-
rule for rule in [1, 2, 3]
255-
256-
ok learn().join(' ') is '1 2 3'
257-
258-
ok rule(101) is 101
259-
260-
f = -> [-> ok no, 'should cache source']
261-
ok yes for k of [f] = f()
247+
248+
249+
test "Loop variables should be able to reference outer variables", ->
250+
outer = 1
251+
do ->
252+
null for outer in [1, 2, 3]
253+
eq outer, 3
262254

263255

264256
test "Lenient on pure statements not trying to reach out of the closure", ->
@@ -499,3 +491,14 @@ test "#2007: Return object literal from comprehension", ->
499491
eq 2, y.length
500492
eq 1, y[0].x
501493
eq 0, y[1].x
494+
495+
test "#2274: Allow @values as loop variables", ->
496+
obj = {
497+
item: null
498+
method: ->
499+
for @item in [1, 2, 3]
500+
null
501+
}
502+
eq obj.item, null
503+
obj.method()
504+
eq obj.item, 3

tests/cases/functions.coffee

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ test "splats", ->
9595
arrayEq [0, 1], (((splat..., _, _1) -> splat) 0, 1, 2, 3)
9696
arrayEq [2], (((_, _1, splat..., _2) -> splat) 0, 1, 2, 3)
9797

98+
test "destructured splatted parameters", ->
99+
arr = [0,1,2]
100+
splatArray = ([a...]) -> a
101+
splatArrayRest = ([a...],b...) -> arrayEq(a,b); b
102+
arrayEq splatArray(arr), arr
103+
arrayEq splatArrayRest(arr,0,1,2), arr
104+
98105
test "@-parameters: automatically assign an argument's value to a property of the context", ->
99106
nonce = {}
100107

@@ -186,3 +193,16 @@ test "#1844: bound functions in nested comprehensions causing empty var statemen
186193
test "#1859: inline function bodies shouldn't modify prior postfix ifs", ->
187194
list = [1, 2, 3]
188195
ok true if list.some (x) -> x is 2
196+
197+
test "#2258: allow whitespace-style parameter lists in function definitions", ->
198+
func = (
199+
a, b, c
200+
) -> c
201+
eq func(1, 2, 3), 3
202+
203+
func = (
204+
a
205+
b
206+
c
207+
) -> b
208+
eq func(1, 2, 3), 2

tests/cases/objects.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,11 @@ test "#1961, #1974, regression with compound assigning to an implicit object", -
269269
four: 4
270270

271271
eq obj.four, 4
272+
273+
test "#2207: Immediate implicit closes don't close implicit objects", ->
274+
func = ->
275+
key: for i in [1, 2, 3] then i
276+
277+
eq func().key.join(' '), '1 2 3'
278+
279+

tests/cases/operators.coffee

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,11 @@ test "#2155 ... conditional assignment to a closure", ->
274274
x = null
275275
func = -> x ?= (-> if true then 'hi')
276276
func()
277-
eq x(), 'hi'
277+
eq x(), 'hi'
278+
279+
test "#2197: Existential existential double trouble", ->
280+
counter = 0
281+
func = -> counter++
282+
func()? ? 100
283+
eq counter, 1
284+

tests/cases/scope.coffee

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,66 @@ test "#1973: redefining Array/Object constructors shouldn't confuse __X helpers"
4141
obj = {arr}
4242
for own k of obj
4343
eq arr, obj[k]
44+
45+
test "#2255: global leak with splatted @-params", ->
46+
ok not x?
47+
arrayEq [0], ((@x...) -> @x).call {}, 0
48+
ok not x?
49+
50+
test "#1183: super + fat arrows", ->
51+
dolater = (cb) -> cb()
52+
53+
class A
54+
constructor: ->
55+
@_i = 0
56+
foo : (cb) ->
57+
dolater =>
58+
@_i += 1
59+
cb()
60+
61+
class B extends A
62+
constructor : ->
63+
super
64+
foo : (cb) ->
65+
dolater =>
66+
dolater =>
67+
@_i += 2
68+
super cb
69+
70+
b = new B
71+
b.foo => eq b._i, 3
72+
73+
test "#1183: super + wrap", ->
74+
class A
75+
m : -> 10
76+
77+
class B extends A
78+
constructor : -> super
79+
80+
B::m = -> r = try super()
81+
82+
eq (new B).m(), 10
83+
84+
test "#1183: super + closures", ->
85+
class A
86+
constructor: ->
87+
@i = 10
88+
foo : -> @i
89+
90+
class B extends A
91+
foo : ->
92+
ret = switch 1
93+
when 0 then 0
94+
when 1 then super()
95+
ret
96+
eq (new B).foo(), 10
97+
98+
test "#2331: bound super regression", ->
99+
class A
100+
@value = 'A'
101+
method: -> @constructor.value
102+
103+
class B extends A
104+
method: => super
105+
106+
eq (new B).method(), 'A'

tests/cases/soaks.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test "soaked property access caches method calls", ->
2323
eq nonce , obj.fn()?.a
2424
eq undefined, obj.fn()?.b
2525

26-
test "soaked property access chaching", ->
26+
test "soaked property access caching", ->
2727
nonce = {}
2828
counter = 0
2929
fn = ->

0 commit comments

Comments
 (0)