Support ternaries in marker labels#5857
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
Did you consider using esprima? |
Nope. I think it is an overkill for us. Especially at this stage. |
src/profile-logic/marker-schema.ts
Outdated
| const ternaryMatch = part.match(TERNARY_RE); | ||
| if (ternaryMatch) { | ||
| const [, condRef, truthyStr, falsyStr] = ternaryMatch; | ||
| const condKeys = condRef.trim().split('.'); |
There was a problem hiding this comment.
nit: Technically trim() is not needed here since the regexp [\w.]+ can't match leading and trailing whitespace. But not an issue really.
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I will do that 👍🏻 Would also be a good opportunity for me to learn that process 😀
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
Closes #5818.
Add support for ternaries in marker labels, eg
"{marker.data.canceled ? '❌' : ''} {marker.data.delay}". What to know:marker.data.*."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.