Skip to content

Commit 8e262ec

Browse files
committed
refactor(elements): drop bool transform on inputs with built-in ones
1 parent cd55104 commit 8e262ec

File tree

3 files changed

+30
-143
lines changed

3 files changed

+30
-143
lines changed

projects/igniteui-angular-elements/src/analyzer/component.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as ts from 'typescript';
22
import type { ComponentMetadata, ContentQuery } from './types';
3-
import { asString, first, getDecoratorName, getDecorators, getProvidedAs, getSelector, getTypeExpressionIdentifier, isMethod, isOverride, isProperty, isPublic, isReadOnly } from './utils';
3+
import { asString, first, getDecoratorName, getDecorators, getProvidedAs, getSelector, getTypeExpressionIdentifier, hasDecoratorTransformValue, isMethod, isOverride, isProperty, isPublic, isReadOnly } from './utils';
44

55

66
const isInput = (dec: ts.Decorator) => getDecoratorName(dec).includes('Input');
@@ -116,11 +116,16 @@ export class AnalyzerComponent {
116116
}
117117

118118
/**
119-
* Return all boolean `@Input` properties of the underlying component.
119+
* Return boolean `@Input` properties of the underlying component that require transform.
120120
*/
121121
private get booleanProperties() {
122-
return this.inputProperties
123-
.filter(prop => this.checker.getTypeAtLocation(prop.valueDeclaration!).getFlags() & ts.TypeFlags.Boolean);
122+
const res = this.inputProperties
123+
.filter(prop => this.checker.getTypeAtLocation(prop.valueDeclaration!).getFlags() & ts.TypeFlags.Boolean)
124+
.filter(prop => {
125+
const dec = getDecorators(first(prop.declarations as any)).find(isInput);
126+
return !hasDecoratorTransformValue(dec,'booleanAttribute');
127+
});
128+
return res;
124129
}
125130

