Skip to content

Commit 42c4326

Browse files
committed
Fix arrow functions in derived class constructors
Fixes #1987
1 parent 3679110 commit 42c4326

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/codegeneration/ParenTrait.js

+16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import {
1616
ArgumentList,
1717
ArrayLiteral,
18+
BinaryExpression,
1819
ExpressionStatement,
1920
NewExpression,
2021
ParenExpression,
@@ -141,5 +142,20 @@ export function ParenTrait(ParseTreeTransformerClass) {
141142
}
142143
return new PropertyNameAssignment(tree.location, name, value);
143144
}
145+
146+
transformBinaryExpression(tree) {
147+
let left = this.transformAny(tree.left);
148+
let right = this.transformAny(tree.right);
149+
if (left.type === COMMA_EXPRESSION) {
150+
left = wrap(left);
151+
}
152+
if (right.type === COMMA_EXPRESSION) {
153+
right = wrap(right);
154+
}
155+
if (left === tree.left && right === tree.right) {
156+
return tree;
157+
}
158+
return new BinaryExpression(tree.location, left, tree.operator, right);
159+
}
144160
};
145161
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Base {
2+
bar() {
3+
return 1;
4+
}
5+
}
6+
7+
class Derived extends Base {
8+
constructor() {
9+
super()
10+
this.foo = () => {
11+
return this.bar();
12+
};
13+
}
14+
bar() {
15+
return 2;
16+
}
17+
}
18+
19+
let d = new Derived();
20+
assert.equal(2, (0, d).foo());

0 commit comments

Comments
 (0)