diff --git a/packages/binding/src/definition/definition.ts b/packages/binding/src/definition/definition.ts index e241cf83..77ff80c6 100644 --- a/packages/binding/src/definition/definition.ts +++ b/packages/binding/src/definition/definition.ts @@ -1,6 +1,10 @@ import { AGGREGATION_BINDING_INFO, PROPERTY_BINDING_INFO } from "../api"; import { BindContext, BindingInfoElement, PropertyType } from "../types"; -import { buildType, getAltTypesPrime, getDocumentation } from "../utils"; +import { + buildType, + findPrimitiveTypeInAggregation, + getDocumentation, +} from "../utils"; import { getFallBackElements } from "./fall-back-definition"; import type { UI5Aggregation, @@ -97,7 +101,7 @@ export const getBindingElements = ( properties: propBinding.properties, }) ); - const altTypes = getAltTypesPrime(aggregation); + const altTypes = findPrimitiveTypeInAggregation(aggregation); if (altTypes) { // if `altTypes`, add `PROPERTY_BINDING_INFO` properties too elements.push( diff --git a/packages/binding/src/services/completion/providers/binding.ts b/packages/binding/src/services/completion/providers/binding.ts index 713fe2b7..49c21586 100644 --- a/packages/binding/src/services/completion/providers/binding.ts +++ b/packages/binding/src/services/completion/providers/binding.ts @@ -17,7 +17,7 @@ import { import { BindContext } from "../../../types"; import { createInitialSnippet } from "./create-initial-snippet"; import { - getAltTypesPrime, + findPrimitiveTypeInAggregation, getCursorContext, getLogger, isMacrosMetaContextPath, @@ -140,7 +140,7 @@ export function bindingSuggestions({ ); } - const altTypes = getAltTypesPrime(ui5Aggregation); + const altTypes = findPrimitiveTypeInAggregation(ui5Aggregation); if (altTypes) { // for `altTypes`, `PROPERTY_BINDING_INFO` properties are added (duplicate allowed) return completionItems; diff --git a/packages/binding/src/services/diagnostics/validators/check-required.ts b/packages/binding/src/services/diagnostics/validators/check-required.ts index 95d143bf..38582f58 100644 --- a/packages/binding/src/services/diagnostics/validators/check-required.ts +++ b/packages/binding/src/services/diagnostics/validators/check-required.ts @@ -1,4 +1,4 @@ -import { findRange, getAltTypesPrime } from "../../../utils"; +import { findRange, findPrimitiveTypeInAggregation } from "../../../utils"; import { BindingIssue, BINDING_ISSUE_TYPE, @@ -21,7 +21,7 @@ export const checkRequiredElement = ( /* istanbul ignore next */ (i) => i.key?.text === reqEl.name ); - const altTypes = getAltTypesPrime(aggregation); + const altTypes = findPrimitiveTypeInAggregation(aggregation); if (!usedRequiredEl && altTypes) { // some property e.g `tooltip` can be used with both `aggregation binding info` or `property binding info`. Therefore `altTypes` is defined in design time. // if `altTypes` is present, check if any element is used. This is a very broad check to avoid false diagnostic. diff --git a/packages/binding/src/utils/index.ts b/packages/binding/src/utils/index.ts index 4dea8536..b2b30a6d 100644 --- a/packages/binding/src/utils/index.ts +++ b/packages/binding/src/utils/index.ts @@ -20,7 +20,14 @@ export { getLogger } from "./logger"; export { getDocumentation } from "./documentation"; -export const getAltTypesPrime = ( +/** + * Finds and returns the first alternative type in the aggregation's altTypes array + * that has a kind property equal to "PrimitiveType". + * + * @param {UI5Aggregation} [aggregation] - The aggregation object which may contain alternative types. + * @returns {UI5Type | undefined} - The first alternative type with kind "PrimitiveType", or undefined if not found. + */ +export const findPrimitiveTypeInAggregation = ( aggregation?: UI5Aggregation ): UI5Type | undefined => aggregation?.altTypes?.find((i) => i.kind === "PrimitiveType");