From 0041e3bb49e3ef23bd81c320a07b7cb4a18e7e0d Mon Sep 17 00:00:00 2001 From: ppisljar Date: Thu, 10 Mar 2022 07:18:27 -0800 Subject: [PATCH] fixing getByAlias --- src/plugins/expressions/common/executor/executor.ts | 6 +++--- src/plugins/expressions/common/util/get_by_alias.ts | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/plugins/expressions/common/executor/executor.ts b/src/plugins/expressions/common/executor/executor.ts index 4b953db4ea820..fb019dc7b9d53 100644 --- a/src/plugins/expressions/common/executor/executor.ts +++ b/src/plugins/expressions/common/executor/executor.ts @@ -20,7 +20,7 @@ import { ExpressionType } from '../expression_types/expression_type'; import { AnyExpressionTypeDefinition } from '../expression_types/types'; import { ExpressionAstExpression, ExpressionAstFunction } from '../ast'; import { ExpressionValueError, typeSpecs } from '../expression_types/specs'; -import { getByAlias } from '../util'; +import { ALL_NAMESPACES, getByAlias } from '../util'; import { SavedObjectReference } from '../../../../core/types'; import { MigrateFunctionsObject, @@ -227,7 +227,7 @@ export class Executor = Record = Record { const realIndex = index + additionalFunctions; const { function: fnName, arguments: fnArgs } = funcAst; - const fn = getByAlias(functions, fnName); + const fn = getByAlias(functions, fnName, ALL_NAMESPACES); if (!fn) { return newAst; } diff --git a/src/plugins/expressions/common/util/get_by_alias.ts b/src/plugins/expressions/common/util/get_by_alias.ts index e265fe42512f6..051c9c7721d15 100644 --- a/src/plugins/expressions/common/util/get_by_alias.ts +++ b/src/plugins/expressions/common/util/get_by_alias.ts @@ -11,6 +11,9 @@ * the given object/array for a case-insensitive match, which could be either the * `name` itself, or something under the `aliases` property. */ + +export const ALL_NAMESPACES = '*'; + export function getByAlias( node: T[] | Record, nodeName: string, @@ -20,10 +23,13 @@ export function getByAlias { if (!name) return false; if (name.toLowerCase() === lowerCaseName) { - if (!namespace || namespace === nameSpace) return true; + if (!namespace || nameSpace === ALL_NAMESPACES || namespace === nameSpace) return true; } return (aliases || []).some((alias) => { - return alias.toLowerCase() === lowerCaseName && (!namespace || namespace === nameSpace); + return ( + alias.toLowerCase() === lowerCaseName && + (!namespace || nameSpace === ALL_NAMESPACES || namespace === nameSpace) + ); }); }); }