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

Expanded types fix undefined error #26

Merged
merged 3 commits into from
Oct 29, 2023
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
16 changes: 0 additions & 16 deletions demo/lit-app/custom-elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,6 @@
"path": "src/radio-button/radio-button.ts",
"declarations": [],
"exports": [
{
"kind": "js",
"name": "RadioButton",
"declaration": {
"name": "RadioButton",
"module": "src/radio-button/radio-button.ts"
}
},
{
"kind": "custom-element-definition",
"name": "radio-button",
Expand All @@ -491,14 +483,6 @@
"path": "src/radio-group/radio-group.ts",
"declarations": [],
"exports": [
{
"kind": "js",
"name": "RadioGroup",
"declaration": {
"name": "RadioGroup",
"module": "src/radio-group/radio-group.ts"
}
},
{
"kind": "custom-element-definition",
"name": "radio-group",
Expand Down
4 changes: 4 additions & 0 deletions packages/expanded-types/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.1

- Add optional chaining to prevent errors when types are `undefined`.

## 1.1.0

- Update TypeScript configuration to support jsDoc types
Expand Down
2 changes: 1 addition & 1 deletion packages/expanded-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cem-plugin-expanded-types",
"version": "1.1.0",
"version": "1.1.1",
"description": "A CEM Analyzer plugin to add expanded TypeScript types to the Custom Elements Manifest",
"main": "index.js",
"module": "index.js",
Expand Down
13 changes: 6 additions & 7 deletions packages/expanded-types/src/cem-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ function getExpandedType(fileName: string, typeName: string): string {
}

function getUnionTypes(fileName: string, typeName: string) {
return typeName
const parts = typeName
?.split("|")
.map((part) => part.trim())
.filter((part) => part.length > 0)
.map((part) => getExpandedType(fileName, part))
.join(" | ");
.filter((part) => part.length > 0);
return parts?.map((part) => getExpandedType(fileName, part)).join(" | ") || '';
}

function getObjectTypes(fileName: string, typeName: string) {
Expand Down Expand Up @@ -134,7 +133,7 @@ function setEnumTypes(node: any) {
const name = node.name.escapedText;
const shortText = node.members
?.map((mem: any) => mem.initializer?.text)
.join(" | ");
.join(" | ") || '';

aliasTypes[currentFilename][name] = shortText;
}
Expand All @@ -146,7 +145,7 @@ function setBasicUnionTypes(node: any) {
const value = type?.literal?.text;
return typeof value === "string" ? `'${value}'` : value;
})
.join(" | ");
.join(" | ") || '';
aliasTypes[currentFilename][name] = unionTypes;
}

Expand All @@ -159,7 +158,7 @@ function setComplexUnionTypes(node: any) {
?.map((type: any) =>
typeof type.value === "string" ? `'${type.value}'` : type.value
)
.join(" | ");
.join(" | ") || '';

aliasTypes[currentFilename][name] = unionTypes;
}
Expand Down