Skip to content

Commit

Permalink
fix: also parse tyepscript file (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
zernonia authored Nov 10, 2023
1 parent 9d80355 commit 6e5963e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/cli/src/utils/transformers/transform-css-vars.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type * as z from 'zod'
import MagicString from 'magic-string'
import type { SFCTemplateBlock } from '@vue/compiler-sfc'
import { parse, walk } from '@vue/compiler-sfc'
import { SyntaxKind } from 'ts-morph'
import type { registryBaseColorSchema } from '@/src/utils/registry/schema'
@@ -10,18 +11,23 @@ export const transformCssVars: Transformer = async ({
config,
baseColor,
}) => {
const isVueFile = sourceFile.getFilePath().endsWith('vue')
// No transform if using css variables.
if (config.tailwind?.cssVariables || !baseColor?.inlineColors || sourceFile.getFilePath().endsWith('ts'))
if (config.tailwind?.cssVariables || !baseColor?.inlineColors)
return sourceFile

const parsed = parse(sourceFile.getText())
const template = parsed.descriptor.template
let template: SFCTemplateBlock | null = null

if (!template)
return sourceFile
if (isVueFile) {
const parsed = parse(sourceFile.getText())
template = parsed.descriptor.template

if (!template)
return sourceFile
}

sourceFile.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach((node) => {
if (template.loc.start.offset >= node.getPos())
if (template && template.loc.start.offset >= node.getPos())
return sourceFile

const value = node.getText()

0 comments on commit 6e5963e

Please sign in to comment.