Skip to content

Support ternaries in marker labels#5857

Merged
fatadel merged 5 commits intofirefox-devtools:mainfrom
fatadel:support-ternaries-5818
Mar 3, 2026
Merged

Support ternaries in marker labels#5857
fatadel merged 5 commits intofirefox-devtools:mainfrom
fatadel:support-ternaries-5818

Conversation

@fatadel
Copy link
Contributor

@fatadel fatadel commented Feb 24, 2026

Closes #5818.

Add support for ternaries in marker labels, eg "{marker.data.canceled ? '❌' : ''} {marker.data.delay}". What to know:

  1. The conditional clause can refer to payload fields only, ie marker.data.*.
  2. The condition is checked for truthiness only, no other conditional operator can be used. Truthiness = classical JS truthiness, ie not null/undefined/empty.
  3. The true/false branches should be single-quoted string literals, "marker.data.* ? 'yes' : 'no'".

I am not sure how to test this except for the tests. Let me know if it is fine to land like this, or we need to thoroughly test things out.

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.36%. Comparing base (850e4ff) to head (78c16f3).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5857   +/-   ##
=======================================
  Coverage   85.36%   85.36%           
=======================================
  Files         320      320           
  Lines       31916    31932   +16     
  Branches     8780     8700   -80     
=======================================
+ Hits        27246    27260   +14     
- Misses       4239     4241    +2     
  Partials      431      431           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fatadel fatadel requested review from canova and mstange February 24, 2026 17:28
@fatadel fatadel marked this pull request as ready for review February 24, 2026 17:28
@carverdamien
Copy link

Did you consider using esprima?

@fatadel
Copy link
Contributor Author

fatadel commented Feb 25, 2026

Did you consider using esprima?

Nope. I think it is an overkill for us. Especially at this stage.

Copy link
Member

@canova canova left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

const ternaryMatch = part.match(TERNARY_RE);
if (ternaryMatch) {
const [, condRef, truthyStr, falsyStr] = ternaryMatch;
const condKeys = condRef.trim().split('.');
Copy link
Member

Choose a reason for hiding this comment

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

nit: Technically trim() is not needed here since the regexp [\w.]+ can't match leading and trailing whitespace. But not an issue really.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Let's keep the code clean, I've removed it.

// Handle: ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^

// Check for a ternary expression:
// Given: "{marker.data.canceled ? '❌' : ''} {marker.data.delay}"
Copy link
Member

Choose a reason for hiding this comment

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

It looks like we went with the single quotes, which I think makes sense considering the C++ strings. It might also make sense to update the marker documentation that we have in Firefox to mention this new feature: https://firefox-source-docs.mozilla.org/tools/profiler/markers-guide.html#:~:text=The%20arguments%20is%20a%20string%20that%20may%20refer%20to%20marker%20data%20within%20braces

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will do that 👍🏻 Would also be a good opportunity for me to learn that process 😀

@fatadel fatadel merged commit 167efec into firefox-devtools:main Mar 3, 2026
21 checks passed
@fatadel fatadel deleted the support-ternaries-5818 branch March 3, 2026 07:31
@canova canova mentioned this pull request Mar 3, 2026
canova added a commit that referenced this pull request Mar 3, 2026
Changes:

[fatadel] Fix crash when nativeSymbol index is out of bounds in assembly
view (#5850)
[depfu[bot]] Update all Yarn dependencies (2026-02-25) (#5859)
[Nazım Can Altınova] Fix the color of dark mode back arrow svg (#5863)
[fatadel] Force canvas redraw when system theme changes (#5861)
[Nazım Can Altınova] Fix unhandled promise rejection in
setupInitialUrlState (#5864)
[fatadel] Persist selected marker in URL and show sticky tooltip on load
(#5847)
[Markus Stange] Implement the "collapse resource" transform with the
help of the "collapse direct recursion" transform. (#5824)
[Markus Stange] Bump rollup from 2.79.2 to 2.80.0 (#5868)
[Markus Stange] Remove async attribute from module script tag. (#5870)
[Nazım Can Altınova] Update the docsify package that's used in the user
documentation (#5872)
[Markus Stange] Share stackTable, frameTable, funcTable, resourceTable
and nativeSymbols between threads (#5482)
[Nazım Can Altınova] Escape CSS URLs that are coming from profiles
(#5874)
[fatadel] Update home page message for the other browser case (#5866)
[fatadel] Add support for ternaries in marker labels (#5857)
[Markus Stange] Reduce allocations for getStackLineInfo +
getStackAddressInfo (#5761)

And special thanks to our localizers:

de: Ger
fy-NL: Fjoerfoks
it: Francesco Lodolo [:flod]
nl: Fjoerfoks
ru: berry
ru: Valery Ledovskoy
zh-TW: Pin-guang Chen
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.

Support ternaries in marker labels

3 participants