126131
/**

projects/igniteui-angular-elements/src/analyzer/elements.config.ts

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export var registerConfig = [
5454
],
5555
additionalProperties: [],
5656
methods: ["show", "hide"],
57-
boolProps: ["hidden"],
5857
provideAs: IgxActionStripToken,
5958
},
6059
{
@@ -94,25 +93,6 @@ export var registerConfig = [
9493
"filterCellTemplate",
9594
],
9695
numericProps: ["rowEnd", "colEnd", "rowStart", "colStart"],
97-
boolProps: [
98-
"merge",
99-
"sortable",
100-
"selectable",
101-
"groupable",
102-
"editable",
103-
"filterable",
104-
"resizable",
105-
"autosizeHeader",
106-
"hasSummary",
107-
"hidden",
108-
"disableHiding",
109-
"disablePinning",
110-
"filteringIgnoreCase",
111-
"sortingIgnoreCase",
112-
"searchable",
113-
"pinned",
114-
"visibleWhenCollapsed",
115-
],
11696
},
11797
{
11898
component: IgxColumnGroupComponent,
@@ -154,26 +134,6 @@ export var registerConfig = [
154134
"filterCellTemplate",
155135
],
156136
numericProps: ["rowEnd", "colEnd", "rowStart", "colStart"],
157-
boolProps: [
158-
"collapsible",
159-
"expanded",
160-
"searchable",
161-
"hidden",
162-
"merge",
163-
"sortable",
164-
"groupable",
165-
"editable",
166-
"filterable",
167-
"resizable",
168-
"autosizeHeader",
169-
"hasSummary",
170-
"disableHiding",
171-
"disablePinning",
172-
"filteringIgnoreCase",
173-
"sortingIgnoreCase",
174-
"pinned",
175-
"visibleWhenCollapsed",
176-
],
177137
provideAs: IgxColumnComponent,
178138
},
179139
{
@@ -210,26 +170,6 @@ export var registerConfig = [
210170
"filterCellTemplate",
211171
],
212172
numericProps: ["rowEnd", "colEnd", "rowStart", "colStart"],
213-
boolProps: [
214-
"hidden",
215-
"collapsible",
216-
"expanded",
217-
"searchable",
218-
"merge",
219-
"sortable",
220-
"groupable",
221-
"editable",
222-
"filterable",
223-
"resizable",
224-
"autosizeHeader",
225-
"hasSummary",
226-
"disableHiding",
227-
"disablePinning",
228-
"filteringIgnoreCase",
229-
"sortingIgnoreCase",
230-
"pinned",
231-
"visibleWhenCollapsed",
232-
],
233173
provideAs: IgxColumnComponent,
234174
},
235175
{
@@ -387,22 +327,6 @@ export var registerConfig = [
387327
"rowHeight",
388328
"totalRecords",
389329
],
390-
boolProps: [
391-
"groupsExpanded",
392-
"hideGroupedColumns",
393-
"showGroupArea",
394-
"autoGenerate",
395-
"moving",
396-
"hideRowSelectors",
397-
"rowDraggable",
398-
"rowEditable",
399-
"isLoading",
400-
"allowFiltering",
401-
"allowAdvancedFiltering",
402-
"showSummaryOnCollapse",
403-
"batchEditing",
404-
"selectRowOnClick",
405-
],
406330
},
407331
{
408332
component: IgxGridEditingActionsComponent,
@@ -411,7 +335,6 @@ export var registerConfig = [
411335
contentQueries: [],
412336
additionalProperties: [{ name: "hasChildren" }],
413337
methods: ["startEdit"],
414-
boolProps: ["addRow", "editRow", "deleteRow", "addChild", "asMenuItems"],
415338
provideAs: IgxGridActionsBaseDirective,
416339
},
417340
{
@@ -421,7 +344,6 @@ export var registerConfig = [
421344
contentQueries: [],
422345
additionalProperties: [],
423346
methods: ["pin", "unpin", "scrollToRow"],
424-
boolProps: ["asMenuItems"],
425347
provideAs: IgxGridActionsBaseDirective,
426348
},
427349
{
@@ -472,7 +394,6 @@ export var registerConfig = [
472394
],
473395
additionalProperties: [{ name: "nativeElement" }],
474396
methods: [],
475-
boolProps: ["showProgress"],
476397
provideAs: IgxToolbarToken,
477398
},
478399
{
@@ -482,7 +403,6 @@ export var registerConfig = [
482403
contentQueries: [],
483404
additionalProperties: [],
484405
methods: ["export"],
485-
boolProps: ["exportCSV", "exportExcel"],
486406
},
487407
{
488408
component: IgxGridToolbarHidingComponent,
@@ -492,7 +412,6 @@ export var registerConfig = [
492412
additionalProperties: [],
493413
methods: ["checkAll", "uncheckAll"],
494414
numericProps: ["indentetion"],
495-
boolProps: ["hideFilter"],
496415
},
497416
{
498417
component: IgxGridToolbarPinningComponent,
@@ -502,7 +421,6 @@ export var registerConfig = [
502421
additionalProperties: [],
503422
methods: ["checkAll", "uncheckAll"],
504423
numericProps: ["indentetion"],
505-
boolProps: ["hideFilter"],
506424
},
507425
{
508426
component: IgxGridToolbarTitleComponent,
@@ -673,20 +591,6 @@ export var registerConfig = [
673591
"rowHeight",
674592
"totalRecords",
675593
],
676-
boolProps: [
677-
"expandChildren",
678-
"showExpandAll",
679-
"autoGenerate",
680-
"moving",
681-
"hideRowSelectors",
682-
"rowDraggable",
683-
"rowEditable",
684-
"isLoading",
685-
"allowFiltering",
686-
"allowAdvancedFiltering",
687-
"showSummaryOnCollapse",
688-
"selectRowOnClick",
689-
],
690594
},
691595
{
692596
component: IgxPaginatorComponent,
@@ -715,12 +619,6 @@ export var registerConfig = [
715619
contentQueries: [],
716620
additionalProperties: [{ name: "animationSettings", writable: true }],
717621
methods: [],
718-
boolProps: [
719-
"columnsExpanded",
720-
"rowsExpanded",
721-
"filtersExpanded",
722-
"valuesExpanded",
723-
],
724622
},
725623
{
726624
component: IgxPivotGridComponent,
@@ -830,13 +728,6 @@ export var registerConfig = [
830728
"rowSelectorTemplate",
831729
],
832730
numericProps: ["rowHeight"],
833-
boolProps: [
834-
"autoGenerateConfig",
835-
"superCompactMode",
836-
"defaultExpandState",
837-
"isLoading",
838-
"selectRowOnClick",
839-
],
840731
},
841732
{
842733
component: IgxRowIslandComponent,
@@ -975,20 +866,6 @@ export var registerConfig = [
975866
"rowHeight",
976867
"totalRecords",
977868
],
978-
boolProps: [
979-
"expandChildren",
980-
"showExpandAll",
981-
"autoGenerate",
982-
"moving",
983-
"hideRowSelectors",
984-
"rowDraggable",
985-
"rowEditable",
986-
"isLoading",
987-
"allowFiltering",
988-
"allowAdvancedFiltering",
989-
"showSummaryOnCollapse",
990-
"selectRowOnClick",
991-
],
992869
},
993870
{
994871
component: IgxTreeGridComponent,
@@ -1137,19 +1014,5 @@ export var registerConfig = [
11371014
"rowHeight",
11381015
"totalRecords",
11391016
],
1140-
boolProps: [
1141-
"cascadeOnDelete",
1142-
"autoGenerate",
1143-
"moving",
1144-
"hideRowSelectors",
1145-
"rowDraggable",
1146-
"rowEditable",
1147-
"isLoading",
1148-
"allowFiltering",
1149-
"allowAdvancedFiltering",
1150-
"showSummaryOnCollapse",
1151-
"batchEditing",
1152-
"selectRowOnClick",
1153-
],
11541017
},
11551018
];

projects/igniteui-angular-elements/src/analyzer/utils.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,17 @@ export function asString(x?: ts.Symbol) {
9999
/** Get the properties of the `@Component({ ...properties })` decorator object param */
100100
function getDecoratorProps(component: ts.ClassDeclaration): ts.NodeArray<ts.ObjectLiteralElementLike> | null {
101101
const expression = getDecorators(component)?.find(x => getDecoratorName(x) === 'Component')?.expression;
102+
return getCallExpressionProps(expression);
103+
}
102104

