summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@matthewphillips.info> 2021-06-01 21:03:38 -0400
committerGravatar GitHub <noreply@github.com> 2021-06-01 20:03:38 -0500
commit46871d2d4a7968c0c3b38bdb147eae3a2d4852f8 (patch)
tree222975d229d497657d7ffdafb8dd97291128f51e
parentee5b1ac12f60f1c0265d395d742dd8e1db880411 (diff)
downloadastro-46871d2d4a7968c0c3b38bdb147eae3a2d4852f8.tar.gz
astro-46871d2d4a7968c0c3b38bdb147eae3a2d4852f8.tar.zst
astro-46871d2d4a7968c0c3b38bdb147eae3a2d4852f8.zip
Don't append a class attribute to the doctype (#284)
* Don't append a class attribute to the doctype Fixes #282 * Add changeset
-rw-r--r--.changeset/fast-colts-shout.md5
-rw-r--r--packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts3
-rw-r--r--packages/astro/test/astro-doctype.test.js8
-rw-r--r--packages/astro/test/fixtures/astro-doctype/src/pages/provided.astro9
4 files changed, 23 insertions, 2 deletions
diff --git a/.changeset/fast-colts-shout.md b/.changeset/fast-colts-shout.md
new file mode 100644
index 000000000..40932357e
--- /dev/null
+++ b/.changeset/fast-colts-shout.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fixed bug where a class attribute was added to the doctype
diff --git a/packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts b/packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts
index 7a038dd7a..a7d20b9d4 100644
--- a/packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts
+++ b/packages/astro/src/compiler/transform/postcss-scoped-styles/index.ts
@@ -14,8 +14,7 @@ const CSS_SEPARATORS = new Set([' ', ',', '+', '>', '~']);
const KEYFRAME_PERCENT = /\d+\.?\d*%/;
/** HTML tags that should never get scoped classes */
-export const NEVER_SCOPED_TAGS = new Set<string>(['base', 'body', 'font', 'frame', 'frameset', 'head', 'html', 'link', 'meta', 'noframes', 'noscript', 'script', 'style', 'title']);
-
+export const NEVER_SCOPED_TAGS = new Set<string>(['base', 'body', 'font', 'frame', 'frameset', 'head', 'html', 'link', 'meta', 'noframes', 'noscript', 'script', 'style', 'title', '!doctype']);
/**
* Scope Rules
* Given a selector string (`.btn>span,.nav>span`), add an additional CSS class to every selector (`.btn.myClass>span.myClass,.nav.myClass>span.myClass`)
diff --git a/packages/astro/test/astro-doctype.test.js b/packages/astro/test/astro-doctype.test.js
index d0d0db105..0db0135ae 100644
--- a/packages/astro/test/astro-doctype.test.js
+++ b/packages/astro/test/astro-doctype.test.js
@@ -40,6 +40,14 @@ DType('Automatically prepends the standards mode doctype', async () => {
assert.ok(html.startsWith('<!doctype html>'), 'Doctype always included');
});
+DType('No attributes added when doctype is provided by user', async () => {
+ const result = await runtime.load('/provided');
+ if (result.error) throw new Error(result.error);
+
+ const html = result.contents.toString('utf-8');
+ assert.ok(html.startsWith('<!doctype html>'), 'Doctype always included');
+});
+
DType.skip('Preserves user provided doctype', async () => {
const result = await runtime.load('/preserve');
if (result.error) throw new Error(result.error);
diff --git a/packages/astro/test/fixtures/astro-doctype/src/pages/provided.astro b/packages/astro/test/fixtures/astro-doctype/src/pages/provided.astro
new file mode 100644
index 000000000..8544ba765
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-doctype/src/pages/provided.astro
@@ -0,0 +1,9 @@
+---
+let title = 'My Site';
+---
+
+<!doctype html>
+<html lang="en">
+ <head><title>{title}</title></head>
+ <body><h1>Hello world</h1></body>
+</html> \ No newline at end of file