diff options
author | 2021-03-19 17:07:45 -0400 | |
---|---|---|
committer | 2021-03-19 17:07:45 -0400 | |
commit | 17c3c98f07628b43b941b84831e8e1f9bcd7ca46 (patch) | |
tree | 2e2b3c7d6bd67ebaabe6636ae6867ad368ac6c3a /src/codegen/index.ts | |
parent | 8ebc077cb0d9f50aae22d2651bd5ef13fe4641d3 (diff) | |
download | astro-17c3c98f07628b43b941b84831e8e1f9bcd7ca46.tar.gz astro-17c3c98f07628b43b941b84831e8e1f9bcd7ca46.tar.zst astro-17c3c98f07628b43b941b84831e8e1f9bcd7ca46.zip |
Initial tests set up (#10)
* Begin debugging
* Initial tests set up
This adds tests using uvu (we can switch if people want) and restructures things a bit so that it's easier to test.
Like in snowpack you set up a little project. In our tests you can say:
```js
const result = await runtime.load('/blog/hello-world')
```
And analyze the result. I included a `test-helpers.js` which has a function that will turn HTML into a cheerio instance, for inspecting the result HTML.
* Add CI
* Remove extra console logs
* Formatting
Diffstat (limited to 'src/codegen/index.ts')
-rw-r--r-- | src/codegen/index.ts | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/src/codegen/index.ts b/src/codegen/index.ts index 9b3104f0a..662d63858 100644 --- a/src/codegen/index.ts +++ b/src/codegen/index.ts @@ -1,6 +1,6 @@ import type { CompileOptions } from '../@types/compiler'; import type { Ast, TemplateNode } from '../compiler/interfaces'; -import type { JsxItem, TransformResult } from '../@types/astro.js'; +import type { JsxItem, TransformResult } from '../@types/astro'; import eslexer from 'es-module-lexer'; import esbuild from 'esbuild'; @@ -61,7 +61,6 @@ function getAttributes(attrs: Attribute[]): Record<string, string> { result[attr.name] = JSON.stringify(getTextFromAttribute(val)); continue; default: - console.log(val); throw new Error('UNKNOWN V'); } } @@ -75,7 +74,6 @@ function getTextFromAttribute(attr: any): string { if (attr.data !== undefined) { return attr.data; } - console.log(attr); throw new Error('UNKNOWN attr'); } @@ -169,12 +167,11 @@ function compileScriptSafe(raw: string, loader: 'jsx' | 'tsx'): string { export async function codegen(ast: Ast, { compileOptions }: CodeGenOptions): Promise<TransformResult> { await eslexer.init; - const script = compileScriptSafe(ast.instance ? ast.instance.content : '', 'tsx'); // Compile scripts as TypeScript, always + const script = compileScriptSafe(ast.instance ? ast.instance.content : '', 'tsx'); // Todo: Validate that `h` and `Fragment` aren't defined in the script - const [scriptImports] = eslexer.parse(script, 'optional-sourcename'); const components = Object.fromEntries( scriptImports.map((imp) => { @@ -193,7 +190,6 @@ export async function codegen(ast: Ast, { compileOptions }: CodeGenOptions): Pro walk(ast.html, { enter(node: TemplateNode) { - // console.log("enter", node.type); switch (node.type) { case 'MustacheTag': let code = compileScriptSafe(node.expression, 'jsx'); @@ -238,7 +234,6 @@ export async function codegen(ast: Ast, { compileOptions }: CodeGenOptions): Pro case 'Element': const name: string = node.name; if (!name) { - console.log(node); throw new Error('AHHHH'); } const attributes = getAttributes(node.attributes); @@ -298,12 +293,10 @@ export async function codegen(ast: Ast, { compileOptions }: CodeGenOptions): Pro return; } default: - console.log(node); throw new Error('Unexpected node type: ' + node.type); } }, leave(node, parent, prop, index) { - // console.log("leave", node.type); switch (node.type) { case 'Text': case 'MustacheTag': |