fix: also parse tyepscript file (#159)
This commit is contained in:
parent
9d8035566f
commit
6e5963ebe9
|
|
@ -1,5 +1,6 @@
|
||||||
import type * as z from 'zod'
|
import type * as z from 'zod'
|
||||||
import MagicString from 'magic-string'
|
import MagicString from 'magic-string'
|
||||||
|
import type { SFCTemplateBlock } from '@vue/compiler-sfc'
|
||||||
import { parse, walk } from '@vue/compiler-sfc'
|
import { parse, walk } from '@vue/compiler-sfc'
|
||||||
import { SyntaxKind } from 'ts-morph'
|
import { SyntaxKind } from 'ts-morph'
|
||||||
import type { registryBaseColorSchema } from '@/src/utils/registry/schema'
|
import type { registryBaseColorSchema } from '@/src/utils/registry/schema'
|
||||||
|
|
@ -10,18 +11,23 @@ export const transformCssVars: Transformer = async ({
|
||||||
config,
|
config,
|
||||||
baseColor,
|
baseColor,
|
||||||
}) => {
|
}) => {
|
||||||
|
const isVueFile = sourceFile.getFilePath().endsWith('vue')
|
||||||
// No transform if using css variables.
|
// No transform if using css variables.
|
||||||
if (config.tailwind?.cssVariables || !baseColor?.inlineColors || sourceFile.getFilePath().endsWith('ts'))
|
if (config.tailwind?.cssVariables || !baseColor?.inlineColors)
|
||||||
return sourceFile
|
return sourceFile
|
||||||
|
|
||||||
|
let template: SFCTemplateBlock | null = null
|
||||||
|
|
||||||
|
if (isVueFile) {
|
||||||
const parsed = parse(sourceFile.getText())
|
const parsed = parse(sourceFile.getText())
|
||||||
const template = parsed.descriptor.template
|
template = parsed.descriptor.template
|
||||||
|
|
||||||
if (!template)
|
if (!template)
|
||||||
return sourceFile
|
return sourceFile
|
||||||
|
}
|
||||||
|
|
||||||
sourceFile.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach((node) => {
|
sourceFile.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach((node) => {
|
||||||
if (template.loc.start.offset >= node.getPos())
|
if (template && template.loc.start.offset >= node.getPos())
|
||||||
return sourceFile
|
return sourceFile
|
||||||
|
|
||||||
const value = node.getText()
|
const value = node.getText()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user