Skip to content

Commit 8bed57e

Browse files
committed
feat(prop): extract default value of props
1 parent c9475aa commit 8bed57e

8 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/compiler/docs/docs-util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export function getEventDetailType(eventType: d.AttributeTypeInfo) {
161161
if (eventType && eventType.text && typeof eventType.text === 'string' && eventType.text !== 'void') {
162162
return eventType.text.trim();
163163
}
164-
return '';
164+
return 'void';
165165
}
166166

167167

src/compiler/docs/markdown-events.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ export class MarkdownEvents {
2727

2828
const table = new MarkdownTable();
2929

30-
table.addHeader(['Event', 'Detail', 'Description']);
30+
table.addHeader([
31+
'Event',
32+
'Description',
33+
'Detail'
34+
]);
3135

3236
rows.forEach(row => {
3337
table.addRow([
3438
'`' + row.eventName + '`',
39+
row.description,
3540
row.detail,
36-
row.description
3741
]);
3842
});
3943

src/compiler/docs/markdown-props.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ export class MarkdownProps {
3232
'Property',
3333
'Attribute',
3434
'Description',
35-
'Type'
35+
'Type',
36+
'Default'
3637
]);
3738

3839
rows.forEach(row => {
3940
table.addRow([
4041
row.propName,
4142
row.attrName,
4243
row.description,
43-
row.type
44+
row.type,
45+
row.default
4446
]);
4547
});
4648

@@ -81,6 +83,9 @@ export class PropRow {
8183
return `\`${this.memberMeta.jsdoc.type}\``;
8284
}
8385

86+
get default() {
87+
return `\`${this.memberMeta.jsdoc.default}\``;
88+
}
8489
}
8590

8691
function filterRow(row: PropRow) {

src/compiler/transpile/datacollection/prop-decorator.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export function getPropDecoratorMeta(diagnostics: d.Diagnostic[], checker: ts.Ty
4242
memberData.reflectToAttrib = getReflectToAttr(propOptions);
4343
memberData.propType = propTypeFromTSType(type);
4444
memberData.jsdoc = serializeSymbol(checker, symbol);
45+
46+
// extract default value
47+
const initializer = prop.initializer;
48+
if (initializer) {
49+
memberData.jsdoc.default = initializer.getText();
50+
}
4551
}
4652

4753
allMembers[memberName] = memberData;

src/compiler/transpile/datacollection/test/component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ describe('component', () => {
214214
'name': 'enableBackdropDismiss',
215215
'tags': [],
216216
'type': 'boolean',
217+
'default': 'true'
217218
},
218219
'memberType': MEMBER_TYPE.Prop,
219220
'propType': PROP_TYPE.Boolean,

src/compiler/transpile/datacollection/test/fixtures/prop-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ActionSheet {
4343

4444
@Prop() enabled?: boolean | string;
4545

46-
@Prop() color?: Color;
46+
@Prop() color?: Color = "primary";
4747

4848
@Prop() config?: ConfigProps;
4949

src/compiler/transpile/datacollection/test/prop-decorator.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ describe('props decorator', () => {
7070
name: 'withOptions',
7171
tags: [],
7272
type: 'number',
73+
default: '88'
7374
},
7475
memberType: MEMBER_TYPE.Prop,
7576
propType: PROP_TYPE.Number,
@@ -164,6 +165,7 @@ describe('props decorator', () => {
164165
name: 'color',
165166
tags: [],
166167
type: `"primary" | "secondary"`,
168+
default: '"primary"'
167169
},
168170
memberType: MEMBER_TYPE.Prop,
169171
propType: PROP_TYPE.String,

src/declarations/component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export interface JsDoc {
167167
documentation: string;
168168
type: string;
169169
tags: JSDocTagInfo[];
170+
default?: string;
170171
parameters?: JsDoc[];
171172
returns?: {
172173
type: string;

0 commit comments

Comments
 (0)