[ci] yarn format

This commit is contained in:
matthewp 2021-06-21 16:29:33 +00:00 committed by GitHub Actions
parent b547892411
commit b2a72ccac4
5 changed files with 34 additions and 55 deletions

View file

@ -102,13 +102,10 @@ async function transformFromSource(
interface CompileComponentOptions { interface CompileComponentOptions {
compileOptions: CompileOptions; compileOptions: CompileOptions;
filename: string; filename: string;
projectRoot: string, projectRoot: string;
isPage?: boolean; isPage?: boolean;
} }
export async function compileComponent( export async function compileComponent(source: string, { compileOptions, filename, projectRoot, isPage }: CompileComponentOptions): Promise<CompileResult> {
source: string,
{ compileOptions, filename, projectRoot, isPage }: CompileComponentOptions
): Promise<CompileResult> {
const result = await transformFromSource(source, { compileOptions, filename, projectRoot }); const result = await transformFromSource(source, { compileOptions, filename, projectRoot });
const site = compileOptions.astroConfig.buildOptions.site || `http://localhost:${compileOptions.astroConfig.devOptions.port}`; const site = compileOptions.astroConfig.buildOptions.site || `http://localhost:${compileOptions.astroConfig.devOptions.port}`;

View file

@ -17,7 +17,7 @@ export default function (opts: TransformOptions): Transformer {
}, },
leave(node) { leave(node) {
eoh.leave(node); eoh.leave(node);
} },
}, },
InlineComponent: { InlineComponent: {
enter(node) { enter(node) {
@ -33,7 +33,7 @@ export default function (opts: TransformOptions): Transformer {
}, },
leave(node) { leave(node) {
eoh.leave(node); eoh.leave(node);
} },
}, },
}, },
}, },
@ -59,10 +59,7 @@ export default function (opts: TransformOptions): Transformer {
start: 0, start: 0,
end: 0, end: 0,
type: 'Expression', type: 'Expression',
codeChunks: [ codeChunks: ['Astro.css.map(css => (', '))'],
'Astro.css.map(css => (',
'))'
],
children: [ children: [
{ {
type: 'Element', type: 'Element',
@ -75,9 +72,9 @@ export default function (opts: TransformOptions): Transformer {
{ {
type: 'Text', type: 'Text',
raw: 'stylesheet', raw: 'stylesheet',
data: 'stylesheet' data: 'stylesheet',
} },
] ],
}, },
{ {
name: 'href', name: 'href',
@ -91,22 +88,20 @@ export default function (opts: TransformOptions): Transformer {
start: 0, start: 0,
end: 0, end: 0,
type: 'Expression', type: 'Expression',
codeChunks: [ codeChunks: ['css'],
'css' children: [],
], },
children: [] },
} ],
} },
]
}
], ],
start: 0, start: 0,
end: 0, end: 0,
children: [] children: [],
} },
] ],
} },
] ],
}); });
if (hasComponents) { if (hasComponents) {
@ -157,19 +152,16 @@ export default function (opts: TransformOptions): Transformer {
start: 0, start: 0,
end: 0, end: 0,
type: 'Expression', type: 'Expression',
codeChunks: [ codeChunks: ['Astro.isPage ? (', ') : null'],
'Astro.isPage ? (',
') : null'
],
children: [ children: [
{ {
start: 0, start: 0,
end: 0, end: 0,
type: 'Fragment', type: 'Fragment',
children children,
} },
] ],
} };
eoh.append(conditionalNode); eoh.append(conditionalNode);
}, },

View file

@ -1,22 +1,13 @@
import type { TemplateNode } from '@astrojs/parser'; import type { TemplateNode } from '@astrojs/parser';
const validHeadElements = new Set([ const validHeadElements = new Set(['!doctype', 'title', 'meta', 'link', 'style', 'script', 'noscript', 'base']);
'!doctype',
'title',
'meta',
'link',
'style',
'script',
'noscript',
'base'
]);
export class EndOfHead { export class EndOfHead {
private head: TemplateNode | null = null; private head: TemplateNode | null = null;
private firstNonHead: TemplateNode | null = null; private firstNonHead: TemplateNode | null = null;
private parent: TemplateNode | null = null; private parent: TemplateNode | null = null;
private stack: TemplateNode[] = []; private stack: TemplateNode[] = [];
public append: (...node: TemplateNode[]) => void = () => void 0; public append: (...node: TemplateNode[]) => void = () => void 0;
get found(): boolean { get found(): boolean {
@ -24,27 +15,27 @@ export class EndOfHead {
} }
enter(node: TemplateNode) { enter(node: TemplateNode) {
if(this.found) { if (this.found) {
return; return;
} }
this.stack.push(node); this.stack.push(node);
// Fragment has no name // Fragment has no name
if(!node.name) { if (!node.name) {
return; return;
} }
const name = node.name.toLowerCase(); const name = node.name.toLowerCase();
if(name === 'head') { if (name === 'head') {
this.head = node; this.head = node;
this.parent = this.stack[this.stack.length - 2]; this.parent = this.stack[this.stack.length - 2];
this.append = this.appendToHead; this.append = this.appendToHead;
return; return;
} }
if(!validHeadElements.has(name)) { if (!validHeadElements.has(name)) {
this.firstNonHead = node; this.firstNonHead = node;
this.parent = this.stack[this.stack.length - 2]; this.parent = this.stack[this.stack.length - 2];
this.append = this.prependToFirstNonHead; this.append = this.prependToFirstNonHead;
@ -66,4 +57,4 @@ export class EndOfHead {
let idx: number = this.parent?.children!.indexOf(this.firstNonHead!) || 0; let idx: number = this.parent?.children!.indexOf(this.firstNonHead!) || 0;
this.parent?.children?.splice(idx, 0, ...nodes); this.parent?.children?.splice(idx, 0, ...nodes);
} }
} }

View file

@ -228,7 +228,7 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro
}, },
children: [], children: [],
props: { collection }, 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; })) as string;
return { return {

View file

@ -7,8 +7,8 @@ const NoHeadEl = suite('Documents without a head');
setup(NoHeadEl, './fixtures/no-head-el', { setup(NoHeadEl, './fixtures/no-head-el', {
runtimeOptions: { runtimeOptions: {
mode: 'development' mode: 'development',
} },
}); });
NoHeadEl('Places style and scripts before the first non-head element', async ({ runtime }) => { 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'); assert.equal($('script[src="/_snowpack/hmr-client.js"]').length, 1, 'Only the hmr client for the page');
}); });
NoHeadEl.run(); NoHeadEl.run();