diff options
author | 2021-03-30 10:51:31 -0400 | |
---|---|---|
committer | 2021-03-30 10:51:31 -0400 | |
commit | 3b27eaac4384e82e7f08122f0797a9671470781a (patch) | |
tree | 8c4c1b653d7f947e1589a35046ef4f64b92d7c97 /src/compiler/optimize/index.ts | |
parent | dbd764bdeb2b514a426690cedb390edb9c2a75de (diff) | |
download | astro-3b27eaac4384e82e7f08122f0797a9671470781a.tar.gz astro-3b27eaac4384e82e7f08122f0797a9671470781a.tar.zst astro-3b27eaac4384e82e7f08122f0797a9671470781a.zip |
Add support for doctype (#37)
* Add support for doctype
* Automatically prepend doctype
Diffstat (limited to 'src/compiler/optimize/index.ts')
-rw-r--r-- | src/compiler/optimize/index.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/compiler/optimize/index.ts b/src/compiler/optimize/index.ts index aa5ca58f3..d86ce3c24 100644 --- a/src/compiler/optimize/index.ts +++ b/src/compiler/optimize/index.ts @@ -1,7 +1,10 @@ import { walk } from 'estree-walker'; import type { Ast, TemplateNode } from '../../parser/interfaces'; import { NodeVisitor, Optimizer, VisitorFn } from '../../@types/optimizer'; + +// Optimizers import optimizeStyles from './styles.js'; +import optimizeDoctype from './doctype.js'; interface VisitorCollection { enter: Map<string, VisitorFn[]>; @@ -44,19 +47,19 @@ function createVisitorCollection() { function walkAstWithVisitors(tmpl: TemplateNode, collection: VisitorCollection) { walk(tmpl, { - enter(node) { + enter(node, parent, key, index) { if (collection.enter.has(node.type)) { const fns = collection.enter.get(node.type)!; for (let fn of fns) { - fn(node); + fn(node, parent, key, index); } } }, - leave(node) { + leave(node, parent, key, index) { if (collection.leave.has(node.type)) { const fns = collection.leave.get(node.type)!; for (let fn of fns) { - fn(node); + fn(node, parent, key, index); } } }, @@ -73,7 +76,7 @@ export async function optimize(ast: Ast, opts: OptimizeOptions) { const cssVisitors = createVisitorCollection(); const finalizers: Array<() => Promise<void>> = []; - const optimizers = [optimizeStyles(opts)]; + const optimizers = [optimizeStyles(opts), optimizeDoctype(opts)]; for (const optimizer of optimizers) { collectVisitors(optimizer, htmlVisitors, cssVisitors, finalizers); |