mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(common): drop value not a number message in production (#60699)
Drops value not a number message in production. PR Close #60699
This commit is contained in:
parent
1c6d5b2e23
commit
ad5fbd944d
4 changed files with 22 additions and 8 deletions
|
|
@ -71,7 +71,9 @@ export const enum RuntimeErrorCode {
|
|||
// (undocumented)
|
||||
UNKNOWN_DATE_TYPE_VALUE = 2301,
|
||||
// (undocumented)
|
||||
UNKNOWN_ZONE_WIDTH = 2302
|
||||
UNKNOWN_ZONE_WIDTH = 2302,
|
||||
// (undocumented)
|
||||
VALUE_NOT_A_NUMBER = 2309
|
||||
}
|
||||
|
||||
// (No @packageDocumentation comment for this package)
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ export const enum RuntimeErrorCode {
|
|||
INVALID_DIGIT_INFO = 2306,
|
||||
INVALID_NUMBER_OF_DIGITS_AFTER_FRACTION = 2307,
|
||||
NO_PLURAL_MESSAGE_FOUND = 2308,
|
||||
VALUE_NOT_A_NUMBER = 2309,
|
||||
|
||||
// Keep 2800 - 2900 for Http Errors.
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,20 @@
|
|||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
|
||||
import {DEFAULT_CURRENCY_CODE, Inject, LOCALE_ID, Pipe, PipeTransform} from '@angular/core';
|
||||
import {
|
||||
DEFAULT_CURRENCY_CODE,
|
||||
Inject,
|
||||
LOCALE_ID,
|
||||
Pipe,
|
||||
PipeTransform,
|
||||
ɵRuntimeError as RuntimeError,
|
||||
} from '@angular/core';
|
||||
|
||||
import {formatCurrency, formatNumber, formatPercent} from '../i18n/format_number';
|
||||
import {getCurrencySymbol} from '../i18n/locale_data_api';
|
||||
|
||||
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
|
||||
import {RuntimeErrorCode} from '../errors';
|
||||
|
||||
/**
|
||||
* @ngModule CommonModule
|
||||
|
|
@ -274,7 +282,7 @@ export class CurrencyPipe implements PipeTransform {
|
|||
locale ||= this._locale;
|
||||
|
||||
if (typeof display === 'boolean') {
|
||||
if ((typeof ngDevMode === 'undefined' || ngDevMode) && <any>console && <any>console.warn) {
|
||||
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
||||
console.warn(
|
||||
`Warning: the currency pipe has been changed in Angular v5. The symbolDisplay option (third parameter) is now a string instead of a boolean. The accepted values are "code", "symbol" or "symbol-narrow".`,
|
||||
);
|
||||
|
|
@ -313,7 +321,10 @@ function strToNumber(value: number | string): number {
|
|||
return Number(value);
|
||||
}
|
||||
if (typeof value !== 'number') {
|
||||
throw new Error(`${value} is not a number`);
|
||||
throw new RuntimeError(
|
||||
RuntimeErrorCode.VALUE_NOT_A_NUMBER,
|
||||
ngDevMode && `${value} is not a number`,
|
||||
);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,10 +63,10 @@ describe('Number pipes', () => {
|
|||
|
||||
it('should not support other objects', () => {
|
||||
expect(() => pipe.transform({} as any)).toThrowError(
|
||||
`NG02100: InvalidPipeArgument: '[object Object] is not a number' for pipe 'DecimalPipe'`,
|
||||
`NG02100: InvalidPipeArgument: 'NG02309: [object Object] is not a number' for pipe 'DecimalPipe'`,
|
||||
);
|
||||
expect(() => pipe.transform('123abc')).toThrowError(
|
||||
`NG02100: InvalidPipeArgument: '123abc is not a number' for pipe 'DecimalPipe'`,
|
||||
`NG02100: InvalidPipeArgument: 'NG02309: 123abc is not a number' for pipe 'DecimalPipe'`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -125,7 +125,7 @@ describe('Number pipes', () => {
|
|||
|
||||
it('should not support other objects', () => {
|
||||
expect(() => pipe.transform({} as any)).toThrowError(
|
||||
`NG02100: InvalidPipeArgument: '[object Object] is not a number' for pipe 'PercentPipe'`,
|
||||
`NG02100: InvalidPipeArgument: 'NG02309: [object Object] is not a number' for pipe 'PercentPipe'`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -214,7 +214,7 @@ describe('Number pipes', () => {
|
|||
|
||||
it('should not support other objects', () => {
|
||||
expect(() => pipe.transform({} as any)).toThrowError(
|
||||
`NG02100: InvalidPipeArgument: '[object Object] is not a number' for pipe 'CurrencyPipe'`,
|
||||
`NG02100: InvalidPipeArgument: 'NG02309: [object Object] is not a number' for pipe 'CurrencyPipe'`,
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue