Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions cmd/astro-wasm/astro-wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
t "github.com/withastro/compiler/internal/t"
"github.com/withastro/compiler/internal/transform"
wasm_utils "github.com/withastro/compiler/internal_wasm/utils"
"golang.org/x/net/html/atom"
)

var done chan bool
Expand Down Expand Up @@ -160,22 +159,10 @@ func Parse() interface{} {
parseOptions := makeParseOptions(js.Value(args[1]))

var doc *astro.Node
nodes, err := astro.ParseFragment(strings.NewReader(source), &astro.Node{
Type: astro.ElementNode,
Data: atom.Template.String(),
DataAtom: atom.Template,
})
doc, err := astro.Parse(strings.NewReader(source))
if err != nil {
fmt.Println(err)
}
doc = &astro.Node{
Type: astro.DocumentNode,
}
for i := 0; i < len(nodes); i++ {
n := nodes[i]
doc.AppendChild(n)
}

result := printer.PrintToJSON(source, doc, parseOptions)

return vert.ValueOf(ParseResult{
Expand All @@ -196,22 +183,10 @@ func Transform() interface{} {
go func() {
var doc *astro.Node

nodes, err := astro.ParseFragment(strings.NewReader(source), &astro.Node{
Type: astro.ElementNode,
Data: atom.Template.String(),
DataAtom: atom.Template,
})
doc, err := astro.Parse(strings.NewReader(source))
if err != nil {
fmt.Println(err)
}
doc = &astro.Node{
Type: astro.DocumentNode,
HydrationDirectives: make(map[string]bool),
}
for i := 0; i < len(nodes); i++ {
n := nodes[i]
doc.AppendChild(n)
}

// Hoist styles and scripts to the top-level
transform.ExtractStyles(doc)
Expand Down
7 changes: 7 additions & 0 deletions internal/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ func TestPrinter(t *testing.T) {
code: `<button>Click</button>`,
},
},
{
name: "basic renderHead",
source: `<html><head><title>Ah</title></head></html>`,
want: want{
code: `<html><head><title>Ah</title>${$$renderHead($$result)}</head></html>`,
},
},
{
name: "basic (frontmatter)",
source: `---
Expand Down
Binary file modified lib/compiler/deno/astro.wasm
Binary file not shown.
4 changes: 4 additions & 0 deletions lib/compiler/test/body-fragment.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import ThemeToggleButton from './ThemeToggleButton.tsx';
}
);

if (result.code.includes('<head>')) {
throw new Error('Expected output not to contain <head>');
}

if (!result.code.includes('<body><div>Hello!</div></body>')) {
throw new Error('Expected output to contain <body><div>Hello!</div></body>');
}
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/test/parse.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ async function run() {
if (result.ast.type !== 'root') {
throw new Error(`Expected "ast" root node to be of type "root"`);
}
const [frontmatter, _, element] = result.ast.children;
const [frontmatter, element] = result.ast.children;
if (frontmatter.type !== 'frontmatter') {
throw new Error(`Expected first child node to be of type "frontmatter"`);
}
if (element.type !== 'element') {
throw new Error(`Expected third child node to be of type "element"`);
throw new Error(`Expected second child node to be of type "element"`);
}

walk(result.ast, (node) => {
Expand Down
27 changes: 27 additions & 0 deletions lib/compiler/test/render-head.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-console */
import { transform } from '@astrojs/compiler';

const source = `<html><head><title>Ah</title></head></html>`;

async function run() {
const result = await transform(source, {
site: undefined,
sourcefile: '/Users/matthew/dev/astro/packages/astro/test/fixtures/astro-attrs/src/pages/namespaced.astro',
sourcemap: 'both',
internalURL: 'astro/internal',
preprocessStyle: async (_value, _attrs) => {
return null;
},
});

if (!result.code.includes('$$renderHead(')) {
console.log(result.code);
throw new Error('Result did not include $$renderHead(');
}
}

await run().catch((err) => {
console.error(err);
process.exit(1);
});
1 change: 1 addition & 0 deletions lib/compiler/test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ import './script-fragment.test.mjs';
import './top-level-expression.test.mjs';
import './stress.test.mjs';
import './parse.test.mjs';
import './render-head.test.mjs';