Skip to content

Commit 3433985

Browse files
committed
Fix bug with EOComputedFunctionExpressionProp super expressions
1 parent 552806a commit 3433985

6 files changed

Lines changed: 28 additions & 8 deletions

File tree

transforms/ember-object/__testfixtures__/decorators.input.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const Foo1 = EmberObject.extend({
2626
observedProp: watcher('xyz', function() {
2727
return 'observed';
2828
}),
29+
observedProp2: watcher('xyz', function() {
30+
return this._super(...arguments);
31+
}),
2932
event: on('click', function() {
3033
return 'abc';
3134
}),

transforms/ember-object/__testfixtures__/decorators.output.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class Foo1 extends EmberObject {
4646
return 'observed';
4747
}
4848

49+
@watcher('xyz')
50+
observedProp2() {
51+
return super.observedProp2(...arguments);
52+
}
53+
4954
@on('click')
5055
event() {
5156
return 'abc';

transforms/helpers/eo-prop/private/computed/function-expression.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { default as j } from 'jscodeshift';
22
import type * as AST from '../../../ast';
3-
import { replaceGetterSetterSuperExpressions } from '../../../transform-helper';
3+
import {
4+
replaceGetterSetterSuperExpressions,
5+
replaceMethodSuperExpressions,
6+
} from '../../../transform-helper';
47
import { assert, defined } from '../../../util/types';
58
import AbstractEOComputedProp from './abstract';
69

@@ -69,8 +72,7 @@ export default class EOComputedFunctionExpressionProp extends AbstractEOComputed
6972
lastArg && lastArg.type === 'FunctionExpression',
7073
'expected lastArg to be a FunctionExpression'
7174
);
72-
// FIXME: Is this correct? Maybe should handle kind === 'method' with replaceMethodSuperExpression ??
73-
return replaceGetterSetterSuperExpressions(
75+
return this.replaceSuperExpression(
7476
j.classMethod.from({
7577
kind: defined(this.kind),
7678
key: this.key,
@@ -83,4 +85,14 @@ export default class EOComputedFunctionExpressionProp extends AbstractEOComputed
8385
this.key
8486
);
8587
}
88+
89+
private get replaceSuperExpression(): (
90+
classMethod: AST.ClassMethod,
91+
replaceWithUndefined: boolean,
92+
identifier: AST.Identifier
93+
) => AST.ClassMethod {
94+
return this.kind === 'method'
95+
? replaceMethodSuperExpressions
96+
: replaceGetterSetterSuperExpressions;
97+
}
8698
}

transforms/helpers/eo-prop/private/function-expression.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { default as j } from 'jscodeshift';
22
import type * as AST from '../../ast';
3-
import { replaceMethodSuperExpression } from '../../transform-helper';
3+
import { replaceMethodSuperExpressions } from '../../transform-helper';
44
import AbstractEOProp from './abstract';
55

66
/**
@@ -42,7 +42,7 @@ export default class EOFunctionExpressionProp extends AbstractEOProp<
4242
protected override readonly supportsObjectLiteralDecorators = true;
4343

4444
build(): AST.ClassMethod {
45-
return replaceMethodSuperExpression(
45+
return replaceMethodSuperExpressions(
4646
j.classMethod.from({
4747
kind: 'method',
4848
key: this.key,

transforms/helpers/eo-prop/private/method.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { default as j } from 'jscodeshift';
22
import type * as AST from '../../ast';
3-
import { replaceMethodSuperExpression } from '../../transform-helper';
3+
import { replaceMethodSuperExpressions } from '../../transform-helper';
44
import AbstractEOProp from './abstract';
55

66
/**
@@ -46,7 +46,7 @@ export default class EOMethod extends AbstractEOProp<
4646
protected override readonly supportsObjectLiteralDecorators = true;
4747

4848
build(): AST.ClassMethod {
49-
return replaceMethodSuperExpression(
49+
return replaceMethodSuperExpressions(
5050
j.classMethod.from({
5151
kind: this.kind,
5252
key: this.key,

transforms/helpers/transform-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function replaceGetterSetterSuperExpressions(
129129
* super.methodName(...arguments);
130130
* ```
131131
*/
132-
export function replaceMethodSuperExpression(
132+
export function replaceMethodSuperExpressions(
133133
classMethod: AST.ClassMethod,
134134
replaceWithUndefined: boolean
135135
): AST.ClassMethod {

0 commit comments

Comments
 (0)