summaryrefslogtreecommitdiff
path: root/src/compiler/index.ts
diff options
context:
space:
mode:
authorGravatar Drew Powers <1369770+drwpow@users.noreply.github.com> 2021-04-01 10:25:28 -0600
committerGravatar GitHub <noreply@github.com> 2021-04-01 10:25:28 -0600
commitc26c244ca2634d462616d6cf71072fbe26becba2 (patch)
tree1bd5e83eff9ca88200aacb272c84439f192015ec /src/compiler/index.ts
parentf6a7ac67befff863e34133673efb78ea7ac0fe48 (diff)
downloadastro-c26c244ca2634d462616d6cf71072fbe26becba2.tar.gz
astro-c26c244ca2634d462616d6cf71072fbe26becba2.tar.zst
astro-c26c244ca2634d462616d6cf71072fbe26becba2.zip
Annoying Lint PR #2 (#47)
Diffstat (limited to 'src/compiler/index.ts')
-rw-r--r--src/compiler/index.ts16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/compiler/index.ts b/src/compiler/index.ts
index 88ea5caf9..541bae21e 100644
--- a/src/compiler/index.ts
+++ b/src/compiler/index.ts
@@ -13,6 +13,7 @@ import { encodeMarkdown } from '../micromark-encode.js';
import { optimize } from './optimize/index.js';
import { codegen } from './codegen.js';
+/** Return Astro internal import URL */
function internalImport(internalPath: string) {
return `/_astro_internal/${internalPath}`;
}
@@ -23,6 +24,13 @@ interface ConvertAstroOptions {
fileID: string;
}
+/**
+ * .astro -> .jsx
+ * Core function processing .astro files. Initiates all 3 phases of compilation:
+ * 1. Parse
+ * 2. Optimize
+ * 3. Codegen
+ */
async function convertAstroToJsx(template: string, opts: ConvertAstroOptions): Promise<TransformResult> {
const { filename } = opts;
@@ -34,10 +42,14 @@ async function convertAstroToJsx(template: string, opts: ConvertAstroOptions): P
// 2. Optimize the AST
await optimize(ast, opts);
- // Turn AST into JSX
+ // 3. Turn AST into JSX
return await codegen(ast, opts);
}
+/**
+ * .md -> .jsx
+ * Core function processing Markdown, but along the way also calls convertAstroToJsx().
+ */
async function convertMdToJsx(
contents: string,
{ compileOptions, filename, fileID }: { compileOptions: CompileOptions; filename: string; fileID: string }
@@ -80,6 +92,7 @@ async function convertMdToJsx(
type SupportedExtensions = '.astro' | '.md';
+/** Given a file, process it either as .astro or .md. */
async function transformFromSource(
contents: string,
{ compileOptions, filename, projectRoot }: { compileOptions: CompileOptions; filename: string; projectRoot: string }
@@ -95,6 +108,7 @@ async function transformFromSource(
}
}
+/** Return internal code that gets processed in Snowpack */
export async function compileComponent(
source: string,
{ compileOptions, filename, projectRoot }: { compileOptions: CompileOptions; filename: string; projectRoot: string }