diff --git a/cmd/astro-wasm/astro-wasm.go b/cmd/astro-wasm/astro-wasm.go index 8a539b976..d8e958815 100644 --- a/cmd/astro-wasm/astro-wasm.go +++ b/cmd/astro-wasm/astro-wasm.go @@ -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 @@ -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{ @@ -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) diff --git a/internal/printer/printer_test.go b/internal/printer/printer_test.go index 73c3e7759..41a709fd6 100644 --- a/internal/printer/printer_test.go +++ b/internal/printer/printer_test.go @@ -94,6 +94,13 @@ func TestPrinter(t *testing.T) { code: ``, }, }, + { + name: "basic renderHead", + source: `Ah`, + want: want{ + code: `Ah${$$renderHead($$result)}`, + }, + }, { name: "basic (frontmatter)", source: `--- diff --git a/lib/compiler/deno/astro.wasm b/lib/compiler/deno/astro.wasm index a4244f92f..307f11984 100755 Binary files a/lib/compiler/deno/astro.wasm and b/lib/compiler/deno/astro.wasm differ diff --git a/lib/compiler/test/body-fragment.test.mjs b/lib/compiler/test/body-fragment.test.mjs index 9db56d7ac..2d45f7a06 100644 --- a/lib/compiler/test/body-fragment.test.mjs +++ b/lib/compiler/test/body-fragment.test.mjs @@ -20,6 +20,10 @@ import ThemeToggleButton from './ThemeToggleButton.tsx'; } ); + if (result.code.includes('')) { + throw new Error('Expected output not to contain '); + } + if (!result.code.includes('
Hello!
')) { throw new Error('Expected output to contain
Hello!
'); } diff --git a/lib/compiler/test/parse.test.mjs b/lib/compiler/test/parse.test.mjs index cff4bf02a..7d2979e20 100644 --- a/lib/compiler/test/parse.test.mjs +++ b/lib/compiler/test/parse.test.mjs @@ -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) => { diff --git a/lib/compiler/test/render-head.test.mjs b/lib/compiler/test/render-head.test.mjs new file mode 100644 index 000000000..a24688b4e --- /dev/null +++ b/lib/compiler/test/render-head.test.mjs @@ -0,0 +1,27 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable no-console */ +import { transform } from '@astrojs/compiler'; + +const source = `Ah`; + +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); +}); diff --git a/lib/compiler/test/test.mjs b/lib/compiler/test/test.mjs index 5390358d2..e5650b340 100644 --- a/lib/compiler/test/test.mjs +++ b/lib/compiler/test/test.mjs @@ -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';