Skip to content

Commit c79279b

Browse files
pfaffeDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
[styles] Properly render a color fallback if the color failed to parse
Bug: 396080529 Change-Id: I9baf7bf9d2af72f017f5d8680567ae884a41ed80 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6441443 Commit-Queue: Ergün Erdoğmuş <ergunsh@chromium.org> Auto-Submit: Philip Pfaffe <pfaffe@chromium.org> Reviewed-by: Ergün Erdoğmuş <ergunsh@chromium.org>
1 parent 9cdc258 commit c79279b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

front_end/panels/elements/StylePropertyTreeElement.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,13 @@ describeWithMockConnection('StylePropertyTreeElement', () => {
860860
assert.isOk(colorSwatch.getColor());
861861
assert.strictEqual(colorSwatch?.getColor()?.asString(Common.Color.Format.HSL), 'hsl(240deg 50% 50%)');
862862
});
863+
864+
it('renders fallbacks correctly when the color fails to parse', () => {
865+
const stylePropertyTreeElement = getTreeElement('color', 'lch(50 min(1, 8) 8deg)');
866+
stylePropertyTreeElement.updateTitle();
867+
const angle = stylePropertyTreeElement.valueElement?.querySelector('devtools-css-angle');
868+
assert.exists(angle);
869+
});
863870
});
864871

865872
describe('BezierRenderer', () => {

front_end/panels/elements/StylePropertyTreeElement.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ export class ColorRenderer extends rendererBase(SDK.CSSPropertyParserMatchers.Co
402402
// Now try render a color swatch if the result is parsable.
403403
const color = Common.Color.parse(colorText);
404404
if (!color) {
405+
if (match.node.name === 'CallExpression') {
406+
return Renderer.render(ASTUtils.children(match.node), context).nodes;
407+
}
405408
return [document.createTextNode(colorText)];
406409
}
407410
const swatch = this.renderColorSwatch(color, valueChild);

0 commit comments

Comments
 (0)