Skip to content

Commit

Permalink
fix: jsx attributes with a 'null' value
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-richter committed Aug 7, 2024
1 parent 920c15e commit 2495bca
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
39 changes: 39 additions & 0 deletions src/features/report/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,45 @@ describe("scanAST", () => {
`);
});

it('should handle props with "null" syntax', () => {
const code = `
export const Code = ({ title, files, deps }: CodeProps) => {
return (
<SandpackCodeEditor wrapContent />
)
}
`
const ast = scanAST({ code, filePath: "src/test/Component.tsx" });

expect(ast).toMatchInlineSnapshot(`
{
"components": [
{
"location": {
"end": {
"column": 23,
"line": 4,
},
"start": {
"column": 5,
"line": 4,
},
},
"name": "SandpackCodeEditor",
"props": [
{
"name": "wrapContent",
"value": true,
},
],
"propsSpread": false,
},
],
"filePath": "src/test/Component.tsx",
}
`)
})

it("should parse literal values from JSXExpressionContainers", () => {
const code = `
import { Button } from 'my-library';
Expand Down
4 changes: 3 additions & 1 deletion src/features/report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ const getComponentNameFromAST = (
return nameObj.name;
};

function getPropValue(node: TSESTree.JSXExpression | TSESTree.Literal) {
function getPropValue(node: TSESTree.JSXExpression | TSESTree.Literal | null) {
if (!node) return true;

if (node.type === "Literal") {
return node.value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/features/report/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const scan = (crawlFrom: string) => {
.glob(...globs)
.withRelativePaths()
.exclude((dirName) =>
dirName.startsWith("node_modules") || dirName.startsWith('.')
dirName.startsWith("node_modules") || dirName.startsWith('.') || dirName.startsWith('dist')
)
.crawl(crawlFrom)
.sync();
Expand Down

0 comments on commit 2495bca

Please sign in to comment.