import { parse } from '@vue/compiler-sfc'; export function toTSX(code: string, className: string): string { let result = `export default function ${className}__AstroComponent_(_props: Record): any {}`; // NOTE: As you can expect, using regexes for this is not exactly the most reliable way of doing things // However, I couldn't figure out a way to do it using Vue's compiler, I tried looking at how Volar does it, but I // didn't really understand everything happening there and it seemed to be pretty Volar-specific. I do believe // someone more knowledgeable on Vue's internals could figure it out, but since this solution is good enough for most // Vue components (and it's an improvement over, well, nothing), it's alright, I think try { const parsedResult = parse(code); if (parsedResult.errors.length > 0) { return ` let ${className}__AstroComponent_: Error export default ${className}__AstroComponent_ `; } // Vue supports 2 type of script blocks: setup and non-setup const regularScriptBlockContent = parsedResult.descriptor.script?.content ?? ''; const { scriptSetup } = parsedResult.descriptor; if (scriptSetup) { const definePropsType = scriptSetup.content.match(/defineProps<([\S\s]+?)>\s?\(\)/m); const propsGeneric = scriptSetup.attrs.generic; const propsGenericType = propsGeneric ? `<${propsGeneric}>` : ''; if (definePropsType) { result = ` ${regularScriptBlockContent} ${scriptSetup.content} export default function ${className}__AstroComponent_${propsGenericType}(_props: ${definePropsType[1]}): any {
} `; } else { // TODO. Find a way to support generics when using defineProps without passing explicit types. // Right now something like this `defineProps({ prop: { type: Array as PropType } })` // won't be correctly typed in Astro. const defineProps = scriptSetup.content.match(/defineProps\([\s\S]+\)/m); if (defineProps) { result = ` import { defineProps } from '@vue/runtime-core'; ${regularScriptBlockContent} const Props = ${defineProps[0]} export default function ${className}__AstroComponent_${propsGenericType}(_props: typeof Props): any {
} `; } } } } catch (e: any) { return result; } return result; } ng-length Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Expand)AuthorFilesLines
2022-11-16`console.timeLog()` but no extra arguments yetGravatar Jarred Sumner 1-3/+21
2022-11-16Mark some more commonjs modulesGravatar Jarred Sumner 2-7/+34
2022-11-16Remove incorrect assertionGravatar Jarred Sumner 1-3/+1
2022-11-16Another testGravatar Jarred Sumner 1-0/+9
2022-11-16Make `node:http`.createServer work betterGravatar Jarred Sumner 6-39/+178
2022-11-15Fix another assertion failureGravatar Jarred Sumner 1-1/+1
2022-11-15Fix assertion failureGravatar Jarred Sumner 1-0/+4
2022-11-15Handle trailing slashGravatar Jarred Sumner 1-1/+17
2022-11-15Fixes #1390Gravatar Jarred Sumner 2-24/+54
2022-11-15Fixes #1403Gravatar Jarred Sumner 1-11/+16
2022-11-15Never resize on closeGravatar Jarred Sumner 1-2/+6
2022-11-15Handle blocking initial readGravatar Jarred Sumner 1-0/+18
2022-11-15Prevent blocking write()Gravatar Jarred Sumner 1-75/+89
2022-11-15Add non-standard headers API typesGravatar Jarred Sumner 3-2/+57
2022-11-15Add test for non-standard Headers API additionsGravatar Jarred Sumner 1-0/+24
2022-11-15add generated getter/setter type with thisValue (#1513)Gravatar Dylan Conway 6-38/+107
2022-11-15Update ZigGlobalObject.cppGravatar Jarred Sumner 1-3/+1
2022-11-15Add a test with decently large headersGravatar Jarred Sumner 1-0/+61
2022-11-15Update test types a littleGravatar Jarred Sumner 1-2/+2
2022-11-15Add missing typeGravatar Jarred Sumner 1-0/+5
2022-11-14switch default encoding order (#1510)Gravatar Dylan Conway 1-1/+1
2022-11-14Fix spawn macOS issueGravatar Jarred Sumner 1-7/+11
2022-11-14Fix crash in web crypto. caused by refptrGravatar Jarred Sumner 3-2/+15
2022-11-14Fix crashiness with `process.env`Gravatar Jarred Sumner 2-27/+66
2022-11-14Fix string encoding issue in JSC C API usagesGravatar Jarred Sumner 3-139/+74
2022-11-14Prevent double-frees in log msgsGravatar Jarred Sumner 1-4/+15
2022-11-14Fix build errorGravatar Jarred SUmner 2-6/+1
2022-11-14Bugfixes and perf improvements to child_processGravatar Jarred SUmner 15-192/+416
2022-11-13use `write$NOCANCEL`, more loggingGravatar Jarred Sumner 3-12/+42
2022-11-13Add an e2e testGravatar Jarred Sumner 3-0/+52
2022-11-13Add missing `rmdir` exportGravatar Jarred Sumner 1-1/+2
2022-11-13Make node streams faster (#1502)Gravatar Jarred Sumner 23-406/+836
2022-11-13Fix incorrect exit status messageGravatar Jarred Sumner 1-3/+6
2022-11-12Fix syntax errorGravatar Jarred Sumner 1-2/+2
2022-11-12Set linker script to Bun 0.2Gravatar Jarred SUmner 1-1/+1
2022-11-12Fix infinite write loop on LinuxGravatar Jarred SUmner 3-44/+185
2022-11-12Add missing typeGravatar Jarred SUmner 1-1/+1
2022-11-12Add linker script to remove unwanted exports (#1499)Gravatar Tom Birch 2-1/+9
2022-11-12Fix memory leak in gzip pool + add test for gzip'd dataGravatar Jarred SUmner 7-62/+1530
2022-11-12Redo how we poll pipes (#1496)Gravatar Jarred Sumner 22-707/+1251
2022-11-11Add test that fails on linuxGravatar Jarred Sumner 7-21/+42
2022-11-112 framesGravatar Jarred Sumner 1-1/+1
2022-11-11Revert "Omit frame pointer"Gravatar Jarred Sumner 1-0/+1
2022-11-11Don't rm cachedGravatar Jarred Sumner 4-4/+0
2022-11-11try thisGravatar Jarred Sumner 4-0/+4
2022-11-11Update bun-linux-build.ymlGravatar Jarred Sumner 1-1/+0
2022-11-11try using git actionGravatar Jarred Sumner 4-7/+8
2022-11-11Remove with `git rm`Gravatar Jarred Sumner 2-8/+0