Allow implicit call with class with no body (#5053)

* allow implicit call with class with no body

* more tests
This commit is contained in:
Julian Rosse 2018-05-13 15:20:09 -04:00 committed by Geoffrey Booth
parent 8e66ae404e
commit 7dbdca8c54
3 changed files with 25 additions and 0 deletions

View File

@ -542,6 +542,8 @@
// the continuation of an object. // the continuation of an object.
} else if (inImplicitObject() && tag === 'TERMINATOR' && prevTag !== ',' && !(startsLine && this.looksObjectish(i + 1))) { } else if (inImplicitObject() && tag === 'TERMINATOR' && prevTag !== ',' && !(startsLine && this.looksObjectish(i + 1))) {
endImplicitObject(); endImplicitObject();
} else if (inImplicitControl() && tokens[stackTop()[1]][0] === 'CLASS' && tag === 'TERMINATOR') {
stack.pop();
} else { } else {
break; break;
} }

View File

@ -379,6 +379,8 @@ exports.Rewriter = class Rewriter
else if inImplicitObject() and tag is 'TERMINATOR' and prevTag isnt ',' and else if inImplicitObject() and tag is 'TERMINATOR' and prevTag isnt ',' and
not (startsLine and @looksObjectish(i + 1)) not (startsLine and @looksObjectish(i + 1))
endImplicitObject() endImplicitObject()
else if inImplicitControl() and tokens[stackTop()[1]][0] is 'CLASS' and tag is 'TERMINATOR'
stack.pop()
else else
break break

View File

@ -903,3 +903,24 @@ test "#4473: variable scope in chained calls", ->
obj.foo({f} = {f: 1}).bar(-> f = 5) obj.foo({f} = {f: 1}).bar(-> f = 5)
eq f, 5 eq f, 5
test "#5052: implicit call of class with no body", ->
doesNotThrow -> CoffeeScript.compile 'f class'
doesNotThrow -> CoffeeScript.compile 'f class A'
doesNotThrow -> CoffeeScript.compile 'f class A extends B'
f = (args...) -> args
a = 1
[klass, shouldBeA] = f class A, a
eq shouldBeA, a
[shouldBeA] = f a, class A
eq shouldBeA, a
[obj, klass, shouldBeA] =
f
b: 1
class A
a
eq shouldBeA, a