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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export const getHighlightStyles = (
218218
return highlightedDates(dateIsoString);
219219
} catch (e) {
220220
printIonError(
221-
'Exception thrown from provided `highlightedDates` callback. Please check your function and try again.',
221+
'[ion-datetime] - Exception thrown from provided `highlightedDates` callback. Please check your function and try again.',
222222
el,
223223
e
224224
);

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const warnIfTimeZoneProvided = (el: HTMLElement, formatOptions?: FormatOp
1414
formatOptions?.time?.timeZone ||
1515
formatOptions?.time?.timeZoneName
1616
) {
17-
printIonWarning('Datetime: "timeZone" and "timeZoneName" are not supported in "formatOptions".', el);
17+
printIonWarning('[ion-datetime] - "timeZone" and "timeZoneName" are not supported in "formatOptions".', el);
1818
}
1919
};
2020

@@ -33,19 +33,22 @@ export const checkForPresentationFormatMismatch = (
3333
case 'month':
3434
case 'year':
3535
if (formatOptions.date === undefined) {
36-
printIonWarning(`Datetime: The '${presentation}' presentation requires a date object in formatOptions.`, el);
36+
printIonWarning(
37+
`[ion-datetime] - The '${presentation}' presentation requires a date object in formatOptions.`,
38+
el
39+
);
3740
}
3841
break;
3942
case 'time':
4043
if (formatOptions.time === undefined) {
41-
printIonWarning(`Datetime: The 'time' presentation requires a time object in formatOptions.`, el);
44+
printIonWarning(`[ion-datetime] - The 'time' presentation requires a time object in formatOptions.`, el);
4245
}
4346
break;
4447
case 'date-time':
4548
case 'time-date':
4649
if (formatOptions.date === undefined && formatOptions.time === undefined) {
4750
printIonWarning(
48-
`Datetime: The '${presentation}' presentation requires either a date or time object (or both) in formatOptions.`,
51+
`[ion-datetime] - The '${presentation}' presentation requires either a date or time object (or both) in formatOptions.`,
4952
el
5053
);
5154
}

core/src/components/input-password-toggle/input-password-toggle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class InputPasswordToggle implements ComponentInterface {
5959
onTypeChange(newValue: TextFieldTypes) {
6060
if (newValue !== 'text' && newValue !== 'password') {
6161
printIonWarning(
62-
`ion-input-password-toggle only supports inputs of type "text" or "password". Input of type "${newValue}" is not compatible.`,
62+
`[ion-input-password-toggle] - Only inputs of type "text" or "password" are supported. Input of type "${newValue}" is not compatible.`,
6363
this.el
6464
);
6565

@@ -74,7 +74,7 @@ export class InputPasswordToggle implements ComponentInterface {
7474

7575
if (!inputElRef) {
7676
printIonWarning(
77-
'No ancestor ion-input found for ion-input-password-toggle. This component must be slotted inside of an ion-input.',
77+
'[ion-input-password-toggle] - No ancestor ion-input found. This component must be slotted inside of an ion-input.',
7878
el
7979
);
8080

core/src/components/input/input.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const getCounterText = (
2424
try {
2525
return counterFormatter(valueLength, maxLength);
2626
} catch (e) {
27-
printIonError('Exception in provided `counterFormatter`.', e);
27+
printIonError('[ion-input] - Exception in provided `counterFormatter`:', e);
2828
return defaultCounterText;
2929
}
3030
};

core/src/components/item-sliding/item-sliding.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ComponentInterface, EventEmitter } from '@stencil/core';
22
import { Component, Element, Event, Host, Method, Prop, State, Watch, h } from '@stencil/core';
33
import { findClosestIonContent, disableContentScrollY, resetContentScrollY } from '@utils/content';
44
import { isEndSide } from '@utils/helpers';
5+
import { printIonWarning } from '@utils/logging';
56
import { watchForOptions } from '@utils/watch-options';
67

78
import { getIonMode } from '../../global/ionic-global';
@@ -343,7 +344,7 @@ export class ItemSliding implements ComponentInterface {
343344
case ItemSide.None:
344345
return;
345346
default:
346-
console.warn('invalid ItemSideFlags value', this.sides);
347+
printIonWarning('[ion-item-sliding] - invalid ItemSideFlags value', this.sides);
347348
break;
348349
}
349350

core/src/components/menu/menu.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { GESTURE_CONTROLLER } from '@utils/gesture';
66
import { shouldUseCloseWatcher } from '@utils/hardware-back-button';
77
import type { Attributes } from '@utils/helpers';
88
import { inheritAriaAttributes, assert, clamp, isEndSide as isEnd } from '@utils/helpers';
9+
import { printIonError } from '@utils/logging';
910
import { menuController } from '@utils/menu-controller';
1011
import { BACKDROP, GESTURE, getPresentedOverlay } from '@utils/overlays';
1112
import { isPlatform } from '@utils/platform';
@@ -215,13 +216,13 @@ export class Menu implements ComponentInterface, MenuI {
215216
const content = this.contentId !== undefined ? document.getElementById(this.contentId) : null;
216217

217218
if (content === null) {
218-
console.error('Menu: must have a "content" element to listen for drag events on.');
219+
printIonError('[ion-menu] - Must have a "content" element to listen for drag events on.');
219220
return;
220221
}
221222

222223
if (this.el.contains(content)) {
223-
console.error(
224-
`Menu: "contentId" should refer to the main view's ion-content, not the ion-content inside of the ion-menu.`
224+
printIonError(
225+
`[ion-menu] - The "contentId" should refer to the main view's ion-content, not the ion-content inside of the ion-menu.`
225226
);
226227
}
227228

core/src/components/modal/modal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
427427
}
428428

429429
if (breakpoints !== undefined && initialBreakpoint !== undefined && !breakpoints.includes(initialBreakpoint)) {
430-
printIonWarning('Your breakpoints array must include the initialBreakpoint value.');
430+
printIonWarning('[ion-modal] - Your breakpoints array must include the initialBreakpoint value.');
431431
}
432432

433433
if (!this.htmlAttributes?.id) {
@@ -847,12 +847,12 @@ export class Modal implements ComponentInterface, OverlayInterface {
847847
@Method()
848848
async setCurrentBreakpoint(breakpoint: number): Promise<void> {
849849
if (!this.isSheetModal) {
850-
printIonWarning('setCurrentBreakpoint is only supported on sheet modals.');
850+
printIonWarning('[ion-modal] - setCurrentBreakpoint is only supported on sheet modals.');
851851
return;
852852
}
853853
if (!this.breakpoints!.includes(breakpoint)) {
854854
printIonWarning(
855-
`Attempted to set invalid breakpoint value ${breakpoint}. Please double check that the breakpoint value is part of your defined breakpoints.`
855+
`[ion-modal] - Attempted to set invalid breakpoint value ${breakpoint}. Please double check that the breakpoint value is part of your defined breakpoints.`
856856
);
857857
return;
858858
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
145145
await modal.evaluate((el: HTMLIonModalElement) => el.setCurrentBreakpoint(0.5));
146146

147147
expect(warnings.length).toBe(1);
148-
expect(warnings[0]).toBe('[Ionic Warning]: setCurrentBreakpoint is only supported on sheet modals.');
148+
expect(warnings[0]).toBe(
149+
'[Ionic Warning]: [ion-modal] - setCurrentBreakpoint is only supported on sheet modals.'
150+
);
149151
});
150152

151153
test('it should return undefined when getting the breakpoint on a non-sheet modal', async ({ page }) => {

core/src/components/modal/test/sheet/modal.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
9696
test('it should warn when setting an invalid breakpoint', async () => {
9797
expect(warnings.length).toBe(1);
9898
expect(warnings[0]).toBe(
99-
'[Ionic Warning]: Attempted to set invalid breakpoint value 0.01. Please double check that the breakpoint value is part of your defined breakpoints.'
99+
'[Ionic Warning]: [ion-modal] - Attempted to set invalid breakpoint value 0.01. Please double check that the breakpoint value is part of your defined breakpoints.'
100100
);
101101
});
102102
});

0 commit comments

Comments
 (0)