Skip to content

Commit

Permalink
fix:fragment frontmatter is optional (#184)
Browse files Browse the repository at this point in the history
* fix: make fragment frontmatter optional

* chore: lint fix
  • Loading branch information
natemoo-re authored Nov 30, 2021
1 parent 7149135 commit 1f0ba41
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-planes-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Fix bug when fragment parsing frontmatter is missing
3 changes: 2 additions & 1 deletion internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2864,7 +2864,8 @@ func ParseFragmentWithOptions(r io.Reader, context *Node, opts ...ParseOption) (
}

var result []*Node
if p.fm.FirstChild != nil {

if p.fm != nil && p.fm.FirstChild != nil {
p.fm.Parent.RemoveChild(p.fm)
result = append(result, p.fm)
}
Expand Down
Binary file modified lib/compiler/deno/astro.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions lib/compiler/test/empty-style.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-unused-vars */

import { transform } from '@astrojs/compiler';
import sass from 'sass';
Expand Down
3 changes: 2 additions & 1 deletion lib/compiler/test/output.test.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-console */
import { transform } from '@astrojs/compiler';

Expand All @@ -12,7 +13,7 @@ async function run() {
sourcefile: '/Users/matthew/dev/astro/packages/astro/test/fixtures/astro-attrs/src/pages/namespaced.astro',
sourcemap: 'both',
internalURL: 'astro/internal',
preprocessStyle: async (value, attrs) => {
preprocessStyle: async (_value, _attrs) => {
return null;
},
}
Expand Down
18 changes: 18 additions & 0 deletions lib/compiler/test/script-fragment.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable no-console */

import { transform } from '@astrojs/compiler';

async function run() {
const result = await transform(`<script src={Astro.resolve("../scripts/no_hoist_nonmodule.js")}></script>`, {
sourcemap: true,
as: 'fragment',
site: undefined,
sourcefile: 'MoreMenu.astro',
sourcemap: 'both',
internalURL: 'astro/internal',
});

console.log(result.code);
}

await run();
1 change: 1 addition & 0 deletions lib/compiler/test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ import './body-fragment.test.mjs';
import './component-only.test.mjs';
import './empty-style.test.mjs';
import './output.test.mjs';
import './script-fragment.test.mjs';
2 changes: 2 additions & 0 deletions lib/compiler/test/visible.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable no-console */
/* eslint-disable no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */

import { transform } from '@astrojs/compiler';

Expand Down

0 comments on commit 1f0ba41

Please sign in to comment.