fix: prevent transforming importDeclaration
This commit is contained in:
parent
0f551c85e6
commit
386c77c9c6
|
|
@ -31,6 +31,11 @@ export const transformTwPrefixes: Transformer = async ({
|
||||||
return sourceFile
|
return sourceFile
|
||||||
|
|
||||||
const value = node.getText()
|
const value = node.getText()
|
||||||
|
|
||||||
|
// Do not parse imported packages/files
|
||||||
|
if (node.getParent().getKind() === SyntaxKind.ImportDeclaration)
|
||||||
|
return
|
||||||
|
|
||||||
const hasClosingDoubleQuote = value.match(/"/g)?.length === 2
|
const hasClosingDoubleQuote = value.match(/"/g)?.length === 2
|
||||||
const hasFunction = value.startsWith('"cn(')
|
const hasFunction = value.startsWith('"cn(')
|
||||||
if (value.search('\'') === -1 && hasClosingDoubleQuote && !hasFunction) {
|
if (value.search('\'') === -1 && hasClosingDoubleQuote && !hasFunction) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||||
|
|
||||||
exports[`transform tailwind prefix 1`] = `
|
exports[`transform tailwind prefix 1`] = `
|
||||||
"const testVariants = cva(
|
"import { cva } from "class-variance-authority";
|
||||||
|
export const testVariants = cva(
|
||||||
"tw-bg-background hover:tw-bg-muted tw-text-primary-foreground sm:focus:tw-text-accent-foreground",
|
"tw-bg-background hover:tw-bg-muted tw-text-primary-foreground sm:focus:tw-text-accent-foreground",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
|
|
@ -54,6 +55,13 @@ exports[`transform tailwind prefix 4`] = `
|
||||||
)
|
)
|
||||||
"
|
"
|
||||||
:class="cn(buttonVariants({ variant, size }), props.class)"
|
:class="cn(buttonVariants({ variant, size }), props.class)"
|
||||||
|
:class="
|
||||||
|
cn(
|
||||||
|
buttonVariants({ 'outline' }),
|
||||||
|
props.class,
|
||||||
|
'tw-bg-background'
|
||||||
|
)
|
||||||
|
"
|
||||||
>
|
>
|
||||||
foo
|
foo
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ it('transform tailwind prefix', async () => {
|
||||||
expect(
|
expect(
|
||||||
await transform({
|
await transform({
|
||||||
filename: 'test.ts',
|
filename: 'test.ts',
|
||||||
raw: `const testVariants = cva(
|
raw: `import { cva } from "class-variance-authority"
|
||||||
|
|
||||||
|
export const testVariants = cva(
|
||||||
'bg-background hover:bg-muted text-primary-foreground sm:focus:text-accent-foreground',
|
'bg-background hover:bg-muted text-primary-foreground sm:focus:text-accent-foreground',
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
|
|
@ -88,6 +90,13 @@ it('transform tailwind prefix', async () => {
|
||||||
id="testing" v-bind="props" @click="handleSomething" :data-test="true"
|
id="testing" v-bind="props" @click="handleSomething" :data-test="true"
|
||||||
:class="cn('bg-background hover:bg-muted', true && 'text-primary-foreground sm:focus:text-accent-foreground')"
|
:class="cn('bg-background hover:bg-muted', true && 'text-primary-foreground sm:focus:text-accent-foreground')"
|
||||||
:class="cn(buttonVariants({ variant, size }), props.class)"
|
:class="cn(buttonVariants({ variant, size }), props.class)"
|
||||||
|
:class="
|
||||||
|
cn(
|
||||||
|
buttonVariants({ 'outline' }),
|
||||||
|
props.class,
|
||||||
|
'bg-background'
|
||||||
|
)
|
||||||
|
"
|
||||||
>
|
>
|
||||||
foo
|
foo
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user