Skip to content

Commit fc43bc3

Browse files
committed
Standardize handling of decorators-disabled errors
1 parent d66c3c2 commit fc43bc3

4 files changed

Lines changed: 30 additions & 40 deletions

File tree

transforms/helpers/eo-extend-expression.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as AST from './ast';
33
import { createIdentifierDecorator } from './decorator-helper';
44
import type { DecoratorImportInfoMap } from './decorator-info';
55
import type { EOClassDecorator, EOProp } from './eo-prop/index';
6-
import makeEOProp from './eo-prop/index';
6+
import makeEOProp, { isEOClassDecorator, isEOProp } from './eo-prop/index';
77
import logger from './log-helper';
88
import type { Options } from './options';
99
import { getClassName, getExpressionToReplace } from './parse-helper';
@@ -16,8 +16,7 @@ export default class EOExtendExpression {
1616

1717
private expression: AST.EOExpression | null = null;
1818
private mixins: AST.EOMixin[];
19-
readonly properties: EOProp[];
20-
readonly decorators: EOClassDecorator[];
19+
readonly properties: Array<EOClassDecorator | EOProp>;
2120

2221
constructor(
2322
private path: AST.Path<AST.EOExtendExpression>,
@@ -48,24 +47,9 @@ export default class EOExtendExpression {
4847
this.mixins = mixins;
4948

5049
const rawProperties = this.expression?.properties ?? [];
51-
const properties: EOProp[] = [];
52-
const decorators: EOClassDecorator[] = [];
53-
54-
for (const property of rawProperties) {
55-
const eoProp = makeEOProp(
56-
property,
57-
existingDecoratorImportInfos,
58-
options
59-
);
60-
if (eoProp.isClassDecorator) {
61-
decorators.push(eoProp);
62-
} else {
63-
properties.push(eoProp);
64-
}
65-
}
66-
67-
this.properties = properties;
68-
this.decorators = decorators;
50+
this.properties = rawProperties.map((raw) =>
51+
makeEOProp(raw, existingDecoratorImportInfos, options)
52+
);
6953
}
7054

7155
transform(): boolean {
@@ -97,8 +81,8 @@ export default class EOExtendExpression {
9781
tagName: false,
9882
unobserves: false,
9983
};
100-
const allProps = [...this.decorators, ...this.properties];
101-
for (const prop of allProps) {
84+
const { properties } = this;
85+
for (const prop of properties) {
10286
specs = {
10387
action: specs.action || prop.decoratorImportSpecs.action,
10488
classNames: specs.classNames || prop.decoratorImportSpecs.classNames,
@@ -151,10 +135,10 @@ export default class EOExtendExpression {
151135
}
152136

153137
private buildClassBody(): AST.ClassBody {
154-
const { properties } = this;
138+
const objectProperties = this.properties.filter(isEOProp);
155139
let classBody: Parameters<AST.ClassBodyBuilder>[0] = [];
156140

157-
for (const prop of properties) {
141+
for (const prop of objectProperties) {
158142
const built = prop.build();
159143
if (Array.isArray(built)) {
160144
classBody = [...classBody, ...built];
@@ -186,16 +170,16 @@ export default class EOExtendExpression {
186170
}
187171

188172
private buildClassDecorators(): AST.Decorator[] {
189-
const { decorators } = this;
173+
const classDecoratorProperties = this.properties.filter(isEOClassDecorator);
190174
const { classicDecorator } = this.options;
191175
const classDecorators: AST.Decorator[] = [];
192176

193177
if (classicDecorator) {
194178
classDecorators.push(createIdentifierDecorator('classic'));
195179
}
196180

197-
for (const decorator of decorators) {
198-
classDecorators.push(decorator.build());
181+
for (const prop of classDecoratorProperties) {
182+
classDecorators.push(prop.build());
199183
}
200184

201185
return classDecorators;
@@ -219,6 +203,7 @@ export default class EOExtendExpression {
219203
for (const prop of this.properties) {
220204
errors = [...errors, ...prop.errors];
221205
}
206+
222207
return errors;
223208
}
224209

transforms/helpers/eo-prop/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,15 @@ export default function makeEOProp(
5252
return new EOSimpleProp(eoProp, options);
5353
}
5454
}
55+
56+
/** Type predicate */
57+
export function isEOProp(p: EOProp | EOClassDecorator): p is EOProp {
58+
return !p.isClassDecorator;
59+
}
60+
61+
/** Type predicate */
62+
export function isEOClassDecorator(
63+
p: EOProp | EOClassDecorator
64+
): p is EOClassDecorator {
65+
return p.isClassDecorator;
66+
}

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { Options } from '../../options';
44
import type { RuntimeData } from '../../runtime-data';
55
import type { DecoratorImportSpecs } from '../../util/index';
66
import {
7-
DECORATORS_REQUIRED_PROP_NAMES,
87
OFF_DECORATOR_NAME,
98
UNOBSERVES_DECORATOR_NAME,
109
allowObjectLiteralDecorator,
@@ -129,17 +128,6 @@ export default abstract class AbstractEOProp<
129128
errors.push(this.makeError("need option '--decorators=true'"));
130129
}
131130

132-
const unsupportedPropNames: readonly string[] = decorators
133-
? []
134-
: DECORATORS_REQUIRED_PROP_NAMES;
135-
if (unsupportedPropNames.includes(this.name)) {
136-
errors.push(
137-
this.makeError(
138-
`property with name '${this.name}' and type '${this.type}' can not be transformed`
139-
)
140-
);
141-
}
142-
143131
errors = [...errors, ...this.typeErrors];
144132

145133
return errors;

transforms/helpers/eo-prop/private/actions/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export default class EOActionsProp extends AbstractEOProp<
5050
});
5151
}
5252

53+
// eslint-disable-next-line @typescript-eslint/class-literal-property-style
54+
protected override get needsDecorators(): boolean {
55+
return true;
56+
}
57+
5358
protected override get typeErrors(): string[] {
5459
return [...this.lifecycleHookErrors, ...this.infiniteLoopErrors];
5560
}

0 commit comments

Comments
 (0)