Skip to content

Commit

Permalink
Fix issue with className extraction when spread operator is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri BARBOT committed Jan 22, 2023
1 parent 37239cc commit 4d55083
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Nothing yet!

## [0.4.3] - 2023-01-22

### Fixed

- Fix issue with className extraction when spread operator is used

## [0.4.2] - 2023-01-22

### Changed
Expand All @@ -34,7 +40,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add missing props to extracted components when expressions are used

[unreleased]: https://github.com/dimitribarbot/tailwind-styled-components-extractor/compare/v0.4.2...HEAD
[unreleased]: https://github.com/dimitribarbot/tailwind-styled-components-extractor/compare/v0.4.3...HEAD
[0.4.3]: https://github.com/dimitribarbot/tailwind-styled-components-extractor/compare/v0.4.2...v0.4.3
[0.4.2]: https://github.com/dimitribarbot/tailwind-styled-components-extractor/compare/v0.4.1...v0.4.2
[0.4.1]: https://github.com/dimitribarbot/tailwind-styled-components-extractor/compare/v0.4.0...v0.4.1
[0.4.0]: https://github.com/dimitribarbot/tailwind-styled-components-extractor/compare/v0.3.2...v0.4.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tailwind-styled-components-extractor",
"displayName": "Tailwind Styled-Components Extractor",
"version": "0.4.2",
"version": "0.4.3",
"description": "Generate tailwind styled-components from JSX tags. A faster tailwind styled-component workflow.",
"license": "MIT",
"publisher": "dimitribarbot",
Expand Down
7 changes: 7 additions & 0 deletions src/lib/extractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe("collectUnboundComponents", () => {
<Efg className={c ? "justify-center" : "justify-start"} />
<Ghi className={\`flex flex-col \${c(a?.e) && "flex"} \${(a && b) || c ? "justify-center" : "justify-start"}\`} b={b} />
<Efg className="justify-center" />
<Efg className={{ ...(a || {}) }.b ?? ""} />
<Ghi />
<section />
</Def>
Expand Down Expand Up @@ -61,6 +62,12 @@ describe("collectUnboundComponents", () => {
className: "justify-center",
classNameOffsets: { start: 393, end: 419 }
},
{
name: "Efg",
propNames: ["a"],
className: '${({ a }) => { ...(a || {}) }.b ?? ""}',
classNameOffsets: { start: 438, end: 474 }
},
{
name: "Ghi",
propNames: [],
Expand Down
10 changes: 10 additions & 0 deletions src/lib/extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
isJSXOpeningElement,
isLogicalExpression,
isMemberExpression,
isObjectExpression,
isOptionalMemberExpression,
isSpreadElement,
isStringLiteral,
isTemplateLiteral,
JSXAttribute,
Expand Down Expand Up @@ -207,6 +209,14 @@ const fillExpressionIdentifiers = (
for (const argument of expression.arguments) {
if (isExpression(argument)) {
fillExpressionIdentifiers(argument, identifiers);
} else if (isSpreadElement(argument)) {
fillExpressionIdentifiers(argument.argument, identifiers);
}
}
} else if (isObjectExpression(expression)) {
for (const property of expression.properties) {
if (isSpreadElement(property)) {
fillExpressionIdentifiers(property.argument, identifiers);
}
}
} else if (isConditionalExpression(expression)) {
Expand Down

0 comments on commit 4d55083

Please sign in to comment.