@@ -4,7 +4,7 @@ import type { Options } from './types'
44import { resolve } from 'pathe'
55import { existsSync } from 'fs'
66import { parse } from '@vue/compiler-dom'
7- import { RootNode , ElementNode } from '@vue/compiler-dom'
7+ import type { RootNode , ElementNode , AttributeNode } from '@vue/compiler-dom'
88
99function getRootBlock (
1010 root : RootNode ,
@@ -23,6 +23,17 @@ function isSetupScript(node: ElementNode) {
2323 return node . props . some ( ( prop ) => prop . type === 6 && prop . name === 'setup' )
2424}
2525
26+ function langAttr ( node ?: ElementNode ) : string {
27+ if ( ! node ) return ''
28+ const langProp = node . props . find (
29+ ( prop ) => prop . type === 6 && prop . name === 'lang' ,
30+ ) as AttributeNode | undefined
31+ if ( langProp && langProp . value ?. content ) {
32+ return ` lang="${ langProp . value . content } "`
33+ }
34+ return ''
35+ }
36+
2637/**
2738 * Imports `FormKitLazyProvider` component into the script block of the SFC.
2839 * @param code - The SFC source code.
@@ -37,12 +48,13 @@ function injectProviderImport(code: string): string {
3748 console . error ( err )
3849 return code
3950 }
51+ const script = getRootBlock ( root , 'script' )
4052 const importStatement = `import { FormKitLazyProvider } from '@formkit/vue'`
4153 const setupScript = root . children . find (
4254 ( node ) => node . type === 1 && node . tag === 'script' && isSetupScript ( node ) ,
4355 ) as ElementNode | undefined
4456 if ( ! setupScript ) {
45- return `<script setup>${ importStatement } </script>
57+ return `<script setup${ langAttr ( script ) } >${ importStatement } </script>
4658${ code } `
4759 }
4860 const startAt = setupScript . children [ 0 ] . loc . start . offset
0 commit comments