Skip to content

Commit d52fca0

Browse files
fix(config): allow LogLevel to work with isolatedModules and update all warns and errors to respect logLevel (#30350)
Issue number: internal --------- ## What is the current behavior? - `LogLevel` throws error `Error: Cannot access ambient const enums when 'isolatedModules' is enabled` - Several existing console warns and errors are not calling the function that respects the `logLevel` config ## What is the new behavior? - Remove `const` from the `enum` to work with `isolatedModules` - Update `console.warn`s to `printIonWarning` - Update `console.error`s to `printIonError` ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information Dev build: `8.5.5-dev.11744729748.174bf7e0` --------- Co-authored-by: Brandy Smith <[email protected]>
1 parent 8dd566b commit d52fca0

File tree

41 files changed

+124
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+124
-92
lines changed

core/src/components/accordion-group/accordion-group.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class AccordionGroup implements ComponentInterface {
8787
* Custom behavior: ['a', 'b']
8888
*/
8989
printIonWarning(
90-
`ion-accordion-group was passed an array of values, but multiple="false". This is incorrect usage and may result in unexpected behaviors. To dismiss this warning, pass a string to the "value" property when multiple="false".
90+
`[ion-accordion-group] - An array of values was passed, but multiple is "false". This is incorrect usage and may result in unexpected behaviors. To dismiss this warning, pass a string to the "value" property when multiple="false".
9191
9292
Value Passed: [${value.map((v) => `'${v}'`).join(', ')}]
9393
`,

core/src/components/alert/alert.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Gesture } from '@utils/gesture';
55
import { createButtonActiveGesture } from '@utils/gesture/button-active';
66
import { raf } from '@utils/helpers';
77
import { createLockController } from '@utils/lock-controller';
8+
import { printIonWarning } from '@utils/logging';
89
import {
910
createDelegateController,
1011
createTriggerController,
@@ -318,8 +319,8 @@ export class Alert implements ComponentInterface, OverlayInterface {
318319
// checkboxes and inputs are all accepted, but they cannot be mixed.
319320
const inputTypes = new Set(inputs.map((i) => i.type));
320321
if (inputTypes.has('checkbox') && inputTypes.has('radio')) {
321-
console.warn(
322-
`Alert cannot mix input types: ${Array.from(inputTypes.values()).join(
322+
printIonWarning(
323+
`[ion-alert] - Alert cannot mix input types: ${Array.from(inputTypes.values()).join(
323324
'/'
324325
)}. Please see alert docs for more info.`
325326
);

core/src/components/app/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class App implements ComponentInterface {
4646
*/
4747
if (shouldUseCloseWatcher()) {
4848
printIonWarning(
49-
'experimentalCloseWatcher was set to `true`, but hardwareBackButton was set to `false`. Both config options must be `true` for the Close Watcher API to be used.'
49+
'[ion-app] - experimentalCloseWatcher was set to `true`, but hardwareBackButton was set to `false`. Both config options must be `true` for the Close Watcher API to be used.'
5050
);
5151
}
5252

core/src/components/button/button.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export class Button implements ComponentInterface, AnchorInterface, ButtonInterf
235235
* element with that id is not a form element.
236236
*/
237237
printIonWarning(
238-
`Form with selector: "#${form}" could not be found. Verify that the id is attached to a <form> element.`,
238+
`[ion-button] - Form with selector: "#${form}" could not be found. Verify that the id is attached to a <form> element.`,
239239
this.el
240240
);
241241
return null;
@@ -246,7 +246,7 @@ export class Button implements ComponentInterface, AnchorInterface, ButtonInterf
246246
* element with that id could not be found in the DOM.
247247
*/
248248
printIonWarning(
249-
`Form with selector: "#${form}" could not be found. Verify that the id is correct and the form is rendered in the DOM.`,
249+
`[ion-button] - Form with selector: "#${form}" could not be found. Verify that the id is correct and the form is rendered in the DOM.`,
250250
this.el
251251
);
252252
return null;
@@ -260,7 +260,7 @@ export class Button implements ComponentInterface, AnchorInterface, ButtonInterf
260260
* as the form attribute.
261261
*/
262262
printIonWarning(
263-
`The provided "form" element is invalid. Verify that the form is a HTMLFormElement and rendered in the DOM.`,
263+
`[ion-button] - The provided "form" element is invalid. Verify that the form is a HTMLFormElement and rendered in the DOM.`,
264264
this.el
265265
);
266266
return null;

core/src/components/button/test/form-reference/button.e2e.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ configs({ directions: ['ltr'], modes: ['ios'] }).forEach(({ title, config }) =>
169169

170170
expect(logs.length).toBe(1);
171171
expect(logs[0]).toContain(
172-
'[Ionic Warning]: Form with selector: "#missingForm" could not be found. Verify that the id is correct and the form is rendered in the DOM.'
172+
'[Ionic Warning]: [ion-button] - Form with selector: "#missingForm" could not be found. Verify that the id is correct and the form is rendered in the DOM.'
173173
);
174174
});
175175

@@ -197,7 +197,7 @@ configs({ directions: ['ltr'], modes: ['ios'] }).forEach(({ title, config }) =>
197197

198198
expect(logs.length).toBe(1);
199199
expect(logs[0]).toContain(
200-
'[Ionic Warning]: The provided "form" element is invalid. Verify that the form is a HTMLFormElement and rendered in the DOM.'
200+
'[Ionic Warning]: [ion-button] - The provided "form" element is invalid. Verify that the form is a HTMLFormElement and rendered in the DOM.'
201201
);
202202
});
203203
});

core/src/components/datetime-button/datetime-button.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ export class DatetimeButton implements ComponentInterface {
6363
const { datetime } = this;
6464
if (!datetime) {
6565
printIonError(
66-
'An ID associated with an ion-datetime instance is required for ion-datetime-button to function properly.',
66+
'[ion-datetime-button] - An ID associated with an ion-datetime instance is required to function properly.',
6767
this.el
6868
);
6969
return;
7070
}
7171

7272
const datetimeEl = (this.datetimeEl = document.getElementById(datetime) as HTMLIonDatetimeElement | null);
7373
if (!datetimeEl) {
74-
printIonError(`No ion-datetime instance found for ID '${datetime}'.`, this.el);
74+
printIonError(`[ion-datetime-button] - No ion-datetime instance found for ID '${datetime}'.`, this.el);
7575
return;
7676
}
7777

@@ -81,7 +81,7 @@ export class DatetimeButton implements ComponentInterface {
8181
*/
8282
if (datetimeEl.tagName !== 'ION-DATETIME') {
8383
printIonError(
84-
`Expected an ion-datetime instance for ID '${datetime}' but received '${datetimeEl.tagName.toLowerCase()}' instead.`,
84+
`[ion-datetime-button] - Expected an ion-datetime instance for ID '${datetime}' but received '${datetimeEl.tagName.toLowerCase()}' instead.`,
8585
datetimeEl
8686
);
8787
return;
@@ -245,7 +245,7 @@ export class DatetimeButton implements ComponentInterface {
245245
try {
246246
headerText = titleSelectedDatesFormatter(parsedValues);
247247
} catch (e) {
248-
printIonError('Exception in provided `titleSelectedDatesFormatter`: ', e);
248+
printIonError('[ion-datetime-button] - Exception in provided `titleSelectedDatesFormatter`:', e);
249249
}
250250
}
251251
this.dateText = headerText;

core/src/components/datetime/datetime.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ export class Datetime implements ComponentInterface {
584584
* Custom behavior: ['a', 'b']
585585
*/
586586
printIonWarning(
587-
`ion-datetime was passed an array of values, but multiple="false". This is incorrect usage and may result in unexpected behaviors. To dismiss this warning, pass a string to the "value" property when multiple="false".
587+
`[ion-datetime] - An array of values was passed, but multiple is "false". This is incorrect usage and may result in unexpected behaviors. To dismiss this warning, pass a string to the "value" property when multiple="false".
588588
589589
Value Passed: [${value.map((v) => `'${v}'`).join(', ')}]
590590
`,
@@ -1389,24 +1389,24 @@ export class Datetime implements ComponentInterface {
13891389

13901390
if (multiple) {
13911391
if (presentation !== 'date') {
1392-
printIonWarning('Multiple date selection is only supported for presentation="date".', el);
1392+
printIonWarning('[ion-datetime] - Multiple date selection is only supported for presentation="date".', el);
13931393
}
13941394

13951395
if (preferWheel) {
1396-
printIonWarning('Multiple date selection is not supported with preferWheel="true".', el);
1396+
printIonWarning('[ion-datetime] - Multiple date selection is not supported with preferWheel="true".', el);
13971397
}
13981398
}
13991399

14001400
if (highlightedDates !== undefined) {
14011401
if (presentation !== 'date' && presentation !== 'date-time' && presentation !== 'time-date') {
14021402
printIonWarning(
1403-
'The highlightedDates property is only supported with the date, date-time, and time-date presentations.',
1403+
'[ion-datetime] - The highlightedDates property is only supported with the date, date-time, and time-date presentations.',
14041404
el
14051405
);
14061406
}
14071407

14081408
if (preferWheel) {
1409-
printIonWarning('The highlightedDates property is not supported with preferWheel="true".', el);
1409+
printIonWarning('[ion-datetime] - The highlightedDates property is not supported with preferWheel="true".', el);
14101410
}
14111411
}
14121412

@@ -1668,7 +1668,7 @@ export class Datetime implements ComponentInterface {
16681668
disabled = !isDateEnabled(convertDataToISO(referenceParts));
16691669
} catch (e) {
16701670
printIonError(
1671-
'Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
1671+
'[ion-datetime] - Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
16721672
e
16731673
);
16741674
}
@@ -1759,7 +1759,7 @@ export class Datetime implements ComponentInterface {
17591759
disabled = !isDateEnabled(convertDataToISO(referenceParts));
17601760
} catch (e) {
17611761
printIonError(
1762-
'Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
1762+
'[ion-datetime] - Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
17631763
e
17641764
);
17651765
}
@@ -2262,7 +2262,7 @@ export class Datetime implements ComponentInterface {
22622262
isCalDayDisabled = !isDateEnabled(dateIsoString);
22632263
} catch (e) {
22642264
printIonError(
2265-
'Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
2265+
'[ion-datetime] - Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
22662266
el,
22672267
e
22682268
);
@@ -2483,7 +2483,7 @@ export class Datetime implements ComponentInterface {
24832483
try {
24842484
headerText = titleSelectedDatesFormatter(convertDataToISO(activeParts));
24852485
} catch (e) {
2486-
printIonError('Exception in provided `titleSelectedDatesFormatter`: ', e);
2486+
printIonError('[ion-datetime] - Exception in provided `titleSelectedDatesFormatter`:', e);
24872487
}
24882488
}
24892489
} else {

core/src/components/datetime/test/basic/datetime.e2e.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
687687

688688
expect(logs.length).toBe(1);
689689
expect(logs[0]).toContain(
690-
'[Ionic Warning]: Datetime: "timeZone" and "timeZoneName" are not supported in "formatOptions".'
690+
'[Ionic Warning]: [ion-datetime] - "timeZone" and "timeZoneName" are not supported in "formatOptions".'
691691
);
692692
});
693693

@@ -717,7 +717,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
717717

718718
expect(logs.length).toBe(1);
719719
expect(logs[0]).toContain(
720-
"[Ionic Warning]: Datetime: The 'date-time' presentation requires either a date or time object (or both) in formatOptions."
720+
"[Ionic Warning]: [ion-datetime] - The 'date-time' presentation requires either a date or time object (or both) in formatOptions."
721721
);
722722
});
723723
});

core/src/components/datetime/utils/comparison.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const warnIfValueOutOfBounds = (
4848
for (const val of valueArray) {
4949
if ((min !== undefined && isBefore(val, min)) || (max !== undefined && isAfter(val, max))) {
5050
printIonWarning(
51-
'The value provided to ion-datetime is out of bounds.\n\n' +
51+
'[ion-datetime] - The value provided to ion-datetime is out of bounds.\n\n' +
5252
`Min: ${JSON.stringify(min)}\n` +
5353
`Max: ${JSON.stringify(max)}\n` +
5454
`Value: ${JSON.stringify(value)}`

core/src/components/datetime/utils/parse.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ export function parseDate(val: string | string[] | undefined | null): DatetimePa
105105

106106
if (parse === null) {
107107
// wasn't able to parse the ISO datetime
108-
printIonWarning(`Unable to parse date string: ${val}. Please provide a valid ISO 8601 datetime string.`);
108+
printIonWarning(
109+
`[ion-datetime] - Unable to parse date string: ${val}. Please provide a valid ISO 8601 datetime string.`
110+
);
109111
return undefined;
110112
}
111113

0 commit comments

Comments
 (0)