Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jsdoc): remove attr name for Object props #4680

Merged
merged 1 commit into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/5-development/03-understanding-components-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Properties of type `Object`, properties with `multiple` set to`true` and propert
| `type` | Property type | N/A | The type of the property. For more information on types see the table below. |
| `defaultValue` | Any valid value for the type | undefined | Default value of the property. Cannot be set for type "Boolean". Booleans are always false by default in HTML.|
| `multiple` | Boolean | false | Indicates whether the property represents a single value or is an array of values of the given type. |
| `noAttribute` | Boolean | false | No attribute equivalent will be created for that property. Always false for properties of type Object. |
| `noAttribute` | Boolean | false | No attribute equivalent will be created for that property. Always true for properties of type Object. |

The `type` setting is required.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ module.exports = {
{{/if}}
<br>
{{#if (toKebabCase this.name)}}
<code>{{toKebabCase this.name}}</code>
{{#unless this.noattribute}}
<code>{{toKebabCase this.name}}</code>
{{/unless}}
{{/if}}
</div>
<div class="cell api-table-content-cell">{{this.type}}</div>
Expand Down
9 changes: 9 additions & 0 deletions packages/tools/lib/jsdoc/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
*
* native
*
* noattribute
*
* allowPreventDefault
*
* It furthermore listens to the following JSDoc3 events to implement additional functionality
Expand Down Expand Up @@ -2099,6 +2101,13 @@ exports.defineTags = function(dictionary) {
doclet.native = true;
}
});

dictionary.defineTag('noattribute', {
mustHaveValue: false,
onTagged: function(doclet, tag) {
doclet.noattribute = true;
}
});
};

exports.handlers = {
Expand Down
15 changes: 13 additions & 2 deletions packages/tools/lib/jsdoc/template/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2804,6 +2804,10 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
attrib("export", undefined, '', true);
}

if (member.noattribute) {
attrib("noattribute", true);
}

if (member.readonly) {
attrib("readonly", member.readonly, null);
}
Expand All @@ -2815,7 +2819,14 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
if ( member.since ) {
attrib("since", extractVersion(member.since));
}
attrib("type", listTypes(member.type));

var type = listTypes(member.type);
attrib("type", type);

if ((type === "object" || type === "Object") && visibility(member) === "public") {
attrib("noattribute", true);
}

tag("description", normalizeWS(member.description), true);
if (member.defaultvalue) {
attrib("defaultValue", member.defaultvalue);
Expand Down Expand Up @@ -3854,7 +3865,7 @@ function createAPIJS(symbols, filename) {

var output = [];

var rkeywords = /^(?:abstract|as|boolean|break|byte|case|catch|char|class|continue|const|debugger|default|delete|do|double|else|enum|export|extends|false|final|finally|float|for|function|goto|if|implements|import|in|instanceof|int|interface|is|long|namespace|native|new|null|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|use|var|void|volatile|while|with)$/;
var rkeywords = /^(?:abstract|as|boolean|break|byte|case|catch|char|class|continue|const|debugger|default|delete|do|double|else|enum|export|extends|false|final|finally|float|for|function|goto|if|implements|import|in|instanceof|int|interface|is|long|namespace|native|new|null|noattribute|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|use|var|void|volatile|while|with)$/;

function isNoKeyword($) { return !rkeywords.test($.name); }

Expand Down