diff options
author | 2021-04-12 17:21:29 -0600 | |
---|---|---|
committer | 2021-04-12 17:21:29 -0600 | |
commit | 3639190b4e1b4c97836d448fa80a58aa45c823a7 (patch) | |
tree | 31160f051aa00cb0ebb820ab2061fb7d16956ee0 /src/compiler/codegen/utils.ts | |
parent | 687ff5bacd8c776e514f53c4b59c3a67274d3971 (diff) | |
download | astro-3639190b4e1b4c97836d448fa80a58aa45c823a7.tar.gz astro-3639190b4e1b4c97836d448fa80a58aa45c823a7.tar.zst astro-3639190b4e1b4c97836d448fa80a58aa45c823a7.zip |
Renaming to import.meta.fetchContent (#70)
* Change to import.meta.glob()
Change of plans—maintain parity with Snowpack and Vite because our Collections API will use a different interface
* Get basic pagination working
* Get params working
* Rename to import.meta.fetchContent
* Upgrade to fdir
Diffstat (limited to 'src/compiler/codegen/utils.ts')
-rw-r--r-- | src/compiler/codegen/utils.ts | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/compiler/codegen/utils.ts b/src/compiler/codegen/utils.ts new file mode 100644 index 000000000..5a9316fa1 --- /dev/null +++ b/src/compiler/codegen/utils.ts @@ -0,0 +1,20 @@ +/** + * Codegen utils + */ + +import type { VariableDeclarator } from '@babel/types'; + +/** Is this an import.meta.* built-in? You can pass an optional 2nd param to see if the name matches as well. */ +export function isImportMetaDeclaration(declaration: VariableDeclarator, metaName?: string): 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.type !== 'MetaProperty') return false; + // optional: if metaName specified, match that + if (metaName && (init.callee.property.type !== 'Identifier' || init.callee.property.name !== metaName)) return false; + return true; +} |