Skip to content

Commit 6f9e491

Browse files
committed
Don't assign undefined
1 parent 34123b3 commit 6f9e491

4 files changed

Lines changed: 43 additions & 37 deletions

File tree

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,97 +30,97 @@ class Foo extends EmberObject {
3030
// @ember/object/computed
3131

3232
@alias('foo')
33-
hasAlias = undefined;
33+
hasAlias;
3434

3535
@and('foo', 'bar')
36-
hasAnd = undefined;
36+
hasAnd;
3737

3838
@bool('foo')
39-
hasBool = undefined;
39+
hasBool;
4040

4141
@collect('foo', 'bar')
42-
hasCollect = undefined;
42+
hasCollect;
4343

4444
@deprecatingAlias('foo')
45-
hasDeprecatingAlias = undefined;
45+
hasDeprecatingAlias;
4646

4747
@empty('foo')
48-
hasEmpty = undefined;
48+
hasEmpty;
4949

5050
@equal('foo', 'bar')
51-
hasEqual = undefined;
51+
hasEqual;
5252

5353
@filterBy('foo', 'bar')
54-
hasFilterBy = undefined;
54+
hasFilterBy;
5555

5656
@gt('foo', 'bar')
57-
hasGt = undefined;
57+
hasGt;
5858

5959
@gte('foo', 'bar')
60-
hasGte = undefined;
60+
hasGte;
6161

6262
@intersect('foo', 'bar')
63-
hasIntersect = undefined;
63+
hasIntersect;
6464

6565
@lt('foo', 'bar')
66-
hasLt = undefined;
66+
hasLt;
6767

6868
@lte('foo', 'bar')
69-
hasLte = undefined;
69+
hasLte;
7070

7171
@mapBy('foo', 'bar')
72-
hasMapBy = undefined;
72+
hasMapBy;
7373

7474
@match('foo', /bar/)
75-
hasMatch = undefined;
75+
hasMatch;
7676

7777
@max('foo', 'bar')
78-
hasMax = undefined;
78+
hasMax;
7979

8080
@min('foo', 'bar')
81-
hasMin = undefined;
81+
hasMin;
8282

8383
@none('foo')
84-
hasNone = undefined;
84+
hasNone;
8585

8686
@not('foo')
87-
hasNot = undefined;
87+
hasNot;
8888

8989
@notEmpty('foo')
90-
hasNotEmpty = undefined;
90+
hasNotEmpty;
9191

9292
@oneWay('foo')
93-
hasOneWay = undefined;
93+
hasOneWay;
9494

9595
@or('foo', 'bar')
96-
hasOr = undefined;
96+
hasOr;
9797

9898
@readOnly('foo')
99-
hasReadOnly = undefined;
99+
hasReadOnly;
100100

101101
@reads('foo')
102-
hasReads = undefined;
102+
hasReads;
103103

104104
@setDiff('foo', 'bar')
105-
hasSetDiff = undefined;
105+
hasSetDiff;
106106

107107
@sum('foo', 'bar')
108-
hasSum = undefined;
108+
hasSum;
109109

110110
@union('foo', 'bar')
111-
hasUnion = undefined;
111+
hasUnion;
112112

113113
@uniq('foo')
114-
hasUniq = undefined;
114+
hasUniq;
115115

116116
@uniqBy('foo', 'bar')
117-
hasUniqBy = undefined;
117+
hasUniqBy;
118118

119119
@filter('foo', function(foo, index, array) { return false })
120-
hasFilter = undefined;
120+
hasFilter;
121121

122122
@map('foo', function(foo, index, array) { return 'bar' })
123-
hasMap = undefined;
123+
hasMap;
124124

125125
@sort('foo', function(a, b) {
126126
if (a.priority > b.priority) {
@@ -131,7 +131,7 @@ class Foo extends EmberObject {
131131

132132
return 0;
133133
})
134-
hasSort = undefined;
134+
hasSort;
135135

136136
// @glimmer/tracking
137137

transforms/helpers/ast.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ export function isNode<T extends ASTNode['type'] = ASTNode['type']>(
7070
);
7171
}
7272

73-
function isIdent(u: unknown, ...names: string[]): u is Identifier {
73+
/**
74+
* Type predicate that checks if the value is an Identifier
75+
* (matching one of the given names, if provided).
76+
*/
77+
export function isIdent(u: unknown, ...names: string[]): u is Identifier {
7478
return isNode(u, 'Identifier') && names.includes(u.name);
7579
}
7680

transforms/helpers/eo-prop/private/computed/property.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ export default class EOComputedProp extends AbstractEOComputedProp<AST.ClassProp
4949
build(): AST.ClassProperty {
5050
const classProp = j.classProperty.from({
5151
key: this.key,
52-
// TODO: This how we can remove the `= undefined` value;
53-
value: this.hasDecorators ? null : this.value,
52+
value: null,
5453
comments: this.comments,
5554
computed: this.rawProp.computed ?? false,
5655
});

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { default as j } from 'jscodeshift';
2-
import type * as AST from '../../ast';
2+
import * as AST from '../../ast';
33
import { createDecoratorWithArgs } from '../../decorator-helper';
44
import logger from '../../log-helper';
55
import AbstractEOProp from './abstract';
@@ -50,7 +50,10 @@ export default class EOSimpleProp extends AbstractEOProp<
5050
build(): AST.ClassProperty {
5151
const classProp = j.classProperty.from({
5252
key: this.key,
53-
value: this.hasDecorators ? null : this.value,
53+
value:
54+
this.hasDecorators || AST.isIdent(this.value, 'undefined')
55+
? null
56+
: this.value,
5457
comments: this.comments,
5558
computed: this.rawProp.computed ?? false,
5659
});

0 commit comments

Comments
 (0)