diff options
| author | ST-DDT <[email protected]> | 2024-06-14 15:24:27 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-06-14 15:24:27 +0200 |
| commit | 5f77d389a805c6527b489c699a0b517ca9b17739 (patch) | |
| tree | e9cbd9e16dc558ac59919f22f2ba93099014f9b6 /src/modules | |
| parent | a5ffca1c7863531d459f67cbab7bd9ba34d16904 (diff) | |
| download | faker-5f77d389a805c6527b489c699a0b517ca9b17739.tar.xz faker-5f77d389a805c6527b489c699a0b517ca9b17739.zip | |
chore(helpers): deprecate invocations on non-functions for fakeEval (#2913)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/helpers/eval.ts | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/modules/helpers/eval.ts b/src/modules/helpers/eval.ts index 4a861ec0..5c34fbe6 100644 --- a/src/modules/helpers/eval.ts +++ b/src/modules/helpers/eval.ts @@ -81,7 +81,7 @@ export function fakeEval( do { let index: number; if (remaining.startsWith('(')) { - [index, current] = evalProcessFunction(remaining, current); + [index, current] = evalProcessFunction(remaining, current, expression); } else { [index, current] = evalProcessExpression(remaining, current); } @@ -109,10 +109,12 @@ export function fakeEval( * * @param input The input string to parse. * @param entrypoints The entrypoints to attempt the call on. + * @param expression The full expression to use in errors. */ function evalProcessFunction( input: string, - entrypoints: ReadonlyArray<unknown> + entrypoints: ReadonlyArray<unknown>, + expression: string ): [continueIndex: number, mapped: unknown[]] { const [index, params] = findParams(input); const nextChar = input[index + 1]; @@ -133,9 +135,22 @@ function evalProcessFunction( return [ index + (nextChar === '.' ? 2 : 1), // one for the closing bracket, one for the dot entrypoints.map((entrypoint): unknown => - // TODO @ST-DDT 2023-12-11: Replace in v9 + // TODO @ST-DDT 2023-12-11: Replace in v10 // typeof entrypoint === 'function' ? entrypoint(...params) : undefined - typeof entrypoint === 'function' ? entrypoint(...params) : entrypoint + { + if (typeof entrypoint === 'function') { + return entrypoint(...params); + } + + console.warn( + `[@faker-js/faker]: Invoking expressions which are not functions is deprecated since v9.0 and will be removed in v10.0. +Please remove the parentheses or replace the expression with an actual function. +${expression} +${' '.repeat(expression.length - input.length)}^` + ); + + return entrypoint; + } ), ]; } |
