@sanity/codegen 3.68.3 → 3.68.4-corel.526
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.esm.js +62 -104
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +62 -104
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +62 -104
- package/lib/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/typescript/parseSource.ts +23 -2
|
@@ -3,10 +3,17 @@ import type * as babelTypes from '@babel/types'
|
|
|
3
3
|
|
|
4
4
|
// helper function to parse a source file
|
|
5
5
|
export function parseSourceFile(
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
_source: string,
|
|
7
|
+
_filename: string,
|
|
8
8
|
babelOptions: TransformOptions,
|
|
9
9
|
): babelTypes.File {
|
|
10
|
+
let source = _source
|
|
11
|
+
let filename = _filename
|
|
12
|
+
if (filename.endsWith('.astro')) {
|
|
13
|
+
// append .ts to the filename so babel will parse it as typescript
|
|
14
|
+
filename += '.ts'
|
|
15
|
+
source = parseAstro(source)
|
|
16
|
+
}
|
|
10
17
|
const result = parse(source, {
|
|
11
18
|
...babelOptions,
|
|
12
19
|
filename,
|
|
@@ -18,3 +25,17 @@ export function parseSourceFile(
|
|
|
18
25
|
|
|
19
26
|
return result
|
|
20
27
|
}
|
|
28
|
+
|
|
29
|
+
function parseAstro(source: string): string {
|
|
30
|
+
// find all code fences, the js code is between --- and ---
|
|
31
|
+
const codeFences = source.match(/---\n([\s\S]*?)\n---/g)
|
|
32
|
+
if (!codeFences) {
|
|
33
|
+
return ''
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return codeFences
|
|
37
|
+
.map((codeFence) => {
|
|
38
|
+
return codeFence.split('\n').slice(1, -1).join('\n')
|
|
39
|
+
})
|
|
40
|
+
.join('\n')
|
|
41
|
+
}
|