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

fix prefix #2913

Merged
merged 4 commits into from
Feb 2, 2024
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
5 changes: 5 additions & 0 deletions .changeset/chatty-rocks-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-ui": patch
---

fix tw prefix
4 changes: 2 additions & 2 deletions packages/cli/src/utils/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
'./app/**/*.{ts,tsx}',
'./src/**/*.{ts,tsx}',
],
prefix: "<%- prefix %>",
prefix: '<%- prefix %>',
theme: {
container: {
center: true,
Expand Down Expand Up @@ -55,7 +55,7 @@ module.exports = {
'./app/**/*.{ts,tsx}',
'./src/**/*.{ts,tsx}',
],
prefix: "<%- prefix %>",
prefix: '<%- prefix %>',
theme: {
container: {
center: true,
Expand Down
50 changes: 25 additions & 25 deletions packages/cli/src/utils/transformers/transform-tw-prefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export const transformTwPrefixes: Transformer = async ({
const defaultClassNames = node.getArguments()[0];
if (defaultClassNames) {
defaultClassNames.replaceWithText(
`"${applyPrefix(
defaultClassNames.getText()?.replace(/"/g, ''),
`'${applyPrefix(
defaultClassNames.getText()?.replace(/'/g, '').replace(/"/g, ''),
config.tailwind.prefix
)}"`
)}'`
);
}
}
Expand All @@ -45,10 +45,10 @@ export const transformTwPrefixes: Transformer = async ({
);
if (classNames) {
classNames?.replaceWithText(
`"${applyPrefix(
classNames.getText()?.replace(/"/g, ''),
`'${applyPrefix(
classNames.getText()?.replace(/'/g, '').replace(/"/g, ''),
config.tailwind.prefix
)}"`
)}'`
);
}
});
Expand All @@ -59,15 +59,15 @@ export const transformTwPrefixes: Transformer = async ({
// Find all jsx attributes with the name className.
sourceFile.getDescendantsOfKind(SyntaxKind.JsxAttribute).forEach((node) => {
if (node.getName() === 'className') {
// className="..."
// className='...'
if (node.getInitializer()?.isKind(SyntaxKind.StringLiteral)) {
const value = node.getInitializer();
if (value) {
value.replaceWithText(
`"${applyPrefix(
value.getText()?.replace(/"/g, ''),
`'${applyPrefix(
value.getText()?.replace(/'/g, '').replace(/"/g, ''),
config.tailwind.prefix
)}"`
)}'`
);
}
}
Expand All @@ -90,20 +90,20 @@ export const transformTwPrefixes: Transformer = async ({
.getChildrenOfKind(SyntaxKind.StringLiteral)
.forEach((node) => {
node.replaceWithText(
`"${applyPrefix(
node.getText()?.replace(/"/g, ''),
`'${applyPrefix(
node.getText()?.replace(/'/g, '').replace(/"/g, ''),
config.tailwind.prefix
)}"`
)}'`
);
});
}

if (node.isKind(SyntaxKind.StringLiteral)) {
node.replaceWithText(
`"${applyPrefix(
node.getText()?.replace(/"/g, ''),
`'${applyPrefix(
node.getText()?.replace(/'/g, '').replace(/"/g, ''),
config.tailwind.prefix
)}"`
)}'`
);
}
});
Expand Down Expand Up @@ -131,20 +131,20 @@ export const transformTwPrefixes: Transformer = async ({
.getChildrenOfKind(SyntaxKind.StringLiteral)
.forEach((node) => {
node.replaceWithText(
`"${applyPrefix(
node.getText()?.replace(/"/g, ''),
`'${applyPrefix(
node.getText()?.replace(/'/g, '').replace(/"/g, ''),
config.tailwind.prefix
)}"`
)}'`
);
});
}

if (arg.isKind(SyntaxKind.StringLiteral)) {
arg.replaceWithText(
`"${applyPrefix(
arg.getText()?.replace(/"/g, ''),
`'${applyPrefix(
arg.getText()?.replace(/'/g, '').replace(/"/g, ''),
config.tailwind.prefix
)}"`
)}'`
);
}
});
Expand All @@ -158,10 +158,10 @@ export const transformTwPrefixes: Transformer = async ({
const classNames = node.getInitializer();
if (classNames) {
classNames.replaceWithText(
`"${applyPrefix(
classNames.getText()?.replace(/"/g, ''),
`'${applyPrefix(
classNames.getText()?.replace(/'/g, '').replace(/"/g, ''),
config.tailwind.prefix
)}"`
)}'`
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
exports[`transform tailwind prefix 1`] = `
"import * as React from \\"react\\"
export function Foo() {
return <div className=\\"tw-bg-background hover:tw-bg-muted tw-text-primary-foreground sm:focus:tw-text-accent-foreground\\">foo</div>
return <div className='tw-bg-background hover:tw-bg-muted tw-text-primary-foreground sm:focus:tw-text-accent-foreground'>foo</div>
}
"
`;

exports[`transform tailwind prefix 2`] = `
"import * as React from 'react'
export function Foo() {
return <div className=\\"tw-'bg-white hover:tw-bg-stone-100 tw-text-stone-50 sm:focus:tw-text-stone-900 dark:tw-bg-stone-950 dark:hover:tw-bg-stone-800 dark:tw-text-stone-900 dark:sm:focus:tw-text-stone-50'\\">foo</div>
return <div className='tw-bg-white hover:tw-bg-stone-100 tw-text-stone-50 sm:focus:tw-text-stone-900 dark:tw-bg-stone-950 dark:hover:tw-bg-stone-800 dark:tw-text-stone-900 dark:sm:focus:tw-text-stone-50'>foo</div>
}
"
`;

exports[`transform tailwind prefix 3`] = `
"import * as React from 'react'
export function Foo() {
return <div className={cn(\\"tw-'bg-white hover:tw-bg-stone-100 dark:tw-bg-stone-950 dark:hover:tw-bg-stone-800'\\", true && \\"tw-'text-stone-50 sm:focus:tw-text-stone-900 dark:tw-text-stone-900 dark:sm:focus:tw-text-stone-50'\\")}>foo</div>
return <div className={cn('tw-bg-white hover:tw-bg-stone-100 dark:tw-bg-stone-950 dark:hover:tw-bg-stone-800', true && 'tw-text-stone-50 sm:focus:tw-text-stone-900 dark:tw-text-stone-900 dark:sm:focus:tw-text-stone-50')}>foo</div>
}
"
`;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/utils/transform-tw-prefix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function Foo() {
filename: 'test.ts',
raw: `import * as React from "react"
export function Foo() {
return <div className={cn("bg-background hover:bg-muted", true && "text-primary-foreground sm:focus:text-accent-foreground")}>foo</div>
return <div className={cn('bg-background hover:bg-muted', true && 'text-primary-foreground sm:focus:text-accent-foreground')}>foo</div>
}
`,
config: {
Expand Down
Loading