Skip to content

Commit

Permalink
refactor: function rename and jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
marufrasully committed Jan 24, 2025
1 parent 0879770 commit 17c9fd1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/binding/src/definition/definition.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions packages/binding/src/services/completion/providers/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { BindContext } from "../../../types";
import { createInitialSnippet } from "./create-initial-snippet";
import {
getAltTypesPrime,
findPrimitiveTypeInAggregation,
getCursorContext,
getLogger,
isMacrosMetaContextPath,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findRange, getAltTypesPrime } from "../../../utils";
import { findRange, findPrimitiveTypeInAggregation } from "../../../utils";
import {
BindingIssue,
BINDING_ISSUE_TYPE,
Expand All @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion packages/binding/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 17c9fd1

Please sign in to comment.