Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Event binding in XML Templates #559

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

d3xter666
Copy link
Contributor

@d3xter666 d3xter666 commented Feb 20, 2025

In XML templating it's possible to provide bindings fоr every attribute no matter if it's property, aggregation, event, etc.
Therefore, the linter needs to analyze the bindings within events as "normal" bindings and not just like events.

@d3xter666 d3xter666 requested review from codeworrior and a team February 20, 2025 14:12
@matz3
Copy link
Member

matz3 commented Feb 21, 2025

Can you also add a fixture for the class attribute? That one is also used in XML templating e.g. class="{=${device>/system/phone} ? sapMObjectStatusSmall : sapMObjectStatusLarge}"

@d3xter666 d3xter666 requested a review from matz3 February 24, 2025 07:07
// We need to parse and lint these as well
const bindingInfo =
this.#bindingLinter.lintPropertyBinding(prop.value, this.#requireDeclarations, position);
if (bindingInfo && prop.value.startsWith("{") && prop.value.endsWith("}")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A composite binding is a valid binding but doesn't necessarily start or end with curly brackets, e.g. .event{field>Value/$Path}Handler.

AFAICS the bindingInfo will not be an object if there is no binding, so it is already sufficient to check for that.

Also see my changes in #533 which set the bUnescape argument to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, check the new solution. It verifies if the potential function name is a valid JS identifier.
The pattern is a bit enhanced to support the all the variants of using functions in XML.
Source:

const validFunctionName = /^[$_\p{ID_Start}][$_\p{ID_Continue}]*$/u;

@d3xter666 d3xter666 force-pushed the fix-enhance-binding-parser branch from 4cc917e to a1e5c13 Compare February 24, 2025 10:50
@d3xter666 d3xter666 force-pushed the fix-enhance-binding-parser branch from a1e5c13 to 9b6ab91 Compare February 24, 2025 10:53
@matz3
Copy link
Member

matz3 commented Feb 24, 2025

Please add new cases which previously caused false-positive findings to test/fixtures/linter/rules/NoGlobals/GlobalEventHandlers.view.xml.

@d3xter666 d3xter666 force-pushed the fix-enhance-binding-parser branch from 9b6ab91 to 241cb94 Compare February 24, 2025 11:10
@d3xter666 d3xter666 requested a review from matz3 February 24, 2025 12:08
@matz3
Copy link
Member

matz3 commented Feb 24, 2025

There seem to be problems with parsing certain bindings which are working fine at runtime, but can't be parsed in here:
<Button press=".onPressButton($event, { code: ${ui>/sCode} })" />

This causes a parsing error Unexpected '$'.

@matz3 matz3 force-pushed the fix-enhance-binding-parser branch from 1578fc9 to ccdc865 Compare February 25, 2025 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants