@@ -1636,17 +1636,16 @@ exports.Class = class Class extends Base
1636
1636
super ()
1637
1637
1638
1638
compileNode : (o ) ->
1639
- @name = @ determineName ()
1640
- executableBody = @ walkBody ()
1639
+ @name = @ determineName ()
1640
+ @ walkBody ()
1641
1641
1642
1642
# Special handling to allow `class expr.A extends A` declarations
1643
1643
parentName = @parent .base .value if @parent instanceof Value and not @parent .hasProperties ()
1644
1644
@hasNameClash = @name ? and @name is parentName
1645
1645
1646
1646
node = @
1647
-
1648
- if executableBody or @hasNameClash
1649
- node = new ExecutableClassBody node, executableBody
1647
+ if @executableBody or @hasNameClash
1648
+ node = new ExecutableClassBody node, @executableBody
1650
1649
else if not @name ? and o .level is LEVEL_TOP
1651
1650
# Anonymous classes are only valid in expressions
1652
1651
node = new Parens node
@@ -1666,7 +1665,7 @@ exports.Class = class Class extends Base
1666
1665
1667
1666
compileClassDeclaration : (o ) ->
1668
1667
@ctor ?= @ makeDefaultConstructor () if @externalCtor or @boundMethods .length
1669
- @ctor ? .noReturn = true
1668
+ @ctor ? .noReturn = yes
1670
1669
1671
1670
@ proxyBoundMethods () if @boundMethods .length
1672
1671
@@ -1678,10 +1677,14 @@ exports.Class = class Class extends Base
1678
1677
result .push @ makeCode (' extends ' ), @parent .compileToFragments (o)... , @ makeCode ' ' if @parent
1679
1678
1680
1679
result .push @ makeCode ' {'
1681
- unless @body .isEmpty ()
1682
- @body .spaced = true
1680
+ unless @passthroughBody . isEmpty () and @ body .isEmpty ()
1681
+ @body .spaced = yes
1683
1682
result .push @ makeCode ' \n '
1684
- result .push @body .compileToFragments (o, LEVEL_TOP)...
1683
+ unless @passthroughBody .isEmpty ()
1684
+ result .push @passthroughBody .compileToFragments (o, LEVEL_TOP)...
1685
+ result .push @ makeCode ' \n\n ' unless @body .isEmpty ()
1686
+ unless @body .isEmpty ()
1687
+ result .push @body .compileToFragments (o, LEVEL_TOP)...
1685
1688
result .push @ makeCode " \n #{ @tab } "
1686
1689
result .push @ makeCode ' }'
1687
1690
@@ -1704,21 +1707,21 @@ exports.Class = class Class extends Base
1704
1707
if name in JS_FORBIDDEN then " _#{ name} " else name
1705
1708
1706
1709
walkBody : ->
1707
- @ctor = null
1708
- @boundMethods = []
1709
- executableBody = null
1710
+ @ctor = null
1711
+ @boundMethods = []
1710
1712
1711
- initializer = []
1712
- { expressions } = @body
1713
+ initializer = []
1714
+ passthroughBodyExpressions = []
1715
+ { expressions } = @body
1713
1716
1714
1717
i = 0
1715
- for expression in expressions .slice ()
1716
- if expression instanceof Value and expression .isObject true
1718
+ for expression, expressionIndex in expressions .slice ()
1719
+ if expression instanceof Value and expression .isObject yes
1717
1720
{ properties } = expression .base
1718
1721
exprs = []
1719
1722
end = 0
1720
1723
start = 0
1721
- pushSlice = -> exprs .push new Value new Obj properties[start... end], true if end > start
1724
+ pushSlice = -> exprs .push new Value new Obj properties[start... end], yes if end > start
1722
1725
1723
1726
while assign = properties[end]
1724
1727
if initializerExpression = @ addInitializerExpression assign
@@ -1731,6 +1734,9 @@ exports.Class = class Class extends Base
1731
1734
1732
1735
expressions[i.. i] = exprs
1733
1736
i += exprs .length
1737
+ else if expression instanceof Value and expression .base instanceof PassthroughLiteral
1738
+ passthroughBodyExpressions .push expression
1739
+ expressions .splice expressionIndex, 1
1734
1740
else
1735
1741
if initializerExpression = @ addInitializerExpression expression
1736
1742
initializer .push initializerExpression
@@ -1746,9 +1752,12 @@ exports.Class = class Class extends Base
1746
1752
else if method .bound
1747
1753
@boundMethods .push method
1748
1754
1755
+ @passthroughBody = new Block passthroughBodyExpressions
1756
+
1749
1757
if initializer .length isnt expressions .length
1750
1758
@body .expressions = (expression .hoist () for expression in initializer)
1751
- new Block expressions
1759
+ @executableBody = new Block expressions
1760
+
1752
1761
1753
1762
# Add an expression to the class initializer
1754
1763
#
0 commit comments