Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c83cfc5

Browse files
committed
feat(analyzer): css prop fallbacks
1 parent 4431cbb commit c83cfc5

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

.changeset/modern-numbers-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lit-labs/analyzer': minor
3+
---
4+
5+
Add CSS Custom Property fallback (default) values to manifest

packages/labs/analyzer/src/lib/model.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ export interface NamedDescribed extends Described {
536536
name: string;
537537
}
538538

539+
export interface NamedDescribedDefault extends NamedDescribed {
540+
default?: string;
541+
}
542+
539543
export interface TypedNamedDescribed extends NamedDescribed {
540544
type?: string;
541545
}
@@ -569,7 +573,7 @@ export class CustomElementDeclaration extends ClassDeclaration {
569573
readonly tagname: string | undefined;
570574
readonly events: Map<string, Event>;
571575
readonly slots: Map<string, NamedDescribed>;
572-
readonly cssProperties: Map<string, NamedDescribed>;
576+
readonly cssProperties: Map<string, NamedDescribedDefault>;
573577
readonly cssParts: Map<string, NamedDescribed>;
574578

575579
constructor(init: CustomElementDeclarationInit) {

packages/labs/analyzer/src/test/lit-element/jsdoc_test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ for (const lang of languages) {
104104
test('cssProperties - Correct number found', ({getModule}) => {
105105
const element = getModule('element-a').getDeclaration('ElementA');
106106
assert.ok(element.isLitElementDeclaration());
107-
assert.equal(element.cssProperties.size, 6);
107+
assert.equal(element.cssProperties.size, 9);
108108
});
109109

110110
test('cssProperties - no-description', ({getModule}) => {
@@ -137,6 +137,37 @@ for (const lang of languages) {
137137
assert.equal(prop.description, 'Description for --with-description-dash');
138138
});
139139

140+
/**
141+
* @cssProperty [--default-no-description=#324fff]
142+
* @cssProperty [--default-with-description=#324fff] Description for --default-with-description
143+
* with wraparound
144+
* @cssProperty [--default-with-description-dash=#324fff] - Description for --default-with-description-dash
145+
*/
146+
147+
test('cssProperties - default-no-description', ({getModule}) => {
148+
const element = getModule('element-a').getDeclaration('ElementA');
149+
assert.ok(element.isLitElementDeclaration());
150+
const prop = element.cssProperties.get('--default-no-description');
151+
assert.ok(prop);
152+
assert.equal(prop.default, '#324fff');
153+
});
154+
155+
test('cssProperties - default-with-description', ({getModule}) => {
156+
const element = getModule('element-a').getDeclaration('ElementA');
157+
assert.ok(element.isLitElementDeclaration());
158+
const prop = element.cssProperties.get('--with-description');
159+
assert.ok(prop);
160+
assert.equal(prop.default, '#324fff');
161+
});
162+
163+
test('cssProperties - default-with-description-dash', ({getModule}) => {
164+
const element = getModule('element-a').getDeclaration('ElementA');
165+
assert.ok(element.isLitElementDeclaration());
166+
const prop = element.cssProperties.get('--with-description-dash');
167+
assert.ok(prop);
168+
assert.equal(prop.default, '#324fff');
169+
});
170+
140171
test('cssProperties - short-no-description', ({getModule}) => {
141172
const element = getModule('element-a').getDeclaration('ElementA');
142173
assert.ok(element.isLitElementDeclaration());

packages/labs/analyzer/test-files/ts/vanilla-jsdoc/src/element-a.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
* @cssProperty --with-description Description for --with-description
2121
* with wraparound
2222
* @cssProperty --with-description-dash - Description for --with-description-dash
23+
* @cssProperty [--default-no-description=#324fff]
24+
* @cssProperty [--default-with-description=#324fff] Description for --default-with-description
25+
* with wraparound
26+
* @cssProperty [--default-with-description-dash=#324fff] - Description for --default-with-description-dash
2327
* @cssProp --short-no-description
2428
* @cssProp --short-with-description Description for --short-with-description
2529
* with wraparound

0 commit comments

Comments
 (0)