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 <6577830+brandyscarney@users.noreply.github.com>
This commit is contained in:
Brandy Smith
2025-04-16 12:23:16 -04:00
committed by GitHub
parent 8dd566b5c1
commit d52fca084c
41 changed files with 124 additions and 92 deletions

View File

@ -584,7 +584,7 @@ export class Datetime implements ComponentInterface {
* Custom behavior: ['a', 'b']
*/
printIonWarning(
`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".
`[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".
Value Passed: [${value.map((v) => `'${v}'`).join(', ')}]
`,
@ -1389,24 +1389,24 @@ export class Datetime implements ComponentInterface {
if (multiple) {
if (presentation !== 'date') {
printIonWarning('Multiple date selection is only supported for presentation="date".', el);
printIonWarning('[ion-datetime] - Multiple date selection is only supported for presentation="date".', el);
}
if (preferWheel) {
printIonWarning('Multiple date selection is not supported with preferWheel="true".', el);
printIonWarning('[ion-datetime] - Multiple date selection is not supported with preferWheel="true".', el);
}
}
if (highlightedDates !== undefined) {
if (presentation !== 'date' && presentation !== 'date-time' && presentation !== 'time-date') {
printIonWarning(
'The highlightedDates property is only supported with the date, date-time, and time-date presentations.',
'[ion-datetime] - The highlightedDates property is only supported with the date, date-time, and time-date presentations.',
el
);
}
if (preferWheel) {
printIonWarning('The highlightedDates property is not supported with preferWheel="true".', el);
printIonWarning('[ion-datetime] - The highlightedDates property is not supported with preferWheel="true".', el);
}
}
@ -1668,7 +1668,7 @@ export class Datetime implements ComponentInterface {
disabled = !isDateEnabled(convertDataToISO(referenceParts));
} catch (e) {
printIonError(
'Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
'[ion-datetime] - Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
e
);
}
@ -1759,7 +1759,7 @@ export class Datetime implements ComponentInterface {
disabled = !isDateEnabled(convertDataToISO(referenceParts));
} catch (e) {
printIonError(
'Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
'[ion-datetime] - Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
e
);
}
@ -2262,7 +2262,7 @@ export class Datetime implements ComponentInterface {
isCalDayDisabled = !isDateEnabled(dateIsoString);
} catch (e) {
printIonError(
'Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
'[ion-datetime] - Exception thrown from provided `isDateEnabled` function. Please check your function and try again.',
el,
e
);
@ -2483,7 +2483,7 @@ export class Datetime implements ComponentInterface {
try {
headerText = titleSelectedDatesFormatter(convertDataToISO(activeParts));
} catch (e) {
printIonError('Exception in provided `titleSelectedDatesFormatter`: ', e);
printIonError('[ion-datetime] - Exception in provided `titleSelectedDatesFormatter`:', e);
}
}
} else {

View File

@ -687,7 +687,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
expect(logs.length).toBe(1);
expect(logs[0]).toContain(
'[Ionic Warning]: Datetime: "timeZone" and "timeZoneName" are not supported in "formatOptions".'
'[Ionic Warning]: [ion-datetime] - "timeZone" and "timeZoneName" are not supported in "formatOptions".'
);
});
@ -717,7 +717,7 @@ configs({ modes: ['md'], directions: ['ltr'] }).forEach(({ title, config }) => {
expect(logs.length).toBe(1);
expect(logs[0]).toContain(
"[Ionic Warning]: Datetime: The 'date-time' presentation requires either a date or time object (or both) in formatOptions."
"[Ionic Warning]: [ion-datetime] - The 'date-time' presentation requires either a date or time object (or both) in formatOptions."
);
});
});

View File

@ -48,7 +48,7 @@ export const warnIfValueOutOfBounds = (
for (const val of valueArray) {
if ((min !== undefined && isBefore(val, min)) || (max !== undefined && isAfter(val, max))) {
printIonWarning(
'The value provided to ion-datetime is out of bounds.\n\n' +
'[ion-datetime] - The value provided to ion-datetime is out of bounds.\n\n' +
`Min: ${JSON.stringify(min)}\n` +
`Max: ${JSON.stringify(max)}\n` +
`Value: ${JSON.stringify(value)}`

View File

@ -105,7 +105,9 @@ export function parseDate(val: string | string[] | undefined | null): DatetimePa
if (parse === null) {
// wasn't able to parse the ISO datetime
printIonWarning(`Unable to parse date string: ${val}. Please provide a valid ISO 8601 datetime string.`);
printIonWarning(
`[ion-datetime] - Unable to parse date string: ${val}. Please provide a valid ISO 8601 datetime string.`
);
return undefined;
}

View File

@ -218,7 +218,7 @@ export const getHighlightStyles = (
return highlightedDates(dateIsoString);
} catch (e) {
printIonError(
'Exception thrown from provided `highlightedDates` callback. Please check your function and try again.',
'[ion-datetime] - Exception thrown from provided `highlightedDates` callback. Please check your function and try again.',
el,
e
);

View File

@ -14,7 +14,7 @@ export const warnIfTimeZoneProvided = (el: HTMLElement, formatOptions?: FormatOp
formatOptions?.time?.timeZone ||
formatOptions?.time?.timeZoneName
) {
printIonWarning('Datetime: "timeZone" and "timeZoneName" are not supported in "formatOptions".', el);
printIonWarning('[ion-datetime] - "timeZone" and "timeZoneName" are not supported in "formatOptions".', el);
}
};
@ -33,19 +33,22 @@ export const checkForPresentationFormatMismatch = (
case 'month':
case 'year':
if (formatOptions.date === undefined) {
printIonWarning(`Datetime: The '${presentation}' presentation requires a date object in formatOptions.`, el);
printIonWarning(
`[ion-datetime] - The '${presentation}' presentation requires a date object in formatOptions.`,
el
);
}
break;
case 'time':
if (formatOptions.time === undefined) {
printIonWarning(`Datetime: The 'time' presentation requires a time object in formatOptions.`, el);
printIonWarning(`[ion-datetime] - The 'time' presentation requires a time object in formatOptions.`, el);
}
break;
case 'date-time':
case 'time-date':
if (formatOptions.date === undefined && formatOptions.time === undefined) {
printIonWarning(
`Datetime: The '${presentation}' presentation requires either a date or time object (or both) in formatOptions.`,
`[ion-datetime] - The '${presentation}' presentation requires either a date or time object (or both) in formatOptions.`,
el
);
}