summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/astro/src/compiler/index.ts7
-rw-r--r--packages/astro/src/compiler/transform/head.ts52
-rw-r--r--packages/astro/src/compiler/transform/util/end-of-head.ts23
-rw-r--r--packages/astro/src/runtime.ts2
-rw-r--r--packages/astro/test/no-head-el.test.js5
5 files changed, 34 insertions, 55 deletions
diff --git a/packages/astro/src/compiler/index.ts b/packages/astro/src/compiler/index.ts
index 0ba3d1898..aad0be330 100644
--- a/packages/astro/src/compiler/index.ts
+++ b/packages/astro/src/compiler/index.ts
@@ -102,13 +102,10 @@ async function transformFromSource(
interface CompileComponentOptions {
compileOptions: CompileOptions;
filename: string;
- projectRoot: string,
+ projectRoot: string;
isPage?: boolean;
}
-export async function compileComponent(
- source: string,
- { compileOptions, filename, projectRoot, isPage }: CompileComponentOptions
-): Promise<CompileResult> {
+export async function compileComponent(source: string, { compileOptions, filename, projectRoot, isPage }: CompileComponentOptions): Promise<CompileResult> {
const result = await transformFromSource(source, { compileOptions, filename, projectRoot });
const site = compileOptions.astroConfig.buildOptions.site || `http://localhost:${compileOptions.astroConfig.devOptions.port}`;
diff --git a/packages/astro/src/compiler/transform/head.ts b/packages/astro/src/compiler/transform/head.ts
index 935e0fd1e..fdf07cdfc 100644
--- a/packages/astro/src/compiler/transform/head.ts
+++ b/packages/astro/src/compiler/transform/head.ts
@@ -17,7 +17,7 @@ export default function (opts: TransformOptions): Transformer {
},
leave(node) {
eoh.leave(node);
- }
+ },
},
InlineComponent: {
enter(node) {
@@ -33,7 +33,7 @@ export default function (opts: TransformOptions): Transformer {
},
leave(node) {
eoh.leave(node);
- }
+ },
},
},
},
@@ -59,10 +59,7 @@ export default function (opts: TransformOptions): Transformer {
start: 0,
end: 0,
type: 'Expression',
- codeChunks: [
- 'Astro.css.map(css => (',
- '))'
- ],
+ codeChunks: ['Astro.css.map(css => (', '))'],
children: [
{
type: 'Element',
@@ -75,9 +72,9 @@ export default function (opts: TransformOptions): Transformer {
{
type: 'Text',
raw: 'stylesheet',
- data: 'stylesheet'
- }
- ]
+ data: 'stylesheet',
+ },
+ ],
},
{
name: 'href',
@@ -91,22 +88,20 @@ export default function (opts: TransformOptions): Transformer {
start: 0,
end: 0,
type: 'Expression',
- codeChunks: [
- 'css'
- ],
- children: []
- }
- }
- ]
- }
+ codeChunks: ['css'],
+ children: [],
+ },
+ },
+ ],
+ },
],
start: 0,
end: 0,
- children: []
- }
- ]
- }
- ]
+ children: [],
+ },
+ ],
+ },
+ ],
});
if (hasComponents) {
@@ -157,19 +152,16 @@ export default function (opts: TransformOptions): Transformer {
start: 0,
end: 0,
type: 'Expression',
- codeChunks: [
- 'Astro.isPage ? (',
- ') : null'
- ],
+ codeChunks: ['Astro.isPage ? (', ') : null'],
children: [
{
start: 0,
end: 0,
type: 'Fragment',
- children
- }
- ]
- }
+ children,
+ },
+ ],
+ };
eoh.append(conditionalNode);
},
diff --git a/packages/astro/src/compiler/transform/util/end-of-head.ts b/packages/astro/src/compiler/transform/util/end-of-head.ts
index d1af82fa5..cdf4d3423 100644
--- a/packages/astro/src/compiler/transform/util/end-of-head.ts
+++ b/packages/astro/src/compiler/transform/util/end-of-head.ts
@@ -1,22 +1,13 @@
import type { TemplateNode } from '@astrojs/parser';
-const validHeadElements = new Set([
- '!doctype',
- 'title',
- 'meta',
- 'link',
- 'style',
- 'script',
- 'noscript',
- 'base'
-]);
+const validHeadElements = new Set(['!doctype', 'title', 'meta', 'link', 'style', 'script', 'noscript', 'base']);
export class EndOfHead {
private head: TemplateNode | null = null;
private firstNonHead: TemplateNode | null = null;
private parent: TemplateNode | null = null;
private stack: TemplateNode[] = [];
-
+
public append: (...node: TemplateNode[]) => void = () => void 0;
get found(): boolean {
@@ -24,27 +15,27 @@ export class EndOfHead {
}
enter(node: TemplateNode) {
- if(this.found) {
+ if (this.found) {
return;
}
this.stack.push(node);
// Fragment has no name
- if(!node.name) {
+ if (!node.name) {
return;
}
const name = node.name.toLowerCase();
- if(name === 'head') {
+ if (name === 'head') {
this.head = node;
this.parent = this.stack[this.stack.length - 2];
this.append = this.appendToHead;
return;
}
- if(!validHeadElements.has(name)) {
+ if (!validHeadElements.has(name)) {
this.firstNonHead = node;
this.parent = this.stack[this.stack.length - 2];
this.append = this.prependToFirstNonHead;
@@ -66,4 +57,4 @@ export class EndOfHead {
let idx: number = this.parent?.children!.indexOf(this.firstNonHead!) || 0;
this.parent?.children?.splice(idx, 0, ...nodes);
}
-} \ No newline at end of file
+}
diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts
index bd4c4b525..9a374b757 100644
--- a/packages/astro/src/runtime.ts
+++ b/packages/astro/src/runtime.ts
@@ -228,7 +228,7 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro
},
children: [],
props: { collection },
- css: Array.isArray(mod.css) ? mod.css : typeof mod.css === 'string' ? [mod.css] : []
+ css: Array.isArray(mod.css) ? mod.css : typeof mod.css === 'string' ? [mod.css] : [],
})) as string;
return {
diff --git a/packages/astro/test/no-head-el.test.js b/packages/astro/test/no-head-el.test.js
index 76c756241..2ecc40531 100644
--- a/packages/astro/test/no-head-el.test.js
+++ b/packages/astro/test/no-head-el.test.js
@@ -7,8 +7,8 @@ const NoHeadEl = suite('Documents without a head');
setup(NoHeadEl, './fixtures/no-head-el', {
runtimeOptions: {
- mode: 'development'
- }
+ mode: 'development',
+ },
});
NoHeadEl('Places style and scripts before the first non-head element', async ({ runtime }) => {
@@ -25,5 +25,4 @@ NoHeadEl('Places style and scripts before the first non-head element', async ({
assert.equal($('script[src="/_snowpack/hmr-client.js"]').length, 1, 'Only the hmr client for the page');
});
-
NoHeadEl.run();