From 7995ae5f60673e513e49b0015e16d437ff270f6e Mon Sep 17 00:00:00 2001 From: break-stuff Date: Wed, 25 Oct 2023 17:36:39 -0400 Subject: [PATCH 1/2] add optional chaining to prevent errors --- demo/lit-app/custom-elements.json | 28 +++++++++++------------ packages/expanded-types/src/cem-plugin.ts | 16 ++++++------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/demo/lit-app/custom-elements.json b/demo/lit-app/custom-elements.json index e626c12..e8338c7 100644 --- a/demo/lit-app/custom-elements.json +++ b/demo/lit-app/custom-elements.json @@ -4,13 +4,13 @@ "modules": [ { "kind": "javascript-module", - "path": "/Users/burtonsmith/Documents/Projects/cem-tools/demo/lit-app/src/radio-group/alt-types.ts", + "path": "/home/parallels/Documents/Projects/cem-tools/demo/lit-app/src/radio-group/alt-types.ts", "declarations": [], "exports": [] }, { "kind": "javascript-module", - "path": "/Users/burtonsmith/Documents/Projects/cem-tools/demo/lit-app/src/radio-group/RadioGroup.ts", + "path": "/home/parallels/Documents/Projects/cem-tools/demo/lit-app/src/radio-group/RadioGroup.ts", "declarations": [ { "kind": "variable", @@ -299,7 +299,7 @@ "name": "ComplexObject", "declaration": { "name": "ComplexObject", - "module": "/Users/burtonsmith/Documents/Projects/cem-tools/demo/lit-app/src/radio-group/RadioGroup.ts" + "module": "/home/parallels/Documents/Projects/cem-tools/demo/lit-app/src/radio-group/RadioGroup.ts" } }, { @@ -307,14 +307,14 @@ "name": "RadioGroup", "declaration": { "name": "RadioGroup", - "module": "/Users/burtonsmith/Documents/Projects/cem-tools/demo/lit-app/src/radio-group/RadioGroup.ts" + "module": "/home/parallels/Documents/Projects/cem-tools/demo/lit-app/src/radio-group/RadioGroup.ts" } } ] }, { "kind": "javascript-module", - "path": "/Users/burtonsmith/Documents/Projects/cem-tools/demo/lit-app/src/radio-button/RadioButton.ts", + "path": "/home/parallels/Documents/Projects/cem-tools/demo/lit-app/src/radio-button/RadioButton.ts", "declarations": [ { "kind": "class", @@ -404,7 +404,7 @@ "name": "RadioButton", "declaration": { "name": "RadioButton", - "module": "/Users/burtonsmith/Documents/Projects/cem-tools/demo/lit-app/src/radio-button/RadioButton.ts" + "module": "/home/parallels/Documents/Projects/cem-tools/demo/lit-app/src/radio-button/RadioButton.ts" } } ] @@ -450,30 +450,30 @@ }, { "kind": "javascript-module", - "path": "src/radio-group/radio-group.ts", + "path": "src/radio-button/radio-button.ts", "declarations": [], "exports": [ { "kind": "custom-element-definition", - "name": "radio-group", + "name": "radio-button", "declaration": { - "name": "RadioGroup", - "module": "/src/radio-group/RadioGroup.js" + "name": "RadioButton", + "module": "/src/radio-button/RadioButton.js" } } ] }, { "kind": "javascript-module", - "path": "src/radio-button/radio-button.ts", + "path": "src/radio-group/radio-group.ts", "declarations": [], "exports": [ { "kind": "custom-element-definition", - "name": "radio-button", + "name": "radio-group", "declaration": { - "name": "RadioButton", - "module": "/src/radio-button/RadioButton.js" + "name": "RadioGroup", + "module": "/src/radio-group/RadioGroup.js" } } ] diff --git a/packages/expanded-types/src/cem-plugin.ts b/packages/expanded-types/src/cem-plugin.ts index f018335..4a929a5 100644 --- a/packages/expanded-types/src/cem-plugin.ts +++ b/packages/expanded-types/src/cem-plugin.ts @@ -78,17 +78,17 @@ function getExpandedType(fileName: string, typeName: string): string { function getUnionTypes(fileName: string, typeName: string) { const parts = typeName - .split("|") + ?.split("|") .map((part) => part.trim()) .filter((part) => part.length > 0); - return parts.map((part) => getExpandedType(fileName, part)).join(" | "); + return parts?.map((part) => getExpandedType(fileName, part)).join(" | ") || ''; } function getObjectTypes(fileName: string, typeName: string) { const parts = [ ...new Set( typeName - .split(/[:{}]/) + ?.split(/[:{}]/) .map((part) => part.trim()) .filter((part) => part.length > 0) ), @@ -133,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; } @@ -141,11 +141,11 @@ function setEnumTypes(node: any) { function setBasicUnionTypes(node: any) { const name = node.name?.escapedText; const unionTypes = node?.type?.types - .map((type: any) => { + ?.map((type: any) => { const value = type?.literal?.text; return typeof value === "string" ? `'${value}'` : value; }) - .join(" | "); + .join(" | ") || ''; aliasTypes[currentFilename][name] = unionTypes; } @@ -155,10 +155,10 @@ function setComplexUnionTypes(node: any) { typeChecker.getSymbolAtLocation(node.name) ); const unionTypes = resolvedTypes.types - .map((type: any) => + ?.map((type: any) => typeof type.value === "string" ? `'${type.value}'` : type.value ) - .join(" | "); + .join(" | ") || ''; aliasTypes[currentFilename][name] = unionTypes; } From 57719aec490ea024795c6d7f82c48d35994e63af Mon Sep 17 00:00:00 2001 From: break-stuff Date: Wed, 25 Oct 2023 17:38:16 -0400 Subject: [PATCH 2/2] prep for release --- packages/expanded-types/CHANGELOG.md | 4 ++++ packages/expanded-types/package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/expanded-types/CHANGELOG.md b/packages/expanded-types/CHANGELOG.md index 0ba85d0..8d9470d 100644 --- a/packages/expanded-types/CHANGELOG.md +++ b/packages/expanded-types/CHANGELOG.md @@ -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 diff --git a/packages/expanded-types/package.json b/packages/expanded-types/package.json index f267b60..8745ef2 100644 --- a/packages/expanded-types/package.json +++ b/packages/expanded-types/package.json @@ -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",