Skip to content

Commit

Permalink
fix: better @Attribute jsdoc support
Browse files Browse the repository at this point in the history
  • Loading branch information
thepassle committed May 7, 2024
1 parent 7029066 commit 5e7a9f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/analyzer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Release 0.9.9
- Support `@attribute` jsdoc better

## Release 0.9.8
- Skip `...super.properties` in lit's `static properties`

Expand Down
20 changes: 17 additions & 3 deletions packages/analyzer/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203107,7 +203107,7 @@ var isDispatchEvent = (node) => node.expression?.name?.getText() === "dispatchEv
var isReturnStatement = (statement) => statement?.kind === import_typescript2.default.SyntaxKind.ReturnStatement;
var isCustomElementsDefineCall = (node) => (node?.expression?.getText() === "customElements" || node?.expression?.getText() === "window.customElements" || node?.expression?.getText() === "globalThis.customElements") && node?.name?.getText() === "define" && node?.parent?.kind === import_typescript2.default.SyntaxKind.CallExpression;
function hasAttrAnnotation(member) {
return member?.jsDoc?.some((jsDoc) => jsDoc?.tags?.some((tag) => safe(() => tag?.tagName?.getText()) === "attr"));
return member?.jsDoc?.some((jsDoc) => jsDoc?.tags?.some((tag) => safe(() => ["attribute", "attr"].includes(tag?.tagName?.getText()))));
}
function hasInitializer(node) {
return node?.declarationList?.declarations?.some((declaration) => declaration?.initializer);
Expand Down Expand Up @@ -203852,8 +203852,8 @@ function handleHeritage(classTemplate, moduleDoc, context, node) {
}
function handleAttrJsDoc(node, doc) {
node?.jsDoc?.forEach((jsDoc) => {
const docs = parse(jsDoc?.getFullText())?.find((doc2) => doc2?.tags?.some(({ tag }) => tag === "attr"));
const attrTag = docs?.tags?.find(({ tag }) => tag === "attr");
const docs = parse(jsDoc?.getFullText())?.find((doc2) => doc2?.tags?.some(({ tag }) => ["attribute", "attr"].includes(tag)));
const attrTag = docs?.tags?.find(({ tag }) => ["attribute", "attr"].includes(tag));
if (attrTag?.name) {
doc.name = attrTag.name;
}
Expand Down Expand Up @@ -204195,6 +204195,20 @@ function mapClassMember(source, classTemplate, context, node, statement, express
...resolveModuleOrPackageSpecifier({ path: source.getSourceFile().fileName }, context, expression?.right?.getText())
};
}
if (hasAttrAnnotation(statement)) {
const field = existingMember;
let attribute = createAttributeFromField(field);
attribute = handleAttrJsDoc(statement, attribute);
field.attribute = attribute.name;
let attrAlreadyExists = classTemplate.attributes.find((attr) => attr.name === attribute.name);
if (attrAlreadyExists) {
classTemplate.attributes = classTemplate.attributes.map((attr) => {
return attr.name === attribute.name ? { ...attrAlreadyExists, ...attribute } : attr;
});
} else {
classTemplate.attributes.push(attribute);
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@custom-elements-manifest/analyzer",
"version": "0.9.8",
"version": "0.9.9",
"description": "",
"license": "MIT",
"type": "module",
Expand Down

0 comments on commit 5e7a9f4

Please sign in to comment.