105+
/** Get the properties of the `func({ ...properties })` call expression object param */
106+
function getCallExpressionProps(expression?: ts.Expression): ts.NodeArray<ts.ObjectLiteralElementLike> | null {
103107
if (!expression || !ts.isCallExpression(expression))
104108
return null;
105109

106110
const args = [...expression.arguments];
107111

108-
if (!ts.isObjectLiteralExpression(args[0]))
112+
if (!args[0] || !ts.isObjectLiteralExpression(args[0]))
109113
return null;
110114

111115
const literal = args[0];
@@ -143,7 +147,6 @@ export function getProvidedAs(component: ts.ClassDeclaration, type: ts.Interface
143147
}
144148

145149
return null;
146-
147150
}
148151

149152
/**
@@ -200,6 +203,22 @@ export function isUseExistingType(obj: ts.ObjectLiteralExpression, type: ts.Inte
200203
return initializer ? initializer.getText() === type.symbol.escapedName : false;
201204
}
202205

206+
/**
207+
* Checks if a provided decorator's prams object transform property has the required value set
208+
*
209+
* @example
210+
* ```ts
211+
* Input({ transform: booleanAttribute })
212+
* ```
213+
*
214+
* @param decorator The decorator node
215+
* @param transform The transform value to check for
216+
*/
217+
export function hasDecoratorTransformValue(decorator: ts.Decorator | undefined, transform: string): boolean {
218+
const props = getCallExpressionProps(decorator?.expression);
219+
return !!props?.some(p => ts.isPropertyAssignment(p) && p.name.getText() === 'transform' && p.initializer.getText() === transform);
220+
}
221+
203222
/**
204223
* Checks if given import declaration contains a given type (by name for now)
205224
* @param importDecl the import declaration to check

0 commit comments

Comments
 (0)