diff --git a/lib/coffeescript/rewriter.js b/lib/coffeescript/rewriter.js index 833a6d08..f7ee7a42 100644 --- a/lib/coffeescript/rewriter.js +++ b/lib/coffeescript/rewriter.js @@ -542,6 +542,8 @@ // the continuation of an object. } else if (inImplicitObject() && tag === 'TERMINATOR' && prevTag !== ',' && !(startsLine && this.looksObjectish(i + 1))) { endImplicitObject(); + } else if (inImplicitControl() && tokens[stackTop()[1]][0] === 'CLASS' && tag === 'TERMINATOR') { + stack.pop(); } else { break; } diff --git a/src/rewriter.coffee b/src/rewriter.coffee index 2f6638e6..de9c646e 100644 --- a/src/rewriter.coffee +++ b/src/rewriter.coffee @@ -379,6 +379,8 @@ exports.Rewriter = class Rewriter else if inImplicitObject() and tag is 'TERMINATOR' and prevTag isnt ',' and not (startsLine and @looksObjectish(i + 1)) endImplicitObject() + else if inImplicitControl() and tokens[stackTop()[1]][0] is 'CLASS' and tag is 'TERMINATOR' + stack.pop() else break diff --git a/test/function_invocation.coffee b/test/function_invocation.coffee index a98c08a6..3b193de2 100644 --- a/test/function_invocation.coffee +++ b/test/function_invocation.coffee @@ -903,3 +903,24 @@ test "#4473: variable scope in chained calls", -> obj.foo({f} = {f: 1}).bar(-> 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