diff options
author | 2021-04-13 18:08:32 -0600 | |
---|---|---|
committer | 2021-04-13 18:08:32 -0600 | |
commit | 3d0d53486caa1c6194aa0cdc0f3988824462bca4 (patch) | |
tree | ec5772a19483741ca5aeb454c722b9c9bc342e23 /src/compiler/codegen/utils.ts | |
parent | 4a71de9e3d47af33f862cd25750b725a0f35e687 (diff) | |
download | astro-3d0d53486caa1c6194aa0cdc0f3988824462bca4.tar.gz astro-3d0d53486caa1c6194aa0cdc0f3988824462bca4.tar.zst astro-3d0d53486caa1c6194aa0cdc0f3988824462bca4.zip |
Add Astro.fetchContent API (#91)
Diffstat (limited to 'src/compiler/codegen/utils.ts')
-rw-r--r-- | src/compiler/codegen/utils.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/compiler/codegen/utils.ts b/src/compiler/codegen/utils.ts index 5a9316fa1..e1c558bc4 100644 --- a/src/compiler/codegen/utils.ts +++ b/src/compiler/codegen/utils.ts @@ -18,3 +18,22 @@ export function isImportMetaDeclaration(declaration: VariableDeclarator, metaNam if (metaName && (init.callee.property.type !== 'Identifier' || init.callee.property.name !== metaName)) return false; return true; } + +/** Is this an Astro.fetchContent() call? */ +export function isFetchContent(declaration: VariableDeclarator): boolean { + let { init } = declaration; + if (!init) return false; // definitely not import.meta + // this could be `await import.meta`; if so, evaluate that: + if (init.type === 'AwaitExpression') { + init = init.argument; + } + // continue evaluating + if ( + init.type !== 'CallExpression' || + init.callee.type !== 'MemberExpression' || + (init.callee.object as any).name !== 'Astro' || + (init.callee.property as any).name !== 'fetchContent' + ) + return false; + return true; +} |